xmlrpc OverflowError fault
Trying to get a Zope DateTime object (as dictionary value) via xml-rpc gives on OverflowError! You can try it yourself: (I used a freshly installed Zope-2.9.3 [with python-2.4.3] on Linux FC3; but other versions should behave equally.) Add a Python Script in the Zope OFS root folder: return {'root_modification_time': container.bobobase_modification_time()} The www request returns: {'root_modification_time': DateTime('2006/05/13 14:33:12.445 GMT+2')} But the XML-RPC returns: xmlrpclib.Fault: (-1, 'Unexpected Zope exception: exceptions.OverflowError - long int exceeds XML-RPC limits' The reason for this is, that the DateTime object is treated as a normal instance by xmlrpclib, ie __dict__ is marshalled (which, unfortunately, contains the attribute '_millis', which is usually too big). It would be better anyway, if Zope DateTime objects would be marshalled as XML-RPC dates (dateTime.iso8601). Eg like that: --- xmlrpclib.py.ori 2006-05-13 13:29:45.606954800 +0200 +++ xmlrpclib.py.wlang 2006-05-13 13:32:45.923542512 +0200 @@ -701,10 +701,15 @@ def dump_instance(self, value, write): # check for special wrappers + import DateTime as ZopeDateTime if value.__class__ in WRAPPERS: self.write = write value.encode(self) del self.write + elif value.__class__ == ZopeDateTime.DateTime: + self.write = write + DateTime(value).encode(self) + del self.write else: # store instance attributes as a struct (really?) self.dump_struct(value.__dict__, write) However, this would modify xmlrpclib.py from the python distribution, wich is plain ugly. Can anyone think of a better solution? Is it possible to change xmlrpclib.WRAPPERS from Zope, but leave python's xmlrpclib.py unaffected? \wlang{} -- Willi.Langenberger@wu-wien.ac.at Fax: +43/1/31336/9207 Zentrum fuer Informatikdienste, Wirtschaftsuniversitaet Wien, Austria
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Willi Langenberger wrote:
Trying to get a Zope DateTime object (as dictionary value) via xml-rpc gives on OverflowError! You can try it yourself:
(I used a freshly installed Zope-2.9.3 [with python-2.4.3] on Linux FC3; but other versions should behave equally.)
Add a Python Script in the Zope OFS root folder:
return {'root_modification_time': container.bobobase_modification_time()}
The www request returns:
{'root_modification_time': DateTime('2006/05/13 14:33:12.445 GMT+2')}
But the XML-RPC returns:
xmlrpclib.Fault: (-1, 'Unexpected Zope exception: exceptions.OverflowError - long int exceeds XML-RPC limits'
The reason for this is, that the DateTime object is treated as a normal instance by xmlrpclib, ie __dict__ is marshalled (which, unfortunately, contains the attribute '_millis', which is usually too big).
It would be better anyway, if Zope DateTime objects would be marshalled as XML-RPC dates (dateTime.iso8601). Eg like that:
--- xmlrpclib.py.ori 2006-05-13 13:29:45.606954800 +0200 +++ xmlrpclib.py.wlang 2006-05-13 13:32:45.923542512 +0200 @@ -701,10 +701,15 @@
def dump_instance(self, value, write): # check for special wrappers + import DateTime as ZopeDateTime if value.__class__ in WRAPPERS: self.write = write value.encode(self) del self.write + elif value.__class__ == ZopeDateTime.DateTime: + self.write = write + DateTime(value).encode(self) + del self.write else: # store instance attributes as a struct (really?) self.dump_struct(value.__dict__, write)
However, this would modify xmlrpclib.py from the python distribution, wich is plain ugly.
Can anyone think of a better solution? Is it possible to change xmlrpclib.WRAPPERS from Zope, but leave python's xmlrpclib.py unaffected?
A monkeypatch of the module should work fine, as the 'WRAPPERS' object is looked up as a global at each use. If anybody *else* imports it using 'from xmlrpc import WRAPPERS', then they won't see the new registration after the monkeypatch, because 'WRAPPERS' is a tuple, and must therefore be replaced, rather than mutated. Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEZ16G+gerLs4ltQ4RAkVcAKC65Q7BndJYWAMrTxAnMQpGE6PSPwCcDeei wH2FCbIssrTcXUL5zaMpehw= =5HQX -----END PGP SIGNATURE-----
According to Tres Seaver:
Trying to get a Zope DateTime object (as dictionary value) via xml-rpc gives on OverflowError! You can try it yourself:
(I used a freshly installed Zope-2.9.3 [with python-2.4.3] on Linux FC3; but other versions should behave equally.)
Add a Python Script in the Zope OFS root folder:
return {'root_modification_time': container.bobobase_modification_time()}
The www request returns:
{'root_modification_time': DateTime('2006/05/13 14:33:12.445 GMT+2')}
But the XML-RPC returns:
xmlrpclib.Fault: (-1, 'Unexpected Zope exception: exceptions.OverflowError - long int exceeds XML-RPC limits'
A monkeypatch of the module should work fine, as the 'WRAPPERS' object is looked up as a global at each use. If anybody *else* imports it using 'from xmlrpc import WRAPPERS', then they won't see the new registration after the monkeypatch, because 'WRAPPERS' is a tuple, and must therefore be replaced, rather than mutated.
Tres, thanks for the hint! I updated my patch in the collector (http://www.zope.org/Collectors/Zope/2109). Is there chance to get this in the Zope distribution? Thanks, \wlang{} $ cat xmlrpc-datetime.patch --- DateTime/DateTime.py.ori 2006-05-12 13:53:46.000000000 +0200 +++ DateTime/DateTime.py 2006-05-15 23:15:40.485825640 +0200 @@ -1805,6 +1805,11 @@ d1 = (( d4 - L) % 365) + L return d1/7 + 1 + # wlang, 2006-05: make DateTime instances marshallable via xml-rpc + def encode(self, out): + out.write("<value><dateTime.iso8601>") + out.write(self.ISO8601()) + out.write("</dateTime.iso8601></value>\n") class strftimeFormatter: --- ZPublisher/xmlrpc.py.ori 2006-05-12 13:53:45.000000000 +0200 +++ ZPublisher/xmlrpc.py 2006-05-15 23:15:05.055211912 +0200 @@ -23,6 +23,10 @@ import sys, types from HTTPResponse import HTTPResponse import xmlrpclib +# wlang, 2006-05: monkeypatch to make DateTime marshallable via xml-rpc +from DateTime import DateTime +xmlrpclib.WRAPPERS = xmlrpclib.WRAPPERS + (DateTime,) + from zExceptions import Unauthorized -- Willi.Langenberger@wu-wien.ac.at Fax: +43/1/31336/9207 Zentrum fuer Informatikdienste, Wirtschaftsuniversitaet Wien, Austria
participants (2)
-
Tres Seaver -
Willi Langenberger