Skip to content

Commit

Permalink
mypy: install _all_ dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Sep 22, 2022
1 parent f89a8ce commit 0e824c6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mitmproxy/addons/dumper.py
Expand Up @@ -314,7 +314,7 @@ def websocket_end(self, f: http.HTTPFlow):

def format_websocket_error(self, websocket: WebSocketData) -> str:
try:
ret = CloseReason(websocket.close_code).name
ret = CloseReason(websocket.close_code).name # type: ignore
except ValueError:
ret = f"UNKNOWN_ERROR={websocket.close_code}"
if websocket.close_reason:
Expand Down
3 changes: 2 additions & 1 deletion mitmproxy/command.py
Expand Up @@ -5,6 +5,7 @@
import inspect
import logging

import pyparsing
import sys
import textwrap
import types
Expand Down Expand Up @@ -194,7 +195,7 @@ def parse_partial(
Parse a possibly partial command. Return a sequence of ParseResults and a sequence of remainder type help items.
"""

parts: list[str] = command_lexer.expr.parseString(cmdstr, parseAll=True)
parts: pyparsing.ParseResults = command_lexer.expr.parseString(cmdstr, parseAll=True)

parsed: list[ParseResult] = []
next_params: list[CommandParameter] = [
Expand Down
16 changes: 7 additions & 9 deletions mitmproxy/proxy/layers/http/_http1.py
Expand Up @@ -141,7 +141,7 @@ def done(self, event: events.ConnectionEvent) -> layer.CommandGenerator[None]:
def make_pipe(self) -> layer.CommandGenerator[None]:
self.state = self.passthrough
if self.buf:
already_received = self.buf.maybe_extract_at_most(len(self.buf))
already_received = self.buf.maybe_extract_at_most(len(self.buf)) or b""
# Some clients send superfluous newlines after CONNECT, we want to eat those.
already_received = already_received.lstrip(b"\r\n")
if already_received:
Expand Down Expand Up @@ -264,11 +264,10 @@ def read_headers(
if isinstance(event, events.DataReceived):
request_head = self.buf.maybe_extract_lines()
if request_head:
request_head = [
bytes(x) for x in request_head
] # TODO: Make url.parse compatible with bytearrays
try:
self.request = http1.read_request_head(request_head)
self.request = http1.read_request_head(
[bytes(x) for x in request_head]
)
if self.context.options.validate_inbound_headers:
http1.validate_headers(self.request.headers)
expected_body_size = http1.expected_http_body_size(self.request)
Expand Down Expand Up @@ -388,11 +387,10 @@ def read_headers(

response_head = self.buf.maybe_extract_lines()
if response_head:
response_head = [
bytes(x) for x in response_head
] # TODO: Make url.parse compatible with bytearrays
try:
self.response = http1.read_response_head(response_head)
self.response = http1.read_response_head(
[bytes(x) for x in response_head]
)
if self.context.options.validate_inbound_headers:
http1.validate_headers(self.response.headers)
expected_size = http1.expected_http_body_size(
Expand Down
7 changes: 3 additions & 4 deletions mitmproxy/proxy/layers/http/_upstream_proxy.py
Expand Up @@ -75,11 +75,10 @@ def receive_handshake_data(
self.buf += data
response_head = self.buf.maybe_extract_lines()
if response_head:
response_head = [
bytes(x) for x in response_head
] # TODO: Make url.parse compatible with bytearrays
try:
response = http1.read_response_head(response_head)
response = http1.read_response_head([
bytes(x) for x in response_head
])
except ValueError as e:
proxyaddr = human.format_address(self.tunnel_connection.address)
yield commands.Log(f"{proxyaddr}: {e}")
Expand Down
5 changes: 3 additions & 2 deletions mitmproxy/proxy/mode_servers.py
Expand Up @@ -144,10 +144,10 @@ async def handle_tcp_connection(
)
handler.layer = self.make_top_layer(handler.layer.context)
if isinstance(self.mode, mode_specs.TransparentMode):
socket = writer.get_extra_info("socket")
s = cast(socket.socket, writer.get_extra_info("socket"))
try:
assert platform.original_addr
original_dst = platform.original_addr(socket)
original_dst = platform.original_addr(s)
except Exception as e:
logger.error(f"Transparent mode failure: {e!r}")
return
Expand Down Expand Up @@ -390,6 +390,7 @@ async def wg_handle_tcp_connection(self, stream: wg.TcpStream) -> None:
await self.handle_tcp_connection(stream, stream)

def wg_handle_udp_datagram(self, data: bytes, remote_addr: Address, local_addr: Address) -> None:
assert self._server is not None
transport = WireGuardDatagramTransport(self._server, local_addr, remote_addr)
self.handle_udp_datagram(
transport,
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -36,6 +36,7 @@ deps =
types-requests==2.28.10
types-cryptography==3.3.23
types-pyOpenSSL==22.0.10
-e .[dev]

commands =
mypy {posargs}
Expand Down

0 comments on commit 0e824c6

Please sign in to comment.