org.python.core.RegistryKey#PYTHON_LOCALE_CONTROL . Additional implementation
details for users of this class are captured below.
Unicode. In general, Java and its locale settings are quite unicode heavy, making rich use of different symbols for e.g. currencies. This solution allows some of that to leak through by encoding the Java locale value with the current character encoding. The Python locale module is quite conservative and tends to keep things as solely strings. Python 2.x usually supports only string / ascii by default in many cases, and only unicode when asked. This is a little less conservative while only allowing values consistent with the current encoding.
An example of this is some Python implementations using EUR rather than the Euro symbol €
('u20ac'), probably because € is only available in Unicode. In the Java implementation,
if UTF-8 encoding is set, the resulting entry in localeconv()['currency_code'] is
'\xe2\x82\xac'. This can be used by print() and related functions directly.
Encoding failures for currency_symbol fall back to int_curr_symbol (eg EUR).
Encoding failures for negative_sign, which are sometimes unicode, fall back to an ANSI
hyphen ('-'). Other encoding failures fallback to the 'C' locale values, where possible.
The C emulation locale uses only ANSI characters in non-unicode strings, in keeping with it being the locale of last resort and maximum compatibility.
Positive sign position (p_sign_posn) is not a distinguished concept in Java and so this
is hardcoded to 3.
This class ensures read/write consistency, when changing locales via
setlocale(PyInteger, PyString), by declaring private variable currentLocale as
volatile, and only assigning it immutable objects. It does not lock to guarantee sequencing of
setLocale() calls from separate threads. In the rare cases where that would be needed, it
is the responsibility of the calling code.
| Modifier and Type | Field and Description |
|---|---|
| public static final PyString | |
| public static PyString | |
| public static PyString | |
| public static PyString | |
| public static PyString | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final Set | |
| public static final PyString | |
| public static final int | |
| public static final PyInteger | |
| private static volatile PyLocale | |
| private static final DateSymbolLocale | |
| public static PyObject | Error
The |
| public static final PyInteger | |
| public static final PyInteger | |
| public static final PyInteger | |
| public static final PyInteger | |
| public static final PyInteger | |
| public static final PyInteger | |
| public static final PyInteger | |
| public static final String | |
| public static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| private static void | |
| private static void | |
| private static void | |
| public static void | |
| public static DateSymbolLocale | |
| public static void | |
| private static boolean | |
| private static Locale | |
| public static PyDictionary | |
| public static PyException | |
| protected static void | putConvEntry(PyDictionary result, String key, String value)
Put |
| protected static void | putConvEntry(PyDictionary result, String key, char value)
Put |
| protected static void | putConvEntry(PyDictionary result, String key, PyObject value)
Put |
| public static PyString | |
| public static PyString | |
| public static int | |
| public static PyString |
| __doc__ | back to summary |
|---|---|
| public static final PyString __doc__ | |
| __doc___localeconv | back to summary |
|---|---|
| public static PyString __doc___localeconv | |
| __doc___setlocale | back to summary |
|---|---|
| public static PyString __doc___setlocale | |
| __doc___strcoll | back to summary |
|---|---|
| public static PyString __doc___strcoll | |
| __doc___strxfrm | back to summary |
|---|---|
| public static PyString __doc___strxfrm | |
| __LC_ADDRESS | back to summary |
|---|---|
private static final int __LC_ADDRESS
| |
| __LC_ALL | back to summary |
|---|---|
| private static final int __LC_ALL | |
| __LC_COLLATE | back to summary |
|---|---|
| private static final int __LC_COLLATE | |
| __LC_CTYPE | back to summary |
|---|---|
| private static final int __LC_CTYPE | |
| __LC_IDENTIFICATION | back to summary |
|---|---|
private static final int __LC_IDENTIFICATION
| |
| __LC_MEASUREMENT | back to summary |
|---|---|
private static final int __LC_MEASUREMENT
| |
| __LC_MESSAGES | back to summary |
|---|---|
| private static final int __LC_MESSAGES | |
| __LC_MONETARY | back to summary |
|---|---|
| private static final int __LC_MONETARY | |
| __LC_NAME | back to summary |
|---|---|
private static final int __LC_NAME
| |
| __LC_NUMERIC | back to summary |
|---|---|
| private static final int __LC_NUMERIC | |
| __LC_PAPER | back to summary |
|---|---|
private static final int __LC_PAPER
| |
| __LC_TELEPHONE | back to summary |
|---|---|
private static final int __LC_TELEPHONE
| |
| __LC_TIME | back to summary |
|---|---|
| private static final int __LC_TIME | |
| AVAILABLE_LOCALES | back to summary |
|---|---|
| private static final Set<Locale> AVAILABLE_LOCALES | |
| C_LOCALE_PY_STRING | back to summary |
|---|---|
| public static final PyString C_LOCALE_PY_STRING | |
| CHAR_MAX | back to summary |
|---|---|
| public static final int CHAR_MAX | |
| CHAR_MAX_PY_INT | back to summary |
|---|---|
| public static final PyInteger CHAR_MAX_PY_INT | |
| currentLocale | back to summary |
|---|---|
| private static volatile PyLocale currentLocale | |
| DEFAULT_LOCALE | back to summary |
|---|---|
| private static final DateSymbolLocale DEFAULT_LOCALE | |
| Error | back to summary |
|---|---|
| public static PyObject Error The | |
| LC_ALL | back to summary |
|---|---|
| public static final PyInteger LC_ALL | |
| LC_COLLATE | back to summary |
|---|---|
| public static final PyInteger LC_COLLATE | |
| LC_CTYPE | back to summary |
|---|---|
| public static final PyInteger LC_CTYPE | |
| LC_MESSAGES | back to summary |
|---|---|
| public static final PyInteger LC_MESSAGES | |
| LC_MONETARY | back to summary |
|---|---|
| public static final PyInteger LC_MONETARY | |
| LC_NUMERIC | back to summary |
|---|---|
| public static final PyInteger LC_NUMERIC | |
| LC_TIME | back to summary |
|---|---|
| public static final PyInteger LC_TIME | |
| LOCALE_CONTROL_JYTHON2_LEGACY | back to summary |
|---|---|
| public static final String LOCALE_CONTROL_JYTHON2_LEGACY | |
| LOCALE_CONTROL_SETTABLE | back to summary |
|---|---|
| public static final String LOCALE_CONTROL_SETTABLE | |
| _locale | back to summary |
|---|---|
| public _locale() | |
| changeCurrentLocale | back to summary |
|---|---|
| private static void changeCurrentLocale(PyLocale pyLocale) | |
| changeCurrentLocaleToC | back to summary |
|---|---|
| private static void changeCurrentLocaleToC() | |
| changeCurrentLocaleToDefault | back to summary |
|---|---|
| private static void changeCurrentLocaleToDefault() | |
| changeLocaleFromLocaleString | back to summary |
|---|---|
| private static void changeLocaleFromLocaleString(PyString locale) | |
| classDictInit | back to summary |
|---|---|
| public static void classDictInit(PyObject dict) | |
| getDateSymbolLocale | back to summary |
|---|---|
| public static DateSymbolLocale getDateSymbolLocale() Current | |
| initClassExceptions | back to summary |
|---|---|
public static void initClassExceptions(PyObject exceptions)
| |
| isAvailableLocale | back to summary |
|---|---|
| private static boolean isAvailableLocale(Locale locale) | |
| loadLocale | back to summary |
|---|---|
| private static Locale loadLocale(String language) | |
| localeconv | back to summary |
|---|---|
| public static PyDictionary localeconv() | |
| LocaleException | back to summary |
|---|---|
| public static PyException LocaleException(String message) | |
| putConvEntry | back to summary |
|---|---|
| protected static void putConvEntry(PyDictionary result, String key, String value) Put | |
| putConvEntry | back to summary |
|---|---|
| protected static void putConvEntry(PyDictionary result, String key, char value) Put | |
| putConvEntry | back to summary |
|---|---|
| protected static void putConvEntry(PyDictionary result, String key, PyObject value) Put | |
| setlocale | back to summary |
|---|---|
| public static PyString setlocale(PyInteger category) | |
| setlocale | back to summary |
|---|---|
| public static PyString setlocale(PyInteger category, PyString locale) Java Locale loading behaviour is quite forgiving, or uninformative, depending on your perspective. It will return a dummy locale for any language tag that fits the syntax, or make various attempts to approximate a locale. This solution instead follows the stricter Python behaviour of requiring a particular locale to be installed. | |
| strcoll | back to summary |
|---|---|
| public static int strcoll(PyString str1, PyString str2) | |
| strxfrm | back to summary |
|---|---|
| public static PyString strxfrm(PyString str1) | |