summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2000-06-08 17:49:41 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2000-06-08 17:49:41 (GMT)
commit2348114ba839977fc831ce786e89ab1c6780fe4c (patch)
treea5e76909895817ba049ec943ebd704c9009ef81e /Lib
parentd2412a35b13b18b5de8c522aeeee7cba6d740ae4 (diff)
downloadcpython-2348114ba839977fc831ce786e89ab1c6780fe4c.zip
cpython-2348114ba839977fc831ce786e89ab1c6780fe4c.tar.gz
cpython-2348114ba839977fc831ce786e89ab1c6780fe4c.tar.bz2
Marc-Andre Lemburg <mal@lemburg.com>:
Added emulations of the C APIs in _locale to be used when the _locale module is not enabled. They return the correct values assuming the 'C' locale.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/locale.py64
1 files changed, 61 insertions, 3 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index cb01821..a4e1e44 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -13,9 +13,67 @@
import string
-### C lib locale APIs
-
-from _locale import *
+### Load C lib locale APIs or use an emulation
+
+try:
+ from _locale import *
+
+except ImportError:
+
+ CHAR_MAX = 127
+ LC_ALL = 6
+ LC_COLLATE = 3
+ LC_CTYPE = 0
+ LC_MESSAGES = 5
+ LC_MONETARY = 4
+ LC_NUMERIC = 1
+ LC_TIME = 2
+ Error = ValueError
+
+ def localeconv():
+ """ localeconv() -> dict.
+ Returns numeric and monetary locale-specific parameters.
+ """
+ # 'C' locale default values
+ return {'grouping': [127],
+ 'currency_symbol': '',
+ 'n_sign_posn': 127,
+ 'p_cs_precedes': 127,
+ 'n_cs_precedes': 127,
+ 'mon_grouping': [],
+ 'n_sep_by_space': 127,
+ 'decimal_point': '.',
+ 'negative_sign': '',
+ 'positive_sign': '',
+ 'p_sep_by_space': 127,
+ 'int_curr_symbol': '',
+ 'p_sign_posn': 127,
+ 'thousands_sep': '',
+ 'mon_thousands_sep': '',
+ 'frac_digits': 127,
+ 'mon_decimal_point': '',
+ 'int_frac_digits': 127}
+
+ def setlocale(category, value=None):
+ """ setlocale(integer,string=None) -> string.
+ Activates/queries locale processing.
+ """
+ if value is not None and \
+ value is not 'C':
+ raise Error,'_locale emulation only supports "C" locale'
+ return 'C'
+
+ def strcoll(a,b):
+ """ strcoll(string,string) -> int.
+ Compares two strings according to the locale.
+ """
+ return cmp(a,b)
+
+ def strxfrm(s):
+ """ strxfrm(string) -> string.
+ Returns a string that behaves for cmp locale-aware.
+ """
+ return s
### Number formatting APIs