本文整理匯總了Python中thrift.transport.THeaderTransport.THeaderTransport.getTransport方法的典型用法代碼示例。如果您正苦於以下問題:Python THeaderTransport.getTransport方法的具體用法?Python THeaderTransport.getTransport怎麽用?Python THeaderTransport.getTransport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類thrift.transport.THeaderTransport.THeaderTransport
的用法示例。
在下文中一共展示了THeaderTransport.getTransport方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestEof
# 需要導入模塊: from thrift.transport.THeaderTransport import THeaderTransport [as 別名]
# 或者: from thrift.transport.THeaderTransport.THeaderTransport import getTransport [as 別名]
class TestEof(unittest.TestCase):
def setUp(self):
self.trans = TTransport.TMemoryBuffer()
self.trans = THeaderTransport(self.trans)
self.prot = TBinaryProtocol.TBinaryProtocol(self.trans)
self.x = Xtruct()
self.x.string_thing = "Zero"
self.x.byte_thing = 0
def testOversizeFrameRecv(self):
"""Test that an oversize frame on recv gets a TTransportException"""
self.trans.set_max_frame_size(200)
self.x.write(self.prot)
self.trans.flush()
inTrans = TTransport.TMemoryBuffer(self.trans.getTransport().getvalue())
inTrans = THeaderTransport(inTrans)
inProt = TBinaryProtocol.TBinaryProtocol(inTrans)
inTrans.set_max_frame_size(2)
try:
self.x.read(inProt)
except TTransport.TTransportException:
return
self.fail("Should have gotten TTransportException")
def testOversizeFrameSend(self):
"""Test that an oversize frame on send gets a TTransportException"""
self.trans.set_max_frame_size(2)
self.x.write(self.prot)
try:
self.trans.flush()
except TTransport.TTransportException:
return
self.fail("Should have gotten TTransportException")
示例2: serialize_texception
# 需要導入模塊: from thrift.transport.THeaderTransport import THeaderTransport [as 別名]
# 或者: from thrift.transport.THeaderTransport.THeaderTransport import getTransport [as 別名]
def serialize_texception(cls, fname, seqid, exception):
"""This saves us a bit of processing time for timeout handling by
reusing the Thrift structs involved in exception serialization.
NOTE: this is not thread-safe nor is it meant to be.
"""
# the serializer is a singleton
if cls._exception_serializer is None:
buffer = TWriteOnlyBuffer()
transport = THeaderTransport(buffer)
cls._exception_serializer = THeaderProtocol(transport)
else:
transport = cls._exception_serializer.trans
buffer = transport.getTransport()
buffer.reset()
serializer = cls._exception_serializer
serializer.writeMessageBegin(fname, TMessageType.EXCEPTION, seqid)
exception.write(serializer)
serializer.writeMessageEnd()
serializer.trans.flush()
return buffer.getvalue()