You store just the StringIO
object when calling self._storage.stream_write(filename, io)
:
def put_content(self, path, content, chunk=None):
path = self._init_path(path)
try:
self._swift_container[path] = content
except Exception:
raise IOError("Could not put content")
where content
is the io
object you passed in.
Later on, you pass that file object to StringIO
again:
stream = StringIO.StringIO(self.get_content(path))
This calls str()
on self.get_content(path)
, storing the string representation of a cStringIO.StringI()
instance:
>>> from cStringIO import StringIO
>>> str(StringIO('test data'))
'<cStringIO.StringI object at 0x1074ea470>'
Your reading code works fine, it is your writing mock that needs to actually take the data out of the StringIO
object.
A .read()
call will do here:
def put_content(self, path, content, chunk=None):
path = self._init_path(path)
try:
self._swift_container[path] = content.read()
except Exception:
raise IOError("Could not put content")