本文整理汇总了Python中thrift.transport.TTransport.TBufferedTransport.open方法的典型用法代码示例。如果您正苦于以下问题:Python TBufferedTransport.open方法的具体用法?Python TBufferedTransport.open怎么用?Python TBufferedTransport.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thrift.transport.TTransport.TBufferedTransport
的用法示例。
在下文中一共展示了TBufferedTransport.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def __init__(self, host=None, port=10000, authMechanism=None, user=None, password=None, database=None, configuration=None, timeout=None):
authMechanisms = set(['NOSASL', 'PLAIN', 'KERBEROS', 'LDAP'])
if authMechanism not in authMechanisms:
raise NotImplementedError('authMechanism is either not supported or not implemented')
#Must set a password for thrift, even if it doesn't need one
#Open issue with python-sasl
if authMechanism == 'PLAIN' and (password is None or len(password) == 0):
password = 'password'
socket = TSocket(host, port)
socket.setTimeout(timeout)
if authMechanism == 'NOSASL':
transport = TBufferedTransport(socket)
else:
sasl_mech = 'PLAIN'
saslc = sasl.Client()
saslc.setAttr("username", user)
saslc.setAttr("password", password)
if authMechanism == 'KERBEROS':
krb_host,krb_service = self._get_krb_settings(host, configuration)
sasl_mech = 'GSSAPI'
saslc.setAttr("host", krb_host)
saslc.setAttr("service", krb_service)
saslc.init()
transport = TSaslClientTransport(saslc, sasl_mech, socket)
self.client = TCLIService.Client(TBinaryProtocol(transport))
transport.open()
res = self.client.OpenSession(TOpenSessionReq(username=user, password=password, configuration=configuration))
self.session = res.sessionHandle
if database is not None:
with self.cursor() as cur:
query = "USE {0}".format(database)
cur.execute(query)
示例2: main
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def main(args):
if(len(args) < 4):
print "%s tablename column pattern output[option]"%(args[0])
sys.exit(1)
tablename=args[1]
column = args[2]
pattern = args[3]
outputfile = ""
if(len(args)>4):
outputfile=args[4]
getConfiguration('host.properties')
transport = TBufferedTransport(TSocket(hbaseHost, 9090))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
global client
client = Hbase.Client(protocol)
# tablename = "%s_%s_master_%s"%(orgId,subOrgId,orgId)
rowlist = columnGrep(tablename,column,pattern)
print len(rowlist)
printStdout(rowlist,outputfile)
示例3: main
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def main(argv):
p = argparse.ArgumentParser()
add_common_args(p)
# Since THeaderTransport acts as framed transport when detected frame, we
# cannot use --transport=framed as it would result in 2 layered frames.
p.add_argument('--override-transport')
p.add_argument('--override-protocol')
args = p.parse_args()
assert args.protocol == 'header'
assert args.transport == 'buffered'
assert not args.ssl
sock = TSocket(args.host, args.port, socket_family=socket.AF_INET)
if not args.override_transport or args.override_transport == 'buffered':
trans = TBufferedTransport(sock)
elif args.override_transport == 'framed':
print('TFRAMED')
trans = TFramedTransport(sock)
else:
raise ValueError('invalid transport')
trans.open()
if not args.override_protocol or args.override_protocol == 'binary':
proto = TBinaryProtocol(trans)
elif args.override_protocol == 'compact':
proto = TCompactProtocol(trans)
else:
raise ValueError('invalid transport')
test_void(proto)
test_void(proto)
trans.close()
示例4: main
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def main(args):
# getColumnInfo(table_name)
if(len(args)<2):
print "TableScan.py tableName No[10]"
sys.exit(1)
table_name=args[1]
NO=10;
if(len(args)<3):
NO=10;
else:
NO=int(args[2]);
getConfiguration('host.properties')
transport = TBufferedTransport(TSocket(hbaseHost, 9090))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
global client
client = Hbase.Client(protocol)
ret=getRowsLimit(table_name,NO)
printRowsResult(ret)
示例5: __init__
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def __init__(self, host=None, port=10000, authMechanism=None, user=None, password=None, database=None, cursorclass = Cursor):
authMechanisms = set(['NOSASL', 'PLAIN', 'KERBEROS', 'LDAP'])
if authMechanism not in authMechanisms or authMechanism == 'KERBEROS':
raise NotImplementedError('authMechanism is either not supported or not implemented')
#Must set a password for thrift, even if it doesn't need one
#Open issue with python-sasl
if authMechanism == 'PLAIN' and (password is None or len(password) == 0):
password = 'password'
socket = TSocket(host, port)
self.cursorclass = cursorclass
if authMechanism == 'NOSASL':
transport = TBufferedTransport(socket)
else:
saslc = sasl.Client()
saslc.setAttr("username", user)
saslc.setAttr("password", password)
saslc.init()
transport = TSaslClientTransport(saslc, "PLAIN", socket)
self.client = TCLIService.Client(TBinaryProtocol(transport))
transport.open()
res = self.client.OpenSession(TOpenSessionReq())
self.session = res.sessionHandle
if database is not None:
with self.cursor() as cur:
query = "USE {0}".format(database)
cur.execute(query)
示例6: __init__
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def __init__( self, host, port ):
transport = TBufferedTransport(TSocket(host, port))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
self.client = HBaseThrift.Client(protocol)
self.client
示例7: __init__
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def __init__(self,context):
self.context=context
self.table = self.context.config.HBASE_STORAGE_TABLE
self.data_fam = self.context.config.HBASE_STORAGE_FAMILY
transport = TBufferedTransport(TSocket(host=self.context.config.HBASE_STORAGE_SERVER_HOST, port=self.context.config.HBASE_STORAGE_SERVER_PORT))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
self.storage = Hbase.Client(protocol)
示例8: HS2TestSuite
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
class HS2TestSuite(ImpalaTestSuite):
def setup(self):
host, port = IMPALAD_HS2_HOST_PORT.split(":")
self.socket = TSocket(host, port)
self.transport = TBufferedTransport(self.socket)
self.transport.open()
self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
self.hs2_client = TCLIService.Client(self.protocol)
def teardown(self):
if self.socket:
self.socket.close()
@staticmethod
def check_response(response,
expected_status_code = TCLIService.TStatusCode.SUCCESS_STATUS,
expected_error_prefix = None):
assert response.status.statusCode == expected_status_code
if expected_status_code != TCLIService.TStatusCode.SUCCESS_STATUS\
and expected_error_prefix is not None:
assert response.status.errorMessage.startswith(expected_error_prefix)
def close(self, op_handle):
close_op_req = TCLIService.TCloseOperationReq()
close_op_req.operationHandle = op_handle
close_op_resp = self.hs2_client.CloseOperation(close_op_req)
assert close_op_resp.status.statusCode == TCLIService.TStatusCode.SUCCESS_STATUS
def fetch(self, handle, orientation, size, expected_num_rows = None):
"""Fetches at most size number of rows from the query identified by the given
operation handle. Uses the given fetch orientation. Asserts that the fetch returns
a success status, and that the number of rows returned is equal to size, or
equal to the given expected_num_rows (it one was given)."""
fetch_results_req = TCLIService.TFetchResultsReq()
fetch_results_req.operationHandle = handle
fetch_results_req.orientation = orientation
fetch_results_req.maxRows = size
fetch_results_resp = self.hs2_client.FetchResults(fetch_results_req)
HS2TestSuite.check_response(fetch_results_resp)
num_rows = size
if expected_num_rows is not None:
num_rows = expected_num_rows
assert len(fetch_results_resp.results.rows) == num_rows
return fetch_results_resp
def fetch_fail(self, handle, orientation, expected_error_prefix):
"""Attempts to fetch rows from the query identified by the given operation handle.
Asserts that the fetch returns an error with an error message matching the given
expected_error_prefix."""
fetch_results_req = TCLIService.TFetchResultsReq()
fetch_results_req.operationHandle = handle
fetch_results_req.orientation = orientation
fetch_results_req.maxRows = 100
fetch_results_resp = self.hs2_client.FetchResults(fetch_results_req)
HS2TestSuite.check_response(fetch_results_resp, TCLIService.TStatusCode.ERROR_STATUS,
expected_error_prefix)
return fetch_results_resp
示例9: connect
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def connect(server='localhost', port=9090, timeout=None):
socket = TSocket(server, int(port))
if timeout is not None:
socket.setTimeout(timeout)
transport = TBufferedTransport(socket)
transport.open()
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
client = Hbase.Client(protocol)
return client
示例10: main
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def main(args):
getConfiguration('host.properties')
transport = TBufferedTransport(TSocket(hbaseHost, 9090))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
global client
client = Hbase.Client(protocol)
getTableNames()
示例11: getMasterTables
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def getMasterTables(hbaseHost):
transport = TBufferedTransport(TSocket(hbaseHost, 9090))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
for table in client.getTableNames():
if 'master' in table:
print table
transport.close()
示例12: hs2_port_is_open
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def hs2_port_is_open(self):
"""Test if the HS2 port is open. Does not need to authenticate."""
# Impyla will try to authenticate as part of connecting, so preserve previous logic
# that uses the HS2 thrift code directly.
try:
socket = TSocket(self.hostname, self.hs2_port)
transport = TBufferedTransport(socket)
transport.open()
transport.close()
return True
except Exception, e:
LOG.info(e)
return False
示例13: start
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def start():
logger = logging.getLogger('ted')
logger.addHandler(logging.StreamHandler())
transport = TBufferedTransport(TSocket('localhost', 9030))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)
global client
client = ted.TedService.Client(protocol)
shell = code.InteractiveConsole(globals())
shell.interact("Run client.<command> where command is a Ted command (eg: getWatching())\nSee dir(Iface) for commands")
示例14: __init__
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
def __init__(self, host=None, port=10000, authMechanism=None, user=None, password=None, database=None):
authMechanisms = {'NOSASL', 'PLAIN', 'KERBEROS', 'LDAP'}
if authMechanism not in authMechanisms or authMechanism == 'KERBEROS':
raise NotImplementedError('authMechanism is either not supported or not implemented')
socket = TSocket(host, port)
if authMechanism == 'NOSASL':
transport = TBufferedTransport(socket)
else:
saslc = sasl.Client()
saslc.setAttr("username", user)
saslc.setAttr("password", password)
saslc.init()
transport = TSaslClientTransport(saslc, "PLAIN", socket)
self.client = TCLIService.Client(TBinaryProtocol(transport))
transport.open()
res = self.client.OpenSession(TOpenSessionReq())
self.session = res.sessionHandle
示例15: ThriftClient
# 需要导入模块: from thrift.transport.TTransport import TBufferedTransport [as 别名]
# 或者: from thrift.transport.TTransport.TBufferedTransport import open [as 别名]
class ThriftClient(object):
def __init__(self, port=6458, host="127.0.0.1"):
self.host = host
self.port = port
self.client = None
self.transport = None
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()
def execute(self, name, *args, **kwargs):
if self.client is None:
self.connect()
result = getattr(self.client, name)(*args, **kwargs)
return result
def create(self, key, second, minute = -1, hour = -1, day = -1, month = -1, week = -1, action="shell", params={}):
return self.execute("create", key, second, minute, hour, day, month, week, action, params)
def create_timeout(self, key, second, minute = -1, hour = -1, day = -1, month = -1, week = -1, count=1, action="shell", params={}):
return self.execute("createTimeout", key, second, minute, hour, day, month, week, count, action, params)
def remove(self, key):
return self.execute("remove", key)
def get(self, key):
return self.execute("get", key)
def get_current(self):
return self.execute("getCurrent")
def get_time(self, timestamp):
return self.execute("getTime", timestamp)
def get_keys(self, prefix=''):
return self.execute("getKeys", prefix)
def __del__(self):
if self.client:
self.transport.close()
self.transport = None
self.client = None