Ejemplo n.º 1
0
class FolkloreBinaryProtocol(object):
    """Thrift binary protocol wrapper

    Used for ``thrift_protocol_class`` config.

    :param sock: client socket
    """
    def __init__(self, sock):
        self.sock = sock
        self.trans = None

    def get_proto(self):
        """Create a TBinaryProtocol instance
        """
        self.trans = TBufferedTransport(self.sock)
        return TBinaryProtocol(self.trans)

    def close(self):
        """Close underlying transport
        """
        if self.trans is not None:
            try:
                self.trans.close()
            finally:
                self.trans = None
Ejemplo n.º 2
0
def client_context(service, host, port,
                   proto_factory=TBinaryProtocolFactory()):
    try:
        transport = TBufferedTransport(TSocket(host, port))
        protocol = proto_factory.get_protocol(transport)
        transport.open()
        yield TClient(service, protocol)
    finally:
        transport.close()
Ejemplo n.º 3
0
def make_client(service, host, port, proto_factory=TBinaryProtocolFactory()):
    transport = TBufferedTransport(TSocket(host, port))
    protocol = proto_factory.get_protocol(transport)
    transport.open()
    return TClient(service, protocol)
Ejemplo n.º 4
0
 def get_proto(self):
     """Create a TBinaryProtocol instance
     """
     self.trans = TBufferedTransport(self.sock)
     return TBinaryProtocol(self.trans)