summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/__init__.py
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2000-12-12 14:45:35 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2000-12-12 14:45:35 (GMT)
commit988ad2bdff836665f004c285fb09182c35775fd6 (patch)
tree3ad1622183cc8b6f49e7e91794fb68b0ca4eef94 /Lib/encodings/__init__.py
parent5fa0bd64a8cda3286c1c82f25c643391051a3f90 (diff)
downloadcpython-988ad2bdff836665f004c285fb09182c35775fd6.zip
cpython-988ad2bdff836665f004c285fb09182c35775fd6.tar.gz
cpython-988ad2bdff836665f004c285fb09182c35775fd6.tar.bz2
Changed .getaliases() support to register the new aliases in the
encodings package aliases mapping dictionary rather than in the internal cache used by the search function. This enables aliases to take advantage of the full normalization process applied to encoding names which was previously not available. The patch restricts alias registration to new aliases. Existing aliases cannot be overridden anymore.
Diffstat (limited to 'Lib/encodings/__init__.py')
-rw-r--r--Lib/encodings/__init__.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py
index 8df9020..51ec873 100644
--- a/Lib/encodings/__init__.py
+++ b/Lib/encodings/__init__.py
@@ -18,8 +18,9 @@
* getaliases() -> sequence of encoding name strings to use as aliases
- Alias names returned by getaliases() must be lower-case.
-
+ Alias names returned by getaliases() must be standard encoding
+ names as defined above (lower-case, hyphens converted to
+ underscores).
Written by Marc-Andre Lemburg (mal@lemburg.com).
@@ -45,6 +46,7 @@ def search_function(encoding):
try:
mod = __import__(modname,globals(),locals(),'*')
except ImportError,why:
+ # cache misses
_cache[encoding] = None
return None
@@ -63,15 +65,21 @@ def search_function(encoding):
'incompatible codecs in module "%s.%s"' % \
(__name__,modname)
- # Cache the encoding and its aliases
+ # Cache the codec registry entry
_cache[encoding] = entry
+
+ # Register its aliases (without overwriting previously registered
+ # aliases)
try:
codecaliases = mod.getaliases()
except AttributeError:
pass
else:
for alias in codecaliases:
- _cache[alias] = entry
+ if not aliases.aliases.has_key(alias):
+ aliases.aliases[alias] = modname
+
+ # Return the registry entry
return entry
# Register the search_function in the Python codec registry