Top Description Fields Constructors Methods
org.python.modules._locale

public Class _locale

extends Object
implements ClassDictInit
Class Inheritance
All Implemented Interfaces
org.python.core.ClassDictInit
Imports
java.nio.charset.Charset, java.util.Arrays, .Collections, .HashSet, .Locale, .Set, org.python.core.ClassDictInit, .Py, .PyDictionary, .PyException, .PyInteger, .PyObject, .PyString, .PyStringMap, .PySystemState

Java native implementation of underlying locale functions, fitting the interface defined or implied by the Python locale module. Functional documentation can be found in the Python module docstring. This class depends on registry key 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.

Since
Jython 2.7.2

Field Summary

Modifier and TypeField 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<Locale>
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 locale module exposes _locale.Error as locale.Error.

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
private static void
private static void
private static void
public static void
public static DateSymbolLocale
getDateSymbolLocale()

Current DateSymbolLocale used by the Python interpreter.

public static void
private static boolean
private static Locale
loadLocale(String language)

public static PyDictionary
public static PyException
protected static void
putConvEntry(PyDictionary result, String key, String value)

Put key mapping to value into result, converting to PyStrings as needed

protected static void
putConvEntry(PyDictionary result, String key, char value)

Put key mapping to value into result, converting to PyStrings as needed

protected static void
putConvEntry(PyDictionary result, String key, PyObject value)

Put key mapping to value into result, converting key to PyString.

public static PyString
setlocale(PyInteger category)

public static PyString
setlocale(PyInteger category, PyString locale)

Java Locale loading behaviour is quite forgiving, or uninformative, depending on your perspective.

public static int
public static PyString
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__doc__back to summary
public static final PyString __doc__
__doc___localeconvback to summary
public static PyString __doc___localeconv
__doc___setlocaleback to summary
public static PyString __doc___setlocale
__doc___strcollback to summary
public static PyString __doc___strcoll
__doc___strxfrmback to summary
public static PyString __doc___strxfrm
__LC_ADDRESSback to summary
private static final int __LC_ADDRESS
Annotations
@SuppressWarnings:unused
__LC_ALLback to summary
private static final int __LC_ALL
__LC_COLLATEback to summary
private static final int __LC_COLLATE
__LC_CTYPEback to summary
private static final int __LC_CTYPE
__LC_IDENTIFICATIONback to summary
private static final int __LC_IDENTIFICATION
Annotations
@SuppressWarnings:unused
__LC_MEASUREMENTback to summary
private static final int __LC_MEASUREMENT
Annotations
@SuppressWarnings:unused
__LC_MESSAGESback to summary
private static final int __LC_MESSAGES
__LC_MONETARYback to summary
private static final int __LC_MONETARY
__LC_NAMEback to summary
private static final int __LC_NAME
Annotations
@SuppressWarnings:unused
__LC_NUMERICback to summary
private static final int __LC_NUMERIC
__LC_PAPERback to summary
private static final int __LC_PAPER
Annotations
@SuppressWarnings:unused
__LC_TELEPHONEback to summary
private static final int __LC_TELEPHONE
Annotations
@SuppressWarnings:unused
__LC_TIMEback to summary
private static final int __LC_TIME
AVAILABLE_LOCALESback to summary
private static final Set<Locale> AVAILABLE_LOCALES
C_LOCALE_PY_STRINGback to summary
public static final PyString C_LOCALE_PY_STRING
CHAR_MAXback to summary
public static final int CHAR_MAX
CHAR_MAX_PY_INTback to summary
public static final PyInteger CHAR_MAX_PY_INT
currentLocaleback to summary
private static volatile PyLocale currentLocale
DEFAULT_LOCALEback to summary
private static final DateSymbolLocale DEFAULT_LOCALE
Errorback to summary
public static PyObject Error

The locale module exposes _locale.Error as locale.Error. Some Python functions, including strptime(), depend on locale.Error, making it part of the public API for native locale implementations.

LC_ALLback to summary
public static final PyInteger LC_ALL
LC_COLLATEback to summary
public static final PyInteger LC_COLLATE
LC_CTYPEback to summary
public static final PyInteger LC_CTYPE
LC_MESSAGESback to summary
public static final PyInteger LC_MESSAGES
LC_MONETARYback to summary
public static final PyInteger LC_MONETARY
LC_NUMERICback to summary
public static final PyInteger LC_NUMERIC
LC_TIMEback to summary
public static final PyInteger LC_TIME
LOCALE_CONTROL_JYTHON2_LEGACYback to summary
public static final String LOCALE_CONTROL_JYTHON2_LEGACY
LOCALE_CONTROL_SETTABLEback to summary
public static final String LOCALE_CONTROL_SETTABLE

Constructor Detail

_localeback to summary
public _locale()

Method Detail

changeCurrentLocaleback to summary
private static void changeCurrentLocale(PyLocale pyLocale)
changeCurrentLocaleToCback to summary
private static void changeCurrentLocaleToC()
changeCurrentLocaleToDefaultback to summary
private static void changeCurrentLocaleToDefault()
changeLocaleFromLocaleStringback to summary
private static void changeLocaleFromLocaleString(PyString locale)
classDictInitback to summary
public static void classDictInit(PyObject dict)
getDateSymbolLocaleback to summary
public static DateSymbolLocale getDateSymbolLocale()

Current DateSymbolLocale used by the Python interpreter. This object will no longer reflect the current state after subsequent calls to setlocale.

initClassExceptionsback to summary
public static void initClassExceptions(PyObject exceptions)
Annotations
@SuppressWarnings:serial
isAvailableLocaleback to summary
private static boolean isAvailableLocale(Locale locale)
loadLocaleback to summary
private static Locale loadLocale(String language)
localeconvback to summary
public static PyDictionary localeconv()
LocaleExceptionback to summary
public static PyException LocaleException(String message)
putConvEntryback to summary
protected static void putConvEntry(PyDictionary result, String key, String value)

Put key mapping to value into result, converting to PyStrings as needed

putConvEntryback to summary
protected static void putConvEntry(PyDictionary result, String key, char value)

Put key mapping to value into result, converting to PyStrings as needed

putConvEntryback to summary
protected static void putConvEntry(PyDictionary result, String key, PyObject value)

Put key mapping to value into result, converting key to PyString.

setlocaleback to summary
public static PyString setlocale(PyInteger category)
setlocaleback 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.

strcollback to summary
public static int strcoll(PyString str1, PyString str2)
strxfrmback to summary
public static PyString strxfrm(PyString str1)