Patch #1436130: codecs.lookup() now returns a CodecInfo object (a subclass
of tuple) that provides incremental decoders and encoders (a way to use
stateful codecs without the stream API). Functions
codecs.getincrementaldecoder() and codecs.getincrementalencoder() have
been added.
diff --git a/Lib/encodings/mac_roman.py b/Lib/encodings/mac_roman.py
index d23aeba..2de8ab5 100644
--- a/Lib/encodings/mac_roman.py
+++ b/Lib/encodings/mac_roman.py
@@ -1,4 +1,4 @@
-""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/ROMAN.TXT' with gencodec.py.
+""" Python Character Mapping Codec mac_roman generated from 'MAPPINGS/VENDORS/APPLE/ROMAN.TXT' with gencodec.py.
"""#"
@@ -9,13 +9,19 @@
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
-
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
-
return codecs.charmap_decode(input,errors,decoding_table)
+class IncrementalEncoder(codecs.IncrementalEncoder):
+ def encode(self, input, final=False):
+ return codecs.charmap_encode(input,self.errors,encoding_map)[0]
+
+class IncrementalDecoder(codecs.IncrementalDecoder):
+ def decode(self, input, final=False):
+ return codecs.charmap_decode(input,self.errors,decoding_table)[0]
+
class StreamWriter(Codec,codecs.StreamWriter):
pass
@@ -25,8 +31,15 @@
### encodings module API
def getregentry():
-
- return (Codec().encode,Codec().decode,StreamReader,StreamWriter)
+ return codecs.CodecInfo(
+ name='mac-roman',
+ encode=Codec().encode,
+ decode=Codec().decode,
+ incrementalencoder=IncrementalEncoder,
+ incrementaldecoder=IncrementalDecoder,
+ streamreader=StreamReader,
+ streamwriter=StreamWriter,
+ )
### Decoding Table
@@ -550,3 +563,4 @@
0xFB01: 0xDE, # LATIN SMALL LIGATURE FI
0xFB02: 0xDF, # LATIN SMALL LIGATURE FL
}
+