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.

classification
Title: restrict codec lookup to encodings package
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: lemburg Nosy List: gvanrossum, hyeshik.chang, lemburg
Priority: normal Keywords: patch

Created on 2006-02-16 21:56 by gvanrossum, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff.txt gvanrossum, 2006-02-16 21:56 patch for encodings/__init__.py and test/test_charmapcodec.py
Messages (7)
msg49497 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-02-16 21:56
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?
msg49498 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2006-02-17 11:49
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. 
msg49499 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2006-02-17 16:15
Logged In: YES 
user_id=38388

See
http://mail.python.org/pipermail/python-dev/2006-February/061230.html
for details why I'm rejecting this patch.
msg49500 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2006-02-17 16:16
Logged In: YES 
user_id=38388

Sorry, wrong SF item...
msg49501 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-02-19 15:01
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.)
msg49502 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2006-02-19 15:23
Logged In: YES 
user_id=38388

Checked in a different fix along the lines I mentioned.

Sending        Lib/encodings/__init__.py
Sending        Lib/test/test_charmapcodec.py
Sending        Misc/NEWS
Transmitting file data ...
Committed revision 42497.
msg49503 - (view) Author: Hyeshik Chang (hyeshik.chang) * (Python committer) Date: 2006-02-19 16:04
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.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42913
2006-02-16 21:56:43gvanrossumcreate