forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e99e96
commit b3f8ee4
Showing
2 changed files
with
41 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import codecs | ||
|
||
def create_win32_code_page_codec(cp): | ||
from codecs import code_page_decode, code_page_decode | ||
|
||
def encode(input, errors='strict'): | ||
return code_page_encode(cp, input, errors) | ||
|
||
def decode(input, errors='strict'): | ||
return code_page_decode(cp, input, errors, True) | ||
|
||
class IncrementalEncoder(codecs.IncrementalEncoder): | ||
def encode(self, input, final=False): | ||
return code_page_encode(cp, input, self.errors)[0] | ||
|
||
class IncrementalDecoder(codecs.BufferedIncrementalDecoder): | ||
def _buffer_decode(self, input, errors, final): | ||
return code_page_decode(cp, input, errors, final) | ||
|
||
class StreamWriter(codecs.StreamWriter): | ||
def encode(self, input, errors='strict'): | ||
return code_page_encode(cp, input, errors) | ||
|
||
class StreamReader(codecs.StreamReader): | ||
def decode(self, input, errors, final): | ||
return code_page_decode(cp, input, errors, final) | ||
|
||
return codecs.CodecInfo( | ||
name=f'cp{cp}', | ||
encode=encode, | ||
decode=decode, | ||
incrementalencoder=IncrementalEncoder, | ||
incrementaldecoder=IncrementalDecoder, | ||
streamreader=StreamReader, | ||
streamwriter=StreamWriter, | ||
) |