Kaydet (Commit) d7238ec3 authored tarafından Michael W. Hudson's avatar Michael W. Hudson

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.
üst 48f97f39
...@@ -28,7 +28,7 @@ Notes: ...@@ -28,7 +28,7 @@ Notes:
bytes that occupy space in the buffer. bytes that occupy space in the buffer.
- There's a simple test set (see end of this file). - There's a simple test set (see end of this file).
""" """
import types
try: try:
from errno import EINVAL from errno import EINVAL
except ImportError: except ImportError:
...@@ -38,8 +38,10 @@ __all__ = ["StringIO"] ...@@ -38,8 +38,10 @@ __all__ = ["StringIO"]
class StringIO: class StringIO:
def __init__(self, buf = ''): def __init__(self, buf = ''):
# Force self.buf to be a string # Force self.buf to be a string or unicode
self.buf = str(buf) if type(buf) is not types.UnicodeType:
buf = str(buf)
self.buf = buf
self.len = len(buf) self.len = len(buf)
self.buflist = [] self.buflist = []
self.pos = 0 self.pos = 0
...@@ -135,8 +137,9 @@ class StringIO: ...@@ -135,8 +137,9 @@ class StringIO:
if self.closed: if self.closed:
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 # Force s to be a string or unicode
s = str(s) if type(s) is not types.UnicodeType:
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))
self.len = self.pos self.len = self.pos
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment