MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / parse

Method parse

mitmproxy/proxy/mode_specs.py:99–136  ·  view source on GitHub ↗

Parse a proxy mode specification and return the corresponding `ProxyMode` instance.

(cls, spec: str)

Source from the content-addressed store, hash-verified

97 @classmethod
98 @cache
99 def parse(cls, spec: str) -> Self:
100 """
101 Parse a proxy mode specification and return the corresponding `ProxyMode` instance.
102 """
103 head, _, listen_at = spec.rpartition("@")
104 if not head:
105 head = listen_at
106 listen_at = ""
107
108 mode, _, data = head.partition(":")
109
110 if listen_at:
111 if ":" in listen_at:
112 host, _, port_str = listen_at.rpartition(":")
113 else:
114 host = None
115 port_str = listen_at
116 try:
117 port = int(port_str)
118 if port < 0 or 65535 < port:
119 raise ValueError
120 except ValueError:
121 raise ValueError(f"invalid port: {port_str}")
122 else:
123 host = None
124 port = None
125
126 try:
127 mode_cls = ProxyMode.__types[mode.lower()]
128 except KeyError:
129 raise ValueError(f"unknown mode")
130
131 if not issubclass(mode_cls, cls):
132 raise ValueError(f"{mode!r} is not a spec for a {cls.type_name} mode")
133
134 return mode_cls(
135 full_spec=spec, data=data, custom_listen_host=host, custom_listen_port=port
136 )
137
138 def listen_host(self, default: str | None = None) -> str:
139 """

Callers 15

parse_specFunction · 0.45
makeMethod · 0.45
from_stateMethod · 0.45
__post_init__Method · 0.45
__post_init__Method · 0.45
handleFunction · 0.45
_read_request_lineFunction · 0.45
configureMethod · 0.45
parse_specFunction · 0.45
set_filter_cmdMethod · 0.45
resolveMethod · 0.45
configureMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected