def create_transport(host, port, service, transport_type="buffered", user=None, password=None, use_ssl=False, ssl_cert=None): """ Create a new Thrift Transport based on the requested type. Supported transport types: - buffered, returns simple buffered transport - plain_sasl, return a SASL transport with the PLAIN mechanism - kerberos, return a SASL transport with the GSSAPI mechanism If use_ssl is True, the connection will use SSL, optionally using the file at ssl_cert as the CA cert. """ port = int(port) if use_ssl: from thrift.transport import TSSLSocket if ssl_cert is None: sock = TSSLSocket.TSSLSocket(host, port, validate=False) else: sock = TSSLSocket.TSSLSocket(host, port, validate=True, ca_certs=ssl_cert) # Set allowed SSL / TLS protocols to a permissive set to connect to any Impala server. import ssl sock.SSL_VERSION = ssl.PROTOCOL_SSLv23 else: sock = TSocket(host, port) if transport_type.lower() == "buffered": return TBufferedTransport(sock) # Set defaults for LDAP connections if transport_type.lower() == "plain_sasl": if user is None: user = getpass.getuser() if password is None: password = "" # Initializes a sasl client from shell.thrift_sasl import TSaslClientTransport def sasl_factory(): sasl_client = sasl.Client() sasl_client.setAttr("host", host) sasl_client.setAttr("service", service) if transport_type.lower() == "plain_sasl": sasl_client.setAttr("username", user) sasl_client.setAttr("password", password) sasl_client.init() return sasl_client if transport_type.lower() == "plain_sasl": return TSaslClientTransport(sasl_factory, "PLAIN", sock) else: # GSSASPI is the underlying mechanism used by kerberos to authenticate. return TSaslClientTransport(sasl_factory, "GSSAPI", sock)
def __init__(self, hostName, port): # Create a socket to the Airavata Server transport = TSSLSocket.TSSLSocket(hostName, port, validate=False) # Use Buffered Protocol to speedup over raw sockets transport = TTransport.TBufferedTransport(transport) # Airavata currently uses Binary Protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a Airavata client to use the protocol encoder self.airavataClient = Airavata.Client(protocol) transport.open() #client_id = r'XXXXXXXXXX' #client_secret = r'XXXXXXXXXXX' #client = BackendApplicationClient(client_id=client_id) #oauth = OAuth2Session(client=client) #token = oauth.fetch_token(token_url='https://idp.scigap.org:9443/oauth2/token', client_id=client_id, client_secret=client_secret) #self.authzToken = AuthzToken(token["access_token"]) self.authzToken = AuthzToken("") claimsMap = {"userName": "******", "gatewayID": "seagrid"} self.authzToken.claimsMap = claimsMap self.gateWayId = "seagrid" print self.airavataClient.getAPIVersion(self.authzToken)
def setUp(self): if options.http_path: self.transport = THttpClient.THttpClient(options.host, port=options.port, path=options.http_path) else: if options.ssl: from thrift.transport import TSSLSocket socket = TSSLSocket.TSSLSocket(options.host, options.port, validate=False) else: socket = TSocket.TSocket(options.host, options.port) # frame or buffer depending upon args if options.framed: self.transport = TTransport.TFramedTransport(socket) else: self.transport = TTransport.TBufferedTransport(socket) if options.zlib: self.transport = TZlibTransport.TZlibTransport( self.transport, 9) self.transport.open() protocol = self.protocol_factory.getProtocol(self.transport) if options.multiple: p = TMultiplexedProtocol.TMultiplexedProtocol( protocol, "ThriftTest") self.client = ThriftTest.Client(p) p = TMultiplexedProtocol.TMultiplexedProtocol( protocol, "SecondService") self.client2 = SecondService.Client(p) else: self.client = ThriftTest.Client(protocol) self.client2 = None
def _open_connection(self, address): """ Opens a connection with a server address. :param address: the address of the server to connect to """ (url, port) = self._parse_address_for_hostname_and_port(address) if self._tls: verifier_type = self._get_verifier_type(self.cert_verification_mode) if self._proxy: proxy_host, proxy_port = self._proxy.split(":") self._transport = TProxySSLSocket(url, port, proxy_host, proxy_port, verifier_type, ca_certs=self._tls_key_path) else: ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) if self._tls_key_path is not None: ssl_context.load_cert_chain(self._tls_key_path, self._tls_key_path) ssl_context.verify_mode = verifier_type self._transport = TSSLSocket.TSSLSocket(url, port, ca_certs=self._tls_key_path, validate_callback=lambda cert, hostname: None) # disabling hostname validation else: if self._proxy: proxy_host, proxy_port = self._proxy.split(":") self._transport = TProxySocket(proxy_host, proxy_port, url, port) else: self._transport = TSocket.TSocket(url, port) self._transport = TTransport.TFramedTransport(self._transport) self._transport.open() self._protocol = TFinagleProtocol(self._transport, client_id=self._client_id)
def getFile(self, deviceId, filePath): print "device ID -> " + str(deviceId) print "file Path -> " + filePath query = ('Select DeviceIp From Devices Where DeviceId=%s' % (deviceId)) try: self.cur.execute(query) except Exception as e: print e devIp = self.cur.fetchone()[0] query = ('Select DevicePort From Devices Where DeviceId=%s' % (deviceId)) try: self.cur.execute(query) except Exception as e: print e devPort = self.cur.fetchone()[0] print devIp print devPort clientSocket = TSSLSocket.TSSLSocket(host=devIp, port=devPort, ca_certs=str(deviceId) + '.crt') clientTransport = TTransport.TFramedTransport(clientSocket) clientProtocol = TBinaryProtocol.TBinaryProtocol(clientTransport) client = clientService.Client(clientProtocol) clientTransport.open() result = client.getFileMetaData(filePath) clientTransport.close() print result return result
def setUp(self): if options.trans == 'http': uri = '{0}://{1}:{2}{3}'.format(('https' if options.ssl else 'http'), options.host, options.port, (options.http_path if options.http_path else '/')) if options.ssl: __cafile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "CA.pem") __certfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.crt") __keyfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.key") self.transport = THttpClient.THttpClient(uri, cafile=__cafile, cert_file=__certfile, key_file=__keyfile) else: self.transport = THttpClient.THttpClient(uri) else: if options.ssl: from thrift.transport import TSSLSocket socket = TSSLSocket.TSSLSocket(options.host, options.port, validate=False) else: socket = TSocket.TSocket(options.host, options.port) # frame or buffer depending upon args self.transport = TTransport.TBufferedTransport(socket) if options.trans == 'framed': self.transport = TTransport.TFramedTransport(socket) elif options.trans == 'buffered': self.transport = TTransport.TBufferedTransport(socket) elif options.trans == '': raise AssertionError('Unknown --transport option: %s' % options.trans) if options.zlib: self.transport = TZlibTransport.TZlibTransport(self.transport, 9) self.transport.open() protocol = self.get_protocol(self.transport) self.client = ThriftTest.Client(protocol) # for multiplexed services: protocol2 = self.get_protocol2(self.transport) self.client2 = SecondService.Client(protocol2) if protocol2 is not None else None
def setUp(self): if options.http_path: self.transport = THttpClient.THttpClient(options.host, port=options.port, path=options.http_path) else: if options.ssl: from thrift.transport import TSSLSocket socket = TSSLSocket.TSSLSocket(options.host, options.port, validate=False) else: socket = TSocket.TSocket(options.host, options.port) # frame or buffer depending upon args self.transport = TTransport.TBufferedTransport(socket) if options.trans == 'framed': self.transport = TTransport.TFramedTransport(socket) elif options.trans == 'buffered': self.transport = TTransport.TBufferedTransport(socket) elif options.trans == '': raise AssertionError('Unknown --transport option: %s' % options.trans) if options.zlib: self.transport = TZlibTransport.TZlibTransport( self.transport, 9) self.transport.open() protocol = self.protocol_factory.getProtocol(self.transport) self.client = ThriftTest.Client(protocol)
def setUp(self): if self.ssl: self.socket = TSSLSocket.TSSLSocket("localhost", self._port) else: self.socket = TSocket.TSocket("localhost", self._port) if self.server_type in FRAMED_TYPES \ and not isinstance(self, HeaderTest): self.transport = TTransport.TFramedTransport(self.socket) else: self.transport = TTransport.TBufferedTransport(self.socket) self.protocol = self.protocol_factory.getProtocol(self.transport) if isinstance(self, HeaderAcceleratedCompactTest): self.protocol.trans.set_protocol_id( THeaderProtocol.THeaderProtocol.T_COMPACT_PROTOCOL) self.protocol.reset_protocol() self.transport.open() self.client = ThriftTest.Client(self.protocol) if self.multiple: p = TMultiplexedProtocol.TMultiplexedProtocol( self.protocol, "ThriftTest") self.client = ThriftTest.Client(p) p = TMultiplexedProtocol.TMultiplexedProtocol( self.protocol, "SecondService") self.client2 = SecondService.Client(p) else: self.client = ThriftTest.Client(self.protocol) self.client2 = None
def _get_transport(self): """Create a Transport. A non-kerberized impalad just needs a simple buffered transport. For the kerberized version, a sasl transport is created. If SSL is enabled, a TSSLSocket underlies the transport stack; otherwise a TSocket is used. """ if self.use_ssl: # TSSLSocket needs the ssl module, which may not be standard on all Operating # Systems. Only attempt to import TSSLSocket if the user wants an SSL connection. from thrift.transport import TSSLSocket # sasl does not accept unicode strings, explicitly encode the string into ascii. host, port = self.impalad[0].encode('ascii', 'ignore'), int(self.impalad[1]) if self.use_ssl: if self.ca_cert is None: # No CA cert means don't try to verify the certificate sock = TSSLSocket.TSSLSocket(host, port, validate=False) else: sock = TSSLSocket.TSSLSocket(host, port, validate=True, ca_certs=self.ca_cert) else: sock = TSocket(host, port) if not (self.use_ldap or self.use_kerberos): return TBufferedTransport(sock) # Initializes a sasl client def sasl_factory(): sasl_client = sasl.Client() sasl_client.setAttr("host", host) if self.use_ldap: sasl_client.setAttr("username", self.user) sasl_client.setAttr("password", self.ldap_password) else: sasl_client.setAttr("service", self.kerberos_service_name) sasl_client.init() return sasl_client # GSSASPI is the underlying mechanism used by kerberos to authenticate. if self.use_kerberos: return TSaslClientTransport(sasl_factory, "GSSAPI", sock) else: return TSaslClientTransport(sasl_factory, "PLAIN", sock)
def get_transport(hostname, port): # Create a socket to the Airavata Server # TODO: validate server certificate transport = TSSLSocket.TSSLSocket(hostname, port, validate=False) # Use Buffered Protocol to speedup over raw sockets transport = TTransport.TBufferedTransport(transport) return transport
def __init__(self): try: self.socket = TSSLSocket.TSSLSocket('192.168.99.105', 9930, validate=False) except Thrift.TException as tx: print('%s' % (tx.message))
def setup_client(self): socket = TSSLSocket.TSSLSocket(host=self.test_host, port=self.test_port, validate=False) self.client_transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(self.client_transport) self.client = DemoService.Client(protocol) self.client_transport.open()
def ssl_socket_factory(host, port): """ Returns a :class:`TSSLSocket` instance. """ return TSSLSocket.TSSLSocket(host, port, ca_certs=ca_certs, validate=validate)
def _get_client(self, options): host, port = self._parse_host_port(options.host, self.default_port) socket = (TSSLSocket.TSSLSocket(host, port) if options.ssl else TSocket.TSocket(host, port)) if options.framed: transport = TTransport.TFramedTransport(socket) else: transport = TTransport.TBufferedTransport(socket) return self._get_client_by_transport(options, transport, socket=socket)
def __init__(self, ip, port): # Make SSL socket self.socket = TSSLSocket.TSSLSocket(ip, port, False) # Buffering is critical. Raw sockets are very slow self.transport = TTransport.TBufferedTransport(self.socket) # Wrap in a protocol self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport) self.sessionId = None self.streamId = None
def __init__(self, ip, ssl_port, tcp_port): # Make SSL socket self.ssl_socket = TSSLSocket.TSSLSocket(ip, ssl_port, False) self.ssl_transport = TTransport.TBufferedTransport(self.ssl_socket) self.ssl_protocol = TBinaryProtocol.TBinaryProtocol(self.ssl_transport) # Make TCP socket self.tcp_socket = TSocket.TSocket(ip, tcp_port) self.tcp_transport = TTransport.TBufferedTransport(self.tcp_socket) self.tcp_protocol = TBinaryProtocol.TBinaryProtocol(self.tcp_transport)
def _get_client_by_host(self): config = self.config host, port = self._parse_host_port(config.host, self.default_port) socket = (TSSLSocket.TSSLSocket(host, port) if config.ssl else TSocket.TSocket(host, port)) if config.framed: transport = TTransport.TFramedTransport(socket) else: transport = TTransport.TBufferedTransport(socket) return self._get_client_by_transport(config, transport, socket=socket)
def get_transport(hostname, port): """Create a socket to the Airavata Server :param hostname: Hostname of Airavata server :param port: Port of Airavata server :return: Transport object """ # TODO: validate server certificate transport = TSSLSocket.TSSLSocket(hostname, port, validate=False) # Use Buffered Protocol to speedup over raw sockets transport = TTransport.TBufferedTransport(transport) return transport
def ssl_transport_factory(host, port, env, config_file): """ SSL Thrift transport factory function. Params: * host .........: hostname of Cassandra node. * port .........: port number to connect to. * env ..........: environment variables. SSL factory will use, if passed, SSL_CERTFILE and SSL_VALIDATE variables. * config_file ..: path to cqlsh config file (usually ~/.cqlshrc). SSL factory will use, if set, certfile and validate options in [ssl] section, as well as host to certfile mapping in [certfiles] section. [certfiles] section is optional, 'validate' setting in [ssl] section is optional too. If validation is enabled then SSL certfile must be provided either in the config file or as an environment variable. Environment variables override any options set in cqlsh config file. """ configs = ConfigParser.SafeConfigParser() configs.read(config_file) def get_option(section, option): try: return configs.get(section, option) except ConfigParser.Error: return None ssl_validate = env.get('SSL_VALIDATE') if ssl_validate is None: ssl_validate = get_option('ssl', 'validate') ssl_validate = ssl_validate is None or ssl_validate.lower() != 'false' ssl_certfile = env.get('SSL_CERTFILE') if ssl_certfile is None: ssl_certfile = get_option('certfiles', host) if ssl_certfile is None: ssl_certfile = get_option('ssl', 'certfile') if ssl_validate and ssl_certfile is None: sys.exit( "Validation is enabled; SSL transport factory requires a valid certfile " "to be specified. Please provide path to the certfile in [ssl] section " "as 'certfile' option in %s (or use [certfiles] section) or set SSL_CERTFILE " "environment variable." % (config_file, )) if not ssl_certfile is None: ssl_certfile = os.path.expanduser(ssl_certfile) tsocket = TSSLSocket.TSSLSocket(host, port, ca_certs=ssl_certfile, validate=ssl_validate) return TTransport.TFramedTransport(tsocket)
def setUp(self): if self.ssl: self.socket = TSSLSocket.TSSLSocket("localhost", self._port) else: self.socket = TSocket.TSocket("localhost", self._port) if self.server_type in FRAMED_TYPES \ and not isinstance(self, HeaderTest): self.transport = TTransport.TFramedTransport(self.socket) else: self.transport = TTransport.TBufferedTransport(self.socket) self.protocol = self.protocol_factory.getProtocol(self.transport) self.transport.open() self.client = ThriftTest.Client(self.protocol)
def get_instance(self): if self.http: self.transport = THttpClient.THttpClient(self.host, self.port, self.uri) else: socket = TSSLSocket.TSSLSocket( self.host, self.port, validate=False) if self.ssl else TSocket.TSocket( self.host, self.port) if self.framed: self.transport = TTransport.TFramedTransport(socket) else: self.transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(self.transport) self.client = ThriftHiveMetastore.Client(protocol) self.transport.open() return self.client
def get_thrift_client(self, use_ssl): socket = ( TSSLSocket.TSSLSocket( host=self.cli_opts.host, port=self.cli_opts.openr_ctrl_port, # verify server cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.cli_opts.ca_file, certfile=self.cli_opts.cert_file, keyfile=self.cli_opts.key_file, verify_name=self.cli_opts.acceptable_peer_name, ) if use_ssl else TSocket.TSocket( host=self.cli_opts.host, port=self.cli_opts.openr_ctrl_port)) socket.setTimeout(self.cli_opts.timeout) transport = THeaderTransport.THeaderTransport(socket) protocol = THeaderProtocol.THeaderProtocol(transport) transport.open() return OpenrCtrl.Client(protocol)
def __init__( self, host: str, ca_file: str, cert_file: str, key_file: str, acceptable_peer_name: str, port: int = consts.Consts.CTRL_PORT, timeout_ms: int = 5000, ) -> None: socket = TSSLSocket.TSSLSocket( host=host, port=port, cert_reqs=ssl.CERT_REQUIRED, ca_certs=ca_file, certfile=cert_file, keyfile=key_file, verify_name=acceptable_peer_name, ) socket.setTimeout(timeout_ms) OpenrCtrlClient.__init__(self, host, THeaderTransport.THeaderTransport(socket))
def connect(self): """Connect to the HostHandler.""" self._logger.info( "Initialize SSLSocket using certfile=%s, keyfile=%s, capath=%s, ciphers=%s" % (self._certfile, self._keyfile, self._capath, self._ciphers)) sock = TSSLSocket.TSSLSocket(host=self._host, port=self._port, validate=self._validate, certfile=self._certfile, keyfile=self._keyfile, capath=self._capath, ciphers=self._ciphers) if self._client_timeout: sock.setTimeout(self._client_timeout * 1000) self._transport = TTransport.TFramedTransport(sock) protocol = TCompactProtocol.TCompactProtocol(self._transport) mux_protocol = TMultiplexedProtocol.TMultiplexedProtocol( protocol, self._service_name) self._client = self._client_cls(mux_protocol) self._transport.open() self._logger.info("Connected to %s:%s. for service %s" % (self._host, self._port, self._service_name))
import sys sys.path.append('gen-py') sys.path.append('gen-py/image') from image import Images from thrift import Thrift from thrift.transport import TSocket, TSSLSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol transport = TTransport.TBufferedTransport( TSSLSocket.TSSLSocket('app.handytextbook.com', 9092, validate=False)) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Images.Client(protocol) transport.open() print("client - getSellItemImages") print("server - " + str(client.getSellItemImages("1"))) transport.close()
def main(): parser = argparse.ArgumentParser() parser.add_argument("--node", "-n", help="Define node address") parser.add_argument("--port", "-p", help="Define node port") parser.add_argument( "--cert", "-c", help="Set path to node certificate. Can either be relative or absolute." ) parser.add_argument( "--calls", help="Set amount of transaction calls to be done against the node") parser.add_argument("--delay", "-d", help="Set delay between amount of transaction calls") parser.add_argument("--amount", "-a", help="Set amount to be transferred") parser.add_argument("--target", "-t", help="Set target for transfer") parser.add_argument("--status", "-s", help="Request status from transaction id") parser.add_argument( "--balance", "-b", help= "Get balance from address. Leave address empty to retrieve own balance.", nargs='?', const=get_own_address()) parser.add_argument( "--history", help= "Get balance history for specified address. Leave address empty to retrieve own history.", nargs='?', const=get_own_address()) parser.add_argument("--address", help="Get own address", action='store_true') try: args = parser.parse_args() except: parser.print_help() sys.exit(0) if args.node and args.port and args.cert: print("Set node to %s" % args.node) print("Set port to %s" % args.port) print("Set cert path to %s" % args.cert) transport = TSSLSocket.TSSLSocket(host=args.node, port=args.port, ca_certs=args.cert) elif args.node and args.cert: print("Set node to %s" % args.node) print("Set cert path to %s" % args.cert) transport = TSSLSocket.TSSLSocket(host=args.node, ca_certs=args.cert) elif args.address: address() sys.exit(0) else: parser.print_help() sys.exit(0) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Transaction.Client(protocol) if args.status: transport.open() status(args.status, client) transport.close() elif args.balance: transport.open() balance(args.balance, client) transport.close() elif args.history: transport.open() history(args.history, client) transport.close() elif args.amount and args.target: if bool(re.match(r"^11x[a-fA-F0-9]{40}$", args.target)): transport.open() #transfer(int(args.amount), int(args.target), client) crypto_transfer(int(args.amount), str(args.target), client) transport.close() else: print('Wrong address!') elif args.calls and args.delay: transport.open() benchmark(int(args.calls), int(args.delay), client) transport.close() else: parser.print_help() sys.exit(0)
def factory(host, port): return TSSLSocket.TSSLSocket( host, port, cert_reqs=(ssl.CERT_REQUIRED if cls.validate else ssl.CERT_NONE))
def __init__( self, uri=None, user=None, password=None, host=None, port=6274, dbname=None, protocol='binary', sessionid=None, bin_cert_validate=None, bin_ca_certs=None, ): self.sessionid = None if sessionid is not None: if any([user, password, uri, dbname]): raise TypeError("Cannot specify sessionid with user, password," " dbname, or uri") if uri is not None: if not all([ user is None, password is None, host is None, port == 6274, dbname is None, protocol == 'binary', bin_cert_validate is None, bin_ca_certs is None ]): raise TypeError("Cannot specify both URI and other arguments") user, password, host, port, dbname, protocol, \ bin_cert_validate, bin_ca_certs = _parse_uri(uri) if host is None: raise TypeError("`host` parameter is required.") if protocol != 'binary' and not all( [bin_cert_validate is None, bin_ca_certs is None]): raise TypeError("Cannot specify bin_cert_validate or bin_ca_certs," " without binary protocol") if protocol in ("http", "https"): if not host.startswith(protocol): # the THttpClient expects http[s]://localhost host = '{0}://{1}'.format(protocol, host) transport = THttpClient.THttpClient("{}:{}".format(host, port)) proto = TJSONProtocol.TJSONProtocol(transport) socket = None elif protocol == "binary": if any([bin_cert_validate is not None, bin_ca_certs]): socket = TSSLSocket.TSSLSocket(host, port, validate=(bin_cert_validate), ca_certs=bin_ca_certs) else: socket = TSocket.TSocket(host, port) transport = TTransport.TBufferedTransport(socket) proto = TBinaryProtocol.TBinaryProtocolAccelerated(transport) else: raise ValueError("`protocol` should be one of", " ['http', 'https', 'binary'],", " got {} instead".format(protocol)) self._user = user self._password = password self._host = host self._port = port self._dbname = dbname self._transport = transport self._protocol = protocol self._socket = socket self._closed = 0 self._tdf = None try: self._transport.open() except TTransportException as e: if e.NOT_OPEN: err = OperationalError("Could not connect to database") raise err from e else: raise self._client = Client(proto) try: # If a sessionid was passed, we should validate it if sessionid: self._session = sessionid self.get_tables() self.sessionid = sessionid else: self._session = self._client.connect(user, password, dbname) except TMapDException as e: raise _translate_exception(e) from e except TTransportException: raise ValueError(f"Connection failed with port {port} and " f"protocol '{protocol}'. Try port 6274 for " "protocol == binary or 6273, 6278 or 443 for " "http[s]") # if OmniSci version <4.6, raise RuntimeError, as data import can be # incorrect for columnar date loads # Caused by https://github.com/omnisci/pymapd/pull/188 semver = self._client.get_version() if Version(semver.split("-")[0]) < Version("4.6"): raise RuntimeError(f"Version {semver} of OmniSci detected. " "Please use pymapd <0.11. See release notes " "for more details.")
def ssl_socket_factory(host, port): TSSLSocket.TSSLSocket.SSL_VERSION = ssl.PROTOCOL_TLSv1_2 return TSSLSocket.TSSLSocket(host, port, ca_certs=ca_certs, validate=validate)
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed': framed = True argi += 1 if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl': ssl = True argi += 1 cmd = sys.argv[argi] args = sys.argv[argi + 1:] if http: transport = THttpClient.THttpClient(host, port, uri) else: socket = TSSLSocket.TSSLSocket( host, port, validate=False) if ssl else TSocket.TSocket(host, port) if framed: transport = TTransport.TFramedTransport(socket) else: transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = SpacyThrift.Client(protocol) transport.open() if cmd == 'tag': if len(args) != 1: print('tag requires 1 args') sys.exit(1) pp.pprint(client.tag(args[0], )) else: