[I18n-sig] Codecs for Big Five and GB 2312

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri, 27 Oct 2000 23:40:42 +0200


> If you are interested, the codec is available at:

> http://pseudo.grad.sccs.chukyo-u.ac.jp/~kajiyama/python/iso_2022_7bit.py.gz

I just had a look, and it seems like an interesting package. I'm
slightly confused about the installation procedure, though.
Installing into python2.0/encodings/{euc_jp,shift_jis,japanese}
doesn't look right to me - add-on packages should be capable of
installing into site-packages by default.

I believe it would actually work if you just install without any
arguments to setup.py. euc_jp would then end-up in
python2.0/site-packages. Later, when you do

  u"Hello".encode("euc-jp")

it looks for a codec. Here, encodings.__init__.search_function do

    modname = encoding.replace('-', '_')
    modname = aliases.aliases.get(modname,modname)
    try:
        mod = __import__(modname,globals(),locals(),'*')
    except ImportError,why:
        _cache[encoding] = None
        return None

First, encoding becomes euc_jp. With no registered aliases, it would
then call __import__ with "euc_jp", which will find the codec in
site-packages.

In the long run, I'd hope that distutils provides a mean to install
additional codecs, e.g via

setup( ...
      codecs = ['japanese']
      ...)

Then, distutils would collect all these strings, and importing codecs
would roughly do

for package in distutils.registered_codec_packages:
  p=__import__(package,global(),locals(),"*")
  p.register()

japanese/__init__.py would provide a register function which registers
another search_function, which would load euc_jp and shift_jis on
demand. That way, users could install additional codecs which are
available to everybody on the system, without having to hack the
Python library proper.

Regards,
Martin