From abb02e59946f9ea3076e96e3b03b51d1cebd46b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Wed, 15 Mar 2006 11:35:15 +0000 Subject: 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. --- Lib/encodings/quopri_codec.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'Lib/encodings/quopri_codec.py') diff --git a/Lib/encodings/quopri_codec.py b/Lib/encodings/quopri_codec.py index d98b5ed04b..b802ae62d2 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, + ) -- cgit v1.2.1