### Implement Custom Archiving/Unarchiving Methods for Python Class Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Provides an example of a Python class that manually implements the `encode_archive` and `decode_archive` methods. These methods define how the object's properties are serialized to and deserialized from the archive, offering fine-grained control over the process. ```python from bpylist2 import archiver class MyClass: first_property = None second_property = None def __init__(self, first_property, second_property): self.first_property = first_property self.second_property = second_property def encode_archive(self, archive): archive.encode('first_property', self.first_property) archive.encode('second_property', self.second_property) def decode_archive(archive): first = archive.decode('first_property') second = archive.decode('second_property') return MyClass(first, second) ``` -------------------------------- ### Run bpylist2 Test Suite Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Command to execute the test suite for the `bpylist2` library. This uses the standard `make` utility, which typically invokes Python's `unittest` module. ```bash make test ``` -------------------------------- ### Publish bpylist2 to PyPI Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Commands to build and publish a new version of the `bpylist2` package to the Python Package Index (PyPI). This process utilizes the `poetry` tool for package management and publishing. ```bash poetry build poetry publish ``` -------------------------------- ### Register Custom Class Mapper for NSKeyedArchiver Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Shows how to register a custom Python class with the `bpylist2.archiver` to map it to a specific Cocoa class name. This mapping allows `bpylist2` to correctly handle custom objects during unarchiving by instantiating the corresponding Python class. ```python archiver.update_class_map({ 'MyCocoaClass': FooArchive }) ``` -------------------------------- ### Archive Python Object to NSKeyedArchiver Format Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Shows how to serialize a standard Python object, such as a dictionary, into the NSKeyedArchiver format using `bpylist2.archiver.archive()`. The function returns the binary data representing the archived object. ```python from bpylist2 import archiver my_object = { 'foo':'bar', 'some_array': [1,2,3,4] } archiver.archive(my_object) ``` -------------------------------- ### Unarchive NSKeyedArchiver Object in Python Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Demonstrates how to read and unarchive an NSKeyedArchiver compatible object from a file using the `bpylist2.archiver` module. The file content is read in binary mode and passed directly to the unarchive function. ```python from bpylist2 import archiver with open('my_archived_object', 'rb') as f: archiver.unarchive(f.read()) ``` -------------------------------- ### Define Custom Dataclass for NSKeyedArchiver Mapping Source: https://github.com/parabolala/bpylist2/blob/main/README.rst Illustrates how to define a Python dataclass that maps to a custom Cocoa class for serialization/deserialization. This class should inherit from `DataclassArchiver` and define fields corresponding to the archived object's properties. ```python @dataclasses.dataclass class MyClass(DataclassArchiver): int_field: int = 0 str_field: str = "" float_field: float = -1.1 list_field: list = dataclasses.field(default_factory=list) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.