[Python-Dev] Parametrized codecs

Andrew Kuchling akuchlin@mems-exchange.org
Wed, 19 Sep 2001 14:01:55 -0400


>The codec design allows extending the constructors using keyword
>arguments, however I'd rather not add a generic **kws argument
>to the base classes since this would hide errors (unknown or
>unsupported keywords, mispellings, etc.).

Isn't such an argument required at least for StreamReaderWriter,
because it actually instantiates two objects?

class StreamReaderWriter:
    def __init__(self, stream, Reader, Writer, errors='strict'):

        """ ...
            Reader, Writer must be factory functions or classes
            providing the StreamReader, StreamWriter interface resp.
        """
        self.stream = stream
        self.reader = Reader(stream, errors)
        self.writer = Writer(stream, errors)

Hmm... you'd better not need to have two different set of keyword
arguments for Reader and Writer.  Is that limitation acceptable?  If
it is, then the list of changes becomes 1) add **kw to codecs.open,
and 2) add **kw to StreamReaderWriter's constructor, and apply it to
the Reader() and Writer() calls.

>The encoder and decoder functions must work stateless.

OK, then they're not suitable for encryption (in general, though
they'd work fine for ECB mode).

--amk