From 4033f00988c6d028017b32c8d627bd041b9c4cd8 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 3 Jul 2020 10:55:29 +1000 Subject: [PATCH] don't stuff mw into function objects Using the global is preferable to fighting against mypy to insert mw into a function object. --- qt/aqt/mediasrv.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index 430deb90d53..68049540817 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -50,8 +50,6 @@ class MediaServer(threading.Thread): def __init__(self, mw: aqt.main.AnkiQt, *args, **kwargs): super().__init__(*args, **kwargs) self.is_shutdown = False - _redirectWebExports.mw = mw # type: ignore - allroutes.mw = mw # type: ignore def run(self): try: @@ -125,9 +123,9 @@ def allroutes(pathin): if flask.request.method == "POST": if path == "graphData": body = request.data - data = graph_data(allroutes.mw.col, **from_json_bytes(body)) + data = graph_data(aqt.mw.col, **from_json_bytes(body)) elif path == "i18nResources": - data = allroutes.mw.col.backend.i18n_resources() + data = aqt.mw.col.backend.i18n_resources() else: return flask.make_response( "Post request to '%s - %s' is a security leak!" % (directory, path), @@ -174,7 +172,7 @@ def _redirectWebExports(path): addonPath = path[len(targetPath) :] try: - addMgr = _redirectWebExports.mw.addonManager + addMgr = aqt.mw.addonManager except AttributeError as error: if devMode: print("_redirectWebExports: %s" % error) @@ -194,7 +192,7 @@ def _redirectWebExports(path): if re.fullmatch(pattern, subPath): return addMgr.addonsFolder(), addonPath - return _redirectWebExports.mw.col.media.dir(), path + return aqt.mw.col.media.dir(), path def graph_data(col: Collection, search: str, days: int) -> bytes: