本文整理匯總了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.
示例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)
示例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
示例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
示例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)
示例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
示例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()
示例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
示例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)
示例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)
示例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
示例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)
示例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)
示例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