MCPcopy
hub / github.com/mitmproxy/mitmproxy / serialize

Function serialize

mitmproxy/optmanager.py:584–605  ·  view source on GitHub ↗

Performs a round-trip serialization. If text is not None, it is treated as a previous serialization that should be modified in-place. - If "defaults" is False, only options with non-default values are serialized. Default values in text are preserved. - Unknown options i

(
    opts: OptManager, file: TextIO, text: str, defaults: bool = False
)

Source from the content-addressed store, hash-verified

582
583
584def serialize(
585 opts: OptManager, file: TextIO, text: str, defaults: bool = False
586) -> None:
587 """
588 Performs a round-trip serialization. If text is not None, it is
589 treated as a previous serialization that should be modified
590 in-place.
591
592 - If "defaults" is False, only options with non-default values are
593 serialized. Default values in text are preserved.
594 - Unknown options in text are removed.
595 - Raises OptionsError if text is invalid.
596 """
597 data = parse(text)
598 for k in opts.keys():
599 if defaults or opts.has_changed(k):
600 data[k] = getattr(opts, k)
601 for k in list(data.keys()):
602 if k not in opts._options:
603 del data[k]
604
605 ruamel.yaml.YAML().dump(data, file)
606
607
608def save(opts: OptManager, path: Path | str, defaults: bool = False) -> None:

Callers 1

saveFunction · 0.70

Calls 4

parseFunction · 0.70
keysMethod · 0.45
has_changedMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…