Update of /cvsroot/pywin32/pywin32/win32/Lib
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv5473
Modified Files:
win32timezone.py
Log Message:
Fixed pickling error, caused by the pickle-unfriendly ctypes.Structures
Index: win32timezone.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32timezone.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** win32timezone.py 16 Jan 2009 03:22:24 -0000 1.20
--- win32timezone.py 18 Jan 2009 21:50:27 -0000 1.21
***************
*** 164,167 ****
--- 164,172 ----
log = logging.getLogger(__file__)
+ # define a couple of Structure comparison methods (these have to appear before the
+ # definitions of subclasses or they won't be used in the type construction.
+ ctypes.Structure.__eq__ = lambda self, other: str(buffer(self)) == str(buffer(other))
+ ctypes.Structure.__ne__ = lambda self, other: str(buffer(self)) != str(buffer(other))
+
# A couple of C-type structures for working with the Windows Platform SDK
class SYSTEMTIME(ctypes.Structure):
***************
*** 188,191 ****
--- 193,214 ----
]
+ # define a couple of functions to enable ctypes.Structure pickling
+ def __construct_structure(type_, buffer):
+ "Construct a ctypes.Structure subclass from a buffer"
+ assert issubclass(type_, ctypes.Structure)
+ obj = type_.__new__(type_)
+ # TODO, what if buffer is larger that the sizeof obj?
+ ctypes.memmove(ctypes.addressof(obj), buffer, len(buffer))
+ return obj
+
+ def __reduce(self):
+ """
+ A method to make ctypes.Structures pickleable
+ from http://osdir.com/ml/python.ctypes/2006-03/msg00009.html
+ """
+ args = (self.__class__, str(buffer(self)))
+ return (__construct_structure, args)
+ ctypes.Structure.__reduce__ = __reduce
+
class TimeZoneDefinition(TIME_ZONE_INFORMATION):
***************
*** 245,248 ****
--- 268,273 ----
value = TIME_ZONE_INFORMATION.__getattribute__(other, name)
setattr(self, name, value)
+ # consider
+ #
def __getattribute__(self, attr):
|