mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Issue #6213: Implement getstate() and setstate() methods of utf-8-sig and
utf-16 incremental encoders.
This commit is contained in:
parent
3ff4463b35
commit
73363e817a
4 changed files with 28 additions and 5 deletions
|
|
@ -25,18 +25,24 @@ def decode(input, errors='strict'):
|
|||
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'):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue