diff options
Diffstat (limited to 'Lib/encodings/__init__.py')
-rw-r--r-- | Lib/encodings/__init__.py | 31 |
1 files changed, 20 insertions, 11 deletions
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 |