Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e35553e

Browse files
committed
Fix io.StringIO for wide Python builds.
1 parent 9d2ac22 commit e35553e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

Lib/io.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ class StringIO(_MemoryIOMixin):
598598
# Reuses the same code as BytesIO, but encode strings on the way in
599599
# and decode them on the way out.
600600

601+
charsize = len("!".encode("unicode-internal"))
602+
601603
def __init__(self, initial_string=None):
602604
if initial_string is not None:
603605
buffer = initial_string.encode("unicode-internal")
@@ -609,21 +611,24 @@ def getvalue(self):
609611
return self._buffer.encode("unicode-internal")
610612

611613
def read(self, n=-1):
612-
return super(StringIO, self).read(n*2).decode("unicode-internal")
614+
return super(StringIO, self).read(n*self.charsize) \
615+
.decode("unicode-internal")
613616

614617
def write(self, s):
615-
return super(StringIO, self).write(s.encode("unicode-internal"))//2
618+
return super(StringIO, self).write(s.encode("unicode-internal")) \
619+
//self.charsize
616620

617621
def seek(self, pos, whence=0):
618-
return super(StringIO, self).seek(2*pos, whence)//2
622+
return super(StringIO, self).seek(self.charsize*pos, whence) \
623+
//self.charsize
619624

620625
def tell(self):
621-
return super(StringIO, self).tell()//2
626+
return super(StringIO, self).tell()//self.charsize
622627

623628
def truncate(self, pos=None):
624629
if pos is not None:
625-
pos *= 2
626-
return super(StringIO, self).truncate(pos)//2
630+
pos *= self.charsize
631+
return super(StringIO, self).truncate(pos)//self.charsize
627632

628633
def readinto(self, b: bytes) -> int:
629634
self._unsupported("readinto")

0 commit comments

Comments
 (0)