[Python-ideas] Query available codecs and error handlers
M.-A. Lemburg
mal at egenix.com
Fri Aug 29 10:30:55 CEST 2014
On 29.08.2014 10:16, Steven D'Aprano wrote:
> On Fri, Aug 29, 2014 at 09:33:47AM +0200, M.-A. Lemburg wrote:
>> On 29.08.2014 07:45, Steven D'Aprano wrote:
>>> Unless I am badly misinformed, there is no way to programmatically check
>>> what codecs and error handlers are available. I propose two functions in
>>> the codecs module:
>>>
>>> get_codecs()
>>> get_error_handlers()
>>>
>>> which each return a set of the available codec, or error handler, names.
>>
>> Question is: how would you implement these ?
>>
>> The codec registry uses lookup functions to find codecs, so we'd
>> have to extend those lookup functions to also support reporting
>> known installed codecs.
>
> Arrgggh, you're right -- I've been working on a wrong assumption. I had
> forgotten that the codecs.register function takes a function, not a
> name.
>
> I always forgot that, because it's such a strange and unhelpful API
> compared to, say, a mapping of name:codec. It's probably water under the
> bridge now, but is there any documentation for why this API was used in
> the first place?
Because at the time I designed the API in 1999/2000 it wasn't
clear how people would start writing codecs.
Note that codecs do not use a simple name to codec mapping to
figure out the implementation module name. The name typically
goes through a few layers of normalization and then a alias
dictionary to find the name of the implementation.
The lookup functions were meant to implement these more complex
n-1 mappings.
I also thought that codec implementation might want to tap
into system registries of codecs, use file based tables
as basis for encodings, or even implement load on demand.
Today, it's rather obvious that apparently no one has considered
doing any of this, so it would have been better to design a system
where you explicitly register individual codecs (together
with a set of attributes).
It should be possible to phase out the lookup API and expose
the encodings package lookup mechanism directly in the codecs
module. I can help guide people, if they are willing to do the
work, but don't have time to work on this myself.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Aug 29 2014)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2014-08-27: Released eGenix PyRun 2.0.1 ... http://egenix.com/go62
2014-09-19: PyCon UK 2014, Coventry, UK ... 21 days to go
2014-09-27: PyDDF Sprint 2014 ... 29 days to go
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list