The following issues were found

test/mitmproxy/data/addonscripts/concurrent_decorator_class.py
7 issues
Unable to import 'mitmproxy.script'
Error

Line: 2 Column: 1

              import time
from mitmproxy.script import concurrent


class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)

            

Reported by Pylint.

Unused argument 'flow'
Error

Line: 8 Column: 23

              class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)


addons = [ConcurrentClass()]

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import time
from mitmproxy.script import concurrent


class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 5 Column: 1

              from mitmproxy.script import concurrent


class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)


            

Reported by Pylint.

Missing class docstring
Error

Line: 5 Column: 1

              from mitmproxy.script import concurrent


class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 5

              class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)


addons = [ConcurrentClass()]

            

Reported by Pylint.

Method could be a function
Error

Line: 8 Column: 5

              class ConcurrentClass:

    @concurrent
    def request(self, flow):
        time.sleep(0.1)


addons = [ConcurrentClass()]

            

Reported by Pylint.

test/mitmproxy/net/test_server_spec.py
7 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.net import server_spec


@pytest.mark.parametrize("spec,out", [
    ("example.com", ("https", ("example.com", 443))),
    ("http://example.com", ("http", ("example.com", 80))),
    ("smtp.example.com:25", ("http", ("smtp.example.com", 25))),

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.net import server_spec


@pytest.mark.parametrize("spec,out", [
    ("example.com", ("https", ("example.com", 443))),
    ("http://example.com", ("http", ("example.com", 80))),
    ("smtp.example.com:25", ("http", ("smtp.example.com", 25))),

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

                  ("http://[::1]/", ("http", ("::1", 80))),
    ("https://[::1]/", ("https", ("::1", 443))),
    ("http://[::1]:8080", ("http", ("::1", 8080))),
])
def test_parse(spec, out):
    assert server_spec.parse(spec) == out


def test_parse_err():

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 17
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  ("http://[::1]:8080", ("http", ("::1", 8080))),
])
def test_parse(spec, out):
    assert server_spec.parse(spec) == out


def test_parse_err():
    with pytest.raises(ValueError, match="Invalid server specification"):
        server_spec.parse(":")

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 20 Column: 1

                  assert server_spec.parse(spec) == out


def test_parse_err():
    with pytest.raises(ValueError, match="Invalid server specification"):
        server_spec.parse(":")

    with pytest.raises(ValueError, match="Invalid server scheme"):
        server_spec.parse("ftp://example.com")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 34 Column: 1

                      server_spec.parse("example.com:999999")


def test_parse_with_mode():
    assert server_spec.parse_with_mode("m:example.com") == ("m", ("https", ("example.com", 443)))
    with pytest.raises(ValueError):
        server_spec.parse_with_mode("moo")

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 35
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              

def test_parse_with_mode():
    assert server_spec.parse_with_mode("m:example.com") == ("m", ("https", ("example.com", 443)))
    with pytest.raises(ValueError):
        server_spec.parse_with_mode("moo")

            

Reported by Bandit.

test/mitmproxy/tools/console/test_palettes.py
7 issues
Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy.tools.console import palettes


class TestPalette:

    def test_helptext(self):
        for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 4 Column: 1

              from mitmproxy.tools.console import palettes


class TestPalette:

    def test_helptext(self):
        for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              from mitmproxy.tools.console import palettes


class TestPalette:

    def test_helptext(self):
        for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 5

              
class TestPalette:

    def test_helptext(self):
        for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():
            assert i.palette(True)

            

Reported by Pylint.

Method could be a function
Error

Line: 6 Column: 5

              
class TestPalette:

    def test_helptext(self):
        for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():
            assert i.palette(True)

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 8
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
    def test_helptext(self):
        for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():
            assert i.palette(True)

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 10
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      for i in palettes.palettes.values():
            assert i.palette(False)
        for i in palettes.palettes.values():
            assert i.palette(True)

            

Reported by Bandit.

examples/contrib/change_upstream_proxy.py
6 issues
Unable to import 'mitmproxy'
Error

Line: 1 Column: 1

              from mitmproxy import http
import typing

# This scripts demonstrates how mitmproxy can switch to a second/different upstream proxy
# in upstream proxy mode.
#
# Usage: mitmdump -U http://default-upstream-proxy.local:8080/ -s change_upstream_proxy.py
#
# If you want to change the target server, you should modify flow.request.host and flow.request.port

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy import http
import typing

# This scripts demonstrates how mitmproxy can switch to a second/different upstream proxy
# in upstream proxy mode.
#
# Usage: mitmdump -U http://default-upstream-proxy.local:8080/ -s change_upstream_proxy.py
#
# If you want to change the target server, you should modify flow.request.host and flow.request.port

            

Reported by Pylint.

standard import "import typing" should be placed before "from mitmproxy import http"
Error

Line: 2 Column: 1

              from mitmproxy import http
import typing

# This scripts demonstrates how mitmproxy can switch to a second/different upstream proxy
# in upstream proxy mode.
#
# Usage: mitmdump -U http://default-upstream-proxy.local:8080/ -s change_upstream_proxy.py
#
# If you want to change the target server, you should modify flow.request.host and flow.request.port

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              # If you want to change the target server, you should modify flow.request.host and flow.request.port


def proxy_address(flow: http.HTTPFlow) -> typing.Tuple[str, int]:
    # Poor man's loadbalancing: route every second domain through the alternative proxy.
    if hash(flow.request.host) % 2 == 1:
        return ("localhost", 8082)
    else:
        return ("localhost", 8081)

            

Reported by Pylint.

Unnecessary "else" after "return"
Error

Line: 14 Column: 5

              
def proxy_address(flow: http.HTTPFlow) -> typing.Tuple[str, int]:
    # Poor man's loadbalancing: route every second domain through the alternative proxy.
    if hash(flow.request.host) % 2 == 1:
        return ("localhost", 8082)
    else:
        return ("localhost", 8081)



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                      return ("localhost", 8081)


def request(flow: http.HTTPFlow) -> None:
    if flow.request.method == "CONNECT":
        # If the decision is done by domain, one could also modify the server address here.
        # We do it after CONNECT here to have the request data available as well.
        return
    address = proxy_address(flow)

            

Reported by Pylint.

mitmproxy/addons/anticache.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy import ctx


class AntiCache:
    def load(self, loader):
        loader.add_option(
            "anticache", bool, False,
            """
            Strip out request headers that might cause the server to return

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              from mitmproxy import ctx


class AntiCache:
    def load(self, loader):
        loader.add_option(
            "anticache", bool, False,
            """
            Strip out request headers that might cause the server to return

            

Reported by Pylint.

Method could be a function
Error

Line: 5 Column: 5

              

class AntiCache:
    def load(self, loader):
        loader.add_option(
            "anticache", bool, False,
            """
            Strip out request headers that might cause the server to return
            304-not-modified.

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 5

              

class AntiCache:
    def load(self, loader):
        loader.add_option(
            "anticache", bool, False,
            """
            Strip out request headers that might cause the server to return
            304-not-modified.

            

Reported by Pylint.

Method could be a function
Error

Line: 14 Column: 5

                          """
        )

    def request(self, flow):
        if ctx.options.anticache:
            flow.request.anticache()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 5

                          """
        )

    def request(self, flow):
        if ctx.options.anticache:
            flow.request.anticache()

            

Reported by Pylint.

mitmproxy/addons/anticomp.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy import ctx


class AntiComp:
    def load(self, loader):
        loader.add_option(
            "anticomp", bool, False,
            "Try to convince servers to send us un-compressed data."
        )

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              from mitmproxy import ctx


class AntiComp:
    def load(self, loader):
        loader.add_option(
            "anticomp", bool, False,
            "Try to convince servers to send us un-compressed data."
        )

            

Reported by Pylint.

Method could be a function
Error

Line: 5 Column: 5

              

class AntiComp:
    def load(self, loader):
        loader.add_option(
            "anticomp", bool, False,
            "Try to convince servers to send us un-compressed data."
        )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 5

              

class AntiComp:
    def load(self, loader):
        loader.add_option(
            "anticomp", bool, False,
            "Try to convince servers to send us un-compressed data."
        )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 5

                          "Try to convince servers to send us un-compressed data."
        )

    def request(self, flow):
        if ctx.options.anticomp:
            flow.request.anticomp()

            

Reported by Pylint.

Method could be a function
Error

Line: 11 Column: 5

                          "Try to convince servers to send us un-compressed data."
        )

    def request(self, flow):
        if ctx.options.anticomp:
            flow.request.anticomp()

            

Reported by Pylint.

mitmproxy/addons/comment.py
6 issues
Redefining name 'flow' from outer scope (line 2)
Error

Line: 8 Column: 23

              
class Comment:
    @command.command("flow.comment")
    def comment(self, flow: typing.Sequence[flow.Flow], comment: str) -> None:
        "Add a comment to a flow"

        updated = []
        for f in flow:
            f.comment = comment

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import typing
from mitmproxy import command, flow, ctx
from mitmproxy.hooks import UpdateHook


class Comment:
    @command.command("flow.comment")
    def comment(self, flow: typing.Sequence[flow.Flow], comment: str) -> None:
        "Add a comment to a flow"

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 6 Column: 1

              from mitmproxy.hooks import UpdateHook


class Comment:
    @command.command("flow.comment")
    def comment(self, flow: typing.Sequence[flow.Flow], comment: str) -> None:
        "Add a comment to a flow"

        updated = []

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from mitmproxy.hooks import UpdateHook


class Comment:
    @command.command("flow.comment")
    def comment(self, flow: typing.Sequence[flow.Flow], comment: str) -> None:
        "Add a comment to a flow"

        updated = []

            

Reported by Pylint.

Method could be a function
Error

Line: 8 Column: 5

              
class Comment:
    @command.command("flow.comment")
    def comment(self, flow: typing.Sequence[flow.Flow], comment: str) -> None:
        "Add a comment to a flow"

        updated = []
        for f in flow:
            f.comment = comment

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 12 Column: 13

                      "Add a comment to a flow"

        updated = []
        for f in flow:
            f.comment = comment
            updated.append(f)

        ctx.master.addons.trigger(UpdateHook(updated))

            

Reported by Pylint.

examples/addons/commands-simple.py
6 issues
Unable to import 'mitmproxy'
Error

Line: 2 Column: 1

              """Add a custom command to mitmproxy's command prompt."""
from mitmproxy import command
from mitmproxy import ctx


class MyAddon:
    def __init__(self):
        self.num = 0


            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 3 Column: 1

              """Add a custom command to mitmproxy's command prompt."""
from mitmproxy import command
from mitmproxy import ctx


class MyAddon:
    def __init__(self):
        self.num = 0


            

Reported by Pylint.

Module name "commands-simple" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              """Add a custom command to mitmproxy's command prompt."""
from mitmproxy import command
from mitmproxy import ctx


class MyAddon:
    def __init__(self):
        self.num = 0


            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from mitmproxy import ctx


class MyAddon:
    def __init__(self):
        self.num = 0

    @command.command("myaddon.inc")
    def inc(self) -> None:

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 6 Column: 1

              from mitmproxy import ctx


class MyAddon:
    def __init__(self):
        self.num = 0

    @command.command("myaddon.inc")
    def inc(self) -> None:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 5

                      self.num = 0

    @command.command("myaddon.inc")
    def inc(self) -> None:
        self.num += 1
        ctx.log.info(f"num = {self.num}")


addons = [

            

Reported by Pylint.

mitmproxy/addons/stickyauth.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              import typing

from mitmproxy import exceptions
from mitmproxy import flowfilter
from mitmproxy import ctx


class StickyAuth:
    def __init__(self):

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from mitmproxy import ctx


class StickyAuth:
    def __init__(self):
        self.flt = None
        self.hosts = {}

    def load(self, loader):

            

Reported by Pylint.

Method could be a function
Error

Line: 13 Column: 5

                      self.flt = None
        self.hosts = {}

    def load(self, loader):
        loader.add_option(
            "stickyauth", typing.Optional[str], None,
            "Set sticky auth filter. Matched against requests."
        )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 5

                      self.flt = None
        self.hosts = {}

    def load(self, loader):
        loader.add_option(
            "stickyauth", typing.Optional[str], None,
            "Set sticky auth filter. Matched against requests."
        )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 5

                          "Set sticky auth filter. Matched against requests."
        )

    def configure(self, updated):
        if "stickyauth" in updated:
            if ctx.options.stickyauth:
                flt = flowfilter.parse(ctx.options.stickyauth)
                if not flt:
                    raise exceptions.OptionsError(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 5

                          else:
                self.flt = None

    def request(self, flow):
        if self.flt:
            host = flow.request.host
            if "authorization" in flow.request.headers:
                self.hosts[host] = flow.request.headers["authorization"]
            elif flowfilter.match(self.flt, flow):

            

Reported by Pylint.

mitmproxy/net/http/headers.py
6 issues
Redefining built-in 'type'
Error

Line: 32 Column: 27

                  return ts[0].lower(), ts[1].lower(), d


def assemble_content_type(type, subtype, parameters):
    if not parameters:
        return f"{type}/{subtype}"
    params = "; ".join(
        f"{k}={v}"
        for k, v in parameters.items()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import collections
from typing import Dict, Optional, Tuple


def parse_content_type(c: str) -> Optional[Tuple[str, str, Dict[str, str]]]:
    """
        A simple parser for content-type values. Returns a (type, subtype,
        parameters) tuple, where type and subtype are strings, and parameters
        is a dict. If the string could not be parsed, return None.

            

Reported by Pylint.

Argument name "c" doesn't conform to snake_case naming style
Error

Line: 5 Column: 1

              from typing import Dict, Optional, Tuple


def parse_content_type(c: str) -> Optional[Tuple[str, str, Dict[str, str]]]:
    """
        A simple parser for content-type values. Returns a (type, subtype,
        parameters) tuple, where type and subtype are strings, and parameters
        is a dict. If the string could not be parsed, return None.


            

Reported by Pylint.

Variable name "ts" doesn't conform to snake_case naming style
Error

Line: 20 Column: 5

                          ("text", "html", {"charset": "UTF-8"})
    """
    parts = c.split(";", 1)
    ts = parts[0].split("/", 1)
    if len(ts) != 2:
        return None
    d = collections.OrderedDict()
    if len(parts) == 2:
        for i in parts[1].split(";"):

            

Reported by Pylint.

Variable name "d" doesn't conform to snake_case naming style
Error

Line: 23 Column: 5

                  ts = parts[0].split("/", 1)
    if len(ts) != 2:
        return None
    d = collections.OrderedDict()
    if len(parts) == 2:
        for i in parts[1].split(";"):
            clause = i.split("=", 1)
            if len(clause) == 2:
                d[clause[0].strip()] = clause[1].strip()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

                  return ts[0].lower(), ts[1].lower(), d


def assemble_content_type(type, subtype, parameters):
    if not parameters:
        return f"{type}/{subtype}"
    params = "; ".join(
        f"{k}={v}"
        for k, v in parameters.items()

            

Reported by Pylint.