88import sys
99import errno
1010
11- from io import StringIO
11+ from io import BytesIO
1212
1313from smmap import (
1414 StaticWindowMapManager ,
@@ -78,14 +78,14 @@ def unpack_from(fmt, data, offset=0):
7878#{ compatibility stuff ...
7979
8080
81- class _RandomAccessStringIO (object ):
81+ class _RandomAccessBytesIO (object ):
8282
8383 """Wrapper to provide required functionality in case memory maps cannot or may
8484 not be used. This is only really required in python 2.4"""
8585 __slots__ = '_sio'
8686
8787 def __init__ (self , buf = '' ):
88- self ._sio = StringIO (buf )
88+ self ._sio = BytesIO (buf )
8989
9090 def __getattr__ (self , attr ):
9191 return getattr (self ._sio , attr )
@@ -130,7 +130,7 @@ def make_sha(source=''.encode("ascii")):
130130def allocate_memory (size ):
131131 """:return: a file-protocol accessible memory block of the given size"""
132132 if size == 0 :
133- return _RandomAccessStringIO ( '' )
133+ return _RandomAccessBytesIO ( b '' )
134134 # END handle empty chunks gracefully
135135
136136 try :
@@ -140,7 +140,7 @@ def allocate_memory(size):
140140 # this of course may fail if the amount of memory is not available in
141141 # one chunk - would only be the case in python 2.4, being more likely on
142142 # 32 bit systems.
143- return _RandomAccessStringIO ( "\0 " * size )
143+ return _RandomAccessBytesIO ( b "\0 " * size )
144144 # END handle memory allocation
145145
146146
@@ -169,7 +169,7 @@ def file_contents_ro(fd, stream=False, allow_mmap=True):
169169 # read manully
170170 contents = os .read (fd , os .fstat (fd ).st_size )
171171 if stream :
172- return _RandomAccessStringIO (contents )
172+ return _RandomAccessBytesIO (contents )
173173 return contents
174174
175175
0 commit comments