diff options
author | Marc-André Lemburg <mal@egenix.com> | 2006-02-19 15:22:22 +0000 |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2006-02-19 15:22:22 +0000 |
commit | e4bdd7d89f4bbe6e4450d5db156a78939aa735f2 (patch) | |
tree | 95b9f06f6701128562bca960bffe18511bce846b /Lib | |
parent | e06d5e7f6bc92052d97e59ee98ca7df9b397dac8 (diff) | |
download | cpython-e4bdd7d89f4bbe6e4450d5db156a78939aa735f2.tar.gz |
Fix the encodings package codec search function to only search
inside its own package. Fixes problem reported in patch #1433198.
Add codec search function for codec test codec.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/encodings/__init__.py | 2 | ||||
-rw-r--r-- | Lib/test/test_charmapcodec.py | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index 8a50ac13e8..01463bc34c 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -91,7 +91,7 @@ def search_function(encoding): if not modname: continue try: - mod = __import__(modname, + mod = __import__('encodings.' + modname, globals(), locals(), _import_tail) except ImportError: pass diff --git a/Lib/test/test_charmapcodec.py b/Lib/test/test_charmapcodec.py index 79d82c1460..2866984005 100644 --- a/Lib/test/test_charmapcodec.py +++ b/Lib/test/test_charmapcodec.py @@ -11,8 +11,19 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). import test.test_support, unittest -# test codec's full path name (see test/testcodec.py) -codecname = 'test.testcodec' +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' class CharmapCodecTest(unittest.TestCase): def test_constructorx(self): |