MCPcopy
hub / github.com/mitmproxy/mitmproxy / load_path

Method load_path

mitmproxy/tools/console/keymap.py:209–232  ·  view source on GitHub ↗
(self, km, p)

Source from the content-addressed store, hash-verified

207 logging.error(e)
208
209 def load_path(self, km, p):
210 if os.path.exists(p) and os.path.isfile(p):
211 with open(p, encoding="utf8") as f:
212 try:
213 txt = f.read()
214 except UnicodeDecodeError as e:
215 raise KeyBindingError(f"Encoding error - expected UTF8: {p}: {e}")
216 try:
217 vals = self.parse(txt)
218 except KeyBindingError as e:
219 raise KeyBindingError(f"Error reading {p}: {e}") from e
220 for v in vals:
221 user_ctxs = v.get("ctx", ["global"])
222 try:
223 km._check_contexts(user_ctxs)
224 km.remove(v["key"], user_ctxs)
225 km.add(
226 key=v["key"],
227 command=v["cmd"],
228 contexts=user_ctxs,
229 help=v.get("help", None),
230 )
231 except ValueError as e:
232 raise KeyBindingError(f"Error reading {p}: {e}") from e
233
234 def parse(self, text):
235 try:

Callers 3

test_load_pathFunction · 0.95
keymap_load_pathMethod · 0.95
runningMethod · 0.95

Calls 7

parseMethod · 0.95
KeyBindingErrorClass · 0.85
_check_contextsMethod · 0.80
readMethod · 0.45
getMethod · 0.45
removeMethod · 0.45
addMethod · 0.45

Tested by 1

test_load_pathFunction · 0.76