summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-16 12:53:48 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-05-16 12:53:48 (GMT)
commite35553e24c6b90db9ab22298cef663192972bbab (patch)
treeaadeac2109551638eb7d3a17ffcc07ce3b0c5f35
parent9d2ac227210fa8c7ba14a581747d1a1836e7274c (diff)
downloadcpython-e35553e24c6b90db9ab22298cef663192972bbab.zip
cpython-e35553e24c6b90db9ab22298cef663192972bbab.tar.gz
cpython-e35553e24c6b90db9ab22298cef663192972bbab.tar.bz2
Fix io.StringIO for wide Python builds.
-rw-r--r--Lib/io.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 177526f..20821b6 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -598,6 +598,8 @@ class StringIO(_MemoryIOMixin):
# Reuses the same code as BytesIO, but encode strings on the way in
# and decode them on the way out.
+ charsize = len("!".encode("unicode-internal"))
+
def __init__(self, initial_string=None):
if initial_string is not None:
buffer = initial_string.encode("unicode-internal")
@@ -609,21 +611,24 @@ class StringIO(_MemoryIOMixin):
return self._buffer.encode("unicode-internal")
def read(self, n=-1):
- return super(StringIO, self).read(n*2).decode("unicode-internal")
+ return super(StringIO, self).read(n*self.charsize) \
+ .decode("unicode-internal")
def write(self, s):
- return super(StringIO, self).write(s.encode("unicode-internal"))//2
+ return super(StringIO, self).write(s.encode("unicode-internal")) \
+ //self.charsize
def seek(self, pos, whence=0):
- return super(StringIO, self).seek(2*pos, whence)//2
+ return super(StringIO, self).seek(self.charsize*pos, whence) \
+ //self.charsize
def tell(self):
- return super(StringIO, self).tell()//2
+ return super(StringIO, self).tell()//self.charsize
def truncate(self, pos=None):
if pos is not None:
- pos *= 2
- return super(StringIO, self).truncate(pos)//2
+ pos *= self.charsize
+ return super(StringIO, self).truncate(pos)//self.charsize
def readinto(self, b: bytes) -> int:
self._unsupported("readinto")