MCPcopy
hub / github.com/mitmproxy/mitmproxy / parse

Method parse

mitmproxy/tools/console/keymap.py:234–262  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

232 raise KeyBindingError(f"Error reading {p}: {e}") from e
233
234 def parse(self, text):
235 try:
236 data = ruamel.yaml.YAML(typ="safe", pure=True).load(text)
237 except ruamel.yaml.error.MarkedYAMLError as v:
238 if hasattr(v, "problem_mark"):
239 snip = v.problem_mark.get_snippet()
240 raise KeyBindingError(
241 "Key binding config error at line %s:\n%s\n%s"
242 % (v.problem_mark.line + 1, snip, v.problem)
243 )
244 else:
245 raise KeyBindingError("Could not parse key bindings.")
246 if not data:
247 return []
248 if not isinstance(data, list):
249 raise KeyBindingError("Invalid keybinding config - expected a list of keys")
250
251 for k in data:
252 unknown = k.keys() - keyAttrs.keys()
253 if unknown:
254 raise KeyBindingError("Unknown key attributes: %s" % unknown)
255 missing = requiredKeyAttrs - k.keys()
256 if missing:
257 raise KeyBindingError("Missing required key attributes: %s" % unknown)
258 for attr in k.keys():
259 if not keyAttrs[attr](k[attr]):
260 raise KeyBindingError("Invalid type for %s" % attr)
261
262 return data

Callers 4

test_parseFunction · 0.95
load_pathMethod · 0.95
tdnsflowFunction · 0.45
tclient_connFunction · 0.45

Calls 3

KeyBindingErrorClass · 0.85
loadMethod · 0.45
keysMethod · 0.45

Tested by 1

test_parseFunction · 0.76