[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Merge r27386 from X3.0
branch: Allow xmlrpclib.DateTime values in
Philipp von Weitershausen
philikon at philikon.de
Wed Sep 1 12:44:08 EDT 2004
Log message for revision 27387:
Merge r27386 from X3.0 branch: Allow xmlrpclib.DateTime values in
xml-rpc data exchange.
Changed:
U Zope3/trunk/src/zope/app/publisher/xmlrpc/README.txt
U Zope3/trunk/src/zope/app/publisher/xmlrpc/configure.zcml
U Zope3/trunk/src/zope/publisher/xmlrpc.py
-=-
Modified: Zope3/trunk/src/zope/app/publisher/xmlrpc/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/publisher/xmlrpc/README.txt 2004-09-01 16:40:47 UTC (rev 27386)
+++ Zope3/trunk/src/zope/app/publisher/xmlrpc/README.txt 2004-09-01 16:44:08 UTC (rev 27387)
@@ -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/trunk/src/zope/app/publisher/xmlrpc/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/publisher/xmlrpc/configure.zcml 2004-09-01 16:40:47 UTC (rev 27386)
+++ Zope3/trunk/src/zope/app/publisher/xmlrpc/configure.zcml 2004-09-01 16:44:08 UTC (rev 27387)
@@ -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/trunk/src/zope/publisher/xmlrpc.py
===================================================================
--- Zope3/trunk/src/zope/publisher/xmlrpc.py 2004-09-01 16:40:47 UTC (rev 27386)
+++ Zope3/trunk/src/zope/publisher/xmlrpc.py 2004-09-01 16:44:08 UTC (rev 27387)
@@ -158,18 +158,22 @@
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
def premarshal(data):
"""Premarshal data before handing it to xmlrpclib for marhalling
- The initial putpuse of this function is to remove security proxies
+ The initial purpose of this function is to remove security proxies
without resorting to removeSecurityProxy. This way, we can avoid
inadvertently providing access to data that should be protected.
More information about the Zope3-Checkins
mailing list