summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-03-18 13:31:31 (GMT)
committerMichael W. Hudson <mwh@python.net>2002-03-18 13:31:31 (GMT)
commitd11f1fac66c852ef62b9ddb1ff4c23caf1b8b7c9 (patch)
treec855ce2b81a27863f96d002128415cf95f62f80c
parentfca4ed6a0997c2b8bb557b1066ac9bdae969ff86 (diff)
downloadcpython-d11f1fac66c852ef62b9ddb1ff4c23caf1b8b7c9.zip
cpython-d11f1fac66c852ef62b9ddb1ff4c23caf1b8b7c9.tar.gz
cpython-d11f1fac66c852ef62b9ddb1ff4c23caf1b8b7c9.tar.bz2
Make StringIO work in non-unicode builds.
Lots of tests fail in non-unicode builds, but I think most of these are "bugs" in the tests. I hope so, anyway.
-rw-r--r--Lib/StringIO.py4
-rw-r--r--Lib/test/test_StringIO.py25
2 files changed, 15 insertions, 14 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
index 1840bad..26549d1 100644
--- a/Lib/StringIO.py
+++ b/Lib/StringIO.py
@@ -39,7 +39,7 @@ __all__ = ["StringIO"]
class StringIO:
def __init__(self, buf = ''):
# Force self.buf to be a string or unicode
- if type(buf) is not types.UnicodeType:
+ if type(buf) not in types.StringTypes:
buf = str(buf)
self.buf = buf
self.len = len(buf)
@@ -138,7 +138,7 @@ class StringIO:
raise ValueError, "I/O operation on closed file"
if not s: return
# Force s to be a string or unicode
- if type(s) is not types.UnicodeType:
+ if type(s) not in types.StringTypes:
s = str(s)
if self.pos > self.len:
self.buflist.append('\0'*(self.pos - self.len))
diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py
index bf3640c..79d2e73 100644
--- a/Lib/test/test_StringIO.py
+++ b/Lib/test/test_StringIO.py
@@ -71,20 +71,21 @@ class TestGenericStringIO(unittest.TestCase):
class TestStringIO(TestGenericStringIO):
MODULE = StringIO
- def test_unicode(self):
+ if test_support.have_unicode:
+ def test_unicode(self):
- # The StringIO module also supports concatenating Unicode
- # snippets to larger Unicode strings. This is tested by this
- # method. Note that cStringIO does not support this extension.
+ # The StringIO module also supports concatenating Unicode
+ # snippets to larger Unicode strings. This is tested by this
+ # method. Note that cStringIO does not support this extension.
- f = self.MODULE.StringIO()
- f.write(self._line[:6])
- f.seek(3)
- f.write(unicode(self._line[20:26]))
- f.write(unicode(self._line[52]))
- s = f.getvalue()
- self.assertEqual(s, unicode('abcuvwxyz!'))
- self.assertEqual(type(s), types.UnicodeType)
+ f = self.MODULE.StringIO()
+ f.write(self._line[:6])
+ f.seek(3)
+ f.write(unicode(self._line[20:26]))
+ f.write(unicode(self._line[52]))
+ s = f.getvalue()
+ self.assertEqual(s, unicode('abcuvwxyz!'))
+ self.assertEqual(type(s), types.UnicodeType)
class TestcStringIO(TestGenericStringIO):
MODULE = cStringIO