[Python-checkins] r83199 - in python/branches/release26-maint: Lib/encodings/utf_16.py Lib/encodings/utf_8_sig.py Misc/NEWS

victor.stinner python-checkins at python.org
Wed Jul 28 03:55:43 CEST 2010


Author: victor.stinner
Date: Wed Jul 28 03:55:43 2010
New Revision: 83199

Log:
Merged revisions 83198 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/release27-maint

........
  r83198 | victor.stinner | 2010-07-28 03:39:45 +0200 (mer., 28 juil. 2010) | 3 lines
  
  Issue #6213: Implement getstate() and setstate() methods of utf-8-sig and
  utf-16 incremental encoders.
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/encodings/utf_16.py
   python/branches/release26-maint/Lib/encodings/utf_8_sig.py
   python/branches/release26-maint/Misc/NEWS

Modified: python/branches/release26-maint/Lib/encodings/utf_16.py
==============================================================================
--- python/branches/release26-maint/Lib/encodings/utf_16.py	(original)
+++ python/branches/release26-maint/Lib/encodings/utf_16.py	Wed Jul 28 03:55:43 2010
@@ -34,6 +34,22 @@
         codecs.IncrementalEncoder.reset(self)
         self.encoder = None
 
+    def getstate(self):
+        # state info we return to the caller:
+        # 0: stream is in natural order for this platform
+        # 2: endianness hasn't been determined yet
+        # (we're never writing in unnatural order)
+        return (2 if self.encoder is None else 0)
+
+    def setstate(self, state):
+        if state:
+            self.encoder = None
+        else:
+            if sys.byteorder == 'little':
+                self.encoder = codecs.utf_16_le_encode
+            else:
+                self.encoder = codecs.utf_16_be_encode
+
 class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
     def __init__(self, errors='strict'):
         codecs.BufferedIncrementalDecoder.__init__(self, errors)

Modified: python/branches/release26-maint/Lib/encodings/utf_8_sig.py
==============================================================================
--- python/branches/release26-maint/Lib/encodings/utf_8_sig.py	(original)
+++ python/branches/release26-maint/Lib/encodings/utf_8_sig.py	Wed Jul 28 03:55:43 2010
@@ -25,18 +25,24 @@
 class IncrementalEncoder(codecs.IncrementalEncoder):
     def __init__(self, errors='strict'):
         codecs.IncrementalEncoder.__init__(self, errors)
-        self.first = True
+        self.first = 1
 
     def encode(self, input, final=False):
         if self.first:
-            self.first = False
+            self.first = 0
             return codecs.BOM_UTF8 + codecs.utf_8_encode(input, self.errors)[0]
         else:
             return codecs.utf_8_encode(input, self.errors)[0]
 
     def reset(self):
         codecs.IncrementalEncoder.reset(self)
-        self.first = True
+        self.first = 1
+
+    def getstate(self):
+        return self.first
+
+    def setstate(self, state):
+        self.first = state
 
 class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
     def __init__(self, errors='strict'):

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Wed Jul 28 03:55:43 2010
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #6213: Implement getstate() and setstate() methods of utf-8-sig and
+  utf-16 incremental encoders.
+
 - Issue #8271: during the decoding of an invalid UTF-8 byte sequence, only the
   start byte and the continuation byte(s) are now considered invalid, instead
   of the number of bytes specified by the start byte.


More information about the Python-checkins mailing list