Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: locale.py
"""Locale support module.
[0] Fix | Delete
[1] Fix | Delete
The module provides low-level access to the C lib's locale APIs and adds high
[2] Fix | Delete
level number formatting APIs as well as a locale aliasing engine to complement
[3] Fix | Delete
these.
[4] Fix | Delete
[5] Fix | Delete
The aliasing engine includes support for many commonly used locale names and
[6] Fix | Delete
maps them to values suitable for passing to the C lib's setlocale() function. It
[7] Fix | Delete
also includes default encodings for all supported locale names.
[8] Fix | Delete
[9] Fix | Delete
"""
[10] Fix | Delete
[11] Fix | Delete
import sys
[12] Fix | Delete
import encodings
[13] Fix | Delete
import encodings.aliases
[14] Fix | Delete
import re
[15] Fix | Delete
import collections
[16] Fix | Delete
from builtins import str as _builtin_str
[17] Fix | Delete
import functools
[18] Fix | Delete
[19] Fix | Delete
# Try importing the _locale module.
[20] Fix | Delete
#
[21] Fix | Delete
# If this fails, fall back on a basic 'C' locale emulation.
[22] Fix | Delete
[23] Fix | Delete
# Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before
[24] Fix | Delete
# trying the import. So __all__ is also fiddled at the end of the file.
[25] Fix | Delete
__all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
[26] Fix | Delete
"setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm",
[27] Fix | Delete
"str", "atof", "atoi", "format", "format_string", "currency",
[28] Fix | Delete
"normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
[29] Fix | Delete
"LC_NUMERIC", "LC_ALL", "CHAR_MAX"]
[30] Fix | Delete
[31] Fix | Delete
def _strcoll(a,b):
[32] Fix | Delete
""" strcoll(string,string) -> int.
[33] Fix | Delete
Compares two strings according to the locale.
[34] Fix | Delete
"""
[35] Fix | Delete
return (a > b) - (a < b)
[36] Fix | Delete
[37] Fix | Delete
def _strxfrm(s):
[38] Fix | Delete
""" strxfrm(string) -> string.
[39] Fix | Delete
Returns a string that behaves for cmp locale-aware.
[40] Fix | Delete
"""
[41] Fix | Delete
return s
[42] Fix | Delete
[43] Fix | Delete
try:
[44] Fix | Delete
[45] Fix | Delete
from _locale import *
[46] Fix | Delete
[47] Fix | Delete
except ImportError:
[48] Fix | Delete
[49] Fix | Delete
# Locale emulation
[50] Fix | Delete
[51] Fix | Delete
CHAR_MAX = 127
[52] Fix | Delete
LC_ALL = 6
[53] Fix | Delete
LC_COLLATE = 3
[54] Fix | Delete
LC_CTYPE = 0
[55] Fix | Delete
LC_MESSAGES = 5
[56] Fix | Delete
LC_MONETARY = 4
[57] Fix | Delete
LC_NUMERIC = 1
[58] Fix | Delete
LC_TIME = 2
[59] Fix | Delete
Error = ValueError
[60] Fix | Delete
[61] Fix | Delete
def localeconv():
[62] Fix | Delete
""" localeconv() -> dict.
[63] Fix | Delete
Returns numeric and monetary locale-specific parameters.
[64] Fix | Delete
"""
[65] Fix | Delete
# 'C' locale default values
[66] Fix | Delete
return {'grouping': [127],
[67] Fix | Delete
'currency_symbol': '',
[68] Fix | Delete
'n_sign_posn': 127,
[69] Fix | Delete
'p_cs_precedes': 127,
[70] Fix | Delete
'n_cs_precedes': 127,
[71] Fix | Delete
'mon_grouping': [],
[72] Fix | Delete
'n_sep_by_space': 127,
[73] Fix | Delete
'decimal_point': '.',
[74] Fix | Delete
'negative_sign': '',
[75] Fix | Delete
'positive_sign': '',
[76] Fix | Delete
'p_sep_by_space': 127,
[77] Fix | Delete
'int_curr_symbol': '',
[78] Fix | Delete
'p_sign_posn': 127,
[79] Fix | Delete
'thousands_sep': '',
[80] Fix | Delete
'mon_thousands_sep': '',
[81] Fix | Delete
'frac_digits': 127,
[82] Fix | Delete
'mon_decimal_point': '',
[83] Fix | Delete
'int_frac_digits': 127}
[84] Fix | Delete
[85] Fix | Delete
def setlocale(category, value=None):
[86] Fix | Delete
""" setlocale(integer,string=None) -> string.
[87] Fix | Delete
Activates/queries locale processing.
[88] Fix | Delete
"""
[89] Fix | Delete
if value not in (None, '', 'C'):
[90] Fix | Delete
raise Error('_locale emulation only supports "C" locale')
[91] Fix | Delete
return 'C'
[92] Fix | Delete
[93] Fix | Delete
# These may or may not exist in _locale, so be sure to set them.
[94] Fix | Delete
if 'strxfrm' not in globals():
[95] Fix | Delete
strxfrm = _strxfrm
[96] Fix | Delete
if 'strcoll' not in globals():
[97] Fix | Delete
strcoll = _strcoll
[98] Fix | Delete
[99] Fix | Delete
[100] Fix | Delete
_localeconv = localeconv
[101] Fix | Delete
[102] Fix | Delete
# With this dict, you can override some items of localeconv's return value.
[103] Fix | Delete
# This is useful for testing purposes.
[104] Fix | Delete
_override_localeconv = {}
[105] Fix | Delete
[106] Fix | Delete
@functools.wraps(_localeconv)
[107] Fix | Delete
def localeconv():
[108] Fix | Delete
d = _localeconv()
[109] Fix | Delete
if _override_localeconv:
[110] Fix | Delete
d.update(_override_localeconv)
[111] Fix | Delete
return d
[112] Fix | Delete
[113] Fix | Delete
[114] Fix | Delete
### Number formatting APIs
[115] Fix | Delete
[116] Fix | Delete
# Author: Martin von Loewis
[117] Fix | Delete
# improved by Georg Brandl
[118] Fix | Delete
[119] Fix | Delete
# Iterate over grouping intervals
[120] Fix | Delete
def _grouping_intervals(grouping):
[121] Fix | Delete
last_interval = None
[122] Fix | Delete
for interval in grouping:
[123] Fix | Delete
# if grouping is -1, we are done
[124] Fix | Delete
if interval == CHAR_MAX:
[125] Fix | Delete
return
[126] Fix | Delete
# 0: re-use last group ad infinitum
[127] Fix | Delete
if interval == 0:
[128] Fix | Delete
if last_interval is None:
[129] Fix | Delete
raise ValueError("invalid grouping")
[130] Fix | Delete
while True:
[131] Fix | Delete
yield last_interval
[132] Fix | Delete
yield interval
[133] Fix | Delete
last_interval = interval
[134] Fix | Delete
[135] Fix | Delete
#perform the grouping from right to left
[136] Fix | Delete
def _group(s, monetary=False):
[137] Fix | Delete
conv = localeconv()
[138] Fix | Delete
thousands_sep = conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
[139] Fix | Delete
grouping = conv[monetary and 'mon_grouping' or 'grouping']
[140] Fix | Delete
if not grouping:
[141] Fix | Delete
return (s, 0)
[142] Fix | Delete
if s[-1] == ' ':
[143] Fix | Delete
stripped = s.rstrip()
[144] Fix | Delete
right_spaces = s[len(stripped):]
[145] Fix | Delete
s = stripped
[146] Fix | Delete
else:
[147] Fix | Delete
right_spaces = ''
[148] Fix | Delete
left_spaces = ''
[149] Fix | Delete
groups = []
[150] Fix | Delete
for interval in _grouping_intervals(grouping):
[151] Fix | Delete
if not s or s[-1] not in "0123456789":
[152] Fix | Delete
# only non-digit characters remain (sign, spaces)
[153] Fix | Delete
left_spaces = s
[154] Fix | Delete
s = ''
[155] Fix | Delete
break
[156] Fix | Delete
groups.append(s[-interval:])
[157] Fix | Delete
s = s[:-interval]
[158] Fix | Delete
if s:
[159] Fix | Delete
groups.append(s)
[160] Fix | Delete
groups.reverse()
[161] Fix | Delete
return (
[162] Fix | Delete
left_spaces + thousands_sep.join(groups) + right_spaces,
[163] Fix | Delete
len(thousands_sep) * (len(groups) - 1)
[164] Fix | Delete
)
[165] Fix | Delete
[166] Fix | Delete
# Strip a given amount of excess padding from the given string
[167] Fix | Delete
def _strip_padding(s, amount):
[168] Fix | Delete
lpos = 0
[169] Fix | Delete
while amount and s[lpos] == ' ':
[170] Fix | Delete
lpos += 1
[171] Fix | Delete
amount -= 1
[172] Fix | Delete
rpos = len(s) - 1
[173] Fix | Delete
while amount and s[rpos] == ' ':
[174] Fix | Delete
rpos -= 1
[175] Fix | Delete
amount -= 1
[176] Fix | Delete
return s[lpos:rpos+1]
[177] Fix | Delete
[178] Fix | Delete
_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
[179] Fix | Delete
r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
[180] Fix | Delete
[181] Fix | Delete
def format(percent, value, grouping=False, monetary=False, *additional):
[182] Fix | Delete
"""Returns the locale-aware substitution of a %? specifier
[183] Fix | Delete
(percent).
[184] Fix | Delete
[185] Fix | Delete
additional is for format strings which contain one or more
[186] Fix | Delete
'*' modifiers."""
[187] Fix | Delete
# this is only for one-percent-specifier strings and this should be checked
[188] Fix | Delete
match = _percent_re.match(percent)
[189] Fix | Delete
if not match or len(match.group())!= len(percent):
[190] Fix | Delete
raise ValueError(("format() must be given exactly one %%char "
[191] Fix | Delete
"format specifier, %s not valid") % repr(percent))
[192] Fix | Delete
return _format(percent, value, grouping, monetary, *additional)
[193] Fix | Delete
[194] Fix | Delete
def _format(percent, value, grouping=False, monetary=False, *additional):
[195] Fix | Delete
if additional:
[196] Fix | Delete
formatted = percent % ((value,) + additional)
[197] Fix | Delete
else:
[198] Fix | Delete
formatted = percent % value
[199] Fix | Delete
# floats and decimal ints need special action!
[200] Fix | Delete
if percent[-1] in 'eEfFgG':
[201] Fix | Delete
seps = 0
[202] Fix | Delete
parts = formatted.split('.')
[203] Fix | Delete
if grouping:
[204] Fix | Delete
parts[0], seps = _group(parts[0], monetary=monetary)
[205] Fix | Delete
decimal_point = localeconv()[monetary and 'mon_decimal_point'
[206] Fix | Delete
or 'decimal_point']
[207] Fix | Delete
formatted = decimal_point.join(parts)
[208] Fix | Delete
if seps:
[209] Fix | Delete
formatted = _strip_padding(formatted, seps)
[210] Fix | Delete
elif percent[-1] in 'diu':
[211] Fix | Delete
seps = 0
[212] Fix | Delete
if grouping:
[213] Fix | Delete
formatted, seps = _group(formatted, monetary=monetary)
[214] Fix | Delete
if seps:
[215] Fix | Delete
formatted = _strip_padding(formatted, seps)
[216] Fix | Delete
return formatted
[217] Fix | Delete
[218] Fix | Delete
def format_string(f, val, grouping=False):
[219] Fix | Delete
"""Formats a string in the same way that the % formatting would use,
[220] Fix | Delete
but takes the current locale into account.
[221] Fix | Delete
Grouping is applied if the third parameter is true."""
[222] Fix | Delete
percents = list(_percent_re.finditer(f))
[223] Fix | Delete
new_f = _percent_re.sub('%s', f)
[224] Fix | Delete
[225] Fix | Delete
if isinstance(val, collections.Mapping):
[226] Fix | Delete
new_val = []
[227] Fix | Delete
for perc in percents:
[228] Fix | Delete
if perc.group()[-1]=='%':
[229] Fix | Delete
new_val.append('%')
[230] Fix | Delete
else:
[231] Fix | Delete
new_val.append(format(perc.group(), val, grouping))
[232] Fix | Delete
else:
[233] Fix | Delete
if not isinstance(val, tuple):
[234] Fix | Delete
val = (val,)
[235] Fix | Delete
new_val = []
[236] Fix | Delete
i = 0
[237] Fix | Delete
for perc in percents:
[238] Fix | Delete
if perc.group()[-1]=='%':
[239] Fix | Delete
new_val.append('%')
[240] Fix | Delete
else:
[241] Fix | Delete
starcount = perc.group('modifiers').count('*')
[242] Fix | Delete
new_val.append(_format(perc.group(),
[243] Fix | Delete
val[i],
[244] Fix | Delete
grouping,
[245] Fix | Delete
False,
[246] Fix | Delete
*val[i+1:i+1+starcount]))
[247] Fix | Delete
i += (1 + starcount)
[248] Fix | Delete
val = tuple(new_val)
[249] Fix | Delete
[250] Fix | Delete
return new_f % val
[251] Fix | Delete
[252] Fix | Delete
def currency(val, symbol=True, grouping=False, international=False):
[253] Fix | Delete
"""Formats val according to the currency settings
[254] Fix | Delete
in the current locale."""
[255] Fix | Delete
conv = localeconv()
[256] Fix | Delete
[257] Fix | Delete
# check for illegal values
[258] Fix | Delete
digits = conv[international and 'int_frac_digits' or 'frac_digits']
[259] Fix | Delete
if digits == 127:
[260] Fix | Delete
raise ValueError("Currency formatting is not possible using "
[261] Fix | Delete
"the 'C' locale.")
[262] Fix | Delete
[263] Fix | Delete
s = format('%%.%if' % digits, abs(val), grouping, monetary=True)
[264] Fix | Delete
# '<' and '>' are markers if the sign must be inserted between symbol and value
[265] Fix | Delete
s = '<' + s + '>'
[266] Fix | Delete
[267] Fix | Delete
if symbol:
[268] Fix | Delete
smb = conv[international and 'int_curr_symbol' or 'currency_symbol']
[269] Fix | Delete
precedes = conv[val<0 and 'n_cs_precedes' or 'p_cs_precedes']
[270] Fix | Delete
separated = conv[val<0 and 'n_sep_by_space' or 'p_sep_by_space']
[271] Fix | Delete
[272] Fix | Delete
if precedes:
[273] Fix | Delete
s = smb + (separated and ' ' or '') + s
[274] Fix | Delete
else:
[275] Fix | Delete
s = s + (separated and ' ' or '') + smb
[276] Fix | Delete
[277] Fix | Delete
sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
[278] Fix | Delete
sign = conv[val<0 and 'negative_sign' or 'positive_sign']
[279] Fix | Delete
[280] Fix | Delete
if sign_pos == 0:
[281] Fix | Delete
s = '(' + s + ')'
[282] Fix | Delete
elif sign_pos == 1:
[283] Fix | Delete
s = sign + s
[284] Fix | Delete
elif sign_pos == 2:
[285] Fix | Delete
s = s + sign
[286] Fix | Delete
elif sign_pos == 3:
[287] Fix | Delete
s = s.replace('<', sign)
[288] Fix | Delete
elif sign_pos == 4:
[289] Fix | Delete
s = s.replace('>', sign)
[290] Fix | Delete
else:
[291] Fix | Delete
# the default if nothing specified;
[292] Fix | Delete
# this should be the most fitting sign position
[293] Fix | Delete
s = sign + s
[294] Fix | Delete
[295] Fix | Delete
return s.replace('<', '').replace('>', '')
[296] Fix | Delete
[297] Fix | Delete
def str(val):
[298] Fix | Delete
"""Convert float to string, taking the locale into account."""
[299] Fix | Delete
return format("%.12g", val)
[300] Fix | Delete
[301] Fix | Delete
def delocalize(string):
[302] Fix | Delete
"Parses a string as a normalized number according to the locale settings."
[303] Fix | Delete
[304] Fix | Delete
conv = localeconv()
[305] Fix | Delete
[306] Fix | Delete
#First, get rid of the grouping
[307] Fix | Delete
ts = conv['thousands_sep']
[308] Fix | Delete
if ts:
[309] Fix | Delete
string = string.replace(ts, '')
[310] Fix | Delete
[311] Fix | Delete
#next, replace the decimal point with a dot
[312] Fix | Delete
dd = conv['decimal_point']
[313] Fix | Delete
if dd:
[314] Fix | Delete
string = string.replace(dd, '.')
[315] Fix | Delete
return string
[316] Fix | Delete
[317] Fix | Delete
def atof(string, func=float):
[318] Fix | Delete
"Parses a string as a float according to the locale settings."
[319] Fix | Delete
return func(delocalize(string))
[320] Fix | Delete
[321] Fix | Delete
def atoi(string):
[322] Fix | Delete
"Converts a string to an integer according to the locale settings."
[323] Fix | Delete
return int(delocalize(string))
[324] Fix | Delete
[325] Fix | Delete
def _test():
[326] Fix | Delete
setlocale(LC_ALL, "")
[327] Fix | Delete
#do grouping
[328] Fix | Delete
s1 = format("%d", 123456789,1)
[329] Fix | Delete
print(s1, "is", atoi(s1))
[330] Fix | Delete
#standard formatting
[331] Fix | Delete
s1 = str(3.14)
[332] Fix | Delete
print(s1, "is", atof(s1))
[333] Fix | Delete
[334] Fix | Delete
### Locale name aliasing engine
[335] Fix | Delete
[336] Fix | Delete
# Author: Marc-Andre Lemburg, mal@lemburg.com
[337] Fix | Delete
# Various tweaks by Fredrik Lundh <fredrik@pythonware.com>
[338] Fix | Delete
[339] Fix | Delete
# store away the low-level version of setlocale (it's
[340] Fix | Delete
# overridden below)
[341] Fix | Delete
_setlocale = setlocale
[342] Fix | Delete
[343] Fix | Delete
def _replace_encoding(code, encoding):
[344] Fix | Delete
if '.' in code:
[345] Fix | Delete
langname = code[:code.index('.')]
[346] Fix | Delete
else:
[347] Fix | Delete
langname = code
[348] Fix | Delete
# Convert the encoding to a C lib compatible encoding string
[349] Fix | Delete
norm_encoding = encodings.normalize_encoding(encoding)
[350] Fix | Delete
#print('norm encoding: %r' % norm_encoding)
[351] Fix | Delete
norm_encoding = encodings.aliases.aliases.get(norm_encoding.lower(),
[352] Fix | Delete
norm_encoding)
[353] Fix | Delete
#print('aliased encoding: %r' % norm_encoding)
[354] Fix | Delete
encoding = norm_encoding
[355] Fix | Delete
norm_encoding = norm_encoding.lower()
[356] Fix | Delete
if norm_encoding in locale_encoding_alias:
[357] Fix | Delete
encoding = locale_encoding_alias[norm_encoding]
[358] Fix | Delete
else:
[359] Fix | Delete
norm_encoding = norm_encoding.replace('_', '')
[360] Fix | Delete
norm_encoding = norm_encoding.replace('-', '')
[361] Fix | Delete
if norm_encoding in locale_encoding_alias:
[362] Fix | Delete
encoding = locale_encoding_alias[norm_encoding]
[363] Fix | Delete
#print('found encoding %r' % encoding)
[364] Fix | Delete
return langname + '.' + encoding
[365] Fix | Delete
[366] Fix | Delete
def _append_modifier(code, modifier):
[367] Fix | Delete
if modifier == 'euro':
[368] Fix | Delete
if '.' not in code:
[369] Fix | Delete
return code + '.ISO8859-15'
[370] Fix | Delete
_, _, encoding = code.partition('.')
[371] Fix | Delete
if encoding in ('ISO8859-15', 'UTF-8'):
[372] Fix | Delete
return code
[373] Fix | Delete
if encoding == 'ISO8859-1':
[374] Fix | Delete
return _replace_encoding(code, 'ISO8859-15')
[375] Fix | Delete
return code + '@' + modifier
[376] Fix | Delete
[377] Fix | Delete
def normalize(localename):
[378] Fix | Delete
[379] Fix | Delete
""" Returns a normalized locale code for the given locale
[380] Fix | Delete
name.
[381] Fix | Delete
[382] Fix | Delete
The returned locale code is formatted for use with
[383] Fix | Delete
setlocale().
[384] Fix | Delete
[385] Fix | Delete
If normalization fails, the original name is returned
[386] Fix | Delete
unchanged.
[387] Fix | Delete
[388] Fix | Delete
If the given encoding is not known, the function defaults to
[389] Fix | Delete
the default encoding for the locale code just like setlocale()
[390] Fix | Delete
does.
[391] Fix | Delete
[392] Fix | Delete
"""
[393] Fix | Delete
# Normalize the locale name and extract the encoding and modifier
[394] Fix | Delete
code = localename.lower()
[395] Fix | Delete
if ':' in code:
[396] Fix | Delete
# ':' is sometimes used as encoding delimiter.
[397] Fix | Delete
code = code.replace(':', '.')
[398] Fix | Delete
if '@' in code:
[399] Fix | Delete
code, modifier = code.split('@', 1)
[400] Fix | Delete
else:
[401] Fix | Delete
modifier = ''
[402] Fix | Delete
if '.' in code:
[403] Fix | Delete
langname, encoding = code.split('.')[:2]
[404] Fix | Delete
else:
[405] Fix | Delete
langname = code
[406] Fix | Delete
encoding = ''
[407] Fix | Delete
[408] Fix | Delete
# First lookup: fullname (possibly with encoding and modifier)
[409] Fix | Delete
lang_enc = langname
[410] Fix | Delete
if encoding:
[411] Fix | Delete
norm_encoding = encoding.replace('-', '')
[412] Fix | Delete
norm_encoding = norm_encoding.replace('_', '')
[413] Fix | Delete
lang_enc += '.' + norm_encoding
[414] Fix | Delete
lookup_name = lang_enc
[415] Fix | Delete
if modifier:
[416] Fix | Delete
lookup_name += '@' + modifier
[417] Fix | Delete
code = locale_alias.get(lookup_name, None)
[418] Fix | Delete
if code is not None:
[419] Fix | Delete
return code
[420] Fix | Delete
#print('first lookup failed')
[421] Fix | Delete
[422] Fix | Delete
if modifier:
[423] Fix | Delete
# Second try: fullname without modifier (possibly with encoding)
[424] Fix | Delete
code = locale_alias.get(lang_enc, None)
[425] Fix | Delete
if code is not None:
[426] Fix | Delete
#print('lookup without modifier succeeded')
[427] Fix | Delete
if '@' not in code:
[428] Fix | Delete
return _append_modifier(code, modifier)
[429] Fix | Delete
if code.split('@', 1)[1].lower() == modifier:
[430] Fix | Delete
return code
[431] Fix | Delete
#print('second lookup failed')
[432] Fix | Delete
[433] Fix | Delete
if encoding:
[434] Fix | Delete
# Third try: langname (without encoding, possibly with modifier)
[435] Fix | Delete
lookup_name = langname
[436] Fix | Delete
if modifier:
[437] Fix | Delete
lookup_name += '@' + modifier
[438] Fix | Delete
code = locale_alias.get(lookup_name, None)
[439] Fix | Delete
if code is not None:
[440] Fix | Delete
#print('lookup without encoding succeeded')
[441] Fix | Delete
if '@' not in code:
[442] Fix | Delete
return _replace_encoding(code, encoding)
[443] Fix | Delete
code, modifier = code.split('@', 1)
[444] Fix | Delete
return _replace_encoding(code, encoding) + '@' + modifier
[445] Fix | Delete
[446] Fix | Delete
if modifier:
[447] Fix | Delete
# Fourth try: langname (without encoding and modifier)
[448] Fix | Delete
code = locale_alias.get(langname, None)
[449] Fix | Delete
if code is not None:
[450] Fix | Delete
#print('lookup without modifier and encoding succeeded')
[451] Fix | Delete
if '@' not in code:
[452] Fix | Delete
code = _replace_encoding(code, encoding)
[453] Fix | Delete
return _append_modifier(code, modifier)
[454] Fix | Delete
code, defmod = code.split('@', 1)
[455] Fix | Delete
if defmod.lower() == modifier:
[456] Fix | Delete
return _replace_encoding(code, encoding) + '@' + defmod
[457] Fix | Delete
[458] Fix | Delete
return localename
[459] Fix | Delete
[460] Fix | Delete
def _parse_localename(localename):
[461] Fix | Delete
[462] Fix | Delete
""" Parses the locale code for localename and returns the
[463] Fix | Delete
result as tuple (language code, encoding).
[464] Fix | Delete
[465] Fix | Delete
The localename is normalized and passed through the locale
[466] Fix | Delete
alias engine. A ValueError is raised in case the locale name
[467] Fix | Delete
cannot be parsed.
[468] Fix | Delete
[469] Fix | Delete
The language code corresponds to RFC 1766. code and encoding
[470] Fix | Delete
can be None in case the values cannot be determined or are
[471] Fix | Delete
unknown to this implementation.
[472] Fix | Delete
[473] Fix | Delete
"""
[474] Fix | Delete
code = normalize(localename)
[475] Fix | Delete
if '@' in code:
[476] Fix | Delete
# Deal with locale modifiers
[477] Fix | Delete
code, modifier = code.split('@', 1)
[478] Fix | Delete
if modifier == 'euro' and '.' not in code:
[479] Fix | Delete
# Assume Latin-9 for @euro locales. This is bogus,
[480] Fix | Delete
# since some systems may use other encodings for these
[481] Fix | Delete
# locales. Also, we ignore other modifiers.
[482] Fix | Delete
return code, 'iso-8859-15'
[483] Fix | Delete
[484] Fix | Delete
if '.' in code:
[485] Fix | Delete
return tuple(code.split('.')[:2])
[486] Fix | Delete
elif code == 'C':
[487] Fix | Delete
return None, None
[488] Fix | Delete
raise ValueError('unknown locale: %s' % localename)
[489] Fix | Delete
[490] Fix | Delete
def _build_localename(localetuple):
[491] Fix | Delete
[492] Fix | Delete
""" Builds a locale code from the given tuple (language code,
[493] Fix | Delete
encoding).
[494] Fix | Delete
[495] Fix | Delete
No aliasing or normalizing takes place.
[496] Fix | Delete
[497] Fix | Delete
"""
[498] Fix | Delete
try:
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function