MCPcopy
hub / github.com/mitmproxy/mitmproxy / set

Method set

mitmproxy/optmanager.py:310–347  ·  view source on GitHub ↗

Takes a list of set specification in standard form (option=value). Options that are known are updated immediately. If defer is true, options that are not known are deferred, and will be set once they are added. May raise an `OptionsError` if a value is malfo

(self, *specs: str, defer: bool = False)

Source from the content-addressed store, hash-verified

308 )
309
310 def set(self, *specs: str, defer: bool = False) -> None:
311 """
312 Takes a list of set specification in standard form (option=value).
313 Options that are known are updated immediately. If defer is true,
314 options that are not known are deferred, and will be set once they
315 are added.
316
317 May raise an `OptionsError` if a value is malformed or an option is unknown and defer is False.
318 """
319 # First, group specs by option name.
320 unprocessed: dict[str, list[str]] = {}
321 for spec in specs:
322 if "=" in spec:
323 name, value = spec.split("=", maxsplit=1)
324 unprocessed.setdefault(name, []).append(value)
325 else:
326 unprocessed.setdefault(spec, [])
327
328 # Second, convert values to the correct type.
329 processed: dict[str, Any] = {}
330 for name in list(unprocessed.keys()):
331 if name in self._options:
332 processed[name] = self._parse_setval(
333 self._options[name], unprocessed.pop(name)
334 )
335
336 # Third, stash away unrecognized options or complain about them.
337 if defer:
338 self.deferred.update(
339 {k: _UnconvertedStrings(v) for k, v in unprocessed.items()}
340 )
341 elif unprocessed:
342 raise exceptions.OptionsError(
343 f"Unknown option(s): {', '.join(unprocessed)}"
344 )
345
346 # Finally, apply updated options.
347 self.update(**processed)
348
349 def process_deferred(self) -> None:
350 """

Callers

nothing calls this directly

Calls 10

_parse_setvalMethod · 0.95
updateMethod · 0.95
_UnconvertedStringsClass · 0.85
splitMethod · 0.45
appendMethod · 0.45
setdefaultMethod · 0.45
keysMethod · 0.45
popMethod · 0.45
itemsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected