This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients doerwalter, ezio.melotti, lemburg, ncoghlan, serhiy.storchaka, vstinner
Date 2013-11-22.00:51:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1385081480.53.0.0982610679856.issue19619@psf.upfronthosting.co.za>
In-reply-to
Content
> There is no "codec registry" - there is only the default codec search
function, the encodings import namespace, the normalisation algorithm
and the alias dictionary.

interp->codec_search_cache can be seen as the "registry". If you store codecs in two different registries depending a property, attribute, whatever; you keep O(1) complexity (bo extra strcmp or getting an attribute at each lookup). The overhead is only when you load a codec for the first time.

It should not be so hard to add a second dictionary.

You don't need to touch all parts of the codecs machinery, only interp->codec_search_cache.

It would not be possible to have the name in the two registries. So codecs.lookup() would still return any kind of codecs, it would just lookup in two dictionaries instead of one. So codecs.encode/decode would be unchanged too (if you want to keep these functions ;-)).

Only bytes.decode/str.encode would be modified to only lookup in the "text codecs" only registry.


Yet another option: add a new dictionary, but leave interp->codec_search_cache unchanged. Text codecs would also be registered twice: once in interp->codec_search_cache, once in the second dictionary. So bytes.decode/str.encode would only lookup in the text codecs dictionary, instead of interp->codec_search_cache. That's all ;-)


> Victor pointed out this should now raise LookupError rather than TypeError.

If you accept to raise a LookupError, the "two registries" option may become more obvious, isn't it?
History
Date User Action Args
2013-11-22 00:51:20vstinnersetrecipients: + vstinner, lemburg, doerwalter, ncoghlan, ezio.melotti, serhiy.storchaka
2013-11-22 00:51:20vstinnersetmessageid: <1385081480.53.0.0982610679856.issue19619@psf.upfronthosting.co.za>
2013-11-22 00:51:20vstinnerlinkissue19619 messages
2013-11-22 00:51:20vstinnercreate