コード例 #1
0
    def _process(self, method):
        assert isinstance(method, str), 'Invalid method %s' % method
        proc = self.server.processing
        assert isinstance(proc, Processing), 'Invalid processing %s' % proc
        
        request, requestCnt = proc.ctx.request(), proc.ctx.requestCnt()
        assert isinstance(request, RequestHTTP), 'Invalid request %s' % request
        assert isinstance(requestCnt, RequestContentHTTP), 'Invalid request content %s' % requestCnt
        
        if RequestHTTP.clientIP in request: request.clientIP = self.client_address[0]
        url = urlparse(self.path)
        request.scheme, request.method = HTTP, method.upper()
        request.uri = url.path.lstrip('/')
        if RequestHTTP.headers in request: request.headers = dict(self.headers)
        if RequestHTTP.parameters in request: request.parameters = parse_qsl(url.query, True, False)

        chain = Chain(proc, FILL_ALL, request=request, requestCnt=requestCnt)
        chain.onFinalize(self._processRespond)
        
        if RequestContentHTTPAsyncore.doContentReader in requestCnt:
            while True:
                if not chain.do():
                    self._readContinue()
                    break
                if requestCnt.doContentReader:
                    assert callable(requestCnt.doContentReader), 'Invalid content reader %s' % requestCnt.doContentReader
                    self._chain, self._reader = chain, requestCnt.doContentReader
                    self._readContent()  # Now we proceed to read content stage
                    break
        else:
            self._readContinue()
            chain.execute()
コード例 #2
0
ファイル: server_asyncore.py プロジェクト: vivienney/Ally-Py
 def _process(self, method):
     assert isinstance(method, str), 'Invalid method %s' % method
     proc = self.server.processing
     assert isinstance(proc, Processing), 'Invalid processing %s' % proc
     
     request, requestCnt = proc.ctx.request(), proc.ctx.requestCnt()
     assert isinstance(request, RequestHTTP), 'Invalid request %s' % request
     assert isinstance(requestCnt, RequestContentHTTP), 'Invalid request content %s' % requestCnt
     
     if RequestHTTP.clientIP in request: request.clientIP = self.client_address[0]
     url = urlparse(self.path)
     request.scheme, request.method = HTTP, method.upper()
     request.headers = dict(self.headers)
     request.uri = url.path.lstrip('/')
     request.parameters = parse_qsl(url.query, True, False)
     
     requestCnt.source = self.rfile
     
     chain = Chain(proc)
     chain.process(**proc.fillIn(request=request, requestCnt=requestCnt,
                                 response=proc.ctx.response(), responseCnt=proc.ctx.responseCnt()))
     
     def respond():
         response, responseCnt = chain.arg.response, chain.arg.responseCnt
         assert isinstance(response, ResponseHTTP), 'Invalid response %s' % response
         assert isinstance(responseCnt, ResponseContentHTTP), 'Invalid response content %s' % responseCnt
 
         if ResponseHTTP.headers in response and response.headers is not None:
             for name, value in response.headers.items(): self.send_header(name, value)
 
         assert isinstance(response.status, int), 'Invalid response status code %s' % response.status
         if ResponseHTTP.text in response and response.text: text = response.text
         elif ResponseHTTP.code in response and response.code: text = response.code
         else: text = None
         self.send_response(response.status, text)
         self.end_headers()
 
         if ResponseContentHTTP.source in responseCnt and responseCnt.source is not None:
             if isinstance(responseCnt.source, IInputStream): source = readGenerator(responseCnt.source, self.bufferSize)
             else: source = responseCnt.source
             self._writeq.append((WRITE_ITER, iter(source)))
             
         self._writeq.append((WRITE_CLOSE, None))
         
     chain.callBack(respond)
     
     while True:
         if not chain.do():
             self._next(3)  # Now we proceed to write stage
             break
         if RequestContentHTTPAsyncore.contentReader in requestCnt and requestCnt.contentReader is not None:
             self._next(2)  # Now we proceed to read stage
             self._reader = requestCnt.contentReader
             break
コード例 #3
0
    def _process(self, method):
        assert isinstance(method, str), 'Invalid method %s' % method
        proc = self.server.processing
        assert isinstance(proc, Processing), 'Invalid processing %s' % proc

        request, requestCnt = proc.ctx.request(), proc.ctx.requestCnt()
        assert isinstance(request, RequestHTTP), 'Invalid request %s' % request
        assert isinstance(
            requestCnt,
            RequestContentHTTP), 'Invalid request content %s' % requestCnt

        if RequestHTTP.clientIP in request:
            request.clientIP = self.client_address[0]
        url = urlparse(self.path)
        request.scheme, request.method = HTTP, method.upper()
        request.uri = url.path.lstrip('/')
        if RequestHTTP.headers in request: request.headers = dict(self.headers)
        if RequestHTTP.parameters in request:
            request.parameters = parse_qsl(url.query, True, False)

        chain = Chain(proc, FILL_ALL, request=request, requestCnt=requestCnt)
        chain.onFinalize(self._processRespond)

        if RequestContentHTTPAsyncore.doContentReader in requestCnt:
            while True:
                if not chain.do():
                    self._readContinue()
                    break
                if requestCnt.doContentReader:
                    assert callable(
                        requestCnt.doContentReader
                    ), 'Invalid content reader %s' % requestCnt.doContentReader
                    self._chain, self._reader = chain, requestCnt.doContentReader
                    self._readContent()  # Now we proceed to read content stage
                    break
        else:
            self._readContinue()
            chain.execute()