[issue17878] There is no way to get a list of available codecs

Marc-Andre Lemburg report at bugs.python.org
Thu May 2 16:47:27 CEST 2013


Marc-Andre Lemburg added the comment:

On 02.05.2013 16:41, Nick Coghlan wrote:
> 
> Nick Coghlan added the comment:
> 
> This is actually similar to the problem with getting the list of modules an importer provides (that is, we don't currently have an officially defined method in the importer protocol for that, although pkgutil.iter_importer_modules implicitly looks for an "iter_modules" method, due to the old import emulation used until Python 3.2).
> 
> I see three possibilities:
> 
> 1. Use independent purpose specific protocols to get a list of entries out of these objects.
> 
> 2. Create a new, common protocol for extracting lists of entries from search hooks like importers and codec search functions
> 
> 3. Use the existing __iter__ protocol
> 
> I'm currently thinking option 3 might be a reasonable way forward. That is, if a codec search hook wants to provide a listing of available codecs, it can just define __iter__ in addition to __call__. Importers could define __iter__ in addition to the other methods in the importer API.
> 
> Thoughts?

Too obscure :-)

Let the object expose a method: .list_codecs() -> returns a list
of supported codecs as CodecInfo objects.

We may also deprecate the .__call__() in favor of:
.find_codec(encoding) -> return codec implementing encoding.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17878>
_______________________________________


More information about the Python-bugs-list mailing list