diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py index 645f3a934..4214d6ea5 100644 --- a/mitmproxy/addonmanager.py +++ b/mitmproxy/addonmanager.py @@ -42,7 +42,7 @@ def safecall(): yield except (exceptions.AddonHalt, exceptions.OptionsError): raise - except Exception as e: + except Exception: etype, value, tb = sys.exc_info() tb = cut_traceback(tb, "invoke_addon") ctx.log.error( diff --git a/mitmproxy/addons/core.py b/mitmproxy/addons/core.py index 0322b4ce6..a908dbb31 100644 --- a/mitmproxy/addons/core.py +++ b/mitmproxy/addons/core.py @@ -53,7 +53,7 @@ class Core: if "body_size_limit" in updated: try: human.parse_size(opts.body_size_limit) - except ValueError as e: + except ValueError: raise exceptions.OptionsError( "Invalid body size limit specification: %s" % opts.body_size_limit diff --git a/mitmproxy/addons/proxyauth.py b/mitmproxy/addons/proxyauth.py index f8fc344a7..abdc1eacf 100644 --- a/mitmproxy/addons/proxyauth.py +++ b/mitmproxy/addons/proxyauth.py @@ -152,7 +152,7 @@ class ProxyAuth: p = ctx.options.proxyauth[1:] try: self.htpasswd = passlib.apache.HtpasswdFile(p) - except (ValueError, OSError) as v: + except (ValueError, OSError): raise exceptions.OptionsError( "Could not open htpasswd file: %s" % p ) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 1c8bd0cee..8d27840f5 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -103,7 +103,7 @@ orders = [ ] -class View(collections.Sequence): +class View(collections.abc.Sequence): def __init__(self): super().__init__() self._store = collections.OrderedDict() @@ -638,7 +638,7 @@ class Focus: self.flow = flow -class Settings(collections.Mapping): +class Settings(collections.abc.Mapping): def __init__(self, view: View) -> None: self.view = view self._values: typing.MutableMapping[str, typing.Dict] = {} diff --git a/mitmproxy/master.py b/mitmproxy/master.py index ecb8090bb..e5683356b 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -84,13 +84,14 @@ class Master: exc = None try: loop() - except Exception as e: # pragma: no cover + except Exception: # pragma: no cover exc = traceback.format_exc() finally: if not self.should_exit.is_set(): # pragma: no cover self.shutdown() loop = asyncio.get_event_loop() - for p in asyncio.Task.all_tasks(): + tasks = asyncio.all_tasks(loop) if sys.version_info >= (3, 7) else asyncio.Task.all_tasks(loop) + for p in tasks: p.cancel() loop.close() diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py index eae7f06d9..42b61f4d2 100644 --- a/mitmproxy/proxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -642,7 +642,7 @@ class Http2SingleStreamLayer(httpbase._HttpTransmissionLayer, basethread.BaseThr try: layer() - except exceptions.Http2ZombieException as e: # pragma: no cover + except exceptions.Http2ZombieException: # pragma: no cover pass except exceptions.ProtocolException as e: # pragma: no cover self.log(repr(e), "info") diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/_main.py index 8baaa1c45..f1c763b2b 100644 --- a/mitmproxy/tools/_main.py +++ b/mitmproxy/tools/_main.py @@ -134,7 +134,7 @@ def run( except exceptions.OptionsError as e: print("%s: %s" % (sys.argv[0], e), file=sys.stderr) sys.exit(1) - except (KeyboardInterrupt, RuntimeError) as e: + except (KeyboardInterrupt, RuntimeError): pass return master diff --git a/release/cibuild.py b/release/cibuild.py index ba17ced27..820606398 100755 --- a/release/cibuild.py +++ b/release/cibuild.py @@ -279,7 +279,7 @@ class BuildEnviron: if self.tag.startswith("v"): try: parver.Version.parse(self.tag[1:], strict=True) - except parver.ParseError as e: + except parver.ParseError: return self.tag return self.tag[1:] return self.tag diff --git a/release/docker/Dockerfile b/release/docker/Dockerfile index 7c9a24212..258bccf59 100644 --- a/release/docker/Dockerfile +++ b/release/docker/Dockerfile @@ -21,7 +21,8 @@ RUN addgroup -S mitmproxy && adduser -S -G mitmproxy mitmproxy \ openssl-dev \ python3 \ python3-dev \ - && python3 -m ensurepip \ + && python3 -m ensurepip --upgrade \ + && pip3 install -U pip \ && LDFLAGS=-L/lib pip3 install -U /home/mitmproxy/${WHEEL_BASENAME_MITMPROXY} \ && apk del --purge \ git \ diff --git a/release/docker/DockerfileARMv7 b/release/docker/DockerfileARMv7 index 6e04b7ad7..40f10edef 100644 --- a/release/docker/DockerfileARMv7 +++ b/release/docker/DockerfileARMv7 @@ -23,7 +23,8 @@ RUN addgroup -S mitmproxy && adduser -S -G mitmproxy mitmproxy \ openssl-dev \ python3 \ python3-dev \ - && python3 -m ensurepip \ + && python3 -m ensurepip --upgrade \ + && pip3 install -U pip \ && LDFLAGS=-L/lib pip3 install -U /home/mitmproxy/${WHEEL_BASENAME_MITMPROXY} \ && apk del --purge \ git \ diff --git a/setup.cfg b/setup.cfg index 173166d13..83144c22d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [flake8] max-line-length = 140 max-complexity = 25 -ignore = E251,C901,W503,W292,E722,E741 +ignore = E251,E252,C901,W292,W503,W504,W605,E722,E741 exclude = mitmproxy/contrib/*,test/mitmproxy/data/*,release/build/*,mitmproxy/io/proto/* addons = file,open,basestring,xrange,unicode,long,cmp diff --git a/setup.py b/setup.py index f3e0312e6..5833ce38a 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,7 @@ setup( "brotlipy>=0.7.0,<0.8", "certifi>=2015.11.20.1", # no semver here - this should always be on the last release! "click>=6.2, <7", - "cryptography>=2.1.4,<2.4", + "cryptography>=2.1.4,<2.5", "h2>=3.0.1,<4", "hyperframe>=5.1.0,<6", "kaitaistruct>=0.7,<0.9", @@ -74,9 +74,9 @@ setup( "protobuf>=3.6.0, <3.7", "pyasn1>=0.3.1,<0.5", "pyOpenSSL>=17.5,<18.1", - "pyparsing>=2.1.3, <2.3", - "pyperclip>=1.6.0, <1.7", - "ruamel.yaml>=0.13.2, <0.15.55", + "pyparsing>=2.1.3,<2.4", + "pyperclip>=1.6.0,<1.8", + "ruamel.yaml>=0.15,<0.16", "sortedcontainers>=1.5.4,<2.1", "tornado>=4.3,<5.2", "urwid>=2.0.1,<2.1", @@ -88,7 +88,7 @@ setup( ], 'dev': [ "asynctest>=0.12.0", - "flake8>=3.5, <3.6", + "flake8>=3.5,<3.7", "Flask>=1.0,<1.1", "mypy>=0.590,<0.591", "parver>=0.1,<2.0", @@ -97,9 +97,9 @@ setup( "pytest-faulthandler>=1.3.1,<2", "pytest-timeout>=1.2.1,<2", "pytest-xdist>=1.22,<2", - "pytest>=3.3,<4", + "pytest>=4.0,<5", "requests>=2.9.1, <3", - "tox>=3.0,<3.2", + "tox>=3.5,<3.6", "rstcheck>=2.2, <4.0", ], 'examples': [ diff --git a/test/mitmproxy/addons/test_readfile.py b/test/mitmproxy/addons/test_readfile.py index 3d28d8b7d..94e18cdb3 100644 --- a/test/mitmproxy/addons/test_readfile.py +++ b/test/mitmproxy/addons/test_readfile.py @@ -30,8 +30,8 @@ def data(): @pytest.fixture -def corrupt_data(): - f = data() +def corrupt_data(data): + f = io.BytesIO(data.getvalue()) f.seek(0, io.SEEK_END) f.write(b"qibble") f.seek(0) diff --git a/test/mitmproxy/net/http/test_headers.py b/test/mitmproxy/net/http/test_headers.py index e8eb31d31..8fc8b027f 100644 --- a/test/mitmproxy/net/http/test_headers.py +++ b/test/mitmproxy/net/http/test_headers.py @@ -75,7 +75,7 @@ class TestHeaders: def test_replace_multi(self): headers = self._2host() - headers.replace(r"Host: example\.com", r"Host: example.de") + headers.replace(r"Host: example.com", r"Host: example.de") assert headers.get_all("Host") == ["example.de", "example.org"] def test_replace_remove_spacer(self): diff --git a/test/mitmproxy/test_http.py b/test/mitmproxy/test_http.py index 49e61e25a..8a299d8e7 100644 --- a/test/mitmproxy/test_http.py +++ b/test/mitmproxy/test_http.py @@ -49,7 +49,7 @@ class TestHTTPRequest: r.path = "path/foo" r.headers["Foo"] = "fOo" r.content = b"afoob" - assert r.replace("foo(?i)", "boo") == 4 + assert r.replace("(?i)foo", "boo") == 4 assert r.path == "path/boo" assert b"foo" not in r.content assert r.headers["boo"] == "boo" @@ -82,7 +82,7 @@ class TestHTTPResponse: r = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) r.headers["Foo"] = "fOo" r.content = b"afoob" - assert r.replace("foo(?i)", "boo") == 3 + assert r.replace("(?i)foo", "boo") == 3 assert b"foo" not in r.content assert r.headers["boo"] == "boo" diff --git a/tox.ini b/tox.ini index 9401b8f26..85cf40aaf 100644 --- a/tox.ini +++ b/tox.ini @@ -44,8 +44,8 @@ commands = passenv = TRAVIS_* APPVEYOR_* AWS_* TWINE_* DOCKER_* RTOOL_KEY WHEEL DOCKER PYINSTALLER WININSTALLER deps = -rrequirements.txt - pyinstaller==3.3.1 - twine==1.11.0 + pyinstaller==3.4 + twine==1.12.1 awscli commands = mitmdump --version