A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2001-September/017562.html below:

[Python-Dev] Parametrized codecs

[Python-Dev] Parametrized codecsM.-A. Lemburg mal@lemburg.com
Wed, 19 Sep 2001 13:01:39 +0200
Andrew Kuchling wrote:
> 
> Are there any codecs that can take parameters at initialization time?
> If not, how about supporting them? 

Even though this is not documented in the Unicode PEP, the 
extensibility of the constructor using extra (keyword) arguments is 
intended.

> 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().

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.).

The codec.open() API is different though: it could grow a
**kws argument which is then apply()ed to the codec constructor.
The constructor will then raise any exceptions related to 
malformed keyword parameters.
 
There's no need to add **kws to codec.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?)

The encoder and decoder functions must work stateless.
StreamReader/Writer instances should be used for everything 
that has to do with state since these are instantiatied per use
whereas encoder and decoder functions fetched using codec.lookup()
can be used multiple times.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4