xmlrpclib and mx.DateTime

Ashley Walsh ashleywalsh at synengco.com
Tue Jan 29 22:46:30 EST 2002


On Tue, 29 Jan 2002 17:11:33 -0800, Chuck Esterbrook
<ChuckEsterbrook at StockAlerts.com> wrote:

>Hi,
>
>Does anyone have a patch lying about to make xmlrpclib and mx.DateTime
>play nice together?
>
>xmlrpclib raises an exception when it tries to "xml marshal" an
>mx.DateTime. I'm not the first to run into this and I'm wondering if
>anyone has "fixed it" already.
>
>
>-Chuck
>

You can modify the Marshaller and Unmarshaller in xmlrpclib like this:


import xmlrpclib
import mx.DateTime

# Extend xmlrpclib.Marshaller to mx.DateTime.DateTime type

def dump_datetime(self, value):
    self.write("<value><dateTime.iso8601>%s</dateTime.iso8601></value>\n"\
               % xmlrpclib.escape(str(value)))

xmlrpclib.Marshaller.dispatch[mx.DateTime.DateTimeType] = dump_datetime


# modify xmlrpclib.Unmarshaller to generate
# mx.DateTime.DateTime instances

def end_dateTime(self, join=string.join):
    self.append(mx.DateTime.DateTimeFrom(join(self._data, "")))
    self._value = 0

xmlrpclib.Unmarshaller.end_dateTime = end_dateTime
xmlrpclib.Unmarshaller.dispatch["dateTime.iso8601"] = end_dateTime


Ashley





More information about the Python-list mailing list