[Zope3-checkins] SVN: Zope3/trunk/src/zope/publisher/ - Fixed issue 550: added adapter for datetime.datetime for xmlrpc premarshalling

Christian Theune cvs-admin at zope.org
Sun Jun 18 22:00:53 EDT 2006


Log message for revision 68741:
   - Fixed issue 550: added adapter for datetime.datetime for xmlrpc premarshalling
  

Changed:
  U   Zope3/trunk/src/zope/publisher/configure.zcml
  U   Zope3/trunk/src/zope/publisher/xmlrpc.py
  U   Zope3/trunk/src/zope/publisher/xmlrpc.txt

-=-
Modified: Zope3/trunk/src/zope/publisher/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/publisher/configure.zcml	2006-06-19 01:29:56 UTC (rev 68740)
+++ Zope3/trunk/src/zope/publisher/configure.zcml	2006-06-19 02:00:50 UTC (rev 68741)
@@ -21,6 +21,11 @@
       />
 
   <adapter
+      factory=".xmlrpc.PythonDateTimePreMarshaller"
+      for="datetime.datetime"
+      />
+
+  <adapter
       factory=".xmlrpc.DictPreMarshaller"
       for="dict"
       />

Modified: Zope3/trunk/src/zope/publisher/xmlrpc.py
===================================================================
--- Zope3/trunk/src/zope/publisher/xmlrpc.py	2006-06-19 01:29:56 UTC (rev 68740)
+++ Zope3/trunk/src/zope/publisher/xmlrpc.py	2006-06-19 02:00:50 UTC (rev 68741)
@@ -199,6 +199,12 @@
     def __call__(self):
         return xmlrpclib.DateTime(self.data.value)
 
+class PythonDateTimePreMarshaller(PreMarshallerBase):
+    """Pre-marshaller for datetime.datetime"""
+
+    def __call__(self):
+        return xmlrpclib.DateTime(self.data.isoformat())
+
 def premarshal(data):
     """Premarshal data before handing it to xmlrpclib for marhalling
 

Modified: Zope3/trunk/src/zope/publisher/xmlrpc.txt
===================================================================
--- Zope3/trunk/src/zope/publisher/xmlrpc.txt	2006-06-19 01:29:56 UTC (rev 68740)
+++ Zope3/trunk/src/zope/publisher/xmlrpc.txt	2006-06-19 02:00:50 UTC (rev 68741)
@@ -48,3 +48,14 @@
   >>> type(stripped_fault) is Proxy
   False
 
+Standard python datetime objects are also handled:
+
+  >>> import datetime
+  >>> sample = datetime.datetime(2006,06,17,21,41,00)
+  >>> stripped_date = premarshal(sample)
+  >>> isinstance(stripped_date, datetime.datetime)
+  False
+  >>> isinstance(stripped_date, xmlrpclib.DateTime)
+  True
+
+



More information about the Zope3-Checkins mailing list