The following issues were found

test/mitmproxy/addons/test_save.py
39 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.test import taddons
from mitmproxy.test import tflow

from mitmproxy import io
from mitmproxy import exceptions
from mitmproxy.addons import save
from mitmproxy.addons import view

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.test import taddons
from mitmproxy.test import tflow

from mitmproxy import io
from mitmproxy import exceptions
from mitmproxy.addons import save
from mitmproxy.addons import view

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              from mitmproxy.addons import view


def test_configure(tmpdir):
    sa = save.Save()
    with taddons.context(sa) as tctx:
        with pytest.raises(exceptions.OptionsError):
            tctx.configure(sa, save_stream_file=str(tmpdir))
        with pytest.raises(Exception, match="Invalid filter"):

            

Reported by Pylint.

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

Line: 13 Column: 5

              

def test_configure(tmpdir):
    sa = save.Save()
    with taddons.context(sa) as tctx:
        with pytest.raises(exceptions.OptionsError):
            tctx.configure(sa, save_stream_file=str(tmpdir))
        with pytest.raises(Exception, match="Invalid filter"):
            tctx.configure(

            

Reported by Pylint.

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

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

                              sa, save_stream_file=str(tmpdir.join("foo")), save_stream_filter="~~"
            )
        tctx.configure(sa, save_stream_filter="foo")
        assert sa.filt
        tctx.configure(sa, save_stream_filter=None)
        assert not sa.filt


def rd(p):

            

Reported by Bandit.

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

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

                      tctx.configure(sa, save_stream_filter="foo")
        assert sa.filt
        tctx.configure(sa, save_stream_filter=None)
        assert not sa.filt


def rd(p):
    with open(p, "rb") as f:
        x = io.FlowReader(f)

            

Reported by Bandit.

Function name "rd" doesn't conform to snake_case naming style
Error

Line: 27 Column: 1

                      assert not sa.filt


def rd(p):
    with open(p, "rb") as f:
        x = io.FlowReader(f)
        return list(x.stream())



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                      assert not sa.filt


def rd(p):
    with open(p, "rb") as f:
        x = io.FlowReader(f)
        return list(x.stream())



            

Reported by Pylint.

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

Line: 27 Column: 1

                      assert not sa.filt


def rd(p):
    with open(p, "rb") as f:
        x = io.FlowReader(f)
        return list(x.stream())



            

Reported by Pylint.

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

Line: 28 Column: 27

              

def rd(p):
    with open(p, "rb") as f:
        x = io.FlowReader(f)
        return list(x.stream())


def test_tcp(tmpdir):

            

Reported by Pylint.

mitmproxy/tools/console/keybindings.py
39 issues
Unable to import 'urwid'
Error

Line: 1 Column: 1

              import urwid
import blinker
import textwrap
from mitmproxy.tools.console import layoutwidget
from mitmproxy.tools.console import signals

HELP_HEIGHT = 5



            

Reported by Pylint.

Unused argument 'size'
Error

Line: 35 Column: 24

                  def selectable(self):
        return True

    def keypress(self, size, key):
        return key


class KeyListWalker(urwid.ListWalker):
    def __init__(self, master):

            

Reported by Pylint.

Unused argument 'sender'
Error

Line: 49 Column: 28

                      self.set_focus(0)
        signals.keybindings_change.connect(self.sig_modified)

    def sig_modified(self, sender):
        self.bindings = list(self.master.keymap.list("all"))
        self.set_focus(min(self.index, len(self.bindings) - 1))
        self._modified()

    def get_edit_text(self):

            

Reported by Pylint.

Unused variable 'foc'
Error

Line: 98 Column: 13

              
    def keypress(self, size, key):
        if key == "m_select":
            foc, idx = self.get_focus()
            # Act here
        elif key == "m_start":
            self.set_focus(0)
            self.walker._modified()
        elif key == "m_end":

            

Reported by Pylint.

Unused variable 'idx'
Error

Line: 98 Column: 18

              
    def keypress(self, size, key):
        if key == "m_select":
            foc, idx = self.get_focus()
            # Act here
        elif key == "m_start":
            self.set_focus(0)
            self.walker._modified()
        elif key == "m_end":

            

Reported by Pylint.

Access to a protected member _modified of a client class
Error

Line: 102 Column: 13

                          # Act here
        elif key == "m_start":
            self.set_focus(0)
            self.walker._modified()
        elif key == "m_end":
            self.set_focus(len(self.walker.bindings) - 1)
            self.walker._modified()
        return super().keypress(size, key)


            

Reported by Pylint.

Access to a protected member _modified of a client class
Error

Line: 105 Column: 13

                          self.walker._modified()
        elif key == "m_end":
            self.set_focus(len(self.walker.bindings) - 1)
            self.walker._modified()
        return super().keypress(size, key)


class KeyHelp(urwid.Frame):
    def __init__(self, master):

            

Reported by Pylint.

Attribute 'focus_position' defined outside __init__
Error

Line: 153 Column: 13

              
    def keypress(self, size, key):
        if key == "m_next":
            self.focus_position = (
                self.focus_position + 1
            ) % len(self.widget_list)
            self.widget_list[1].set_active(self.focus_position == 1)
            key = None


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import urwid
import blinker
import textwrap
from mitmproxy.tools.console import layoutwidget
from mitmproxy.tools.console import signals

HELP_HEIGHT = 5



            

Reported by Pylint.

standard import "import textwrap" should be placed before "import urwid"
Error

Line: 3 Column: 1

              import urwid
import blinker
import textwrap
from mitmproxy.tools.console import layoutwidget
from mitmproxy.tools.console import signals

HELP_HEIGHT = 5



            

Reported by Pylint.

examples/contrib/webscanner_helper/test_urldict.py
38 issues
Unable to import 'mitmproxy.test'
Error

Line: 1 Column: 1

              from mitmproxy.test import tflow, tutils
from examples.contrib.webscanner_helper.urldict import URLDict

url = "http://10.10.10.10"
new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'

            

Reported by Pylint.

Unable to import 'examples.contrib.webscanner_helper.urldict'
Error

Line: 2 Column: 1

              from mitmproxy.test import tflow, tutils
from examples.contrib.webscanner_helper.urldict import URLDict

url = "http://10.10.10.10"
new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy.test import tflow, tutils
from examples.contrib.webscanner_helper.urldict import URLDict

url = "http://10.10.10.10"
new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'

            

Reported by Pylint.

Constant name "url" doesn't conform to UPPER_CASE naming style
Error

Line: 4 Column: 1

              from mitmproxy.test import tflow, tutils
from examples.contrib.webscanner_helper.urldict import URLDict

url = "http://10.10.10.10"
new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'

            

Reported by Pylint.

Constant name "new_content_body" doesn't conform to UPPER_CASE naming style
Error

Line: 5 Column: 1

              from examples.contrib.webscanner_helper.urldict import URLDict

url = "http://10.10.10.10"
new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'
input_file_content_error = f'{{"{url_error}": {content}}}'

            

Reported by Pylint.

Constant name "new_content_title" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              
url = "http://10.10.10.10"
new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'
input_file_content_error = f'{{"{url_error}": {content}}}'


            

Reported by Pylint.

Constant name "url_error" doesn't conform to UPPER_CASE naming style
Error

Line: 8 Column: 1

              new_content_body = "New Body"
new_content_title = "New Title"
content = f'{{"body": "{new_content_body}", "title": "{new_content_title}"}}'
url_error = "i~nvalid"
input_file_content = f'{{"{url}": {content}}}'
input_file_content_error = f'{{"{url_error}": {content}}}'


class TestUrlDict:

            

Reported by Pylint.

Missing class docstring
Error

Line: 13 Column: 1

              input_file_content_error = f'{{"{url_error}": {content}}}'


class TestUrlDict:

    def test_urldict_empty(self):
        urldict = URLDict()
        dump = urldict.dumps()
        assert dump == '{}'

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

              
class TestUrlDict:

    def test_urldict_empty(self):
        urldict = URLDict()
        dump = urldict.dumps()
        assert dump == '{}'

    def test_urldict_loads(self):

            

Reported by Pylint.

Method could be a function
Error

Line: 15 Column: 5

              
class TestUrlDict:

    def test_urldict_empty(self):
        urldict = URLDict()
        dump = urldict.dumps()
        assert dump == '{}'

    def test_urldict_loads(self):

            

Reported by Pylint.

mitmproxy/tools/console/consoleaddons.py
37 issues
Redefining name 'flow' from outer scope (line 9)
Error

Line: 310 Column: 25

                      self.master.switch_view("help")

    @command.command("console.view.flow")
    def view_flow(self, flow: flow.Flow) -> None:
        """View a flow."""
        if isinstance(flow, (http.HTTPFlow, tcp.TCPFlow)):
            self.master.switch_view("flowview")
        else:
            ctx.log.warn(f"No detail view for {type(flow).__name__}.")

            

Reported by Pylint.

Redefining name 'flow' from outer scope (line 9)
Error

Line: 332 Column: 24

              
    @command.command("console.bodyview")
    @command.argument("part", type=mitmproxy.types.Choice("console.bodyview.options"))
    def bodyview(self, flow: flow.Flow, part: str) -> None:
        """
            Spawn an external viewer for a flow request or response body based
            on the detected MIME type. We use the mailcap system to find the
            correct viewer, and fall back to the programs in $PAGER or $EDITOR
            if necessary.

            

Reported by Pylint.

Redefining name 'flow' from outer scope (line 9)
Error

Line: 360 Column: 9

                      """
            Possible components for console.edit.focus.
        """
        flow = self.master.view.focus.flow
        focus_options = []

        if type(flow) == tcp.TCPFlow:
            focus_options = ["tcp-message"]
        elif type(flow) == http.HTTPFlow:

            

Reported by Pylint.

Redefining name 'flow' from outer scope (line 9)
Error

Line: 391 Column: 9

                      """
            Edit a component of the currently focused flow.
        """
        flow = self.master.view.focus.flow
        # This shouldn't be necessary once this command is "console.edit @focus",
        # but for now it is.
        if not flow:
            raise exceptions.CommandError("No flow selected.")
        flow.backup()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import csv
import typing

import mitmproxy.types
from mitmproxy import command, command_lexer
from mitmproxy import contentviews
from mitmproxy import ctx
from mitmproxy import exceptions
from mitmproxy import flow

            

Reported by Pylint.

Too many public methods (49/20)
Error

Line: 45 Column: 1

              ]


class ConsoleAddon:
    """
        An addon that exposes console-specific commands, and hooks into required
        events.
    """


            

Reported by Pylint.

Method could be a function
Error

Line: 55 Column: 5

                      self.master = master
        self.started = False

    def load(self, loader):
        loader.add_option(
            "console_default_contentview", str, "auto",
            "The default content view mode.",
            choices=[i.name.lower() for i in contentviews.views]
        )

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 55 Column: 5

                      self.master = master
        self.started = False

    def load(self, loader):
        loader.add_option(
            "console_default_contentview", str, "auto",
            "The default content view mode.",
            choices=[i.name.lower() for i in contentviews.views]
        )

            

Reported by Pylint.

Method could be a function
Error

Line: 104 Column: 5

                      )

    @command.command("console.layout.options")
    def layout_options(self) -> typing.Sequence[str]:
        """
            Returns the available options for the console_layout option.
        """
        return ["single", "vertical", "horizontal"]


            

Reported by Pylint.

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

Line: 133 Column: 9

                      """
            Reset the current option in the options editor.
        """
        fv = self.master.window.current("options")
        if not fv:
            raise exceptions.CommandError("Not viewing options.")
        self.master.commands.call_strings("options.reset.one", [fv.current_name()])

    @command.command("console.nav.start")

            

Reported by Pylint.

test/mitmproxy/proxy/layers/http/test_http_version_interop.py
37 issues
Unable to import 'h2.config'
Error

Line: 3 Column: 1

              from typing import Tuple

import h2.config
import h2.connection
import h2.events

from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode

            

Reported by Pylint.

Unable to import 'h2.connection'
Error

Line: 4 Column: 1

              from typing import Tuple

import h2.config
import h2.connection
import h2.events

from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode

            

Reported by Pylint.

Unable to import 'h2.events'
Error

Line: 5 Column: 1

              
import h2.config
import h2.connection
import h2.events

from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData

            

Reported by Pylint.

Unable to import 'mitmproxy.http'
Error

Line: 7 Column: 1

              import h2.connection
import h2.events

from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived

            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.context'
Error

Line: 8 Column: 1

              import h2.events

from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers import http

            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.layers.http'
Error

Line: 9 Column: 1

              
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers import http
from test.mitmproxy.proxy.layers.http.hyper_h2_test_helpers import FrameFactory

            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.commands'
Error

Line: 10 Column: 1

              from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers import http
from test.mitmproxy.proxy.layers.http.hyper_h2_test_helpers import FrameFactory
from test.mitmproxy.proxy.layers.http.test_http2 import example_request_headers, example_response_headers, make_h2

            

Reported by Pylint.

Unable to import 'mitmproxy.connection'
Error

Line: 11 Column: 1

              from mitmproxy.proxy.context import Context
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers import http
from test.mitmproxy.proxy.layers.http.hyper_h2_test_helpers import FrameFactory
from test.mitmproxy.proxy.layers.http.test_http2 import example_request_headers, example_response_headers, make_h2
from test.mitmproxy.proxy.tutils import Placeholder, Playbook, reply

            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.events'
Error

Line: 12 Column: 1

              from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers import http
from test.mitmproxy.proxy.layers.http.hyper_h2_test_helpers import FrameFactory
from test.mitmproxy.proxy.layers.http.test_http2 import example_request_headers, example_response_headers, make_h2
from test.mitmproxy.proxy.tutils import Placeholder, Playbook, reply


            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.layers'
Error

Line: 13 Column: 1

              from mitmproxy.proxy.commands import CloseConnection, OpenConnection, SendData
from mitmproxy.connection import Server
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers import http
from test.mitmproxy.proxy.layers.http.hyper_h2_test_helpers import FrameFactory
from test.mitmproxy.proxy.layers.http.test_http2 import example_request_headers, example_response_headers, make_h2
from test.mitmproxy.proxy.tutils import Placeholder, Playbook, reply

h2f = FrameFactory()

            

Reported by Pylint.

mitmproxy/tools/console/grideditor/editors.py
36 issues
Unable to import 'urwid'
Error

Line: 1 Column: 1

              import urwid
import typing

from mitmproxy import exceptions
from mitmproxy.http import Headers
from mitmproxy.tools.console import layoutwidget
from mitmproxy.tools.console import signals
from mitmproxy.tools.console.grideditor import base
from mitmproxy.tools.console.grideditor import col_bytes

            

Reported by Pylint.

An attribute defined in mitmproxy.tools.console.grideditor.base line 275 hides this method
Error

Line: 197 Column: 5

                      self.name = name
        super().__init__(master, [[i] for i in vals], self.callback)

    def callback(self, vals):
        try:
            setattr(self.master.options, self.name, [i[0] for i in vals])
        except exceptions.OptionsError as v:
            signals.status_message.send(message=str(v))


            

Reported by Pylint.

An attribute defined in mitmproxy.tools.console.grideditor.base line 275 hides this method
Error

Line: 228 Column: 5

                          self.columns = [col_viewany.Column("")] * len(vals[0])
        super().__init__(master, vals, self.callback)

    def callback(self, vals):
        pass

    def is_error(self, col, val):
        pass

            

Reported by Pylint.

TODO: Next row on enter?
Error

Line: 87 Column: 3

              

class PathEditor(base.FocusEditor):
    # TODO: Next row on enter?
    title = "Edit Path Components"
    columns = [
        col_text.Column("Component"),
    ]


            

Reported by Pylint.

Unused argument 'prev'
Error

Line: 140 Column: 29

                              ret.append(i)
        return ret

    def layout_pushed(self, prev):
        if self.grideditor.master.view.focus.flow:
            self._w = base.BaseGridEditor(
                self.grideditor.master,
                self.title,
                self.columns,

            

Reported by Pylint.

Attribute '_w' defined outside __init__
Error

Line: 142 Column: 13

              
    def layout_pushed(self, prev):
        if self.grideditor.master.view.focus.flow:
            self._w = base.BaseGridEditor(
                self.grideditor.master,
                self.title,
                self.columns,
                self.grideditor.walker.get_current_value(),
                self.grideditor.set_subeditor_value,

            

Reported by Pylint.

Attribute '_w' defined outside __init__
Error

Line: 152 Column: 13

                              self.grideditor.walker.focus_col
            )
        else:
            self._w = urwid.Pile([])


class SetCookieEditor(base.FocusEditor):
    title = "Edit SetCookie Header"
    columns = [

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import urwid
import typing

from mitmproxy import exceptions
from mitmproxy.http import Headers
from mitmproxy.tools.console import layoutwidget
from mitmproxy.tools.console import signals
from mitmproxy.tools.console.grideditor import base
from mitmproxy.tools.console.grideditor import col_bytes

            

Reported by Pylint.

standard import "import typing" should be placed before "import urwid"
Error

Line: 2 Column: 1

              import urwid
import typing

from mitmproxy import exceptions
from mitmproxy.http import Headers
from mitmproxy.tools.console import layoutwidget
from mitmproxy.tools.console import signals
from mitmproxy.tools.console.grideditor import base
from mitmproxy.tools.console.grideditor import col_bytes

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

              from mitmproxy.tools.console.grideditor import col_viewany


class QueryEditor(base.FocusEditor):
    title = "Edit Query"
    columns = [
        col_text.Column("Key"),
        col_text.Column("Value")
    ]

            

Reported by Pylint.

mitmproxy/contrib/kaitaistruct/tls_client_hello.py
36 issues
Unable to import 'kaitaistruct'
Error

Line: 9 Column: 1

              from enum import Enum
from pkg_resources import parse_version

from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO

if parse_version(ks_version) < parse_version('0.7'):
    raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))



            

Reported by Pylint.

Unused import array
Error

Line: 3 Column: 1

              # This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import array
import struct
import zlib
from enum import Enum
from pkg_resources import parse_version

from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO

            

Reported by Pylint.

Unused import struct
Error

Line: 4 Column: 1

              # This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import array
import struct
import zlib
from enum import Enum
from pkg_resources import parse_version

from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO

            

Reported by Pylint.

Unused import zlib
Error

Line: 5 Column: 1

              
import array
import struct
import zlib
from enum import Enum
from pkg_resources import parse_version

from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO


            

Reported by Pylint.

Unused Enum imported from enum
Error

Line: 6 Column: 1

              import array
import struct
import zlib
from enum import Enum
from pkg_resources import parse_version

from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO

if parse_version(ks_version) < parse_version('0.7'):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import array
import struct
import zlib
from enum import Enum
from pkg_resources import parse_version

from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO

            

Reported by Pylint.

Line too long (118/100)
Error

Line: 12 Column: 1

              from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO

if parse_version(ks_version) < parse_version('0.7'):
    raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))


class TlsClientHello(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io

            

Reported by Pylint.

Too many instance attributes (9/7)
Error

Line: 15 Column: 1

                  raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))


class TlsClientHello(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self
        self.version = self._root.Version(self._io, self, self._root)

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 15 Column: 1

                  raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))


class TlsClientHello(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self
        self.version = self._root.Version(self._io, self, self._root)

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

                  raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))


class TlsClientHello(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self
        self.version = self._root.Version(self._io, self, self._root)

            

Reported by Pylint.

mitmproxy/io/compat.py
36 issues
Missing function or method docstring
Error

Line: 15 Column: 1

              from mitmproxy.utils import strutils


def convert_011_012(data):
    data[b"version"] = (0, 12)
    return data


def convert_012_013(data):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                  return data


def convert_012_013(data):
    data[b"version"] = (0, 13)
    return data


def convert_013_014(data):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 1

                  return data


def convert_013_014(data):
    data[b"request"][b"first_line_format"] = data[b"request"].pop(b"form_in")
    data[b"request"][b"http_version"] = b"HTTP/" + ".".join(
        str(x) for x in data[b"request"].pop(b"httpversion")).encode()
    data[b"response"][b"http_version"] = b"HTTP/" + ".".join(
        str(x) for x in data[b"response"].pop(b"httpversion")).encode()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 39 Column: 1

                  return data


def convert_014_015(data):
    data[b"version"] = (0, 15)
    return data


def convert_015_016(data):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 44 Column: 1

                  return data


def convert_015_016(data):
    for m in (b"request", b"response"):
        if b"body" in data[m]:
            data[m][b"content"] = data[m].pop(b"body")
    if b"msg" in data[b"response"]:
        data[b"response"][b"reason"] = data[b"response"].pop(b"msg")

            

Reported by Pylint.

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

Line: 45 Column: 9

              

def convert_015_016(data):
    for m in (b"request", b"response"):
        if b"body" in data[m]:
            data[m][b"content"] = data[m].pop(b"body")
    if b"msg" in data[b"response"]:
        data[b"response"][b"reason"] = data[b"response"].pop(b"msg")
    data[b"request"].pop(b"form_out", None)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 55 Column: 1

                  return data


def convert_016_017(data):
    data[b"server_conn"][b"peer_address"] = None
    data[b"version"] = (0, 17)
    return data



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 61 Column: 1

                  return data


def convert_017_018(data):
    # convert_unicode needs to be called for every dual release and the first py3-only release
    data = convert_unicode(data)

    data["server_conn"]["ip_address"] = data["server_conn"].pop("peer_address", None)
    data["marked"] = False

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 71 Column: 1

                  return data


def convert_018_019(data):
    # convert_unicode needs to be called for every dual release and the first py3-only release
    data = convert_unicode(data)

    data["request"].pop("stickyauth", None)
    data["request"].pop("stickycookie", None)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 90 Column: 1

                  return data


def convert_019_100(data):
    # convert_unicode needs to be called for every dual release and the first py3-only release
    data = convert_unicode(data)

    data["version"] = (1, 0, 0)
    return data

            

Reported by Pylint.

test/mitmproxy/net/test_tls.py
36 issues
Missing module docstring
Error

Line: 1 Column: 1

              from pathlib import Path

from OpenSSL import SSL
from mitmproxy import certs
from mitmproxy.net import tls

CLIENT_HELLO_NO_EXTENSIONS = bytes.fromhex(
    "03015658a756ab2c2bff55f636814deac086b7ca56b65058c7893ffc6074f5245f70205658a75475103a152637"
    "78e1bb6d22e8bbd5b6b0a3a59760ad354e91ba20d353001a0035002f000a000500040009000300060008006000"

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              )


def test_make_master_secret_logger():
    assert tls.make_master_secret_logger(None) is None
    assert isinstance(tls.make_master_secret_logger("filepath"), tls.MasterSecretLogger)


def test_sslkeylogfile(tdata, monkeypatch):

            

Reported by Pylint.

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

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

              

def test_make_master_secret_logger():
    assert tls.make_master_secret_logger(None) is None
    assert isinstance(tls.make_master_secret_logger("filepath"), tls.MasterSecretLogger)


def test_sslkeylogfile(tdata, monkeypatch):
    keylog = []

            

Reported by Bandit.

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

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

              
def test_make_master_secret_logger():
    assert tls.make_master_secret_logger(None) is None
    assert isinstance(tls.make_master_secret_logger("filepath"), tls.MasterSecretLogger)


def test_sslkeylogfile(tdata, monkeypatch):
    keylog = []
    monkeypatch.setattr(tls, "log_master_secret", lambda conn, secrets: keylog.append(secrets))

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 24 Column: 1

                  assert isinstance(tls.make_master_secret_logger("filepath"), tls.MasterSecretLogger)


def test_sslkeylogfile(tdata, monkeypatch):
    keylog = []
    monkeypatch.setattr(tls, "log_master_secret", lambda conn, secrets: keylog.append(secrets))

    store = certs.CertStore.from_files(
        Path(tdata.path("mitmproxy/net/data/verificationcerts/trusted-root.pem")),

            

Reported by Pylint.

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

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

                          break
        read, write = write, read

    assert keylog
    assert keylog[0].startswith(b"SERVER_HANDSHAKE_TRAFFIC_SECRET")


def test_is_record_magic():
    assert not tls.is_tls_record_magic(b"POST /")

            

Reported by Bandit.

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

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

                      read, write = write, read

    assert keylog
    assert keylog[0].startswith(b"SERVER_HANDSHAKE_TRAFFIC_SECRET")


def test_is_record_magic():
    assert not tls.is_tls_record_magic(b"POST /")
    assert not tls.is_tls_record_magic(b"\x16\x03")

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 79 Column: 1

                  assert keylog[0].startswith(b"SERVER_HANDSHAKE_TRAFFIC_SECRET")


def test_is_record_magic():
    assert not tls.is_tls_record_magic(b"POST /")
    assert not tls.is_tls_record_magic(b"\x16\x03")
    assert not tls.is_tls_record_magic(b"\x16\x03\x04")
    assert tls.is_tls_record_magic(b"\x16\x03\x00")
    assert tls.is_tls_record_magic(b"\x16\x03\x01")

            

Reported by Pylint.

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

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

              

def test_is_record_magic():
    assert not tls.is_tls_record_magic(b"POST /")
    assert not tls.is_tls_record_magic(b"\x16\x03")
    assert not tls.is_tls_record_magic(b"\x16\x03\x04")
    assert tls.is_tls_record_magic(b"\x16\x03\x00")
    assert tls.is_tls_record_magic(b"\x16\x03\x01")
    assert tls.is_tls_record_magic(b"\x16\x03\x02")

            

Reported by Bandit.

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

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

              
def test_is_record_magic():
    assert not tls.is_tls_record_magic(b"POST /")
    assert not tls.is_tls_record_magic(b"\x16\x03")
    assert not tls.is_tls_record_magic(b"\x16\x03\x04")
    assert tls.is_tls_record_magic(b"\x16\x03\x00")
    assert tls.is_tls_record_magic(b"\x16\x03\x01")
    assert tls.is_tls_record_magic(b"\x16\x03\x02")
    assert tls.is_tls_record_magic(b"\x16\x03\x03")

            

Reported by Bandit.

examples/contrib/test_har_dump.py
35 issues
Unable to import 'mitmproxy.test'
Error

Line: 3 Column: 1

              import json

from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy.net.http import cookies


class TestHARDump:

            

Reported by Pylint.

Unable to import 'mitmproxy.test'
Error

Line: 4 Column: 1

              import json

from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy.net.http import cookies


class TestHARDump:

            

Reported by Pylint.

Unable to import 'mitmproxy.test'
Error

Line: 5 Column: 1

              
from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy.net.http import cookies


class TestHARDump:
    def flow(self, resp_content=b'message'):

            

Reported by Pylint.

Unable to import 'mitmproxy.net.http'
Error

Line: 6 Column: 1

              from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy.net.http import cookies


class TestHARDump:
    def flow(self, resp_content=b'message'):
        times = dict(

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import json

from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy.net.http import cookies


class TestHARDump:

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from mitmproxy.net.http import cookies


class TestHARDump:
    def flow(self, resp_content=b'message'):
        times = dict(
            timestamp_start=746203272,
            timestamp_end=746203272,
        )

            

Reported by Pylint.

Method could be a function
Error

Line: 10 Column: 5

              

class TestHARDump:
    def flow(self, resp_content=b'message'):
        times = dict(
            timestamp_start=746203272,
            timestamp_end=746203272,
        )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 5

              

class TestHARDump:
    def flow(self, resp_content=b'message'):
        times = dict(
            timestamp_start=746203272,
            timestamp_end=746203272,
        )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 5

                          resp=tutils.tresp(content=resp_content, **times)
        )

    def test_simple(self, tmpdir, tdata):
        # context is needed to provide ctx.log function that
        # is invoked if there are exceptions
        with taddons.context() as tctx:
            a = tctx.script(tdata.path("../examples/contrib/har_dump.py"))
            # check script is read without errors

            

Reported by Pylint.

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

Line: 26 Column: 13

                      # context is needed to provide ctx.log function that
        # is invoked if there are exceptions
        with taddons.context() as tctx:
            a = tctx.script(tdata.path("../examples/contrib/har_dump.py"))
            # check script is read without errors
            assert tctx.master.logs == []
            assert a.name_value   # last function in har_dump.py

            path = str(tmpdir.join("somefile"))

            

Reported by Pylint.