Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
    def parse(xml) -> Save:
        parser = XMLParser()
        _dict = parser.load(xml)

        return SaveParser._parse(_dict)