[Zope-dev] Re: xmlrpc OverflowError fault

Tres Seaver tseaver at palladion.com
Sun May 14 12:44:54 EDT 2006


-----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 at 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-----



More information about the Zope-Dev mailing list