summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/__init__.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2006-03-15 11:35:15 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2006-03-15 11:35:15 (GMT)
commitabb02e59946f9ea3076e96e3b03b51d1cebd46b4 (patch)
tree165444acd89173a8832547078cbc417d4626116e /Lib/encodings/__init__.py
parente2ebb2d7f777db2de72cfeb0e3c489ac4cc5c400 (diff)
downloadcpython-abb02e59946f9ea3076e96e3b03b51d1cebd46b4.zip
cpython-abb02e59946f9ea3076e96e3b03b51d1cebd46b4.tar.gz
cpython-abb02e59946f9ea3076e96e3b03b51d1cebd46b4.tar.bz2
Patch #1436130: codecs.lookup() now returns a CodecInfo object (a subclass
of tuple) that provides incremental decoders and encoders (a way to use stateful codecs without the stream API). Functions codecs.getincrementaldecoder() and codecs.getincrementalencoder() have been added.
Diffstat (limited to 'Lib/encodings/__init__.py')
-rw-r--r--Lib/encodings/__init__.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py
index ddaacb9..f8d2a2a 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,\
+ '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__)
+ '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