class Part(dict): def __init__(self, stream: str = Union[bytes, str], default: Optional[Dict[str, Any]] = None) -> None: self.parser = XMLParser() if isinstance(stream, str): stream = stream.encode() try: loaded = self.parser.load(stream) except Exception: if default is None: default = {} loaded = default super().__init__(loaded) def __str__(self) -> str: return dumps(self, indent=4) def __repr__(self) -> str: info = {"outer_len": len(self)} return make_repr(self, info) def dump(self) -> str: """Dump the part and return a string.""" return self.parser.dump(self)
class Part(dict): def __init__(self, string: str = "", default: Optional[Dict[str, Any]] = None) -> None: self.parser = XMLParser() try: assert string # fall into <except> clause if empty loaded = self.parser.load(string) except Exception: if default is None: default = {} loaded = default super().__init__(loaded) def __str__(self) -> str: return json.dumps(self, indent=4) def __repr__(self) -> str: string = super().__repr__() info = {"len": len(string)} return make_repr(self, info) def dump(self) -> str: """Dump the part and return a string.""" return self.parser.dump(self)
def __init__(self, string: str = "", default: Optional[Dict[str, Any]] = None) -> None: self.parser = XMLParser() try: assert string # fall into <except> clause if empty loaded = self.parser.load(string) except Exception: if default is None: default = {} loaded = default super().__init__(loaded)
def __init__(self, stream: str = Union[bytes, str], default: Optional[Dict[str, Any]] = None) -> None: self.parser = XMLParser() if isinstance(stream, str): stream = stream.encode() try: loaded = self.parser.load(stream) except Exception: if default is None: default = {} loaded = default super().__init__(loaded)
def parse(xml) -> Save: parser = XMLParser() _dict = parser.load(xml) return SaveParser._parse(_dict)