[Python-checkins] python/dist/src/Lib/encodings __init__.py, 1.19, 1.20

lemburg at users.sourceforge.net lemburg at users.sourceforge.net
Tue Jan 20 04:40:16 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/encodings
In directory sc8-pr-cvs1:/tmp/cvs-serv19015

Modified Files:
	__init__.py 
Log Message:
Let the default encodings search function lookup aliases before trying the codec import. This allows applications to install codecs which override (non-special-cased) builtin codecs.

Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/encodings/__init__.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** __init__.py	16 May 2003 17:07:51 -0000	1.19
--- __init__.py	20 Jan 2004 09:40:14 -0000	1.20
***************
*** 28,32 ****
  """#"
  
! import codecs, exceptions, types
  
  _cache = {}
--- 28,32 ----
  """#"
  
! import codecs, exceptions, types, aliases
  
  _cache = {}
***************
*** 39,42 ****
--- 39,43 ----
                        '                                                '
                        '                ')
+ _aliases = aliases.aliases
  
  class CodecRegistryError(exceptions.LookupError,
***************
*** 75,95 ****
      # Import the module:
      #
!     # First look in the encodings package, then try to lookup the
!     # encoding in the aliases mapping and retry the import using the
!     # default import module lookup scheme with the alias name.
      #
!     modname = normalize_encoding(encoding)
!     try:
!         mod = __import__('encodings.' + modname,
!                          globals(), locals(), _import_tail)
!     except ImportError:
!         import aliases
!         modname = (aliases.aliases.get(modname) or
!                    aliases.aliases.get(modname.replace('.', '_')) or
!                    modname)
          try:
!             mod = __import__(modname, globals(), locals(), _import_tail)
          except ImportError:
!             mod = None
  
      try:
--- 76,104 ----
      # Import the module:
      #
!     # First try to find an alias for the normalized encoding
!     # name and lookup the module using the aliased name, then try to
!     # lookup the module using the standard import scheme, i.e. first
!     # try in the encodings package, then at top-level.
      #
!     norm_encoding = normalize_encoding(encoding)
!     aliased_encoding = _aliases.get(norm_encoding) or \
!                        _aliases.get(norm_encoding.replace('.', '_'))
!     if aliased_encoding is not None:
!         modnames = [aliased_encoding,
!                     norm_encoding]
!     else:
!         modnames = [norm_encoding]
!     for modname in modnames:
!         if not modname:
!             continue
          try:
!             mod = __import__(modname,
!                              globals(), locals(), _import_tail)
          except ImportError:
!             pass
!         else:
!             break
!     else:
!         mod = None
  
      try:
***************
*** 126,133 ****
          pass
      else:
-         import aliases
          for alias in codecaliases:
!             if not aliases.aliases.has_key(alias):
!                 aliases.aliases[alias] = modname
  
      # Return the registry entry
--- 135,141 ----
          pass
      else:
          for alias in codecaliases:
!             if not _aliases.has_key(alias):
!                 _aliases[alias] = modname
  
      # Return the registry entry





More information about the Python-checkins mailing list