mirror of
https://github.com/python/cpython.git
synced 2025-01-19 06:54:52 +08:00
locale.py now uses an updated locale alias table (built using
Tools/i18n/makelocalealias.py, a tool to parse the X11 locale alias file); the encoding lookup was enhanced to use Python's encoding alias table As sige-effect, this fixes SF bug [ 1080864 ] locale.py doesn't recognize valid locale setting.
This commit is contained in:
parent
9ab8818c87
commit
bb4f1bdd8b
1090
Lib/locale.py
1090
Lib/locale.py
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,11 @@ Extension Modules
|
|||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- locale.py now uses an updated locale alias table (built using
|
||||||
|
Tools/i18n/makelocalealias.py, a tool to parse the X11 locale
|
||||||
|
alias file); the encoding lookup was enhanced to use Python's
|
||||||
|
encoding alias table
|
||||||
|
|
||||||
- moved deprecated modules to Lib/lib-old: whrandom, tzparse, statcache.
|
- moved deprecated modules to Lib/lib-old: whrandom, tzparse, statcache.
|
||||||
|
|
||||||
- the pickle module no longer accepts the deprecated None option in the
|
- the pickle module no longer accepts the deprecated None option in the
|
||||||
|
70
Tools/i18n/makelocalealias.py
Normal file
70
Tools/i18n/makelocalealias.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
Convert the X11 locale.alias file into a mapping dictionary suitable
|
||||||
|
for locale.py.
|
||||||
|
|
||||||
|
Written by Marc-Andre Lemburg <mal@genix.com>, 2004-12-10.
|
||||||
|
|
||||||
|
"""
|
||||||
|
import locale
|
||||||
|
|
||||||
|
# Location of the alias file
|
||||||
|
LOCALE_ALIAS = '/usr/lib/X11/locale/locale.alias'
|
||||||
|
|
||||||
|
def parse(filename):
|
||||||
|
|
||||||
|
f = open(filename)
|
||||||
|
lines = f.read().splitlines()
|
||||||
|
data = {}
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
if line[:1] == '#':
|
||||||
|
continue
|
||||||
|
locale, alias = line.split()
|
||||||
|
# Strip ':'
|
||||||
|
if locale[-1] == ':':
|
||||||
|
locale = locale[:-1]
|
||||||
|
# Lower-case locale
|
||||||
|
locale = locale.lower()
|
||||||
|
# Ignore one letter locale mappings (except for 'c')
|
||||||
|
if len(locale) == 1 and locale != 'c':
|
||||||
|
continue
|
||||||
|
# Normalize encoding, if given
|
||||||
|
if '.' in locale:
|
||||||
|
lang, encoding = locale.split('.')[:2]
|
||||||
|
encoding = encoding.replace('-', '')
|
||||||
|
encoding = encoding.replace('_', '')
|
||||||
|
locale = lang + '.' + encoding
|
||||||
|
data[locale] = alias
|
||||||
|
return data
|
||||||
|
|
||||||
|
def pprint(data):
|
||||||
|
|
||||||
|
items = data.items()
|
||||||
|
items.sort()
|
||||||
|
for k,v in items:
|
||||||
|
print ' %-40s%r,' % ('%r:' % k, v)
|
||||||
|
|
||||||
|
def print_differences(data, olddata):
|
||||||
|
|
||||||
|
items = olddata.items()
|
||||||
|
items.sort()
|
||||||
|
for k, v in items:
|
||||||
|
if not data.has_key(k):
|
||||||
|
print '# removed %r' % k
|
||||||
|
elif olddata[k] != data[k]:
|
||||||
|
print '# updated %r -> %r to %r' % \
|
||||||
|
(k, olddata[k], data[k])
|
||||||
|
# Additions are not mentioned
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
data = locale.locale_alias.copy()
|
||||||
|
data.update(parse(LOCALE_ALIAS))
|
||||||
|
print_differences(data, locale.locale_alias)
|
||||||
|
print
|
||||||
|
print 'locale_alias = {'
|
||||||
|
pprint(data)
|
||||||
|
print '}'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user