summaryrefslogtreecommitdiff
path: root/Lib/codecs.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2005-07-20 22:15:39 +0000
committerWalter Dörwald <walter@livinglogic.de>2005-07-20 22:15:39 +0000
commitc9878e1b220b748788c3faa656257d5da4cd46c7 (patch)
tree93c82f0d65fecef02e121768f00181b4800fd2f6 /Lib/codecs.py
parent21c825417fc993d708c3ff57e2b8b97b09a20159 (diff)
downloadcpython-git-c9878e1b220b748788c3faa656257d5da4cd46c7.tar.gz
Make attributes and local variables in the StreamReader str objects instead
of unicode objects, so that codecs that do a str->str decoding won't promote the result to unicode. This fixes SF bug #1241507.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r--Lib/codecs.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 08cf50b31e..0ffa38268f 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -229,7 +229,9 @@ class StreamReader(Codec):
self.stream = stream
self.errors = errors
self.bytebuffer = ""
- self.charbuffer = u""
+ # For str->str decoding this will stay a str
+ # For str->unicode decoding the first read will promote it to unicode
+ self.charbuffer = ""
def decode(self, input, errors='strict'):
raise NotImplementedError
@@ -284,7 +286,7 @@ class StreamReader(Codec):
if chars < 0:
# Return everything we've got
result = self.charbuffer
- self.charbuffer = u""
+ self.charbuffer = ""
else:
# Return the first chars characters
result = self.charbuffer[:chars]
@@ -301,7 +303,7 @@ class StreamReader(Codec):
"""
readsize = size or 72
- line = u""
+ line = ""
# If size is given, we call read() only once
while True:
data = self.read(readsize)
@@ -309,7 +311,7 @@ class StreamReader(Codec):
# If we're at a "\r" read one extra character (which might
# be a "\n") to get a proper line ending. If the stream is
# temporarily exhausted we return the wrong line ending.
- if data.endswith(u"\r"):
+ if data.endswith("\r"):
data += self.read(size=1, chars=1)
line += data
@@ -319,7 +321,7 @@ class StreamReader(Codec):
line0withoutend = lines[0].splitlines(False)[0]
if line0withend != line0withoutend: # We really have a line end
# Put the rest back together and keep it until the next call
- self.charbuffer = u"".join(lines[1:]) + self.charbuffer
+ self.charbuffer = "".join(lines[1:]) + self.charbuffer
if keepends:
line = line0withend
else: