def client_context(service, host='localhost', port=9090, path='', scheme='http', proto_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory(), ssl_context_factory=None, http_header_factory=None, timeout=DEFAULT_HTTP_CLIENT_TIMEOUT_MS, url=''): if url: parsed_url = urllib.parse.urlparse(url) host = parsed_url.hostname or host port = parsed_url.port or port scheme = parsed_url.scheme or scheme path = parsed_url.path or path if path and path[0] != "/": # path should have `/` prefix, but we can make a compatible here. path = "/" + path uri = HTTP_URI.format(scheme=scheme, host=host, port=port, path=path) http_socket = THttpClient(uri, timeout, ssl_context_factory, http_header_factory) transport = trans_factory.get_transport(http_socket) try: iprot = proto_factory.get_protocol(transport) transport.open() yield TClient(service, iprot) finally: transport.close()
def _refresh_thrift_client(self): """Refresh the Thrift socket, transport, and client.""" socket = TSocket(host=self.host, port=self.port, socket_timeout=self.timeout) self.transport = self._transport_class(socket) protocol = self._protocol_class(self.transport, decode_response=False) self.client = TClient(Hbase, protocol)
def make_client(service, host="localhost", port=9090, unix_socket=None, proto_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory(), timeout=None, cafile=None, ssl_context=None, certfile=None, keyfile=None): if unix_socket: socket = TSocket(unix_socket=unix_socket) if certfile: warnings.warn("SSL only works with host:port, not unix_socket.") elif host and port: if cafile or ssl_context: socket = TSSLSocket(host, port, socket_timeout=timeout, cafile=cafile, certfile=certfile, keyfile=keyfile, ssl_context=ssl_context) else: socket = TSocket(host, port, socket_timeout=timeout) else: raise ValueError("Either host/port or unix_socket must be provided.") transport = trans_factory.get_transport(socket) protocol = proto_factory.get_protocol(transport) transport.open() return TClient(service, protocol)
def get_tclient(self, service, protocol): if self.tracking is True: from thriftpy2.contrib.tracking import TTrackedClient client = TTrackedClient(self.tracker_factory, service, protocol) else: from thriftpy2.thrift import TClient client = TClient(service, protocol) return client
def __loadSession(self): # Talk Service self.transport.setCustomHeaders({ "User-Agent": Config.UA, "X-Line-Carrier": Config.CARRIER, "X-Line-Application": Config.LA, "X-Line-Access": self.authToken }) self.transport.path = Config.LINE_API_QUERY_PATH_FIR self.talk = TClient(self.thrift.Service, self.protocol) self.profile = self.talk.getProfile() print("[Login success] " + self.profile.displayName) self.transport.path = Config.LONG_POLLING self.poll = TClient(self.thrift.Service, self.protocol) self.revision = self.poll.getLastOpRevision()
def client_context(service, host="localhost", port=9090, unix_socket=None, proto_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory(), timeout=None, socket_timeout=3000, connect_timeout=3000, cafile=None, ssl_context=None, certfile=None, keyfile=None, url=""): if url: parsed_url = urllib.parse.urlparse(url) host = parsed_url.hostname or host port = parsed_url.port or port if timeout: warnings.warn("`timeout` deprecated, use `socket_timeout` and " "`connect_timeout` instead.") socket_timeout = connect_timeout = timeout if unix_socket: socket = TSocket(unix_socket=unix_socket, connect_timeout=connect_timeout, socket_timeout=socket_timeout) if certfile: warnings.warn("SSL only works with host:port, not unix_socket.") elif host and port: if cafile or ssl_context: socket = TSSLSocket(host, port, connect_timeout=connect_timeout, socket_timeout=socket_timeout, cafile=cafile, certfile=certfile, keyfile=keyfile, ssl_context=ssl_context) else: socket = TSocket(host, port, connect_timeout=connect_timeout, socket_timeout=socket_timeout) else: raise ValueError( "Either host/port or unix_socket or url must be provided.") try: transport = trans_factory.get_transport(socket) protocol = proto_factory.get_protocol(transport) transport.open() yield TClient(service, protocol) finally: transport.close()
def _refresh_thrift_client(self): """Refresh the Thrift socket, transport, and client.""" socket = TSocket(self.host, self.port) if self.timeout is not None: socket.set_timeout(self.timeout) self.transport = self._transport_class(socket) if self.use_kerberos: self.transport = TSaslClientTransport(self.transport, self.host, self.sasl_service_name) protocol = self._protocol_class(self.transport, decode_response=False) self.client = TClient(Hbase, protocol)
def make_client( service, host, port, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory(), socket_factory=TNonBlockingSocket, socket_timeout=1000, ): socket = socket_factory(host, port, socket_timeout=socket_timeout) transport = trans_factory.get_transport(socket) protocol = proto_factory.get_protocol(transport) transport.open() return TClient(service, protocol)
def make_client(service, host, port, path='', scheme='http', proto_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory(), ssl_context_factory=None, timeout=DEFAULT_HTTP_CLIENT_TIMEOUT_MS): uri = HTTP_URI.format(scheme=scheme, host=host, port=port, path=path) http_socket = THttpClient(uri, timeout, ssl_context_factory) transport = trans_factory.get_transport(http_socket) iprot = proto_factory.get_protocol(transport) transport.open() return TClient(service, iprot)
def __init__(self): self.thrift = thriftpy2.load("line.thrift") self.transport = THttpClient(Config.HOST) self.transport.setCustomHeaders({ "User-Agent": Config.UA, "X-Line-Application": Config.LA, "X-Line-Carrier": Config.CARRIER, "X-LHM": "POST", "X-lal": "ja-JP_JP" }) self.protocol = TCompactProtocol(self.transport) self.transport.open() self.client = TClient(self.thrift.Service, self.protocol) self.certificate = None
def __init__(self): self.line_thrift = thriftpy2.load(os.path.dirname(__file__) + "/line.thrift", module_name="line_thrift") self.transport = THttpClient("https://gd2.line.naver.jp:443") self.transport.setCustomHeaders({ "User-Agent": "Line/7.14.0 iPad5,1 10.2.0", "X-Line-Application": "IOSIPAD\t7.14.0\tiPhone OS\t10.12.0", "X-LHM": "POST", "X-lal": "ja-JP_JP" }) self.protocol = TCompactProtocol(self.transport) self.transport.open() self.client = TClient(self.line_thrift.LineService, self.protocol) self._session = requests.session()
def make_client(service, host='localhost', port=9090, path='', scheme='http', proto_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory(), ssl_context_factory=None, timeout=DEFAULT_HTTP_CLIENT_TIMEOUT_MS, url=''): if url: parsed_url = urllib.parse.urlparse(url) host = parsed_url.hostname or host port = parsed_url.port or port scheme = parsed_url.scheme or scheme path = parsed_url.path or path uri = HTTP_URI.format(scheme=scheme, host=host, port=port, path=path) http_socket = THttpClient(uri, timeout, ssl_context_factory) transport = trans_factory.get_transport(http_socket) iprot = proto_factory.get_protocol(transport) transport.open() return TClient(service, iprot)
def make_client(service, host="localhost", port=9090, unix_socket=None, proto_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory(), timeout=3000, cafile=None, ssl_context=None, certfile=None, keyfile=None, url="", socket_family=socket.AF_INET): if url: parsed_url = urllib.parse.urlparse(url) host = parsed_url.hostname or host port = parsed_url.port or port if unix_socket: socket = TSocket(unix_socket=unix_socket, socket_timeout=timeout) if certfile: warnings.warn("SSL only works with host:port, not unix_socket.") elif host and port: if cafile or ssl_context: socket = TSSLSocket(host, port, socket_timeout=timeout, socket_family=socket_family, cafile=cafile, certfile=certfile, keyfile=keyfile, ssl_context=ssl_context) else: socket = TSocket(host, port, socket_family=socket_family, socket_timeout=timeout) else: raise ValueError( "Either host/port or unix_socket or url must be provided.") transport = trans_factory.get_transport(socket) protocol = proto_factory.get_protocol(transport) transport.open() return TClient(service, protocol)
def _refresh_thrift_client(self): """Refresh the Thrift sockets, transports, and clients.""" self.subconnections = [] for server in self.servers: socket = TSocket(host=server["host"], port=server["port"], socket_timeout=self.timeout) transport = self._transport_class(socket) protocol = self._protocol_class(transport, decode_response=False) client = TClient(Hbase, protocol) subconnection = Subconnection(server=server, transport=transport, client=client, status=0) self.subconnections.append(subconnection) self.client = HAClient(self.subconnections)
def _refresh_thrift_client(self): """Refresh the Thrift socket, transport, and client.""" socket = TSocket(self.host, self.port) if self.timeout is not None: socket.set_timeout(self.timeout) self.transport = self._transport_class(socket) if self.use_kerberos: self.transport = TSaslClientTransport( self.transport, self.host, self.sasl_service_name, generate_tickets=self.generate_tickets, using_keytab=self.using_keytab, principal=self.principal, keytab_file=self.keytab_file, ccache_file=self.ccache_file, password=self.password) protocol = self._protocol_class(self.transport, decode_response=False) self.client = TClient(Hbase, protocol)
import thriftpy2 from thriftpy2.http import THttpClient from thriftpy2.protocol import TCompactProtocol from thriftpy2.thrift import TClient line_thrift = thriftpy2.load("line.thrift", module_name="line_thrift") transport = THttpClient("https://gd2.line.naver.jp:443/S4") transport.setCustomHeaders({ "User-Agent": "Line/7.14.0 iPad5,1 10.2.0", "X-Line-Application": "IOSIPAD\t7.14.0\tiPhone OS\t10.12.0", "X-LHM": "POST", "X-lal": "ja-JP_JP" }) protocol = TCompactProtocol(transport) transport.open() client = TClient(line_thrift.LineService, protocol) transport.path = "/api/v4/TalkService.do" qr = client.getAuthQrcode(keepLoggedIn=1, systemName="LLL")