Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe4b34c

Browse files
committed
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.
1 parent c3e950c commit fe4b34c

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

Lib/encodings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def search_function(encoding):
9191
if not modname:
9292
continue
9393
try:
94-
mod = __import__(modname,
94+
mod = __import__('encodings.' + modname,
9595
globals(), locals(), _import_tail)
9696
except ImportError:
9797
pass

Lib/test/test_charmapcodec.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@
1111

1212
import test.test_support, unittest
1313

14-
# test codec's full path name (see test/testcodec.py)
15-
codecname = 'test.testcodec'
14+
import codecs
15+
16+
# Register a search function which knows about our codec
17+
def codec_search_function(encoding):
18+
if encoding == 'testcodec':
19+
from test import testcodec
20+
return tuple(testcodec.getregentry())
21+
return None
22+
23+
codecs.register(codec_search_function)
24+
25+
# test codec's name (see test/testcodec.py)
26+
codecname = 'testcodec'
1627

1728
class CharmapCodecTest(unittest.TestCase):
1829
def test_constructorx(self):

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ What's New in Python 2.5 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Fix the encodings package codec search function to only search
16+
inside its own package. Fixes problem reported in patch #1433198.
17+
18+
Note: Codec packages should implement and register their own
19+
codec search function. PEP 100 has the details.
20+
1521
- PEP 353: Using ssize_t as the index type.
1622

1723
- Patch #1400181, fix unicode string formatting to not use the locale.

0 commit comments

Comments
 (0)