This commit was manufactured by cvs2svn to create tag 'r234c1'.
[python/dscho.git] / Modules / _localemodule.c
blob363a823f3df15e1d4ba4589cc24384b1ba43d846
1 /***********************************************************
2 Copyright (C) 1997, 2002, 2003 Martin von Loewis
4 Permission to use, copy, modify, and distribute this software and its
5 documentation for any purpose and without fee is hereby granted,
6 provided that the above copyright notice appear in all copies.
8 This software comes with no warranty. Use at your own risk.
10 ******************************************************************/
12 #include "Python.h"
14 #include <stdio.h>
15 #include <errno.h>
16 #include <locale.h>
17 #include <string.h>
18 #include <ctype.h>
20 #ifdef HAVE_LANGINFO_H
21 #include <langinfo.h>
22 #endif
24 #ifdef HAVE_LIBINTL_H
25 #include <libintl.h>
26 #endif
28 #ifdef HAVE_WCHAR_H
29 #include <wchar.h>
30 #endif
32 #if defined(MS_WINDOWS)
33 #define WIN32_LEAN_AND_MEAN
34 #include <windows.h>
35 #endif
37 #if defined(__APPLE__) || defined(__MWERKS__)
38 #include "macglue.h"
39 #endif
41 #ifdef RISCOS
42 char *strdup(const char *);
43 #endif
45 PyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");
47 static PyObject *Error;
49 /* support functions for formatting floating point numbers */
51 PyDoc_STRVAR(setlocale__doc__,
52 "(integer,string=None) -> string. Activates/queries locale processing.");
54 /* to record the LC_NUMERIC settings */
55 static PyObject* grouping = NULL;
56 static PyObject* thousands_sep = NULL;
57 static PyObject* decimal_point = NULL;
58 /* if non-null, indicates that LC_NUMERIC is different from "C" */
59 static char* saved_numeric = NULL;
61 /* the grouping is terminated by either 0 or CHAR_MAX */
62 static PyObject*
63 copy_grouping(char* s)
65 int i;
66 PyObject *result, *val = NULL;
68 if (s[0] == '\0')
69 /* empty string: no grouping at all */
70 return PyList_New(0);
72 for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)
73 ; /* nothing */
75 result = PyList_New(i+1);
76 if (!result)
77 return NULL;
79 i = -1;
80 do {
81 i++;
82 val = PyInt_FromLong(s[i]);
83 if (!val)
84 break;
85 if (PyList_SetItem(result, i, val)) {
86 Py_DECREF(val);
87 val = NULL;
88 break;
90 } while (s[i] != '\0' && s[i] != CHAR_MAX);
92 if (!val) {
93 Py_DECREF(result);
94 return NULL;
97 return result;
100 static void
101 fixup_ulcase(void)
103 PyObject *mods, *strop, *string, *ulo;
104 unsigned char ul[256];
105 int n, c;
107 /* find the string and strop modules */
108 mods = PyImport_GetModuleDict();
109 if (!mods)
110 return;
111 string = PyDict_GetItemString(mods, "string");
112 if (string)
113 string = PyModule_GetDict(string);
114 strop=PyDict_GetItemString(mods, "strop");
115 if (strop)
116 strop = PyModule_GetDict(strop);
117 if (!string && !strop)
118 return;
120 /* create uppercase map string */
121 n = 0;
122 for (c = 0; c < 256; c++) {
123 if (isupper(c))
124 ul[n++] = c;
126 ulo = PyString_FromStringAndSize((const char *)ul, n);
127 if (!ulo)
128 return;
129 if (string)
130 PyDict_SetItemString(string, "uppercase", ulo);
131 if (strop)
132 PyDict_SetItemString(strop, "uppercase", ulo);
133 Py_DECREF(ulo);
135 /* create lowercase string */
136 n = 0;
137 for (c = 0; c < 256; c++) {
138 if (islower(c))
139 ul[n++] = c;
141 ulo = PyString_FromStringAndSize((const char *)ul, n);
142 if (!ulo)
143 return;
144 if (string)
145 PyDict_SetItemString(string, "lowercase", ulo);
146 if (strop)
147 PyDict_SetItemString(strop, "lowercase", ulo);
148 Py_DECREF(ulo);
150 /* create letters string */
151 n = 0;
152 for (c = 0; c < 256; c++) {
153 if (isalpha(c))
154 ul[n++] = c;
156 ulo = PyString_FromStringAndSize((const char *)ul, n);
157 if (!ulo)
158 return;
159 if (string)
160 PyDict_SetItemString(string, "letters", ulo);
161 Py_DECREF(ulo);
164 static PyObject*
165 PyLocale_setlocale(PyObject* self, PyObject* args)
167 int category;
168 char *locale = NULL, *result;
169 PyObject *result_object;
170 struct lconv *lc;
172 if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
173 return NULL;
175 if (locale) {
176 /* set locale */
177 result = setlocale(category, locale);
178 if (!result) {
179 /* operation failed, no setting was changed */
180 PyErr_SetString(Error, "unsupported locale setting");
181 return NULL;
183 result_object = PyString_FromString(result);
184 if (!result_object)
185 return NULL;
186 /* record changes to LC_NUMERIC */
187 if (category == LC_NUMERIC || category == LC_ALL) {
188 if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0) {
189 /* user just asked for default numeric locale */
190 if (saved_numeric)
191 free(saved_numeric);
192 saved_numeric = NULL;
193 } else {
194 /* remember values */
195 lc = localeconv();
196 Py_XDECREF(grouping);
197 grouping = copy_grouping(lc->grouping);
198 Py_XDECREF(thousands_sep);
199 thousands_sep = PyString_FromString(lc->thousands_sep);
200 Py_XDECREF(decimal_point);
201 decimal_point = PyString_FromString(lc->decimal_point);
202 if (saved_numeric)
203 free(saved_numeric);
204 saved_numeric = strdup(locale);
205 /* restore to "C" */
206 setlocale(LC_NUMERIC, "C");
209 /* record changes to LC_CTYPE */
210 if (category == LC_CTYPE || category == LC_ALL)
211 fixup_ulcase();
212 /* things that got wrong up to here are ignored */
213 PyErr_Clear();
214 } else {
215 /* get locale */
216 /* restore LC_NUMERIC first, if appropriate */
217 if (saved_numeric)
218 setlocale(LC_NUMERIC, saved_numeric);
219 result = setlocale(category, NULL);
220 if (!result) {
221 PyErr_SetString(Error, "locale query failed");
222 return NULL;
224 result_object = PyString_FromString(result);
225 /* restore back to "C" */
226 if (saved_numeric)
227 setlocale(LC_NUMERIC, "C");
229 return result_object;
232 PyDoc_STRVAR(localeconv__doc__,
233 "() -> dict. Returns numeric and monetary locale-specific parameters.");
235 static PyObject*
236 PyLocale_localeconv(PyObject* self)
238 PyObject* result;
239 struct lconv *l;
240 PyObject *x;
242 result = PyDict_New();
243 if (!result)
244 return NULL;
246 /* if LC_NUMERIC is different in the C library, use saved value */
247 l = localeconv();
249 /* hopefully, the localeconv result survives the C library calls
250 involved herein */
252 #define RESULT_STRING(s)\
253 x = PyString_FromString(l->s);\
254 if (!x) goto failed;\
255 PyDict_SetItemString(result, #s, x);\
256 Py_XDECREF(x)
258 #define RESULT_INT(i)\
259 x = PyInt_FromLong(l->i);\
260 if (!x) goto failed;\
261 PyDict_SetItemString(result, #i, x);\
262 Py_XDECREF(x)
264 /* Numeric information */
265 if (saved_numeric){
266 /* cannot use localeconv results */
267 PyDict_SetItemString(result, "decimal_point", decimal_point);
268 PyDict_SetItemString(result, "grouping", grouping);
269 PyDict_SetItemString(result, "thousands_sep", thousands_sep);
270 } else {
271 RESULT_STRING(decimal_point);
272 RESULT_STRING(thousands_sep);
273 x = copy_grouping(l->grouping);
274 if (!x)
275 goto failed;
276 PyDict_SetItemString(result, "grouping", x);
277 Py_XDECREF(x);
280 /* Monetary information */
281 RESULT_STRING(int_curr_symbol);
282 RESULT_STRING(currency_symbol);
283 RESULT_STRING(mon_decimal_point);
284 RESULT_STRING(mon_thousands_sep);
285 x = copy_grouping(l->mon_grouping);
286 if (!x)
287 goto failed;
288 PyDict_SetItemString(result, "mon_grouping", x);
289 Py_XDECREF(x);
290 RESULT_STRING(positive_sign);
291 RESULT_STRING(negative_sign);
292 RESULT_INT(int_frac_digits);
293 RESULT_INT(frac_digits);
294 RESULT_INT(p_cs_precedes);
295 RESULT_INT(p_sep_by_space);
296 RESULT_INT(n_cs_precedes);
297 RESULT_INT(n_sep_by_space);
298 RESULT_INT(p_sign_posn);
299 RESULT_INT(n_sign_posn);
300 return result;
302 failed:
303 Py_XDECREF(result);
304 Py_XDECREF(x);
305 return NULL;
308 PyDoc_STRVAR(strcoll__doc__,
309 "string,string -> int. Compares two strings according to the locale.");
311 static PyObject*
312 PyLocale_strcoll(PyObject* self, PyObject* args)
314 #if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)
315 char *s1,*s2;
317 if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
318 return NULL;
319 return PyInt_FromLong(strcoll(s1, s2));
320 #else
321 PyObject *os1, *os2, *result = NULL;
322 wchar_t *ws1 = NULL, *ws2 = NULL;
323 int rel1 = 0, rel2 = 0, len1, len2;
325 if (!PyArg_ParseTuple(args, "OO:strcoll", &os1, &os2))
326 return NULL;
327 /* If both arguments are byte strings, use strcoll. */
328 if (PyString_Check(os1) && PyString_Check(os2))
329 return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
330 PyString_AS_STRING(os2)));
331 /* If neither argument is unicode, it's an error. */
332 if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
333 PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
335 /* Convert the non-unicode argument to unicode. */
336 if (!PyUnicode_Check(os1)) {
337 os1 = PyUnicode_FromObject(os1);
338 if (!os1)
339 return NULL;
340 rel1 = 1;
342 if (!PyUnicode_Check(os2)) {
343 os2 = PyUnicode_FromObject(os2);
344 if (!os2) {
345 Py_DECREF(os1);
346 return NULL;
348 rel2 = 1;
350 /* Convert the unicode strings to wchar[]. */
351 len1 = PyUnicode_GET_SIZE(os1) + 1;
352 len2 = PyUnicode_GET_SIZE(os2) + 1;
353 ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
354 if (!ws1) {
355 PyErr_NoMemory();
356 goto done;
358 if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)
359 goto done;
360 ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t));
361 if (!ws2) {
362 PyErr_NoMemory();
363 goto done;
365 if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)
366 goto done;
367 /* Collate the strings. */
368 result = PyInt_FromLong(wcscoll(ws1, ws2));
369 done:
370 /* Deallocate everything. */
371 if (ws1) PyMem_FREE(ws1);
372 if (ws2) PyMem_FREE(ws2);
373 if (rel1) {
374 Py_DECREF(os1);
376 if (rel2) {
377 Py_DECREF(os2);
379 return result;
380 #endif
384 PyDoc_STRVAR(strxfrm__doc__,
385 "string -> string. Returns a string that behaves for cmp locale-aware.");
387 static PyObject*
388 PyLocale_strxfrm(PyObject* self, PyObject* args)
390 char *s, *buf;
391 size_t n1, n2;
392 PyObject *result;
394 if (!PyArg_ParseTuple(args, "s:strxfrm", &s))
395 return NULL;
397 /* assume no change in size, first */
398 n1 = strlen(s) + 1;
399 buf = PyMem_Malloc(n1);
400 if (!buf)
401 return PyErr_NoMemory();
402 n2 = strxfrm(buf, s, n1);
403 if (n2 > n1) {
404 /* more space needed */
405 buf = PyMem_Realloc(buf, n2);
406 if (!buf)
407 return PyErr_NoMemory();
408 strxfrm(buf, s, n2);
410 result = PyString_FromString(buf);
411 PyMem_Free(buf);
412 return result;
415 #if defined(MS_WINDOWS)
416 static PyObject*
417 PyLocale_getdefaultlocale(PyObject* self)
419 char encoding[100];
420 char locale[100];
422 PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
424 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
425 LOCALE_SISO639LANGNAME,
426 locale, sizeof(locale))) {
427 int i = strlen(locale);
428 locale[i++] = '_';
429 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
430 LOCALE_SISO3166CTRYNAME,
431 locale+i, sizeof(locale)-i))
432 return Py_BuildValue("ss", locale, encoding);
435 /* If we end up here, this windows version didn't know about
436 ISO639/ISO3166 names (it's probably Windows 95). Return the
437 Windows language identifier instead (a hexadecimal number) */
439 locale[0] = '0';
440 locale[1] = 'x';
441 if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
442 locale+2, sizeof(locale)-2)) {
443 return Py_BuildValue("ss", locale, encoding);
446 /* cannot determine the language code (very unlikely) */
447 Py_INCREF(Py_None);
448 return Py_BuildValue("Os", Py_None, encoding);
450 #endif
452 #if defined(__APPLE__)
453 static PyObject*
454 PyLocale_getdefaultlocale(PyObject* self)
456 return Py_BuildValue("Os", Py_None, PyMac_getscript());
458 #endif
460 #ifdef HAVE_LANGINFO_H
461 #define LANGINFO(X) {#X, X}
462 struct langinfo_constant{
463 char* name;
464 int value;
465 } langinfo_constants[] =
467 /* These constants should exist on any langinfo implementation */
468 LANGINFO(DAY_1),
469 LANGINFO(DAY_2),
470 LANGINFO(DAY_3),
471 LANGINFO(DAY_4),
472 LANGINFO(DAY_5),
473 LANGINFO(DAY_6),
474 LANGINFO(DAY_7),
476 LANGINFO(ABDAY_1),
477 LANGINFO(ABDAY_2),
478 LANGINFO(ABDAY_3),
479 LANGINFO(ABDAY_4),
480 LANGINFO(ABDAY_5),
481 LANGINFO(ABDAY_6),
482 LANGINFO(ABDAY_7),
484 LANGINFO(MON_1),
485 LANGINFO(MON_2),
486 LANGINFO(MON_3),
487 LANGINFO(MON_4),
488 LANGINFO(MON_5),
489 LANGINFO(MON_6),
490 LANGINFO(MON_7),
491 LANGINFO(MON_8),
492 LANGINFO(MON_9),
493 LANGINFO(MON_10),
494 LANGINFO(MON_11),
495 LANGINFO(MON_12),
497 LANGINFO(ABMON_1),
498 LANGINFO(ABMON_2),
499 LANGINFO(ABMON_3),
500 LANGINFO(ABMON_4),
501 LANGINFO(ABMON_5),
502 LANGINFO(ABMON_6),
503 LANGINFO(ABMON_7),
504 LANGINFO(ABMON_8),
505 LANGINFO(ABMON_9),
506 LANGINFO(ABMON_10),
507 LANGINFO(ABMON_11),
508 LANGINFO(ABMON_12),
510 #ifdef RADIXCHAR
511 /* The following are not available with glibc 2.0 */
512 LANGINFO(RADIXCHAR),
513 LANGINFO(THOUSEP),
514 /* YESSTR and NOSTR are deprecated in glibc, since they are
515 a special case of message translation, which should be rather
516 done using gettext. So we don't expose it to Python in the
517 first place.
518 LANGINFO(YESSTR),
519 LANGINFO(NOSTR),
521 LANGINFO(CRNCYSTR),
522 #endif
524 LANGINFO(D_T_FMT),
525 LANGINFO(D_FMT),
526 LANGINFO(T_FMT),
527 LANGINFO(AM_STR),
528 LANGINFO(PM_STR),
530 /* The following constants are available only with XPG4, but...
531 AIX 3.2. only has CODESET.
532 OpenBSD doesn't have CODESET but has T_FMT_AMPM, and doesn't have
533 a few of the others.
534 Solution: ifdef-test them all. */
535 #ifdef CODESET
536 LANGINFO(CODESET),
537 #endif
538 #ifdef T_FMT_AMPM
539 LANGINFO(T_FMT_AMPM),
540 #endif
541 #ifdef ERA
542 LANGINFO(ERA),
543 #endif
544 #ifdef ERA_D_FMT
545 LANGINFO(ERA_D_FMT),
546 #endif
547 #ifdef ERA_D_T_FMT
548 LANGINFO(ERA_D_T_FMT),
549 #endif
550 #ifdef ERA_T_FMT
551 LANGINFO(ERA_T_FMT),
552 #endif
553 #ifdef ALT_DIGITS
554 LANGINFO(ALT_DIGITS),
555 #endif
556 #ifdef YESEXPR
557 LANGINFO(YESEXPR),
558 #endif
559 #ifdef NOEXPR
560 LANGINFO(NOEXPR),
561 #endif
562 #ifdef _DATE_FMT
563 /* This is not available in all glibc versions that have CODESET. */
564 LANGINFO(_DATE_FMT),
565 #endif
566 {0, 0}
569 PyDoc_STRVAR(nl_langinfo__doc__,
570 "nl_langinfo(key) -> string\n"
571 "Return the value for the locale information associated with key.");
573 static PyObject*
574 PyLocale_nl_langinfo(PyObject* self, PyObject* args)
576 int item, i;
577 if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
578 return NULL;
579 /* Check whether this is a supported constant. GNU libc sometimes
580 returns numeric values in the char* return value, which would
581 crash PyString_FromString. */
582 #ifdef RADIXCHAR
583 if (saved_numeric) {
584 if(item == RADIXCHAR) {
585 Py_INCREF(decimal_point);
586 return decimal_point;
588 if(item == THOUSEP) {
589 Py_INCREF(thousands_sep);
590 return thousands_sep;
593 #endif
594 for (i = 0; langinfo_constants[i].name; i++)
595 if (langinfo_constants[i].value == item) {
596 /* Check NULL as a workaround for GNU libc's returning NULL
597 instead of an empty string for nl_langinfo(ERA). */
598 const char *result = nl_langinfo(item);
599 return PyString_FromString(result != NULL ? result : "");
601 PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
602 return NULL;
604 #endif /* HAVE_LANGINFO_H */
606 #ifdef HAVE_LIBINTL_H
608 PyDoc_STRVAR(gettext__doc__,
609 "gettext(msg) -> string\n"
610 "Return translation of msg.");
612 static PyObject*
613 PyIntl_gettext(PyObject* self, PyObject *args)
615 char *in;
616 if (!PyArg_ParseTuple(args, "z", &in))
617 return 0;
618 return PyString_FromString(gettext(in));
621 PyDoc_STRVAR(dgettext__doc__,
622 "dgettext(domain, msg) -> string\n"
623 "Return translation of msg in domain.");
625 static PyObject*
626 PyIntl_dgettext(PyObject* self, PyObject *args)
628 char *domain, *in;
629 if (!PyArg_ParseTuple(args, "zz", &domain, &in))
630 return 0;
631 return PyString_FromString(dgettext(domain, in));
634 PyDoc_STRVAR(dcgettext__doc__,
635 "dcgettext(domain, msg, category) -> string\n"
636 "Return translation of msg in domain and category.");
638 static PyObject*
639 PyIntl_dcgettext(PyObject *self, PyObject *args)
641 char *domain, *msgid;
642 int category;
643 if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
644 return 0;
645 return PyString_FromString(dcgettext(domain,msgid,category));
648 PyDoc_STRVAR(textdomain__doc__,
649 "textdomain(domain) -> string\n"
650 "Set the C library's textdmain to domain, returning the new domain.");
652 static PyObject*
653 PyIntl_textdomain(PyObject* self, PyObject* args)
655 char *domain;
656 if (!PyArg_ParseTuple(args, "z", &domain))
657 return 0;
658 domain = textdomain(domain);
659 if (!domain) {
660 PyErr_SetFromErrno(PyExc_OSError);
661 return NULL;
663 return PyString_FromString(domain);
666 PyDoc_STRVAR(bindtextdomain__doc__,
667 "bindtextdomain(domain, dir) -> string\n"
668 "Bind the C library's domain to dir.");
670 static PyObject*
671 PyIntl_bindtextdomain(PyObject* self,PyObject*args)
673 char *domain,*dirname;
674 if (!PyArg_ParseTuple(args, "zz", &domain, &dirname))
675 return 0;
676 dirname = bindtextdomain(domain, dirname);
677 if (!dirname) {
678 PyErr_SetFromErrno(PyExc_OSError);
679 return NULL;
681 return PyString_FromString(dirname);
684 #endif
686 static struct PyMethodDef PyLocale_Methods[] = {
687 {"setlocale", (PyCFunction) PyLocale_setlocale,
688 METH_VARARGS, setlocale__doc__},
689 {"localeconv", (PyCFunction) PyLocale_localeconv,
690 METH_NOARGS, localeconv__doc__},
691 {"strcoll", (PyCFunction) PyLocale_strcoll,
692 METH_VARARGS, strcoll__doc__},
693 {"strxfrm", (PyCFunction) PyLocale_strxfrm,
694 METH_VARARGS, strxfrm__doc__},
695 #if defined(MS_WINDOWS) || defined(__APPLE__)
696 {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
697 #endif
698 #ifdef HAVE_LANGINFO_H
699 {"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
700 METH_VARARGS, nl_langinfo__doc__},
701 #endif
702 #ifdef HAVE_LIBINTL_H
703 {"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,
704 gettext__doc__},
705 {"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,
706 dgettext__doc__},
707 {"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,
708 dcgettext__doc__},
709 {"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,
710 textdomain__doc__},
711 {"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,
712 bindtextdomain__doc__},
713 #endif
714 {NULL, NULL}
717 PyMODINIT_FUNC
718 init_locale(void)
720 PyObject *m, *d, *x;
721 #ifdef HAVE_LANGINFO_H
722 int i;
723 #endif
725 m = Py_InitModule("_locale", PyLocale_Methods);
727 d = PyModule_GetDict(m);
729 x = PyInt_FromLong(LC_CTYPE);
730 PyDict_SetItemString(d, "LC_CTYPE", x);
731 Py_XDECREF(x);
733 x = PyInt_FromLong(LC_TIME);
734 PyDict_SetItemString(d, "LC_TIME", x);
735 Py_XDECREF(x);
737 x = PyInt_FromLong(LC_COLLATE);
738 PyDict_SetItemString(d, "LC_COLLATE", x);
739 Py_XDECREF(x);
741 x = PyInt_FromLong(LC_MONETARY);
742 PyDict_SetItemString(d, "LC_MONETARY", x);
743 Py_XDECREF(x);
745 #ifdef LC_MESSAGES
746 x = PyInt_FromLong(LC_MESSAGES);
747 PyDict_SetItemString(d, "LC_MESSAGES", x);
748 Py_XDECREF(x);
749 #endif /* LC_MESSAGES */
751 x = PyInt_FromLong(LC_NUMERIC);
752 PyDict_SetItemString(d, "LC_NUMERIC", x);
753 Py_XDECREF(x);
755 x = PyInt_FromLong(LC_ALL);
756 PyDict_SetItemString(d, "LC_ALL", x);
757 Py_XDECREF(x);
759 x = PyInt_FromLong(CHAR_MAX);
760 PyDict_SetItemString(d, "CHAR_MAX", x);
761 Py_XDECREF(x);
763 Error = PyErr_NewException("locale.Error", NULL, NULL);
764 PyDict_SetItemString(d, "Error", Error);
766 x = PyString_FromString(locale__doc__);
767 PyDict_SetItemString(d, "__doc__", x);
768 Py_XDECREF(x);
770 #ifdef HAVE_LANGINFO_H
771 for (i = 0; langinfo_constants[i].name; i++) {
772 PyModule_AddIntConstant(m, langinfo_constants[i].name,
773 langinfo_constants[i].value);
775 #endif
779 Local variables:
780 c-basic-offset: 4
781 indent-tabs-mode: nil
782 End: