Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
context.py59 linesDownload Raw Back to proxy
1from typing import TYPE_CHECKING2 3from mitmproxy import connection4from mitmproxy.options import Options5 6if TYPE_CHECKING:7    import mitmproxy.proxy.layer8 9 10class Context:11    """12    The context object provided to each protocol layer in the proxy core.13    """14 15    client: connection.Client16    """The client connection."""17    server: connection.Server18    """19    The server connection.20 21    For practical reasons this attribute is always set, even if there is not server connection yet.22    In this case the server address is `None`.23    """24    options: Options25    """26    Provides access to options for proxy layers. Not intended for use by addons, use `mitmproxy.ctx.options` instead.27    """28    layers: list["mitmproxy.proxy.layer.Layer"]29    """30    The protocol layer stack.31    """32 33    def __init__(34        self,35        client: connection.Client,36        options: Options,37    ) -> None:38        self.client = client39        self.options = options40        self.server = connection.Server(41            address=None, transport_protocol=client.transport_protocol42        )43        self.layers = []44 45    def fork(self) -> "Context":46        ret = Context(self.client, self.options)47        ret.server = self.server48        ret.layers = self.layers.copy()49        return ret50 51    def __repr__(self):52        return (53            f"Context(\n"54            f"  {self.client!r},\n"55            f"  {self.server!r},\n"56            f"  layers=[{self.layers!r}]\n"57            f")"58        )59 
codekingpro/portable-devtools · Team Ai