diff options
author | Thomas Wouters <thomas@python.org> | 2006-04-21 09:43:23 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2006-04-21 09:43:23 (GMT) |
commit | a977329b6fb0e4c95cabb9043794de69b27a1099 (patch) | |
tree | b91552a0578639bd10181ab612039c1bed9bec27 /Lib | |
parent | d858f70617a9df8456e89a898ad8f97bd57c09f9 (diff) | |
download | cpython-a977329b6fb0e4c95cabb9043794de69b27a1099.zip cpython-a977329b6fb0e4c95cabb9043794de69b27a1099.tar.gz cpython-a977329b6fb0e4c95cabb9043794de69b27a1099.tar.bz2 |
Merge part of the trunk changes into the p3yk branch. This merges from 43030
(branch-creation time) up to 43067. 43068 and 43069 contain a little
swapping action between re.py and sre.py, and this mightily confuses svn
merge, so later changes are going in separately.
This merge should break no additional tests.
The last-merged revision is going in a 'last_merge' property on '.' (the
branch directory.) Arbitrarily chosen, really; if there's a BCP for this, I
couldn't find it, but we can easily change it afterwards ;)
Diffstat (limited to 'Lib')
100 files changed, 2509 insertions, 403 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py index 5c463fb..1e5f254 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -72,8 +72,7 @@ class StringIO: method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit. """ - if self.closed: - raise StopIteration + _complain_ifclosed(self.closed) r = self.readline() if not r: raise StopIteration diff --git a/Lib/codecs.py b/Lib/codecs.py index 6895a22..28856c7 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -73,6 +73,23 @@ BOM64_BE = BOM_UTF32_BE ### Codec base classes (defining the API) +class CodecInfo(tuple): + + def __new__(cls, encode, decode, streamreader=None, streamwriter=None, + incrementalencoder=None, incrementaldecoder=None, name=None): + self = tuple.__new__(cls, (encode, decode, streamreader, streamwriter)) + self.name = name + self.encode = encode + self.decode = decode + self.incrementalencoder = incrementalencoder + self.incrementaldecoder = incrementaldecoder + self.streamwriter = streamwriter + self.streamreader = streamreader + return self + + def __repr__(self): + return "<%s.%s object for encoding %s at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, id(self)) + class Codec: """ Defines the interface for stateless encoders/decoders. @@ -137,6 +154,88 @@ class Codec: """ raise NotImplementedError +class IncrementalEncoder(object): + """ + A IncrementalEncoder encodes an input in multiple steps. The input can be + passed piece by piece to the encode() method. The IncrementalEncoder remembers + the state of the Encoding process between calls to encode(). + """ + def __init__(self, errors='strict'): + """ + Creates a IncrementalEncoder instance. + + The IncrementalEncoder may use different error handling schemes by + providing the errors keyword argument. See the module docstring + for a list of possible values. + """ + self.errors = errors + self.buffer = "" + + def encode(self, input, final=False): + """ + Encodes input and returns the resulting object. + """ + raise NotImplementedError + + def reset(self): + """ + Resets the encoder to the initial state. + """ + +class IncrementalDecoder(object): + """ + An IncrementalDecoder decodes an input in multiple steps. The input can be + passed piece by piece to the decode() method. The IncrementalDecoder + remembers the state of the decoding process between calls to decode(). + """ + def __init__(self, errors='strict'): + """ + Creates a IncrementalDecoder instance. + + The IncrementalDecoder may use different error handling schemes by + providing the errors keyword argument. See the module docstring + for a list of possible values. + """ + self.errors = errors + + def decode(self, input, final=False): + """ + Decodes input and returns the resulting object. + """ + raise NotImplementedError + + def reset(self): + """ + Resets the decoder to the initial state. + """ + +class BufferedIncrementalDecoder(IncrementalDecoder): + """ + This subclass of IncrementalDecoder can be used as the baseclass for an + incremental decoder if the decoder must be able to handle incomplete byte + sequences. + """ + def __init__(self, errors='strict'): + IncrementalDecoder.__init__(self, errors) + self.buffer = "" # undecoded input that is kept between calls to decode() + + def _buffer_decode(self, input, errors, final): + # Overwrite this method in subclasses: It must decode input + # and return an (output, length consumed) tuple + raise NotImplementedError + + def decode(self, input, final=False): + # decode input (taking the buffer into account) + data = self.buffer + input + (result, consumed) = self._buffer_decode(data, self.errors, final) + # keep undecoded input until the next call + self.buffer = data[consumed:] + return result + + def reset(self): + IncrementalDecoder.reset(self) + self.bytebuffer = "" + # # The StreamWriter and StreamReader class provide generic working # interfaces which can be used to implement new encoding submodules @@ -666,8 +765,8 @@ def open(filename, mode='rb', encoding=None, errors='strict', buffering=1): file = __builtin__.open(filename, mode, buffering) if encoding is None: return file - (e, d, sr, sw) = lookup(encoding) - srw = StreamReaderWriter(file, sr, sw, errors) + info = lookup(encoding) + srw = StreamReaderWriter(file, info.streamreader, info.streamwriter, errors) # Add attributes to simplify introspection srw.encoding = encoding return srw @@ -699,11 +798,9 @@ def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'): """ if file_encoding is None: file_encoding = data_encoding - encode, decode = lookup(data_encoding)[:2] - Reader, Writer = lookup(file_encoding)[2:] - sr = StreamRecoder(file, - encode, decode, Reader, Writer, - errors) + info = lookup(data_encoding) + sr = StreamRecoder(file, info.encode, info.decode, + info.streamreader, info.streamwriter, errors) # Add attributes to simplify introspection sr.data_encoding = data_encoding sr.file_encoding = file_encoding @@ -719,7 +816,7 @@ def getencoder(encoding): Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[0] + return lookup(encoding).encode def getdecoder(encoding): @@ -729,7 +826,35 @@ def getdecoder(encoding): Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[1] + return lookup(encoding).decode + +def getincrementalencoder(encoding): + + """ Lookup up the codec for the given encoding and return + its IncrementalEncoder class or factory function. + + Raises a LookupError in case the encoding cannot be found + or the codecs doesn't provide an incremental encoder. + + """ + encoder = lookup(encoding).incrementalencoder + if encoder is None: + raise LookupError(encoding) + return encoder + +def getincrementaldecoder(encoding): + + """ Lookup up the codec for the given encoding and return + its IncrementalDecoder class or factory function. + + Raises a LookupError in case the encoding cannot be found + or the codecs doesn't provide an incremental decoder. + + """ + decoder = lookup(encoding).incrementaldecoder + if decoder is None: + raise LookupError(encoding) + return decoder def getreader(encoding): @@ -739,7 +864,7 @@ def getreader(encoding): Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[2] + return lookup(encoding).streamreader def getwriter(encoding): @@ -749,7 +874,43 @@ def getwriter(encoding): Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[3] + return lookup(encoding).streamwriter + +def iterencode(iterator, encoding, errors='strict', **kwargs): + """ + Encoding iterator. + + Encodes the input strings from the iterator using a IncrementalEncoder. + + errors and kwargs are passed through to the IncrementalEncoder + constructor. + """ + encoder = getincrementalencoder(encoding)(errors, **kwargs) + for input in iterator: + output = encoder.encode(input) + if output: + yield output + output = encoder.encode("", True) + if output: + yield output + +def iterdecode(iterator, encoding, errors='strict', **kwargs): + """ + Decoding iterator. + + Decodes the input strings from the iterator using a IncrementalDecoder. + + errors and kwargs are passed through to the IncrementalDecoder + constructor. + """ + decoder = getincrementaldecoder(encoding)(errors, **kwargs) + for input in iterator: + output = decoder.decode(input) + if output: + yield output + output = decoder.decode("", True) + if output: + yield output ### Helpers for charmap-based codecs diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index ddaacb9..1f469bf 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -9,9 +9,10 @@ Each codec module must export the following interface: - * getregentry() -> (encoder, decoder, stream_reader, stream_writer) - The getregentry() API must return callable objects which adhere to - the Python Codec Interface Standard. + * getregentry() -> codecs.CodecInfo object + The getregentry() API must a CodecInfo object with encoder, decoder, + incrementalencoder, incrementaldecoder, streamwriter and streamreader + atttributes which adhere to the Python Codec Interface Standard. In addition, a module may optionally also define the following APIs which are then used by the package's codec search function: @@ -113,16 +114,24 @@ def search_function(encoding): return None # Now ask the module for the registry entry - entry = tuple(getregentry()) - if len(entry) != 4: - raise CodecRegistryError,\ - 'module "%s" (%s) failed to register' % \ - (mod.__name__, mod.__file__) - for obj in entry: - if not callable(obj): + entry = getregentry() + if not isinstance(entry, codecs.CodecInfo): + if not 4 <= len(entry) <= 7: raise CodecRegistryError,\ - 'incompatible codecs in module "%s" (%s)' % \ + 'module "%s" (%s) failed to register' % \ (mod.__name__, mod.__file__) + if not callable(entry[0]) or \ + not callable(entry[1]) or \ + (entry[2] is not None and not callable(entry[2])) or \ + (entry[3] is not None and not callable(entry[3])) or \ + (len(entry) > 4 and entry[4] is not None and not callable(entry[4])) or \ + (len(entry) > 5 and entry[5] is not None and not callable(entry[5])): + raise CodecRegistryError,\ + 'incompatible codecs in module "%s" (%s)' % \ + (mod.__name__, mod.__file__) + if len(entry)<7 or entry[6] is None: + entry += (None,)*(6-len(entry)) + (mod.__name__.split(".", 1)[1],) + entry = codecs.CodecInfo(*entry) # Cache the codec registry entry _cache[encoding] = entry diff --git a/Lib/encodings/ascii.py b/Lib/encodings/ascii.py index 05fc36a..2033cde 100644 --- a/Lib/encodings/ascii.py +++ b/Lib/encodings/ascii.py @@ -17,6 +17,14 @@ class Codec(codecs.Codec): encode = codecs.ascii_encode decode = codecs.ascii_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.ascii_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.ascii_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -31,5 +39,12 @@ class StreamConverter(StreamWriter,StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='ascii', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/base64_codec.py b/Lib/encodings/base64_codec.py index 085ab14..f84e780 100644 --- a/Lib/encodings/base64_codec.py +++ b/Lib/encodings/base64_codec.py @@ -49,6 +49,16 @@ class Codec(codecs.Codec): def decode(self, input,errors='strict'): return base64_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return base64.encodestring(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return base64.decodestring(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -58,5 +68,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (base64_encode,base64_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='base64', + encode=base64_encode, + decode=base64_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/bz2_codec.py b/Lib/encodings/bz2_codec.py index 870474c..81e84b6 100644 --- a/Lib/encodings/bz2_codec.py +++ b/Lib/encodings/bz2_codec.py @@ -51,6 +51,16 @@ class Codec(codecs.Codec): def decode(self, input, errors='strict'): return bz2_decode(input, errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return bz2.compress(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return bz2.decompress(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -60,5 +70,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (bz2_encode,bz2_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name="bz2", + encode=bz2_encode, + decode=bz2_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/charmap.py b/Lib/encodings/charmap.py index 9bd93ec..81189b1 100644 --- a/Lib/encodings/charmap.py +++ b/Lib/encodings/charmap.py @@ -21,30 +21,49 @@ class Codec(codecs.Codec): encode = codecs.charmap_encode decode = codecs.charmap_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict', mapping=None): + codecs.IncrementalEncoder.__init__(self, errors) + self.mapping = mapping + + def encode(self, input, final=False): + return codecs.charmap_encode(input, self.errors, self.mapping)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def __init__(self, errors='strict', mapping=None): + codecs.IncrementalDecoder.__init__(self, errors) + self.mapping = mapping + + def decode(self, input, final=False): + return codecs.charmap_decode(input, self.errors, self.mapping)[0] + class StreamWriter(Codec,codecs.StreamWriter): def __init__(self,stream,errors='strict',mapping=None): - codecs.StreamWriter.__init__(self,stream,errors) self.mapping = mapping def encode(self,input,errors='strict'): - return Codec.encode(input,errors,self.mapping) class StreamReader(Codec,codecs.StreamReader): def __init__(self,stream,errors='strict',mapping=None): - codecs.StreamReader.__init__(self,stream,errors) self.mapping = mapping def decode(self,input,errors='strict'): - return Codec.decode(input,errors,self.mapping) ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='charmap', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/cp037.py b/Lib/encodings/cp037.py index 5864c4b..7e589a9 100644 --- a/Lib/encodings/cp037.py +++ b/Lib/encodings/cp037.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP037.TXT' with gencodec.py. +""" Python Character Mapping Codec cp037 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP037.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp037', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1006.py b/Lib/encodings/cp1006.py index d94563d..7829969 100644 --- a/Lib/encodings/cp1006.py +++ b/Lib/encodings/cp1006.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/CP1006.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1006 generated from 'MAPPINGS/VENDORS/MISC/CP1006.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1006', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1026.py b/Lib/encodings/cp1026.py index 648bed0..01c8804 100644 --- a/Lib/encodings/cp1026.py +++ b/Lib/encodings/cp1026.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP1026.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1026 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP1026.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1026', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1140.py b/Lib/encodings/cp1140.py index 6507552..ac8d41b 100644 --- a/Lib/encodings/cp1140.py +++ b/Lib/encodings/cp1140.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'python-mappings/CP1140.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1140 generated from 'python-mappings/CP1140.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1140', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1250.py b/Lib/encodings/cp1250.py index 73427bc..6e6f57c 100644 --- a/Lib/encodings/cp1250.py +++ b/Lib/encodings/cp1250.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1250 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1250', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1251.py b/Lib/encodings/cp1251.py index f3e107ef..ed835fe 100644 --- a/Lib/encodings/cp1251.py +++ b/Lib/encodings/cp1251.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1251 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1251', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1252.py b/Lib/encodings/cp1252.py index ea7561d..e5b6905 100644 --- a/Lib/encodings/cp1252.py +++ b/Lib/encodings/cp1252.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1252 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1252', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1253.py b/Lib/encodings/cp1253.py index 5feefb3..3ce70b25 100644 --- a/Lib/encodings/cp1253.py +++ b/Lib/encodings/cp1253.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1253.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1253 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1253.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1253', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1254.py b/Lib/encodings/cp1254.py index 6769e1b..31cd48c 100644 --- a/Lib/encodings/cp1254.py +++ b/Lib/encodings/cp1254.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1254.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1254 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1254.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1254', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1255.py b/Lib/encodings/cp1255.py index b994f9d..47c43ce 100644 --- a/Lib/encodings/cp1255.py +++ b/Lib/encodings/cp1255.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1255 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1255', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1256.py b/Lib/encodings/cp1256.py index 5da425e..e90393b 100644 --- a/Lib/encodings/cp1256.py +++ b/Lib/encodings/cp1256.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1256 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1256', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1257.py b/Lib/encodings/cp1257.py index 237a531..dcc81c0 100644 --- a/Lib/encodings/cp1257.py +++ b/Lib/encodings/cp1257.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1257 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1257', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp1258.py b/Lib/encodings/cp1258.py index 5de3fd8..d4d2271 100644 --- a/Lib/encodings/cp1258.py +++ b/Lib/encodings/cp1258.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1258.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1258 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1258.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1258', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp424.py b/Lib/encodings/cp424.py index d19c756..966aecb 100644 --- a/Lib/encodings/cp424.py +++ b/Lib/encodings/cp424.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/CP424.TXT' with gencodec.py. +""" Python Character Mapping Codec cp424 generated from 'MAPPINGS/VENDORS/MISC/CP424.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp424', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp437.py b/Lib/encodings/cp437.py index e9cefaf..52cd882 100644 --- a/Lib/encodings/cp437.py +++ b/Lib/encodings/cp437.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP437.TXT' with gencodec.py. +""" Python Character Mapping Codec cp437 generated from 'VENDORS/MICSFT/PC/CP437.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp437', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp500.py b/Lib/encodings/cp500.py index 3bbefa0..83af090 100644 --- a/Lib/encodings/cp500.py +++ b/Lib/encodings/cp500.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP500.TXT' with gencodec.py. +""" Python Character Mapping Codec cp500 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP500.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp500', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp737.py b/Lib/encodings/cp737.py index 883a8ba..d654448 100644 --- a/Lib/encodings/cp737.py +++ b/Lib/encodings/cp737.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP737.TXT' with gencodec.py. +""" Python Character Mapping Codec cp737 generated from 'VENDORS/MICSFT/PC/CP737.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp737', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp775.py b/Lib/encodings/cp775.py index 1b39188..6a456a5 100644 --- a/Lib/encodings/cp775.py +++ b/Lib/encodings/cp775.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP775.TXT' with gencodec.py. +""" Python Character Mapping Codec cp775 generated from 'VENDORS/MICSFT/PC/CP775.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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,9 +31,15 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) - + return codecs.CodecInfo( + name='cp775', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map decoding_map = codecs.make_identity_dict(range(256)) diff --git a/Lib/encodings/cp850.py b/Lib/encodings/cp850.py index 6481ee0..0c8478c 100644 --- a/Lib/encodings/cp850.py +++ b/Lib/encodings/cp850.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp850', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp852.py b/Lib/encodings/cp852.py index 749b0da..069d547 100644 --- a/Lib/encodings/cp852.py +++ b/Lib/encodings/cp852.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp852', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp855.py b/Lib/encodings/cp855.py index 13146c9..241ef9d 100644 --- a/Lib/encodings/cp855.py +++ b/Lib/encodings/cp855.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp855', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp856.py b/Lib/encodings/cp856.py index 5823dff..c72fcad 100644 --- a/Lib/encodings/cp856.py +++ b/Lib/encodings/cp856.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/CP856.TXT' with gencodec.py. +""" Python Character Mapping Codec cp856 generated from 'MAPPINGS/VENDORS/MISC/CP856.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp856', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp857.py b/Lib/encodings/cp857.py index 6c5cdbb..c24191b 100644 --- a/Lib/encodings/cp857.py +++ b/Lib/encodings/cp857.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp857', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp860.py b/Lib/encodings/cp860.py index cd7cdf4..4acb0cf 100644 --- a/Lib/encodings/cp860.py +++ b/Lib/encodings/cp860.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp860', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp861.py b/Lib/encodings/cp861.py index b140f2e..0939b5b 100644 --- a/Lib/encodings/cp861.py +++ b/Lib/encodings/cp861.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp861', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp862.py b/Lib/encodings/cp862.py index badec08..ea0405c 100644 --- a/Lib/encodings/cp862.py +++ b/Lib/encodings/cp862.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp862', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp863.py b/Lib/encodings/cp863.py index 812bc3d..62dfabf 100644 --- a/Lib/encodings/cp863.py +++ b/Lib/encodings/cp863.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp863', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp864.py b/Lib/encodings/cp864.py index 41f2ea3..02a0e73 100644 --- a/Lib/encodings/cp864.py +++ b/Lib/encodings/cp864.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp864', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp865.py b/Lib/encodings/cp865.py index 8e68c6b..e9f45f1 100644 --- a/Lib/encodings/cp865.py +++ b/Lib/encodings/cp865.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp865', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp866.py b/Lib/encodings/cp866.py index 4c0dd8c..29cd85a 100644 --- a/Lib/encodings/cp866.py +++ b/Lib/encodings/cp866.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp866', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp869.py b/Lib/encodings/cp869.py index 1747546..b4dc99b 100644 --- a/Lib/encodings/cp869.py +++ b/Lib/encodings/cp869.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp869', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/cp874.py b/Lib/encodings/cp874.py index 5e1fea1..591e8aa 100644 --- a/Lib/encodings/cp874.py +++ b/Lib/encodings/cp874.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP874.TXT' with gencodec.py. +""" Python Character Mapping Codec cp874 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP874.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp874', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/cp875.py b/Lib/encodings/cp875.py index ccebb84..879d5a4 100644 --- a/Lib/encodings/cp875.py +++ b/Lib/encodings/cp875.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP875.TXT' with gencodec.py. +""" Python Character Mapping Codec cp875 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP875.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp875', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/hex_codec.py b/Lib/encodings/hex_codec.py index 5c6e4a4..91b38d9 100644 --- a/Lib/encodings/hex_codec.py +++ b/Lib/encodings/hex_codec.py @@ -49,6 +49,16 @@ class Codec(codecs.Codec): def decode(self, input,errors='strict'): return hex_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return binascii.b2a_hex(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return binascii.a2b_hex(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -58,5 +68,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (hex_encode,hex_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='hex', + encode=hex_encode, + decode=hex_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/hp_roman8.py b/Lib/encodings/hp_roman8.py index 4f201b8..dbaaa72 100644 --- a/Lib/encodings/hp_roman8.py +++ b/Lib/encodings/hp_roman8.py @@ -14,13 +14,19 @@ import codecs 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_map) +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_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='hp-roman8', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) ### Decoding Map diff --git a/Lib/encodings/idna.py b/Lib/encodings/idna.py index 3d3ed23..8bdae32 100644 --- a/Lib/encodings/idna.py +++ b/Lib/encodings/idna.py @@ -194,6 +194,14 @@ class Codec(codecs.Codec): return u".".join(result)+trailing_dot, len(input) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return Codec().encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return Codec().decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -203,5 +211,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='idna', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/iso8859_1.py b/Lib/encodings/iso8859_1.py index 6aaea7c..b985585 100644 --- a/Lib/encodings/iso8859_1.py +++ b/Lib/encodings/iso8859_1.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-1.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_1 generated from 'MAPPINGS/ISO8859/8859-1.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-1', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_10.py b/Lib/encodings/iso8859_10.py index 26b55c9..8588430 100644 --- a/Lib/encodings/iso8859_10.py +++ b/Lib/encodings/iso8859_10.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-10.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_10 generated from 'MAPPINGS/ISO8859/8859-10.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-10', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_11.py b/Lib/encodings/iso8859_11.py index ef17167..fffe692 100644 --- a/Lib/encodings/iso8859_11.py +++ b/Lib/encodings/iso8859_11.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-11.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_11 generated from 'MAPPINGS/ISO8859/8859-11.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-11', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_13.py b/Lib/encodings/iso8859_13.py index 0e10c7d..a890580 100644 --- a/Lib/encodings/iso8859_13.py +++ b/Lib/encodings/iso8859_13.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-13.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_13 generated from 'MAPPINGS/ISO8859/8859-13.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-13', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_14.py b/Lib/encodings/iso8859_14.py index b981031..afa458c 100644 --- a/Lib/encodings/iso8859_14.py +++ b/Lib/encodings/iso8859_14.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-14.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_14 generated from 'MAPPINGS/ISO8859/8859-14.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-14', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_15.py b/Lib/encodings/iso8859_15.py index f50a904..4a8334e 100644 --- a/Lib/encodings/iso8859_15.py +++ b/Lib/encodings/iso8859_15.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-15.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_15 generated from 'MAPPINGS/ISO8859/8859-15.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-15', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_16.py b/Lib/encodings/iso8859_16.py index ce8bc5b..aeebfb6 100644 --- a/Lib/encodings/iso8859_16.py +++ b/Lib/encodings/iso8859_16.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-16.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_16 generated from 'MAPPINGS/ISO8859/8859-16.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-16', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_2.py b/Lib/encodings/iso8859_2.py index 417b451..845f322 100644 --- a/Lib/encodings/iso8859_2.py +++ b/Lib/encodings/iso8859_2.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-2.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_2 generated from 'MAPPINGS/ISO8859/8859-2.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-2', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_3.py b/Lib/encodings/iso8859_3.py index c3ad3a9..fbc8775 100644 --- a/Lib/encodings/iso8859_3.py +++ b/Lib/encodings/iso8859_3.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-3.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_3 generated from 'MAPPINGS/ISO8859/8859-3.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-3', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_4.py b/Lib/encodings/iso8859_4.py index b65685a..e705954 100644 --- a/Lib/encodings/iso8859_4.py +++ b/Lib/encodings/iso8859_4.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-4.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_4 generated from 'MAPPINGS/ISO8859/8859-4.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-4', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_5.py b/Lib/encodings/iso8859_5.py index 59fe372..93a4e90 100644 --- a/Lib/encodings/iso8859_5.py +++ b/Lib/encodings/iso8859_5.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-5.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_5 generated from 'MAPPINGS/ISO8859/8859-5.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-5', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_6.py b/Lib/encodings/iso8859_6.py index b07661d9..f911cc4 100644 --- a/Lib/encodings/iso8859_6.py +++ b/Lib/encodings/iso8859_6.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-6.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_6 generated from 'MAPPINGS/ISO8859/8859-6.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-6', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_7.py b/Lib/encodings/iso8859_7.py index 54d0997..4cce6e2 100644 --- a/Lib/encodings/iso8859_7.py +++ b/Lib/encodings/iso8859_7.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-7.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_7 generated from 'MAPPINGS/ISO8859/8859-7.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-7', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_8.py b/Lib/encodings/iso8859_8.py index 24ba1bb..8c29a87 100644 --- a/Lib/encodings/iso8859_8.py +++ b/Lib/encodings/iso8859_8.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-8.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_8 generated from 'MAPPINGS/ISO8859/8859-8.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-8', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/iso8859_9.py b/Lib/encodings/iso8859_9.py index 940d92b..9648e9f 100644 --- a/Lib/encodings/iso8859_9.py +++ b/Lib/encodings/iso8859_9.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-9.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_9 generated from 'MAPPINGS/ISO8859/8859-9.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-9', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/koi8_r.py b/Lib/encodings/koi8_r.py index f2723de..3efeb56 100644 --- a/Lib/encodings/koi8_r.py +++ b/Lib/encodings/koi8_r.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/KOI8-R.TXT' with gencodec.py. +""" Python Character Mapping Codec koi8_r generated from 'MAPPINGS/VENDORS/MISC/KOI8-R.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='koi8-r', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/koi8_u.py b/Lib/encodings/koi8_u.py index 9bbcf7c..5f46db1 100644 --- a/Lib/encodings/koi8_u.py +++ b/Lib/encodings/koi8_u.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'python-mappings/KOI8-U.TXT' with gencodec.py. +""" Python Character Mapping Codec koi8_u generated from 'python-mappings/KOI8-U.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='koi8-u', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/latin_1.py b/Lib/encodings/latin_1.py index 0e55917..370160c 100644 --- a/Lib/encodings/latin_1.py +++ b/Lib/encodings/latin_1.py @@ -17,6 +17,14 @@ class Codec(codecs.Codec): encode = codecs.latin_1_encode decode = codecs.latin_1_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.latin_1_encode(input,self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.latin_1_decode(input,self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -31,5 +39,12 @@ class StreamConverter(StreamWriter,StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-1', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/mac_arabic.py b/Lib/encodings/mac_arabic.py index 6c096b4..7a7d3c5 100644 --- a/Lib/encodings/mac_arabic.py +++ b/Lib/encodings/mac_arabic.py @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-arabic', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/mac_centeuro.py b/Lib/encodings/mac_centeuro.py index d7d67ec..54a1510 100644 --- a/Lib/encodings/mac_centeuro.py +++ b/Lib/encodings/mac_centeuro.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/CENTEURO.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_centeuro generated from 'MAPPINGS/VENDORS/APPLE/CENTEURO.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-centeuro', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_croatian.py b/Lib/encodings/mac_croatian.py index 96e1187..9e93cdd 100644 --- a/Lib/encodings/mac_croatian.py +++ b/Lib/encodings/mac_croatian.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/CROATIAN.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_croatian generated from 'MAPPINGS/VENDORS/APPLE/CROATIAN.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-croatian', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_cyrillic.py b/Lib/encodings/mac_cyrillic.py index f1b1fb0..8ffd715 100644 --- a/Lib/encodings/mac_cyrillic.py +++ b/Lib/encodings/mac_cyrillic.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/CYRILLIC.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_cyrillic generated from 'MAPPINGS/VENDORS/APPLE/CYRILLIC.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-cyrillic', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_farsi.py b/Lib/encodings/mac_farsi.py index 2b61e27..6d26a42 100644 --- a/Lib/encodings/mac_farsi.py +++ b/Lib/encodings/mac_farsi.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/FARSI.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_farsi generated from 'MAPPINGS/VENDORS/APPLE/FARSI.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-farsi', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_greek.py b/Lib/encodings/mac_greek.py index c2dd26f..7264f9a 100644 --- a/Lib/encodings/mac_greek.py +++ b/Lib/encodings/mac_greek.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/GREEK.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_greek generated from 'MAPPINGS/VENDORS/APPLE/GREEK.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-greek', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_iceland.py b/Lib/encodings/mac_iceland.py index d305d29..5d8d9ad 100644 --- a/Lib/encodings/mac_iceland.py +++ b/Lib/encodings/mac_iceland.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/ICELAND.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_iceland generated from 'MAPPINGS/VENDORS/APPLE/ICELAND.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-iceland', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_latin2.py b/Lib/encodings/mac_latin2.py index f5d5225..e322be2 100644 --- a/Lib/encodings/mac_latin2.py +++ b/Lib/encodings/mac_latin2.py @@ -14,13 +14,19 @@ import codecs 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_map) +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_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-latin2', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/mac_roman.py b/Lib/encodings/mac_roman.py index d23aeba..9552e53 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 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### 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 diff --git a/Lib/encodings/mac_romanian.py b/Lib/encodings/mac_romanian.py index 5c35a64..51282c3 100644 --- a/Lib/encodings/mac_romanian.py +++ b/Lib/encodings/mac_romanian.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/ROMANIAN.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_romanian generated from 'MAPPINGS/VENDORS/APPLE/ROMANIAN.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-romanian', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mac_turkish.py b/Lib/encodings/mac_turkish.py index 79894ba..4e5641f 100644 --- a/Lib/encodings/mac_turkish.py +++ b/Lib/encodings/mac_turkish.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/TURKISH.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_turkish generated from 'MAPPINGS/VENDORS/APPLE/TURKISH.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-turkish', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/mbcs.py b/Lib/encodings/mbcs.py index c79f47c..ff77fde 100644 --- a/Lib/encodings/mbcs.py +++ b/Lib/encodings/mbcs.py @@ -18,6 +18,13 @@ class Codec(codecs.Codec): encode = codecs.mbcs_encode decode = codecs.mbcs_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.mbcs_encode(input,self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.mbcs_decode(input,self.errors)[0] class StreamWriter(Codec,codecs.StreamWriter): pass @@ -32,5 +39,12 @@ class StreamConverter(StreamWriter,StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mbcs', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/palmos.py b/Lib/encodings/palmos.py index c0f0606..4b77e2b 100644 --- a/Lib/encodings/palmos.py +++ b/Lib/encodings/palmos.py @@ -15,6 +15,14 @@ class Codec(codecs.Codec): def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_map) +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_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -24,7 +32,15 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='palmos', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/ptcp154.py b/Lib/encodings/ptcp154.py index 5cdd98c..aef8975 100644 --- a/Lib/encodings/ptcp154.py +++ b/Lib/encodings/ptcp154.py @@ -14,13 +14,19 @@ import codecs 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_map) +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_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='ptcp154', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map diff --git a/Lib/encodings/punycode.py b/Lib/encodings/punycode.py index 82fd458..2cde8b9 100644 --- a/Lib/encodings/punycode.py +++ b/Lib/encodings/punycode.py @@ -197,18 +197,27 @@ def punycode_decode(text, errors): ### Codec APIs class Codec(codecs.Codec): - def encode(self,input,errors='strict'): + def encode(self,input,errors='strict'): res = punycode_encode(input) return res, len(input) def decode(self,input,errors='strict'): - if errors not in ('strict', 'replace', 'ignore'): raise UnicodeError, "Unsupported error handling "+errors res = punycode_decode(input, errors) return res, len(input) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return punycode_encode(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + if errors not in ('strict', 'replace', 'ignore'): + raise UnicodeError, "Unsupported error handling "+errors + return punycode_decode(input, errors) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -218,5 +227,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='punycode', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/quopri_codec.py b/Lib/encodings/quopri_codec.py index d98b5ed..b802ae6 100644 --- a/Lib/encodings/quopri_codec.py +++ b/Lib/encodings/quopri_codec.py @@ -46,6 +46,14 @@ class Codec(codecs.Codec): def decode(self, input,errors='strict'): return quopri_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return quopri_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return quopri_decode(input, self.errors)[0] + class StreamWriter(Codec, codecs.StreamWriter): pass @@ -55,4 +63,12 @@ class StreamReader(Codec,codecs.StreamReader): # encodings module API def getregentry(): - return (quopri_encode, quopri_decode, StreamReader, StreamWriter) + return codecs.CodecInfo( + name='quopri', + encode=quopri_encode, + decode=quopri_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/raw_unicode_escape.py b/Lib/encodings/raw_unicode_escape.py index a2f3fff..2b919b4 100644 --- a/Lib/encodings/raw_unicode_escape.py +++ b/Lib/encodings/raw_unicode_escape.py @@ -17,6 +17,14 @@ class Codec(codecs.Codec): encode = codecs.raw_unicode_escape_encode decode = codecs.raw_unicode_escape_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.raw_unicode_escape_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.raw_unicode_escape_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -26,5 +34,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='raw-unicode-escape', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/rot_13.py b/Lib/encodings/rot_13.py index c628181..52b6431 100644 --- a/Lib/encodings/rot_13.py +++ b/Lib/encodings/rot_13.py @@ -14,13 +14,19 @@ import codecs 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_map) +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_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='rot-13', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) ### Decoding Map diff --git a/Lib/encodings/string_escape.py b/Lib/encodings/string_escape.py index c02bfee..e329a26 100644 --- a/Lib/encodings/string_escape.py +++ b/Lib/encodings/string_escape.py @@ -12,6 +12,14 @@ class Codec(codecs.Codec): encode = codecs.escape_encode decode = codecs.escape_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.escape_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.escape_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -19,5 +27,12 @@ class StreamReader(Codec,codecs.StreamReader): pass def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='string-escape', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/tis_620.py b/Lib/encodings/tis_620.py index aa1823e..166d932 100644 --- a/Lib/encodings/tis_620.py +++ b/Lib/encodings/tis_620.py @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'python-mappings/TIS-620.TXT' with gencodec.py. +""" Python Character Mapping Codec tis_620 generated from 'python-mappings/TIS-620.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ import codecs 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 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='tis-620', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table diff --git a/Lib/encodings/undefined.py b/Lib/encodings/undefined.py index d2277ac..4690288 100644 --- a/Lib/encodings/undefined.py +++ b/Lib/encodings/undefined.py @@ -16,10 +16,18 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - raise UnicodeError, "undefined encoding" + raise UnicodeError("undefined encoding") def decode(self,input,errors='strict'): - raise UnicodeError, "undefined encoding" + raise UnicodeError("undefined encoding") + +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + raise UnicodeError("undefined encoding") + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + raise UnicodeError("undefined encoding") class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,5 +38,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='undefined', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/unicode_escape.py b/Lib/encodings/unicode_escape.py index 8fb6293..817f932 100644 --- a/Lib/encodings/unicode_escape.py +++ b/Lib/encodings/unicode_escape.py @@ -17,6 +17,14 @@ class Codec(codecs.Codec): encode = codecs.unicode_escape_encode decode = codecs.unicode_escape_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.unicode_escape_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.unicode_escape_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -26,5 +34,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='unicode-escape', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/unicode_internal.py b/Lib/encodings/unicode_internal.py index 3bd2fa0..df3e775 100644 --- a/Lib/encodings/unicode_internal.py +++ b/Lib/encodings/unicode_internal.py @@ -17,6 +17,14 @@ class Codec(codecs.Codec): encode = codecs.unicode_internal_encode decode = codecs.unicode_internal_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.unicode_internal_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.unicode_internal_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -26,5 +34,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='unicode-internal', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) diff --git a/Lib/encodings/utf_16.py b/Lib/encodings/utf_16.py index 95abb05..eff08f3 100644 --- a/Lib/encodings/utf_16.py +++ b/Lib/encodings/utf_16.py @@ -15,6 +15,47 @@ encode = codecs.utf_16_encode def decode(input, errors='strict'): return codecs.utf_16_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + codecs.IncrementalEncoder.__init__(self, errors) + self.encoder = None + + def encode(self, input, final=False): + if self.encoder is None: + result = codecs.utf_16_encode(input, self.errors)[0] + if sys.byteorder == 'little': + self.encoder = codecs.utf_16_le_encode + else: + self.encoder = codecs.utf_16_be_encode + return result + return self.encoder(input, self.errors)[0] + + def reset(self): + codecs.IncrementalEncoder.reset(self) + self.encoder = None + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def __init__(self, errors='strict'): + codecs.BufferedIncrementalDecoder.__init__(self, errors) + self.decoder = None + + def _buffer_decode(self, input, errors, final): + if self.decoder is None: + (output, consumed, byteorder) = \ + codecs.utf_16_ex_decode(input, errors, 0, final) + if byteorder == -1: + self.decoder = codecs.utf_16_le_decode + elif byteorder == 1: + self.decoder = codecs.utf_16_be_decode + elif consumed >= 2: + raise UnicodeError("UTF-16 stream does not start with BOM") + return (output, consumed) + return self.decoder(input, self.errors, final) + + def reset(self): + codecs.BufferedIncrementalDecoder.reset(self) + self.decoder = None + class StreamWriter(codecs.StreamWriter): def __init__(self, stream, errors='strict'): self.bom_written = False @@ -52,5 +93,12 @@ class StreamReader(codecs.StreamReader): ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-16', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/utf_16_be.py b/Lib/encodings/utf_16_be.py index 9a51f8c..86b458e 100644 --- a/Lib/encodings/utf_16_be.py +++ b/Lib/encodings/utf_16_be.py @@ -15,6 +15,13 @@ encode = codecs.utf_16_be_encode def decode(input, errors='strict'): return codecs.utf_16_be_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_16_be_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = codecs.utf_16_be_decode + class StreamWriter(codecs.StreamWriter): encode = codecs.utf_16_be_encode @@ -24,5 +31,12 @@ class StreamReader(codecs.StreamReader): ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-16-be', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/utf_16_le.py b/Lib/encodings/utf_16_le.py index 95ca830..ec45414 100644 --- a/Lib/encodings/utf_16_le.py +++ b/Lib/encodings/utf_16_le.py @@ -15,15 +15,28 @@ encode = codecs.utf_16_le_encode def decode(input, errors='strict'): return codecs.utf_16_le_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_16_le_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = codecs.utf_16_le_decode + class StreamWriter(codecs.StreamWriter): encode = codecs.utf_16_le_encode class StreamReader(codecs.StreamReader): decode = codecs.utf_16_le_decode - ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-16-le', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/utf_7.py b/Lib/encodings/utf_7.py index ee78d09..d78d192 100644 --- a/Lib/encodings/utf_7.py +++ b/Lib/encodings/utf_7.py @@ -13,6 +13,14 @@ class Codec(codecs.Codec): encode = codecs.utf_7_encode decode = codecs.utf_7_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_7_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def _buffer_decode(self, input, errors, final): + return codecs.utf_7_decode(input, self.errors) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -22,5 +30,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-7', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/utf_8.py b/Lib/encodings/utf_8.py index 9cb0b4b..1bf6336 100644 --- a/Lib/encodings/utf_8.py +++ b/Lib/encodings/utf_8.py @@ -15,6 +15,13 @@ encode = codecs.utf_8_encode def decode(input, errors='strict'): return codecs.utf_8_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_8_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = codecs.utf_8_decode + class StreamWriter(codecs.StreamWriter): encode = codecs.utf_8_encode @@ -24,5 +31,12 @@ class StreamReader(codecs.StreamReader): ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-8', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/utf_8_sig.py b/Lib/encodings/utf_8_sig.py index fa437e6..cd14ab0 100644 --- a/Lib/encodings/utf_8_sig.py +++ b/Lib/encodings/utf_8_sig.py @@ -22,6 +22,42 @@ def decode(input, errors='strict'): (output, consumed) = codecs.utf_8_decode(input, errors, True) return (output, consumed+prefix) +class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + codecs.IncrementalEncoder.__init__(self, errors) + self.first = True + + def encode(self, input, final=False): + if self.first: + self.first = False + return codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0] + else: + return codecs.utf_8_encode(input, errors)[0] + + def reset(self): + codecs.IncrementalEncoder.reset(self) + self.first = True + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def __init__(self, errors='strict'): + codecs.BufferedIncrementalDecoder.__init__(self, errors) + self.first = True + + def _buffer_decode(self, input, errors, final): + if self.first and codecs.BOM_UTF8.startswith(input): # might be a BOM + if len(input) < 3: + # not enough data to decide if this really is a BOM + # => try again on the next call + return (u"", 0) + (output, consumed) = codecs.utf_8_decode(input[3:], errors, final) + self.first = False + return (output, consumed+3) + return codecs.utf_8_decode(input, errors, final) + + def reset(self): + codecs.BufferedIncrementalDecoder.reset(self) + self.first = True + class StreamWriter(codecs.StreamWriter): def reset(self): codecs.StreamWriter.reset(self) @@ -53,5 +89,12 @@ class StreamReader(codecs.StreamReader): ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-8-sig', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py index a70ff9e..0877fe1 100644 --- a/Lib/encodings/uu_codec.py +++ b/Lib/encodings/uu_codec.py @@ -96,9 +96,18 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): return uu_encode(input,errors) + def decode(self,input,errors='strict'): return uu_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return uu_encode(input, errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return uu_decode(input, errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -108,5 +117,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (uu_encode,uu_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='uu', + encode=uu_encode, + decode=uu_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/encodings/zlib_codec.py b/Lib/encodings/zlib_codec.py index 9b6e4d1..2694f15 100644 --- a/Lib/encodings/zlib_codec.py +++ b/Lib/encodings/zlib_codec.py @@ -50,6 +50,16 @@ class Codec(codecs.Codec): def decode(self, input, errors='strict'): return zlib_decode(input, errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return zlib.compress(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return zlib.decompress(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -59,5 +69,12 @@ class StreamReader(Codec,codecs.StreamReader): ### encodings module API def getregentry(): - - return (zlib_encode,zlib_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='zlib', + encode=zlib_encode, + decode=zlib_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 4b2f8a6..7db0dab 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1058,13 +1058,16 @@ class Logger(Filterer): file name, line number and function name. """ f = currentframe().f_back - while 1: + rv = "(unknown file)", 0, "(unknown function)" + while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) if filename == _srcfile: f = f.f_back continue - return filename, f.f_lineno, co.co_name + rv = (filename, f.f_lineno, co.co_name) + break + return rv def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None): """ diff --git a/Lib/runpy.py b/Lib/runpy.py new file mode 100755 index 0000000..afb0098 --- /dev/null +++ b/Lib/runpy.py @@ -0,0 +1,431 @@ +"""runpy.py - locating and running Python code using the module namespace + +Provides support for locating and running Python scripts using the Python +module namespace instead of the native filesystem. + +This allows Python code to play nicely with non-filesystem based PEP 302 +importers when locating support scripts as well as when importing modules. +""" +# Written by Nick Coghlan <ncoghlan at gmail.com> +# to implement PEP 338 (Executing Modules as Scripts) + +import sys +import imp + +__all__ = [ + "run_module", +] + +try: + _get_loader = imp.get_loader +except AttributeError: + # get_loader() is not provided by the imp module, so emulate it + # as best we can using the PEP 302 import machinery exposed since + # Python 2.3. The emulation isn't perfect, but the differences + # in the way names are shadowed shouldn't matter in practice. + import os.path + import marshal # Handle compiled Python files + + # This helper is needed in order for the PEP 302 emulation to + # correctly handle compiled files + def _read_compiled_file(compiled_file): + magic = compiled_file.read(4) + if magic != imp.get_magic(): + return None + try: + compiled_file.read(4) # Skip timestamp + return marshal.load(compiled_file) + except Exception: + return None + + class _AbsoluteImporter(object): + """PEP 302 importer wrapper for top level import machinery""" + def find_module(self, mod_name, path=None): + if path is not None: + return None + try: + file, filename, mod_info = imp.find_module(mod_name) + except ImportError: + return None + suffix, mode, mod_type = mod_info + if mod_type == imp.PY_SOURCE: + loader = _SourceFileLoader(mod_name, file, + filename, mod_info) + elif mod_type == imp.PY_COMPILED: + loader = _CompiledFileLoader(mod_name, file, + filename, mod_info) + elif mod_type == imp.PKG_DIRECTORY: + loader = _PackageDirLoader(mod_name, file, + filename, mod_info) + elif mod_type == imp.C_EXTENSION: + loader = _FileSystemLoader(mod_name, file, + filename, mod_info) + else: + loader = _BasicLoader(mod_name, file, + filename, mod_info) + return loader + + + class _FileSystemImporter(object): + """PEP 302 importer wrapper for filesystem based imports""" + def __init__(self, path_item=None): + if path_item is not None: + if path_item != '' and not os.path.isdir(path_item): + raise ImportError("%s is not a directory" % path_item) + self.path_dir = path_item + else: + raise ImportError("Filesystem importer requires " + "a directory name") + + def find_module(self, mod_name, path=None): + if path is not None: + return None + path_dir = self.path_dir + if path_dir == '': + path_dir = os.getcwd() + sub_name = mod_name.rsplit(".", 1)[-1] + try: + file, filename, mod_info = imp.find_module(sub_name, + [path_dir]) + except ImportError: + return None + if not filename.startswith(path_dir): + return None + suffix, mode, mod_type = mod_info + if mod_type == imp.PY_SOURCE: + loader = _SourceFileLoader(mod_name, file, + filename, mod_info) + elif mod_type == imp.PY_COMPILED: + loader = _CompiledFileLoader(mod_name, file, + filename, mod_info) + elif mod_type == imp.PKG_DIRECTORY: + loader = _PackageDirLoader(mod_name, file, + filename, mod_info) + elif mod_type == imp.C_EXTENSION: + loader = _FileSystemLoader(mod_name, file, + filename, mod_info) + else: + loader = _BasicLoader(mod_name, file, + filename, mod_info) + return loader + + + class _BasicLoader(object): + """PEP 302 loader wrapper for top level import machinery""" + def __init__(self, mod_name, file, filename, mod_info): + self.mod_name = mod_name + self.file = file + self.filename = filename + self.mod_info = mod_info + + def _fix_name(self, mod_name): + if mod_name is None: + mod_name = self.mod_name + elif mod_name != self.mod_name: + raise ImportError("Loader for module %s cannot handle " + "module %s" % (self.mod_name, mod_name)) + return mod_name + + def load_module(self, mod_name=None): + mod_name = self._fix_name(mod_name) + mod = imp.load_module(mod_name, self.file, + self.filename, self.mod_info) + mod.__loader__ = self # for introspection + return mod + + def get_code(self, mod_name=None): + return None + + def get_source(self, mod_name=None): + return None + + def is_package(self, mod_name=None): + return False + + def close(self): + if self.file: + self.file.close() + + def __del__(self): + self.close() + + + class _FileSystemLoader(_BasicLoader): + """PEP 302 loader wrapper for filesystem based imports""" + def get_code(self, mod_name=None): + mod_name = self._fix_name(mod_name) + return self._get_code(mod_name) + + def get_data(self, pathname): + return open(pathname, "rb").read() + + def get_filename(self, mod_name=None): + mod_name = self._fix_name(mod_name) + return self._get_filename(mod_name) + + def get_source(self, mod_name=None): + mod_name = self._fix_name(mod_name) + return self._get_source(mod_name) + + def is_package(self, mod_name=None): + mod_name = self._fix_name(mod_name) + return self._is_package(mod_name) + + def _get_code(self, mod_name): + return None + + def _get_filename(self, mod_name): + return self.filename + + def _get_source(self, mod_name): + return None + + def _is_package(self, mod_name): + return False + + class _PackageDirLoader(_FileSystemLoader): + """PEP 302 loader wrapper for PKG_DIRECTORY directories""" + def _is_package(self, mod_name): + return True + + + class _SourceFileLoader(_FileSystemLoader): + """PEP 302 loader wrapper for PY_SOURCE modules""" + def _get_code(self, mod_name): + return compile(self._get_source(mod_name), + self.filename, 'exec') + + def _get_source(self, mod_name): + f = self.file + f.seek(0) + return f.read() + + + class _CompiledFileLoader(_FileSystemLoader): + """PEP 302 loader wrapper for PY_COMPILED modules""" + def _get_code(self, mod_name): + f = self.file + f.seek(0) + return _read_compiled_file(f) + + + def _get_importer(path_item): + """Retrieve a PEP 302 importer for the given path item + + The returned importer is cached in sys.path_importer_cache + if it was newly created by a path hook. + + If there is no importer, a wrapper around the basic import + machinery is returned. This wrapper is never inserted into + the importer cache (None is inserted instead). + + The cache (or part of it) can be cleared manually if a + rescan of sys.path_hooks is necessary. + """ + try: + importer = sys.path_importer_cache[path_item] + except KeyError: + for path_hook in sys.path_hooks: + try: + importer = path_hook(path_item) + break + except ImportError: + pass + else: + importer = None + sys.path_importer_cache[path_item] = importer + if importer is None: + try: + importer = _FileSystemImporter(path_item) + except ImportError: + pass + return importer + + + def _get_path_loader(mod_name, path=None): + """Retrieve a PEP 302 loader using a path importer""" + if path is None: + path = sys.path + absolute_loader = _AbsoluteImporter().find_module(mod_name) + if isinstance(absolute_loader, _FileSystemLoader): + # Found in filesystem, so scan path hooks + # before accepting this one as the right one + loader = None + else: + # Not found in filesystem, so use top-level loader + loader = absolute_loader + else: + loader = absolute_loader = None + if loader is None: + for path_item in path: + importer = _get_importer(path_item) + if importer is not None: + loader = importer.find_module(mod_name) + if loader is not None: + # Found a loader for our module + break + else: + # No path hook found, so accept the top level loader + loader = absolute_loader + return loader + + def _get_package(pkg_name): + """Retrieve a named package""" + pkg = __import__(pkg_name) + sub_pkg_names = pkg_name.split(".") + for sub_pkg in sub_pkg_names[1:]: + pkg = getattr(pkg, sub_pkg) + return pkg + + def _get_loader(mod_name, path=None): + """Retrieve a PEP 302 loader for the given module or package + + If the module or package is accessible via the normal import + mechanism, a wrapper around the relevant part of that machinery + is returned. + + Non PEP 302 mechanisms (e.g. the Windows registry) used by the + standard import machinery to find files in alternative locations + are partially supported, but are searched AFTER sys.path. Normally, + these locations are searched BEFORE sys.path, preventing sys.path + entries from shadowing them. + For this to cause a visible difference in behaviour, there must + be a module or package name that is accessible via both sys.path + and one of the non PEP 302 file system mechanisms. In this case, + the emulation will find the former version, while the builtin + import mechanism will find the latter. + Items of the following types can be affected by this discrepancy: + imp.C_EXTENSION + imp.PY_SOURCE + imp.PY_COMPILED + imp.PKG_DIRECTORY + """ + try: + loader = sys.modules[mod_name].__loader__ + except (KeyError, AttributeError): + loader = None + if loader is None: + imp.acquire_lock() + try: + # Module not in sys.modules, or uses an unhooked loader + parts = mod_name.rsplit(".", 1) + if len(parts) == 2: + # Sub package, so use parent package's path + pkg_name, sub_name = parts + if pkg_name and pkg_name[0] != '.': + if path is not None: + raise ImportError("Path argument must be None " + "for a dotted module name") + pkg = _get_package(pkg_name) + try: + path = pkg.__path__ + except AttributeError: + raise ImportError(pkg_name + + " is not a package") + else: + raise ImportError("Relative import syntax is not " + "supported by _get_loader()") + else: + # Top level module, so stick with default path + sub_name = mod_name + + for importer in sys.meta_path: + loader = importer.find_module(mod_name, path) + if loader is not None: + # Found a metahook to handle the module + break + else: + # Handling via the standard path mechanism + loader = _get_path_loader(mod_name, path) + finally: + imp.release_lock() + return loader + + +# This helper is needed due to a missing component in the PEP 302 +# loader protocol (specifically, "get_filename" is non-standard) +def _get_filename(loader, mod_name): + try: + get_filename = loader.get_filename + except AttributeError: + return None + else: + return get_filename(mod_name) + +# ------------------------------------------------------------ +# Done with the import machinery emulation, on with the code! + +def _run_code(code, run_globals, init_globals, + mod_name, mod_fname, mod_loader): + """Helper for _run_module_code""" + if init_globals is not None: + run_globals.update(init_globals) + run_globals.update(__name__ = mod_name, + __file__ = mod_fname, + __loader__ = mod_loader) + exec code in run_globals + return run_globals + +def _run_module_code(code, init_globals=None, + mod_name=None, mod_fname=None, + mod_loader=None, alter_sys=False): + """Helper for run_module""" + # Set up the top level namespace dictionary + if alter_sys: + # Modify sys.argv[0] and sys.module[mod_name] + temp_module = imp.new_module(mod_name) + mod_globals = temp_module.__dict__ + saved_argv0 = sys.argv[0] + restore_module = mod_name in sys.modules + if restore_module: + saved_module = sys.modules[mod_name] + imp.acquire_lock() + try: + sys.argv[0] = mod_fname + sys.modules[mod_name] = temp_module + try: + _run_code(code, mod_globals, init_globals, + mod_name, mod_fname, mod_loader) + finally: + sys.argv[0] = saved_argv0 + if restore_module: + sys.modules[mod_name] = saved_module + else: + del sys.modules[mod_name] + finally: + imp.release_lock() + # Copy the globals of the temporary module, as they + # may be cleared when the temporary module goes away + return mod_globals.copy() + else: + # Leave the sys module alone + return _run_code(code, {}, init_globals, + mod_name, mod_fname, mod_loader) + + +def run_module(mod_name, init_globals=None, + run_name=None, alter_sys=False): + """Execute a module's code without importing it + + Returns the resulting top level namespace dictionary + """ + loader = _get_loader(mod_name) + if loader is None: + raise ImportError("No module named " + mod_name) + code = loader.get_code(mod_name) + if code is None: + raise ImportError("No code object available for " + mod_name) + filename = _get_filename(loader, mod_name) + if run_name is None: + run_name = mod_name + return _run_module_code(code, init_globals, run_name, + filename, loader, alter_sys) + + +if __name__ == "__main__": + # Run the module specified as the next command line argument + if len(sys.argv) < 2: + print >> sys.stderr, "No module specified for execution" + else: + del sys.argv[0] # Make the requested module sys.argv[0] + run_module(sys.argv[0], run_name="__main__", alter_sys=True) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index b4c229a..b850912 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -1136,9 +1136,6 @@ class _ExpectedSkips: s = _expectations[sys.platform] self.expected = set(s.split()) - # this isn't a regularly run unit test, it is always skipped - self.expected.add('test_hashlib_speed') - if not os.path.supports_unicode_filenames: self.expected.add('test_pep277') diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index c61f7cc..cc3367f 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -75,6 +75,13 @@ class TestGenericStringIO(unittest.TestCase): f.close() self.assertEqual(f.closed, True) + def test_isatty(self): + f = self.MODULE.StringIO() + self.assertRaises(TypeError, f.isatty, None) + self.assertEqual(f.isatty(), False) + f.close() + self.assertRaises(ValueError, f.isatty) + def test_iterator(self): eq = self.assertEqual unless = self.failUnless @@ -87,6 +94,8 @@ class TestGenericStringIO(unittest.TestCase): eq(line, self._line + '\n') i += 1 eq(i, 5) + self._fp.close() + self.assertRaises(ValueError, self._fp.next) class TestStringIO(TestGenericStringIO): MODULE = StringIO diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index 7bf5314..74a9cdf 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -5,8 +5,6 @@ from test.test_support import verify, verbose import sys import warnings -warnings.filterwarnings("ignore", ".* 'pre' .*", DeprecationWarning, - r'pre$') warnings.filterwarnings("ignore", ".* regsub .*", DeprecationWarning, r'^regsub$') warnings.filterwarnings("ignore", @@ -122,7 +120,6 @@ class AllTest(unittest.TestCase): self.check_all("poplib") self.check_all("posixpath") self.check_all("pprint") - self.check_all("pre") # deprecated self.check_all("profile") self.check_all("pstats") self.check_all("pty") diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 3944d65..913aa91 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -41,6 +41,33 @@ class ReadTest(unittest.TestCase): self.assertEqual(r.bytebuffer, "") self.assertEqual(r.charbuffer, u"") + # do the check again, this time using a incremental decoder + d = codecs.getincrementaldecoder(self.encoding)() + result = u"" + for (c, partialresult) in zip(input.encode(self.encoding), partialresults): + result += d.decode(c) + self.assertEqual(result, partialresult) + # check that there's nothing left in the buffers + self.assertEqual(d.decode("", True), u"") + self.assertEqual(d.buffer, "") + + # Check whether the rest method works properly + d.reset() + result = u"" + for (c, partialresult) in zip(input.encode(self.encoding), partialresults): + result += d.decode(c) + self.assertEqual(result, partialresult) + # check that there's nothing left in the buffers + self.assertEqual(d.decode("", True), u"") + self.assertEqual(d.buffer, "") + + # check iterdecode() + encoded = input.encode(self.encoding) + self.assertEqual( + input, + u"".join(codecs.iterdecode(encoded, self.encoding)) + ) + def test_readline(self): def getreader(input): stream = StringIO.StringIO(input.encode(self.encoding)) @@ -977,6 +1004,12 @@ class BasicUnicodeTest(unittest.TestCase): def test_basics(self): s = u"abc123" # all codecs should be able to encode these for encoding in all_unicode_encodings: + name = codecs.lookup(encoding).name + if encoding.endswith("_codec"): + name += "_codec" + elif encoding == "latin_1": + name = "latin_1" + self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-")) (bytes, size) = codecs.getencoder(encoding)(s) if encoding != "unicode_internal": self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding)) @@ -999,6 +1032,30 @@ class BasicUnicodeTest(unittest.TestCase): decodedresult += reader.read() self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + # check incremental decoder/encoder and iterencode()/iterdecode() + try: + encoder = codecs.getincrementalencoder(encoding)() + except LookupError: # no IncrementalEncoder + pass + else: + # check incremental decoder/encoder + encodedresult = "" + for c in s: + encodedresult += encoder.encode(c) + decoder = codecs.getincrementaldecoder(encoding)() + decodedresult = u"" + for c in encodedresult: + decodedresult += decoder.decode(c) + self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + + # check iterencode()/iterdecode() + result = u"".join(codecs.iterdecode(codecs.iterencode(s, encoding), encoding)) + self.assertEqual(result, s, "%r != %r (encoding=%r)" % (result, s, encoding)) + + # check iterencode()/iterdecode() with empty string + result = u"".join(codecs.iterdecode(codecs.iterencode(u"", encoding), encoding)) + self.assertEqual(result, u"") + def test_seek(self): # all codecs should be able to encode these s = u"%s\n%s\n" % (100*u"abc123", 100*u"def456") diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py new file mode 100644 index 0000000..88e9900 --- /dev/null +++ b/Lib/test/test_runpy.py @@ -0,0 +1,172 @@ +# Test the runpy module +import unittest +import os +import os.path +import sys +import tempfile +from test.test_support import verbose, run_unittest +from runpy import _run_module_code, run_module + +# Set up the test code and expected results + +class RunModuleCodeTest(unittest.TestCase): + + expected_result = ["Top level assignment", "Lower level reference"] + test_source = ( + "# Check basic code execution\n" + "result = ['Top level assignment']\n" + "def f():\n" + " result.append('Lower level reference')\n" + "f()\n" + "# Check the sys module\n" + "import sys\n" + "run_argv0 = sys.argv[0]\n" + "if __name__ in sys.modules:\n" + " run_name = sys.modules[__name__].__name__\n" + "# Check nested operation\n" + "import runpy\n" + "nested = runpy._run_module_code('x=1\\n', mod_name='<run>',\n" + " alter_sys=True)\n" + ) + + + def test_run_module_code(self): + initial = object() + name = "<Nonsense>" + file = "Some other nonsense" + loader = "Now you're just being silly" + d1 = dict(initial=initial) + saved_argv0 = sys.argv[0] + d2 = _run_module_code(self.test_source, + d1, + name, + file, + loader, + True) + self.failUnless("result" not in d1) + self.failUnless(d2["initial"] is initial) + self.failUnless(d2["result"] == self.expected_result) + self.failUnless(d2["nested"]["x"] == 1) + self.failUnless(d2["__name__"] is name) + self.failUnless(d2["run_name"] is name) + self.failUnless(d2["__file__"] is file) + self.failUnless(d2["run_argv0"] is file) + self.failUnless(d2["__loader__"] is loader) + self.failUnless(sys.argv[0] is saved_argv0) + self.failUnless(name not in sys.modules) + + def test_run_module_code_defaults(self): + saved_argv0 = sys.argv[0] + d = _run_module_code(self.test_source) + self.failUnless(d["result"] == self.expected_result) + self.failUnless(d["__name__"] is None) + self.failUnless(d["__file__"] is None) + self.failUnless(d["__loader__"] is None) + self.failUnless(d["run_argv0"] is saved_argv0) + self.failUnless("run_name" not in d) + self.failUnless(sys.argv[0] is saved_argv0) + +class RunModuleTest(unittest.TestCase): + + def expect_import_error(self, mod_name): + try: + run_module(mod_name) + except ImportError: + pass + else: + self.fail("Expected import error for " + mod_name) + + def test_invalid_names(self): + self.expect_import_error("sys") + self.expect_import_error("sys.imp.eric") + self.expect_import_error("os.path.half") + self.expect_import_error("a.bee") + self.expect_import_error(".howard") + self.expect_import_error("..eaten") + + def test_library_module(self): + run_module("runpy") + + def _make_pkg(self, source, depth): + pkg_name = "__runpy_pkg__" + init_fname = "__init__"+os.extsep+"py" + test_fname = "runpy_test"+os.extsep+"py" + pkg_dir = sub_dir = tempfile.mkdtemp() + if verbose: print " Package tree in:", sub_dir + sys.path.insert(0, pkg_dir) + if verbose: print " Updated sys.path:", sys.path[0] + for i in range(depth): + sub_dir = os.path.join(sub_dir, pkg_name) + os.mkdir(sub_dir) + if verbose: print " Next level in:", sub_dir + pkg_fname = os.path.join(sub_dir, init_fname) + pkg_file = open(pkg_fname, "w") + pkg_file.close() + if verbose: print " Created:", pkg_fname + mod_fname = os.path.join(sub_dir, test_fname) + mod_file = open(mod_fname, "w") + mod_file.write(source) + mod_file.close() + if verbose: print " Created:", mod_fname + mod_name = (pkg_name+".")*depth + "runpy_test" + return pkg_dir, mod_fname, mod_name + + def _del_pkg(self, top, depth, mod_name): + for i in range(depth+1): # Don't forget the module itself + parts = mod_name.rsplit(".", i) + entry = parts[0] + try: + del sys.modules[entry] + except KeyError, ex: + if verbose: print ex # Persist with cleaning up + if verbose: print " Removed sys.modules entries" + del sys.path[0] + if verbose: print " Removed sys.path entry" + for root, dirs, files in os.walk(top, topdown=False): + for name in files: + try: + os.remove(os.path.join(root, name)) + except OSError, ex: + if verbose: print ex # Persist with cleaning up + for name in dirs: + fullname = os.path.join(root, name) + try: + os.rmdir(fullname) + except OSError, ex: + if verbose: print ex # Persist with cleaning up + try: + os.rmdir(top) + if verbose: print " Removed package tree" + except OSError, ex: + if verbose: print ex # Persist with cleaning up + + def _check_module(self, depth): + pkg_dir, mod_fname, mod_name = ( + self._make_pkg("x=1\n", depth)) + try: + if verbose: print "Running from source:", mod_name + d1 = run_module(mod_name) # Read from source + self.failUnless(d1["x"] == 1) + del d1 # Ensure __loader__ entry doesn't keep file open + __import__(mod_name) + os.remove(mod_fname) + if verbose: print "Running from compiled:", mod_name + d2 = run_module(mod_name) # Read from bytecode + self.failUnless(d2["x"] == 1) + del d2 # Ensure __loader__ entry doesn't keep file open + finally: + self._del_pkg(pkg_dir, depth, mod_name) + if verbose: print "Module executed successfully" + + def test_run_module(self): + for depth in range(4): + if verbose: print "Testing package depth:", depth + self._check_module(depth) + + +def test_main(): + run_unittest(RunModuleCodeTest) + run_unittest(RunModuleTest) + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_hashlib_speed.py b/Lib/test/time_hashlib.py index c84a62b..1bf707d 100644 --- a/Lib/test/test_hashlib_speed.py +++ b/Lib/test/time_hashlib.py @@ -1,15 +1,14 @@ +# It's intended that this script be run by hand. It runs speed tests on +# hashlib functions; it does not test for correctness. import sys, time import hashlib -from test import test_support def creatorFunc(): raise RuntimeError, "eek, creatorFunc not overridden" - def test_scaled_msg(scale, name): - iterations = 106201/scale * 20 longStr = 'Z'*scale @@ -39,10 +38,6 @@ def test_zero(): -### this 'test' is not normally run. skip it if the test runner finds it -if __name__ != '__main__': - raise test_support.TestSkipped, "not a unit test (stand alone benchmark)" - hName = sys.argv[1] # |