home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-python-addon-1.4.9-installer.exe / locale.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2004-10-01  |  21.9 KB  |  758 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.3)
  3.  
  4. """ Locale support.
  5.  
  6.     The module provides low-level access to the C lib's locale APIs
  7.     and adds high level number formatting APIs as well as a locale
  8.     aliasing engine to complement these.
  9.  
  10.     The aliasing engine includes support for many commonly used locale
  11.     names and maps them to values suitable for passing to the C lib's
  12.     setlocale() function. It also includes default encodings for all
  13.     supported locale names.
  14.  
  15. """
  16. import sys
  17. __all__ = [
  18.     'setlocale',
  19.     'Error',
  20.     'localeconv',
  21.     'strcoll',
  22.     'strxfrm',
  23.     'format',
  24.     'str',
  25.     'atof',
  26.     'atoi',
  27.     'LC_CTYPE',
  28.     'LC_COLLATE',
  29.     'LC_TIME',
  30.     'LC_MONETARY',
  31.     'LC_NUMERIC',
  32.     'LC_ALL',
  33.     'CHAR_MAX']
  34.  
  35. try:
  36.     from _locale import *
  37. except ImportError:
  38.     CHAR_MAX = 127
  39.     LC_ALL = 6
  40.     LC_COLLATE = 3
  41.     LC_CTYPE = 0
  42.     LC_MESSAGES = 5
  43.     LC_MONETARY = 4
  44.     LC_NUMERIC = 1
  45.     LC_TIME = 2
  46.     Error = ValueError
  47.     
  48.     def localeconv():
  49.         ''' localeconv() -> dict.
  50.             Returns numeric and monetary locale-specific parameters.
  51.         '''
  52.         return {
  53.             'grouping': [
  54.                 127],
  55.             'currency_symbol': '',
  56.             'n_sign_posn': 127,
  57.             'p_cs_precedes': 127,
  58.             'n_cs_precedes': 127,
  59.             'mon_grouping': [],
  60.             'n_sep_by_space': 127,
  61.             'decimal_point': '.',
  62.             'negative_sign': '',
  63.             'positive_sign': '',
  64.             'p_sep_by_space': 127,
  65.             'int_curr_symbol': '',
  66.             'p_sign_posn': 127,
  67.             'thousands_sep': '',
  68.             'mon_thousands_sep': '',
  69.             'frac_digits': 127,
  70.             'mon_decimal_point': '',
  71.             'int_frac_digits': 127 }
  72.  
  73.     
  74.     def setlocale(category, value = None):
  75.         ''' setlocale(integer,string=None) -> string.
  76.             Activates/queries locale processing.
  77.         '''
  78.         if value not in (None, '', 'C'):
  79.             raise Error, '_locale emulation only supports "C" locale'
  80.         
  81.         return 'C'
  82.  
  83.     
  84.     def strcoll(a, b):
  85.         ''' strcoll(string,string) -> int.
  86.             Compares two strings according to the locale.
  87.         '''
  88.         return cmp(a, b)
  89.  
  90.     
  91.     def strxfrm(s):
  92.         ''' strxfrm(string) -> string.
  93.             Returns a string that behaves for cmp locale-aware.
  94.         '''
  95.         return s
  96.  
  97.  
  98.  
  99. def _group(s):
  100.     conv = localeconv()
  101.     grouping = conv['grouping']
  102.     if not grouping:
  103.         return (s, 0)
  104.     
  105.     result = ''
  106.     seps = 0
  107.     spaces = ''
  108.     if s[-1] == ' ':
  109.         sp = s.find(' ')
  110.         spaces = s[sp:]
  111.         s = s[:sp]
  112.     
  113.     while s and grouping:
  114.         if grouping[0] == CHAR_MAX:
  115.             break
  116.         elif grouping[0] != 0:
  117.             group = grouping[0]
  118.             grouping = grouping[1:]
  119.         
  120.         if result:
  121.             result = s[-group:] + conv['thousands_sep'] + result
  122.             seps += 1
  123.         else:
  124.             result = s[-group:]
  125.         s = s[:-group]
  126.         if s and s[-1] not in '0123456789':
  127.             return (s + result + spaces, seps)
  128.             continue
  129.     if not result:
  130.         return (s + spaces, seps)
  131.     
  132.     if s:
  133.         result = s + conv['thousands_sep'] + result
  134.         seps += 1
  135.     
  136.     return (result + spaces, seps)
  137.  
  138.  
  139. def format(f, val, grouping = 0):
  140.     '''Formats a value in the same way that the % formatting would use,
  141.     but takes the current locale into account.
  142.     Grouping is applied if the third parameter is true.'''
  143.     result = f % val
  144.     fields = result.split('.')
  145.     seps = 0
  146.     if grouping:
  147.         (fields[0], seps) = _group(fields[0])
  148.     
  149.     if len(fields) == 2:
  150.         result = fields[0] + localeconv()['decimal_point'] + fields[1]
  151.     elif len(fields) == 1:
  152.         result = fields[0]
  153.     else:
  154.         raise Error, 'Too many decimal points in result string'
  155.     while seps:
  156.         sp = result.find(' ')
  157.         if sp == -1:
  158.             break
  159.         
  160.         result = result[:sp] + result[sp + 1:]
  161.         seps -= 1
  162.     return result
  163.  
  164.  
  165. def str(val):
  166.     '''Convert float to integer, taking the locale into account.'''
  167.     return format('%.12g', val)
  168.  
  169.  
  170. def atof(str, func = float):
  171.     '''Parses a string as a float according to the locale settings.'''
  172.     ts = localeconv()['thousands_sep']
  173.     if ts:
  174.         s = str.split(ts)
  175.         str = ''.join(s)
  176.     
  177.     dd = localeconv()['decimal_point']
  178.     if dd:
  179.         s = str.split(dd)
  180.         str = '.'.join(s)
  181.     
  182.     return func(str)
  183.  
  184.  
  185. def atoi(str):
  186.     '''Converts a string to an integer according to the locale settings.'''
  187.     return atof(str, int)
  188.  
  189.  
  190. def _test():
  191.     setlocale(LC_ALL, '')
  192.     s1 = format('%d', 123456789, 1)
  193.     print s1, 'is', atoi(s1)
  194.     s1 = str(3.1400000000000001)
  195.     print s1, 'is', atof(s1)
  196.  
  197. _setlocale = setlocale
  198.  
  199. def normalize(localename):
  200.     ''' Returns a normalized locale code for the given locale
  201.         name.
  202.  
  203.         The returned locale code is formatted for use with
  204.         setlocale().
  205.  
  206.         If normalization fails, the original name is returned
  207.         unchanged.
  208.  
  209.         If the given encoding is not known, the function defaults to
  210.         the default encoding for the locale code just like setlocale()
  211.         does.
  212.  
  213.     '''
  214.     fullname = localename.lower()
  215.     if ':' in fullname:
  216.         fullname = fullname.replace(':', '.')
  217.     
  218.     if '.' in fullname:
  219.         (langname, encoding) = fullname.split('.')[:2]
  220.         fullname = langname + '.' + encoding
  221.     else:
  222.         langname = fullname
  223.         encoding = ''
  224.     code = locale_alias.get(fullname, None)
  225.     if code is not None:
  226.         return code
  227.     
  228.     code = locale_alias.get(langname, None)
  229.     if code is not None:
  230.         if '.' in code:
  231.             (langname, defenc) = code.split('.')
  232.         else:
  233.             langname = code
  234.             defenc = ''
  235.         if encoding:
  236.             encoding = encoding_alias.get(encoding, encoding)
  237.         else:
  238.             encoding = defenc
  239.         if encoding:
  240.             return langname + '.' + encoding
  241.         else:
  242.             return langname
  243.     else:
  244.         return localename
  245.  
  246.  
  247. def _parse_localename(localename):
  248.     ''' Parses the locale code for localename and returns the
  249.         result as tuple (language code, encoding).
  250.  
  251.         The localename is normalized and passed through the locale
  252.         alias engine. A ValueError is raised in case the locale name
  253.         cannot be parsed.
  254.  
  255.         The language code corresponds to RFC 1766.  code and encoding
  256.         can be None in case the values cannot be determined or are
  257.         unknown to this implementation.
  258.  
  259.     '''
  260.     code = normalize(localename)
  261.     if '@' in localename:
  262.         (code, modifier) = code.split('@')
  263.         if modifier == 'euro' and '.' not in code:
  264.             return (code, 'iso-8859-15')
  265.         
  266.     
  267.     if '.' in code:
  268.         return code.split('.')[:2]
  269.     elif code == 'C':
  270.         return (None, None)
  271.     
  272.     raise ValueError, 'unknown locale: %s' % localename
  273.  
  274.  
  275. def _build_localename(localetuple):
  276.     ''' Builds a locale code from the given tuple (language code,
  277.         encoding).
  278.  
  279.         No aliasing or normalizing takes place.
  280.  
  281.     '''
  282.     (language, encoding) = localetuple
  283.     if language is None:
  284.         language = 'C'
  285.     
  286.     if encoding is None:
  287.         return language
  288.     else:
  289.         return language + '.' + encoding
  290.  
  291.  
  292. def getdefaultlocale(envvars = ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG')):
  293.     ''' Tries to determine the default locale settings and returns
  294.         them as tuple (language code, encoding).
  295.  
  296.         According to POSIX, a program which has not called
  297.         setlocale(LC_ALL, "") runs using the portable \'C\' locale.
  298.         Calling setlocale(LC_ALL, "") lets it use the default locale as
  299.         defined by the LANG variable. Since we don\'t want to interfere
  300.         with the current locale setting we thus emulate the behavior
  301.         in the way described above.
  302.  
  303.         To maintain compatibility with other platforms, not only the
  304.         LANG variable is tested, but a list of variables given as
  305.         envvars parameter. The first found to be defined will be
  306.         used. envvars defaults to the search path used in GNU gettext;
  307.         it must always contain the variable name \'LANG\'.
  308.  
  309.         Except for the code \'C\', the language code corresponds to RFC
  310.         1766.  code and encoding can be None in case the values cannot
  311.         be determined.
  312.  
  313.     '''
  314.     
  315.     try:
  316.         import _locale
  317.         (code, encoding) = _locale._getdefaultlocale()
  318.     except (ImportError, AttributeError):
  319.         pass
  320.  
  321.     if sys.platform == 'win32' and code and code[:2] == '0x':
  322.         code = windows_locale.get(int(code, 0))
  323.     
  324.     return (code, encoding)
  325.     import os
  326.     lookup = os.environ.get
  327.     for variable in envvars:
  328.         localename = lookup(variable, None)
  329.         if localename is not None:
  330.             break
  331.             continue
  332.     else:
  333.         localename = 'C'
  334.     return _parse_localename(localename)
  335.  
  336.  
  337. def getlocale(category = LC_CTYPE):
  338.     """ Returns the current setting for the given locale category as
  339.         tuple (language code, encoding).
  340.  
  341.         category may be one of the LC_* value except LC_ALL. It
  342.         defaults to LC_CTYPE.
  343.  
  344.         Except for the code 'C', the language code corresponds to RFC
  345.         1766.  code and encoding can be None in case the values cannot
  346.         be determined.
  347.  
  348.     """
  349.     localename = _setlocale(category)
  350.     if category == LC_ALL and ';' in localename:
  351.         raise TypeError, 'category LC_ALL is not supported'
  352.     
  353.     return _parse_localename(localename)
  354.  
  355.  
  356. def setlocale(category, locale = None):
  357.     ''' Set the locale for the given category.  The locale can be
  358.         a string, a locale tuple (language code, encoding), or None.
  359.  
  360.         Locale tuples are converted to strings the locale aliasing
  361.         engine.  Locale strings are passed directly to the C lib.
  362.  
  363.         category may be given as one of the LC_* values.
  364.  
  365.     '''
  366.     if locale and type(locale) is not type(''):
  367.         locale = normalize(_build_localename(locale))
  368.     
  369.     return _setlocale(category, locale)
  370.  
  371.  
  372. def resetlocale(category = LC_ALL):
  373.     ''' Sets the locale for category to the default setting.
  374.  
  375.         The default setting is determined by calling
  376.         getdefaultlocale(). category defaults to LC_ALL.
  377.  
  378.     '''
  379.     _setlocale(category, _build_localename(getdefaultlocale()))
  380.  
  381. if sys.platform in ('win32', 'darwin', 'mac'):
  382.     
  383.     def getpreferredencoding(do_setlocale = True):
  384.         '''Return the charset that the user is likely using.'''
  385.         import _locale
  386.         return _locale._getdefaultlocale()[1]
  387.  
  388. else:
  389.     
  390.     try:
  391.         CODESET
  392.     except NameError:
  393.         
  394.         def getpreferredencoding(do_setlocale = True):
  395.             '''Return the charset that the user is likely using,
  396.             by looking at environment variables.'''
  397.             return getdefaultlocale()[1]
  398.  
  399.  
  400.     
  401.     def getpreferredencoding(do_setlocale = True):
  402.         '''Return the charset that the user is likely using,
  403.             according to the system configuration.'''
  404.         if do_setlocale:
  405.             oldloc = setlocale(LC_CTYPE)
  406.             setlocale(LC_CTYPE, '')
  407.             result = nl_langinfo(CODESET)
  408.             setlocale(LC_CTYPE, oldloc)
  409.             return result
  410.         else:
  411.             return nl_langinfo(CODESET)
  412.  
  413. encoding_alias = {
  414.     '437': 'C',
  415.     'c': 'C',
  416.     'iso8859': 'ISO8859-1',
  417.     '8859': 'ISO8859-1',
  418.     '88591': 'ISO8859-1',
  419.     'ascii': 'ISO8859-1',
  420.     'en': 'ISO8859-1',
  421.     'iso88591': 'ISO8859-1',
  422.     'iso_8859-1': 'ISO8859-1',
  423.     '885915': 'ISO8859-15',
  424.     'iso885915': 'ISO8859-15',
  425.     'iso_8859-15': 'ISO8859-15',
  426.     'iso8859-2': 'ISO8859-2',
  427.     'iso88592': 'ISO8859-2',
  428.     'iso_8859-2': 'ISO8859-2',
  429.     'iso88595': 'ISO8859-5',
  430.     'iso88596': 'ISO8859-6',
  431.     'iso88597': 'ISO8859-7',
  432.     'iso88598': 'ISO8859-8',
  433.     'iso88599': 'ISO8859-9',
  434.     'iso-2022-jp': 'JIS7',
  435.     'jis': 'JIS7',
  436.     'jis7': 'JIS7',
  437.     'sjis': 'SJIS',
  438.     'tis620': 'TACTIS',
  439.     'ajec': 'eucJP',
  440.     'eucjp': 'eucJP',
  441.     'ujis': 'eucJP',
  442.     'utf-8': 'utf',
  443.     'utf8': 'utf',
  444.     'utf8@ucs4': 'utf' }
  445. locale_alias = {
  446.     'american': 'en_US.ISO8859-1',
  447.     'ar': 'ar_AA.ISO8859-6',
  448.     'ar_aa': 'ar_AA.ISO8859-6',
  449.     'ar_sa': 'ar_SA.ISO8859-6',
  450.     'arabic': 'ar_AA.ISO8859-6',
  451.     'bg': 'bg_BG.ISO8859-5',
  452.     'bg_bg': 'bg_BG.ISO8859-5',
  453.     'bulgarian': 'bg_BG.ISO8859-5',
  454.     'c-french': 'fr_CA.ISO8859-1',
  455.     'c': 'C',
  456.     'c_c': 'C',
  457.     'cextend': 'en_US.ISO8859-1',
  458.     'chinese-s': 'zh_CN.eucCN',
  459.     'chinese-t': 'zh_TW.eucTW',
  460.     'croatian': 'hr_HR.ISO8859-2',
  461.     'cs': 'cs_CZ.ISO8859-2',
  462.     'cs_cs': 'cs_CZ.ISO8859-2',
  463.     'cs_cz': 'cs_CZ.ISO8859-2',
  464.     'cz': 'cz_CZ.ISO8859-2',
  465.     'cz_cz': 'cz_CZ.ISO8859-2',
  466.     'czech': 'cs_CS.ISO8859-2',
  467.     'da': 'da_DK.ISO8859-1',
  468.     'da_dk': 'da_DK.ISO8859-1',
  469.     'danish': 'da_DK.ISO8859-1',
  470.     'de': 'de_DE.ISO8859-1',
  471.     'de_at': 'de_AT.ISO8859-1',
  472.     'de_ch': 'de_CH.ISO8859-1',
  473.     'de_de': 'de_DE.ISO8859-1',
  474.     'dutch': 'nl_BE.ISO8859-1',
  475.     'ee': 'ee_EE.ISO8859-4',
  476.     'el': 'el_GR.ISO8859-7',
  477.     'el_gr': 'el_GR.ISO8859-7',
  478.     'en': 'en_US.ISO8859-1',
  479.     'en_au': 'en_AU.ISO8859-1',
  480.     'en_ca': 'en_CA.ISO8859-1',
  481.     'en_gb': 'en_GB.ISO8859-1',
  482.     'en_ie': 'en_IE.ISO8859-1',
  483.     'en_nz': 'en_NZ.ISO8859-1',
  484.     'en_uk': 'en_GB.ISO8859-1',
  485.     'en_us': 'en_US.ISO8859-1',
  486.     'eng_gb': 'en_GB.ISO8859-1',
  487.     'english': 'en_EN.ISO8859-1',
  488.     'english_uk': 'en_GB.ISO8859-1',
  489.     'english_united-states': 'en_US.ISO8859-1',
  490.     'english_us': 'en_US.ISO8859-1',
  491.     'es': 'es_ES.ISO8859-1',
  492.     'es_ar': 'es_AR.ISO8859-1',
  493.     'es_bo': 'es_BO.ISO8859-1',
  494.     'es_cl': 'es_CL.ISO8859-1',
  495.     'es_co': 'es_CO.ISO8859-1',
  496.     'es_cr': 'es_CR.ISO8859-1',
  497.     'es_ec': 'es_EC.ISO8859-1',
  498.     'es_es': 'es_ES.ISO8859-1',
  499.     'es_gt': 'es_GT.ISO8859-1',
  500.     'es_mx': 'es_MX.ISO8859-1',
  501.     'es_ni': 'es_NI.ISO8859-1',
  502.     'es_pa': 'es_PA.ISO8859-1',
  503.     'es_pe': 'es_PE.ISO8859-1',
  504.     'es_py': 'es_PY.ISO8859-1',
  505.     'es_sv': 'es_SV.ISO8859-1',
  506.     'es_uy': 'es_UY.ISO8859-1',
  507.     'es_ve': 'es_VE.ISO8859-1',
  508.     'et': 'et_EE.ISO8859-4',
  509.     'et_ee': 'et_EE.ISO8859-4',
  510.     'fi': 'fi_FI.ISO8859-1',
  511.     'fi_fi': 'fi_FI.ISO8859-1',
  512.     'finnish': 'fi_FI.ISO8859-1',
  513.     'fr': 'fr_FR.ISO8859-1',
  514.     'fr_be': 'fr_BE.ISO8859-1',
  515.     'fr_ca': 'fr_CA.ISO8859-1',
  516.     'fr_ch': 'fr_CH.ISO8859-1',
  517.     'fr_fr': 'fr_FR.ISO8859-1',
  518.     'fre_fr': 'fr_FR.ISO8859-1',
  519.     'french': 'fr_FR.ISO8859-1',
  520.     'french_france': 'fr_FR.ISO8859-1',
  521.     'ger_de': 'de_DE.ISO8859-1',
  522.     'german': 'de_DE.ISO8859-1',
  523.     'german_germany': 'de_DE.ISO8859-1',
  524.     'greek': 'el_GR.ISO8859-7',
  525.     'hebrew': 'iw_IL.ISO8859-8',
  526.     'hr': 'hr_HR.ISO8859-2',
  527.     'hr_hr': 'hr_HR.ISO8859-2',
  528.     'hu': 'hu_HU.ISO8859-2',
  529.     'hu_hu': 'hu_HU.ISO8859-2',
  530.     'hungarian': 'hu_HU.ISO8859-2',
  531.     'icelandic': 'is_IS.ISO8859-1',
  532.     'id': 'id_ID.ISO8859-1',
  533.     'id_id': 'id_ID.ISO8859-1',
  534.     'is': 'is_IS.ISO8859-1',
  535.     'is_is': 'is_IS.ISO8859-1',
  536.     'iso-8859-1': 'en_US.ISO8859-1',
  537.     'iso-8859-15': 'en_US.ISO8859-15',
  538.     'iso8859-1': 'en_US.ISO8859-1',
  539.     'iso8859-15': 'en_US.ISO8859-15',
  540.     'iso_8859_1': 'en_US.ISO8859-1',
  541.     'iso_8859_15': 'en_US.ISO8859-15',
  542.     'it': 'it_IT.ISO8859-1',
  543.     'it_ch': 'it_CH.ISO8859-1',
  544.     'it_it': 'it_IT.ISO8859-1',
  545.     'italian': 'it_IT.ISO8859-1',
  546.     'iw': 'iw_IL.ISO8859-8',
  547.     'iw_il': 'iw_IL.ISO8859-8',
  548.     'ja': 'ja_JP.eucJP',
  549.     'ja.jis': 'ja_JP.JIS7',
  550.     'ja.sjis': 'ja_JP.SJIS',
  551.     'ja_jp': 'ja_JP.eucJP',
  552.     'ja_jp.ajec': 'ja_JP.eucJP',
  553.     'ja_jp.euc': 'ja_JP.eucJP',
  554.     'ja_jp.eucjp': 'ja_JP.eucJP',
  555.     'ja_jp.iso-2022-jp': 'ja_JP.JIS7',
  556.     'ja_jp.jis': 'ja_JP.JIS7',
  557.     'ja_jp.jis7': 'ja_JP.JIS7',
  558.     'ja_jp.mscode': 'ja_JP.SJIS',
  559.     'ja_jp.sjis': 'ja_JP.SJIS',
  560.     'ja_jp.ujis': 'ja_JP.eucJP',
  561.     'japan': 'ja_JP.eucJP',
  562.     'japanese': 'ja_JP.SJIS',
  563.     'japanese-euc': 'ja_JP.eucJP',
  564.     'japanese.euc': 'ja_JP.eucJP',
  565.     'jp_jp': 'ja_JP.eucJP',
  566.     'ko': 'ko_KR.eucKR',
  567.     'ko_kr': 'ko_KR.eucKR',
  568.     'ko_kr.euc': 'ko_KR.eucKR',
  569.     'korean': 'ko_KR.eucKR',
  570.     'lt': 'lt_LT.ISO8859-4',
  571.     'lv': 'lv_LV.ISO8859-4',
  572.     'mk': 'mk_MK.ISO8859-5',
  573.     'mk_mk': 'mk_MK.ISO8859-5',
  574.     'nl': 'nl_NL.ISO8859-1',
  575.     'nl_be': 'nl_BE.ISO8859-1',
  576.     'nl_nl': 'nl_NL.ISO8859-1',
  577.     'no': 'no_NO.ISO8859-1',
  578.     'no_no': 'no_NO.ISO8859-1',
  579.     'norwegian': 'no_NO.ISO8859-1',
  580.     'pl': 'pl_PL.ISO8859-2',
  581.     'pl_pl': 'pl_PL.ISO8859-2',
  582.     'polish': 'pl_PL.ISO8859-2',
  583.     'portuguese': 'pt_PT.ISO8859-1',
  584.     'portuguese_brazil': 'pt_BR.ISO8859-1',
  585.     'posix': 'C',
  586.     'posix-utf2': 'C',
  587.     'pt': 'pt_PT.ISO8859-1',
  588.     'pt_br': 'pt_BR.ISO8859-1',
  589.     'pt_pt': 'pt_PT.ISO8859-1',
  590.     'ro': 'ro_RO.ISO8859-2',
  591.     'ro_ro': 'ro_RO.ISO8859-2',
  592.     'ru': 'ru_RU.ISO8859-5',
  593.     'ru_ru': 'ru_RU.ISO8859-5',
  594.     'rumanian': 'ro_RO.ISO8859-2',
  595.     'russian': 'ru_RU.ISO8859-5',
  596.     'serbocroatian': 'sh_YU.ISO8859-2',
  597.     'sh': 'sh_YU.ISO8859-2',
  598.     'sh_hr': 'sh_HR.ISO8859-2',
  599.     'sh_sp': 'sh_YU.ISO8859-2',
  600.     'sh_yu': 'sh_YU.ISO8859-2',
  601.     'sk': 'sk_SK.ISO8859-2',
  602.     'sk_sk': 'sk_SK.ISO8859-2',
  603.     'sl': 'sl_CS.ISO8859-2',
  604.     'sl_cs': 'sl_CS.ISO8859-2',
  605.     'sl_si': 'sl_SI.ISO8859-2',
  606.     'slovak': 'sk_SK.ISO8859-2',
  607.     'slovene': 'sl_CS.ISO8859-2',
  608.     'sp': 'sp_YU.ISO8859-5',
  609.     'sp_yu': 'sp_YU.ISO8859-5',
  610.     'spanish': 'es_ES.ISO8859-1',
  611.     'spanish_spain': 'es_ES.ISO8859-1',
  612.     'sr_sp': 'sr_SP.ISO8859-2',
  613.     'sv': 'sv_SE.ISO8859-1',
  614.     'sv_se': 'sv_SE.ISO8859-1',
  615.     'swedish': 'sv_SE.ISO8859-1',
  616.     'th_th': 'th_TH.TACTIS',
  617.     'tr': 'tr_TR.ISO8859-9',
  618.     'tr_tr': 'tr_TR.ISO8859-9',
  619.     'turkish': 'tr_TR.ISO8859-9',
  620.     'univ': 'en_US.utf',
  621.     'universal': 'en_US.utf',
  622.     'zh': 'zh_CN.eucCN',
  623.     'zh_cn': 'zh_CN.eucCN',
  624.     'zh_cn.big5': 'zh_TW.eucTW',
  625.     'zh_cn.euc': 'zh_CN.eucCN',
  626.     'zh_tw': 'zh_TW.eucTW',
  627.     'zh_tw.euc': 'zh_TW.eucTW' }
  628. windows_locale = {
  629.     1028: 'zh_TW',
  630.     2052: 'zh_CN',
  631.     1030: 'da_DK',
  632.     1043: 'nl_NL',
  633.     1033: 'en_US',
  634.     2057: 'en_UK',
  635.     3081: 'en_AU',
  636.     4105: 'en_CA',
  637.     5129: 'en_NZ',
  638.     6153: 'en_IE',
  639.     7177: 'en_ZA',
  640.     1035: 'fi_FI',
  641.     1036: 'fr_FR',
  642.     2060: 'fr_BE',
  643.     3084: 'fr_CA',
  644.     4108: 'fr_CH',
  645.     1031: 'de_DE',
  646.     1032: 'el_GR',
  647.     1037: 'iw_IL',
  648.     1039: 'is_IS',
  649.     1040: 'it_IT',
  650.     1041: 'ja_JA',
  651.     1044: 'no_NO',
  652.     2070: 'pt_PT',
  653.     3082: 'es_ES',
  654.     1089: 'sw_KE',
  655.     1053: 'sv_SE',
  656.     2077: 'sv_FI',
  657.     1055: 'tr_TR' }
  658.  
  659. def _print_locale():
  660.     ''' Test function.
  661.     '''
  662.     categories = { }
  663.     
  664.     def _init_categories(categories = categories):
  665.         for k, v in globals().items():
  666.             if k[:3] == 'LC_':
  667.                 categories[k] = v
  668.                 continue
  669.         
  670.  
  671.     _init_categories()
  672.     del categories['LC_ALL']
  673.     print 'Locale defaults as determined by getdefaultlocale():'
  674.     print '-' * 72
  675.     (lang, enc) = getdefaultlocale()
  676.     print 'Language: ',
  677.     if not lang:
  678.         pass
  679.     print '(undefined)'
  680.     print 'Encoding: ',
  681.     if not enc:
  682.         pass
  683.     print '(undefined)'
  684.     print 
  685.     print 'Locale settings on startup:'
  686.     print '-' * 72
  687.     for name, category in categories.items():
  688.         print name, '...'
  689.         (lang, enc) = getlocale(category)
  690.         print '   Language: ',
  691.         if not lang:
  692.             pass
  693.         print '(undefined)'
  694.         print '   Encoding: ',
  695.         if not enc:
  696.             pass
  697.         print '(undefined)'
  698.         print 
  699.     
  700.     print 
  701.     print 'Locale settings after calling resetlocale():'
  702.     print '-' * 72
  703.     resetlocale()
  704.     for name, category in categories.items():
  705.         print name, '...'
  706.         (lang, enc) = getlocale(category)
  707.         print '   Language: ',
  708.         if not lang:
  709.             pass
  710.         print '(undefined)'
  711.         print '   Encoding: ',
  712.         if not enc:
  713.             pass
  714.         print '(undefined)'
  715.         print 
  716.     
  717.     
  718.     try:
  719.         setlocale(LC_ALL, '')
  720.     except:
  721.         print 'NOTE:'
  722.         print 'setlocale(LC_ALL, "") does not support the default locale'
  723.         print 'given in the OS environment variables.'
  724.  
  725.     print 
  726.     print 'Locale settings after calling setlocale(LC_ALL, ""):'
  727.     print '-' * 72
  728.     for name, category in categories.items():
  729.         print name, '...'
  730.         (lang, enc) = getlocale(category)
  731.         print '   Language: ',
  732.         if not lang:
  733.             pass
  734.         print '(undefined)'
  735.         print '   Encoding: ',
  736.         if not enc:
  737.             pass
  738.         print '(undefined)'
  739.         print 
  740.     
  741.  
  742.  
  743. try:
  744.     LC_MESSAGES
  745. except NameError:
  746.     pass
  747.  
  748. __all__.append('LC_MESSAGES')
  749. if __name__ == '__main__':
  750.     print 'Locale aliasing:'
  751.     print 
  752.     _print_locale()
  753.     print 
  754.     print 'Number formatting:'
  755.     print 
  756.     _test()
  757.  
  758.