当前位置: 首页>>代码示例>>Python>>正文


Python TBinaryProtocol.TBinaryProtocol方法代码示例

本文整理汇总了Python中thrift.protocol.TBinaryProtocol.TBinaryProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python TBinaryProtocol.TBinaryProtocol方法的具体用法?Python TBinaryProtocol.TBinaryProtocol怎么用?Python TBinaryProtocol.TBinaryProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thrift.protocol.TBinaryProtocol的用法示例。


在下文中一共展示了TBinaryProtocol.TBinaryProtocol方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def open(self):
        """Establish HTTP connection to the server.

        Note: THttpClient also supports https and will use http/https according
        to the scheme in the URL it is given.
        """
        self._lock.acquire()
        try:
            self._transport = THttpClient.THttpClient(self._collector_url)
            self._transport.open()
            protocol = TBinaryProtocol.TBinaryProtocol(self._transport)
            self._client = ReportingService.Client(protocol)
        except Thrift.TException:
            self._open_exceptions_count += 1
        else:
            self.ready = True
        finally:
            self._lock.release()


    # May throw an Exception on failure. 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:23,代码来源:thrift_connection.py

示例2: __init__

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def __init__(
            self,
            thrift_url='',
            auth=None,
            client=jaeger.Client,
            transport=sync.SyncTransport,
            http_transport=THttpClient.THttpClient):
        self.transport = transport(self)
        self.thrift_url = thrift_url
        self.auth = auth
        self.http_transport = http_transport(uri_or_host=thrift_url)
        self.client = client(
            iprot=TBinaryProtocol.TBinaryProtocol(trans=self.http_transport))

        # set basic auth header
        if auth is not None:
            import base64
            auth_header = '{}:{}'.format(*auth)
            decoded = base64.b64encode(auth_header.encode()).decode('ascii')
            basic_auth = dict(Authorization='Basic {}'.format(decoded))
            self.http_transport.setCustomHeaders(basic_auth) 
开发者ID:census-instrumentation,项目名称:opencensus-python,代码行数:23,代码来源:__init__.py

示例3: __init__

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def __init__(self, node=None, host=None, port=None, ks_name='ks', cf_name='cf',
                 cassandra_interface='11'):
        """
        initializes the connection.
         - node: a ccm node. If supplied, the host and port, and cassandra_interface
           will be pulled from the node.
         - host, port: overwritten if node is supplied
         - ks_name, cf_name: all operations are done on the supplied ks and cf
         - cassandra_interface: '07' and '11' are currently supported. This is the
           thrift interface to cassandra. '11' suffices for now except when creating
           keyspaces against cassandra0.7, in which case 07 must be used.
        """
        if node:
            host, port = node.network_interfaces['thrift']
        self.node = node
        self.host = host
        self.port = port
        self.cassandra_interface = cassandra_interface

        # import the correct version of the cassandra thrift interface
        # and set self.Cassandra as the imported module
        module_name = 'cassandra-thrift.v%s' % cassandra_interface
        imp = __import__(module_name, globals(), locals(), ['Cassandra'])
        self.Cassandra = imp.Cassandra

        socket = TSocket.TSocket(host, port)
        self.transport = TTransport.TFramedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = self.Cassandra.Client(protocol)

        socket.open()
        self.open_socket = True

        self.ks_name = ks_name
        self.cf_name = cf_name 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:37,代码来源:putget_test.py

示例4: get_thrift_client

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def get_thrift_client(host='127.0.0.1', port=9160):
    socket = TSocket.TSocket(host, port)
    transport = TTransport.TFramedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Cassandra.Client(protocol)
    client.transport = transport
    return client 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:9,代码来源:thrift_test.py

示例5: __init__

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def __init__(self, host, port):
        self.host = host
        self.port = port
        transport = TSocket.TSocket(host, port)
        self.transport = TTransport.TFramedTransport(transport)
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = Nimbus.Client(self.protocol) 
开发者ID:dispel4py,项目名称:dispel4py,代码行数:9,代码来源:client.py

示例6: connectHBase

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
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 
开发者ID:SparksFly8,项目名称:Learning_Python,代码行数:15,代码来源:python3_thrift_hbase2.py

示例7: connect

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
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() 
开发者ID:snower,项目名称:forsun,代码行数:8,代码来源:__init__.py

示例8: get_client

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def get_client():
    transport = TSocket.TSocket('localhost', 8200)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = PasteFileService.Client(protocol)
    transport.open()
    return client 
开发者ID:dongweiming,项目名称:web_develop,代码行数:9,代码来源:client.py

示例9: __init__

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def __init__(self, thrift_url="", auth=None):
        self.thrift_url = thrift_url
        self.auth = auth
        self.http_transport = THttpClient.THttpClient(
            uri_or_host=self.thrift_url
        )
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.http_transport)

        # set basic auth header
        if auth is not None:
            auth_header = "{}:{}".format(*auth)
            decoded = base64.b64encode(auth_header.encode()).decode("ascii")
            basic_auth = dict(Authorization="Basic {}".format(decoded))
            self.http_transport.setCustomHeaders(basic_auth) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:16,代码来源:__init__.py

示例10: options

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def options():
    return MessageSnifferOptions(
        iface=None,
        port=9090,
        ip=None,
        pcap_file=get_pcap_path('calc-service-binary'),
        protocol=TBinaryProtocol,
        finagle_thrift=False,
        read_values=True,
        max_queued=2000,
        max_message_size=2000,
        debug=False) 
开发者ID:pinterest,项目名称:thrift-tools,代码行数:14,代码来源:test_printer.py

示例11: detect_protocol

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
def detect_protocol(cls, data, default=None):
        """ TODO: support fbthrift, finagle-thrift, finagle-mux, CORBA """
        if cls.is_compact_protocol(data):
            return TCompactProtocol
        elif cls.is_binary_protocol(data):
            return TBinaryProtocol
        elif cls.is_json_protocol(data):
            return TJSONProtocol

        if default is None:
            raise ValueError('Unknown protocol')

        return default 
开发者ID:pinterest,项目名称:thrift-tools,代码行数:15,代码来源:thrift_message.py

示例12: __init__

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
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) 
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:15,代码来源:client.py

示例13: get_metastore_client

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
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) 
开发者ID:apache,项目名称:airflow,代码行数:45,代码来源:hive.py

示例14: Main

# 需要导入模块: from thrift.protocol import TBinaryProtocol [as 别名]
# 或者: from thrift.protocol.TBinaryProtocol import TBinaryProtocol [as 别名]
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 
开发者ID:Juniper,项目名称:vmx-docker-lwaftr,代码行数:53,代码来源:sampleIDLapp.py


注:本文中的thrift.protocol.TBinaryProtocol.TBinaryProtocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。