PyObjCTools.Conversion
– Convert data structures¶
Functions for converting between Cocoa and pure Python data structures. These functions are only needed when a use case requires instances of “native” classes, in most use cases instances of “foreign” classes can be used without problems.
- PyObjCTools.Conversion.propertyListFromPythonCollection(pyCol, conversionHelper=None)¶
Convert a Python collection (dictionary, array, tuple, string) into an Objective-C collection.
- Parameters:
pyCol – The python value to convert
conversionHelper – Callable with a single argument that accepts a value and returns the Cocoa equivalent. This function is called for values which propertyListFromPythonCollection cannot convert automatically.
- Returns:
The Cocoa representation of pyCol
- PyObjCTools.Conversion.pythonCollectionFromPropertyList(ocCol, conversionHelper=None)¶
Converts a Foundation based collection– a property list– into a Python collection.
- Parameters:
ocCol – The Cocoa value to convert
conversionHelper – Callable with a single argument that accepts a value and returns the Python equivalent. This function is called for values which pythonCollectionFromPropertyList cannot convert automatically.
- Returns:
The Python representation of ocCol
- PyObjCTools.Conversion.serializePropertyList(aPropertyList, format='xml') bytes ¶
Serialize a property list into a byte string.
Note
For cross platform code the standard library module
plistlib
should be used.- Parameters:
aPropertyList – A property list value (list, dict, …)
format – The format to use,
"xml"
for an XML property list, or"binary"
for a binary property list.
- Returns:
A serialized property list with the contents of aPropertyList
- PyObjCTools.Conversion.deserializePropertyList(propertyListData)¶
Deserialize a property list from a byte string.
Note
For cross platform code the standard library module
plistlib
should be used.- Parameters:
propertyListData – A byte string with the serialized property list
- Returns:
The deserialized value (dict, tuple, …)
- PyObjCTools.Conversion.toPythonDecimal(aNSDecimalNumber) decimal.Decimal ¶
Convert an instance of
NSDecimalNumber
todecimal.Decimal
- Parameters:
aNSDecimalNumber – The value to convert
- Returns:
aNSDecimalNumber converted to
decimal.Decimal
- PyObjCTools.Conversion.fromPythonDecimal(aPythonDecimal) NSDecimalNumber ¶
Convert an instance of
decimal.Decimal
toNSDecimalNumber
- Parameters:
aPythonDecimal – The value to convert
- Returns:
aPythonDecimal converted to
NSDecimalNumber
.