本文整理汇总了Python中thrift.transport.TTransport.TBufferedTransport方法的典型用法代码示例。如果您正苦于以下问题:Python TTransport.TBufferedTransport方法的具体用法?Python TTransport.TBufferedTransport怎么用?Python TTransport.TBufferedTransport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thrift.transport.TTransport
的用法示例。
在下文中一共展示了TTransport.TBufferedTransport方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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:
示例2: __init__
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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)
示例3: connectHBase
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [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
示例4: connect
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [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()
示例5: _check_open
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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
示例6: get_client
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [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
示例7: __init__
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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)
示例8: _make_connection
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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
示例9: connect
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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)
示例10: __init__
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [as 别名]
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)
示例11: __init__
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [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)
示例12: get_metastore_client
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [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)
示例13: Main
# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TBufferedTransport [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