https://github.com/Marketcircle/bpylist
Parse and Generate binary plists and NSKeyedArchiver archives
https://github.com/Marketcircle/bpylist
binary-plist nskeyedarchiver python
Last synced: 5 months ago
JSON representation
Parse and Generate binary plists and NSKeyedArchiver archives
- Host: GitHub
- URL: https://github.com/Marketcircle/bpylist
- Owner: Marketcircle
- Created: 2017-09-12T14:15:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-05T13:36:00.000Z (over 2 years ago)
- Last Synced: 2024-10-12T21:24:03.467Z (6 months ago)
- Topics: binary-plist, nskeyedarchiver, python
- Language: C
- Homepage:
- Size: 203 KB
- Stars: 16
- Watchers: 4
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
- jimsghstars - Marketcircle/bpylist - Parse and Generate binary plists and NSKeyedArchiver archives (C)
README
bpylist |pypi version| |Build Status|
=====================================Implementation of the `Apple's Binary
Plist `__
and the NSKeyedArchiver formatUsage
-----Binary Plists
~~~~~~~~~~~~~Generating bplist is easy, and similar to the ``plistlib`` module in
Python's Standard Library.. code:: python
from bpylist import bplist
bpylist.generate(my_object)
Reading is easy as well. The ``generate`` function takes a bytes object
and returns the top-level object of the binary plist... code:: python
from bpylist import bplist
with open('myplist.plist', 'rb') as f:
bpylist.parse(f.read())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**
.. code:: python
from bpylist import archiver
with open('my_archived_object', 'rb') as f:
archiver.unarchive(f.read())**Archiving an object**
.. code:: python
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.
The Python class needs to implement the ``encode_archive`` and
``decode_archive`` methods... code:: python
## Define a Python Class
from bpylist import archiver
class MyClass:
first_property = None
second_property = Nonedef __init__(self, first_property, second_property):
self.first_property = first_property
self.second_property = second_propertydef 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)## Register the class for the Cocoa class 'MyCocoaClass'
archiver.update_class_map({ 'MyCocoaClass': FooArchive })
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... |pypi version| image:: https://img.shields.io/pypi/v/bpylist.svg
:target: https://pypi.org/project/bpylist/
.. |Build Status| image:: https://travis-ci.org/Marketcircle/bpylist.svg?branch=master
:target: https://travis-ci.org/Marketcircle/bpylist