[Python-checkins] CVS: python/dist/src/Lib/encodings __init__.py,1.4,1.5

M.-A. Lemburg python-dev@python.org
Tue, 12 Dec 2000 06:45:37 -0800


Update of /cvsroot/python/python/dist/src/Lib/encodings
In directory slayer.i.sourceforge.net:/tmp/cvs-serv25240

Modified Files:
	__init__.py 
Log Message:
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.

Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/encodings/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** __init__.py	2000/06/13 12:04:05	1.4
--- __init__.py	2000/12/12 14:45:35	1.5
***************
*** 19,25 ****
      * getaliases() -> sequence of encoding name strings to use as aliases
  
!     Alias names returned by getaliases() must be lower-case.
  
- 
  Written by Marc-Andre Lemburg (mal@lemburg.com).
  
--- 19,26 ----
      * getaliases() -> sequence of encoding name strings to use as aliases
  
!     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).
  
***************
*** 46,49 ****
--- 47,51 ----
          mod = __import__(modname,globals(),locals(),'*')
      except ImportError,why:
+         # cache misses
          _cache[encoding] = None
          return None
***************
*** 64,69 ****
                    (__name__,modname)
  
!     # Cache the encoding and its aliases
      _cache[encoding] = entry
      try:
          codecaliases = mod.getaliases()
--- 66,74 ----
                    (__name__,modname)
  
!     # Cache the codec registry entry
      _cache[encoding] = entry
+ 
+     # Register its aliases (without overwriting previously registered
+     # aliases)
      try:
          codecaliases = mod.getaliases()
***************
*** 72,76 ****
      else:
          for alias in codecaliases:
!             _cache[alias] = entry
      return entry
  
--- 77,84 ----
      else:
          for alias in codecaliases:
!             if not aliases.aliases.has_key(alias):
!                 aliases.aliases[alias] = modname
! 
!     # Return the registry entry
      return entry