Example #1
0
 def _prepare_uimodules(self):
     """Prepare the UI Modules object"""
     if 'ui_modules' in self._settings:
         logger.debug('Preparing uimodules for import')
         try:
             # Assign the modules to the import
             self._settings['ui_modules'] = \
                 utils.import_namespaced_class(self._settings['ui_modules'])
         except ImportError as error:
             logger.error("Error importing UI Modules %s: %s",
                                self._settings['ui_modules'], error)
Example #2
0
    def _import_class(self, class_path):
        """Try and import the specified namespaced class.

        :param str class_path: The full path to the class (foo.bar.Baz)
        :rtype: class

        """
        LOGGER.debug('Importing %s', class_path)
        try:
            return utils.import_namespaced_class(class_path)
        except ImportError as error:
            LOGGER.critical('Could not import %s: %s', class_path, error)
            return None
Example #3
0
 def _prepare_transforms(self):
     """Prepare the UI Modules object"""
     if 'transforms' in self._settings:
         logger.info('Preparing %i transform class(es) for import',
                           len(self._settings['transforms']))
         transforms = list()
         for transform in self._settings['transforms']:
             try:
                 # Assign the modules to the import
                 transforms.append(utils.import_namespaced_class(transform))
             except ImportError as error:
                 logger.error("Error importing UI Modules %s: %s",
                                    self._settings['ui_modules'], error)
         self._settings['transforms'] = transforms
Example #4
0
    def _prepare_route(self, attributes):
        """Take a given inbound list for a route and parse it creating the
        route and importing the class it belongs to.

        :param list attributes: Route attributes
        :rtype: list

        """
        # Validate it's a list or set
        if type(attributes) not in (list, tuple):
            logger.error("Invalid route, must be a list or tuple: %r",
                               attributes)
            return False

        # By default we do not have extra kwargs
        kwargs = None

        # If we have a regex based route, set it up with a raw string
        if attributes[0] == 're':
            route = r"%s" % attributes[1]
            module = attributes[2]
            if len(attributes) == 4:
                kwargs = attributes[3]
        else:
            route  = r"%s" % attributes[0]
            module = attributes[1]
            if len(attributes) == 3:
                kwargs = attributes[2]

        logger.debug("Initializing route: %s with %s", route, module)

        # Return the reference to the python class at the end of the
        # namespace. eg foo.Baz, foo.bar.Baz
        try:
            handler = utils.import_namespaced_class(module)
        except ImportError as error:
            logger.error("Module import error for %s: %r",
                               module, error)
            return None

        # Our base prepared route
        prepared_route = [route, handler]

        # If the route has an optional kwargs dict
        if kwargs:
            prepared_route.append(kwargs)

        # Return the route
        return tuple(prepared_route)
Example #5
0
    def _prepare_route(self, attributes):
        """Take a given inbound list for a route and parse it creating the
        route and importing the class it belongs to.

        :param list attributes: Route attributes
        :rtype: list

        """
        # Validate it's a list or set
        if type(attributes) not in (list, tuple):
            logger.error("Invalid route, must be a list or tuple: %r",
                         attributes)
            return False

        # By default we do not have extra kwargs
        kwargs = None

        # If we have a regex based route, set it up with a raw string
        if attributes[0] == 're':
            route = r"%s" % attributes[1]
            module = attributes[2]
            if len(attributes) == 4:
                kwargs = attributes[3]
        else:
            route = r"%s" % attributes[0]
            module = attributes[1]
            if len(attributes) == 3:
                kwargs = attributes[2]

        logger.debug("Initializing route: %s with %s", route, module)

        # Return the reference to the python class at the end of the
        # namespace. eg foo.Baz, foo.bar.Baz
        try:
            handler = utils.import_namespaced_class(module)
        except ImportError as error:
            logger.error("Module import error for %s: %r", module, error)
            return None

        # Our base prepared route
        prepared_route = [route, handler]

        # If the route has an optional kwargs dict
        if kwargs:
            prepared_route.append(kwargs)

        # Return the route
        return tuple(prepared_route)