On 29.08.2014 09:49, Nick Coghlan wrote:
On 29 August 2014 17:33, 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.
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__
It's fairly easy to have the lookup function in the encodings package to also look in say a "siteencodings" package for codecs it cannot find in the stdlib encodings package. This new siteencodings package could then be setup as namespace package to make installation easier. That doesn't answer the original question, though, since introspection of available codecs would still not be possible.
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-en...
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.
Here's one idea: don't use a table, but instead have one subsection per codec. There are already a few subsections for specific codecs on the page.
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).
Since it's not a feature, the doc change could potentially be backported. -- 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/