mirror of https://github.com/python/cpython
Make StringIO work in --disable-unicode builds...
This commit is contained in:
parent
775c11f07a
commit
e1c67d1dc0
|
@ -39,7 +39,7 @@ __all__ = ["StringIO"]
|
||||||
class StringIO:
|
class StringIO:
|
||||||
def __init__(self, buf = ''):
|
def __init__(self, buf = ''):
|
||||||
# Force self.buf to be a string or unicode
|
# Force self.buf to be a string or unicode
|
||||||
if not isinstance(buf, types.UnicodeType):
|
if not isinstance(buf, types.StringTypes):
|
||||||
buf = str(buf)
|
buf = str(buf)
|
||||||
self.buf = buf
|
self.buf = buf
|
||||||
self.len = len(buf)
|
self.len = len(buf)
|
||||||
|
@ -138,7 +138,7 @@ class StringIO:
|
||||||
raise ValueError, "I/O operation on closed file"
|
raise ValueError, "I/O operation on closed file"
|
||||||
if not s: return
|
if not s: return
|
||||||
# Force s to be a string or unicode
|
# Force s to be a string or unicode
|
||||||
if not isinstance(s, types.UnicodeType):
|
if not isinstance(s, types.StringTypes):
|
||||||
s = str(s)
|
s = str(s)
|
||||||
if self.pos > self.len:
|
if self.pos > self.len:
|
||||||
self.buflist.append('\0'*(self.pos - self.len))
|
self.buflist.append('\0'*(self.pos - self.len))
|
||||||
|
|
|
@ -73,6 +73,8 @@ class TestStringIO(TestGenericStringIO):
|
||||||
|
|
||||||
def test_unicode(self):
|
def test_unicode(self):
|
||||||
|
|
||||||
|
if not test_support.have_unicode: return
|
||||||
|
|
||||||
# The StringIO module also supports concatenating Unicode
|
# The StringIO module also supports concatenating Unicode
|
||||||
# snippets to larger Unicode strings. This is tested by this
|
# snippets to larger Unicode strings. This is tested by this
|
||||||
# method. Note that cStringIO does not support this extension.
|
# method. Note that cStringIO does not support this extension.
|
||||||
|
|
Loading…
Reference in New Issue