The following issues were found

test/mitmproxy/addons/test_stickycookie.py
57 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

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

from mitmproxy.addons import stickycookie
from mitmproxy.test import tutils as ntutils



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

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

from mitmproxy.addons import stickycookie
from mitmproxy.test import tutils as ntutils



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              from mitmproxy.test import tutils as ntutils


def test_domain_match():
    assert stickycookie.domain_match("www.google.com", ".google.com")
    assert stickycookie.domain_match("google.com", ".google.com")


class TestStickyCookie:

            

Reported by Pylint.

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

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

              

def test_domain_match():
    assert stickycookie.domain_match("www.google.com", ".google.com")
    assert stickycookie.domain_match("google.com", ".google.com")


class TestStickyCookie:
    def test_config(self):

            

Reported by Bandit.

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

              
def test_domain_match():
    assert stickycookie.domain_match("www.google.com", ".google.com")
    assert stickycookie.domain_match("google.com", ".google.com")


class TestStickyCookie:
    def test_config(self):
        sc = stickycookie.StickyCookie()

            

Reported by Bandit.

Missing class docstring
Error

Line: 15 Column: 1

                  assert stickycookie.domain_match("google.com", ".google.com")


class TestStickyCookie:
    def test_config(self):
        sc = stickycookie.StickyCookie()
        with taddons.context(sc) as tctx:
            with pytest.raises(Exception, match="invalid filter"):
                tctx.configure(sc, stickycookie="~b")

            

Reported by Pylint.

Method could be a function
Error

Line: 16 Column: 5

              

class TestStickyCookie:
    def test_config(self):
        sc = stickycookie.StickyCookie()
        with taddons.context(sc) as tctx:
            with pytest.raises(Exception, match="invalid filter"):
                tctx.configure(sc, stickycookie="~b")


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 5

              

class TestStickyCookie:
    def test_config(self):
        sc = stickycookie.StickyCookie()
        with taddons.context(sc) as tctx:
            with pytest.raises(Exception, match="invalid filter"):
                tctx.configure(sc, stickycookie="~b")


            

Reported by Pylint.

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

Line: 17 Column: 9

              
class TestStickyCookie:
    def test_config(self):
        sc = stickycookie.StickyCookie()
        with taddons.context(sc) as tctx:
            with pytest.raises(Exception, match="invalid filter"):
                tctx.configure(sc, stickycookie="~b")

            tctx.configure(sc, stickycookie="foo")

            

Reported by Pylint.

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

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

                              tctx.configure(sc, stickycookie="~b")

            tctx.configure(sc, stickycookie="foo")
            assert sc.flt
            tctx.configure(sc, stickycookie=None)
            assert not sc.flt

    def test_simple(self):
        sc = stickycookie.StickyCookie()

            

Reported by Bandit.

test/mitmproxy/proxy/layers/test_modes.py
56 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              import copy

import pytest

from mitmproxy import platform
from mitmproxy.connection import Client, Server
from mitmproxy.proxy.commands import CloseConnection, GetSocket, Log, OpenConnection, SendData
from mitmproxy.proxy.context import Context
from mitmproxy.proxy.events import ConnectionClosed, DataReceived

            

Reported by Pylint.

Expression "playbook << OpenConnection(tctx.server) >> DataReceived(tctx.client, b'\x01\x02\x03') >> reply(None, to=OpenConnection(tctx.server))" is assigned to nothing
Error

Line: 153 Column: 9

                  tctx.options.connection_strategy = connection_strategy
    playbook = Playbook(modes.ReverseProxy(tctx))
    if connection_strategy == "eager":
        (
            playbook
            << OpenConnection(tctx.server)
            >> DataReceived(tctx.client, b"\x01\x02\x03")
            >> reply(None, to=OpenConnection(tctx.server))
        )

            

Reported by Pylint.

Expression "playbook >> DataReceived(tctx.client, b'\x01\x02\x03')" is assigned to nothing
Error

Line: 160 Column: 9

                          >> reply(None, to=OpenConnection(tctx.server))
        )
    else:
        (
            playbook
            >> DataReceived(tctx.client, b"\x01\x02\x03")
        )
    if patch:
        (

            

Reported by Pylint.

Expression "playbook << NextLayerHook(Placeholder(NextLayer)) >> reply_next_layer(tcp.TCPLayer) << TcpStartHook(flow) >> reply()" is assigned to nothing
Error

Line: 165 Column: 9

                          >> DataReceived(tctx.client, b"\x01\x02\x03")
        )
    if patch:
        (
            playbook
            << NextLayerHook(Placeholder(NextLayer))
            >> reply_next_layer(tcp.TCPLayer)
            << TcpStartHook(flow)
            >> reply()

            

Reported by Pylint.

Expression "playbook << OpenConnection(tctx.server) >> reply(None)" is assigned to nothing
Error

Line: 173 Column: 13

                          >> reply()
        )
        if connection_strategy == "lazy":
            (
                playbook
                << OpenConnection(tctx.server)
                >> reply(None)
            )
        assert (

            

Reported by Pylint.

Expression "playbook << NextLayerHook(Placeholder(NextLayer)) >> reply_next_layer(tcp.TCPLayer) << TcpStartHook(flow) >> reply() << OpenConnection(tctx.server) >> reply(None)" is assigned to nothing
Error

Line: 187 Column: 13

                      assert data() == b"\x01\x02\x03"
    else:
        if connection_strategy == "lazy":
            (
                playbook
                << NextLayerHook(Placeholder(NextLayer))
                >> reply_next_layer(tcp.TCPLayer)
                << TcpStartHook(flow)
                >> reply()

            

Reported by Pylint.

Expression "playbook << GetSocket(tctx.client) >> reply(sock)" is assigned to nothing
Error

Line: 214 Column: 5

              
    sock = object()
    playbook = Playbook(modes.TransparentProxy(tctx))
    (
        playbook
        << GetSocket(tctx.client)
        >> reply(sock)
    )
    if connection_strategy == "lazy":

            

Reported by Pylint.

Expression "playbook >> DataReceived(tctx.client, bytes([x]))" is assigned to nothing
Error

Line: 323 Column: 9

                  tctx.options.connection_strategy = "lazy"
    playbook = Playbook(modes.Socks5Proxy(tctx))
    for x in CLIENT_HELLO:
        playbook >> DataReceived(tctx.client, bytes([x]))
    playbook << SendData(tctx.client, b"\x05\x00")
    for x in b"\x05\x01\x00\x01\x7f\x00\x00\x01\x12\x34":
        playbook >> DataReceived(tctx.client, bytes([x]))
    assert playbook << SendData(tctx.client, b"\x05\x00\x00\x01\x00\x00\x00\x00\x00\x00")


            

Reported by Pylint.

Expression "playbook << SendData(tctx.client, b'\x05\x00')" is assigned to nothing
Error

Line: 324 Column: 5

                  playbook = Playbook(modes.Socks5Proxy(tctx))
    for x in CLIENT_HELLO:
        playbook >> DataReceived(tctx.client, bytes([x]))
    playbook << SendData(tctx.client, b"\x05\x00")
    for x in b"\x05\x01\x00\x01\x7f\x00\x00\x01\x12\x34":
        playbook >> DataReceived(tctx.client, bytes([x]))
    assert playbook << SendData(tctx.client, b"\x05\x00\x00\x01\x00\x00\x00\x00\x00\x00")



            

Reported by Pylint.

Expression "playbook >> DataReceived(tctx.client, bytes([x]))" is assigned to nothing
Error

Line: 326 Column: 9

                      playbook >> DataReceived(tctx.client, bytes([x]))
    playbook << SendData(tctx.client, b"\x05\x00")
    for x in b"\x05\x01\x00\x01\x7f\x00\x00\x01\x12\x34":
        playbook >> DataReceived(tctx.client, bytes([x]))
    assert playbook << SendData(tctx.client, b"\x05\x00\x00\x01\x00\x00\x00\x00\x00\x00")


@pytest.mark.parametrize("data,err,msg", [
    (b"GET / HTTP/1.1",

            

Reported by Pylint.

test/mitmproxy/test_connection.py
55 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.connection import Server, Client, ConnectionState
from mitmproxy.test.tflow import tclient_conn, tserver_conn


class TestConnection:
    def test_basic(self):
        c = Client(

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.connection import Server, Client, ConnectionState
from mitmproxy.test.tflow import tclient_conn, tserver_conn


class TestConnection:
    def test_basic(self):
        c = Client(

            

Reported by Pylint.

Missing class docstring
Error

Line: 7 Column: 1

              from mitmproxy.test.tflow import tclient_conn, tserver_conn


class TestConnection:
    def test_basic(self):
        c = Client(
            ("127.0.0.1", 52314),
            ("127.0.0.1", 8080),
            1607780791

            

Reported by Pylint.

Method could be a function
Error

Line: 8 Column: 5

              

class TestConnection:
    def test_basic(self):
        c = Client(
            ("127.0.0.1", 52314),
            ("127.0.0.1", 8080),
            1607780791
        )

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 5

              

class TestConnection:
    def test_basic(self):
        c = Client(
            ("127.0.0.1", 52314),
            ("127.0.0.1", 8080),
            1607780791
        )

            

Reported by Pylint.

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

Line: 9 Column: 9

              
class TestConnection:
    def test_basic(self):
        c = Client(
            ("127.0.0.1", 52314),
            ("127.0.0.1", 8080),
            1607780791
        )
        assert not c.tls_established

            

Reported by Pylint.

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

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

                          ("127.0.0.1", 8080),
            1607780791
        )
        assert not c.tls_established
        c.timestamp_tls_setup = 1607780792
        assert c.tls_established
        assert c.connected
        c.state = ConnectionState.CAN_WRITE
        assert not c.connected

            

Reported by Bandit.

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

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

                      )
        assert not c.tls_established
        c.timestamp_tls_setup = 1607780792
        assert c.tls_established
        assert c.connected
        c.state = ConnectionState.CAN_WRITE
        assert not c.connected

    def test_eq(self):

            

Reported by Bandit.

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

                      assert not c.tls_established
        c.timestamp_tls_setup = 1607780792
        assert c.tls_established
        assert c.connected
        c.state = ConnectionState.CAN_WRITE
        assert not c.connected

    def test_eq(self):
        c = tclient_conn()

            

Reported by Bandit.

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

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

                      assert c.tls_established
        assert c.connected
        c.state = ConnectionState.CAN_WRITE
        assert not c.connected

    def test_eq(self):
        c = tclient_conn()
        c2 = c.copy()
        assert c == c

            

Reported by Bandit.

test/mitmproxy/addons/test_modifyheaders.py
54 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.addons.modifyheaders import parse_modify_spec, ModifyHeaders
from mitmproxy.test import taddons
from mitmproxy.test import tflow


def test_parse_modify_spec():
    spec = parse_modify_spec("/foo/bar/voing", True)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy.addons.modifyheaders import parse_modify_spec, ModifyHeaders
from mitmproxy.test import taddons
from mitmproxy.test import tflow


def test_parse_modify_spec():
    spec = parse_modify_spec("/foo/bar/voing", True)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              from mitmproxy.test import tflow


def test_parse_modify_spec():
    spec = parse_modify_spec("/foo/bar/voing", True)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"


            

Reported by Pylint.

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

              
def test_parse_modify_spec():
    spec = parse_modify_spec("/foo/bar/voing", True)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

    spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"

            

Reported by Bandit.

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

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

              def test_parse_modify_spec():
    spec = parse_modify_spec("/foo/bar/voing", True)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

    spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"

            

Reported by Bandit.

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

                  spec = parse_modify_spec("/foo/bar/voing", True)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

    spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"vo/ing/"

            

Reported by Bandit.

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

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

                  assert spec.read_replacement() == b"voing"

    spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"vo/ing/"

    spec = parse_modify_spec("/bar/voing", False)
    assert spec.matches(tflow.tflow())

            

Reported by Bandit.

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

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

              
    spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"vo/ing/"

    spec = parse_modify_spec("/bar/voing", False)
    assert spec.matches(tflow.tflow())
    assert spec.subject == b"bar"

            

Reported by Bandit.

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

                  spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"vo/ing/"

    spec = parse_modify_spec("/bar/voing", False)
    assert spec.matches(tflow.tflow())
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

            

Reported by Bandit.

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

                  assert spec.read_replacement() == b"vo/ing/"

    spec = parse_modify_spec("/bar/voing", False)
    assert spec.matches(tflow.tflow())
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

    with pytest.raises(ValueError, match="Invalid regular expression"):
        parse_modify_spec("/[/two", True)

            

Reported by Bandit.

mitmproxy/tools/console/flowview.py
54 issues
Unable to import 'urwid'
Error

Line: 8 Column: 1

              
import mitmproxy.flow
import mitmproxy.tools.console.master  # noqa
import urwid
from mitmproxy import contentviews
from mitmproxy import ctx
from mitmproxy import http
from mitmproxy import tcp
from mitmproxy.tools.console import common

            

Reported by Pylint.

Unused Optional imported from typing
Error

Line: 4 Column: 1

              import math
import sys
from functools import lru_cache
from typing import Optional, Union  # noqa

import mitmproxy.flow
import mitmproxy.tools.console.master  # noqa
import urwid
from mitmproxy import contentviews

            

Reported by Pylint.

Unused Union imported from typing
Error

Line: 4 Column: 1

              import math
import sys
from functools import lru_cache
from typing import Optional, Union  # noqa

import mitmproxy.flow
import mitmproxy.tools.console.master  # noqa
import urwid
from mitmproxy import contentviews

            

Reported by Pylint.

Unused variable 'cols'
Error

Line: 35 Column: 9

                      self.focus_changed()

    def focus_changed(self):
        cols, _ = self.master.ui.get_cols_rows()
        if self.master.view.focus.flow:
            self._w = common.format_flow(
                self.master.view.focus.flow,
                render_mode=common.RenderMode.DETAILVIEW,
                hostheader=self.master.options.showhost,

            

Reported by Pylint.

Attribute '_get_content_view_message' defined outside __init__
Error

Line: 246 Column: 13

                              getattr(message, "path", None),
            ))
            # we need to pass the message off-band because it's not hashable
            self._get_content_view_message = message
            return self._get_content_view(viewmode, limit, flow_modify_cache_invalidation)

    @lru_cache(maxsize=200)
    def _get_content_view(self, viewmode, max_lines, _):
        message = self._get_content_view_message

            

Reported by Pylint.

Attribute '_get_content_view_message' defined outside __init__
Error

Line: 252 Column: 9

                  @lru_cache(maxsize=200)
    def _get_content_view(self, viewmode, max_lines, _):
        message = self._get_content_view_message
        self._get_content_view_message = None
        description, lines, error = contentviews.get_message_content_view(
            viewmode, message, self.flow
        )
        if error:
            self.master.log.debug(error)

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 367 Column: 1

                      )
        self.master = master

    def focus_changed(self, *args, **kwargs):
        self.body.focus_changed()
        self.header.focus_changed()

            

Reported by Pylint.

Unused argument 'args'
Error

Line: 367 Column: 1

                      )
        self.master = master

    def focus_changed(self, *args, **kwargs):
        self.body.focus_changed()
        self.header.focus_changed()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import math
import sys
from functools import lru_cache
from typing import Optional, Union  # noqa

import mitmproxy.flow
import mitmproxy.tools.console.master  # noqa
import urwid
from mitmproxy import contentviews

            

Reported by Pylint.

Missing class docstring
Error

Line: 21 Column: 1

              from mitmproxy.utils import strutils


class SearchError(Exception):
    pass


class FlowViewHeader(urwid.WidgetWrap):


            

Reported by Pylint.

test/mitmproxy/proxy/tutils.py
54 issues
Consider explicitly re-raising using the 'from' keyword
Error

Line: 42 Column: 17

                          try:
                x = x.setdefault(y)
            except TypeError as e:
                raise TypeError(f"Placeholder type error for {type(a).__name__}.{k}: {e}")
        if x != y:
            return False

    return True


            

Reported by Pylint.

Redefining name 'layer' from outer scope (line 8)
Error

Line: 134 Column: 13

              
    def __init__(
            self,
            layer: Layer,
            hooks: bool = True,
            logs: bool = False,
            expected: typing.Optional[PlaybookEntryList] = None,
    ):
        if expected is None:

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 188 Column: 28

                              if hasattr(x, "playbook_eval"):
                    try:
                        x = self.expected[i] = x.playbook_eval(self)
                    except Exception:
                        self.actual.append(_TracebackInPlaybook(traceback.format_exc()))
                        break
                for name, value in vars(x).items():
                    if isinstance(value, _Placeholder):
                        setattr(x, name, value())

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 204 Column: 24

                              self.actual.append(x)
                try:
                    cmds: typing.List[commands.Command] = list(self.layer.handle_event(x))
                except Exception:
                    self.actual.append(_TracebackInPlaybook(traceback.format_exc()))
                    break

                cmds = list(_merge_sends(cmds, ignore_hooks=not self.hooks, ignore_logs=not self.logs))


            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 319 Column: 13

                      try:
            inst = reply_cls(self.to, *self.args)
        except TypeError as e:
            raise ValueError(f"Cannot instantiate {reply_cls.__name__}: {e}")
        return inst


T = typing.TypeVar("T")


            

Reported by Pylint.

Redefining name 'context' from outer scope (line 8)
Error

Line: 382 Column: 24

                  """Layer that records all events but does nothing."""
    event_log: typing.List[events.Event]

    def __init__(self, context: context.Context) -> None:
        super().__init__(context)
        self.event_log = []

    def _handle_event(self, event: events.Event) -> layer.CommandGenerator[None]:
        self.event_log.append(event)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import collections.abc
import difflib
import itertools
import re
import traceback
import typing

from mitmproxy.proxy import commands, context, layer
from mitmproxy.proxy import events

            

Reported by Pylint.

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

Line: 18 Column: 1

              PlaybookEntryList = typing.List[PlaybookEntry]


def _eq(
        a: PlaybookEntry,
        b: PlaybookEntry
) -> bool:
    """Compare two commands/events, and possibly update placeholders."""
    if type(a) != type(b):

            

Reported by Pylint.

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

Line: 18 Column: 1

              PlaybookEntryList = typing.List[PlaybookEntry]


def _eq(
        a: PlaybookEntry,
        b: PlaybookEntry
) -> bool:
    """Compare two commands/events, and possibly update placeholders."""
    if type(a) != type(b):

            

Reported by Pylint.

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

Line: 23 Column: 8

                      b: PlaybookEntry
) -> bool:
    """Compare two commands/events, and possibly update placeholders."""
    if type(a) != type(b):
        return False

    a_dict = a.__dict__
    b_dict = b.__dict__
    # we can assume a.keys() == b.keys()

            

Reported by Pylint.

test/mitmproxy/proxy/layers/http/test_http1.py
51 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import http
from mitmproxy.proxy.commands import SendData
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook


            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 3 Column: 1

              import pytest

from mitmproxy import http
from mitmproxy.proxy.commands import SendData
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook


            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.commands'
Error

Line: 4 Column: 1

              import pytest

from mitmproxy import http
from mitmproxy.proxy.commands import SendData
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook


            

Reported by Pylint.

Unable to import 'mitmproxy.proxy.events'
Error

Line: 5 Column: 1

              
from mitmproxy import http
from mitmproxy.proxy.commands import SendData
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook



            

Reported by Pylint.

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

Line: 6 Column: 1

              from mitmproxy import http
from mitmproxy.proxy.commands import SendData
from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook


class TestServer:

            

Reported by Pylint.

Unable to import 'test.mitmproxy.proxy.tutils'
Error

Line: 8 Column: 1

              from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook


class TestServer:
    @pytest.mark.parametrize("pipeline", ["pipeline", None])
    def test_simple(self, tctx, pipeline):

            

Reported by Pylint.

No name 'mitmproxy' in module 'test'
Error

Line: 8 Column: 1

              from mitmproxy.proxy.events import DataReceived
from mitmproxy.proxy.layers.http import Http1Server, ReceiveHttp, RequestHeaders, RequestEndOfMessage, \
    ResponseHeaders, ResponseEndOfMessage, RequestData, Http1Client, ResponseData
from test.mitmproxy.proxy.tutils import Placeholder, Playbook


class TestServer:
    @pytest.mark.parametrize("pipeline", ["pipeline", None])
    def test_simple(self, tctx, pipeline):

            

Reported by Pylint.

Expression "playbook >> DataReceived(tctx.client, b'POST http://example.com/one HTTP/1.1\r\nContent-Length: 3\r\n\r\nabc' + (req2 if pipeline else b'')) << ReceiveHttp(hdrs1) << ReceiveHttp(RequestData(1, b'abc')) << ReceiveHttp(RequestEndOfMessage(1)) >> ResponseHeaders(1, http.Response.make(200)) << SendData(tctx.client, b'HTTP/1.1 200 OK\r\ncontent-length: 0\r\n\r\n') >> ResponseEndOfMessage(1)" is assigned to nothing
Error

Line: 22 Column: 9

                          b"\r\n"
        )
        playbook = Playbook(Http1Server(tctx))
        (
                playbook
                >> DataReceived(tctx.client,
                                b"POST http://example.com/one HTTP/1.1\r\n"
                                b"Content-Length: 3\r\n"
                                b"\r\n"

            

Reported by Pylint.

Expression "playbook >> DataReceived(tctx.client, req2)" is assigned to nothing
Error

Line: 38 Column: 13

                              >> ResponseEndOfMessage(1)
        )
        if not pipeline:
            playbook >> DataReceived(tctx.client, req2)
        assert (
                playbook
                << ReceiveHttp(hdrs2)
                << ReceiveHttp(RequestEndOfMessage(3))
        )

            

Reported by Pylint.

Expression "playbook >> DataReceived(tctx.client, b'CONNECT example.com:443 HTTP/1.1\r\ncontent-length: 0\r\n\r\n' + (b'some plain tcp' if pipeline else b'')) << ReceiveHttp(Placeholder(RequestHeaders)) >> ResponseHeaders(1, http.Response.make(200)) << SendData(tctx.client, b'HTTP/1.1 200 OK\r\ncontent-length: 0\r\n\r\n') >> ResponseEndOfMessage(1)" is assigned to nothing
Error

Line: 48 Column: 9

                  @pytest.mark.parametrize("pipeline", ["pipeline", None])
    def test_connect(self, tctx, pipeline):
        playbook = Playbook(Http1Server(tctx))
        (
                playbook
                >> DataReceived(tctx.client,
                                b"CONNECT example.com:443 HTTP/1.1\r\n"
                                b"content-length: 0\r\n"
                                b"\r\n"

            

Reported by Pylint.

mitmproxy/contrib/wbxml/ASCommandResponse.py
51 issues
Attempted relative import beyond top-level package
Error

Line: 30 Column: 1

              OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
from .ASWBXML import ASWBXML
import logging

class ASCommandResponse:

	def __init__(self, response):

            

Reported by Pylint.

Instance of 'ASCommandResponse' has no 'wbxmlBytes' member
Error

Line: 47 Column: 10

              			raise ValueError("Error: {0}".format(e))

	def getWBXMLBytes(self):
		return self.wbxmlBytes
	
	def getXMLString(self):
		return self.xmlString
	
	def decodeWBXML(self, body):

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 44 Column: 4

              				raise ValueError("Empty WBXML body passed")
		except Exception as e:
			self.xmlString = None
			raise ValueError("Error: {0}".format(e))

	def getWBXMLBytes(self):
		return self.wbxmlBytes
	
	def getXMLString(self):

            

Reported by Pylint.

Module name "ASCommandResponse" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              #!/usr/bin/env python3
'''
@author: David Shaw, shawd@vmware.com

Inspired by EAS Inspector for Fiddler
https://easinspectorforfiddler.codeplex.com

----- The MIT License (MIT) ----- 
Filename: ASCommandResponse.py

            

Reported by Pylint.

Trailing whitespace
Error

Line: 8 Column: 34

              Inspired by EAS Inspector for Fiddler
https://easinspectorforfiddler.codeplex.com

----- The MIT License (MIT) ----- 
Filename: ASCommandResponse.py
Copyright (c) 2014, David P. Shaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

            

Reported by Pylint.

standard import "import logging" should be placed before "from .ASWBXML import ASWBXML"
Error

Line: 31 Column: 1

              THE SOFTWARE.
'''
from .ASWBXML import ASWBXML
import logging

class ASCommandResponse:

	def __init__(self, response):
		self.wbxmlBody = response

            

Reported by Pylint.

Missing class docstring
Error

Line: 33 Column: 1

              from .ASWBXML import ASWBXML
import logging

class ASCommandResponse:

	def __init__(self, response):
		self.wbxmlBody = response
		try:
			if ( len(response) > 0):

            

Reported by Pylint.

Bad indentation. Found 1 spaces, expected 4
Style

Line: 35 Column: 1

              
class ASCommandResponse:

	def __init__(self, response):
		self.wbxmlBody = response
		try:
			if ( len(response) > 0):
				self.xmlString = self.decodeWBXML(self.wbxmlBody)
			else:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 8
Style

Line: 36 Column: 1

              class ASCommandResponse:

	def __init__(self, response):
		self.wbxmlBody = response
		try:
			if ( len(response) > 0):
				self.xmlString = self.decodeWBXML(self.wbxmlBody)
			else:
				raise ValueError("Empty WBXML body passed")

            

Reported by Pylint.

Attribute name "wbxmlBody" doesn't conform to snake_case naming style
Error

Line: 36 Column: 3

              class ASCommandResponse:

	def __init__(self, response):
		self.wbxmlBody = response
		try:
			if ( len(response) > 0):
				self.xmlString = self.decodeWBXML(self.wbxmlBody)
			else:
				raise ValueError("Empty WBXML body passed")

            

Reported by Pylint.

mitmproxy/tools/console/window.py
50 issues
Unable to import 'urwid'
Error

Line: 4 Column: 1

              import os
import re

import urwid
from mitmproxy.tools.console import commands
from mitmproxy.tools.console import common
from mitmproxy.tools.console import eventlog
from mitmproxy.tools.console import flowlist
from mitmproxy.tools.console import flowview

            

Reported by Pylint.

Unable to import 'urwid'
Error

Line: 21 Column: 5

              if os.name == "nt":
    from mitmproxy.contrib.urwid import raw_display
else:
    from urwid import raw_display  # type: ignore


class StackWidget(urwid.Frame):
    def __init__(self, window, widget, title, focus):
        self.is_focused = focus

            

Reported by Pylint.

Redefining built-in 'help'
Error

Line: 11 Column: 1

              from mitmproxy.tools.console import flowlist
from mitmproxy.tools.console import flowview
from mitmproxy.tools.console import grideditor
from mitmproxy.tools.console import help
from mitmproxy.tools.console import keybindings
from mitmproxy.tools.console import options
from mitmproxy.tools.console import overlay
from mitmproxy.tools.console import signals
from mitmproxy.tools.console import statusbar

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 108 Column: 1

                      self.stack.append(wname)
        self.call("layout_pushed", prev)

    def pop(self, *args, **kwargs):
        """
            Pop off the stack, return True if we're already at the top.
        """
        if not self.overlay and len(self.stack) == 1:
            return True

            

Reported by Pylint.

Unused argument 'args'
Error

Line: 108 Column: 1

                      self.stack.append(wname)
        self.call("layout_pushed", prev)

    def pop(self, *args, **kwargs):
        """
            Pop off the stack, return True if we're already at the top.
        """
        if not self.overlay and len(self.stack) == 1:
            return True

            

Reported by Pylint.

Unused argument 'updated'
Error

Line: 163 Column: 33

                  def focus_stack(self):
        return self.stacks[self.pane]

    def configure(self, otions, updated):
        self.refresh()

    def refresh(self):
        """
            Redraw the layout.

            

Reported by Pylint.

Unused argument 'otions'
Error

Line: 163 Column: 25

                  def focus_stack(self):
        return self.stacks[self.pane]

    def configure(self, otions, updated):
        self.refresh()

    def refresh(self):
        """
            Redraw the layout.

            

Reported by Pylint.

Attribute 'body' defined outside __init__
Error

Line: 204 Column: 9

                              focus_column=self.pane
            )

        self.body = urwid.AttrWrap(w, "background")

    def flow_changed(self, sender, flow):
        if self.master.view.focus.flow:
            if flow.id == self.master.view.focus.flow.id:
                self.focus_changed()

            

Reported by Pylint.

Unused argument 'sender'
Error

Line: 206 Column: 28

              
        self.body = urwid.AttrWrap(w, "background")

    def flow_changed(self, sender, flow):
        if self.master.view.focus.flow:
            if flow.id == self.master.view.focus.flow.id:
                self.focus_changed()

    def focus_changed(self, *args, **kwargs):

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 211 Column: 1

                          if flow.id == self.master.view.focus.flow.id:
                self.focus_changed()

    def focus_changed(self, *args, **kwargs):
        """
            Triggered when the focus changes - either when it's modified, or
            when it changes to a different flow altogether.
        """
        for i in self.stacks:

            

Reported by Pylint.

mitmproxy/tools/console/palettes.py
50 issues
Value 'self.high' is unsubscriptable
Error

Line: 57 Column: 28

                      highback, lowback = None, None
        if not transparent:
            if self.high and self.high.get("background"):
                highback = self.high["background"][1]
            lowback = self.low["background"][1]

        for i in self._fields:
            if transparent and i == "background":
                l.append(["background", "default", "default"])

            

Reported by Pylint.

Instance of 'Palette' has no 'low' member
Error

Line: 58 Column: 23

                      if not transparent:
            if self.high and self.high.get("background"):
                highback = self.high["background"][1]
            lowback = self.low["background"][1]

        for i in self._fields:
            if transparent and i == "background":
                l.append(["background", "default", "default"])
            else:

            

Reported by Pylint.

Instance of 'Palette' has no 'low' member
Error

Line: 65 Column: 28

                              l.append(["background", "default", "default"])
            else:
                v = [i]
                low = list(self.low[i])
                if lowback and low[1] == "default":
                    low[1] = lowback
                v.extend(low)
                if self.high and i in self.high:
                    v.append(None)

            

Reported by Pylint.

Value 'self.high' doesn't support membership test
Error

Line: 69 Column: 39

                              if lowback and low[1] == "default":
                    low[1] = lowback
                v.extend(low)
                if self.high and i in self.high:
                    v.append(None)
                    high = list(self.high[i])
                    if highback and high[1] == "default":
                        high[1] = highback
                    v.extend(high)

            

Reported by Pylint.

Value 'self.high' is unsubscriptable
Error

Line: 71 Column: 33

                              v.extend(low)
                if self.high and i in self.high:
                    v.append(None)
                    high = list(self.high[i])
                    if highback and high[1] == "default":
                        high[1] = highback
                    v.extend(high)
                elif highback and self.low[i][1] == "default":
                    high = [None, low[0], highback]

            

Reported by Pylint.

Instance of 'Palette' has no 'low' member
Error

Line: 75 Column: 35

                                  if highback and high[1] == "default":
                        high[1] = highback
                    v.extend(high)
                elif highback and self.low[i][1] == "default":
                    high = [None, low[0], highback]
                    v.extend(high)
                l.append(tuple(v))
        return l


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import typing  # noqa
# Low-color themes should ONLY use the standard foreground and background
# colours listed here:
#
# http://urwid.org/manual/displayattributes.html
#


class Palette:

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              #


class Palette:
    _fields = [
        'background',
        'title',

        # Status bar & heading

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 9 Column: 1

              #


class Palette:
    _fields = [
        'background',
        'title',

        # Status bar & heading

            

Reported by Pylint.

Line too long (119/100)
Error

Line: 25 Column: 1

                      'option_selected_key',

        # List and Connections
        'method_get', 'method_post', 'method_delete', 'method_other', 'method_head', 'method_put', 'method_http2_push',
        'scheme_http', 'scheme_https', 'scheme_ws', 'scheme_wss', 'scheme_tcp', 'scheme_other',
        'url_punctuation', 'url_domain', 'url_filename', 'url_extension', 'url_query_key', 'url_query_value',
        'content_none', 'content_text', 'content_script', 'content_media', 'content_data', 'content_raw', 'content_other',
        'focus',
        'code_200', 'code_300', 'code_400', 'code_500', 'code_other',

            

Reported by Pylint.