当前位置: 首页>>代码示例>>Python>>正文


Python TTransport.TMemoryBuffer方法代码示例

本文整理汇总了Python中thrift.transport.TTransport.TMemoryBuffer方法的典型用法代码示例。如果您正苦于以下问题:Python TTransport.TMemoryBuffer方法的具体用法?Python TTransport.TMemoryBuffer怎么用?Python TTransport.TMemoryBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thrift.transport.TTransport的用法示例。


在下文中一共展示了TTransport.TMemoryBuffer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_stream

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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) 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:19,代码来源:TTornado.py

示例2: SerializeThriftCall

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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() 
开发者ID:steveniemitz,项目名称:scales,代码行数:25,代码来源:serializer.py

示例3: _read_next

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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) 
开发者ID:pinterest,项目名称:thrift-tools,代码行数:22,代码来源:thrift_file.py

示例4: _start_receiving

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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) 
开发者ID:jaegertracing,项目名称:jaeger-client-python,代码行数:25,代码来源:ZipkinCollector.py

示例5: serialize_body

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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 
开发者ID:uber,项目名称:tchannel-python,代码行数:21,代码来源:thrift.py

示例6: __auth_headers

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:36,代码来源:emrthttpclient.py

示例7: stringReceived

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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) 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:14,代码来源:TTwisted.py

示例8: render_POST

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:14,代码来源:TTwisted.py

示例9: handle

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
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] 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:32,代码来源:TNonblockingServer.py

示例10: __init__

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [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) 
开发者ID:Aditmadzs,项目名称:Protect4,代码行数:42,代码来源:THttpServer.py

示例11: parseClientMessage

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
def parseClientMessage(self, msg, channel, queue, thriftClient,
                           iprot_factory=None):
        deliveryTag = msg.delivery_tag
        tr = TTransport.TMemoryBuffer(msg.content.body)
        if iprot_factory is None:
            iprot = self.factory.iprot_factory.getProtocol(tr)
        else:
            iprot = iprot_factory.getProtocol(tr)
        (fname, mtype, rseqid) = iprot.readMessageBegin()

        if rseqid in thriftClient._reqs:
            # log.msg('Got reply: fname = %r, rseqid = %s, mtype = %r, routing key = %r, client = %r, msg.content.body = %r' % (fname, rseqid, mtype, msg.routing_key, thriftClient, msg.content.body))
            pass
        else:
            log.msg('Missing rseqid! fname = %r, rseqid = %s, mtype = %r, routing key = %r, client = %r, msg.content.body = %r' % (fname, rseqid, mtype, msg.routing_key, thriftClient, msg.content.body))
            
        method = getattr(thriftClient, 'recv_' + fname)
        method(iprot, mtype, rseqid)

        channel.basic_ack(deliveryTag, True)
        
        d = queue.get()
        d.addCallback(self.parseClientMessage, channel, queue, thriftClient,
            iprot_factory=iprot_factory)
        d.addErrback(self.catchClosedClientQueue)
        d.addErrback(self.handleClientQueueError) 
开发者ID:txamqp,项目名称:txamqp,代码行数:28,代码来源:protocol.py

示例12: parseClientUnrouteableMessage

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
def parseClientUnrouteableMessage(self, msg, channel, queue, thriftClient,
                                      iprot_factory=None):
        tr = TTransport.TMemoryBuffer(msg.content.body)
        if iprot_factory is None:
            iprot = self.factory.iprot_factory.getProtocol(tr)
        else:
            iprot = iprot_factory.getProtocol(tr)
        (fname, mtype, rseqid) = iprot.readMessageBegin()

        # log.msg('Got unroutable. fname = %r, rseqid = %s, mtype = %r, routing key = %r, client = %r, msg.content.body = %r' % (fname, rseqid, mtype, msg.routing_key, thriftClient, msg.content.body))

        try:
            d = thriftClient._reqs.pop(rseqid)
        except KeyError:
            # KeyError will occur if the remote Thrift method is oneway,
            # since there is no outstanding local request deferred for
            # oneway calls.
            pass
        else:
            d.errback(TTransport.TTransportException(
                type=TTransport.TTransportException.NOT_OPEN,
                message='Unrouteable message, routing key = %r calling function %r'
                % (msg.routing_key, fname)))

        d = queue.get()
        d.addCallback(self.parseClientUnrouteableMessage, channel, queue,
            thriftClient, iprot_factory=iprot_factory)
        d.addErrback(self.catchClosedClientQueue)
        d.addErrback(self.handleClientQueueError) 
开发者ID:txamqp,项目名称:txamqp,代码行数:31,代码来源:protocol.py

示例13: parseServerMessage

# 需要导入模块: from thrift.transport import TTransport [as 别名]
# 或者: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
def parseServerMessage(self, msg, channel, exchange, queue, processor,
        iprot_factory=None, oprot_factory=None):
        deliveryTag = msg.delivery_tag
        try:
            replyTo = msg.content[self.replyToField]
        except KeyError:
            replyTo = None

        tmi = TTransport.TMemoryBuffer(msg.content.body)
        tr = TwistedAMQPTransport(channel, exchange, replyTo)

        if iprot_factory is None:
            iprot = self.factory.iprot_factory.getProtocol(tmi)
        else:
            iprot = iprot_factory.getProtocol(tmi)

        if oprot_factory is None:
            oprot = self.factory.oprot_factory.getProtocol(tr)
        else:
            oprot = oprot_factory.getProtocol(tr)

        d = processor.process(iprot, oprot)
        channel.basic_ack(deliveryTag, True)

        d = queue.get()
        d.addCallback(self.parseServerMessage, channel, exchange, queue,
            processor, iprot_factory, oprot_factory)
        d.addErrback(self.catchClosedServerQueue)
        d.addErrback(self.handleServerQueueError) 
开发者ID:txamqp,项目名称:txamqp,代码行数:31,代码来源:protocol.py


注:本文中的thrift.transport.TTransport.TMemoryBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。