Navigation Menu

Skip to content

Commit

Permalink
don't stuff mw into function objects
Browse files Browse the repository at this point in the history
Using the global is preferable to fighting against mypy to insert mw
into a function object.
  • Loading branch information
dae committed Jul 3, 2020
1 parent 14602be commit 4033f00
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions qt/aqt/mediasrv.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 4033f00

Please sign in to comment.