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]
Beispiel #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, ))
Beispiel #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
Beispiel #4
0
 def __init__(self, *args):
     if (len(args) == 2):
         self.__initArgs__(args[0], args[1],
                           TTransport.TTransportFactoryBase(),
                           TTransport.TTransportFactoryBase(),
                           TBinaryProtocol.TBinaryProtocolFactory(),
                           TBinaryProtocol.TBinaryProtocolFactory())
     elif (len(args) == 4):
         self.__initArgs__(args[0], args[1], args[2], args[2], args[3],
                           args[3])
     elif (len(args) == 6):
         self.__initArgs__(args[0], args[1], args[2], args[3], args[4],
                           args[5])
 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())
Beispiel #6
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)
Beispiel #7
0
    def connectionMade(self):
        self._sendSASLMessage(self.START, self.sasl.mechanism)
        initial_message = yield deferToThread(self.sasl.process)
        self._sendSASLMessage(self.OK, initial_message)

        while True:
            status, challenge = yield self._receiveSASLMessage()
            if status == self.OK:
                response = yield deferToThread(self.sasl.process, challenge)
                self._sendSASLMessage(self.OK, response)
            elif status == self.COMPLETE:
                if not self.sasl.complete:
                    msg = "The server erroneously indicated that SASL " \
                          "negotiation was complete"
                    raise TTransport.TTransportException(msg, message=msg)
                else:
                    break
            else:
                msg = "Bad SASL negotiation status: %d (%s)" % (status,
                                                                challenge)
                raise TTransport.TTransportException(msg, message=msg)

        self._sasl_negotiation_deferred = None
        ThriftClientProtocol.connectionMade(self)
Beispiel #8
0
 def connectionLost(self, reason=connectionDone):
     for k, v in six.iteritems(self.client._reqs):
         tex = TTransport.TTransportException(
             type=TTransport.TTransportException.END_OF_FILE,
             message='Connection closed')
         v.errback(tex)