[I18n-sig] Intro + Encoding names issue

Martin v. Loewis martin@v.loewis.de
Sat, 27 Oct 2001 10:40:31 +0200


>     1) whether it is appropriate to put the burden of creating aliases
>        on either application developers or end users (and you probably
>        gathered that I think it isn't); and

No, it isn't.

>     2) assuming we would like people to be able to use standard
>        encoding names without creating their own aliases, is there a
>        way to accomplish this goal and still allow language-specific
>        codecs sets to be maintained as separate packages?

Starting with Python 2.1, there is an easy solution. To discuss this,
I assume you know what a codec search function is and how to register
one (see codecs.register if you don't).

Now, suppose you hava a package "japanese", containing a number of
codecs. Inside japanese/__init__.py, register a search function for
these codecs. So anybody importing "japanese" will get a codec
"euc-jp". Install the "japanese" directory into site-packages.

This works for all Python versions, but still requires applications to
"import japanese". That is where a 2.1 feature comes into play: In
site-packages, create a file "japanese.pth". In that file, add a
single line

import japanese

Then, every time python starts, the japanese codecs will be
automatically registered.

HTH,
Martin