Skip to content

Commit f6a5fcc

Browse files
committed
replace StringIO with cStringIO in python 2.x
1 parent 158219f commit f6a5fcc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

ezodf/bytestreammanager.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
class ByteStreamManager(FileManager):
1616
def __init__(self, buffer=None):
1717
if is_stream(buffer):
18-
self._zipfile_as_bytes = buffer
18+
self._zipfile_as_bytes = buffer.getvalue()
1919
else:
20-
self._zipfile_as_bytes = StringIO(buffer)
20+
self._zipfile_as_bytes = buffer
2121
super(ByteStreamManager, self).__init__()
2222

2323
def save(self, filename, backup=False):
@@ -31,5 +31,4 @@ def has_zip(self):
3131
return self._zipfile_as_bytes is not None
3232

3333
def _open_bytestream(self):
34-
self._zipfile_as_bytes.seek(0)
35-
return self._zipfile_as_bytes
34+
return StringIO(self._zipfile_as_bytes)

ezodf/compatibility.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ def is_stream(instance):
4040

4141
else: # PY2
4242
# distiguish StringIO
43-
from StringIO import StringIO
43+
from cStringIO import StringIO
4444
from cStringIO import InputType, OutputType
45+
from StringIO import SlowStringIO
4546

4647
tostr=unicode
4748
def is_string(value):
@@ -80,4 +81,4 @@ def is_zipfile(data):
8081
def is_stream(instance):
8182
return (isinstance(instance, InputType) or
8283
isinstance(instance, OutputType) or
83-
isinstance(instance, StringIO))
84+
isinstance(instance, SlowStringIO))

0 commit comments

Comments
 (0)