Patch #1436130: codecs.lookup() now returns a CodecInfo object (a subclass
of tuple) that provides incremental decoders and encoders (a way to use
stateful codecs without the stream API). Functions
codecs.getincrementaldecoder() and codecs.getincrementalencoder() have
been added.
diff --git a/Lib/encodings/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 @@
     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 @@
 ### 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,
+    )