[Python-checkins] python/dist/src/Lib codecs.py,1.35.2.7,1.35.2.8

doerwalter@users.sourceforge.net doerwalter at users.sourceforge.net
Thu Jul 21 00:52:11 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6952/Lib

Modified Files:
      Tag: release24-maint
	codecs.py 
Log Message:
Backport checkin:
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.


Index: codecs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v
retrieving revision 1.35.2.7
retrieving revision 1.35.2.8
diff -u -d -r1.35.2.7 -r1.35.2.8
--- codecs.py	21 Apr 2005 21:53:43 -0000	1.35.2.7
+++ codecs.py	20 Jul 2005 22:52:08 -0000	1.35.2.8
@@ -229,7 +229,9 @@
         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 @@
         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 @@
 
         """
         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 @@
                 # 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 @@
                 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:



More information about the Python-checkins mailing list