The following issues were found

mitmproxy/tools/console/commandexecutor.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              import typing

from mitmproxy import exceptions
from mitmproxy import flow
from mitmproxy import ctx

from mitmproxy.tools.console import overlay
from mitmproxy.tools.console import signals


            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 11 Column: 1

              from mitmproxy.tools.console import signals


class CommandExecutor:
    def __init__(self, master):
        self.master = master

    def __call__(self, cmd):
        if cmd.strip():

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              from mitmproxy.tools.console import signals


class CommandExecutor:
    def __init__(self, master):
        self.master = master

    def __call__(self, cmd):
        if cmd.strip():

            

Reported by Pylint.

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

Line: 19 Column: 13

                      if cmd.strip():
            try:
                ret = self.master.commands.execute(cmd)
            except exceptions.CommandError as e:
                ctx.log.error(str(e))
            else:
                if ret:
                    if type(ret) == typing.Sequence[flow.Flow]:
                        signals.status_message.send(

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 23 Column: 24

                              ctx.log.error(str(e))
            else:
                if ret:
                    if type(ret) == typing.Sequence[flow.Flow]:
                        signals.status_message.send(
                            message="Command returned %s flows" % len(ret)
                        )
                    elif type(ret) == flow.Flow:
                        signals.status_message.send(

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 27 Column: 26

                                      signals.status_message.send(
                            message="Command returned %s flows" % len(ret)
                        )
                    elif type(ret) == flow.Flow:
                        signals.status_message.send(
                            message="Command returned 1 flow"
                        )
                    else:
                        self.master.overlay(

            

Reported by Pylint.

test/mitmproxy/proxy/layers/test_tls_fuzz.py
6 issues
Unable to import 'hypothesis'
Error

Line: 1 Column: 1

              from hypothesis import given, example
from hypothesis.strategies import binary, integers

from mitmproxy.net.tls import ClientHello
from mitmproxy.proxy.layers.tls import parse_client_hello

client_hello_with_extensions = bytes.fromhex(
    "16030300bb"  # record layer
    "010000b7"  # handshake layer

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 2 Column: 1

              from hypothesis import given, example
from hypothesis.strategies import binary, integers

from mitmproxy.net.tls import ClientHello
from mitmproxy.proxy.layers.tls import parse_client_hello

client_hello_with_extensions = bytes.fromhex(
    "16030300bb"  # record layer
    "010000b7"  # handshake layer

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from hypothesis import given, example
from hypothesis.strategies import binary, integers

from mitmproxy.net.tls import ClientHello
from mitmproxy.proxy.layers.tls import parse_client_hello

client_hello_with_extensions = bytes.fromhex(
    "16030300bb"  # record layer
    "010000b7"  # handshake layer

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

              
@given(i=integers(0, len(client_hello_with_extensions)), data=binary())
@example(i=183, data=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00')
def test_fuzz_h2_request_chunks(i, data):
    try:
        ch = parse_client_hello(client_hello_with_extensions[:i] + data)
    except ValueError:
        pass
    else:

            

Reported by Pylint.

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

Line: 22 Column: 9

              @example(i=183, data=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00')
def test_fuzz_h2_request_chunks(i, data):
    try:
        ch = parse_client_hello(client_hello_with_extensions[:i] + data)
    except ValueError:
        pass
    else:
        assert ch is None or isinstance(ch, ClientHello)

            

Reported by Pylint.

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

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

                  except ValueError:
        pass
    else:
        assert ch is None or isinstance(ch, ClientHello)

            

Reported by Bandit.

mitmproxy/tools/console/layoutwidget.py
5 issues
Unnecessary pass statement
Error

Line: 22 Column: 9

                          The view focus has changed. Layout objects should implement the API
            rather than directly subscribing to events.
        """
        pass

    def view_changed(self):
        """
            The view list has changed.
        """

            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 28 Column: 9

                      """
            The view list has changed.
        """
        pass

    def layout_popping(self):
        """
            We are just about to pop a window off the stack, or exit an overlay.
        """

            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 34 Column: 9

                      """
            We are just about to pop a window off the stack, or exit an overlay.
        """
        pass

    def layout_pushed(self, prev):
        """
            We have just pushed a window onto the stack.
        """

            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 40 Column: 9

                      """
            We have just pushed a window onto the stack.
        """
        pass

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              class LayoutWidget:
    """
        All top-level layout widgets and all widgets that may be set in an
        overlay must comply with this API.
    """
    # Title is only required for windows, not overlay components
    title = ""
    keyctx = ""


            

Reported by Pylint.

test/mitmproxy/data/addonscripts/concurrent_decorator_err.py
5 issues
Unable to import 'mitmproxy.script'
Error

Line: 1 Column: 1

              from mitmproxy.script import concurrent


@concurrent
def load(v):
    pass

            

Reported by Pylint.

Unused argument 'v'
Error

Line: 5 Column: 10

              

@concurrent
def load(v):
    pass

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy.script import concurrent


@concurrent
def load(v):
    pass

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              

@concurrent
def load(v):
    pass

            

Reported by Pylint.

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

Line: 5 Column: 1

              

@concurrent
def load(v):
    pass

            

Reported by Pylint.

test/mitmproxy/addons/test_comment.py
5 issues
Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy.test import tflow, taddons
from mitmproxy.addons.comment import Comment


def test_comment():
    c = Comment()
    f = tflow.tflow()

    with taddons.context():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              from mitmproxy.addons.comment import Comment


def test_comment():
    c = Comment()
    f = tflow.tflow()

    with taddons.context():
        c.comment([f], "foo")

            

Reported by Pylint.

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

Line: 6 Column: 5

              

def test_comment():
    c = Comment()
    f = tflow.tflow()

    with taddons.context():
        c.comment([f], "foo")


            

Reported by Pylint.

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

Line: 7 Column: 5

              
def test_comment():
    c = Comment()
    f = tflow.tflow()

    with taddons.context():
        c.comment([f], "foo")

    assert f.comment == "foo"

            

Reported by Pylint.

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

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

                  with taddons.context():
        c.comment([f], "foo")

    assert f.comment == "foo"

            

Reported by Bandit.

mitmproxy/coretypes/bidi.py
5 issues
Exception arguments suggest string formatting might be intended
Error

Line: 24 Column: 9

                  def __getattr__(self, k):
        if k in self.names:
            return self.names[k]
        raise AttributeError("No such attribute: %s", k)

    def get_name(self, n, default=None):
        return self.values.get(n, default)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              class BiDi:

    """
        A wee utility class for keeping bi-directional mappings, like field
        constants in protocols. Names are attributes on the object, dict-like
        access maps values to names:

        CONST = BiDi(a=1, b=2)
        assert CONST.a == 1

            

Reported by Pylint.

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

Line: 16 Column: 16

                  def __init__(self, **kwargs):
        self.names = kwargs
        self.values = {}
        for k, v in kwargs.items():
            self.values[v] = k
        if len(self.names) != len(self.values):
            raise ValueError("Duplicate values not allowed.")

    def __getattr__(self, k):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 5

                          return self.names[k]
        raise AttributeError("No such attribute: %s", k)

    def get_name(self, n, default=None):
        return self.values.get(n, default)

            

Reported by Pylint.

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

Line: 26 Column: 5

                          return self.names[k]
        raise AttributeError("No such attribute: %s", k)

    def get_name(self, n, default=None):
        return self.values.get(n, default)

            

Reported by Pylint.

test/mitmproxy/addons/test_block.py
5 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import connection
from mitmproxy.addons import block
from mitmproxy.test import taddons


@pytest.mark.parametrize("block_global, block_private, should_be_killed, address", [
    # block_global: loopback

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import connection
from mitmproxy.addons import block
from mitmproxy.test import taddons


@pytest.mark.parametrize("block_global, block_private, should_be_killed, address", [
    # block_global: loopback

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 1

                  (False, True, False, (r"::ffff:216.58.207.174%scope",)),
    (False, True, False, ("2001:4860:4860::8888",)),
])
@pytest.mark.asyncio
async def test_block_global(block_global, block_private, should_be_killed, address):
    ar = block.Block()
    with taddons.context(ar) as tctx:
        tctx.configure(ar, block_global=block_global, block_private=block_private)
        client = connection.Client(address, ("127.0.0.1", 8080), 1607699500)

            

Reported by Pylint.

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

Line: 55 Column: 5

              ])
@pytest.mark.asyncio
async def test_block_global(block_global, block_private, should_be_killed, address):
    ar = block.Block()
    with taddons.context(ar) as tctx:
        tctx.configure(ar, block_global=block_global, block_private=block_private)
        client = connection.Client(address, ("127.0.0.1", 8080), 1607699500)
        ar.client_connected(client)
        assert bool(client.error) == should_be_killed

            

Reported by Pylint.

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

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

                      tctx.configure(ar, block_global=block_global, block_private=block_private)
        client = connection.Client(address, ("127.0.0.1", 8080), 1607699500)
        ar.client_connected(client)
        assert bool(client.error) == should_be_killed

            

Reported by Bandit.

examples/addons/nonblocking.py
5 issues
Unable to import 'mitmproxy.script'
Error

Line: 9 Column: 1

              """
import time

from mitmproxy.script import concurrent


@concurrent  # Remove this and see what happens
def request(flow):
    # This is ugly in mitmproxy's UI, but you don't want to use mitmproxy.ctx.log from a different thread.

            

Reported by Pylint.

Line too long (115/100)
Error

Line: 4 Column: 1

              """
Make events hooks non-blocking.

When event hooks are decorated with @concurrent, they will be run in their own thread, freeing the main event loop.
Please note that this generally opens the door to race conditions and decreases performance if not required.
"""
import time

from mitmproxy.script import concurrent

            

Reported by Pylint.

Line too long (108/100)
Error

Line: 5 Column: 1

              Make events hooks non-blocking.

When event hooks are decorated with @concurrent, they will be run in their own thread, freeing the main event loop.
Please note that this generally opens the door to race conditions and decreases performance if not required.
"""
import time

from mitmproxy.script import concurrent


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              

@concurrent  # Remove this and see what happens
def request(flow):
    # This is ugly in mitmproxy's UI, but you don't want to use mitmproxy.ctx.log from a different thread.
    print(f"handle request: {flow.request.host}{flow.request.path}")
    time.sleep(5)
    print(f"start  request: {flow.request.host}{flow.request.path}")

            

Reported by Pylint.

Line too long (106/100)
Error

Line: 14 Column: 1

              
@concurrent  # Remove this and see what happens
def request(flow):
    # This is ugly in mitmproxy's UI, but you don't want to use mitmproxy.ctx.log from a different thread.
    print(f"handle request: {flow.request.host}{flow.request.path}")
    time.sleep(5)
    print(f"start  request: {flow.request.host}{flow.request.path}")

            

Reported by Pylint.

examples/contrib/dns_spoofing.py
5 issues
Missing class docstring
Error

Line: 34 Column: 1

              parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$")


class Rerouter:
    def request(self, flow):
        if flow.client_conn.tls_established:
            flow.request.scheme = "https"
            sni = flow.client_conn.connection.get_servername()
            port = 443

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 34 Column: 1

              parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$")


class Rerouter:
    def request(self, flow):
        if flow.client_conn.tls_established:
            flow.request.scheme = "https"
            sni = flow.client_conn.connection.get_servername()
            port = 443

            

Reported by Pylint.

Method could be a function
Error

Line: 35 Column: 5

              

class Rerouter:
    def request(self, flow):
        if flow.client_conn.tls_established:
            flow.request.scheme = "https"
            sni = flow.client_conn.connection.get_servername()
            port = 443
        else:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 5

              

class Rerouter:
    def request(self, flow):
        if flow.client_conn.tls_established:
            flow.request.scheme = "https"
            sni = flow.client_conn.connection.get_servername()
            port = 443
        else:

            

Reported by Pylint.

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

Line: 46 Column: 9

                          port = 80

        host_header = flow.request.host_header
        m = parse_host_header.match(host_header)
        if m:
            host_header = m.group("host").strip("[]")
            if m.group("port"):
                port = int(m.group("port"))


            

Reported by Pylint.

mitmproxy/tools/cmdline.py
5 issues
Missing module docstring
Error

Line: 1 Column: 1

              import argparse


def common_options(parser, opts):
    parser.add_argument(
        '--version',
        action='store_true',
        help="show version number and exit",
        dest='version',

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 1

              import argparse


def common_options(parser, opts):
    parser.add_argument(
        '--version',
        action='store_true',
        help="show version number and exit",
        dest='version',

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 104 Column: 1

                  opts.make_parser(group, "modify_headers", metavar="PATTERN", short="H")


def mitmproxy(opts):
    parser = argparse.ArgumentParser(usage="%(prog)s [options]")
    common_options(parser, opts)

    opts.make_parser(parser, "console_layout")
    opts.make_parser(parser, "console_layout_headers")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 119 Column: 1

                  return parser


def mitmdump(opts):
    parser = argparse.ArgumentParser(usage="%(prog)s [options] [filter]")

    common_options(parser, opts)
    opts.make_parser(parser, "flow_detail", metavar = "LEVEL")
    parser.add_argument(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 135 Column: 1

                  return parser


def mitmweb(opts):
    parser = argparse.ArgumentParser(usage="%(prog)s [options]")

    group = parser.add_argument_group("Mitmweb")
    opts.make_parser(group, "web_open_browser")
    opts.make_parser(group, "web_port", metavar="PORT")

            

Reported by Pylint.