Exemplo n.º 1
0
 def __init__(self,
              details,
              code=-32603,
              title=None,
              show_traceback=False):
     ProtocolException.__init__(self, details, title, show_traceback)
     self.code = code
Exemplo n.º 2
0
    def _rpc_process(self, req, protocol, content_type):
        """Process incoming RPC request and finalize response."""
        proto_id = protocol.rpc_info()[0]
        rpcreq = req.rpc = {'mimetype': content_type}
        try:
            self.log.debug("RPC(%s) call by '%s'", proto_id, req.authname)
            rpcreq = req.rpc = protocol.parse_rpc_request(req, content_type)
            rpcreq['mimetype'] = content_type

            # Important ! Check after parsing RPC request to add
            #             protocol-specific fields in response
            #             (e.g. JSON-RPC response `id`)
            req.perm.require('XML_RPC')  # Need at least XML_RPC

            method_name = rpcreq.get('method')
            if method_name is None:
                raise ProtocolException('Missing method name')
            args = rpcreq.get('params') or []
            self.log.debug("RPC(%s) call by '%s' %s", proto_id, \
                                              req.authname, method_name)
            try:
                result = (XMLRPCSystem(self.env).get_method(method_name)(
                    req, args))[0]
                if isinstance(result, GeneratorType):
                    result = list(result)
            except (RPCError, PermissionError, ResourceNotFound), e:
                raise
            except Exception:
                e, tb = sys.exc_info()[-2:]
                raise ServiceException(e), None, tb
            else:
                protocol.send_rpc_result(req, result)
Exemplo n.º 3
0
 def parse_rpc_request(self, req, content_type):
     """ Parse XML-RPC requests."""
     try:
         args, method = xmlrpclib.loads(
                     req.read(int(req.get_header('Content-Length'))))
     except Exception, e:
         self.log.debug("RPC(xml) parse error: %s", to_unicode(e))
         raise ProtocolException(xmlrpclib.Fault(-32700, to_unicode(e)))
Exemplo n.º 4
0
    def _rpc_process(self, req, protocol, content_type):
        """Process incoming RPC request and finalize response."""
        proto_id = protocol.rpc_info()[0]
        rpcreq = req.rpc = {'mimetype': content_type}
        self.log.debug("RPC(%s) call by '%s'", proto_id, req.authname)
        try:
            if req.path_info.startswith('/login/') and \
                    req.authname == 'anonymous':
                raise TracError("Authentication information not available")
            rpcreq = req.rpc = protocol.parse_rpc_request(req, content_type)
            rpcreq['mimetype'] = content_type

            # Important ! Check after parsing RPC request to add
            #             protocol-specific fields in response
            #             (e.g. JSON-RPC response `id`)
            req.perm.require('XML_RPC')  # Need at least XML_RPC

            method_name = rpcreq.get('method')
            if method_name is None:
                raise ProtocolException('Missing method name')
            args = rpcreq.get('params') or []
            self.log.debug("RPC(%s) call by '%s' %s", proto_id, req.authname,
                           method_name)
            try:
                result = (XMLRPCSystem(self.env).get_method(method_name)(
                    req, args))[0]
                if isinstance(result, GeneratorType):
                    result = list(result)
            except (TracError, PermissionError, ResourceNotFound), e:
                raise
            except Exception:
                e, tb = sys.exc_info()[-2:]
                self.log.error(
                    "RPC(%s) [%s] Exception caught while calling "
                    "%s(*%r) by %s%s", proto_id, req.remote_addr,
                    method_name, args, req.authname,
                    exception_to_unicode(e, traceback=True))
                raise ServiceException(e), None, tb
            else:
                protocol.send_rpc_result(req, result)
Exemplo n.º 5
0
 def __init__(self, details, code=-32603, title=None, show_traceback=False):
     ProtocolException.__init__(self, details, title, show_traceback)
     self.code = code