Ejemplo n.º 1
0
 def __call__(self, request_uri, **kwargs):
     """Creates a request based off the class defined in the URI.
     
     Args:
         request_uri (str): URI of the request.
             String is split to get the needed request class
             
     Returns:
         Object of type Request (usually a child of Request)
         
     Raises:
         RequestDoesNotExist: Invalid request
     """
     module_chunk, _, request_chunk = request_uri.rpartition('.')
     request_chunk = request_chunk[0].upper() + request_chunk[1:]
     try:
         module = import_module('%s.%s' % (ABS_IMPORT_PREFIX, module_chunk))
         request_class = getattr(module, request_chunk)
         request = request_class(**kwargs)
         assert isinstance(request, Request)
         return request
     except ImportError:
         raise RequestDoesNotExist("'%s' module does not exist"
                                   % module_chunk)
     except AttributeError:
         raise RequestDoesNotExist("'%s' request does not exist in "
                                   "'%s' module" % (request_chunk,
                                   module_chunk))
Ejemplo n.º 2
0
    def importService(self, service):
        """Import a service class
        
        Args:
            service (str): Service object to return.
            
        Returns:
            Instance of the requested service class.
            
        Raises:
            RequestDoesNotExist: The service import failed.
        """
        from pysis.core.client import Client

        try:
            moduleName = 'pysis.services.' + service.lower()
            module = import_module(moduleName)
            service_class = getattr(module, service)
            service = service_class(Client())
        except ImportError:
            raise RequestDoesNotExist("'%s' module does not exist" % moduleName)
        
        return service