def handle(self):
        """Handle requests.

        WARNING! You must call prepare() BEFORE calling handle()
        """
        assert self.prepared, "You have to call prepare before handle"
        rset, wset, xset = self._select()
        for readable in rset:
            if readable == self._read.fileno():
                # don't care i just need to clean readable flag
                self._read.recv(1024)
            elif readable == self.socket.handle.fileno():
                client = self.socket.accept().handle
                self.clients[client.fileno()] = Connection(
                    client, self.wake_up)
            else:
                connection = self.clients[readable]
                connection.read()
                if connection.status == WAIT_PROCESS:
                    itransport = TTransport.TMemoryBuffer(connection.message)
                    otransport = TTransport.TMemoryBuffer()
                    iprot = self.in_protocol.getProtocol(itransport)
                    oprot = self.out_protocol.getProtocol(otransport)
                    self.tasks.put([
                        self.processor, iprot, oprot, otransport,
                        connection.ready
                    ])
        for writeable in wset:
            self.clients[writeable].write()
        for oob in xset:
            self.clients[oob].close()
            del self.clients[oob]
Esempio n. 2
0
    def stringReceived(self, frame):
        tmi = TTransport.TMemoryBuffer(frame)
        tmo = TTransport.TMemoryBuffer()

        iprot = self.factory.iprot_factory.getProtocol(tmi)
        oprot = self.factory.oprot_factory.getProtocol(tmo)

        d = self.factory.processor.process(iprot, oprot)
        d.addCallbacks(self.processOk, self.processError, callbackArgs=(tmo, ))
Esempio n. 3
0
    def render_POST(self, request):
        request.content.seek(0, 0)
        data = request.content.read()
        tmi = TTransport.TMemoryBuffer(data)
        tmo = TTransport.TMemoryBuffer()

        iprot = self.inputProtocolFactory.getProtocol(tmi)
        oprot = self.outputProtocolFactory.getProtocol(tmo)

        d = self.processor.process(iprot, oprot)
        d.addCallback(self._cbProcess, request, tmo)
        return server.NOT_DONE_YET
Esempio n. 4
0
    def stringReceived(self, frame):
        tr = TTransport.TMemoryBuffer(frame)
        iprot = self._iprot_factory.getProtocol(tr)
        (fname, mtype, rseqid) = iprot.readMessageBegin()

        try:
            method = self.recv_map[fname]
        except KeyError:
            method = getattr(self.client, 'recv_' + fname)
            self.recv_map[fname] = method

        method(iprot, mtype, rseqid)
Esempio n. 5
0
 def do_POST(self):
     # Don't care about the request path.
     itrans = TTransport.TFileObjectTransport(self.rfile)
     otrans = TTransport.TFileObjectTransport(self.wfile)
     itrans = TTransport.TBufferedTransport(
         itrans, int(self.headers['Content-Length']))
     otrans = TTransport.TMemoryBuffer()
     iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
     oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
     try:
         thttpserver.processor.process(iprot, oprot)
     except ResponseException as exn:
         exn.handler(self)
     else:
         self.send_response(200)
         self.send_header("content-type", "application/x-thrift")
         self.end_headers()
         self.wfile.write(otrans.getvalue())