예제 #1
0
 def _dispatch(self, *args, **kw):
     try:
         result = SimpleXMLRPCDispatcher._dispatch(self, *args, **kw)
         # 	self.logger.debug("Result: %s" % (result, ))
         return result
     except:
         self.logger.exception("Error while processing request")
         raise
	def _dispatch(self, *args, **kw):
		try:
			result = SimpleXMLRPCDispatcher._dispatch(self, *args, **kw)
		#	self.logger.debug("Result: %s" % (result, ))
			return result
		except:
			self.logger.exception("Error while processing request")
			raise
예제 #3
0
파일: xmlrpc.py 프로젝트: NETWAYS/ingraph
 def _dispatch(self, method, params):
     try:
         return SimpleXMLRPCDispatcher._dispatch(self, method, params)
     except Exception, e:
         message  = "XML-RPC request caused exception:\n"
         message += "Method: %s\n" % (method)
         message += "Parameters: %s" % (str(params))
         self.logger.exception(message)
         raise
예제 #4
0
파일: xmlrpc.py 프로젝트: NETWAYS/ingraph
 def _dispatch(self, method, params):
     try:
         return SimpleXMLRPCDispatcher._dispatch(self, method, params)
     except Exception, e:
         message = "XML-RPC request caused exception:\n"
         message += "Method: %s\n" % (method)
         message += "Parameters: %s" % (str(params))
         self.logger.exception(message)
         raise
예제 #5
0
파일: main.py 프로젝트: sibiaoluo/beaker
 def _dispatch(self, method, params):
     """ Custom _dispatch so we can log time used to execute method.
     """
     start = datetime.utcnow()
     try:
         result = SimpleXMLRPCDispatcher._dispatch(self, method, params)
     except:
         logger.debug('Time: %s %s %s', datetime.utcnow() - start, str(method), str(params)[0:50])
         raise
     logger.debug('Time: %s %s %s', datetime.utcnow() - start, str(method), str(params)[0:50])
     return result
예제 #6
0
 def _dispatch(self, method, params):
     """
     Custom _dispatch so we can log exceptions and the time taken to
     execute each method.
     """
     start = datetime.utcnow()
     try:
         result = SimpleXMLRPCDispatcher._dispatch(self, method, params)
     except:
         logger.exception('Error handling XML-RPC call %s', str(method))
         logger.debug('Time: %s %s %s', datetime.utcnow() - start, str(method), str(params)[0:50])
         raise
     logger.debug('Time: %s %s %s', datetime.utcnow() - start, str(method), str(params)[0:50])
     return result
예제 #7
0
 def _dispatch(self, method, params):
     """
     Custom _dispatch so we can log exceptions and the time taken to
     execute each method.
     """
     start = datetime.utcnow()
     try:
         result = SimpleXMLRPCDispatcher._dispatch(self, method, params)
     except:
         logger.exception('Error handling XML-RPC call %s', str(method))
         logger.debug('Time: %s %s %s', datetime.utcnow() - start, str(method), str(params)[0:50])
         raise
     logger.debug('Time: %s %s %s', datetime.utcnow() - start, str(method), str(params)[0:50])
     return result
예제 #8
0
    def _dispatch(self, method, params):
        """Dispatches an RPC call.

        :param method: the name of the function to call
        :type method: string
        :param params: the arguments to pass to method
        :type params: list

        """
        requires_auth = method in self.methods_requiring_authentication
        if requires_auth:
            if not len(params) >= 2:
                raise RPCAuthenticationError('<no_username_given>')
            username, password, params = params[0], params[1], params[2:]
            if (username, password) != (self.username, self.password):
                raise RPCAuthenticationError(username)
        return SimpleXMLRPCDispatcher._dispatch(self, method, params)
예제 #9
0
class ServerGateway(object):
    def __init__(self, prefix):
        self.prefix = prefix
        try:
            # Python 2.4
            self.dispatcher = SimpleXMLRPCDispatcher()
        except TypeError:
            # Python 2.5
            self.dispatcher = SimpleXMLRPCDispatcher(allow_none=False, encoding=None)

    def add_function(self, name, func):
        self.dispatcher.register_function(func, ".".join([self.prefix, name]))

    def connect( self, func=None, name=None):
        def _connector(func):
            self.add_function(not name and func.__name__ or name, func)
            return func

        if not func:
            return _connector
        else:
            _connector(func)
            return func

    def __call__(self, request, *args, **kwargs):
        if kwargs:
            raise RuntimeError("Xmlrpc server gateway cannot handle key variable argumets")

        def custom_dispatch(method, params):
            return self.dispatcher._dispatch(method, params + tuple(args))

        response = HttpResponse()
        if len(request.POST):
            response.write(self.dispatcher._marshaled_dispatch(request.raw_post_data, custom_dispatch))
        else:
            methods = self.dispatcher.system_listMethods()

            response['Content-Type'] = 'text/plain'
            for method in methods:
                # __doc__
                help = self.dispatcher.system_methodHelp(method)
                response.write("%s:\n    %s\n\n" % (method, help))

        response['Content-Length'] = str(len(response.content))
        return response
예제 #10
0
class XmlRpc(object):
    def __init__(self, encoding=None, allow_none=True, use_datetime=0):
        self.__queue = []
        self.__encoding = encoding
        self.__allow_none = allow_none
        self.__use_datetime = use_datetime
        self.__dispatcher = SimpleXMLRPCDispatcher(allow_none=allow_none, encoding=encoding)
        
    def splitfmt(self):
        return "xml"
        
    def initiate_request(self, method, args, kwargs, completion):
        if kwargs: raise NotImplemented("Keyword arguments not supported in XML-RPC mode")
        self.__queue.append(completion)
        return xmlrpc_dumps(args, method, encoding=self.__encoding, allow_none=self.__allow_none)
        
    def handle_response(self, rstr):
        completion = self.__queue.pop(0)
        try:
            response = xmlrpc_loads(rstr, self.__use_datetime)
            completion(response[0][0], None)
        except Fault as f:
            completion(None, f)
    
    def dispatch_request(self, reqstr):
        p,m = xmlrpc_loads(reqstr, self.__use_datetime)
        try:
            rsp = self.__dispatcher._dispatch(m, p)
            response = xmlrpc_dumps((rsp,), allow_none=self.__allow_none, encoding=self.__encoding)
        except Fault as fault:
            response = xmlrpc_dumps(fault, allow_none=self.__allow_none, encoding=self.__encoding)
        except:
            exc_type, exc_value, exc_tb = sys.exc_info()
            response = xmlrpc_dumps(
                Fault(1, "%s:%s" % (exc_type, exc_value)),
                encoding=self.__encoding, allow_none=self.__allow_none)
        return response
        
    def register_function(self, func, name=None):
        self.__dispatcher.register_function(func, name)
        
예제 #11
0
    def _dispatch(self, method, params):
        """Executes the requested method and measure how long it took

        :param method: method name
        :param params: method parameters
        :return: Returns a tuple: the method result and the measured time, unless it is a sys method,
        doesn't need to measure sys methods
        :raise xmlrpclib.Fault:
        """
        logger.info("CALL {}({})".format(method, ", ".join([repr(p) for p in params])))
        try:
            before = datetime.now()
            if params:
                cavity = None
                first = params[0]
                print type(first), first
                if isinstance(first, str):
                    print self._cavities
                    cavity = self._cavities.get(first, None)
                    print 'cavity is', cavity
                    if cavity is not None:
                        logger.set_tid(cavity)
                        logger.info('hahaha')
            result = SimpleXMLRPCDispatcher._dispatch(self, method, params)
            delta = datetime.now() - before
            delta = unicode('%s.%06d' % (delta.seconds, delta.microseconds))
            if not method.startswith('sys'):
                return result, delta
            else:
                return result
        except Exception:
            exc_type, exc_value, exc_tb = sys.exc_info()
            tb = traceback.format_exc()
            msg = "%s: %s\n%s" % (exc_type, exc_value, tb)
            logger.exception("FAULT {}: {}".format(method, msg))
            raise xmlrpclib.Fault(1, msg)
예제 #12
0
 def _dispatch(self, method, auth, response_method, params):
     params = (self.auth, response_method, params)
     SimpleXMLRPCDispatcher._dispatch(self, method, params)
예제 #13
0
 def _dispatch(self, method, params):
     if not method.startswith('system.'):
         # Add store to all of our own methods
         params = (self.store,)+tuple(params)
     return SimpleXMLRPCDispatcher._dispatch(self, method, params)
예제 #14
0
 def _dispatch(self, method, auth, response_method, params):
     params = (self.auth, response_method, params)
     SimpleXMLRPCDispatcher._dispatch(self, method, params)
예제 #15
0
    def _dispatch(self, method, params):

        retn = SimpleXMLRPCDispatcher._dispatch(self, method, params)
        retn = translate(retn)
        return retn