示例#1
0
    def __call__(self, request):
        pyamf_request = pyamf.remoting.decode(request.body)
        pyamf_response = pyamf.remoting.Envelope(pyamf_request.amfVersion)

        for name, message in pyamf_request:
            # Dynamically build mapping.  This introduces a performance hit on the first request of each method.
            if message.target not in self._gateway.services:
                fn, parent = route(self, message.target, AMFController)
                self._gateway.addService(fn, message.target)
            
            pyamf_response[name] = self._gateway.getProcessor(message)(message)
        
        response.headers['Content-Type'] = pyamf.remoting.CONTENT_TYPE

        return pyamf.remoting.encode(pyamf_response).getvalue()
示例#2
0
 def __call__(self, request):
     """Parse an XML-RPC body and dispatch."""
     
     length = int(request.headers.get('Content-Length', 0))
     
     if not length:
         log.debug("No content length specified, returning 411 HTTPLengthRequired error.")
         raise HTTPLengthRequired()
     
     if not length or length > self.__max_body_length__:
         log.debug("Content length larger than allowed maximum of %d bytes, returning 413 HTTPRequestEntityTooLarge error.", self.__max_body_length__)
         raise HTTPRequestEntityTooLarge("XML body too large.")
     
     args, method = xmlrpclib.loads(request.body, True)
     
     log.debug("XML-RPC Call: %s%r", method, args)
     
     func, parent = route(self, method, XMLRPCController)
     
     log.debug("Found methd: %r", func)
     
     try:
         args = parent.__before__(*args)
     
     except AttributeError:
         pass
     
     result = func(*args)
     
     try:
         result = parent.__after__(result, *args)
     
     except AttributeError:
         pass
     
     log.debug("Got result: %r", result)
     
     response.content_type = 'text/xml'
     
     return xmlrpclib.dumps((result, ), methodresponse=True, allow_none=self.__allow_none__)