Mercurial > cpython-lru_cache-weakref
diff Lib/StringIO.py @ 21820:a4e4736799b1 2.2
It's merge time!
Backport lemburg's checkin of revision 1.20:
Restore Python 2.1 StringIO.py behaviour: support concatenating
Unicode string snippets to larger Unicode strings.
This fix should also go into Python 2.2.1.
| author | Michael W. Hudson <mwh@python.net> |
|---|---|
| date | Mon, 28 Jan 2002 15:00:27 +0000 |
| parents | ccec02bfe9a0 |
| children | 165e20ac0ab1 e163713b47cf |
line wrap: on
line diff
--- a/Lib/StringIO.py Mon Jan 28 14:58:24 2002 +0000 +++ b/Lib/StringIO.py Mon Jan 28 15:00:27 2002 +0000 @@ -28,7 +28,7 @@ bytes that occupy space in the buffer. - There's a simple test set (see end of this file). """ - +import types try: from errno import EINVAL except ImportError: @@ -38,8 +38,10 @@ class StringIO: def __init__(self, buf = ''): - # Force self.buf to be a string - self.buf = str(buf) + # Force self.buf to be a string or unicode + if type(buf) is not types.UnicodeType: + buf = str(buf) + self.buf = buf self.len = len(buf) self.buflist = [] self.pos = 0 @@ -135,8 +137,9 @@ if self.closed: raise ValueError, "I/O operation on closed file" if not s: return - # Force s to be a string - s = str(s) + # Force s to be a string or unicode + if type(s) is not types.UnicodeType: + s = str(s) if self.pos > self.len: self.buflist.append('\0'*(self.pos - self.len)) self.len = self.pos
