[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/ Allow xmlrpclib.DateTime values in xml-rpc data exchange.

Philipp von Weitershausen philikon at philikon.de
Wed Sep 1 12:40:48 EDT 2004


Log message for revision 27386:
  Allow xmlrpclib.DateTime values in xml-rpc data exchange.
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/README.txt
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/configure.zcml
  U   Zope3/branches/ZopeX3-3.0/src/zope/publisher/xmlrpc.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/README.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/README.txt	2004-09-01 15:51:16 UTC (rev 27385)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/README.txt	2004-09-01 16:40:47 UTC (rev 27386)
@@ -384,4 +384,69 @@
   </methodResponse>
   <BLANKLINE>
 
+DateTime values
+---------------
 
+Unfortunately, `xmlrpclib` does not support Python 2.3's new
+`datetime.datetime` class (it should be made to, really).  DateTime
+values need to be encoded as `xmlrpclib.DateTime` instances:
+  
+  >>> import xmlrpclib, time
+
+  >>> class DateTimeDemo:
+  ...     def __init__(self, context, request):
+  ...         self.context = context
+  ...         self.request = request
+  ...
+  ...     def epoch(self):
+  ...         return xmlrpclib.DateTime(1)
+
+Now we'll register it as a view:
+
+  >>> from zope.configuration import xmlconfig
+  >>> ignored = xmlconfig.string("""
+  ... <configure 
+  ...     xmlns="http://namespaces.zope.org/zope"
+  ...     xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"
+  ...     >
+  ...   <!-- We only need to do this include in this example, 
+  ...        Normally the include has already been done for us. -->
+  ...   <include package="zope.app.publisher.xmlrpc" file="meta.zcml" />
+  ...
+  ...   <xmlrpc:view
+  ...       for="zope.app.folder.folder.IFolder"
+  ...       methods="epoch"
+  ...       class="zope.app.publisher.xmlrpc.README.DateTimeDemo"
+  ...       permission="zope.ManageContent"
+  ...       />
+  ... </configure>
+  ... """)
+
+Now, when we call it, we get a DateTime value
+
+  >>> print http(r"""
+  ... POST / HTTP/1.0
+  ... Authorization: Basic bWdyOm1ncnB3
+  ... Content-Length: 100
+  ... Content-Type: text/xml
+  ... 
+  ... <?xml version='1.0'?>
+  ... <methodCall>
+  ... <methodName>epoch</methodName>
+  ... <params>
+  ... </params>
+  ... </methodCall>
+  ... """, handle_errors=False)
+  HTTP/1.0 200 Ok
+  Content-Length: 163
+  Content-Type: text/xml;charset=utf-8
+  <BLANKLINE>
+  <?xml version='1.0'?>
+  <methodResponse>
+  <params>
+  <param>
+  <value><dateTime.iso8601>19700101T01:00:01</dateTime.iso8601></value>
+  </param>
+  </params>
+  </methodResponse>
+  <BLANKLINE>

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/configure.zcml
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/configure.zcml	2004-09-01 15:51:16 UTC (rev 27385)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/xmlrpc/configure.zcml	2004-09-01 16:40:47 UTC (rev 27386)
@@ -4,9 +4,13 @@
     >
 
   <class class="xmlrpclib.Fault">
-    <require permission="zope.Public" attributes="faultCode faultString" />
+    <allow attributes="faultCode faultString" />
   </class>
 
+  <class class="xmlrpclib.DateTime">
+    <allow attributes="value" />
+  </class>
+
   <view 
       for="zope.interface.Interface"
       type="zope.publisher.interfaces.xmlrpc.IXMLRPCRequest"

Modified: Zope3/branches/ZopeX3-3.0/src/zope/publisher/xmlrpc.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/publisher/xmlrpc.py	2004-09-01 15:51:16 UTC (rev 27385)
+++ Zope3/branches/ZopeX3-3.0/src/zope/publisher/xmlrpc.py	2004-09-01 16:40:47 UTC (rev 27386)
@@ -158,11 +158,15 @@
         premarshal(data.faultString),
         )
 
+def premarshal_datetime(data):
+    return xmlrpclib.DateTime(data.value)
+
 premarshal_dispatch_table = {
     dict: premarshal_dict,
     list: premarshal_list,
     tuple: premarshal_list,
     xmlrpclib.Fault: premarshal_fault,
+    xmlrpclib.DateTime: premarshal_datetime,
     }
 premarshal_dispatch = premarshal_dispatch_table.get
 



More information about the Zope3-Checkins mailing list