Commits

Bill Bumgarner  committed 94ee18c

Added ability to specify helper function when converting python collections to ObjC property lists.

  • Participants
  • Parent commits c986265

Comments (0)

Files changed (2)

File pyobjc/ChangeLog

+2002-10-17  Bill Bumgarner  <bbum@codefab.com>
+	* propertyListFromPythonCollection() takes an optional kv argument
+	that is used as a helper function when the type to be converted in
+	the python collection is not recognized.   For example, the
+	xmlrpclib returns a [somewhat inadequate] internal type known as a
+	DateTime.  To convert this to a Foundation class requires some
+	jumping through hoops that may change a bit during context.  The
+	caller can provide a helper function to do the conversion.
+
 2002-10-16  Bill Bumgarner  <bbum@codefab.com>
-
 	* NSClassFromString() was implemented twice in the Foundation's
 	__init__.py.  The second implementation was supposed to be
 	NSStringFromClass(). Fixed.
 	  regains its orginal 'identity'
 
 2002-10-11  Bill Bumgarner  <bbum@codefab.com>
-
 	* Removed various debugging/development noise from startup.
 
 	* Regenerated various incs in Modules/Cocoa based on new scripts.

File pyobjc/Lib/Foundation/__init__.py

 del gl
 
 from types import *
-def propertyListFromPythonCollection(aPyCollection):
+def propertyListFromPythonCollection(aPyCollection, conversionHelper=None):
 	containerType = type(aPyCollection)
 	if containerType == DictType:
 		collection = NSMutableDictionary.dictionary()
 		for aKey in aPyCollection:
-			convertedValue = propertyListFromPythonCollection( aPyCollection[aKey] )
+			convertedValue = propertyListFromPythonCollection( aPyCollection[aKey], conversionHelper=conversionHelper )
 			collection.setObject_forKey_( convertedValue , aKey )
 		return collection
 	elif containerType in [TupleType, ListType]:
 		collection = NSMutableArray.array()
 		for aValue in aPyCollection:
-			convertedValue = propertyListFromPythonCollection( aValue )
+			convertedValue = propertyListFromPythonCollection( aValue, conversionHelper=conversionHelper )
 			collection.addObject_( convertedValue  )
 		return collection
 	elif containerType in StringTypes:
 	elif containerType == NoneType:
 		return NSNull.null()
 	else:
+		if conversionHelper:
+			return conversionHelper(aPyCollection)
 		raise "UnrecognizedTypeException", "Type %s encountered in python collection;  don't know how to convert." % containerType
 
 # def pythonCollectionFromPropertyList(aPropertyList):