Python thrift.transport.TTransport.TMemoryBuffer() Examples
The following are 30
code examples of thrift.transport.TTransport.TMemoryBuffer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
thrift.transport.TTransport
, or try the search function
.
Example #1
Source File: TTornado.py From galaxy-sdk-python with Apache License 2.0 | 6 votes |
def handle_stream(self, stream, address): host, port = address trans = TTornadoStreamTransport(host=host, port=port, stream=stream, io_loop=self.io_loop) oprot = self._oprot_factory.getProtocol(trans) try: while not trans.stream.closed(): frame = yield trans.readFrame() tr = TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) yield self._processor.process(iprot, oprot) except Exception: logger.exception('thrift exception in handle_stream') trans.close() logger.info('client disconnected %s:%d', host, port)
Example #2
Source File: thrift_file.py From thrift-tools with Apache License 2.0 | 6 votes |
def _read_next(self, start, end): for idx in range(start, end): try: trans = TTransport.TMemoryBuffer(self._data_slice(idx)) proto = self._protocol(trans) tstruct = ThriftStruct.read( proto, max_fields=ThriftStructFile.MAX_FIELDS, max_list_size=ThriftStructFile.MAX_LIST_SIZE, max_map_size=ThriftStructFile.MAX_MAP_SIZE, max_set_size=ThriftStructFile.MAX_SET_SIZE, read_values=self._read_values) skipped = idx - start return (tstruct, None) if skipped == 0 else (tstruct, (start, skipped)) except Exception as ex: if self._debug: print('Bad message: %s (idx=%d)' % (ex, idx)) # nothing found return (None, None)
Example #3
Source File: serializer.py From scales with MIT License | 6 votes |
def SerializeThriftCall(self, msg, buf): """Serialize a MethodCallMessage to a stream Args: msg - The MethodCallMessage to serialize. buf - The buffer to serialize into. """ thrift_buffer = TMemoryBuffer() thrift_buffer._buffer = buf protocol = self._protocol_factory.getProtocol(thrift_buffer) method, args, kwargs = msg.method, msg.args, msg.kwargs is_one_way = self._FindClass('%s_result' % method) is None args_cls = self._FindClass('%s_args' % method) if not args_cls: raise AttributeError('Unable to find args class for method %s' % method) protocol.writeMessageBegin( msg.method, TMessageType.ONEWAY if is_one_way else TMessageType.CALL, self._seq_id) thrift_args = args_cls(*args, **kwargs) thrift_args.write(protocol) protocol.writeMessageEnd()
Example #4
Source File: ZipkinCollector.py From jaeger-client-python with Apache License 2.0 | 6 votes |
def _start_receiving(self): while True: try: frame = yield self._transport.readFrame() except TTransport.TTransportException as e: for future in self._reqs.itervalues(): future.set_exception(e) self._reqs = {} return tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() future = self._reqs.pop(rseqid, None) if not future: # future has already been discarded continue method = getattr(self, 'recv_' + fname) try: result = method(iprot, mtype, rseqid) except Exception as e: future.set_exception(e) else: future.set_result(result)
Example #5
Source File: Agent.py From jaeger-client-python with Apache License 2.0 | 6 votes |
def _start_receiving(self): while True: try: frame = yield self._transport.readFrame() except TTransport.TTransportException as e: for future in self._reqs.itervalues(): future.set_exception(e) self._reqs = {} return tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() future = self._reqs.pop(rseqid, None) if not future: # future has already been discarded continue method = getattr(self, 'recv_' + fname) try: result = method(iprot, mtype, rseqid) except Exception as e: future.set_exception(e) else: future.set_result(result)
Example #6
Source File: SamplingManager.py From jaeger-client-python with Apache License 2.0 | 6 votes |
def _start_receiving(self): while True: try: frame = yield self._transport.readFrame() except TTransport.TTransportException as e: for future in self._reqs.itervalues(): future.set_exception(e) self._reqs = {} return tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() future = self._reqs.pop(rseqid, None) if not future: # future has already been discarded continue method = getattr(self, 'recv_' + fname) try: result = method(iprot, mtype, rseqid) except Exception as e: future.set_exception(e) else: future.set_result(result)
Example #7
Source File: Collector.py From jaeger-client-python with Apache License 2.0 | 6 votes |
def _start_receiving(self): while True: try: frame = yield self._transport.readFrame() except TTransport.TTransportException as e: for future in self._reqs.itervalues(): future.set_exception(e) self._reqs = {} return tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() future = self._reqs.pop(rseqid, None) if not future: # future has already been discarded continue method = getattr(self, 'recv_' + fname) try: result = method(iprot, mtype, rseqid) except Exception as e: future.set_exception(e) else: future.set_result(result)
Example #8
Source File: TracedService.py From jaeger-client-python with Apache License 2.0 | 6 votes |
def _start_receiving(self): while True: try: frame = yield self._transport.readFrame() except TTransport.TTransportException as e: for future in self._reqs.itervalues(): future.set_exception(e) self._reqs = {} return tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() future = self._reqs.pop(rseqid, None) if not future: # future has already been discarded continue method = getattr(self, 'recv_' + fname) try: result = method(iprot, mtype, rseqid) except Exception as e: future.set_exception(e) else: future.set_result(result)
Example #9
Source File: thrift.py From tchannel-python with MIT License | 6 votes |
def serialize_body(self, call_args): # TODO - use fastbinary directly # # fastbinary.encode_binary( # call_args, (call_args.__class__, call_args.thrift_spec) # ) # fastbinary.decode_binary( # result, TMemoryBuffer(body),(result_type, result_type.thrift_spec) # ) # from thrift.protocol import TBinaryProtocol from thrift.transport import TTransport trans = TTransport.TMemoryBuffer() proto = TBinaryProtocol.TBinaryProtocolAccelerated(trans) call_args.write(proto) result = trans.getvalue() return result
Example #10
Source File: THttpServer.py From SOLO with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: __init__.py From opentelemetry-python with Apache License 2.0 | 5 votes |
def __init__( self, host_name, port, max_packet_size=UDP_PACKET_MAX_LENGTH, client=agent.Client, ): self.address = (host_name, port) self.max_packet_size = max_packet_size self.buffer = TTransport.TMemoryBuffer() self.client = client( iprot=TCompactProtocol.TCompactProtocol(trans=self.buffer) )
Example #12
Source File: TNonblockingServer.py From thrift with GNU Lesser General Public License v3.0 | 5 votes |
def handle(self): assert self.prepared, "You have to call prepare before handle" rset, wset, xset, selected = self._select() for readable in rset: if readable == self._read.fileno(): self._read.recv(1024) elif readable == self.socket.handle.fileno(): try: client = self.socket.accept() if client: self.clients[client.handle.fileno()] = Connection(client.handle, self.wake_up) except socket.error: logger.debug('eror disini ', exc_info=True) else: connection = self.clients[readable] if selected: connection.read() if connection.received: connection.status = WAIT_PROCESS msg = connection.received.popleft() itransport = TTransport.TMemoryBuffer(msg.buffer, msg.offset) otransport = TTransport.TMemoryBuffer() iprot = self.in_protocol.getProtocol(itransport) oprot = self.out_protocol.getProtocol(otransport) self.tasks.put([self.processor, iprot, oprot, otransport, connection.ready]) for writeable in wset: self.clients[writeable].write() for oob in xset: self.clients[oob].close() del self.clients[oob]
Example #13
Source File: auth.py From AsyncLine with MIT License | 5 votes |
def loginWithQrcode(self, path=None): self.url(config.MAIN_PATH) qr = await self.call('getAuthQrcode', True, "AsyncLine", "") p_key = generate_asymmetric_keypair() secret_query = create_secret_query(p_key.public_key) print(f"line://au/q/{qr.verifier}?secret={secret_query}&e2eeVersion=1") r = self.waitForPhoneConfirm(qr.verifier) vr = r.json() key_chain = vr['result']['metadata']['encryptedKeyChain'] public_key = vr['result']['metadata']['publicKey'] data_key = decrypt_keychain(p_key, key_chain, public_key) keychain = E2EEKeyChain() tbuffer = TMemoryBuffer(data_key) protocol = TCompactProtocol(tbuffer) keychain.read(protocol) self.url(config.AUTH_PATH) rq = LoginRequest( type=LoginType.QRCODE, identityProvider=IdentityProvider.LINE, keepLoggedIn=True, accessLocation=config.LOGIN_LOCATION, systemName="AsyncLine", verifier=vr["result"]["verifier"], secret=p_key.public_key, e2eeVersion=2 ) lr = await self.call('loginZ', rq) self.updateHeaders({ 'X-Line-Access': lr.authToken }) self.authToken = lr.authToken self.cert = lr.certificate if path: with open(path, "w") as fp: fp.write(lr.authToken) await self.afterLogin()
Example #14
Source File: http_client.py From AsyncLine with MIT License | 5 votes |
def request(self, context: FContext, payload) -> TTransportBase: payload = payload[4:] self._payload = payload self._preflight_request_check(payload) status, text = await self._make_request(context, self._payload) if status == 400: raise TTransportException( type=400, message='Bad request: '+str(text) + ' :: '+ str(payload)) elif status == 403: raise TTransportException( type=403, message='Forbidden: '+str(text)) elif status == 404: raise TTransportException( type=404, message='Not Found: '+str(text)) elif status == 410: pass elif status == 500: raise TTransportException( type=500, message='Backend Error: '+str(text)) elif status >= 300: raise TTransportException( type=TTransportExceptionType.UNKNOWN, message='request errored with {0} and message {1}'.format( status, str(text) )) return TMemoryBuffer(text)
Example #15
Source File: TTwisted.py From SOLO with GNU General Public License v3.0 | 5 votes |
def stringReceived(self, frame): tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() try: method = self.recv_map[fname] except KeyError: method = getattr(self.client, 'recv_' + fname) self.recv_map[fname] = method method(iprot, mtype, rseqid)
Example #16
Source File: emrthttpclient.py From galaxy-sdk-python with Apache License 2.0 | 5 votes |
def __auth_headers(self, headers, body, support_account_key): auth_headers = dict() if self.credential and self.credential.type and self.credential.secretKeyId: if self.credential.type in SIGNATURE_SUPPORT: auth_headers[HOST] = self.host # timestamp auth_headers[TIMESTAMP] = str(int(time.time() + self.__clock_offset)) auth_headers[MI_DATE] = formatdate(usegmt=True) # content md5 auth_headers[CONTENT_MD5] = hashlib.md5(body).hexdigest() headers_to_sign = defaultdict(lambda :[]) for k, v in headers.iteritems(): headers_to_sign[str(k).lower()].append(v) for k, v in auth_headers.iteritems(): headers_to_sign[str(k).lower()].append(v) signature = base64.b64encode(self.sign(self.__form_sign_content("POST", self.uri, headers_to_sign))).strip() auth_string = "Galaxy-V2 %s:%s" % (self.credential.secretKeyId, signature) auth_headers[AUTHORIZATION] = auth_string else: auth_header = HttpAuthorizationHeader() auth_header.secretKeyId = self.credential.secretKeyId auth_header.userType = self.credential.type auth_header.secretKey = self.credential.secretKey auth_header.supportAccountKey = support_account_key mb = TMemoryBuffer() protocol = TJSONProtocol(mb) auth_header.write(protocol) auth_headers[AUTHORIZATION] = str(mb.getvalue()) return auth_headers
Example #17
Source File: TTwisted.py From SOLO with GNU General Public License v3.0 | 5 votes |
def stringReceived(self, frame): tmi = TTransport.TMemoryBuffer(frame) tmo = TTransport.TMemoryBuffer() iprot = self.factory.iprot_factory.getProtocol(tmi) oprot = self.factory.oprot_factory.getProtocol(tmo) d = self.factory.processor.process(iprot, oprot) d.addCallbacks(self.processOk, self.processError, callbackArgs=(tmo,))
Example #18
Source File: TTwisted.py From SOLO with GNU General Public License v3.0 | 5 votes |
def render_POST(self, request): request.content.seek(0, 0) data = request.content.read() tmi = TTransport.TMemoryBuffer(data) tmo = TTransport.TMemoryBuffer() iprot = self.inputProtocolFactory.getProtocol(tmi) oprot = self.outputProtocolFactory.getProtocol(tmo) d = self.processor.process(iprot, oprot) d.addCallback(self._cbProcess, request, tmo) return server.NOT_DONE_YET # CEK KONEKSI INI SBENRNYA DISINU
Example #19
Source File: TNonblockingServer.py From SOLO with GNU General Public License v3.0 | 5 votes |
def handle(self): assert self.prepared, "You have to call prepare before handle" rset, wset, xset, selected = self._select() for readable in rset: if readable == self._read.fileno(): self._read.recv(1024) elif readable == self.socket.handle.fileno(): try: client = self.socket.accept() if client: self.clients[client.handle.fileno()] = Connection(client.handle, self.wake_up) except socket.error: logger.debug('eror disini ', exc_info=True) else: connection = self.clients[readable] if selected: connection.read() if connection.received: connection.status = WAIT_PROCESS msg = connection.received.popleft() itransport = TTransport.TMemoryBuffer(msg.buffer, msg.offset) otransport = TTransport.TMemoryBuffer() iprot = self.in_protocol.getProtocol(itransport) oprot = self.out_protocol.getProtocol(otransport) self.tasks.put([self.processor, iprot, oprot, otransport, connection.ready]) for writeable in wset: self.clients[writeable].write() for oob in xset: self.clients[oob].close() del self.clients[oob]
Example #20
Source File: __init__.py From opencensus-python with Apache License 2.0 | 5 votes |
def __init__( self, host_name=DEFAULT_HOST_NAME, port=DEFAULT_AGENT_PORT, max_packet_size=UDP_PACKET_MAX_LENGTH, client=agent.Client, transport=sync.SyncTransport): self.transport = transport(self) self.address = (host_name, port) self.max_packet_size = max_packet_size self.buffer = TTransport.TMemoryBuffer() self.client = client( iprot=TCompactProtocol.TCompactProtocol(trans=self.buffer))
Example #21
Source File: THttpServer.py From thrift with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #22
Source File: TTwisted.py From thrift with GNU Lesser General Public License v3.0 | 5 votes |
def render_POST(self, request): request.content.seek(0, 0) data = request.content.read() tmi = TTransport.TMemoryBuffer(data) tmo = TTransport.TMemoryBuffer() iprot = self.inputProtocolFactory.getProtocol(tmi) oprot = self.outputProtocolFactory.getProtocol(tmo) d = self.processor.process(iprot, oprot) d.addCallback(self._cbProcess, request, tmo) return server.NOT_DONE_YET # CEK KONEKSI INI SBENRNYA DISINU
Example #23
Source File: TTwisted.py From thrift with GNU Lesser General Public License v3.0 | 5 votes |
def stringReceived(self, frame): tmi = TTransport.TMemoryBuffer(frame) tmo = TTransport.TMemoryBuffer() iprot = self.factory.iprot_factory.getProtocol(tmi) oprot = self.factory.oprot_factory.getProtocol(tmo) d = self.factory.processor.process(iprot, oprot) d.addCallbacks(self.processOk, self.processError, callbackArgs=(tmo,))
Example #24
Source File: TTwisted.py From thrift with GNU Lesser General Public License v3.0 | 5 votes |
def stringReceived(self, frame): tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() try: method = self.recv_map[fname] except KeyError: method = getattr(self.client, 'recv_' + fname) self.recv_map[fname] = method method(iprot, mtype, rseqid)
Example #25
Source File: thrift.py From tchannel-python with MIT License | 5 votes |
def deserialize_body(self, body): from thrift.protocol import TBinaryProtocol from thrift.transport import TTransport trans = TTransport.TMemoryBuffer(body) proto = TBinaryProtocol.TBinaryProtocolAccelerated(trans) result = self.deserialize_type() result.read(proto) return result
Example #26
Source File: TTwisted.py From Aditmadzs2 with GNU General Public License v3.0 | 5 votes |
def render_POST(self, request): request.content.seek(0, 0) data = request.content.read() tmi = TTransport.TMemoryBuffer(data) tmo = TTransport.TMemoryBuffer() iprot = self.inputProtocolFactory.getProtocol(tmi) oprot = self.outputProtocolFactory.getProtocol(tmo) d = self.processor.process(iprot, oprot) d.addCallback(self._cbProcess, request, tmo) return server.NOT_DONE_YET
Example #27
Source File: TTwisted.py From galaxy-sdk-python with Apache License 2.0 | 5 votes |
def stringReceived(self, frame): tr = TTransport.TMemoryBuffer(frame) iprot = self._iprot_factory.getProtocol(tr) (fname, mtype, rseqid) = iprot.readMessageBegin() try: method = self.recv_map[fname] except KeyError: method = getattr(self.client, 'recv_' + fname) self.recv_map[fname] = method method(iprot, mtype, rseqid)
Example #28
Source File: TTwisted.py From galaxy-sdk-python with Apache License 2.0 | 5 votes |
def stringReceived(self, frame): tmi = TTransport.TMemoryBuffer(frame) tmo = TTransport.TMemoryBuffer() iprot = self.factory.iprot_factory.getProtocol(tmi) oprot = self.factory.oprot_factory.getProtocol(tmo) d = self.factory.processor.process(iprot, oprot) d.addCallbacks(self.processOk, self.processError, callbackArgs=(tmo,))
Example #29
Source File: TTwisted.py From galaxy-sdk-python with Apache License 2.0 | 5 votes |
def render_POST(self, request): request.content.seek(0, 0) data = request.content.read() tmi = TTransport.TMemoryBuffer(data) tmo = TTransport.TMemoryBuffer() iprot = self.inputProtocolFactory.getProtocol(tmi) oprot = self.outputProtocolFactory.getProtocol(tmo) d = self.processor.process(iprot, oprot) d.addCallback(self._cbProcess, request, tmo) return server.NOT_DONE_YET
Example #30
Source File: TNonblockingServer.py From galaxy-sdk-python with Apache License 2.0 | 5 votes |
def handle(self): """Handle requests. WARNING! You must call prepare() BEFORE calling handle() """ assert self.prepared, "You have to call prepare before handle" rset, wset, xset = self._select() for readable in rset: if readable == self._read.fileno(): # don't care i just need to clean readable flag self._read.recv(1024) elif readable == self.socket.handle.fileno(): client = self.socket.accept().handle self.clients[client.fileno()] = Connection(client, self.wake_up) else: connection = self.clients[readable] connection.read() if connection.status == WAIT_PROCESS: itransport = TTransport.TMemoryBuffer(connection.message) otransport = TTransport.TMemoryBuffer() iprot = self.in_protocol.getProtocol(itransport) oprot = self.out_protocol.getProtocol(otransport) self.tasks.put([self.processor, iprot, oprot, otransport, connection.ready]) for writeable in wset: self.clients[writeable].write() for oob in xset: self.clients[oob].close() del self.clients[oob]