Beispiel #1
0
    def process(self, request:Request, response:Response, responseCnt:ResponseContent, **keyargs):
        '''
        @see: HandlerProcessorProceed.process
        
        Process the URI to a resource path.
        '''
        assert isinstance(request, Request), 'Invalid required request %s' % request
        assert isinstance(response, Response), 'Invalid response %s' % response
        assert isinstance(responseCnt, ResponseContent), 'Invalid response content %s' % responseCnt
        assert isinstance(request.uri, str), 'Invalid request URI %s' % request.uri
        if response.isSuccess is False: return  # Skip in case the response is in error
        
        paths = request.uri.split('/')
        i = paths[-1].rfind('.') if len(paths) > 0 else -1
        if i < 0:
            clearExtension = True
            request.extension = None
        else:
            clearExtension = i == 0
            request.extension = paths[-1][i + 1:].lower()
            paths[-1] = paths[-1][0:i]
        
        paths = [unquote(p) for p in paths if p]

        if request.extension: responseCnt.type = request.extension
        request.path = findPath(self.resourcesRoot, paths, self.converterPath)
        assert isinstance(request.path, Path), 'Invalid path %s' % request.path
        node = request.path.node
        if not node:
            # we stop the chain processing
            response.code, response.status, response.isSuccess = PATH_NOT_FOUND
            assert log.debug('No resource found for URI %s', request.uri) or True
            return
        
        if not clearExtension:
            # We need to check if the last path element is not a string property ant there might be confusion with the extension
            if isinstance(node, NodeProperty):
                assert isinstance(node, NodeProperty)
                assert isinstance(node.type, Type)
                if node.type.isOf(str):
                    response.code, response.status, response.isSuccess = PATH_NOT_FOUND
                    response.text = 'Missing trailing slash'
                    assert log.debug('Unclear extension for URI %s', request.uri) or True
                    return
                
        assert log.debug('Found resource for URI %s', request.uri) or True

        request.converterId = self.converterPath
        request.converterParameters = self.converterPath
        request.normalizerParameters = self.converterPath

        if Request.argumentsOfType in request and request.argumentsOfType is not None:
            request.argumentsOfType[Scheme] = request.scheme

        response.code, response.status, response.isSuccess = PATH_FOUND
        response.converterId = self.converterPath
Beispiel #2
0
    def process(self, request: Request, response: Response, responseCnt: ResponseContent, **keyargs):
        """
        @see: HandlerProcessorProceed.process
        
        Process the URI to a resource path.
        """
        assert isinstance(request, Request), "Invalid required request %s" % request
        assert isinstance(response, Response), "Invalid response %s" % response
        assert isinstance(responseCnt, ResponseContent), "Invalid response content %s" % responseCnt
        assert isinstance(request.uri, str), "Invalid request URI %s" % request.uri
        if response.isSuccess is False:
            return  # Skip in case the response is in error

        paths = request.uri.split("/")
        i = paths[-1].rfind(".") if len(paths) > 0 else -1
        if i < 0:
            extension = None
        else:
            extension = paths[-1][i + 1 :].lower()
            paths[-1] = paths[-1][0:i]
        paths = [unquote(p) for p in paths if p]

        request.path = findPath(self.resourcesRoot, paths, self.converterPath)
        assert isinstance(request.path, Path), "Invalid path %s" % request.path
        if not request.path.node:
            # we stop the chain processing
            response.code, response.isSuccess = RESOURCE_NOT_FOUND
            response.text = "Cannot find resources for path"
            assert log.debug("No resource found for URI %s", request.uri) or True
            return
        assert log.debug("Found resource for URI %s", request.uri) or True

        request.converterId = self.converterPath
        request.converterParameters = self.converterPath
        request.normalizerParameters = self.converterPath

        if Request.argumentsOfType in request:
            request.argumentsOfType[Scheme] = request.scheme

        assert isinstance(request.decoderHeader, IDecoderHeader), (
            "Invalid request decoder header %s" % request.decoderHeader
        )
        assert isinstance(request.uriRoot, str), "Invalid request root URI %s" % request.uriRoot
        host = request.decoderHeader.retrieve(self.headerHost)
        if host is None:
            response.code, response.isSuccess = MISSING_HEADER
            response.text = "Missing the %s header" % self.headerHost
            assert log.debug("No host header available for URI %s", request.uri) or True
            return
        response.encoderPath = EncoderPathURI(request.scheme, host, request.uriRoot, self.converterPath, extension)

        response.code, response.isSuccess = RESOURCE_FOUND
        response.converterId = self.converterPath
        if extension:
            responseCnt.type = extension
Beispiel #3
0
    def process(self, request: Request, response: Response,
                responseCnt: ResponseContent, **keyargs):
        '''
        @see: HandlerProcessorProceed.process
        
        Process the URI to a resource path.
        '''
        assert isinstance(request,
                          Request), 'Invalid required request %s' % request
        assert isinstance(response, Response), 'Invalid response %s' % response
        assert isinstance(
            responseCnt,
            ResponseContent), 'Invalid response content %s' % responseCnt
        assert isinstance(request.uri,
                          str), 'Invalid request URI %s' % request.uri
        if response.isSuccess is False:
            return  # Skip in case the response is in error

        paths = request.uri.split('/')
        i = paths[-1].rfind('.') if len(paths) > 0 else -1
        if i < 0:
            clearExtension = True
            request.extension = None
        else:
            clearExtension = i == 0
            request.extension = paths[-1][i + 1:].lower()
            paths[-1] = paths[-1][0:i]

        paths = [unquote(p) for p in paths if p]

        if request.extension: responseCnt.type = request.extension
        request.path = findPath(self.resourcesRoot, paths, self.converterPath)
        assert isinstance(request.path, Path), 'Invalid path %s' % request.path
        node = request.path.node
        if not node:
            # we stop the chain processing
            response.code, response.status, response.isSuccess = PATH_NOT_FOUND
            assert log.debug('No resource found for URI %s',
                             request.uri) or True
            return

        if not clearExtension:
            # We need to check if the last path element is not a string property ant there might be confusion with the extension
            if isinstance(node, NodeProperty):
                assert isinstance(node, NodeProperty)
                assert isinstance(node.type, Type)
                if node.type.isOf(str):
                    response.code, response.status, response.isSuccess = PATH_NOT_FOUND
                    response.text = 'Missing trailing slash'
                    assert log.debug('Unclear extension for URI %s',
                                     request.uri) or True
                    return

        assert log.debug('Found resource for URI %s', request.uri) or True

        request.converterId = self.converterPath
        request.converterParameters = self.converterPath
        request.normalizerParameters = self.converterPath

        if Request.argumentsOfType in request and request.argumentsOfType is not None:
            request.argumentsOfType[Scheme] = request.scheme

        response.code, response.status, response.isSuccess = PATH_FOUND
        response.converterId = self.converterPath