Ticket #3219: xmlrpc_datetime.diff

File xmlrpc_datetime.diff, 3.3 KB (added by chadmaine, 9 years ago)
  • twisted/web/xmlrpc.py

     
    9595    separator = '.'
    9696    allowedMethods = ('POST',)
    9797
    98     def __init__(self, allowNone=False):
     98    def __init__(self, allowNone=False, useDateTime=False):
    9999        resource.Resource.__init__(self)
    100100        self.subHandlers = {}
    101101        self.allowNone = allowNone
     102        self.useDateTime = useDateTime
    102103
    103104    def putSubHandler(self, prefix, handler):
    104105        self.subHandlers[prefix] = handler
     
    113114        request.content.seek(0, 0)
    114115        request.setHeader("content-type", "text/xml")
    115116        try:
    116             args, functionPath = xmlrpclib.loads(request.content.read())
     117            args, functionPath = xmlrpclib.loads(request.content.read(), use_datetime=self.useDateTime)
    117118        except Exception, e:
    118119            f = Fault(self.FAILURE, "Can't deserialize input: %s" % (e,))
    119120            self._cbRender(f, request)
     
    301302    protocol = QueryProtocol
    302303
    303304    def __init__(self, path, host, method, user=None, password=None,
    304                  allowNone=False, args=()):
     305                 allowNone=False, args=(), useDateTime=False):
    305306        self.path, self.host = path, host
    306307        self.user, self.password = user, password
    307308        self.payload = payloadTemplate % (method,
    308309            xmlrpclib.dumps(args, allow_none=allowNone))
    309310        self.deferred = defer.Deferred()
     311        self.useDateTime = useDateTime
    310312
    311313    def parseResponse(self, contents):
    312314        if not self.deferred:
    313315            return
    314316        try:
    315             response = xmlrpclib.loads(contents)
     317            response = xmlrpclib.loads(contents, use_datetime=self.useDateTime)
    316318        except:
    317319            deferred, self.deferred = self.deferred, None
    318320            deferred.errback(failure.Failure())
     
    347349    """
    348350    queryFactory = _QueryFactory
    349351
    350     def __init__(self, url, user=None, password=None, allowNone=False):
     352    def __init__(self, url, user=None, password=None, allowNone=False, useDateTime=False):
    351353        """
    352354        @type url: C{str}
    353355        @param url: The URL to which to post method calls.  Calls will be made
     
    370372        @type allowNone: C{bool} or None
    371373        @param allowNone: allow the use of None values in parameters. It's
    372374        passed to the underlying xmlrpclib implementation. Default to False.
     375
     376        @type useDateTime: C{bool} or None
     377        @param useDateTime: Convert xmlrpclib.DateTime objects to datetime.datetime objects. It's
     378        passed to the underlying xmlrpclib implementation. Default to False.
     379
    373380        """
    374381        scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
    375382        netlocParts = netloc.split('@')
     
    397404        if password is not None:
    398405            self.password = password
    399406        self.allowNone = allowNone
     407        self.useDateTime = useDateTime
    400408
    401409    def callRemote(self, method, *args):
    402410        factory = self.queryFactory(
    403411            self.path, self.host, method, self.user,
    404             self.password, self.allowNone, args)
     412            self.password, self.allowNone, args, self.useDateTime)
    405413        if self.secure:
    406414            from twisted.internet import ssl
    407415            reactor.connectSSL(self.host, self.port or 443,