-- Adding TMemoryBuffer.py
Summary:
Submitted by Ben Maurer
Reviewed By: mcslee, aditya
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665184 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/transport/TTransport.py b/lib/py/src/transport/TTransport.py
index 305c10b..3c18221 100644
--- a/lib/py/src/transport/TTransport.py
+++ b/lib/py/src/transport/TTransport.py
@@ -112,6 +112,40 @@
self.__trans.flush()
self.__buf = StringIO()
+class TMemoryBuffer(TTransportBase):
+ """Wraps a string object as a TTransport"""
+
+ def __init__(self, value=None):
+ """value -- a value to read from for stringio
+
+ If value is set, this will be a transport for reading,
+ otherwise, it is for writing"""
+ if value is not None:
+ self._buffer = StringIO(value)
+ else:
+ self._buffer = StringIO()
+
+ def isOpen(self):
+ return not self._buffer.closed
+
+ def open(self):
+ pass
+
+ def close(self):
+ self._buffer.close()
+
+ def read(self, sz):
+ return self._buffer.read(sz)
+
+ def write(self, buf):
+ self._buffer.write(buf)
+
+ def flush(self):
+ pass
+
+ def getvalue(self):
+ return self._buffer.getvalue()
+
class TFramedTransportFactory:
"""Factory transport that builds framed transports"""