Changing codec lookup order. (was: Re: [Python-Dev] Re: [Python-checkins] python/dist/src/Lib/email/test test_email_codecs.py, 1.4, 1.5) (original) (raw)

Hye-Shik Chang perky at i18n.org
Sun Jan 18 17:01:08 EST 2004


On Sun, Jan 18, 2004 at 10:24:12PM +0100, "Martin v. L?wis" wrote:

I also find that installing JapaneseCodecs on top of a CJK-enabled Python 2.4 causes shiftjis to use the CJK codec, not the japanese codec.

Aah. We need to change codec lookup order of encodings.search_function to enable to override default codec by 3rd party one. With attached patch, I could get JapaneseCodecs's one.

Now, I admit that CJK codecs are obviously un-backportable to 2.3 due to this change. ;-)

Hye-Shik -------------- next part -------------- *** init.py.orig Mon Jan 19 06:49:27 2004 --- init.py Mon Jan 19 06:46:16 2004


*** 28,33 **** --- 28,34 ---- """#"

import codecs, exceptions, types


*** 74,96 ****

  # 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:
      getregentry = mod.getregentry

--- 75,97 ----

  # Import the module:
  #

! # First lookup the encoding in the aliases mapping and try the ! # import using the default import module lookup scheme with the ! # alias name if available. Then look in the encodings package. # modname = normalize_encoding(encoding) ! modnamestry = ['encodings.' + modname] ! aliasedname = (aliases.aliases.get(modname) or ! aliases.aliases.get(modname.replace('.', '_'))) ! if aliasedname is not None: ! modnamestry.insert(0, aliasedname) ! for mn in modnamestry: try: ! mod = import(mn, globals(), locals(), _import_tail) except ImportError: mod = None


*** 125,131 **** except AttributeError: pass else:

--- 126,131 ----



More information about the Python-Dev mailing list