mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 11:03:13 +00:00
Extend mypy checks to mitmproxy/addons
Fix a number of issues to do this.
This commit is contained in:
parent
50deaf56bf
commit
c33557a230
@ -66,17 +66,17 @@ class OrderRequestStart(_OrderKey):
|
|||||||
|
|
||||||
|
|
||||||
class OrderRequestMethod(_OrderKey):
|
class OrderRequestMethod(_OrderKey):
|
||||||
def generate(self, f: mitmproxy.flow.Flow) -> datetime.datetime:
|
def generate(self, f: mitmproxy.flow.Flow) -> str:
|
||||||
return f.request.method
|
return f.request.method
|
||||||
|
|
||||||
|
|
||||||
class OrderRequestURL(_OrderKey):
|
class OrderRequestURL(_OrderKey):
|
||||||
def generate(self, f: mitmproxy.flow.Flow) -> datetime.datetime:
|
def generate(self, f: mitmproxy.flow.Flow) -> str:
|
||||||
return f.request.url
|
return f.request.url
|
||||||
|
|
||||||
|
|
||||||
class OrderKeySize(_OrderKey):
|
class OrderKeySize(_OrderKey):
|
||||||
def generate(self, f: mitmproxy.flow.Flow) -> datetime.datetime:
|
def generate(self, f: mitmproxy.flow.Flow) -> int:
|
||||||
s = 0
|
s = 0
|
||||||
if f.request.raw_content:
|
if f.request.raw_content:
|
||||||
s += len(f.request.raw_content)
|
s += len(f.request.raw_content)
|
||||||
@ -166,8 +166,8 @@ class View(collections.Sequence):
|
|||||||
return v
|
return v
|
||||||
return self._rev(v - 1) + 1
|
return self._rev(v - 1) + 1
|
||||||
|
|
||||||
def index(self, f: mitmproxy.flow.Flow) -> int:
|
def index(self, f: mitmproxy.flow.Flow, start: int = 0, stop: typing.Optional[int] = None) -> int:
|
||||||
return self._rev(self._view.index(f))
|
return self._rev(self._view.index(f, start, stop))
|
||||||
|
|
||||||
def __contains__(self, f: mitmproxy.flow.Flow) -> bool:
|
def __contains__(self, f: mitmproxy.flow.Flow) -> bool:
|
||||||
return self._view.__contains__(f)
|
return self._view.__contains__(f)
|
||||||
@ -318,7 +318,7 @@ class Focus:
|
|||||||
"""
|
"""
|
||||||
def __init__(self, v: View) -> None:
|
def __init__(self, v: View) -> None:
|
||||||
self.view = v
|
self.view = v
|
||||||
self._flow = None
|
self._flow = None # type: mitmproxy.flow.Flow
|
||||||
self.sig_change = blinker.Signal()
|
self.sig_change = blinker.Signal()
|
||||||
if len(self.view):
|
if len(self.view):
|
||||||
self.flow = self.view[0]
|
self.flow = self.view[0]
|
||||||
@ -374,29 +374,29 @@ class Focus:
|
|||||||
class Settings(collections.Mapping):
|
class Settings(collections.Mapping):
|
||||||
def __init__(self, view: View) -> None:
|
def __init__(self, view: View) -> None:
|
||||||
self.view = view
|
self.view = view
|
||||||
self.values = {}
|
self._values = {} # type: typing.MutableMapping[str, mitmproxy.flow.Flow]
|
||||||
view.sig_remove.connect(self._sig_remove)
|
view.sig_remove.connect(self._sig_remove)
|
||||||
view.sig_refresh.connect(self._sig_refresh)
|
view.sig_refresh.connect(self._sig_refresh)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.values.clear()
|
self._values.clear()
|
||||||
|
|
||||||
def __iter__(self) -> typing.Iterable:
|
def __iter__(self) -> typing.Iterator:
|
||||||
return iter(self.values)
|
return iter(self._values)
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
return len(self.values)
|
return len(self._values)
|
||||||
|
|
||||||
def __getitem__(self, f: mitmproxy.flow.Flow) -> dict:
|
def __getitem__(self, f: mitmproxy.flow.Flow) -> dict:
|
||||||
if f.id not in self.view._store:
|
if f.id not in self.view._store:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
return self.values.setdefault(f.id, {})
|
return self._values.setdefault(f.id, {})
|
||||||
|
|
||||||
def _sig_remove(self, view, flow):
|
def _sig_remove(self, view, flow):
|
||||||
if flow.id in self.values:
|
if flow.id in self._values:
|
||||||
del self.values[flow.id]
|
del self._values[flow.id]
|
||||||
|
|
||||||
def _sig_refresh(self, view):
|
def _sig_refresh(self, view):
|
||||||
for fid in list(self.values.keys()):
|
for fid in list(self._values.keys()):
|
||||||
if fid not in view._store:
|
if fid not in view._store:
|
||||||
del self.values[fid]
|
del self._values[fid]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import sys
|
import sys
|
||||||
import collections
|
|
||||||
|
|
||||||
import tornado.httpserver
|
import tornado.httpserver
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
|
2
tox.ini
2
tox.ini
@ -21,4 +21,4 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
|
|||||||
commands =
|
commands =
|
||||||
flake8 --jobs 8 --count mitmproxy pathod examples test
|
flake8 --jobs 8 --count mitmproxy pathod examples test
|
||||||
rstcheck README.rst
|
rstcheck README.rst
|
||||||
mypy --silent-imports mitmproxy/addonmanager.py mitmproxy/proxy/protocol/
|
mypy --silent-imports mitmproxy/addons mitmproxy/addonmanager.py mitmproxy/proxy/protocol/
|
||||||
|
Loading…
Reference in New Issue
Block a user