diff options
Diffstat (limited to 'Lib/encodings/utf_32.py')
-rw-r--r-- | Lib/encodings/utf_32.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/encodings/utf_32.py b/Lib/encodings/utf_32.py index 4bbd22a..ed73809 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_32encoder(input, errors) + if sys.byteorder == 'little': + self.encoder = codecs.utf_32_leencoder + else: + self.encoder = codecs.utf_32_beencoder + return result else: - self.encode = codecs.utf_32_be_encode - return result + return self.encoder(input, errors) class StreamReader(codecs.StreamReader): |