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

Function parse_spec

mitmproxy/addons/blocklist.py:17–36  ·  view source on GitHub ↗

Parses strings in the following format, enforces number of segments: /flow-filter/status

(option: str)

Source from the content-addressed store, hash-verified

15
16
17def parse_spec(option: str) -> BlockSpec:
18 """
19 Parses strings in the following format, enforces number of segments:
20
21 /flow-filter/status
22
23 """
24 sep, rem = option[0], option[1:]
25
26 parts = rem.split(sep, 2)
27 if len(parts) != 2:
28 raise ValueError("Invalid number of parameters (2 are expected)")
29 flow_patt, status = parts
30 try:
31 status_code = int(status)
32 except ValueError:
33 raise ValueError(f"Invalid HTTP status code: {status}")
34 flow_filter = flowfilter.parse(flow_patt)
35
36 return BlockSpec(matches=flow_filter, status_code=status_code)
37
38
39class BlockList:

Callers 1

configureMethod · 0.70

Calls 3

BlockSpecClass · 0.85
splitMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…