Re: [Pyobjc-dev] pickled Objective-C objects
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-02-24 18:30:26
|
I managed to add pickle support to (as a test) NSBezierPath by adding a __reduce__ method to a __subclass__. I'm now trying to figure out how to add __reduce__ to all objects, and was hoping to add it to objc._convenience, but I'm stuck. Here's what I have so far: def _unpickleNSObject(data): from Foundation import NSUnarchiver, NSData return NSUnarchiver.unarchiveObjectWithData_( NSData.dataWithBytes_length_(data, len(data))) def __reduce__NSObject(obj): from Foundation import NSArchiver return _unpickleNSObject, (str( NSArchiver.archivedDataWithRootObject_(self).bytes()),) # XXX now add __reduce__NSObject as __reduce__ to all objects Hm, it seems this would work: NSObject.__reduce__ = __reduce__NSObject Is objc._convenience the right place for this? I guess not since it currently doesn't even import Foundation. Just PS: It seems NSData doesn't support the buffer protocol; you can't pass a string where an NSData is expected, and str(anNSDataInstance) doesn't do the right thing. |