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

Method read_replacement

mitmproxy/addons/modifyheaders.py:21–33  ·  view source on GitHub ↗

Process the replacement str. This usually just involves converting it to bytes. However, if it starts with `@`, we interpret the rest as a file path to read from. Raises: - IOError if the file cannot be read.

(self)

Source from the content-addressed store, hash-verified

19 replacement_str: str
20
21 def read_replacement(self) -> bytes:
22 """
23 Process the replacement str. This usually just involves converting it to bytes.
24 However, if it starts with `@`, we interpret the rest as a file path to read from.
25
26 Raises:
27 - IOError if the file cannot be read.
28 """
29 if self.replacement_str.startswith("@"):
30 return Path(self.replacement_str[1:]).expanduser().read_bytes()
31 else:
32 # We could cache this at some point, but unlikely to be a problem.
33 return strutils.escaped_str_to_bytes(self.replacement_str)
34
35
36def parse_modify_spec(option: str, subject_is_regex: bool) -> ModifySpec:

Callers 4

parse_modify_specFunction · 0.95
test_parse_modify_specFunction · 0.80
runMethod · 0.80
runMethod · 0.80

Calls 1

PathClass · 0.85

Tested by 1

test_parse_modify_specFunction · 0.64