The following issues were found

test/mitmproxy/tools/web/test_master.py
10 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import options
from mitmproxy.tools.web import master

from ... import tservers


class TestWebMaster(tservers.MasterTest):

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              from mitmproxy import options
from mitmproxy.tools.web import master

from ... import tservers


class TestWebMaster(tservers.MasterTest):
    def mkmaster(self, **opts):
        o = options.Options(**opts)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import options
from mitmproxy.tools.web import master

from ... import tservers


class TestWebMaster(tservers.MasterTest):

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from ... import tservers


class TestWebMaster(tservers.MasterTest):
    def mkmaster(self, **opts):
        o = options.Options(**opts)
        return master.WebMaster(o)

    @pytest.mark.asyncio

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 5

              

class TestWebMaster(tservers.MasterTest):
    def mkmaster(self, **opts):
        o = options.Options(**opts)
        return master.WebMaster(o)

    @pytest.mark.asyncio
    async def test_basic(self):

            

Reported by Pylint.

Method could be a function
Error

Line: 10 Column: 5

              

class TestWebMaster(tservers.MasterTest):
    def mkmaster(self, **opts):
        o = options.Options(**opts)
        return master.WebMaster(o)

    @pytest.mark.asyncio
    async def test_basic(self):

            

Reported by Pylint.

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

Line: 11 Column: 9

              
class TestWebMaster(tservers.MasterTest):
    def mkmaster(self, **opts):
        o = options.Options(**opts)
        return master.WebMaster(o)

    @pytest.mark.asyncio
    async def test_basic(self):
        m = self.mkmaster()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

                      return master.WebMaster(o)

    @pytest.mark.asyncio
    async def test_basic(self):
        m = self.mkmaster()
        for i in (1, 2, 3):
            await self.dummy_cycle(m, 1, b"")
            assert len(m.view) == i

            

Reported by Pylint.

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

Line: 16 Column: 9

              
    @pytest.mark.asyncio
    async def test_basic(self):
        m = self.mkmaster()
        for i in (1, 2, 3):
            await self.dummy_cycle(m, 1, b"")
            assert len(m.view) == i

            

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

                      m = self.mkmaster()
        for i in (1, 2, 3):
            await self.dummy_cycle(m, 1, b"")
            assert len(m.view) == i

            

Reported by Bandit.

examples/addons/commands-flows.py
10 issues
Unable to import 'mitmproxy'
Error

Line: 4 Column: 1

              """Handle flows as command arguments."""
import typing

from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import flow
from mitmproxy import http



            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 5 Column: 1

              import typing

from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import flow
from mitmproxy import http


class MyAddon:

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 6 Column: 1

              
from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import flow
from mitmproxy import http


class MyAddon:
    @command.command("myaddon.addheader")

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 7 Column: 1

              from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import flow
from mitmproxy import http


class MyAddon:
    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:

            

Reported by Pylint.

Module name "commands-flows" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              """Handle flows as command arguments."""
import typing

from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import flow
from mitmproxy import http



            

Reported by Pylint.

Missing class docstring
Error

Line: 10 Column: 1

              from mitmproxy import http


class MyAddon:
    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:
        for f in flows:
            if isinstance(f, http.HTTPFlow):
                f.request.headers["myheader"] = "value"

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 10 Column: 1

              from mitmproxy import http


class MyAddon:
    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:
        for f in flows:
            if isinstance(f, http.HTTPFlow):
                f.request.headers["myheader"] = "value"

            

Reported by Pylint.

Method could be a function
Error

Line: 12 Column: 5

              
class MyAddon:
    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:
        for f in flows:
            if isinstance(f, http.HTTPFlow):
                f.request.headers["myheader"] = "value"
        ctx.log.alert("done")


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 5

              
class MyAddon:
    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:
        for f in flows:
            if isinstance(f, http.HTTPFlow):
                f.request.headers["myheader"] = "value"
        ctx.log.alert("done")


            

Reported by Pylint.

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

Line: 13 Column: 13

              class MyAddon:
    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:
        for f in flows:
            if isinstance(f, http.HTTPFlow):
                f.request.headers["myheader"] = "value"
        ctx.log.alert("done")



            

Reported by Pylint.

mitmproxy/contentviews/wbxml.py
10 issues
Attempted relative import beyond top-level package
Error

Line: 4 Column: 1

              from typing import Optional

from mitmproxy.contrib.wbxml import ASCommandResponse
from . import base


class ViewWBXML(base.View):
    name = "WBXML"
    __content_types = (

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 20 Column: 9

                          parsedContent = parser.xmlString
            if parsedContent:
                return "WBXML", base.format_text(parsedContent)
        except:
            return None

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(content_type in self.__content_types)

            

Reported by Pylint.

Unused argument 'metadata'
Error

Line: 23 Column: 1

                      except:
            return None

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(content_type in self.__content_types)

            

Reported by Pylint.

Unused argument 'data'
Error

Line: 23 Column: 31

                      except:
            return None

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(content_type in self.__content_types)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

from mitmproxy.contrib.wbxml import ASCommandResponse
from . import base


class ViewWBXML(base.View):
    name = "WBXML"
    __content_types = (

            

Reported by Pylint.

Missing class docstring
Error

Line: 7 Column: 1

              from . import base


class ViewWBXML(base.View):
    name = "WBXML"
    __content_types = (
        "application/vnd.wap.wbxml",
        "application/vnd.ms-sync.wbxml"
    )

            

Reported by Pylint.

Either all return statements in a function should return an expression, or none of them should.
Error

Line: 14 Column: 5

                      "application/vnd.ms-sync.wbxml"
    )

    def __call__(self, data, **metadata):
        try:
            parser = ASCommandResponse.ASCommandResponse(data)
            parsedContent = parser.xmlString
            if parsedContent:
                return "WBXML", base.format_text(parsedContent)

            

Reported by Pylint.

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

Line: 17 Column: 13

                  def __call__(self, data, **metadata):
        try:
            parser = ASCommandResponse.ASCommandResponse(data)
            parsedContent = parser.xmlString
            if parsedContent:
                return "WBXML", base.format_text(parsedContent)
        except:
            return None


            

Reported by Pylint.

Line too long (103/100)
Error

Line: 23 Column: 1

                      except:
            return None

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(content_type in self.__content_types)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 5

                      except:
            return None

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(content_type in self.__content_types)

            

Reported by Pylint.

examples/addons/filter-flows.py
10 issues
Unable to import 'mitmproxy'
Error

Line: 4 Column: 1

              """
Use mitmproxy's filter pattern in scripts.
"""
from mitmproxy import flowfilter
from mitmproxy import ctx, http


class Filter:
    def __init__(self):

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 5 Column: 1

              Use mitmproxy's filter pattern in scripts.
"""
from mitmproxy import flowfilter
from mitmproxy import ctx, http


class Filter:
    def __init__(self):
        self.filter: flowfilter.TFilter = None

            

Reported by Pylint.

Unused argument 'updated'
Error

Line: 12 Column: 25

                  def __init__(self):
        self.filter: flowfilter.TFilter = None

    def configure(self, updated):
        self.filter = flowfilter.parse(ctx.options.flowfilter)

    def load(self, l):
        l.add_option(
            "flowfilter", str, "", "Check that flow matches filter."

            

Reported by Pylint.

Module name "filter-flows" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              """
Use mitmproxy's filter pattern in scripts.
"""
from mitmproxy import flowfilter
from mitmproxy import ctx, http


class Filter:
    def __init__(self):

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from mitmproxy import ctx, http


class Filter:
    def __init__(self):
        self.filter: flowfilter.TFilter = None

    def configure(self, updated):
        self.filter = flowfilter.parse(ctx.options.flowfilter)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 5

                  def __init__(self):
        self.filter: flowfilter.TFilter = None

    def configure(self, updated):
        self.filter = flowfilter.parse(ctx.options.flowfilter)

    def load(self, l):
        l.add_option(
            "flowfilter", str, "", "Check that flow matches filter."

            

Reported by Pylint.

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

Line: 15 Column: 5

                  def configure(self, updated):
        self.filter = flowfilter.parse(ctx.options.flowfilter)

    def load(self, l):
        l.add_option(
            "flowfilter", str, "", "Check that flow matches filter."
        )

    def response(self, flow: http.HTTPFlow) -> None:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

                  def configure(self, updated):
        self.filter = flowfilter.parse(ctx.options.flowfilter)

    def load(self, l):
        l.add_option(
            "flowfilter", str, "", "Check that flow matches filter."
        )

    def response(self, flow: http.HTTPFlow) -> None:

            

Reported by Pylint.

Method could be a function
Error

Line: 15 Column: 5

                  def configure(self, updated):
        self.filter = flowfilter.parse(ctx.options.flowfilter)

    def load(self, l):
        l.add_option(
            "flowfilter", str, "", "Check that flow matches filter."
        )

    def response(self, flow: http.HTTPFlow) -> None:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 5

                          "flowfilter", str, "", "Check that flow matches filter."
        )

    def response(self, flow: http.HTTPFlow) -> None:
        if flowfilter.match(self.filter, flow):
            ctx.log.info("Flow matches filter:")
            ctx.log.info(flow)



            

Reported by Pylint.

examples/addons/options-configure.py
10 issues
Unable to import 'mitmproxy'
Error

Line: 4 Column: 1

              """React to configuration changes."""
import typing

from mitmproxy import ctx
from mitmproxy import exceptions


class AddHeader:
    def load(self, loader):

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 5 Column: 1

              import typing

from mitmproxy import ctx
from mitmproxy import exceptions


class AddHeader:
    def load(self, loader):
        loader.add_option(

            

Reported by Pylint.

Module name "options-configure" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              """React to configuration changes."""
import typing

from mitmproxy import ctx
from mitmproxy import exceptions


class AddHeader:
    def load(self, loader):

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from mitmproxy import exceptions


class AddHeader:
    def load(self, loader):
        loader.add_option(
            name = "addheader",
            typespec = typing.Optional[int],
            default = None,

            

Reported by Pylint.

Method could be a function
Error

Line: 9 Column: 5

              

class AddHeader:
    def load(self, loader):
        loader.add_option(
            name = "addheader",
            typespec = typing.Optional[int],
            default = None,
            help = "Add a header to responses",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

              

class AddHeader:
    def load(self, loader):
        loader.add_option(
            name = "addheader",
            typespec = typing.Optional[int],
            default = None,
            help = "Add a header to responses",

            

Reported by Pylint.

Method could be a function
Error

Line: 17 Column: 5

                          help = "Add a header to responses",
        )

    def configure(self, updates):
        if "addheader" in updates:
            if ctx.options.addheader is not None and ctx.options.addheader > 100:
                raise exceptions.OptionsError("addheader must be <= 100")

    def response(self, flow):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 5

                          help = "Add a header to responses",
        )

    def configure(self, updates):
        if "addheader" in updates:
            if ctx.options.addheader is not None and ctx.options.addheader > 100:
                raise exceptions.OptionsError("addheader must be <= 100")

    def response(self, flow):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 5

                          if ctx.options.addheader is not None and ctx.options.addheader > 100:
                raise exceptions.OptionsError("addheader must be <= 100")

    def response(self, flow):
        if ctx.options.addheader is not None:
            flow.response.headers["addheader"] = str(ctx.options.addheader)


addons = [

            

Reported by Pylint.

Method could be a function
Error

Line: 22 Column: 5

                          if ctx.options.addheader is not None and ctx.options.addheader > 100:
                raise exceptions.OptionsError("addheader must be <= 100")

    def response(self, flow):
        if ctx.options.addheader is not None:
            flow.response.headers["addheader"] = str(ctx.options.addheader)


addons = [

            

Reported by Pylint.

test/mitmproxy/tools/console/test_common.py
10 issues
Unable to import 'urwid'
Error

Line: 1 Column: 1

              import urwid

from mitmproxy.test import tflow
from mitmproxy.tools.console import common


def test_format_flow():
    flows = [
        tflow.tflow(resp=True),

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import urwid

from mitmproxy.test import tflow
from mitmproxy.tools.console import common


def test_format_flow():
    flows = [
        tflow.tflow(resp=True),

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              from mitmproxy.tools.console import common


def test_format_flow():
    flows = [
        tflow.tflow(resp=True),
        tflow.tflow(err=True),
        tflow.ttcpflow(),
        tflow.ttcpflow(err=True),

            

Reported by Pylint.

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

Line: 14 Column: 9

                      tflow.ttcpflow(),
        tflow.ttcpflow(err=True),
    ]
    for f in flows:
        for render_mode in common.RenderMode:
            assert common.format_flow(f, render_mode=render_mode)
            assert common.format_flow(f, render_mode=render_mode, hostheader=True, focused=False)



            

Reported by Pylint.

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

                  ]
    for f in flows:
        for render_mode in common.RenderMode:
            assert common.format_flow(f, render_mode=render_mode)
            assert common.format_flow(f, render_mode=render_mode, hostheader=True, focused=False)


def test_format_keyvals():
    assert common.format_keyvals(

            

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

                  for f in flows:
        for render_mode in common.RenderMode:
            assert common.format_flow(f, render_mode=render_mode)
            assert common.format_flow(f, render_mode=render_mode, hostheader=True, focused=False)


def test_format_keyvals():
    assert common.format_keyvals(
        [

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 20 Column: 1

                          assert common.format_flow(f, render_mode=render_mode, hostheader=True, focused=False)


def test_format_keyvals():
    assert common.format_keyvals(
        [
            ("aa", "bb"),
            ("cc", "dd"),
            ("ee", None),

            

Reported by Pylint.

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

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

              

def test_format_keyvals():
    assert common.format_keyvals(
        [
            ("aa", "bb"),
            ("cc", "dd"),
            ("ee", None),
        ]

            

Reported by Bandit.

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

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

                          common.format_keyvals([("foo", "bar")])
        )
    )
    assert wrapped.render((30,))
    assert common.format_keyvals(
        [
            ("aa", wrapped)
        ]
    )

            

Reported by Bandit.

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

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

                      )
    )
    assert wrapped.render((30,))
    assert common.format_keyvals(
        [
            ("aa", wrapped)
        ]
    )

            

Reported by Bandit.

mitmproxy/contentviews/image/view.py
10 issues
Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              
from mitmproxy.contentviews import base
from mitmproxy.coretypes import multidict
from . import image_parser


def test_ico(h, f):
    if h.startswith(b"\x00\x00\x01\x00"):
        return "ico"

            

Reported by Pylint.

Unused argument 'f'
Error

Line: 9 Column: 17

              from . import image_parser


def test_ico(h, f):
    if h.startswith(b"\x00\x00\x01\x00"):
        return "ico"


imghdr.tests.append(test_ico)

            

Reported by Pylint.

Unused argument 'metadata'
Error

Line: 40 Column: 1

                          view_name = "Unknown Image"
        return view_name, base.format_dict(multidict.MultiDict(image_metadata))

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(bool(
            content_type
            and content_type.startswith("image/")
            and content_type != "image/svg+xml"
        ))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import imghdr
from typing import Optional

from mitmproxy.contentviews import base
from mitmproxy.coretypes import multidict
from . import image_parser


def test_ico(h, f):

            

Reported by Pylint.

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

Line: 9 Column: 1

              from . import image_parser


def test_ico(h, f):
    if h.startswith(b"\x00\x00\x01\x00"):
        return "ico"


imghdr.tests.append(test_ico)

            

Reported by Pylint.

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

Line: 9 Column: 1

              from . import image_parser


def test_ico(h, f):
    if h.startswith(b"\x00\x00\x01\x00"):
        return "ico"


imghdr.tests.append(test_ico)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              from . import image_parser


def test_ico(h, f):
    if h.startswith(b"\x00\x00\x01\x00"):
        return "ico"


imghdr.tests.append(test_ico)

            

Reported by Pylint.

Either all return statements in a function should return an expression, or none of them should.
Error

Line: 9 Column: 1

              from . import image_parser


def test_ico(h, f):
    if h.startswith(b"\x00\x00\x01\x00"):
        return "ico"


imghdr.tests.append(test_ico)

            

Reported by Pylint.

Missing class docstring
Error

Line: 17 Column: 1

              imghdr.tests.append(test_ico)


class ViewImage(base.View):
    name = "Image"

    def __call__(self, data, **metadata):
        image_type = imghdr.what('', h=data)
        if image_type == 'png':

            

Reported by Pylint.

Line too long (103/100)
Error

Line: 40 Column: 1

                          view_name = "Unknown Image"
        return view_name, base.format_dict(multidict.MultiDict(image_metadata))

    def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
        return float(bool(
            content_type
            and content_type.startswith("image/")
            and content_type != "image/svg+xml"
        ))

            

Reported by Pylint.

test/mitmproxy/io/test_compat.py
10 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import io
from mitmproxy import exceptions


@pytest.mark.parametrize("dumpfile, url, count", [
    ["dumpfile-011.mitm", "https://example.com/", 1],
    ["dumpfile-018.mitm", "https://www.example.com/", 1],

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 3 Column: 1

              import pytest

from mitmproxy import io
from mitmproxy import exceptions


@pytest.mark.parametrize("dumpfile, url, count", [
    ["dumpfile-011.mitm", "https://example.com/", 1],
    ["dumpfile-018.mitm", "https://www.example.com/", 1],

            

Reported by Pylint.

Unable to import 'mitmproxy'
Error

Line: 4 Column: 1

              import pytest

from mitmproxy import io
from mitmproxy import exceptions


@pytest.mark.parametrize("dumpfile, url, count", [
    ["dumpfile-011.mitm", "https://example.com/", 1],
    ["dumpfile-018.mitm", "https://www.example.com/", 1],

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from mitmproxy import io
from mitmproxy import exceptions


@pytest.mark.parametrize("dumpfile, url, count", [
    ["dumpfile-011.mitm", "https://example.com/", 1],
    ["dumpfile-018.mitm", "https://www.example.com/", 1],

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

                  ["dumpfile-019.mitm", "https://webrv.rtb-seller.com/", 1],
    ["dumpfile-7-websocket.mitm", "https://echo.websocket.org/", 6],
    ["dumpfile-10.mitm", "https://example.com/", 1]
])
def test_load(tdata, dumpfile, url, count):
    with open(tdata.path("mitmproxy/data/" + dumpfile), "rb") as f:
        flow_reader = io.FlowReader(f)
        flows = list(flow_reader.stream())
        assert len(flows) == count

            

Reported by Pylint.

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

Line: 15 Column: 66

                  ["dumpfile-10.mitm", "https://example.com/", 1]
])
def test_load(tdata, dumpfile, url, count):
    with open(tdata.path("mitmproxy/data/" + dumpfile), "rb") as f:
        flow_reader = io.FlowReader(f)
        flows = list(flow_reader.stream())
        assert len(flows) == count
        assert flows[-1].request.url.startswith(url)


            

Reported by Pylint.

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

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

                  with open(tdata.path("mitmproxy/data/" + dumpfile), "rb") as f:
        flow_reader = io.FlowReader(f)
        flows = list(flow_reader.stream())
        assert len(flows) == count
        assert flows[-1].request.url.startswith(url)


def test_cannot_convert(tdata):
    with open(tdata.path("mitmproxy/data/dumpfile-010.mitm"), "rb") as f:

            

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

                      flow_reader = io.FlowReader(f)
        flows = list(flow_reader.stream())
        assert len(flows) == count
        assert flows[-1].request.url.startswith(url)


def test_cannot_convert(tdata):
    with open(tdata.path("mitmproxy/data/dumpfile-010.mitm"), "rb") as f:
        flow_reader = io.FlowReader(f)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 22 Column: 1

                      assert flows[-1].request.url.startswith(url)


def test_cannot_convert(tdata):
    with open(tdata.path("mitmproxy/data/dumpfile-010.mitm"), "rb") as f:
        flow_reader = io.FlowReader(f)
        with pytest.raises(exceptions.FlowReadException):
            list(flow_reader.stream())

            

Reported by Pylint.

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

Line: 23 Column: 72

              

def test_cannot_convert(tdata):
    with open(tdata.path("mitmproxy/data/dumpfile-010.mitm"), "rb") as f:
        flow_reader = io.FlowReader(f)
        with pytest.raises(exceptions.FlowReadException):
            list(flow_reader.stream())

            

Reported by Pylint.

test/mitmproxy/utils/test_asyncio_utils.py
10 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              import asyncio

import pytest

from mitmproxy.utils import asyncio_utils


async def ttask():
    asyncio_utils.set_task_debug_info(

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import asyncio

import pytest

from mitmproxy.utils import asyncio_utils


async def ttask():
    asyncio_utils.set_task_debug_info(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              from mitmproxy.utils import asyncio_utils


async def ttask():
    asyncio_utils.set_task_debug_info(
        asyncio.current_task(),
        name="newname",
    )
    await asyncio.sleep(999)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

              

@pytest.mark.asyncio
async def test_simple():
    task = asyncio_utils.create_task(
        ttask(),
        name="ttask",
        client=("127.0.0.1", 42313)
    )

            

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

                      name="ttask",
        client=("127.0.0.1", 42313)
    )
    assert asyncio_utils.task_repr(task) == "127.0.0.1:42313: ttask (age: 0s)"
    await asyncio.sleep(0)
    assert "newname" in asyncio_utils.task_repr(task)
    asyncio_utils.cancel_task(task, "bye")
    await asyncio.sleep(0)
    assert task.cancelled()

            

Reported by Bandit.

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

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

                  )
    assert asyncio_utils.task_repr(task) == "127.0.0.1:42313: ttask (age: 0s)"
    await asyncio.sleep(0)
    assert "newname" in asyncio_utils.task_repr(task)
    asyncio_utils.cancel_task(task, "bye")
    await asyncio.sleep(0)
    assert task.cancelled()



            

Reported by Bandit.

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

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

                  assert "newname" in asyncio_utils.task_repr(task)
    asyncio_utils.cancel_task(task, "bye")
    await asyncio.sleep(0)
    assert task.cancelled()


def test_closed_loop():
    # Crude test for line coverage.
    # This should eventually go, see the description in asyncio_utils.create_task for details.

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 31 Column: 1

                  assert task.cancelled()


def test_closed_loop():
    # Crude test for line coverage.
    # This should eventually go, see the description in asyncio_utils.create_task for details.
    asyncio_utils.create_task(
        ttask(),
        name="ttask",

            

Reported by Pylint.

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

Line: 38 Column: 5

                      ttask(),
        name="ttask",
    )
    t = ttask()
    with pytest.raises(RuntimeError):
        asyncio_utils.create_task(
            t,
            name="ttask",
            ignore_closed_loop=False,

            

Reported by Pylint.

Final newline missing
Error

Line: 45 Column: 1

                          name="ttask",
            ignore_closed_loop=False,
        )
    t.close()  # suppress "not awaited" warning
            

Reported by Pylint.

test/mitmproxy/addons/test_browser.py
10 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              from unittest import mock
import pytest

from mitmproxy.addons import browser
from mitmproxy.test import taddons


@pytest.mark.asyncio
async def test_browser():

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from unittest import mock
import pytest

from mitmproxy.addons import browser
from mitmproxy.test import taddons


@pytest.mark.asyncio
async def test_browser():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              

@pytest.mark.asyncio
async def test_browser():
    with mock.patch("subprocess.Popen") as po, mock.patch("shutil.which") as which:
        which.return_value = "chrome"
        b = browser.Browser()
        with taddons.context() as tctx:
            b.start()

            

Reported by Pylint.

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

Line: 10 Column: 44

              
@pytest.mark.asyncio
async def test_browser():
    with mock.patch("subprocess.Popen") as po, mock.patch("shutil.which") as which:
        which.return_value = "chrome"
        b = browser.Browser()
        with taddons.context() as tctx:
            b.start()
            assert po.called

            

Reported by Pylint.

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

Line: 12 Column: 9

              async def test_browser():
    with mock.patch("subprocess.Popen") as po, mock.patch("shutil.which") as which:
        which.return_value = "chrome"
        b = browser.Browser()
        with taddons.context() as tctx:
            b.start()
            assert po.called

            b.start()

            

Reported by Pylint.

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

                      b = browser.Browser()
        with taddons.context() as tctx:
            b.start()
            assert po.called

            b.start()
            await tctx.master.await_log("Starting additional browser")
            assert len(b.browser) == 2
            b.done()

            

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

              
            b.start()
            await tctx.master.await_log("Starting additional browser")
            assert len(b.browser) == 2
            b.done()
            assert not b.browser


@pytest.mark.asyncio

            

Reported by Bandit.

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

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

                          await tctx.master.await_log("Starting additional browser")
            assert len(b.browser) == 2
            b.done()
            assert not b.browser


@pytest.mark.asyncio
async def test_no_browser():
    with mock.patch("shutil.which") as which:

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 25 Column: 1

              

@pytest.mark.asyncio
async def test_no_browser():
    with mock.patch("shutil.which") as which:
        which.return_value = False

        b = browser.Browser()
        with taddons.context() as tctx:

            

Reported by Pylint.

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

Line: 29 Column: 9

                  with mock.patch("shutil.which") as which:
        which.return_value = False

        b = browser.Browser()
        with taddons.context() as tctx:
            b.start()
            await tctx.master.await_log("platform is not supported")

            

Reported by Pylint.