From beb49ab121d268b0f86c5bd9c6e191328fe91915 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 29 Mar 2022 13:51:08 +0200 Subject: [PATCH] don't use #noqa for imports --- docs/scripts/api-events.py | 1 - examples/addons/io-write-flow-file.py | 2 +- examples/contrib/har_dump.py | 2 +- examples/contrib/sslstrip.py | 2 +- mitmproxy/addons/eventstore.py | 2 +- mitmproxy/addons/stickycookie.py | 2 +- mitmproxy/contentviews/raw.py | 2 -- mitmproxy/flow.py | 2 +- mitmproxy/io/compat.py | 2 +- mitmproxy/net/encoding.py | 25 +++++++++---------- mitmproxy/tools/console/flowlist.py | 2 +- mitmproxy/tools/console/flowview.py | 6 ++--- .../tools/console/grideditor/__init__.py | 23 +++++++++++++++-- mitmproxy/tools/console/grideditor/base.py | 2 +- mitmproxy/tools/console/palettes.py | 2 +- mitmproxy/tools/console/statusbar.py | 2 +- 16 files changed, 47 insertions(+), 32 deletions(-) diff --git a/docs/scripts/api-events.py b/docs/scripts/api-events.py index eca751a79..4925610f6 100644 --- a/docs/scripts/api-events.py +++ b/docs/scripts/api-events.py @@ -5,7 +5,6 @@ import textwrap from pathlib import Path from typing import List, Type -import mitmproxy.addons.next_layer # noqa from mitmproxy import hooks, log, addonmanager from mitmproxy.proxy import server_hooks, layer from mitmproxy.proxy.layers import http, modes, tcp, tls, websocket diff --git a/examples/addons/io-write-flow-file.py b/examples/addons/io-write-flow-file.py index e885051d4..567acc6a6 100644 --- a/examples/addons/io-write-flow-file.py +++ b/examples/addons/io-write-flow-file.py @@ -10,7 +10,7 @@ to multiple files in parallel. import random import sys from mitmproxy import io, http -import typing # noqa +import typing class Writer: diff --git a/examples/contrib/har_dump.py b/examples/contrib/har_dump.py index 14ecad701..747a7a18a 100644 --- a/examples/contrib/har_dump.py +++ b/examples/contrib/har_dump.py @@ -13,7 +13,7 @@ import json import base64 import zlib import os -import typing # noqa +import typing from datetime import datetime from datetime import timezone diff --git a/examples/contrib/sslstrip.py b/examples/contrib/sslstrip.py index 16d9b59a4..7b053d440 100644 --- a/examples/contrib/sslstrip.py +++ b/examples/contrib/sslstrip.py @@ -4,7 +4,7 @@ https://moxie.org/software/sslstrip/ """ import re import urllib.parse -import typing # noqa +import typing from mitmproxy import http diff --git a/mitmproxy/addons/eventstore.py b/mitmproxy/addons/eventstore.py index ca20dcd1f..0cf5de70e 100644 --- a/mitmproxy/addons/eventstore.py +++ b/mitmproxy/addons/eventstore.py @@ -1,5 +1,5 @@ import collections -import typing # noqa +import typing import blinker diff --git a/mitmproxy/addons/stickycookie.py b/mitmproxy/addons/stickycookie.py index 3b67bb82c..3d0e12f03 100644 --- a/mitmproxy/addons/stickycookie.py +++ b/mitmproxy/addons/stickycookie.py @@ -1,6 +1,6 @@ import collections from http import cookiejar -from typing import List, Tuple, Dict, Optional # noqa +from typing import List, Tuple, Dict, Optional from mitmproxy import http, flowfilter, ctx, exceptions from mitmproxy.net.http import cookies diff --git a/mitmproxy/contentviews/raw.py b/mitmproxy/contentviews/raw.py index 248021403..a0b0884ec 100644 --- a/mitmproxy/contentviews/raw.py +++ b/mitmproxy/contentviews/raw.py @@ -1,5 +1,3 @@ -from typing import List # noqa - from mitmproxy.utils import strutils from . import base diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 8767ba504..9a1976cbd 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -1,6 +1,6 @@ import asyncio import time -import typing # noqa +import typing import uuid from mitmproxy import connection diff --git a/mitmproxy/io/compat.py b/mitmproxy/io/compat.py index 368eb0d96..86f62a1ef 100644 --- a/mitmproxy/io/compat.py +++ b/mitmproxy/io/compat.py @@ -6,7 +6,7 @@ v3.0.0dev) and versioning. Every change or migration gets a new flow file version number, this prevents issues with developer builds and snapshots. """ import uuid -from typing import Any, Dict, Mapping, Union # noqa +from typing import Any, Dict, Mapping, Union from mitmproxy import version from mitmproxy.utils import strutils diff --git a/mitmproxy/net/encoding.py b/mitmproxy/net/encoding.py index 854931e60..f13c808d6 100644 --- a/mitmproxy/net/encoding.py +++ b/mitmproxy/net/encoding.py @@ -4,15 +4,14 @@ Utility functions for decoding response bodies. import codecs import collections -from io import BytesIO - import gzip import zlib +from io import BytesIO +from typing import Union, overload + import brotli import zstandard as zstd -from typing import Union, Optional, AnyStr, overload # noqa - # We have a shared single-element cache for encoding and decoding. # This is quite useful in practice, e.g. # flow.request.content = flow.request.content.replace(b"foo", b"bar") @@ -39,7 +38,7 @@ def decode(encoded: bytes, encoding: str, errors: str = 'strict') -> Union[str, def decode( - encoded: Union[None, str, bytes], encoding: str, errors: str = 'strict' + encoded: Union[None, str, bytes], encoding: str, errors: str = 'strict' ) -> Union[None, str, bytes]: """ Decode the given input object @@ -56,10 +55,10 @@ def decode( global _cache cached = ( - isinstance(encoded, bytes) and - _cache.encoded == encoded and - _cache.encoding == encoding and - _cache.errors == errors + isinstance(encoded, bytes) and + _cache.encoded == encoded and + _cache.encoding == encoding and + _cache.errors == errors ) if cached: return _cache.decoded @@ -113,10 +112,10 @@ def encode(decoded: Union[None, str, bytes], encoding, errors='strict') -> Union global _cache cached = ( - isinstance(decoded, bytes) and - _cache.decoded == decoded and - _cache.encoding == encoding and - _cache.errors == errors + isinstance(decoded, bytes) and + _cache.decoded == decoded and + _cache.encoding == encoding and + _cache.errors == errors ) if cached: return _cache.encoded diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py index b21a16b3b..431870d97 100644 --- a/mitmproxy/tools/console/flowlist.py +++ b/mitmproxy/tools/console/flowlist.py @@ -2,7 +2,7 @@ import urwid from mitmproxy.tools.console import common from mitmproxy.tools.console import layoutwidget -import mitmproxy.tools.console.master # noqa +import mitmproxy.tools.console.master class FlowItem(urwid.WidgetWrap): diff --git a/mitmproxy/tools/console/flowview.py b/mitmproxy/tools/console/flowview.py index 93c9703a8..2da669e9d 100644 --- a/mitmproxy/tools/console/flowview.py +++ b/mitmproxy/tools/console/flowview.py @@ -1,11 +1,11 @@ import math import sys from functools import lru_cache -from typing import Optional, Union # noqa + +import urwid import mitmproxy.flow -import mitmproxy.tools.console.master # noqa -import urwid +import mitmproxy.tools.console.master from mitmproxy import contentviews from mitmproxy import ctx from mitmproxy import http diff --git a/mitmproxy/tools/console/grideditor/__init__.py b/mitmproxy/tools/console/grideditor/__init__.py index 894f3d22c..4a46e9c90 100644 --- a/mitmproxy/tools/console/grideditor/__init__.py +++ b/mitmproxy/tools/console/grideditor/__init__.py @@ -1,2 +1,21 @@ -from .editors import * # noqa -from . import base # noqa +from . import base +from .editors import CookieAttributeEditor, CookieEditor, DataViewer, OptionsEditor, PathEditor, QueryEditor, \ + RequestHeaderEditor, \ + RequestMultipartEditor, \ + RequestUrlEncodedEditor, \ + ResponseHeaderEditor, SetCookieEditor + +__all__ = [ + "base", + "QueryEditor", + "RequestHeaderEditor", + "ResponseHeaderEditor", + "RequestMultipartEditor", + "RequestUrlEncodedEditor", + "PathEditor", + "CookieEditor", + "CookieAttributeEditor", + "SetCookieEditor", + "OptionsEditor", + "DataViewer", +] diff --git a/mitmproxy/tools/console/grideditor/base.py b/mitmproxy/tools/console/grideditor/base.py index d6991877a..d830afb11 100644 --- a/mitmproxy/tools/console/grideditor/base.py +++ b/mitmproxy/tools/console/grideditor/base.py @@ -8,7 +8,7 @@ from mitmproxy.utils import strutils from mitmproxy import exceptions from mitmproxy.tools.console import signals from mitmproxy.tools.console import layoutwidget -import mitmproxy.tools.console.master # noqa +import mitmproxy.tools.console.master def read_file(filename: str, escaped: bool) -> typing.AnyStr: diff --git a/mitmproxy/tools/console/palettes.py b/mitmproxy/tools/console/palettes.py index 571358864..2b18d83d6 100644 --- a/mitmproxy/tools/console/palettes.py +++ b/mitmproxy/tools/console/palettes.py @@ -1,4 +1,4 @@ -import typing # noqa +import typing # Low-color themes should ONLY use the standard foreground and background # colours listed here: # diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py index 89bda0569..bd481cac5 100644 --- a/mitmproxy/tools/console/statusbar.py +++ b/mitmproxy/tools/console/statusbar.py @@ -3,7 +3,7 @@ from typing import Optional import urwid -import mitmproxy.tools.console.master # noqa +import mitmproxy.tools.console.master from mitmproxy.tools.console import commandexecutor from mitmproxy.tools.console import common from mitmproxy.tools.console import signals