{html.escape(log)}" diff --git a/pylib/anki/media.py b/pylib/anki/media.py index a491f2436..15c03c070 100644 --- a/pylib/anki/media.py +++ b/pylib/anki/media.py @@ -1,6 +1,8 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +# pylint: enable=invalid-name + from __future__ import annotations import os @@ -11,12 +13,13 @@ import time from typing import Any, Callable from anki import media_pb2 +from anki._legacy import DeprecatedNamesMixin, deprecated_keywords from anki.consts import * from anki.latex import render_latex, render_latex_returning_errors from anki.models import NotetypeId from anki.sound import SoundOrVideoTag from anki.template import av_tags_to_native -from anki.utils import intTime +from anki.utils import int_time def media_paths_from_col_path(col_path: str) -> tuple[str, str]: @@ -33,7 +36,7 @@ CheckMediaResponse = media_pb2.CheckMediaResponse # - and audio handling code -class MediaManager: +class MediaManager(DeprecatedNamesMixin): sound_regexps = [r"(?i)(\[sound:(?P
{tr.about_anki_is_a_friendly_intelligent_spaced()}" abouttext += f"
{tr.about_anki_is_licensed_under_the_agpl3()}" - abouttext += f"
{tr.about_version(val=versionWithBuild())}
"
+ abouttext += f"
{tr.about_version(val=version_with_build())}
"
abouttext += ("Python %s Qt %s PyQt %s
") % (
platform.python_version(),
QT_VERSION_STR,
diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py
index 8057cf586..9f80d1d73 100644
--- a/qt/aqt/addcards.py
+++ b/qt/aqt/addcards.py
@@ -10,7 +10,7 @@ from anki.collection import OpChanges, SearchNode
from anki.decks import DeckId
from anki.models import NotetypeId
from anki.notes import Note, NoteFieldsCheckResult, NoteId
-from anki.utils import htmlToTextLine, isMac
+from anki.utils import html_to_text_line, isMac
from aqt import AnkiQt, gui_hooks
from aqt.deckchooser import DeckChooser
from aqt.notetypechooser import NotetypeChooser
@@ -197,7 +197,7 @@ class AddCards(QDialog):
if self.col.find_notes(self.col.build_search_string(SearchNode(nid=nid))):
note = self.col.get_note(nid)
fields = note.fields
- txt = htmlToTextLine(", ".join(fields))
+ txt = html_to_text_line(", ".join(fields))
if len(txt) > 30:
txt = f"{txt[:30]}..."
line = tr.adding_edit(val=txt)
diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py
index c8c69b6de..91d019db1 100644
--- a/qt/aqt/addons.py
+++ b/qt/aqt/addons.py
@@ -95,7 +95,7 @@ class UpdateInfo:
ANKIWEB_ID_RE = re.compile(r"^\d+$")
-current_point_version = anki.utils.pointVersion()
+current_point_version = anki.utils.point_version()
@dataclass
@@ -983,7 +983,7 @@ def download_addon(client: HttpClient, id: int) -> DownloadOk | DownloadError:
if resp.status_code != 200:
return DownloadError(status_code=resp.status_code)
- data = client.streamContent(resp)
+ data = client.stream_content(resp)
fname = re.match(
"attachment; filename=(.+)", resp.headers["content-disposition"]
diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py
index bea54332e..31fe1be98 100644
--- a/qt/aqt/editor.py
+++ b/qt/aqt/editor.py
@@ -484,7 +484,7 @@ noteEditorPromise.then(noteEditor => noteEditor.toolbar.then((toolbar) => toolba
json.dumps(focusTo),
json.dumps(self.note.id),
json.dumps([text_color, highlight_color]),
- json.dumps(self.mw.col.tags.canonify(self.note.tags)),
+ json.dumps(self.note.tags),
)
if self.addMode:
@@ -674,12 +674,12 @@ noteEditorPromise.then(noteEditor => noteEditor.toolbar.then((toolbar) => toolba
def _addMedia(self, path: str, canDelete: bool = False) -> str:
"""Add to media folder and return local img or sound tag."""
# copy to media folder
- fname = self.mw.col.media.addFile(path)
+ fname = self.mw.col.media.add_file(path)
# return a local html link
return self.fnameToLink(fname)
def _addMediaFromData(self, fname: str, data: bytes) -> str:
- return self.mw.col.media.writeData(fname, data)
+ return self.mw.col.media._legacy_write_data(fname, data)
def onRecSound(self) -> None:
aqt.sound.record_audio(
diff --git a/qt/aqt/main.py b/qt/aqt/main.py
index 1249e764f..2e3c08843 100644
--- a/qt/aqt/main.py
+++ b/qt/aqt/main.py
@@ -31,7 +31,7 @@ from anki.decks import DeckDict, DeckId
from anki.hooks import runHook
from anki.notes import NoteId
from anki.sound import AVTag, SoundOrVideoTag
-from anki.utils import devMode, ids2str, intTime, isMac, isWin, splitFields
+from anki.utils import devMode, ids2str, int_time, isMac, isWin, split_fields
from aqt import gui_hooks
from aqt.addons import DownloadLogEntry, check_and_prompt_for_updates, show_log_to_user
from aqt.dbcheck import check_db
@@ -633,11 +633,11 @@ class AnkiQt(QMainWindow):
def maybeOptimize(self) -> None:
# have two weeks passed?
- if (intTime() - self.pm.profile["lastOptimize"]) < 86400 * 14:
+ if (int_time() - self.pm.profile["lastOptimize"]) < 86400 * 14:
return
self.progress.start(label=tr.qt_misc_optimizing())
self.col.optimize()
- self.pm.profile["lastOptimize"] = intTime()
+ self.pm.profile["lastOptimize"] = int_time()
self.pm.save()
self.progress.finish()
@@ -877,7 +877,7 @@ title="{}" {}>{}""".format(
def maybe_check_for_addon_updates(self) -> None:
last_check = self.pm.last_addon_update_check()
- elap = intTime() - last_check
+ elap = int_time() - last_check
if elap > 86_400:
check_and_prompt_for_updates(
@@ -886,7 +886,7 @@ title="{}" {}>{}""".format(
self.on_updates_installed,
requested_by_user=False,
)
- self.pm.set_last_addon_update_check(intTime())
+ self.pm.set_last_addon_update_check(int_time())
def on_updates_installed(self, log: list[DownloadLogEntry]) -> None:
if log:
@@ -1321,7 +1321,7 @@ title="{}" {}>{}""".format(
for id, mid, flds in col.db.execute(
f"select id, mid, flds from notes where id in {ids2str(nids)}"
):
- fields = splitFields(flds)
+ fields = split_fields(flds)
f.write(("\t".join([str(id), str(mid)] + fields)).encode("utf8"))
f.write(b"\n")
diff --git a/qt/aqt/mediasync.py b/qt/aqt/mediasync.py
index 1c5a366ff..5961ceecf 100644
--- a/qt/aqt/mediasync.py
+++ b/qt/aqt/mediasync.py
@@ -12,7 +12,7 @@ import aqt
from anki.collection import Progress
from anki.errors import Interrupted, NetworkError
from anki.types import assert_exhaustive
-from anki.utils import intTime
+from anki.utils import int_time
from aqt import gui_hooks
from aqt.qt import QDialog, QDialogButtonBox, QPushButton, QTextCursor, QTimer, qconnect
from aqt.utils import disable_help_button, showWarning, tr
@@ -67,7 +67,7 @@ class MediaSyncer:
self.mw.taskman.run_in_background(run, self._on_finished)
def _log_and_notify(self, entry: LogEntry) -> None:
- entry_with_time = LogEntryWithTime(time=intTime(), entry=entry)
+ entry_with_time = LogEntryWithTime(time=int_time(), entry=entry)
self._log.append(entry_with_time)
self.mw.taskman.run_on_main(
lambda: gui_hooks.media_sync_did_progress(entry_with_time)
@@ -142,7 +142,7 @@ class MediaSyncer:
last = self._log[-1].time
else:
last = 0
- return intTime() - last
+ return int_time() - last
class MediaSyncDialog(QDialog):
diff --git a/qt/aqt/preferences.py b/qt/aqt/preferences.py
index ba48cf7b8..134507865 100644
--- a/qt/aqt/preferences.py
+++ b/qt/aqt/preferences.py
@@ -244,7 +244,7 @@ class Preferences(QDialog):
def current_lang_index(self) -> int:
codes = [x[1] for x in anki.lang.langs]
- lang = anki.lang.currentLang
+ lang = anki.lang.current_lang
if lang in anki.lang.compatMap:
lang = anki.lang.compatMap[lang]
else:
diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py
index 59ba16572..5ee1533b4 100644
--- a/qt/aqt/profiles.py
+++ b/qt/aqt/profiles.py
@@ -20,7 +20,7 @@ from anki.collection import Collection
from anki.db import DB
from anki.lang import without_unicode_isolation
from anki.sync import SyncAuth
-from anki.utils import intTime, isMac, isWin
+from anki.utils import int_time, isMac, isWin
from aqt import appHelpSite
from aqt.qt import *
from aqt.utils import disable_help_button, showWarning, tr
@@ -68,7 +68,7 @@ class VideoDriver(Enum):
metaConf = dict(
ver=0,
updates=True,
- created=intTime(),
+ created=int_time(),
id=random.randrange(0, 2 ** 63),
lastMsg=-1,
suppressUpdate=False,
@@ -81,7 +81,7 @@ profileConf: dict[str, Any] = dict(
mainWindowGeom=None,
mainWindowState=None,
numBackups=50,
- lastOptimize=intTime(),
+ lastOptimize=int_time(),
# editing
searchHistory=[],
lastTextColor="#00f",
diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py
index 192ed11b2..e75cd5cf8 100644
--- a/qt/aqt/reviewer.py
+++ b/qt/aqt/reviewer.py
@@ -19,7 +19,7 @@ from anki.collection import Config, OpChanges, OpChangesWithCount
from anki.scheduler.v3 import CardAnswer, NextStates, QueuedCards
from anki.scheduler.v3 import Scheduler as V3Scheduler
from anki.tags import MARKED_TAG
-from anki.utils import stripHTML
+from anki.utils import strip_html
from aqt import AnkiQt, gui_hooks
from aqt.browser.card_info import PreviousReviewerCardInfo, ReviewerCardInfo
from aqt.deckoptions import confirm_deck_then_display_options
@@ -573,7 +573,7 @@ class Reviewer:
# munge correct value
cor = self.mw.col.media.strip(self.typeCorrect)
cor = re.sub("(\n|
|?div>)+", " ", cor)
- cor = stripHTML(cor)
+ cor = strip_html(cor)
# ensure we don't chomp multiple whitespace
cor = cor.replace(" ", " ")
cor = html.unescape(cor)
diff --git a/qt/aqt/sync.py b/qt/aqt/sync.py
index 2da20d933..3dcd3a9c2 100644
--- a/qt/aqt/sync.py
+++ b/qt/aqt/sync.py
@@ -12,7 +12,7 @@ import aqt
from anki.errors import Interrupted, SyncError, SyncErrorKind
from anki.lang import without_unicode_isolation
from anki.sync import SyncOutput, SyncStatus
-from anki.utils import platDesc
+from anki.utils import plat_desc
from aqt.qt import (
QDialog,
QDialogButtonBox,
@@ -331,4 +331,4 @@ def get_id_and_pass_from_user(
# export platform version to syncing code
-os.environ["PLATFORM"] = platDesc()
+os.environ["PLATFORM"] = plat_desc()
diff --git a/qt/aqt/taglimit.py b/qt/aqt/taglimit.py
index 0a04ef3ad..a9db514a1 100644
--- a/qt/aqt/taglimit.py
+++ b/qt/aqt/taglimit.py
@@ -39,7 +39,7 @@ class TagLimit(QDialog):
self.exec()
def rebuildTagList(self) -> None:
- usertags = self.mw.col.tags.byDeck(self.deck["id"], True)
+ usertags = self.mw.col.tags.by_deck(self.deck["id"], True)
yes = self.deck.get("activeTags", [])
no = self.deck.get("inactiveTags", [])
yesHash = {}
diff --git a/qt/aqt/update.py b/qt/aqt/update.py
index 4b5a00fbd..fbcd5fcbd 100644
--- a/qt/aqt/update.py
+++ b/qt/aqt/update.py
@@ -7,7 +7,7 @@ from typing import Any
import requests
import aqt
-from anki.utils import platDesc, versionWithBuild
+from anki.utils import plat_desc, version_with_build
from aqt.main import AnkiQt
from aqt.qt import *
from aqt.utils import openLink, showText, tr
@@ -26,8 +26,8 @@ class LatestVersionFinder(QThread):
def _data(self) -> dict[str, Any]:
return {
- "ver": versionWithBuild(),
- "os": platDesc(),
+ "ver": version_with_build(),
+ "os": plat_desc(),
"id": self.config["id"],
"lm": self.config["lastMsg"],
"crt": self.config["created"],
diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py
index 28f1242dc..ed5699059 100644
--- a/qt/aqt/utils.py
+++ b/qt/aqt/utils.py
@@ -12,7 +12,13 @@ from typing import TYPE_CHECKING, Any, Literal, Sequence
import aqt
from anki.collection import Collection, HelpPage
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import
-from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
+from anki.utils import (
+ invalid_filename,
+ isMac,
+ isWin,
+ no_bundled_libs,
+ version_with_build,
+)
from aqt.qt import *
from aqt.theme import theme_manager
@@ -57,7 +63,7 @@ def openHelp(section: HelpPageArgument) -> None:
def openLink(link: str | QUrl) -> None:
tooltip(tr.qt_misc_loading(), period=1000)
- with noBundledLibs():
+ with no_bundled_libs():
QDesktopServices.openUrl(QUrl(link))
@@ -658,7 +664,7 @@ def openFolder(path: str) -> None:
if isWin:
subprocess.run(["explorer", f"file://{path}"], check=False)
else:
- with noBundledLibs():
+ with no_bundled_libs():
QDesktopServices.openUrl(QUrl(f"file://{path}"))
@@ -762,7 +768,7 @@ def closeTooltip() -> None:
# true if invalid; print warning
def checkInvalidFilename(str: str, dirsep: bool = True) -> bool:
- bad = invalidFilename(str, dirsep)
+ bad = invalid_filename(str, dirsep)
if bad:
showWarning(tr.qt_misc_the_following_character_can_not_be(val=bad))
return True
@@ -874,7 +880,7 @@ Platform: {}
Flags: frz={} ao={} sv={}
Add-ons, last update check: {}
""".format(
- versionWithBuild(),
+ version_with_build(),
platform.python_version(),
QT_VERSION_STR,
PYQT_VERSION_STR,
diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py
index 72c0cb976..21e1e79df 100644
--- a/qt/aqt/webview.py
+++ b/qt/aqt/webview.py
@@ -439,7 +439,7 @@ div[contenteditable="true"]:focus {{
window_bg_night = self.get_window_bg_color(True).name()
body_bg = window_bg_night if theme_manager.night_mode else window_bg_day
- if is_rtl(anki.lang.currentLang):
+ if is_rtl(anki.lang.current_lang):
lang_dir = "rtl"
else:
lang_dir = "ltr"