Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions httpdbg/args.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import argparse
from pathlib import Path
from typing import List, Tuple

from httpdbg.log import LogLevel


def read_args(args: List[str]) -> Tuple[argparse.Namespace, List[str]]:
def read_args(args: list[str]) -> tuple[argparse.Namespace, list[str]]:
httpdbg_args = args
client_args = []
for action in ["--console", "--module", "-m", "--script"]:
Expand Down
6 changes: 2 additions & 4 deletions httpdbg/hooks/all.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from contextlib import contextmanager
from typing import Generator
from typing import List
from typing import Tuple
from typing import Union

from httpdbg.hooks.aiohttp import hook_aiohttp
Expand All @@ -26,10 +24,10 @@
@contextmanager
def httprecord(
records: HTTPRecords = None,
initiators: Union[List[str], None] = None,
initiators: Union[list[str], None] = None,
client: bool = True,
server: bool = False,
ignore: Tuple[Tuple[str, int], ...] = (),
ignore: tuple[tuple[str, int], ...] = (),
multiprocess: bool = True,
) -> Generator[HTTPRecords, None, None]:
if records is None:
Expand Down
3 changes: 1 addition & 2 deletions httpdbg/hooks/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import tempfile
import time
import threading
from typing import List
from typing import Union

from httpdbg.env import HTTPDBG_MULTIPROCESS_DIR
Expand All @@ -18,7 +17,7 @@
@contextmanager
def watcher_external(
records: HTTPRecords,
initiators: Union[List[str], None] = None,
initiators: Union[list[str], None] = None,
server: bool = False,
) -> Generator[HTTPRecords, None, None]:
if HTTPDBG_MULTIPROCESS_DIR not in os.environ:
Expand Down
5 changes: 2 additions & 3 deletions httpdbg/hooks/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from contextlib import contextmanager
import functools
from functools import wraps
from typing import Dict
from typing import Generator
from typing import Union

Expand Down Expand Up @@ -37,7 +36,7 @@ def hook(*args, **kwargs):
def set_hook_fastapi_apirouter_add_api_route(
records: HTTPRecords,
method: Callable,
already_mapped: Union[Dict[Callable, Callable], None] = None,
already_mapped: Union[dict[Callable, Callable], None] = None,
):

@wraps(method)
Expand Down Expand Up @@ -123,7 +122,7 @@ def hook_fastapi(records: HTTPRecords) -> Generator[None, None, None]:
try:
import fastapi.routing

already_mapped: Dict[Callable, Callable] = {}
already_mapped: dict[Callable, Callable] = {}

set_hook_fastapi_apirouter_add_api_route_with_already_mapped = (
functools.partial(
Expand Down
7 changes: 3 additions & 4 deletions httpdbg/hooks/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from contextlib import contextmanager
import functools
from functools import wraps
from typing import Dict
from typing import Generator
from typing import Union

Expand Down Expand Up @@ -36,7 +35,7 @@ def hook(*args, **kwargs):
def set_hook_flask_add_url_rule(
records: HTTPRecords,
method: Callable,
already_mapped: Union[Dict[Callable, Callable], None] = None,
already_mapped: Union[dict[Callable, Callable], None] = None,
):

def hook(*args, **kwargs):
Expand Down Expand Up @@ -67,7 +66,7 @@ def hook(*args, **kwargs):
def set_hook_flask_register_error_handler(
records: HTTPRecords,
method: Callable,
already_mapped: Union[Dict[Callable, Callable], None] = None,
already_mapped: Union[dict[Callable, Callable], None] = None,
):

def hook(*args, **kwargs):
Expand Down Expand Up @@ -103,7 +102,7 @@ def hook_flask(records: HTTPRecords) -> Generator[None, None, None]:

# we must not apply the hook more than once on a mapped endpoint function
# AssertionError: View function mapping is overwriting an existing endpoint function: xxxx
already_mapped: Dict[Callable, Callable] = {}
already_mapped: dict[Callable, Callable] = {}

set_hook_flask_add_url_rule_with_already_mapped = functools.partial(
set_hook_flask_add_url_rule, already_mapped=already_mapped
Expand Down
11 changes: 5 additions & 6 deletions httpdbg/hooks/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from types import ModuleType
from typing import Any
from typing import Generator
from typing import List
from typing import Union

from httpdbg.hooks.utils import decorate
Expand Down Expand Up @@ -49,13 +48,13 @@ def hook(*args, **kwargs):

@contextmanager
def hook_generic(
records: HTTPRecords, initiators: Union[List[str], None] = None
records: HTTPRecords, initiators: Union[list[str], None] = None
) -> Generator[None, None, None]:
if initiators:
# we add a hook for a generic initiator only if the module is imported

hooks: List[Callable] = []
already_hooked: List[str] = []
hooks: list[Callable] = []
already_hooked: list[str] = []

original_builtin_import = builtins.__import__

Expand Down Expand Up @@ -130,7 +129,7 @@ def __hook__import__(
fnc = undecorate(fnc)


def list_callables_from_module(records: HTTPRecords, module: str) -> List[Any]:
def list_callables_from_module(records: HTTPRecords, module: str) -> list[Any]:
callables = []

try:
Expand Down Expand Up @@ -180,7 +179,7 @@ def list_callables_from_class(
imported_module: ModuleType,
module: str,
classname: str,
) -> List[Any]:
) -> list[Any]:
callables = []

try:
Expand Down
10 changes: 4 additions & 6 deletions httpdbg/hooks/record.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from abc import ABC, abstractmethod
import datetime
from typing import List
from typing import Tuple
from typing import Union

from httpdbg.utils import get_new_uuid
Expand All @@ -23,7 +21,7 @@ def rawheaders(self) -> bytes:

@property
@abstractmethod
def headers(self) -> List[HTTPDBGHeader]:
def headers(self) -> list[HTTPDBGHeader]:
pass

@property
Expand Down Expand Up @@ -51,7 +49,7 @@ class HTTPRecordRequest(HTTPRecordReqResp, ABC):

@property
@abstractmethod
def cookies(self) -> List[HTTPDBGCookie]:
def cookies(self) -> list[HTTPDBGCookie]:
pass

@property
Expand All @@ -74,7 +72,7 @@ class HTTPRecordResponse(HTTPRecordReqResp, ABC):

@property
@abstractmethod
def cookies(self) -> List[HTTPDBGCookie]:
def cookies(self) -> list[HTTPDBGCookie]:
pass

@property
Expand Down Expand Up @@ -107,7 +105,7 @@ def __init__(
is_client: bool = True,
) -> None:
self.id = get_new_uuid()
self.address: Tuple[str, int] = ("", 0)
self.address: tuple[str, int] = ("", 0)
self._url: Union[str, None] = None
self.initiator_id: Union[str, None] = initiator_id
self.exception: Union[Exception, None] = None
Expand Down
9 changes: 4 additions & 5 deletions httpdbg/hooks/recordhttp1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from urllib.parse import urlparse
from typing import List

from httpdbg.preview import generate_preview
from httpdbg.hooks.record import HTTPRecord
Expand All @@ -18,7 +17,7 @@ class HTTP1RecordReqResp(HTTPRecordReqResp):
def __init__(self) -> None:
self._rawdata: bytes = bytes()
self._rawheaders: bytes = bytes()
self._headers: List[HTTPDBGHeader] = []
self._headers: list[HTTPDBGHeader] = []
self.last_update: datetime.datetime = datetime.datetime.now(
datetime.timezone.utc
)
Expand All @@ -38,7 +37,7 @@ def rawheaders(self) -> bytes:
return self._rawheaders

@property
def headers(self) -> List[HTTPDBGHeader]:
def headers(self) -> list[HTTPDBGHeader]:
if not self._headers:
if self.rawheaders:
for header in self.rawheaders[self.rawheaders.find(b"\r\n") :].split(
Expand Down Expand Up @@ -98,7 +97,7 @@ def __init__(self) -> None:
self._protocol = bytes()

@property
def cookies(self) -> List[HTTPDBGCookie]:
def cookies(self) -> list[HTTPDBGCookie]:
return list_cookies_headers_request_simple_cookies(self.headers)

def _parse_first_line(self) -> None:
Expand Down Expand Up @@ -133,7 +132,7 @@ def __init__(self):
self._message = bytes()

@property
def cookies(self) -> List[HTTPDBGCookie]:
def cookies(self) -> list[HTTPDBGCookie]:
return list_cookies_headers_response_simple_cookies(self.headers)

def _parse_first_line(self) -> None:
Expand Down
12 changes: 6 additions & 6 deletions httpdbg/hooks/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
import traceback
from typing import Generator
from typing import Dict, Tuple, Union
from typing import Union

from httpdbg.initiator import httpdbg_initiator
from httpdbg.log import logger
Expand All @@ -25,9 +25,9 @@
class SocketRawData(object):
"""Store the request data without encryption, even when using an SSLSocket."""

def __init__(self, id: int, address: Tuple[str, int], ssl: bool) -> None:
def __init__(self, id: int, address: tuple[str, int], ssl: bool) -> None:
self.id: int = id
self.address: Tuple[str, int] = address
self.address: tuple[str, int] = address
self.ssl: bool = ssl
self._rawdata: bytes = bytes()
self.record: Union[HTTP1Record, None] = None
Expand Down Expand Up @@ -66,10 +66,10 @@ class TracerHTTP1:

def __init__(
self,
ignore: Tuple[Tuple[str, int], ...] = (),
ignore: tuple[tuple[str, int], ...] = (),
):
self.sockets: Dict[int, SocketRawData] = {}
self.ignore: Tuple[Tuple[str, int], ...] = ignore
self.sockets: dict[int, SocketRawData] = {}
self.ignore: tuple[tuple[str, int], ...] = ignore

def get_socket_data(
self, obj, extra_sock=None, force_new=False, request=None, is_uvicorn=False
Expand Down
12 changes: 5 additions & 7 deletions httpdbg/initiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import platform
import traceback
from typing import Generator
from typing import List
from typing import Tuple
from typing import Union
from typing import TYPE_CHECKING

Expand All @@ -25,7 +23,7 @@ def __init__(
self,
label: str,
short_stack: str,
stack: List[str],
stack: list[str],
):
self.id = get_new_uuid()
self.label = label
Expand Down Expand Up @@ -86,7 +84,7 @@ def compatible_path(path: str) -> str:
return p


def in_lib(line: str, packages: List[str] = None):
def in_lib(line: str, packages: list[str] = None):
if not packages:
packages = ["requests", "httpx", "aiohttp", "urllib3"]
return any(
Expand All @@ -99,7 +97,7 @@ def in_lib(line: str, packages: List[str] = None):

def get_current_instruction(
extracted_stack: traceback.StackSummary,
) -> Tuple[str, str, List[str]]:
) -> tuple[str, str, list[str]]:
instruction = ""
short_stack = ""
stack = []
Expand Down Expand Up @@ -161,7 +159,7 @@ def extract_short_stack_from_file(
before: int,
after: int,
stop_if_instruction_ends: bool = True,
) -> Tuple[str, str]:
) -> tuple[str, str]:
instruction = ""
short_stack = ""

Expand Down Expand Up @@ -243,7 +241,7 @@ def httpdbg_initiator(
original_method: Callable,
*args,
**kwargs,
) -> Generator[Union[Tuple[Initiator, Group, bool], None], None, None]:
) -> Generator[Union[tuple[Initiator, Group, bool], None], None, None]:

try:
if records.current_initiator is None:
Expand Down
3 changes: 1 addition & 2 deletions httpdbg/mode_console.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import code
from typing import List
from typing import Union

from httpdbg.records import HTTPRecords
Expand All @@ -15,7 +14,7 @@ class InteractiveConsoleWithHistory(code.InteractiveConsole):

def __init__(self, records: HTTPRecords, locals=None):
self.records: HTTPRecords = records
self.history: List[str] = []
self.history: list[str] = []
self.incomplete_block: bool = False
super().__init__(locals)

Expand Down
3 changes: 1 addition & 2 deletions httpdbg/mode_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import runpy
from unittest.mock import patch
import sys
from typing import List


def run_module(argv: List[str]) -> None:
def run_module(argv: list[str]) -> None:
try:
with patch.object(sys, "argv", argv):
runpy.run_module(argv[0], run_name="__main__")
Expand Down
3 changes: 1 addition & 2 deletions httpdbg/mode_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import runpy
import sys
import traceback
from typing import List

from httpdbg.log import logger


def run_script(argv: List[str]) -> None:
def run_script(argv: list[str]) -> None:

if len(argv) == 0:
exit("script mode - error - python file required, but none set")
Expand Down
8 changes: 4 additions & 4 deletions httpdbg/preview.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from typing import Tuple, Dict, Union
from typing import Union


def parse_content_type(content_type: str) -> Tuple[str, Dict[str, str]]:
def parse_content_type(content_type: str) -> tuple[str, dict[str, str]]:
s = content_type.split(";")
media_type = s[0]
directives = {}
Expand All @@ -15,8 +15,8 @@ def parse_content_type(content_type: str) -> Tuple[str, Dict[str, str]]:

def generate_preview(
raw_data: bytes, content_type: str, content_encoding: str
) -> Dict[str, Union[str, bool]]:
body: Dict[str, Union[str, bool]] = {}
) -> dict[str, Union[str, bool]]:
body: dict[str, Union[str, bool]] = {}

body["content_type"] = content_type

Expand Down
Loading
Loading