Exemple #1
0
    def lookup(self, path: str, method: str) -> HandlerLookup:
        lookup_key = method + ' ' + path
        try:
            return self._lookup_cache[lookup_key]
        except KeyError:
            pass

        try:
            name, kwargs = self._adapter.match(path, method)
        except werkzeug.exceptions.NotFound:
            raise exceptions.NotFound() from None
        except werkzeug.exceptions.MethodNotAllowed:
            raise exceptions.MethodNotAllowed() from None
        except werkzeug.routing.RequestRedirect as exc:
            path = urlparse(exc.new_url).path
            raise exceptions.Found(path) from None

        view = self._views[name]

        self._lookup_cache[lookup_key] = (view, kwargs)
        if len(self._lookup_cache) > self._lookup_cache_size:
            self._lookup_cache.pop(next(iter(
                self._lookup_cache)))  # pragma: nocover

        return (view, kwargs)
Exemple #2
0
 def lookup(self, path: str, method: str) -> RouterLookup:
     try:
         (name, kwargs) = self.adapter.match(path, method)
     except werkzeug.exceptions.NotFound:
         raise exceptions.NotFound()
     except werkzeug.exceptions.MethodNotAllowed:
         raise exceptions.MethodNotAllowed()
     (view, pipeline) = self.views[name]
     return (view, pipeline, kwargs)
Exemple #3
0
    def lookup(self, path: str, method: str) -> RouterLookup:
        try:
            (name, kwargs) = self.adapter.match(path, method)
        except werkzeug.exceptions.NotFound:
            raise exceptions.NotFound()
        except werkzeug.exceptions.MethodNotAllowed:
            raise exceptions.MethodNotAllowed()
        except werkzeug.routing.RequestRedirect as exc:
            path = urlparse(exc.new_url).path
            raise exceptions.Found(path)

        (view, pipeline) = self.views[name]
        return (view, pipeline, kwargs)
Exemple #4
0
    def lookup(self, path: str, method: str):
        lookup_key = method + " " + path
        try:
            return self._lookup_cache[lookup_key]
        except KeyError:
            pass

        try:
            name, path_params = self.adapter.match(path, method)
        except werkzeug.exceptions.NotFound:
            raise exceptions.NotFound() from None
        except werkzeug.exceptions.MethodNotAllowed:
            raise exceptions.MethodNotAllowed() from None
        except werkzeug.routing.RequestRedirect as exc:
            path = urlparse(exc.new_url).path
            raise exceptions.Found(path) from None

        route = self.name_lookups[name]

        self._lookup_cache[lookup_key] = (route, path_params)
        if len(self._lookup_cache) > self._lookup_cache_size:
            self._lookup_cache.pop(next(iter(self._lookup_cache)))

        return (route, path_params)