[I18n-sig] codec aliases

M.-A. Lemburg mal@lemburg.com
Tue, 12 Dec 2000 15:46:27 +0100


"M.-A. Lemburg" wrote:
> 
> > | > 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).
> >
> > Returning names with underscores in getaliases() seems not
> > sufficient.  In encodings/__init__.py:
> >
> > def search_function(encoding):
> >     ...
> >     # Cache the encoding and its aliases
> >     _cache[encoding] = entry
> >     try:
> >         codecaliases = mod.getaliases()
> >     except AttributeError:
> >         pass
> >     else:
> >         for alias in codecaliases:
> >             _cache[alias] = entry
> >     return entry
> >
> > The names returned by mod.getaliases() are put into _cache as it
> > is, so equivalent names with hyphens will not be defined.
> 
> So I have indeed overlooked something. Thanks for pointing me
> at it (I don't currently have time to test what I write here,
> so please bare with me). The aliases should really be added to
> the aliases.aliases dictionary instead of _cache and also prevent
> overwrites of already existing aliases (since these would cause
> strange and unwanted effects).
> 
> I'll think about this some more and check in a patch to implement
> the above scheme.

I've checked in a patch which should provide the needed
functionality.

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