Orbits  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
Classes | Functions | Variables
locale Namespace Reference

Classes

class  _unicode
 

Functions

def localeconv
 
def setlocale
 
def strcoll
 
def strxfrm
 
def _grouping_intervals
 Number formatting APIs. More...
 
def _group
 
def _strip_padding
 
def format
 
def _format
 
def format_string
 
def currency
 
def str
 
def atof
 
def atoi
 
def _test
 
def normalize
 
def _parse_localename
 
def _build_localename
 
def getdefaultlocale
 
def getlocale
 
def resetlocale
 
def getpreferredencoding
 
def _print_locale
 

Variables

 _unicode = unicode
 
list __all__
 
int CHAR_MAX = 127
 
int LC_ALL = 6
 
int LC_COLLATE = 3
 
int LC_CTYPE = 0
 
int LC_MESSAGES = 5
 
int LC_MONETARY = 4
 
int LC_NUMERIC = 1
 
int LC_TIME = 2
 
 Error = ValueError
 
 _localeconv = localeconv
 
dictionary _override_localeconv = {}
 
tuple _percent_re
 
 _setlocale = setlocale
 Locale name aliasing engine. More...
 
string _ascii_lower_map = ''
 
dictionary locale_encoding_alias
 Database. More...
 
dictionary locale_alias
 
dictionary windows_locale
 

Detailed Description

Locale support.

The module provides low-level access to the C lib's locale APIs
and adds high level number formatting APIs as well as a locale
aliasing engine to complement these.

The aliasing engine includes support for many commonly used locale
names and maps them to values suitable for passing to the C lib's
setlocale() function. It also includes default encodings for all
supported locale names.

Function Documentation

def locale._build_localename (   localetuple)
private
Builds a locale code from the given tuple (language code,
    encoding).

    No aliasing or normalizing takes place.
def locale._format (   percent,
  value,
  grouping = False,
  monetary = False,
  additional 
)
private
def locale._group (   s,
  monetary = False 
)
private
def locale._grouping_intervals (   grouping)
private

Number formatting APIs.

def locale._parse_localename (   localename)
private
Parses the locale code for localename and returns the
    result as tuple (language code, encoding).

    The localename is normalized and passed through the locale
    alias engine. A ValueError is raised in case the locale name
    cannot be parsed.

    The language code corresponds to RFC 1766.  code and encoding
    can be None in case the values cannot be determined or are
    unknown to this implementation.
def locale._print_locale ( )
private
Test function.
def locale._strip_padding (   s,
  amount 
)
private
def locale._test ( )
private
def locale.atof (   string,
  func = float 
)
def locale.atoi (   str)
def locale.currency (   val,
  symbol = True,
  grouping = False,
  international = False 
)
Formats val according to the currency settings
in the current locale.
def locale.format (   percent,
  value,
  grouping = False,
  monetary = False,
  additional 
)
Returns the locale-aware substitution of a %? specifier
(percent).

additional is for format strings which contain one or more
'*' modifiers.
def locale.format_string (   f,
  val,
  grouping = False 
)
Formats a string in the same way that the % formatting would use,
but takes the current locale into account.
Grouping is applied if the third parameter is true.
def locale.getdefaultlocale (   envvars = ('LC_ALL', 'LC_CTYPE',
  LANG,
  LANGUAGE 
)
Tries to determine the default locale settings and returns
    them as tuple (language code, encoding).

    According to POSIX, a program which has not called
    setlocale(LC_ALL, "") runs using the portable 'C' locale.
    Calling setlocale(LC_ALL, "") lets it use the default locale as
    defined by the LANG variable. Since we don't want to interfere
    with the current locale setting we thus emulate the behavior
    in the way described above.

    To maintain compatibility with other platforms, not only the
    LANG variable is tested, but a list of variables given as
    envvars parameter. The first found to be defined will be
    used. envvars defaults to the search path used in GNU gettext;
    it must always contain the variable name 'LANG'.

    Except for the code 'C', the language code corresponds to RFC
    1766.  code and encoding can be None in case the values cannot
    be determined.
def locale.getlocale (   category = LC_CTYPE)
Returns the current setting for the given locale category as
    tuple (language code, encoding).

    category may be one of the LC_* value except LC_ALL. It
    defaults to LC_CTYPE.

    Except for the code 'C', the language code corresponds to RFC
    1766.  code and encoding can be None in case the values cannot
    be determined.
def locale.getpreferredencoding (   do_setlocale = True)
Return the charset that the user is likely using.
Return the charset that the user is likely using,
by looking at environment variables.
Return the charset that the user is likely using,
according to the system configuration.
def locale.localeconv ( )
localeconv() -> dict.
    Returns numeric and monetary locale-specific parameters.
def locale.normalize (   localename)
Returns a normalized locale code for the given locale
    name.

    The returned locale code is formatted for use with
    setlocale().

    If normalization fails, the original name is returned
    unchanged.

    If the given encoding is not known, the function defaults to
    the default encoding for the locale code just like setlocale()
    does.
def locale.resetlocale (   category = LC_ALL)
Sets the locale for category to the default setting.

    The default setting is determined by calling
    getdefaultlocale(). category defaults to LC_ALL.
def locale.setlocale (   category,
  locale = None 
)
setlocale(integer,string=None) -> string.
    Activates/queries locale processing.
Set the locale for the given category.  The locale can be
    a string, an iterable of two strings (language code and encoding),
    or None.

    Iterables are converted to strings using the locale aliasing
    engine.  Locale strings are passed directly to the C lib.

    category may be given as one of the LC_* values.
def locale.str (   val)
Convert float to integer, taking the locale into account.
def locale.strcoll (   a,
  b 
)
strcoll(string,string) -> int.
    Compares two strings according to the locale.
def locale.strxfrm (   s)
strxfrm(string) -> string.
    Returns a string that behaves for cmp locale-aware.

Variable Documentation

list locale.__all__
Initial value:
1 = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
2  "setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm",
3  "str", "atof", "atoi", "format", "format_string", "currency",
4  "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
5  "LC_NUMERIC", "LC_ALL", "CHAR_MAX"]
string locale._ascii_lower_map = ''
locale._localeconv = localeconv
dictionary locale._override_localeconv = {}
tuple locale._percent_re
Initial value:
1 = re.compile(r'%(?:\((?P<key>.*?)\))?'
2  r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
locale._setlocale = setlocale

Locale name aliasing engine.

locale._unicode = unicode
int locale.CHAR_MAX = 127
locale.Error = ValueError
int locale.LC_ALL = 6
int locale.LC_COLLATE = 3
int locale.LC_CTYPE = 0
int locale.LC_MESSAGES = 5
int locale.LC_MONETARY = 4
int locale.LC_NUMERIC = 1
int locale.LC_TIME = 2
dictionary locale.locale_alias
dictionary locale.locale_encoding_alias

Database.

The following data was extracted from the locale.alias file which comes with X11 and then hand edited removing the explicit encoding definitions and adding some more aliases. The file is usually available as /usr/lib/X11/locale/locale.alias.

dictionary locale.windows_locale

Copyright 2014 Google Inc. All rights reserved.