Ejemplo n.º 1
0
    def process(self, rendering, request:Request, response:Response, responseCnt:ResponseContent, **keyargs):
        '''
        @see: HandlerBranchingProceed.process
        
        Create the render for the response object.
        '''
        assert isinstance(rendering, Processing), 'Invalid processing %s' % rendering
        assert isinstance(request, Request), 'Invalid request %s' % request
        assert isinstance(response, Response), 'Invalid response %s' % response
        assert isinstance(responseCnt, ResponseContent), 'Invalid response content %s' % responseCnt
        
        # Resolving the character set
        if responseCnt.charSet:
            try: codecs.lookup(responseCnt.charSet)
            except LookupError: responseCnt.charSet = None
        else: responseCnt.charSet = None

        if not responseCnt.charSet:
            if Request.accCharSets in request and request.accCharSets is not None:
                for charSet in request.accCharSets:
                    try: codecs.lookup(charSet)
                    except LookupError: continue
                    responseCnt.charSet = charSet
                    break
            if not responseCnt.charSet: responseCnt.charSet = self.charSetDefault

        resolved = False
        if responseCnt.type:
            renderChain = Chain(rendering)
            renderChain.process(request=request, response=response, responseCnt=responseCnt, **keyargs)
            if renderChain.doAll().isConsumed():
                if response.isSuccess is not False:
                    response.code, response.isSuccess = ENCODING_UNKNOWN
                    response.text = 'Content type \'%s\' not supported for rendering' % responseCnt.type
            else: resolved = True

        if not resolved:
            # Adding None in case some encoder is configured as default.
            if Request.accTypes in request and request.accTypes is not None:
                contentTypes = itertools.chain(request.accTypes, self.contentTypeDefaults)
            else: contentTypes = self.contentTypeDefaults
            for contentType in contentTypes:
                responseCnt.type = contentType
                renderChain = Chain(rendering)
                renderChain.process(request=request, response=response, responseCnt=responseCnt, **keyargs)
                if not renderChain.doAll().isConsumed(): break
            else:
                raise DevelError('There is no renderer available, this is more likely a setup issues since the '
                                 'default content types should have resolved the renderer')
Ejemplo n.º 2
0
    def __call__(self):
        '''
        Provides the next multi part request content based on the provided multi part stream.
        '''
        if self._nextCnt is not None: return self._nextCnt

        stream, processing = self._stream, self._processing
        assert isinstance(stream, StreamMultiPart), 'Invalid stream %s' % stream
        assert isinstance(processing, Processing), 'Invalid processing %s' % processing

        if not stream._flag & (FLAG_CONTENT_END | FLAG_MARK_END):
            if not stream._flag & FLAG_MARK_START:
                while True:
                    stream._readToMark(self._data.packageSize)
                    if stream._flag & FLAG_MARK_START: break
                    if stream._flag & FLAG_END: return

            req = processing.ctx.request()
            self._nextCnt = reqCnt = self._requestCnt.__class__()
            assert isinstance(req, RequestPopulate), 'Invalid request %s' % req
            assert isinstance(reqCnt, RequestContentMultiPart), 'Invalid request content %s' % reqCnt

            req.headers = stream._pullHeaders()
            if stream._flag & FLAG_CLOSED: stream._flag ^= FLAG_CLOSED

            reqCnt.source = stream
            reqCnt.fetchNextContent = NextContent(reqCnt, self._response, self._processing, self._data, stream)
            reqCnt.previousContent = self._requestCnt
            
            chain = Chain(self._processing).process(request=req, requestCnt=reqCnt, response=self._response)
            return chain.doAll().arg.requestCnt
Ejemplo n.º 3
0
    def __call__(self):
        '''
        Provides the next multi part request content based on the provided multi part stream.
        '''
        if self._nextCnt is not None: return self._nextCnt

        stream, processing = self._stream, self._processing
        assert isinstance(stream,
                          StreamMultiPart), 'Invalid stream %s' % stream
        assert isinstance(processing,
                          Processing), 'Invalid processing %s' % processing

        if not stream._flag & (FLAG_CONTENT_END | FLAG_MARK_END):
            if not stream._flag & FLAG_MARK_START:
                while True:
                    stream._readToMark(self._data.packageSize)
                    if stream._flag & FLAG_MARK_START: break
                    if stream._flag & FLAG_END: return

            req = processing.ctx.request()
            self._nextCnt = reqCnt = self._requestCnt.__class__()
            assert isinstance(req, RequestPopulate), 'Invalid request %s' % req
            assert isinstance(
                reqCnt,
                RequestContentMultiPart), 'Invalid request content %s' % reqCnt

            req.headers = stream._pullHeaders()
            if stream._flag & FLAG_CLOSED: stream._flag ^= FLAG_CLOSED

            reqCnt.source = stream
            reqCnt.fetchNextContent = NextContent(reqCnt, self._response,
                                                  self._processing, self._data,
                                                  stream)
            reqCnt.previousContent = self._requestCnt

            chain = Chain(self._processing).process(request=req,
                                                    requestCnt=reqCnt,
                                                    response=self._response)
            return chain.doAll().arg.requestCnt
Ejemplo n.º 4
0
    def process(self, rendering, request: Request, response: Response,
                responseCnt: ResponseContent, **keyargs):
        '''
        @see: HandlerBranchingProceed.process
        
        Create the render for the response object.
        '''
        assert isinstance(rendering,
                          Processing), 'Invalid processing %s' % rendering
        assert isinstance(request, Request), 'Invalid request %s' % request
        assert isinstance(response, Response), 'Invalid response %s' % response
        assert isinstance(
            responseCnt,
            ResponseContent), 'Invalid response content %s' % responseCnt

        # Resolving the character set
        if responseCnt.charSet:
            try:
                codecs.lookup(responseCnt.charSet)
            except LookupError:
                responseCnt.charSet = None
        else:
            responseCnt.charSet = None

        if not responseCnt.charSet:
            if Request.accCharSets in request and request.accCharSets is not None:
                for charSet in request.accCharSets:
                    try:
                        codecs.lookup(charSet)
                    except LookupError:
                        continue
                    responseCnt.charSet = charSet
                    break
            if not responseCnt.charSet:
                responseCnt.charSet = self.charSetDefault

        resolved = False
        if responseCnt.type:
            renderChain = Chain(rendering)
            renderChain.process(request=request,
                                response=response,
                                responseCnt=responseCnt,
                                **keyargs)
            if renderChain.doAll().isConsumed():
                if response.isSuccess is not False:
                    response.code, response.isSuccess = ENCODING_UNKNOWN
                    response.text = 'Content type \'%s\' not supported for rendering' % responseCnt.type
            else:
                resolved = True

        if not resolved:
            # Adding None in case some encoder is configured as default.
            if Request.accTypes in request and request.accTypes is not None:
                contentTypes = itertools.chain(request.accTypes,
                                               self.contentTypeDefaults)
            else:
                contentTypes = self.contentTypeDefaults
            for contentType in contentTypes:
                responseCnt.type = contentType
                renderChain = Chain(rendering)
                renderChain.process(request=request,
                                    response=response,
                                    responseCnt=responseCnt,
                                    **keyargs)
                if not renderChain.doAll().isConsumed(): break
            else:
                raise DevelError(
                    'There is no renderer available, this is more likely a setup issues since the '
                    'default content types should have resolved the renderer')