[Python-ideas] Query available codecs and error handlers

Nick Coghlan ncoghlan at gmail.com
Fri Aug 29 09:49:07 CEST 2014


On 29 August 2014 17:33, M.-A. Lemburg <mal at egenix.com> 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.

I'd actually be a fan of a PEP to add such an introspection API that
also made it easier to register new codecs just by adding them to a
suitable namespace package. I believe MvL's original idea was to use
the existing encodings package for that, but that doesn't seem
feasible due to the non-empty __init__

> For the stdlib encodings package we could simply put a list into
> the package, e.g. encodings.available_codecs returning a dictionary
> of mappings from codec name to CodecInfo tuples and then extend
> the CodecInfo with some extra information such as supported
> error handlers, alternative names and information about the
> supported input/output types.
>
> At the moment, the available codecs are documented here:
>
> https://docs.python.org/3.5/library/codecs.html?highlight=codecs#standard-encodings
>
> It's probably a good idea to add information about supported
> error handlers to that list.

Those tables are already pretty busy though - I'm not sure how we
could add supported error handler details without making them hard to
read.

Agreed it would be good to make the info more readily available,
though (I had actually hoped to get some proposed revisions together
for the codecs module docs before 3.4 went out the door, but alas, it
was not to be).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list