summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/utf_16.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/encodings/utf_16.py')
-rw-r--r--Lib/encodings/utf_16.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/encodings/utf_16.py b/Lib/encodings/utf_16.py
index eff08f3..61bb041 100644
--- a/Lib/encodings/utf_16.py
+++ b/Lib/encodings/utf_16.py
@@ -58,17 +58,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_16encoder(input, errors)
+ if sys.byteorder == 'little':
+ self.encoder = codecs.utf_16_leencoder
+ else:
+ self.encoder = codecs.utf_16_beencoder
+ return result
else:
- self.encode = codecs.utf_16_be_encode
- return result
+ return self.encoder(input, errors)
class StreamReader(codecs.StreamReader):