Fix the encodings package codec search function to only search
authorMarc-André Lemburg <mal@egenix.com>
Sun, 19 Feb 2006 15:22:22 +0000 (15:22 +0000)
committerMarc-André Lemburg <mal@egenix.com>
Sun, 19 Feb 2006 15:22:22 +0000 (15:22 +0000)
inside its own package. Fixes problem reported in patch #1433198.

Add codec search function for codec test codec.

Lib/encodings/__init__.py
Lib/test/test_charmapcodec.py
Misc/NEWS

index 8a50ac13e84484cc2d3e67f31ac9e3bf5d26cd72..01463bc34c6a1eaaeff8692548e4196ee888ee35 100644 (file)
@@ -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
index 79d82c1460ed8554802e52c7941c90277ec51e2d..2866984005f99a8e6cb6486d28ef342189a2462f 100644 (file)
@@ -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):
index 078f7026f36a1e06524be087a42c81a5a2fb8236..32f6047385dec6e8aa5ec4ddf30b6fb136aaa960 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,12 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Fix the encodings package codec search function to only search
+  inside its own package. Fixes problem reported in patch #1433198.
+
+  Note: Codec packages should implement and register their own
+  codec search function. PEP 100 has the details.
+
 - PEP 353: Using ssize_t as the index type.
 
 - Patch #1400181, fix unicode string formatting to not use the locale.