[Patches] [ python-Patches-1433198 ] restrict codec lookup to encodings package

SourceForge.net noreply at sourceforge.net
Sun Feb 19 17:04:50 CET 2006


Patches item #1433198, was opened at 2006-02-17 06:56
Message generated for change (Comment added) made by perky
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1433198&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: M.-A. Lemburg (lemburg)
Summary: restrict codec lookup to encodings package

Initial Comment:
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?

----------------------------------------------------------------------

>Comment By: Hye-Shik Chang (perky)
Date: 2006-02-20 01:04

Message:
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.


----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2006-02-20 00:23

Message:
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.


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2006-02-20 00:01

Message:
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.)

----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2006-02-18 01:16

Message:
Logged In: YES 
user_id=38388

Sorry, wrong SF item...

----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2006-02-18 01:15

Message:
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.


----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2006-02-17 20:49

Message:
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. 


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1433198&group_id=5470


More information about the Patches mailing list