The following issues were found

mitmproxy/contrib/wbxml/GlobalTokens.py
4 issues
Module name "GlobalTokens" 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: GlobalTokens.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: GlobalTokens.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.

Too few public methods (0/2)
Error

Line: 30 Column: 1

              OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
class GlobalTokens:
    SWITCH_PAGE = 0x00
    END = 0x01
    ENTITY = 0x02
    STR_I = 0x03
    LITERAL = 0x04

            

Reported by Pylint.

Missing class docstring
Error

Line: 30 Column: 1

              OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
class GlobalTokens:
    SWITCH_PAGE = 0x00
    END = 0x01
    ENTITY = 0x02
    STR_I = 0x03
    LITERAL = 0x04

            

Reported by Pylint.

test/mitmproxy/utils/test_data.py
4 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from mitmproxy.utils import data


def test_pkg_data():
    assert data.pkg_data.path("tools/console")
    with pytest.raises(ValueError):
        data.pkg_data.path("nonexistent")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
from mitmproxy.utils import data


def test_pkg_data():
    assert data.pkg_data.path("tools/console")
    with pytest.raises(ValueError):
        data.pkg_data.path("nonexistent")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              from mitmproxy.utils import data


def test_pkg_data():
    assert data.pkg_data.path("tools/console")
    with pytest.raises(ValueError):
        data.pkg_data.path("nonexistent")

            

Reported by Pylint.

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

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

              

def test_pkg_data():
    assert data.pkg_data.path("tools/console")
    with pytest.raises(ValueError):
        data.pkg_data.path("nonexistent")

            

Reported by Bandit.

mitmproxy/ctx.py
4 issues
Unused import mitmproxy.log
Error

Line: 1 Column: 1

              import mitmproxy.log
import mitmproxy.master
import mitmproxy.options

log: "mitmproxy.log.Log"
master: "mitmproxy.master.Master"
options: "mitmproxy.options.Options"

            

Reported by Pylint.

Unused import mitmproxy.master
Error

Line: 2 Column: 1

              import mitmproxy.log
import mitmproxy.master
import mitmproxy.options

log: "mitmproxy.log.Log"
master: "mitmproxy.master.Master"
options: "mitmproxy.options.Options"

            

Reported by Pylint.

Unused import mitmproxy.options
Error

Line: 3 Column: 1

              import mitmproxy.log
import mitmproxy.master
import mitmproxy.options

log: "mitmproxy.log.Log"
master: "mitmproxy.master.Master"
options: "mitmproxy.options.Options"

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import mitmproxy.log
import mitmproxy.master
import mitmproxy.options

log: "mitmproxy.log.Log"
master: "mitmproxy.master.Master"
options: "mitmproxy.options.Options"

            

Reported by Pylint.

mitmproxy/utils/sliding_window.py
4 issues
TODO: move into utils
Error

Line: 20 Column: 3

                      1 2 3
        2 3 None
    """
    # TODO: move into utils
    iters: List[Iterator[Optional[T]]] = list(itertools.tee(iterator, behind + 1 + ahead))
    for i in range(behind):
        iters[i] = itertools.chain((behind - i) * [None], iters[i])
    for i in range(ahead):
        iters[-1 - i] = itertools.islice(

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import itertools
from typing import TypeVar, Iterable, Iterator, Tuple, Optional, List

T = TypeVar('T')


def window(iterator: Iterable[T], behind: int = 0, ahead: int = 0) -> Iterator[Tuple[Optional[T], ...]]:
    """
    Sliding window for an iterator.

            

Reported by Pylint.

Class name "T" doesn't conform to PascalCase naming style
Error

Line: 4 Column: 1

              import itertools
from typing import TypeVar, Iterable, Iterator, Tuple, Optional, List

T = TypeVar('T')


def window(iterator: Iterable[T], behind: int = 0, ahead: int = 0) -> Iterator[Tuple[Optional[T], ...]]:
    """
    Sliding window for an iterator.

            

Reported by Pylint.

Line too long (104/100)
Error

Line: 7 Column: 1

              T = TypeVar('T')


def window(iterator: Iterable[T], behind: int = 0, ahead: int = 0) -> Iterator[Tuple[Optional[T], ...]]:
    """
    Sliding window for an iterator.

    Example:
        >>> for prev, i, nxt in window(range(10), 1, 1):

            

Reported by Pylint.

test/helper_tools/memoryleak2.py
4 issues
Unable to import 'objgraph'
Error

Line: 4 Column: 1

              import secrets
from pathlib import Path

import objgraph

from mitmproxy import certs

if __name__ == "__main__":
    store = certs.CertStore.from_store(path=Path("~/.mitmproxy/").expanduser(), basename="mitmproxy", key_size=2048)

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 6 Column: 1

              
import objgraph

from mitmproxy import certs

if __name__ == "__main__":
    store = certs.CertStore.from_store(path=Path("~/.mitmproxy/").expanduser(), basename="mitmproxy", key_size=2048)
    store.STORE_CAP = 5


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import secrets
from pathlib import Path

import objgraph

from mitmproxy import certs

if __name__ == "__main__":
    store = certs.CertStore.from_store(path=Path("~/.mitmproxy/").expanduser(), basename="mitmproxy", key_size=2048)

            

Reported by Pylint.

Line too long (116/100)
Error

Line: 9 Column: 1

              from mitmproxy import certs

if __name__ == "__main__":
    store = certs.CertStore.from_store(path=Path("~/.mitmproxy/").expanduser(), basename="mitmproxy", key_size=2048)
    store.STORE_CAP = 5

    for _ in range(5):
        store.get_cert(commonname=secrets.token_hex(16).encode(), sans=[], organization=None)


            

Reported by Pylint.

mitmproxy/utils/emoji.py
4 issues
Too many lines in module (1887/1000)
Error

Line: 1 Column: 1

              #!/usr/bin/env python3
"""
All of the emoji and characters that can be used as flow markers.
"""

# auto-generated. run this file to refresh.

emoji = {
    ":+1:": "👍",

            

Reported by Pylint.

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

Line: 1873 Column: 13

                  for name, url in r.json().items():
        codepoints = url.rpartition("/")[2].partition(".png")[0].split("-")
        try:
            emoji_val = "\u200d".join(chr(int(c, 16)) for c in codepoints)
        except ValueError:
            continue  # some GitHub-specific emojis, e.g. "atom".
        print(EMOJI_SRC.format(name=name, emoji_val=emoji_val), file=out)

    # add the default marker

            

Reported by Pylint.

Line too long (105/100)
Error

Line: 1885 Column: 1

                      print(CHAR_SRC.format(name=c, emoji_val=c), file=out)

    Path(__file__).write_text(
        re.sub(r"(?<={\n)[\s\S]*(?=}\n)", lambda x: out.getvalue(), Path(__file__).read_text("utf8"), 1),
        "utf8"
    )
            

Reported by Pylint.

Final newline missing
Error

Line: 1887 Column: 1

                  Path(__file__).write_text(
        re.sub(r"(?<={\n)[\s\S]*(?=}\n)", lambda x: out.getvalue(), Path(__file__).read_text("utf8"), 1),
        "utf8"
    )
            

Reported by Pylint.

test/mitmproxy/data/addonscripts/error.py
4 issues
Unable to import 'mitmproxy'
Error

Line: 1 Column: 1

              from mitmproxy import ctx


def running():
    ctx.log.info("error running")


def request(flow):
    raise ValueError("Error!")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from mitmproxy import ctx


def running():
    ctx.log.info("error running")


def request(flow):
    raise ValueError("Error!")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 1

              from mitmproxy import ctx


def running():
    ctx.log.info("error running")


def request(flow):
    raise ValueError("Error!")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

                  ctx.log.info("error running")


def request(flow):
    raise ValueError("Error!")

            

Reported by Pylint.

examples/addons/http-add-header.py
4 issues
Module name "http-add-header" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              """Add an HTTP header to each response."""


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

    def response(self, flow):
        self.num = self.num + 1

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              """Add an HTTP header to each response."""


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

    def response(self, flow):
        self.num = self.num + 1

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 4 Column: 1

              """Add an HTTP header to each response."""


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

    def response(self, flow):
        self.num = self.num + 1

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 5

                  def __init__(self):
        self.num = 0

    def response(self, flow):
        self.num = self.num + 1
        flow.response.headers["count"] = str(self.num)


addons = [

            

Reported by Pylint.

test/mitmproxy/tools/test_main.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

              import asyncio

from mitmproxy.tools import main


shutdown_script = "mitmproxy/data/addonscripts/shutdown.py"


def test_mitmweb(event_loop, tdata):

            

Reported by Pylint.

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

Line: 6 Column: 1

              from mitmproxy.tools import main


shutdown_script = "mitmproxy/data/addonscripts/shutdown.py"


def test_mitmweb(event_loop, tdata):
    asyncio.set_event_loop(event_loop)
    main.mitmweb([

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              shutdown_script = "mitmproxy/data/addonscripts/shutdown.py"


def test_mitmweb(event_loop, tdata):
    asyncio.set_event_loop(event_loop)
    main.mitmweb([
        "--no-web-open-browser",
        "-s", tdata.path(shutdown_script),
        "-q", "-p", "0", "--web-port", "0",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 1

                  ])


def test_mitmdump(event_loop, tdata):
    asyncio.set_event_loop(event_loop)
    main.mitmdump([
        "-s", tdata.path(shutdown_script),
        "-q", "-p", "0",
    ])

            

Reported by Pylint.

examples/addons/http-stream-modify.py
4 issues
Module name "http-stream-modify" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              """
Modify a streamed response.

Generally speaking, we recommend *not* to stream messages you need to modify.
Modifying streamed responses is tricky and brittle:
    - If the transfer encoding isn't chunked, you cannot simply change the content length.
    - If you want to replace all occurrences of "foobar", make sure to catch the cases
      where one chunk ends with [...]foo" and the next starts with "bar[...].
"""

            

Reported by Pylint.

Line too long (104/100)
Error

Line: 15 Column: 1

              
def modify(data: bytes) -> Union[bytes, Iterable[bytes]]:
    """
    This function will be called for each chunk of request/response body data that arrives at the proxy,
    and once at the end of the message with an empty bytes argument (b"").

    It may either return bytes or an iterable of bytes (which would result in multiple HTTP/2 data frames).
    """
    return data.replace(b"foo", b"bar")

            

Reported by Pylint.

Line too long (107/100)
Error

Line: 18 Column: 1

                  This function will be called for each chunk of request/response body data that arrives at the proxy,
    and once at the end of the message with an empty bytes argument (b"").

    It may either return bytes or an iterable of bytes (which would result in multiple HTTP/2 data frames).
    """
    return data.replace(b"foo", b"bar")


def responseheaders(flow):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

                  return data.replace(b"foo", b"bar")


def responseheaders(flow):
    flow.response.stream = modify

            

Reported by Pylint.