Skip to content

Commit

Permalink
Move functionality into submodules (#174)
Browse files Browse the repository at this point in the history
* move functionality into submodules

* fix stubtests

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
mhils and autofix-ci[bot] authored Sep 2, 2024
1 parent aa00aef commit 4a45bfa
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 136 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

- Move functionality into submodules.

## 0.7.2

- Make `active_executables` raise for invalid paths on Windows.
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ anyhow = { version = "1.0.86", features = ["backtrace"] }
data-encoding = "2.6.0"
log = "0.4.22"
once_cell = "1"
pyo3 = { version = "0.21", features = ["abi3", "abi3-py310", "extension-module", "anyhow"] }
pyo3 = { version = "0.21", features = ["abi3", "abi3-py310", "extension-module", "anyhow", "experimental-declarative-modules"] }
pyo3-asyncio-0-21 = { version = "0.21", features = ["tokio-runtime"] }
pyo3-log = "0.11.0"
rand_core = { version = "0.6.4", features = ["getrandom"] }
Expand Down
8 changes: 8 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import sys
import types

from .mitmproxy_rs import *

__doc__ = mitmproxy_rs.__doc__
if hasattr(mitmproxy_rs, "__all__"):
__all__ = mitmproxy_rs.__all__

# Hacky workaround for https://github.com/PyO3/pyo3/issues/759
for k, v in vars(mitmproxy_rs).items():
if isinstance(v, types.ModuleType):
sys.modules[f"mitmproxy_rs.{k}"] = v
138 changes: 34 additions & 104 deletions mitmproxy-rs/mitmproxy_rs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
from __future__ import annotations

from pathlib import Path
from typing import Awaitable, Callable, Any, Literal
from typing import Any, Literal
from typing import final, overload, TypeVar

from . import certs, dns, local, process_info, udp, wireguard

T = TypeVar("T")

# WireGuard

async def start_wireguard_server(
host: str,
port: int,
private_key: str,
peer_public_keys: list[str],
handle_tcp_stream: Callable[[Stream], Awaitable[None]],
handle_udp_stream: Callable[[Stream], Awaitable[None]],
) -> WireGuardServer: ...

@final
class WireGuardServer:
def getsockname(self) -> tuple[str, int]: ...
def close(self) -> None: ...
async def wait_closed(self) -> None: ...
def __repr__(self) -> str: ...

def genkey() -> str: ...
def pubkey(private_key: str) -> str: ...


# Local Redirector

async def start_local_redirector(
handle_tcp_stream: Callable[[Stream], Awaitable[None]],
handle_udp_stream: Callable[[Stream], Awaitable[None]],
) -> LocalRedirector: ...

@final
class LocalRedirector:
@staticmethod
def describe_spec(spec: str) -> None: ...
def set_intercept(self, spec: str) -> None: ...
def close(self) -> None: ...
async def wait_closed(self) -> None: ...


# UDP

async def start_udp_server(
host: str,
port: int,
handle_udp_stream: Callable[[Stream], Awaitable[None]],
) -> UdpServer: ...

@final
class UdpServer:
def getsockname(self) -> tuple[str, int]: ...
def close(self) -> None: ...
async def wait_closed(self) -> None: ...
def __repr__(self) -> str: ...

async def open_udp_connection(
host: str,
port: int,
*,
local_addr: tuple[str, int] | None = None,
) -> Stream: ...

# TCP / UDP

@final
Expand All @@ -75,62 +14,53 @@ class Stream:
def write(self, data: bytes): ...
async def drain(self) -> None: ...
def write_eof(self): ...

def close(self): ...
def is_closing(self) -> bool: ...
async def wait_closed(self) -> None: ...

@overload
def get_extra_info(self, name: Literal["transport_protocol"], default: None = None) -> Literal["tcp", "udp"]: ...
def get_extra_info(
self, name: Literal["transport_protocol"], default: None = None
) -> Literal["tcp", "udp"]: ...
@overload
def get_extra_info(self, name: Literal["transport_protocol"], default: T) -> Literal["tcp", "udp"] | T: ...
def get_extra_info(
self, name: Literal["transport_protocol"], default: T
) -> Literal["tcp", "udp"] | T: ...
@overload
def get_extra_info(self, name: Literal["peername", "sockname", "original_src", "original_dst", "remote_endpoint"], default: None = None) -> tuple[str, int]: ...
def get_extra_info(
self,
name: Literal[
"peername", "sockname", "original_src", "original_dst", "remote_endpoint"
],
default: None = None,
) -> tuple[str, int]: ...
@overload
def get_extra_info(self, name: Literal["peername", "sockname", "original_src", "original_dst", "remote_endpoint"], default: T) -> tuple[str, int] | T: ...
def get_extra_info(
self,
name: Literal[
"peername", "sockname", "original_src", "original_dst", "remote_endpoint"
],
default: T,
) -> tuple[str, int] | T: ...
@overload
def get_extra_info(self, name: Literal["pid"], default: None = None) -> int: ...
@overload
def get_extra_info(self, name: Literal["pid"], default: T) -> int | T: ...
@overload
def get_extra_info(self, name: Literal["process_name"], default: None = None) -> str: ...
def get_extra_info(
self, name: Literal["process_name"], default: None = None
) -> str: ...
@overload
def get_extra_info(self, name: Literal["process_name"], default: T) -> str | T: ...
@overload
def get_extra_info(self, name: str, default: Any) -> Any: ...

def __repr__(self) -> str: ...


# Certificate Installation

def add_cert(pem: str) -> None: ...
def remove_cert() -> None: ...


# Process Info

def active_executables() -> list[Process]: ...
def executable_icon(path: Path | str) -> bytes: ...

@final
class Process:
@property
def executable(self) -> str: ...
@property
def display_name(self) -> str: ...
@property
def is_visible(self) -> bool: ...
@property
def is_system(self) -> bool: ...

# DNS resolution

@final
class DnsResolver:
def __init__(self, *, name_servers: list[str] | None = None, use_hosts_file: bool = True) -> None: ...
async def lookup_ip(self, host: str) -> list[str]: ...
async def lookup_ipv4(self, host: str) -> list[str]: ...
async def lookup_ipv6(self, host: str) -> list[str]: ...

def get_system_dns_servers(): list[str]
__all__ = [
"certs",
"dns",
"local",
"process_info",
"udp",
"wireguard",
"Stream",
]
4 changes: 4 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/certs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import annotations

def add_cert(pem: str) -> None: ...
def remove_cert() -> None: ...
13 changes: 13 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/dns.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations
from typing import final

@final
class DnsResolver:
def __init__(
self, *, name_servers: list[str] | None = None, use_hosts_file: bool = True
) -> None: ...
async def lookup_ip(self, host: str) -> list[str]: ...
async def lookup_ipv4(self, host: str) -> list[str]: ...
async def lookup_ipv6(self, host: str) -> list[str]: ...

def get_system_dns_servers() -> list[str]: ...
17 changes: 17 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/local.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

from collections.abc import Awaitable, Callable
from typing import final
from . import Stream

async def start_local_redirector(
handle_tcp_stream: Callable[[Stream], Awaitable[None]],
handle_udp_stream: Callable[[Stream], Awaitable[None]],
) -> LocalRedirector: ...
@final
class LocalRedirector:
@staticmethod
def describe_spec(spec: str) -> None: ...
def set_intercept(self, spec: str) -> None: ...
def close(self) -> None: ...
async def wait_closed(self) -> None: ...
16 changes: 16 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/process_info.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations
from pathlib import Path
from typing import final

def active_executables() -> list[Process]: ...
def executable_icon(path: Path | str) -> bytes: ...
@final
class Process:
@property
def executable(self) -> str: ...
@property
def display_name(self) -> str: ...
@property
def is_visible(self) -> bool: ...
@property
def is_system(self) -> bool: ...
24 changes: 24 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/udp.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

from collections.abc import Awaitable, Callable
from typing import final
from . import Stream

async def start_udp_server(
host: str,
port: int,
handle_udp_stream: Callable[[Stream], Awaitable[None]],
) -> UdpServer: ...
@final
class UdpServer:
def getsockname(self) -> tuple[str, int]: ...
def close(self) -> None: ...
async def wait_closed(self) -> None: ...
def __repr__(self) -> str: ...

async def open_udp_connection(
host: str,
port: int,
*,
local_addr: tuple[str, int] | None = None,
) -> Stream: ...
22 changes: 22 additions & 0 deletions mitmproxy-rs/mitmproxy_rs/wireguard.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

from collections.abc import Awaitable, Callable
from typing import final
from . import Stream

def genkey() -> str: ...
def pubkey(private_key: str) -> str: ...
async def start_wireguard_server(
host: str,
port: int,
private_key: str,
peer_public_keys: list[str],
handle_tcp_stream: Callable[[Stream], Awaitable[None]],
handle_udp_stream: Callable[[Stream], Awaitable[None]],
) -> WireGuardServer: ...
@final
class WireGuardServer:
def getsockname(self) -> tuple[str, int]: ...
def close(self) -> None: ...
async def wait_closed(self) -> None: ...
def __repr__(self) -> str: ...
Loading

0 comments on commit 4a45bfa

Please sign in to comment.