Here's a fix for the problem recently mentioned on python-dev, where encoding names are looked up everywhere instead of just in the encodings package. It was slightly more work than I anticipated because there was a unit test that depended on the broken behavior. I've fixed the unittest with a hack that temporarily extends the encodings package's __path__ with sys.path, so that the test package will appear as a subpackage of the encodings package. That's not very clean; an alternative would be to patch sys.modules (but then less of the codec import machinery is exercised by the unit test) or to move the test codec to the encodings package (but that places some test code in a production package). What would you prefer?
Logged In: YES user_id=38388 Hmm, I think the right way would be to register a codec search function for the test codec rather than tweaking the encodings package to implement the old behavior again. This creates a precedent which others might follow to quickly get their code working again which would defeat the purpose of the whole patch: import codecs # Register a search function which knows about our codec def codec_search_function(encoding): if encoding == 'testcodec': from test import testcodec return tuple(testcodec.getregentry()) return None codecs.register(codec_search_function) # test codec's name (see test/testcodec.py) codecname = 'testcodec' Please also add a note to the NEWS file that we've changed the default codec lookup procedure in the encodings package search file.
Logged In: YES user_id=6380 OK, so can this patch be applied or not? What are the consequences for the CJK codecs etc.? Please apply it yourself if the anwer is yes. (Don't backport yet.)
Logged In: YES user_id=55188 CJK codecs in CPython are okay. And iconvcodec has no problem either because it registers its own lookup function. But this will hurt JapaneseCodecs and independent installation of CJKCodecs. And, I know some applications that utilize the previous behavior of search_function. So backport is impossible.