8
8
import sys
9
9
import errno
10
10
11
- from io import StringIO
11
+ from io import BytesIO
12
12
13
13
from smmap import (
14
14
StaticWindowMapManager ,
@@ -78,14 +78,14 @@ def unpack_from(fmt, data, offset=0):
78
78
#{ compatibility stuff ...
79
79
80
80
81
- class _RandomAccessStringIO (object ):
81
+ class _RandomAccessBytesIO (object ):
82
82
83
83
"""Wrapper to provide required functionality in case memory maps cannot or may
84
84
not be used. This is only really required in python 2.4"""
85
85
__slots__ = '_sio'
86
86
87
87
def __init__ (self , buf = '' ):
88
- self ._sio = StringIO (buf )
88
+ self ._sio = BytesIO (buf )
89
89
90
90
def __getattr__ (self , attr ):
91
91
return getattr (self ._sio , attr )
@@ -130,7 +130,7 @@ def make_sha(source=''.encode("ascii")):
130
130
def allocate_memory (size ):
131
131
""":return: a file-protocol accessible memory block of the given size"""
132
132
if size == 0 :
133
- return _RandomAccessStringIO ( '' )
133
+ return _RandomAccessBytesIO ( b '' )
134
134
# END handle empty chunks gracefully
135
135
136
136
try :
@@ -140,7 +140,7 @@ def allocate_memory(size):
140
140
# this of course may fail if the amount of memory is not available in
141
141
# one chunk - would only be the case in python 2.4, being more likely on
142
142
# 32 bit systems.
143
- return _RandomAccessStringIO ( "\0 " * size )
143
+ return _RandomAccessBytesIO ( b "\0 " * size )
144
144
# END handle memory allocation
145
145
146
146
@@ -169,7 +169,7 @@ def file_contents_ro(fd, stream=False, allow_mmap=True):
169
169
# read manully
170
170
contents = os .read (fd , os .fstat (fd ).st_size )
171
171
if stream :
172
- return _RandomAccessStringIO (contents )
172
+ return _RandomAccessBytesIO (contents )
173
173
return contents
174
174
175
175
0 commit comments