コード例 #1
0
ファイル: router.py プロジェクト: rcosnita/fantastico
    def handle_route(self, url, environ):
        '''Method used to identify the given url method handler. It enrich the environ dictionary with a new entry that
        holds a controller instance and a function to be executed from that controller.'''

        route_configs = self._find_url_regex(url)
        route_config = None

        http_verb = environ.get("REQUEST_METHOD").upper()

        for route_config in route_configs:
            if http_verb not in route_config["http_verbs"]:
                route_config = None
                continue

            break

        if not route_config:
            raise FantasticoHttpVerbNotSupported(http_verb)

        http_verb_config = route_config["http_verbs"][http_verb]

        last_dot = http_verb_config.rfind(".")

        if last_dot == -1:
            raise FantasticoNoRoutesError("Route %s has an invalid controller mapped." % url)

        controller_cls = http_verb_config[:last_dot]
        controller_meth = http_verb_config[last_dot + 1:]

        environ["route_%s_handler" % url] = {"controller": instantiator.instantiate_class(controller_cls,
                                                                                          [self._settings_facade]),
                                             "method": controller_meth,
                                             "url_params": route_config.get("url_params")}
コード例 #2
0
ファイル: router.py プロジェクト: rcosnita/fantastico
    def get_loaders(self):
        '''Method used to retrieve all available loaders. If loaders are not currently instantiated they are by these method.
        This method also supports multi threaded workers mode of wsgi with really small memory footprint. It uses an internal
        lock so that it makes sure available loaders are instantiated only once per wsgi worker.'''

        conf_loaders = self._settings_facade.get("routes_loaders") or []

        if len(conf_loaders) == 0:
            raise FantasticoNoRoutesError("No loaders configured.")

        if self._loader_lock is None and len(self._loaders) == 0:
            self._loader_lock = threading.Lock()
            self._loaders = []

        if self._loader_lock:
            self._loader_lock.acquire()

        if len(self._loaders) == 0:
            for loader_cls in conf_loaders:
                loader = instantiator.instantiate_class(loader_cls, [self._settings_facade])

                self._loaders.append(loader)

        if self._loader_lock is not None:
            self._loader_lock.release()
            self._loader_lock = None

        return self._loaders
コード例 #3
0
    def get_loaders(self):
        '''Method used to retrieve all available loaders. If loaders are not currently instantiated they are by these method.
        This method also supports multi threaded workers mode of wsgi with really small memory footprint. It uses an internal
        lock so that it makes sure available loaders are instantiated only once per wsgi worker.'''

        conf_loaders = self._settings_facade.get("routes_loaders") or []

        if len(conf_loaders) == 0:
            raise FantasticoNoRoutesError("No loaders configured.")

        if self._loader_lock is None and len(self._loaders) == 0:
            self._loader_lock = threading.Lock()
            self._loaders = []

        if self._loader_lock:
            self._loader_lock.acquire()

        if len(self._loaders) == 0:
            for loader_cls in conf_loaders:
                loader = instantiator.instantiate_class(
                    loader_cls, [self._settings_facade])

                self._loaders.append(loader)

        if self._loader_lock is not None:
            self._loader_lock.release()
            self._loader_lock = None

        return self._loaders
コード例 #4
0
ファイル: settings.py プロジェクト: rcosnita/fantastico
    def get_config(self):
        '''Method used to return the active configuration which is used by this facade.

        :rtype: :py:class:`fantastico.settings.BasicSettings`
        :returns: Active configuration currently used.'''

        active_config = self._environ.get(self.__ENV_ACTIVE_CONFIG) or "fantastico.settings.BasicSettings"

        self._cached_config = self._cached_config or instantiator.instantiate_class(active_config)

        return self._cached_config
コード例 #5
0
ファイル: fantastico_app.py プロジェクト: rcosnita/fantastico
    def _wrap_middlewares(self):
        """Method used to register all configured middlewares in the correct order."""

        installed_middlewares = self._settings_facade.get("installed_middleware")

        curr_app_cls, curr_app_inst = FantasticoApp, FantasticoApp.OldCallableApp(self.__call__)

        for middleware_cls in reversed(installed_middlewares):
            middleware = instantiator.instantiate_class(middleware_cls, [curr_app_inst])

            curr_app_cls.__call__ = lambda inst, *args: middleware(*args)

            curr_app_cls, curr_app_inst = middleware.__class__, FantasticoApp.OldCallableApp(middleware.__call__)
コード例 #6
0
ファイル: settings.py プロジェクト: bopopescu/fantastico
    def get_config(self):
        '''Method used to return the active configuration which is used by this facade.

        :rtype: :py:class:`fantastico.settings.BasicSettings`
        :returns: Active configuration currently used.'''

        active_config = self._environ.get(
            self.__ENV_ACTIVE_CONFIG) or "fantastico.settings.BasicSettings"

        self._cached_config = self._cached_config or instantiator.instantiate_class(
            active_config)

        return self._cached_config
コード例 #7
0
    def _wrap_middlewares(self):
        '''Method used to register all configured middlewares in the correct order.'''

        installed_middlewares = self._settings_facade.get(
            "installed_middleware")

        curr_app_cls, curr_app_inst = FantasticoApp, FantasticoApp.OldCallableApp(
            self.__call__)

        for middleware_cls in reversed(installed_middlewares):
            middleware = instantiator.instantiate_class(
                middleware_cls, [curr_app_inst])

            curr_app_cls.__call__ = lambda inst, *args: middleware(*args)

            curr_app_cls, curr_app_inst = middleware.__class__, FantasticoApp.OldCallableApp(
                middleware.__call__)
コード例 #8
0
    def handle_route(self, url, environ):
        '''Method used to identify the given url method handler. It enrich the environ dictionary with a new entry that
        holds a controller instance and a function to be executed from that controller.'''

        route_configs = self._find_url_regex(url)
        route_config = None

        http_verb = environ.get("REQUEST_METHOD").upper()

        for route_config in route_configs:
            if http_verb not in route_config["http_verbs"]:
                route_config = None
                continue

            break

        if not route_config:
            raise FantasticoHttpVerbNotSupported(http_verb)

        http_verb_config = route_config["http_verbs"][http_verb]

        last_dot = http_verb_config.rfind(".")

        if last_dot == -1:
            raise FantasticoNoRoutesError(
                "Route %s has an invalid controller mapped." % url)

        controller_cls = http_verb_config[:last_dot]
        controller_meth = http_verb_config[last_dot + 1:]

        environ["route_%s_handler" % url] = {
            "controller":
            instantiator.instantiate_class(controller_cls,
                                           [self._settings_facade]),
            "method":
            controller_meth,
            "url_params":
            route_config.get("url_params")
        }