Exemplo n.º 1
0
    async def resolve(self, request: web.Request):
        """Resolve resource.

        Return (UrlMappingMatchInfo, allowed_methods) pair.
        """
        if (request.path != '/'
                and request.url.parts[1] not in self.hass.data[DATA_PANELS]):
            return None, set()

        if request.method != hdrs.METH_GET:
            return None, {'GET'}

        return web_urldispatcher.UrlMappingMatchInfo({}, self._route), {'GET'}
Exemplo n.º 2
0
    async def resolve(
        self, request: web.Request
    ) -> Tuple[Optional[web_urldispatcher.UrlMappingMatchInfo], Set[str]]:
        """Resolve resource.

        Return (UrlMappingMatchInfo, allowed_methods) pair.
        """
        if (request.path != "/"
                and request.url.parts[1] not in self.hass.data[DATA_PANELS]):
            return None, set()

        if request.method != hdrs.METH_GET:
            return None, {"GET"}

        return web_urldispatcher.UrlMappingMatchInfo({}, self._route), {"GET"}
Exemplo n.º 3
0
    def resolve(self, method: str, path: str, match_dict: dict):
        allowed_methods = set()

        if path is None:
            allowed_methods.update(self._routes)
            if method in self._routes:
                route = self._routes[method]
            elif hdrs.METH_ANY in self._routes:
                route = self._routes[hdrs.METH_ANY]
            else:
                return None, allowed_methods
            return wu.UrlMappingMatchInfo(match_dict, route), allowed_methods
        elif not path:
            location = path
            tail = None
        else:
            parts = path.split('/', 1)
            if len(parts) == 2:
                location, tail = parts
            else:
                location = parts[0]
                tail = None

        if location in self._subs:
            return self._subs[location].resolve(
                method=method,
                path=tail,
                match_dict=match_dict)

        for pattern, sublocation in self._patterns:
            m = pattern.match(path)
            if m is not None:
                for key, value in m.groupdict().items():
                    match_dict[key] = parse.unquote(value)

                index = m.end()
                if len(path) > index:
                    if path[index] == '/':
                        index += 1
                    tail = path[index:]
                else:
                    tail = None

                return sublocation.resolve(
                    method=method, path=tail, match_dict=match_dict)
        return None, allowed_methods
Exemplo n.º 4
0
 async def resolve(self, request: web.Request):
     if request.url.parts[1] == "manifest.webmanifest":
         return None, {"GET"}
     return web_urldispatcher.UrlMappingMatchInfo({}, self._route), {"GET"}