| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
from Metadata import constmethod |
| 4 |
from BaseClass import BaseClass |
| 5 |
from typing import Final |
| 6 |
|
| 7 |
class Persistence(BaseClass): |
| 8 |
""" |
| 9 |
Base.Persistence class. |
| 10 |
|
| 11 |
Class to dump and restore the content of an object. |
| 12 |
|
| 13 |
Author: Juergen Riegel ([email protected]) |
| 14 |
Licence: LGPL |
| 15 |
""" |
| 16 |
|
| 17 |
Content: Final[str] = "" |
| 18 |
"""Content of the object in XML representation.""" |
| 19 |
|
| 20 |
MemSize: Final[int] = 0 |
| 21 |
"""Memory size of the object in bytes.""" |
| 22 |
|
| 23 |
@constmethod |
| 24 |
def dumpContent(self, *, Compression: int = 3) -> bytearray: |
| 25 |
""" |
| 26 |
dumpContent(Compression=3) -> bytearray |
| 27 |
|
| 28 |
Dumps the content of the object, both the XML representation and the additional |
| 29 |
data files required, into a byte representation. |
| 30 |
|
| 31 |
Compression : int |
| 32 |
Set the data compression level in the range [0,9]. Set to 0 for no compression. |
| 33 |
""" |
| 34 |
... |
| 35 |
|
| 36 |
def restoreContent(self, obj: object) -> None: |
| 37 |
# TODO: Starting with Python 3.12, collections.abc.Buffer can be used for type hinting |
| 38 |
""" |
| 39 |
restoreContent(obj) -> None |
| 40 |
|
| 41 |
Restore the content of the object from a byte representation as stored by `dumpContent`. |
| 42 |
It could be restored from any Python object implementing the buffer protocol. |
| 43 |
|
| 44 |
obj : buffer |
| 45 |
Object with buffer protocol support. |
| 46 |
""" |
| 47 |
... |