From: Michael W. Hudson Date: Mon, 28 Jan 2002 15:00:27 +0000 (+0000) Subject: It's merge time! X-Git-Tag: v2.2.1c1~231 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7238ec33fb4d3465eeb56bf6883a28855144f79;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Lib/StringIO.py b/Lib/StringIO.py index e7c8e04fad5a..1840baddad31 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -28,7 +28,7 @@ Notes: 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 @@ __all__ = ["StringIO"] 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 @@ class StringIO: 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