本文整理汇总了Python中thrift.transport.TTransport.TMemoryBuffer.close方法的典型用法代码示例。如果您正苦于以下问题:Python TMemoryBuffer.close方法的具体用法?Python TMemoryBuffer.close怎么用?Python TMemoryBuffer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thrift.transport.TTransport.TMemoryBuffer
的用法示例。
在下文中一共展示了TMemoryBuffer.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: round_robin
# 需要导入模块: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
# 或者: from thrift.transport.TTransport.TMemoryBuffer import close [as 别名]
def round_robin(self, compress=None):
original = b'A' * MAX_FRAME_SIZE
mb = TMemoryBuffer()
trans = THeaderTransport(mb, client_type=CLIENT_TYPE.HEADER)
trans.set_max_frame_size(MAX_FRAME_SIZE + MIN_HEADER_SIZE)
if compress:
trans.add_transform(compress)
trans.write(original)
trans.flush()
frame = mb.getvalue()
# Cleanup the memory buffer
mb.close()
del mb
if compress is None:
# Partial Decode the frame and see if its correct size wise
sz = struct.unpack('!I', frame[:4])[0]
self.assertEqual(sz, BIG_FRAME_MAGIC)
sz = struct.unpack('!Q', frame[4:12])[0]
self.assertEqual(len(frame), sz + 12)
# Read it back
mb = TMemoryBuffer(frame)
trans = THeaderTransport(mb, client_type=CLIENT_TYPE.HEADER)
trans.set_max_frame_size(len(frame))
trans.readFrame(0)
result = trans.read(MAX_FRAME_SIZE)
mb.close()
del mb
self.assertEqual(result, original, 'round-robin different from original')
示例2: testClose
# 需要导入模块: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
# 或者: from thrift.transport.TTransport.TMemoryBuffer import close [as 别名]
def testClose(self):
buf = TMemoryBuffer(b"hello")
buf.close()
self.assertRaises(RuntimeError, buf.read, 5)
self.assertRaises(RuntimeError, buf.write, b"world")