Skip to main content

parse and generate NSKeyedArchiver archives

Project description

This is a fork of Marketcircle/bpylist, which is hopefully more responsive to PRs.

Implementation of the Apple’s Binary Plist and the NSKeyedArchiver format

Usage

Binary Plists

For reading and writing plain PLists please use stdlib plistlib library.

KeyedArchives

NSKeyedArchiver is an Apple proprietary serialization format for Cocoa objects. bpylist supports reading and writing NSKeyedArchiver compatible archives. The API is similar to the binary plist API.

Unarchiving an object

from bpylist import archiver

with open('my_archived_object', 'rb') as f:
    archiver.unarchive(f.read())

Archiving an object

from bpylist import archiver

my_object = { 'foo':'bar', 'some_array': [1,2,3,4] }
archiver.archive(my_object)

Custom objects

If you archive includes classes that are not “standard” Cocoa classes (NSString, NSNumber, NSDate, NSNull, NSDictionary or NSArray), you register a Python class that the Cocoa class maps to and register it.

The simplest way to define a class is by providing a python dataclass, for example you define a class with all the fields of the archived object:

@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)

Alternatively you can implement custom unarchiving code.

The Python class needs to implement the encode_archive and decode_archive methods.

## Define a Python Class

from bpylist 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)

When the mapper class is defined, register it with unarchiver:

## Register the class for the Cocoa class 'MyCocoaClass'

archiver.update_class_map({ 'MyCocoaClass': FooArchive })

How to publish a new version to PyPI

$ pip install twine wheel
$ python setup.py sdist bdist_wheel
$ twine upload dist/*

License

MIT License

Copyright (c) 2017 Marketcircle Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bpylist2-3.0.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

bpylist2-3.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file bpylist2-3.0.1.tar.gz.

File metadata

  • Download URL: bpylist2-3.0.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for bpylist2-3.0.1.tar.gz
Algorithm Hash digest
SHA256 64201129f44caaf2eeab689a52ef8ea234d8103f32386aa750e80e48e57dc0d3
MD5 02c2e9a5ce8c4f0d3cf8cd472fa86afd
BLAKE2b-256 5a5e75a45659e796c06894130c266e3e701665d5a8f83b5f7448c575aaea2cd5

See more details on using hashes here.

File details

Details for the file bpylist2-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: bpylist2-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for bpylist2-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54364b0d79793ee8f2e5d046e9ef7667a3dc1e9098997705bd401f2b16f48c2a
MD5 aa9e67ae5e66f40a45e70c6ce6be3921
BLAKE2b-256 c1d0354a8f9930f01c3096cf86220f86bf1c0f4a8d8eab660ef2db0dcedff48b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page