[Python-Dev] Parametrized codecs
Andrew Kuchling
akuchlin@mems-exchange.org
Tue, 18 Sep 2001 16:17:29 -0400
Are there any codecs that can take parameters at initialization time?
If not, how about supporting them? Here's a motivating example:
import codecs
f = codecs.open('output', 'wb', encoding='DES', # arguments to open()
key = '...', mode = DES.ECB)
f.write('This will be encrypted\n')
f.close()
For this to work, you'd need a few changes to codecs.py. Off the top
of my head, I think StreamReader, StreamWriter, and StreamReaderWriter
all need to grow **kwargs arguments for any additional arguments, as
do codecs.open() and codecs.lookup().
Then someone could write a DES StreamReader/Streamwriter that took a
key and feedback mode at creation time. (codecs.Codec instances are
supposed to be stateless, right?)
--amk