Esempio n. 1
0
    def lookupProcedure(self, procedurePath):
        """
        Lookup a method dynamically.

        1. First, see if it's provided by a sub-handler.
        2. Or try a self-defined method (prefixed with `xmlrpc_`)
        3. Lastly, try dynamically mapped methods.
        4. Or fail loudly.
        """
        log.msg("LOOKING UP:", procedurePath)

        if procedurePath.find(self.separator) != -1:
            prefix, procedurePath = procedurePath.split(self.separator, 1)
            handler = self.getSubHandler(prefix)
            if handler is None:
                raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
                                            "no such subHandler %s" % prefix)
            return handler.lookupProcedure(procedurePath)

        # Try self-defined methods first...
        f = getattr(self, "xmlrpc_%s" % procedurePath, None)

        # Try mapped methods second...
        if f is None:
            f = self._procedure_map.get(procedurePath, None)

        if not f:
            raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
                "procedure %s not found" % procedurePath)
        elif not callable(f):
            raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
                "procedure %s not callable" % procedurePath)
        else:
            return f
Esempio n. 2
0
 def lookupProcedure(self, procedurePath):
     """Override XMLRPC lookupProcedure in order to call getSubHandler
     also if the procedurePath was not registered"""
     pp = procedurePath.split(self.separator)
     # If just one item, it is a function of FileServer itself
     if len(pp) == 1:
         f = getattr(self, 'xmlrpc_' + pp[0], False)
         if f is False:
             raise xmlrpc.NoSuchFunction(
                 self.NOT_FOUND,
                 "FileServer procedure %s not found" % procedurePath)
         return f
     # Function name is always the last item
     f = pp.pop(-1)
     # Filename requires rejoining the remaining part of pp
     prefix = '/'.join(pp)
     # Retrieve the served file
     sub = self.getSubHandler(prefix)
     if sub is False:
         raise xmlrpc.NoSuchFunction(
             self.NOT_FOUND, "SharedFile %s not found for procedure %s" %
             (prefix, procedurePath))
     # Retrieve the function - try first with xmlrpc_ prefix
     cb = getattr(sub, 'xmlrpc_' + f, False)
     # try as-is
     if cb is False:
         cb = getattr(sub, f, False)
     if cb is False:
         raise xmlrpc.NoSuchFunction(
             self.NOT_FOUND,
             "SharedFile method %s not found on handler %s for procedure %s"
             % (f, prefix, procedurePath))
     # Return the function
     return cb
Esempio n. 3
0
 def lookupProcedure(self, procedurePath):
     try:
         return self.methods[procedurePath]
     except KeyError as e:
         raise xmlrpc.NoSuchFunction(
             self.NOT_FOUND,
             "procedure %s not found: %s" % (procedurePath, e))
Esempio n. 4
0
 def lookupProcedure(self, procedureName):
     """
     Lookup a procedure from a fixed set of choices, either I{echo} or
     I{system.listeMethods}.
     """
     if procedureName == 'echo':
         return self.echo
     raise xmlrpc.NoSuchFunction(
         self.NOT_FOUND, 'procedure %s not found' % (procedureName,))
Esempio n. 5
0
 def lookupProcedure(self, procedureName):
     """
     Lookup a procedure from a fixed set of choices, either I{echo} or
     I{system.listeMethods}.
     """
     if procedureName == "echo":
         return self.echo
     raise xmlrpc.NoSuchFunction(
         self.NOT_FOUND, "procedure {} not found".format(procedureName))
Esempio n. 6
0
    def _getFunction(self, functionPath):
        """

        """
        if functionPath.find(self.separator) != -1:
            prefix, functionPath = functionPath.split(self.separator, 1)
            handler = self.getSubHandler(prefix)
            if handler is None:
                raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
                                            "no such subHandler %s" % prefix)
            return handler._getFunction(functionPath)
        f = getattr(self.api, functionPath, None)
        if not f:
            raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
                                        "function %s not found" % functionPath)
        elif not callable(f):
            raise xmlrpc.NoSuchFunction(
                self.NOT_FOUND, "function %s not callable" % functionPath)
        return f
Esempio n. 7
0
 def lookupProcedure(self, procedurePath):
     with log.enter(obj=self, args={'procedurePath': procedurePath}) as tm:
         try:
             if (self.handlers.has_key(procedurePath)):
                 return self.handlers[procedurePath]
             else:
                 wsgi_path = procedurePath.split('.')
                 wsgi_module = import_module('.'.join(
                     wsgi_path[:len(wsgi_path) - 1]))
                 wsgi_app = getattr(wsgi_module,
                                    wsgi_path[len(wsgi_path) - 1])
                 handler = DtxXmlRpcHandler(wsgi_app)
                 self.handlers[procedurePath] = handler
                 return handler
         except:
             log.err(traceback.format_exc())
             raise xmlrpc.NoSuchFunction(
                 self.NOT_FOUND, "Procedure %s not found" % procedurePath)
Esempio n. 8
0
 def _getFunction(self, methodName):
     while self.__pause:
         time.sleep(1)
     
     self.__numRequests = self.__numRequests + 1
     function = None
     try:
         def defer_function(*args):
             return deferToThread(self.__XRMethods[methodName], 
                                  *args)
         function = defer_function
         self.__logger.info(
             "[%s] processing defered XML-RPC call to: %s ..." % 
             (self.__numRequests, methodName))            
     except KeyError:
         self.__logger.warn(
             "[%s] fault %s on XML-RPC call to %s, method not found." % (
             self.__numRequests, self.NOT_FOUND, methodName))
         raise xmlrpc.NoSuchFunction(self.NOT_FOUND, 
                                     "method %s not found" % methodName)
     
     return function
 def lookupProcedure(self, procedurePath):
     try:
         return self._procedureToCallable[procedurePath]
     except KeyError as e:
         raise xmlrpc.NoSuchFunction(
             self.NOT_FOUND, "procedure %s not found" % procedurePath)
Esempio n. 10
0
 def lookupProcedure(self, procedurePath):
     try:
         return self.apiFunctions[procedurePath]
     except KeyError:
         raise xmlrpc.NoSuchFunction(self.NOT_FOUND, "procedure %s not found" % procedurePath)