Module implementing a library for reading and writing binary property list files.
Binary Property List (plist) files provide a faster and smaller serialization format for property lists on OS X. This is a library for generating binary plists which can be read by OS X, iOS, or other clients.
The API models the plistlib API, and will call through to plistlib when XML serialization or deserialization is required.
To generate plists with UID values, wrap the values with the Uid object. The value must be an int.
To generate plists with NSData/CFData values, wrap the values with the Data object. The value must be a bytes object.
Date values can only be datetime.datetime objects.
The exceptions InvalidPlistException and NotBinaryPlistException may be thrown to indicate that the data cannot be serialized or deserialized as a binary plist.
Plist generation example:
from binplistlib import * from datetime import datetime plist = {'aKey':'aValue', '0':1.322, 'now':datetime.now(), 'list':[1,2,3], 'tuple':('a','b','c') } try: writePlist(plist, "example.plist") except (InvalidPlistException, NotBinaryPlistException) as e: print("Something bad happened:", e)Plist parsing example:
from binplistlib import * try: plist = readPlist("example.plist") print(plist) except (InvalidPlistException, NotBinaryPlistException) as e: print("Not a plist:", e)
PlistByteCounts |
PlistTrailer |
__all__ |
apple_reference_date_offset |
BoolWrapper | Class wrapping a boolean value. |
Data | Class implementing a wrapper around bytes types for representing Data values. |
HashableWrapper | Class wrapping a hashable value. |
InvalidPlistException | Exception raised when the plist is incorrectly formatted. |
NotBinaryPlistException | Exception raised when a binary plist was expected but not encountered. |
PlistReader | Class implementing the plist reader. |
PlistWriter | Class implementing the plist writer. |
Uid | Class implementing a wrapper around integers for representing UID values. |
is_stream_binary_plist | Module function to check, if the stream is a binary plist. |
readPlist | Module function to read a plist file. |
readPlistFromBytes | Module function to read from a plist bytes object. |
writePlist | Module function to write a plist file. |
writePlistToBytes | Module function to write a plist bytes object. |
Class wrapping a boolean value.
None |
None |
BoolWrapper | Constructor |
__repr__ | Public method to generate a representation of the object. |
None |
Constructor
Public method to generate a representation of the object.
Class implementing a wrapper around bytes types for representing Data values.
None |
None |
None |
None |
Class wrapping a hashable value.
None |
None |
HashableWrapper | Constructor |
__repr__ | Public method to generate a representation of the object. |
None |
Constructor
Public method to generate a representation of the object.
Exception raised when the plist is incorrectly formatted.
None |
None |
None |
None |
Exception raised when a binary plist was expected but not encountered.
None |
None |
None |
None |
Class implementing the plist reader.
contents |
currentOffset |
file |
offsets |
trailer |
None |
PlistReader | Constructor |
getSizedInteger | Private method to read an integer of a specific size. |
parse | Public method to parse the plist data. |
proc_extra | |
readArray | Private method to read an Array object. |
readAsciiString | Private method to read an ASCII encoded string. |
readData | Private method to read some bytes. |
readDate | Private method to read a date. |
readDict | Private method to read a Dictionary object. |
readInteger | Private method to read an Integer object. |
readObject | Private method to read the object data. |
readReal | Private method to read a Real object. |
readRefs | Private method to read References. |
readRoot | Private method to read the root object. |
readUid | Private method to read a UID. |
readUnicode | Private method to read an Unicode encoded string. |
reset | Private method to reset the instance object. |
setCurrentOffsetToObjectNumber | Private method to set the current offset. |
None |
Constructor
Private method to read an integer of a specific size.
Public method to parse the plist data.
Private method to read an Array object.
Private method to read an ASCII encoded string.
Private method to read some bytes.
Private method to read a date.
Private method to read a Dictionary object.
Private method to read an Integer object.
Private method to read the object data.
Private method to read a Real object.
Private method to read References.
Private method to read the root object.
Private method to read a UID.
Private method to read an Unicode encoded string.
Private method to reset the instance object.
Private method to set the current offset.
Class implementing the plist writer.
byteCounts |
computedUniques |
file |
header |
referencePositions |
trailer |
wrappedFalse |
wrappedTrue |
writtenReferences |
None |
PlistWriter | Constructor |
binaryInt | Private method to pack an integer object. |
binaryReal | Private method to pack a real object. |
check_key | |
computeOffsets | Public method to compute offsets of an object. |
incrementByteCount | Public method to increment the byte count. |
intSize | Private method to determine the number of bytes necessary to store the given integer. |
positionOfObjectReference | Private method to get the position of an object. |
proc_size | |
proc_variable_length | |
realSize | Private method to determine the number of bytes necessary to store the given real. |
reset | Private method to reset the instance object. |
wrapRoot | Private method to generate object wrappers. |
writeObject | Private method to serialize the given object to the output. |
writeObjectReference | Private method to write an object reference. |
writeOffsetTable | Private method to write all of the object reference offsets. |
writeRoot | Public method to write an object to a plist file. |
None |
Constructor
Private method to pack an integer object.
Private method to pack a real object.
Public method to compute offsets of an object.
Public method to increment the byte count.
Private method to determine the number of bytes necessary to store the given integer.
Private method to get the position of an object.
If the given object has been written already, return its position in the offset table. Otherwise, return None.
Private method to determine the number of bytes necessary to store the given real.
Private method to reset the instance object.
Private method to generate object wrappers.
Private method to serialize the given object to the output.
Private method to write an object reference.
Tries to write an object reference, adding it to the references table. Does not write the actual object bytes or set the reference position. Returns a tuple of whether the object was a new reference (True if it was, False if it already was in the reference table) and the new output.
Private method to write all of the object reference offsets.
Public method to write an object to a plist file.
Strategy is:
Class implementing a wrapper around integers for representing UID values.
This is used in keyed archiving.
None |
None |
__repr__ | Public method to return an object representation. |
None |
Public method to return an object representation.
Module function to check, if the stream is a binary plist.
Module function to read a plist file.
Module function to read from a plist bytes object.
Module function to write a plist file.
Module function to write a plist bytes object.