[Python-Dev] Codecs and StreamCodecs

Greg Stein gstein@lyra.org
Tue, 16 Nov 1999 18:29:42 -0800 (PST)


On Tue, 16 Nov 1999, Fred L. Drake, Jr. wrote:
> M.-A. Lemburg writes:
>  > Wouldn't it be possible to have the read/write methods set up
>  > the state when called for the first time ?
> 
>   That slows the down; the constructor should handle initialization.
> Perhaps what gets registered should be:  encoding function, decoding
> function, stream encoder factory (can be a class), stream decoder
> factory (again, can be a class).  These can be encapsulated either
> before or after hitting the registry, and can be None.  The registry

I'm with Fred here; he beat me to the punch (and his email is better than 
what I'd write anyhow :-).

I'd like to see the API be *functions* rather than a particular class
specification. If the spec is going to say "do not alter/store state",
then a function makes much more sense than a method on an object.

Of course, bound method objects could be registered. This might occur if
you have a general JIS encode/decoder but need to instantiate it a little
differently for each JIS variant.
(Andy also mentioned something about "options" in JIS encoding/decoding)

> and provide default implementations from what is provided (stream
> handlers from the functions, or functions from the stream handlers) as 
> required.

Excellent idea...

"I'll provide the encode/decode functions, but I don't have a spiffy
algorithm for streaming -- please provide a stream wrapper for my
functions."

>   Ideally, I should be able to write a module with four well-known
> entry points and then provide the module object itself as the
> registration entry.  Or I could construct a new object that has the
> right interface and register that if it made more sense for the
> encoding.

Mark's idea about throwing these things into a package for on-demand
registrations is much better than a "register-beforehand" model. When the
module is loaded from the package, it calls a registration function to
insert its 4-tuple of registration data.

Cheers,
-g

--
Greg Stein, http://www.lyra.org/