Python thrift.transport.TTransport.TBufferedTransport() Examples

The following are 20 code examples of thrift.transport.TTransport.TBufferedTransport(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module thrift.transport.TTransport , or try the search function .
Example #1
Source File: THttpServer.py    From ajs2 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 processor,
                 server_address,
                 inputProtocolFactory,
                 outputProtocolFactory=None,
                 server_class=BaseHTTPServer.HTTPServer):
        """Set up protocol factories and HTTP server.

        See BaseHTTPServer for server_address.
        See TServer for protocol factories.
        """
        if outputProtocolFactory is None:
            outputProtocolFactory = inputProtocolFactory

        TServer.TServer.__init__(self, processor, None, None, None,
                                 inputProtocolFactory, outputProtocolFactory)

        thttpserver = self

        class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
            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())

        self.httpd = server_class(server_address, RequestHander) 
Example #2
Source File: THttpServer.py    From thrift with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 processor,
                 server_address,
                 inputProtocolFactory,
                 outputProtocolFactory=None,
                 server_class=BaseHTTPServer.HTTPServer):
        if outputProtocolFactory is None:
            outputProtocolFactory = inputProtocolFactory
        TServer.TServer.__init__(self, processor, None, None, None,
                                 inputProtocolFactory, outputProtocolFactory)
        thttpserver = self
        class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
            def do_POST(self):
                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())
        self.httpd = server_class(server_address, RequestHander) 
Example #3
Source File: client.py    From hazelcast-python-client with Apache License 2.0 5 votes vote down vote up
def __init__(self, host, port):
        try:
            # Make socket
            transport = TSocket.TSocket(host=host, port=port)
            # Buffering is critical. Raw sockets are very slow
            transport = TTransport.TBufferedTransport(transport)
            # Wrap in a protocol
            protocol = TBinaryProtocol.TBinaryProtocol(transport)
            self.remote_controller = RemoteController.Client(protocol)
            # Connect!
            transport.open()
        except Thrift.TException as tx:
            self.logger.warn('%s' % tx.message) 
Example #4
Source File: THttpServer.py    From SOLO with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 processor,
                 server_address,
                 inputProtocolFactory,
                 outputProtocolFactory=None,
                 server_class=BaseHTTPServer.HTTPServer):
        if outputProtocolFactory is None:
            outputProtocolFactory = inputProtocolFactory
        TServer.TServer.__init__(self, processor, None, None, None,
                                 inputProtocolFactory, outputProtocolFactory)
        thttpserver = self
        class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
            def do_POST(self):
                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())
        self.httpd = server_class(server_address, RequestHander) 
Example #5
Source File: thrift_client_mixin.py    From kingpin with Apache License 2.0 5 votes vote down vote up
def connect(self, conn_timeout_ms, req_timeout_ms):
        """Connect to the endpoint specified in self.host and self.port.

        .. note:: It makes connection only if it's not already connected.

        """
        if self.connected:
            self._socket.setTimeout(req_timeout_ms)
            return

        # Socket.
        if self.is_ssl:
            self._socket = TSSLSocket(self.host, self.port, self.validate, self.ca_certs)
        else:
            self._socket = TNoDelaySocket(self.host, self.port)
        # Set socket timeout
        self._socket.setTimeout(conn_timeout_ms)

        # Transport.
        self._transport = TBufferedTransport(self._socket)

        # open() may throw TTransportException() if fail to connect.
        self._transport.open()

        # Protocol.
        self._protocol = self.protocol_factory.getProtocol(self._transport)

        # Client.
        # Need to get the parent class of the client class
        # Ex: <class
        # 'data_clients.follower_service_client.FollowerServiceClient'>
        #  =>  <class services.follower.thrift_libs.FollowerService.Client>.
        self._client = self.__class__.__bases__[0](self._protocol)
        self.connected = True
        self.connected_at = time.time()
        self._socket.setTimeout(req_timeout_ms) 
Example #6
Source File: thrift.py    From sublime-elasticsearch-client with MIT License 5 votes vote down vote up
def _make_connection(self):
        socket = self._tsocket_class(*self._tsocket_args)
        socket.setTimeout(self.timeout * 1000.0)
        if self._framed_transport:
            transport = TTransport.TFramedTransport(socket)
        else:
            transport = TTransport.TBufferedTransport(socket)

        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
        client = Rest.Client(protocol)
        client.transport = transport
        transport.open()
        return client 
Example #7
Source File: thrift.py    From sublime-elasticsearch-client with MIT License 5 votes vote down vote up
def __init__(self, host='localhost', port=9500, framed_transport=False, use_ssl=False, **kwargs):
        """
        :arg framed_transport: use `TTransport.TFramedTransport` instead of
            `TTransport.TBufferedTransport`
        """
        if not THRIFT_AVAILABLE:
            raise ImproperlyConfigured("Thrift is not available.")

        super(ThriftConnection, self).__init__(host=host, port=port, **kwargs)
        self._framed_transport = framed_transport
        self._tsocket_class = TSocket.TSocket
        if use_ssl:
            self._tsocket_class = TSSLSocket.TSSLSocket 
        self._tsocket_args = (host, port) 
Example #8
Source File: thrift.py    From splunk-elasticsearch with Apache License 2.0 5 votes vote down vote up
def _make_connection(self):
        socket = self._tsocket_class(*self._tsocket_args)
        socket.setTimeout(self.timeout * 1000.0)
        if self._framed_transport:
            transport = TTransport.TFramedTransport(socket)
        else:
            transport = TTransport.TBufferedTransport(socket)

        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
        client = Rest.Client(protocol)
        client.transport = transport
        transport.open()
        return client 
Example #9
Source File: thrift.py    From splunk-elasticsearch with Apache License 2.0 5 votes vote down vote up
def __init__(self, host='localhost', port=9500, framed_transport=False, use_ssl=False, **kwargs):
        """
        :arg framed_transport: use `TTransport.TFramedTransport` instead of
            `TTransport.TBufferedTransport`
        """
        if not THRIFT_AVAILABLE:
            raise ImproperlyConfigured("Thrift is not available.")

        super(ThriftConnection, self).__init__(host=host, port=port, **kwargs)
        self._framed_transport = framed_transport
        self._tsocket_class = TSocket.TSocket
        if use_ssl:
            self._tsocket_class = TSSLSocket.TSSLSocket 
        self._tsocket_args = (host, port) 
Example #10
Source File: THttpServer.py    From galaxy-sdk-python with Apache License 2.0 5 votes vote down vote up
def __init__(self,
               processor,
               server_address,
               inputProtocolFactory,
               outputProtocolFactory=None,
               server_class=BaseHTTPServer.HTTPServer):
    """Set up protocol factories and HTTP server.

    See BaseHTTPServer for server_address.
    See TServer for protocol factories.
    """
    if outputProtocolFactory is None:
      outputProtocolFactory = inputProtocolFactory

    TServer.TServer.__init__(self, processor, None, None, None,
        inputProtocolFactory, outputProtocolFactory)

    thttpserver = self

    class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
      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, exn:
          exn.handler(self)
        else: 
Example #11
Source File: client.py    From web_develop with GNU General Public License v3.0 5 votes vote down vote up
def get_client():
    transport = TSocket.TSocket('localhost', 8200)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = PasteFileService.Client(protocol)
    transport.open()
    return client 
Example #12
Source File: conftest.py    From pymapd with Apache License 2.0 5 votes vote down vote up
def _check_open():
    """
    Test to see if OmniSci running on localhost and socket open
    """
    socket = TSocket.TSocket("localhost", 6274)
    transport = TTransport.TBufferedTransport(socket)

    try:
        transport.open()
        return True
    except TTransportException:
        return False 
Example #13
Source File: __init__.py    From forsun with MIT License 5 votes vote down vote up
def connect(self):
        self.transport = TSocket(self.host, self.port)
        self.transport = TBufferedTransport(self.transport)
        protocol = TBinaryProtocol(self.transport)
        self.client = Client(protocol)
        self.transport.open() 
Example #14
Source File: THttpServer.py    From Aditmadzs2 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 processor,
                 server_address,
                 inputProtocolFactory,
                 outputProtocolFactory=None,
                 server_class=BaseHTTPServer.HTTPServer):
        """Set up protocol factories and HTTP server.

        See BaseHTTPServer for server_address.
        See TServer for protocol factories.
        """
        if outputProtocolFactory is None:
            outputProtocolFactory = inputProtocolFactory

        TServer.TServer.__init__(self, processor, None, None, None,
                                 inputProtocolFactory, outputProtocolFactory)

        thttpserver = self

        class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
            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())

        self.httpd = server_class(server_address, RequestHander) 
Example #15
Source File: scannerGet.py    From Learning_Python with MIT License 5 votes vote down vote up
def connectHBase():
    '''
    连接远程HBase
    :return: 连接HBase的客户端实例
    '''
    # thrift默认端口是9090
    socket = TSocket.TSocket('10.0.86.245',9090) # 10.0.86.245是master结点ip
    socket.setTimeout(5000)
    transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Hbase.Client(protocol)
    socket.open()
    return client 
Example #16
Source File: python3_thrift_hbase2(paper_creator_aff_try).py    From Learning_Python with MIT License 5 votes vote down vote up
def connectHBase():
    '''
    连接远程HBase
    :return: 连接HBase的客户端实例
    '''
    # thrift默认端口是9090
    socket = TSocket.TSocket('10.0.86.245',9090) # 10.0.86.245是master结点ip
    socket.setTimeout(5000)
    transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Hbase.Client(protocol)
    socket.open()
    return client 
Example #17
Source File: python3_thrift_hbase2.py    From Learning_Python with MIT License 5 votes vote down vote up
def connectHBase():
    '''
    连接远程HBase
    :return: 连接HBase的客户端实例
    '''
    # thrift默认端口是9090
    socket = TSocket.TSocket('10.0.86.245',9090) # 10.0.86.245是master结点ip
    socket.setTimeout(5000)
    transport = TTransport.TBufferedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Hbase.Client(protocol)
    socket.open()
    return client 
Example #18
Source File: THttpServer.py    From Protect4 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 processor,
                 server_address,
                 inputProtocolFactory,
                 outputProtocolFactory=None,
                 server_class=BaseHTTPServer.HTTPServer):
        """Set up protocol factories and HTTP server.

        See BaseHTTPServer for server_address.
        See TServer for protocol factories.
        """
        if outputProtocolFactory is None:
            outputProtocolFactory = inputProtocolFactory

        TServer.TServer.__init__(self, processor, None, None, None,
                                 inputProtocolFactory, outputProtocolFactory)

        thttpserver = self

        class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
            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())

        self.httpd = server_class(server_address, RequestHander) 
Example #19
Source File: sampleIDLapp.py    From vmx-docker-lwaftr with Apache License 2.0 4 votes vote down vote up
def Main():
    parser = argparse.ArgumentParser(prog=os.path.basename(__file__), description='Sample JET application')
    parser.add_argument("--user", nargs='?', help="Username for authentication by JET server (default:%(default)s)",
                        type=str, default=DEFAULT_JSD_USERNAME)
    parser.add_argument("--password", nargs='?', help="Password for authentication by JET server (default:%(default)s",
                        type=str, default=DEFAULT_JSD_PASSWORD)
    parser.add_argument("--address", nargs='?', help="Address of the JSD server. (default: %(default)s)",
                        type=str, default=DEFAULT_JSD_HOST)
    parser.add_argument("--port", nargs='?', help="Port number of the JSD request-response server. (default: %(default)s)",
                        type=int, default=DEFAULT_JSD_PORT)
    parser.add_argument("--certificate", nargs='?', help="Certificate full path. (default: %(default)s)",
                        type= str, default=DEFAULT_JSD_SSL_CERTIFICATE_PATH)
    args = parser.parse_args()


    try:
        # Make socket
        if (args.certificate is not None):
            # SSL connection
            if os.path.exists(args.certificate):
                transport = TSSLSocket.TSSLSocket(args.address,
                                                  args.port,
                                                  ca_certs=args.certificate)
            else:
                print('Certificate file %s does not exist' %(args.certificate))
                raise Exception('Given certificate %s does not exist'
                                %(args.certificate))
        else:
            transport = TSocket.TSocket(args.address, args.port)

        # Buffering is critical. Raw sockets are very slow
        transport = TTransport.TBufferedTransport(transport)
        # Wrap in a protocol
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        mux_mgmt_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "ManagementService")
        mux_route_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol,"RouteService")
        transport.open()
        # IMPORTANT: The first service api to be called should be checkLogin
        mgmt_client = ManagementService.Client(mux_mgmt_protocol)
        result = mgmt_client.LoginCheck(args.user, args.password)
        if result is not True:
            raise ValueError('Login failed for User:%s' %args.user)
        print 'Invoked LoginCheck \nreturn = ', result
        print 'Requesting for mgmt tests'
        ManagementTests(mgmt_client, args.user, args.password)
        print 'Requesting for route tests'
        route_client = RouteService.Client(mux_route_protocol)
        RouteTests(route_client)
    except Exception as tx:
        print '%s' % (tx.message)
    return 
Example #20
Source File: hive.py    From airflow with Apache License 2.0 4 votes vote down vote up
def get_metastore_client(self):
        """
        Returns a Hive thrift client.
        """
        import hmsclient
        from thrift.transport import TSocket, TTransport
        from thrift.protocol import TBinaryProtocol

        conn = self._find_valid_server()

        if not conn:
            raise AirflowException("Failed to locate the valid server.")

        auth_mechanism = conn.extra_dejson.get('authMechanism', 'NOSASL')

        if conf.get('core', 'security') == 'kerberos':
            auth_mechanism = conn.extra_dejson.get('authMechanism', 'GSSAPI')
            kerberos_service_name = conn.extra_dejson.get('kerberos_service_name', 'hive')

        conn_socket = TSocket.TSocket(conn.host, conn.port)

        if conf.get('core', 'security') == 'kerberos' \
                and auth_mechanism == 'GSSAPI':
            try:
                import saslwrapper as sasl
            except ImportError:
                import sasl

            def sasl_factory():
                sasl_client = sasl.Client()
                sasl_client.setAttr("host", conn.host)
                sasl_client.setAttr("service", kerberos_service_name)
                sasl_client.init()
                return sasl_client

            from thrift_sasl import TSaslClientTransport
            transport = TSaslClientTransport(sasl_factory, "GSSAPI", conn_socket)
        else:
            transport = TTransport.TBufferedTransport(conn_socket)

        protocol = TBinaryProtocol.TBinaryProtocol(transport)

        return hmsclient.HMSClient(iprot=protocol)