[I18n-sig] codec aliases

M.-A. Lemburg mal@lemburg.com
Mon, 11 Dec 2000 23:55:59 +0100


Tamito KAJIYAMA wrote:
> 
> Hi all,
> 
> I'm implementing a modularized version of my Japanese codecs
> following Marc-Andre's proposal, and am having two problems
> regarding to codec aliases.
> 
> >>> import codecs
> >>> funcs = codecs.lookup("japanese.jis-7")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> LookupError: unknown encoding
> >>> funcs = codecs.lookup("japanese.jis_7")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> LookupError: unknown encoding
> >>> funcs = codecs.lookup("japanese.iso-2022-jp")
> >>> funcs = codecs.lookup("japanese.iso_2022_jp")
> >>> funcs = codecs.lookup("japanese.jis-7")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> LookupError: unknown encoding
> >>> funcs = codecs.lookup("japanese.jis_7")
> >>>
> 
> One problem is that the alias "japanese.jis-7" does not work
> unless the corresponding original name "japanese.iso-2022-jp"
> have been referred once.  This is because the alias is defined
> by means of getaliases() in japanese/iso_2022_jp.py, and this
> module is not imported when the first time the original name is
> referred.  Is there a work-around for this problem?

The only "work-around" I know of (which doesn't involve some
kind of boot code) is by defining aliases via almost empty
module which redirect the search function to the correct
codec, e.g.

codec_alias.py:
---------------
from codec_alias_target import *

> The other problem is that hyphens and underscores are
> significant in an alias, although they are not in an original
> name.  A work-around is to define all combinations of hyphens
> and underscores for an alias (e.g. defining both
> "japanese.jis-7" and "japanese.jis_7"), but this seems not a
> good idea for me.

Codec aliases returned by codec.getaliases() must always use 
the underscore naming scheme.

The standard search function will convert hyphens to underscores
*before* applying the alias mapping, so there's no need to worry
about different combinations of hyphens and underscores in
the alias names (unless I've overlooked something here).

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company:                                        http://www.egenix.com/
Consulting:                                    http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/