summaryrefslogtreecommitdiffstats
path: root/Lib/encodings
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-22 16:59:09 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-22 16:59:09 (GMT)
commita92ad7ee2cfd4e81c22a7715aa0278196d9da664 (patch)
treeb56c15ee389d4409a703614122260378cc07468a /Lib/encodings
parentfff532bef328f78ac149123845b1962d9ca5ba59 (diff)
downloadcpython-a92ad7ee2cfd4e81c22a7715aa0278196d9da664.zip
cpython-a92ad7ee2cfd4e81c22a7715aa0278196d9da664.tar.gz
cpython-a92ad7ee2cfd4e81c22a7715aa0278196d9da664.tar.bz2
Merged revisions 81471-81472 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81471 | victor.stinner | 2010-05-22 15:37:56 +0200 (sam., 22 mai 2010) | 7 lines Issue #6268: More bugfixes about BOM, UTF-16 and UTF-32 * Fix seek() method of codecs.open(), don't write the BOM twice after seek(0) * Fix reset() method of codecs, UTF-16, UTF-32 and StreamWriter classes * test_codecs: use "w+" mode instead of "wt+". "t" mode is not supported by Solaris or Windows, but does it really exist? I found it the in the issue. ........ r81472 | victor.stinner | 2010-05-22 15:44:25 +0200 (sam., 22 mai 2010) | 4 lines Fix my last commit (r81471) about codecs Rememder: don't touch the code just before a commit ........
Diffstat (limited to 'Lib/encodings')
-rw-r--r--Lib/encodings/utf_16.py20
-rw-r--r--Lib/encodings/utf_32.py20
2 files changed, 26 insertions, 14 deletions
diff --git a/Lib/encodings/utf_16.py b/Lib/encodings/utf_16.py
index 5500c06..809bc9a 100644
--- a/Lib/encodings/utf_16.py
+++ b/Lib/encodings/utf_16.py
@@ -103,17 +103,23 @@ class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
class StreamWriter(codecs.StreamWriter):
def __init__(self, stream, errors='strict'):
- self.bom_written = False
codecs.StreamWriter.__init__(self, stream, errors)
+ self.encoder = None
+
+ def reset(self):
+ codecs.StreamWriter.reset(self)
+ self.encoder = None
def encode(self, input, errors='strict'):
- self.bom_written = True
- result = codecs.utf_16_encode(input, errors)
- if sys.byteorder == 'little':
- self.encode = codecs.utf_16_le_encode
+ if self.encoder is None:
+ result = codecs.utf_16_encode(input, errors)
+ if sys.byteorder == 'little':
+ self.encoder = codecs.utf_16_le_encode
+ else:
+ self.encoder = codecs.utf_16_be_encode
+ return result
else:
- self.encode = codecs.utf_16_be_encode
- return result
+ return self.encoder(input, errors)
class StreamReader(codecs.StreamReader):
diff --git a/Lib/encodings/utf_32.py b/Lib/encodings/utf_32.py
index f0b7709..c052928 100644
--- a/Lib/encodings/utf_32.py
+++ b/Lib/encodings/utf_32.py
@@ -98,17 +98,23 @@ class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
class StreamWriter(codecs.StreamWriter):
def __init__(self, stream, errors='strict'):
- self.bom_written = False
+ self.encoder = None
codecs.StreamWriter.__init__(self, stream, errors)
+ def reset(self):
+ codecs.StreamWriter.reset(self)
+ self.encoder = None
+
def encode(self, input, errors='strict'):
- self.bom_written = True
- result = codecs.utf_32_encode(input, errors)
- if sys.byteorder == 'little':
- self.encode = codecs.utf_32_le_encode
+ if self.encoder is None:
+ result = codecs.utf_32_encode(input, errors)
+ if sys.byteorder == 'little':
+ self.encoder = codecs.utf_32_le_encode
+ else:
+ self.encoder = codecs.utf_32_be_encode
+ return result
else:
- self.encode = codecs.utf_32_be_encode
- return result
+ return self.encoder(input, errors)
class StreamReader(codecs.StreamReader):