The following issues were found

test/mitmproxy/proxy/layers/http/test_http_fuzz.py
91 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              from typing import Tuple, Dict, Any

import pytest
from h2.settings import SettingCodes
from hypothesis import example, given
from hypothesis.strategies import binary, booleans, composite, dictionaries, integers, lists, sampled_from, sets, text, \
    data

from mitmproxy import options, connection

            

Reported by Pylint.

Unable to import 'h2.settings'
Error

Line: 4 Column: 1

              from typing import Tuple, Dict, Any

import pytest
from h2.settings import SettingCodes
from hypothesis import example, given
from hypothesis.strategies import binary, booleans, composite, dictionaries, integers, lists, sampled_from, sets, text, \
    data

from mitmproxy import options, connection

            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 5 Column: 1

              
import pytest
from h2.settings import SettingCodes
from hypothesis import example, given
from hypothesis.strategies import binary, booleans, composite, dictionaries, integers, lists, sampled_from, sets, text, \
    data

from mitmproxy import options, connection
from mitmproxy.addons.proxyserver import Proxyserver

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 6 Column: 1

              import pytest
from h2.settings import SettingCodes
from hypothesis import example, given
from hypothesis.strategies import binary, booleans, composite, dictionaries, integers, lists, sampled_from, sets, text, \
    data

from mitmproxy import options, connection
from mitmproxy.addons.proxyserver import Proxyserver
from mitmproxy.connection import Server

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 9 Column: 1

              from hypothesis.strategies import binary, booleans, composite, dictionaries, integers, lists, sampled_from, sets, text, \
    data

from mitmproxy import options, connection
from mitmproxy.addons.proxyserver import Proxyserver
from mitmproxy.connection import Server
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy import context, events

            

Reported by Pylint.

Unable to import 'mitmproxy.addons.proxyserver'
Error

Line: 10 Column: 1

                  data

from mitmproxy import options, connection
from mitmproxy.addons.proxyserver import Proxyserver
from mitmproxy.connection import Server
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy import context, events
from mitmproxy.proxy.commands import OpenConnection, SendData

            

Reported by Pylint.

Unable to import 'mitmproxy.connection'
Error

Line: 11 Column: 1

              
from mitmproxy import options, connection
from mitmproxy.addons.proxyserver import Proxyserver
from mitmproxy.connection import Server
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy import context, events
from mitmproxy.proxy.commands import OpenConnection, SendData
from mitmproxy.proxy.events import DataReceived, Start, ConnectionClosed

            

Reported by Pylint.

Unable to import 'mitmproxy.http'
Error

Line: 12 Column: 1

              from mitmproxy import options, connection
from mitmproxy.addons.proxyserver import Proxyserver
from mitmproxy.connection import Server
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy import context, events
from mitmproxy.proxy.commands import OpenConnection, SendData
from mitmproxy.proxy.events import DataReceived, Start, ConnectionClosed
from mitmproxy.proxy.layers import http

            

Reported by Pylint.

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

Line: 13 Column: 1

              from mitmproxy.addons.proxyserver import Proxyserver
from mitmproxy.connection import Server
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy import context, events
from mitmproxy.proxy.commands import OpenConnection, SendData
from mitmproxy.proxy.events import DataReceived, Start, ConnectionClosed
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'
Error

Line: 14 Column: 1

              from mitmproxy.connection import Server
from mitmproxy.http import HTTPFlow
from mitmproxy.proxy.layers.http import HTTPMode
from mitmproxy.proxy import context, events
from mitmproxy.proxy.commands import OpenConnection, SendData
from mitmproxy.proxy.events import DataReceived, Start, ConnectionClosed
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 make_h2, example_response_headers, example_request_headers, \

            

Reported by Pylint.

mitmproxy/contrib/kaitaistruct/jpeg.py
87 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.

Attempted relative import beyond top-level package
Error

Line: 15 Column: 1

              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))

from .exif import Exif

class Jpeg(KaitaiStruct):

    class ComponentId(Enum):
        y = 1

            

Reported by Pylint.

Access to member '_m_sampling_x' before its definition line 168
Error

Line: 166 Column: 28

                          @property
            def sampling_x(self):
                if hasattr(self, '_m_sampling_x'):
                    return self._m_sampling_x if hasattr(self, '_m_sampling_x') else None

                self._m_sampling_x = ((self.sampling_factors & 240) >> 4)
                return self._m_sampling_x if hasattr(self, '_m_sampling_x') else None

            @property

            

Reported by Pylint.

Access to member '_m_sampling_y' before its definition line 176
Error

Line: 174 Column: 28

                          @property
            def sampling_y(self):
                if hasattr(self, '_m_sampling_y'):
                    return self._m_sampling_y if hasattr(self, '_m_sampling_y') else None

                self._m_sampling_y = (self.sampling_factors & 15)
                return self._m_sampling_y if hasattr(self, '_m_sampling_y') else None



            

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 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.

Attribute '_m_sampling_x' defined outside __init__
Error

Line: 168 Column: 17

                              if hasattr(self, '_m_sampling_x'):
                    return self._m_sampling_x if hasattr(self, '_m_sampling_x') else None

                self._m_sampling_x = ((self.sampling_factors & 240) >> 4)
                return self._m_sampling_x if hasattr(self, '_m_sampling_x') else None

            @property
            def sampling_y(self):
                if hasattr(self, '_m_sampling_y'):

            

Reported by Pylint.

Attribute '_m_sampling_y' defined outside __init__
Error

Line: 176 Column: 17

                              if hasattr(self, '_m_sampling_y'):
                    return self._m_sampling_y if hasattr(self, '_m_sampling_y') else None

                self._m_sampling_y = (self.sampling_factors & 15)
                return self._m_sampling_y if hasattr(self, '_m_sampling_y') else None



    class ExifInJpeg(KaitaiStruct):

            

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: 13 Column: 1

              

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))

from .exif import Exif

class Jpeg(KaitaiStruct):


            

Reported by Pylint.

test/mitmproxy/net/http/test_url.py
86 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              from typing import AnyStr

import pytest

from mitmproxy.net.http import url
from mitmproxy.net.http.url import parse_authority


def test_parse():

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import AnyStr

import pytest

from mitmproxy.net.http import url
from mitmproxy.net.http.url import parse_authority


def test_parse():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              from mitmproxy.net.http.url import parse_authority


def test_parse():
    with pytest.raises(ValueError):
        url.parse("")

    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"

            

Reported by Pylint.

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

Line: 13 Column: 15

                  with pytest.raises(ValueError):
        url.parse("")

    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"


            

Reported by Pylint.

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

Line: 13 Column: 11

                  with pytest.raises(ValueError):
        url.parse("")

    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"


            

Reported by Pylint.

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

Line: 13 Column: 8

                  with pytest.raises(ValueError):
        url.parse("")

    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"


            

Reported by Pylint.

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

Line: 13 Column: 5

                  with pytest.raises(ValueError):
        url.parse("")

    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"


            

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

                      url.parse("")

    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"

    s, h, po, pa = url.parse("http://foo/bar")

            

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

              
    s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"

    s, h, po, pa = url.parse("http://foo/bar")
    assert s == b"http"

            

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

                  s, h, po, pa = url.parse(b"http://foo.com:8888/test")
    assert s == b"http"
    assert h == b"foo.com"
    assert po == 8888
    assert pa == b"/test"

    s, h, po, pa = url.parse("http://foo/bar")
    assert s == b"http"
    assert h == b"foo"

            

Reported by Bandit.

test/mitmproxy/net/http/test_cookies.py
86 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import time
import pytest
from unittest import mock

from mitmproxy.net.http import cookies


cookie_pairs = [
    [

            

Reported by Pylint.

Access to a protected member _read_key of a client class
Error

Line: 67 Column: 16

                      [(" foo=bar", 1), ("foo", 4)],
    ]
    for q, a in tokens:
        assert cookies._read_key(*q) == a


def test_read_quoted_string():
    tokens = [
        [('"foo" x', 0), ("foo", 5)],

            

Reported by Pylint.

Access to a protected member _read_quoted_string of a client class
Error

Line: 80 Column: 16

                      [('"foo" x', 7), ("", 8)],
    ]
    for q, a in tokens:
        assert cookies._read_quoted_string(*q) == a


def test_read_cookie_pairs():
    vals = [
        [

            

Reported by Pylint.

Access to a protected member _read_cookie_pairs of a client class
Error

Line: 119 Column: 20

                      ],
    ]
    for s, lst in vals:
        ret, off = cookies._read_cookie_pairs(s)
        assert ret == lst


def test_pairs_roundtrips():
    for s, expected in cookie_pairs:

            

Reported by Pylint.

Unused variable 'off'
Error

Line: 119 Column: 14

                      ],
    ]
    for s, lst in vals:
        ret, off = cookies._read_cookie_pairs(s)
        assert ret == lst


def test_pairs_roundtrips():
    for s, expected in cookie_pairs:

            

Reported by Pylint.

Unused variable 'off'
Error

Line: 125 Column: 14

              
def test_pairs_roundtrips():
    for s, expected in cookie_pairs:
        ret, off = cookies._read_cookie_pairs(s)
        assert ret == expected

        s2 = cookies._format_pairs(expected)
        ret, off = cookies._read_cookie_pairs(s2)
        assert ret == expected

            

Reported by Pylint.

Access to a protected member _read_cookie_pairs of a client class
Error

Line: 125 Column: 20

              
def test_pairs_roundtrips():
    for s, expected in cookie_pairs:
        ret, off = cookies._read_cookie_pairs(s)
        assert ret == expected

        s2 = cookies._format_pairs(expected)
        ret, off = cookies._read_cookie_pairs(s2)
        assert ret == expected

            

Reported by Pylint.

Access to a protected member _format_pairs of a client class
Error

Line: 128 Column: 14

                      ret, off = cookies._read_cookie_pairs(s)
        assert ret == expected

        s2 = cookies._format_pairs(expected)
        ret, off = cookies._read_cookie_pairs(s2)
        assert ret == expected


def test_cookie_roundtrips():

            

Reported by Pylint.

Access to a protected member _read_cookie_pairs of a client class
Error

Line: 129 Column: 20

                      assert ret == expected

        s2 = cookies._format_pairs(expected)
        ret, off = cookies._read_cookie_pairs(s2)
        assert ret == expected


def test_cookie_roundtrips():
    for s, expected in cookie_pairs:

            

Reported by Pylint.

Unused variable 'off'
Error

Line: 216 Column: 14

                      ],
    ]
    for s, expected in pairs:
        ret, off = cookies._read_set_cookie_pairs(s)
        assert ret == expected

        s2 = cookies._format_set_cookie_pairs(expected[0])
        ret2, off = cookies._read_set_cookie_pairs(s2)
        assert ret2 == expected

            

Reported by Pylint.

mitmproxy/contrib/kaitaistruct/png.py
85 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.

Access to member '_m_x' before its definition line 127
Error

Line: 125 Column: 24

                      @property
        def x(self):
            if hasattr(self, '_m_x'):
                return self._m_x if hasattr(self, '_m_x') else None

            self._m_x = (self.x_int / 100000.0)
            return self._m_x if hasattr(self, '_m_x') else None

        @property

            

Reported by Pylint.

Access to member '_m_y' before its definition line 135
Error

Line: 133 Column: 24

                      @property
        def y(self):
            if hasattr(self, '_m_y'):
                return self._m_y if hasattr(self, '_m_y') else None

            self._m_y = (self.y_int / 100000.0)
            return self._m_y if hasattr(self, '_m_y') else None



            

Reported by Pylint.

Access to member '_m_gamma_ratio' before its definition line 230
Error

Line: 228 Column: 24

                      @property
        def gamma_ratio(self):
            if hasattr(self, '_m_gamma_ratio'):
                return self._m_gamma_ratio if hasattr(self, '_m_gamma_ratio') else None

            self._m_gamma_ratio = (100000.0 / self.gamma_int)
            return self._m_gamma_ratio if hasattr(self, '_m_gamma_ratio') else None



            

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.

Attribute '_m_x' defined outside __init__
Error

Line: 127 Column: 13

                          if hasattr(self, '_m_x'):
                return self._m_x if hasattr(self, '_m_x') else None

            self._m_x = (self.x_int / 100000.0)
            return self._m_x if hasattr(self, '_m_x') else None

        @property
        def y(self):
            if hasattr(self, '_m_y'):

            

Reported by Pylint.

Attribute '_m_y' defined outside __init__
Error

Line: 135 Column: 13

                          if hasattr(self, '_m_y'):
                return self._m_y if hasattr(self, '_m_y') else None

            self._m_y = (self.y_int / 100000.0)
            return self._m_y if hasattr(self, '_m_y') else None


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

            

Reported by Pylint.

Attribute '_m_gamma_ratio' defined outside __init__
Error

Line: 230 Column: 13

                          if hasattr(self, '_m_gamma_ratio'):
                return self._m_gamma_ratio if hasattr(self, '_m_gamma_ratio') else None

            self._m_gamma_ratio = (100000.0 / self.gamma_int)
            return self._m_gamma_ratio if hasattr(self, '_m_gamma_ratio') else None


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

            

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: 13 Column: 1

              

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 Png(KaitaiStruct):

    class ColorType(Enum):
        greyscale = 0

            

Reported by Pylint.

test/mitmproxy/addons/test_dumper.py
85 issues
Unable to import 'pytest'
Error

Line: 5 Column: 1

              import shutil
from unittest import mock

import pytest

from mitmproxy import exceptions
from mitmproxy.addons import dumper
from mitmproxy.http import Headers
from mitmproxy.test import taddons

            

Reported by Pylint.

Access to a protected member _echo_message of a client class
Error

Line: 105 Column: 9

                  d = dumper.Dumper(sio)
    with taddons.context(d) as ctx:
        ctx.configure(d, flow_detail=3)
        d._echo_message(f.response, f)
        t = sio.getvalue()
        assert "cut off" in t


def test_echo_trailer():

            

Reported by Pylint.

Access to a protected member _echo_request_line of a client class
Error

Line: 145 Column: 9

                      ctx.configure(d, flow_detail=3, showhost=True)
        f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
        f.is_replay = "request"
        d._echo_request_line(f)
        assert "[replay]" in sio.getvalue()
        sio.truncate(0)

        f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
        f.is_replay = None

            

Reported by Pylint.

Access to a protected member _echo_request_line of a client class
Error

Line: 151 Column: 9

              
        f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
        f.is_replay = None
        d._echo_request_line(f)
        assert "[replay]" not in sio.getvalue()
        sio.truncate(0)

        f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
        f.request.http_version = "nonstandard"

            

Reported by Pylint.

Access to a protected member _echo_request_line of a client class
Error

Line: 157 Column: 9

              
        f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
        f.request.http_version = "nonstandard"
        d._echo_request_line(f)
        assert "nonstandard" in sio.getvalue()
        sio.truncate(0)

        ctx.configure(d, flow_detail=0, showhost=True)
        f = tflow.tflow(client_conn=None, server_conn=True, resp=True)

            

Reported by Pylint.

Access to a protected member _echo_request_line of a client class
Error

Line: 165 Column: 9

                      f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
        terminalWidth = max(shutil.get_terminal_size()[0] - 25, 50)
        f.request.url = "http://address:22/" + ("x" * terminalWidth) + "textToBeTruncated"
        d._echo_request_line(f)
        assert "textToBeTruncated" not in sio.getvalue()
        sio.truncate(0)


class TestContentView:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import io
import shutil
from unittest import mock

import pytest

from mitmproxy import exceptions
from mitmproxy.addons import dumper
from mitmproxy.http import Headers

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              from mitmproxy.test import tutils


def test_configure():
    d = dumper.Dumper()
    with taddons.context(d) as ctx:
        ctx.configure(d, dumper_filter="~b foo")
        assert d.filter


            

Reported by Pylint.

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

Line: 16 Column: 5

              

def test_configure():
    d = dumper.Dumper()
    with taddons.context(d) as ctx:
        ctx.configure(d, dumper_filter="~b foo")
        assert d.filter

        f = tflow.tflow(resp=True)

            

Reported by Pylint.

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

                  d = dumper.Dumper()
    with taddons.context(d) as ctx:
        ctx.configure(d, dumper_filter="~b foo")
        assert d.filter

        f = tflow.tflow(resp=True)
        assert not d.match(f)
        f.response.content = b"foo"
        assert d.match(f)

            

Reported by Bandit.

mitmproxy/addons/view.py
84 issues
Unable to import 'sortedcontainers'
Error

Line: 15 Column: 1

              import typing

import blinker
import sortedcontainers

import mitmproxy.flow
from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import exceptions

            

Reported by Pylint.

Assigning result of a function call, where the function has no return
Error

Line: 51 Column: 9

                  def refresh(self, f):
        k = self._key()
        old = self.view.settings[f][k]
        new = self.generate(f)
        if old != new:
            self.view._view.remove(f)
            self.view.settings[f][k] = new
            self.view._view.add(f)
            self.view.sig_view_refresh.send(self.view)

            

Reported by Pylint.

Assigning result of a function call, where the function has no return
Error

Line: 67 Column: 13

                          s = self.view.settings[f]
            if k in s:
                return s[k]
            val = self.generate(f)
            s[k] = val
            return val
        else:
            return self.generate(f)


            

Reported by Pylint.

Access to a protected member _view of a client class
Error

Line: 53 Column: 13

                      old = self.view.settings[f][k]
        new = self.generate(f)
        if old != new:
            self.view._view.remove(f)
            self.view.settings[f][k] = new
            self.view._view.add(f)
            self.view.sig_view_refresh.send(self.view)

    def _key(self):

            

Reported by Pylint.

Access to a protected member _view of a client class
Error

Line: 55 Column: 13

                      if old != new:
            self.view._view.remove(f)
            self.view.settings[f][k] = new
            self.view._view.add(f)
            self.view.sig_view_refresh.send(self.view)

    def _key(self):
        return "_order_%s" % id(self)


            

Reported by Pylint.

Parameters differ from overridden 'index' method
Error

Line: 215 Column: 5

                      v = self._view.bisect_right(f)
        return self._rev(v - 1) + 1

    def index(self, f: mitmproxy.flow.Flow, start: int = 0, stop: typing.Optional[int] = None) -> int:
        return self._rev(self._view.index(f, start, stop))

    def __contains__(self, f: typing.Any) -> bool:
        return self._view.__contains__(f)


            

Reported by Pylint.

String statement has no effect
Error

Line: 237 Column: 5

                              self._base_add(i)
        self.sig_view_refresh.send(self)

    """ View API """

    # Focus
    @command.command("view.focus.go")
    def go(self, offset: int) -> None:
        """

            

Reported by Pylint.

Access to a protected member _bisect of a client class
Error

Line: 661 Column: 20

                      self.flow = self.view[idx]

    def _nearest(self, f, v):
        return min(v._bisect(f), len(v) - 1)

    def _sig_view_remove(self, view, flow, index):
        if len(view) == 0:
            self.flow = None
        elif flow is self.flow:

            

Reported by Pylint.

Unused argument 'view'
Error

Line: 677 Column: 29

                      elif self.flow not in view:
            self.flow = view[self._nearest(self.flow, view)]

    def _sig_view_add(self, view, flow):
        # We only have to act if we don't have a focus element
        if not self.flow:
            self.flow = flow



            

Reported by Pylint.

Unused argument 'view'
Error

Line: 701 Column: 33

                          raise KeyError
        return self._values.setdefault(f.id, {})

    def _sig_store_remove(self, view, flow):
        if flow.id in self._values:
            del self._values[flow.id]

    def _sig_store_refresh(self, view):
        for fid in list(self._values.keys()):

            

Reported by Pylint.

mitmproxy/tools/console/common.py
80 issues
Unable to import 'publicsuffix2'
Error

Line: 6 Column: 1

              import typing
import math
from functools import lru_cache
from publicsuffix2 import get_sld, get_tld

import urwid
import urwid.util

from mitmproxy import flow

            

Reported by Pylint.

Unable to import 'urwid'
Error

Line: 8 Column: 1

              from functools import lru_cache
from publicsuffix2 import get_sld, get_tld

import urwid
import urwid.util

from mitmproxy import flow
from mitmproxy.http import HTTPFlow
from mitmproxy.utils import human, emoji

            

Reported by Pylint.

Unable to import 'urwid.util'
Error

Line: 9 Column: 1

              from publicsuffix2 import get_sld, get_tld

import urwid
import urwid.util

from mitmproxy import flow
from mitmproxy.http import HTTPFlow
from mitmproxy.utils import human, emoji
from mitmproxy.tcp import TCPFlow

            

Reported by Pylint.

Redefining built-in 'str'
Error

Line: 28 Column: 19

                      return True


def highlight_key(str, key, textattr="text", keyattr="key"):
    l = []
    parts = str.split(key, 1)
    if parts[0]:
        l.append((textattr, parts[0]))
    l.append((keyattr, key))

            

Reported by Pylint.

Unused argument 'focus'
Error

Line: 181 Column: 26

                      self.align = align
        super().__init__()

    def pack(self, size, focus=False):
        return (len(self.text), 1)

    def rows(self, size, focus=False):
        return 1


            

Reported by Pylint.

Unused argument 'size'
Error

Line: 181 Column: 20

                      self.align = align
        super().__init__()

    def pack(self, size, focus=False):
        return (len(self.text), 1)

    def rows(self, size, focus=False):
        return 1


            

Reported by Pylint.

Unused argument 'size'
Error

Line: 184 Column: 20

                  def pack(self, size, focus=False):
        return (len(self.text), 1)

    def rows(self, size, focus=False):
        return 1

    def render(self, size, focus=False):
        text = self.text
        attr = self.attr

            

Reported by Pylint.

Unused argument 'focus'
Error

Line: 184 Column: 26

                  def pack(self, size, focus=False):
        return (len(self.text), 1)

    def rows(self, size, focus=False):
        return 1

    def render(self, size, focus=False):
        text = self.text
        attr = self.attr

            

Reported by Pylint.

Unused argument 'focus'
Error

Line: 187 Column: 28

                  def rows(self, size, focus=False):
        return 1

    def render(self, size, focus=False):
        text = self.text
        attr = self.attr
        if self.align == 'right':
            text = text[::-1]
            attr = attr[::-1]

            

Reported by Pylint.

TODO: unicode?
Error

Line: 194 Column: 3

                          text = text[::-1]
            attr = attr[::-1]

        text_len = len(text)  # TODO: unicode?
        if size is not None and len(size) > 0:
            width = size[0]
        else:
            width = text_len


            

Reported by Pylint.

examples/contrib/xss_scanner.py
80 issues
Unable to import 'mitmproxy'
Error

Line: 46 Column: 1

              
import requests

from mitmproxy import http
from mitmproxy import ctx


# The actual payload is put between a frontWall and a backWall to make it easy
# to locate the payload with regular expressions

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 47 Column: 1

              import requests

from mitmproxy import http
from mitmproxy import ctx


# The actual payload is put between a frontWall and a backWall to make it easy
# to locate the payload with regular expressions
FRONT_WALL = b"1029zxc"

            

Reported by Pylint.

Method 'error' is abstract in class 'ParserBase' but is not overridden
Error

Line: 101 Column: 5

                              return value
        return None

    class ScriptURLExtractor(HTMLParser):
        script_URLs: List[str] = []

        def handle_starttag(self, tag, attrs):
            if (tag == "script" or tag == "iframe") and "src" in [name for name, value in attrs]:
                self.script_URLs.append(getValue(attrs, "src"))

            

Reported by Pylint.

Method 'error' is abstract in class 'ParserBase' but is not overridden
Error

Line: 259 Column: 5

                      index = string.rfind(substr)
        return string[:index] + string[index + len(substr):]

    class PathHTMLParser(HTMLParser):
        currentPath = ""
        paths: List[str] = []

        def handle_starttag(self, tag, attrs):
            self.currentPath += ("/" + tag)

            

Reported by Pylint.

Method 'error' is abstract in class 'ParserBase' but is not overridden
Error

Line: 305 Column: 9

              
    def inject_javascript_handler(html: str) -> bool:
        """ Whether you can inject a Javascript:alert(0) as a link """
        class injectJSHandlerHTMLParser(HTMLParser):
            injectJSHandler = False

            def handle_starttag(self, tag, attrs):
                for name, value in attrs:
                    if name == "href" and value.startswith(FRONT_WALL.decode('utf-8')):

            

Reported by Pylint.

Line too long (112/100)
Error

Line: 15 Column: 1

              
Usage: mitmproxy -s xss_scanner.py

This script scans for vulnerabilities by injecting a fuzzing payload (see PAYLOAD below) into 4 different places
and examining the HTML to look for XSS and SQLi injection vulnerabilities. The XSS scanning functionality works by
looking to see whether it is possible to inject HTML based off of of where the payload appears in the page and what
characters are escaped. In addition, it also looks for any script tags that load javascript from unclaimed domains.
The SQLi scanning functionality works by using regular expressions to look for errors from a number of different
common databases. Since it is only looking for errors, it will not find blind SQLi vulnerabilities.

            

Reported by Pylint.

Line too long (114/100)
Error

Line: 16 Column: 1

              Usage: mitmproxy -s xss_scanner.py

This script scans for vulnerabilities by injecting a fuzzing payload (see PAYLOAD below) into 4 different places
and examining the HTML to look for XSS and SQLi injection vulnerabilities. The XSS scanning functionality works by
looking to see whether it is possible to inject HTML based off of of where the payload appears in the page and what
characters are escaped. In addition, it also looks for any script tags that load javascript from unclaimed domains.
The SQLi scanning functionality works by using regular expressions to look for errors from a number of different
common databases. Since it is only looking for errors, it will not find blind SQLi vulnerabilities.


            

Reported by Pylint.

Line too long (115/100)
Error

Line: 17 Column: 1

              
This script scans for vulnerabilities by injecting a fuzzing payload (see PAYLOAD below) into 4 different places
and examining the HTML to look for XSS and SQLi injection vulnerabilities. The XSS scanning functionality works by
looking to see whether it is possible to inject HTML based off of of where the payload appears in the page and what
characters are escaped. In addition, it also looks for any script tags that load javascript from unclaimed domains.
The SQLi scanning functionality works by using regular expressions to look for errors from a number of different
common databases. Since it is only looking for errors, it will not find blind SQLi vulnerabilities.

The 4 places it injects the payload into are:

            

Reported by Pylint.

Line too long (115/100)
Error

Line: 18 Column: 1

              This script scans for vulnerabilities by injecting a fuzzing payload (see PAYLOAD below) into 4 different places
and examining the HTML to look for XSS and SQLi injection vulnerabilities. The XSS scanning functionality works by
looking to see whether it is possible to inject HTML based off of of where the payload appears in the page and what
characters are escaped. In addition, it also looks for any script tags that load javascript from unclaimed domains.
The SQLi scanning functionality works by using regular expressions to look for errors from a number of different
common databases. Since it is only looking for errors, it will not find blind SQLi vulnerabilities.

The 4 places it injects the payload into are:
1. URLs         (e.g. https://example.com/ -> https://example.com/PAYLOAD/)

            

Reported by Pylint.

Line too long (112/100)
Error

Line: 19 Column: 1

              and examining the HTML to look for XSS and SQLi injection vulnerabilities. The XSS scanning functionality works by
looking to see whether it is possible to inject HTML based off of of where the payload appears in the page and what
characters are escaped. In addition, it also looks for any script tags that load javascript from unclaimed domains.
The SQLi scanning functionality works by using regular expressions to look for errors from a number of different
common databases. Since it is only looking for errors, it will not find blind SQLi vulnerabilities.

The 4 places it injects the payload into are:
1. URLs         (e.g. https://example.com/ -> https://example.com/PAYLOAD/)
2. Queries      (e.g. https://example.com/index.html?a=b -> https://example.com/index.html?a=PAYLOAD)

            

Reported by Pylint.

mitmproxy/optmanager.py
80 issues
Unable to import 'ruamel.yaml'
Error

Line: 12 Column: 1

              import typing
import textwrap

import ruamel.yaml

from mitmproxy import exceptions
from mitmproxy.utils import typecheck

"""

            

Reported by Pylint.

String statement has no effect
Error

Line: 17 Column: 1

              from mitmproxy import exceptions
from mitmproxy.utils import typecheck

"""
    The base implementation for Options.
"""

unset = object()


            

Reported by Pylint.

Redefining built-in 'help'
Error

Line: 32 Column: 9

                      name: str,
        typespec: typing.Union[type, object],  # object for Optional[x], which is not a type.
        default: typing.Any,
        help: str,
        choices: typing.Optional[typing.Sequence[str]]
    ) -> None:
        typecheck.check_option_type(name, default, typespec)
        self.name = name
        self.typespec = typespec

            

Reported by Pylint.

Redefining built-in 'help'
Error

Line: 107 Column: 9

                      name: str,
        typespec: typing.Union[type, object],
        default: typing.Any,
        help: str,
        choices: typing.Optional[typing.Sequence[str]] = None
    ) -> None:
        self._options[name] = _Option(name, typespec, default, help, choices)
        self.changed.send(self, updated={name})


            

Reported by Pylint.

Access to a protected member _saferef of a client class
Error

Line: 141 Column: 16

              
        # We reuse blinker's safe reference functionality to cope with weakrefs
        # to bound methods.
        func = blinker._saferef.safe_ref(func)

        @functools.wraps(func)
        def _call(options, updated):
            if updated.intersection(set(opts)):
                f = func()

            

Reported by Pylint.

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

Line: 342 Column: 21

                              try:
                    return int(optstr)
                except ValueError:
                    raise exceptions.OptionsError("Not an integer: %s" % optstr)
            elif o.typespec == int:
                raise exceptions.OptionsError("Option is required: %s" % o.name)
            else:
                return None
        elif o.typespec == bool:

            

Reported by Pylint.

Exception arguments suggest string formatting might be intended
Error

Line: 366 Column: 9

                                  return currentvalue + [optstr]
                else:
                    return [optstr]
        raise NotImplementedError("Unsupported option type: %s", o.typespec)

    def make_parser(self, parser, optname, metavar=None, short=None):
        """
            Auto-Create a command-line parser entry for a named option. If the
            option does not exist, it is ignored.

            

Reported by Pylint.

Exception arguments suggest string formatting might be intended
Error

Line: 439 Column: 13

                              choices=o.choices,
            )
        else:
            raise ValueError("Unsupported option type: %s", o.typespec)


def dump_defaults(opts, out: typing.TextIO):
    """
        Dumps an annotated file with all options.

            

Reported by Pylint.

Access to a protected member _options of a client class
Error

Line: 449 Column: 13

                  # Sort data
    s = ruamel.yaml.comments.CommentedMap()
    for k in sorted(opts.keys()):
        o = opts._options[k]
        s[k] = o.default
        txt = o.help.strip()

        if o.choices:
            txt += " Valid values are %s." % ", ".join(repr(c) for c in o.choices)

            

Reported by Pylint.

Access to a protected member _options of a client class
Error

Line: 473 Column: 13

                  options_dict = {}
    keys = keys if keys else opts.keys()
    for k in sorted(keys):
        o = opts._options[k]
        t = typecheck.typespec_to_str(o.typespec)
        option = {
            'type': t,
            'default': o.default,
            'value': o.current(),

            

Reported by Pylint.