Fix #1474677, non-keyword argument following keyword.
[python.git] / Modules / _localemodule.c
blobe3d1e7f49e16c435758d0c592aafe71ade503b48
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(__APPLE__)
33 #include <CoreFoundation/CoreFoundation.h>
34 #endif
36 #if defined(MS_WINDOWS)
37 #define WIN32_LEAN_AND_MEAN
38 #include <windows.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 /* the grouping is terminated by either 0 or CHAR_MAX */
55 static PyObject*
56 copy_grouping(char* s)
58 int i;
59 PyObject *result, *val = NULL;
61 if (s[0] == '\0')
62 /* empty string: no grouping at all */
63 return PyList_New(0);
65 for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)
66 ; /* nothing */
68 result = PyList_New(i+1);
69 if (!result)
70 return NULL;
72 i = -1;
73 do {
74 i++;
75 val = PyInt_FromLong(s[i]);
76 if (!val)
77 break;
78 if (PyList_SetItem(result, i, val)) {
79 Py_DECREF(val);
80 val = NULL;
81 break;
83 } while (s[i] != '\0' && s[i] != CHAR_MAX);
85 if (!val) {
86 Py_DECREF(result);
87 return NULL;
90 return result;
93 static void
94 fixup_ulcase(void)
96 PyObject *mods, *strop, *string, *ulo;
97 unsigned char ul[256];
98 int n, c;
100 /* find the string and strop modules */
101 mods = PyImport_GetModuleDict();
102 if (!mods)
103 return;
104 string = PyDict_GetItemString(mods, "string");
105 if (string)
106 string = PyModule_GetDict(string);
107 strop=PyDict_GetItemString(mods, "strop");
108 if (strop)
109 strop = PyModule_GetDict(strop);
110 if (!string && !strop)
111 return;
113 /* create uppercase map string */
114 n = 0;
115 for (c = 0; c < 256; c++) {
116 if (isupper(c))
117 ul[n++] = c;
119 ulo = PyString_FromStringAndSize((const char *)ul, n);
120 if (!ulo)
121 return;
122 if (string)
123 PyDict_SetItemString(string, "uppercase", ulo);
124 if (strop)
125 PyDict_SetItemString(strop, "uppercase", ulo);
126 Py_DECREF(ulo);
128 /* create lowercase string */
129 n = 0;
130 for (c = 0; c < 256; c++) {
131 if (islower(c))
132 ul[n++] = c;
134 ulo = PyString_FromStringAndSize((const char *)ul, n);
135 if (!ulo)
136 return;
137 if (string)
138 PyDict_SetItemString(string, "lowercase", ulo);
139 if (strop)
140 PyDict_SetItemString(strop, "lowercase", ulo);
141 Py_DECREF(ulo);
143 /* create letters string */
144 n = 0;
145 for (c = 0; c < 256; c++) {
146 if (isalpha(c))
147 ul[n++] = c;
149 ulo = PyString_FromStringAndSize((const char *)ul, n);
150 if (!ulo)
151 return;
152 if (string)
153 PyDict_SetItemString(string, "letters", ulo);
154 Py_DECREF(ulo);
157 static PyObject*
158 PyLocale_setlocale(PyObject* self, PyObject* args)
160 int category;
161 char *locale = NULL, *result;
162 PyObject *result_object;
164 if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
165 return NULL;
167 if (locale) {
168 /* set locale */
169 result = setlocale(category, locale);
170 if (!result) {
171 /* operation failed, no setting was changed */
172 PyErr_SetString(Error, "unsupported locale setting");
173 return NULL;
175 result_object = PyString_FromString(result);
176 if (!result_object)
177 return NULL;
178 /* record changes to LC_CTYPE */
179 if (category == LC_CTYPE || category == LC_ALL)
180 fixup_ulcase();
181 /* things that got wrong up to here are ignored */
182 PyErr_Clear();
183 } else {
184 /* get locale */
185 result = setlocale(category, NULL);
186 if (!result) {
187 PyErr_SetString(Error, "locale query failed");
188 return NULL;
190 result_object = PyString_FromString(result);
192 return result_object;
195 PyDoc_STRVAR(localeconv__doc__,
196 "() -> dict. Returns numeric and monetary locale-specific parameters.");
198 static PyObject*
199 PyLocale_localeconv(PyObject* self)
201 PyObject* result;
202 struct lconv *l;
203 PyObject *x;
205 result = PyDict_New();
206 if (!result)
207 return NULL;
209 /* if LC_NUMERIC is different in the C library, use saved value */
210 l = localeconv();
212 /* hopefully, the localeconv result survives the C library calls
213 involved herein */
215 #define RESULT_STRING(s)\
216 x = PyString_FromString(l->s);\
217 if (!x) goto failed;\
218 PyDict_SetItemString(result, #s, x);\
219 Py_XDECREF(x)
221 #define RESULT_INT(i)\
222 x = PyInt_FromLong(l->i);\
223 if (!x) goto failed;\
224 PyDict_SetItemString(result, #i, x);\
225 Py_XDECREF(x)
227 /* Numeric information */
228 RESULT_STRING(decimal_point);
229 RESULT_STRING(thousands_sep);
230 x = copy_grouping(l->grouping);
231 if (!x)
232 goto failed;
233 PyDict_SetItemString(result, "grouping", x);
234 Py_XDECREF(x);
236 /* Monetary information */
237 RESULT_STRING(int_curr_symbol);
238 RESULT_STRING(currency_symbol);
239 RESULT_STRING(mon_decimal_point);
240 RESULT_STRING(mon_thousands_sep);
241 x = copy_grouping(l->mon_grouping);
242 if (!x)
243 goto failed;
244 PyDict_SetItemString(result, "mon_grouping", x);
245 Py_XDECREF(x);
246 RESULT_STRING(positive_sign);
247 RESULT_STRING(negative_sign);
248 RESULT_INT(int_frac_digits);
249 RESULT_INT(frac_digits);
250 RESULT_INT(p_cs_precedes);
251 RESULT_INT(p_sep_by_space);
252 RESULT_INT(n_cs_precedes);
253 RESULT_INT(n_sep_by_space);
254 RESULT_INT(p_sign_posn);
255 RESULT_INT(n_sign_posn);
256 return result;
258 failed:
259 Py_XDECREF(result);
260 Py_XDECREF(x);
261 return NULL;
264 PyDoc_STRVAR(strcoll__doc__,
265 "string,string -> int. Compares two strings according to the locale.");
267 static PyObject*
268 PyLocale_strcoll(PyObject* self, PyObject* args)
270 #if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)
271 char *s1,*s2;
273 if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
274 return NULL;
275 return PyInt_FromLong(strcoll(s1, s2));
276 #else
277 PyObject *os1, *os2, *result = NULL;
278 wchar_t *ws1 = NULL, *ws2 = NULL;
279 int rel1 = 0, rel2 = 0, len1, len2;
281 if (!PyArg_ParseTuple(args, "OO:strcoll", &os1, &os2))
282 return NULL;
283 /* If both arguments are byte strings, use strcoll. */
284 if (PyString_Check(os1) && PyString_Check(os2))
285 return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
286 PyString_AS_STRING(os2)));
287 /* If neither argument is unicode, it's an error. */
288 if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
289 PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
291 /* Convert the non-unicode argument to unicode. */
292 if (!PyUnicode_Check(os1)) {
293 os1 = PyUnicode_FromObject(os1);
294 if (!os1)
295 return NULL;
296 rel1 = 1;
298 if (!PyUnicode_Check(os2)) {
299 os2 = PyUnicode_FromObject(os2);
300 if (!os2) {
301 Py_DECREF(os1);
302 return NULL;
304 rel2 = 1;
306 /* Convert the unicode strings to wchar[]. */
307 len1 = PyUnicode_GET_SIZE(os1) + 1;
308 ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
309 if (!ws1) {
310 PyErr_NoMemory();
311 goto done;
313 if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)
314 goto done;
315 ws1[len1 - 1] = 0;
316 len2 = PyUnicode_GET_SIZE(os2) + 1;
317 ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t));
318 if (!ws2) {
319 PyErr_NoMemory();
320 goto done;
322 if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)
323 goto done;
324 ws2[len2 - 1] = 0;
325 /* Collate the strings. */
326 result = PyInt_FromLong(wcscoll(ws1, ws2));
327 done:
328 /* Deallocate everything. */
329 if (ws1) PyMem_FREE(ws1);
330 if (ws2) PyMem_FREE(ws2);
331 if (rel1) {
332 Py_DECREF(os1);
334 if (rel2) {
335 Py_DECREF(os2);
337 return result;
338 #endif
342 PyDoc_STRVAR(strxfrm__doc__,
343 "string -> string. Returns a string that behaves for cmp locale-aware.");
345 static PyObject*
346 PyLocale_strxfrm(PyObject* self, PyObject* args)
348 char *s, *buf;
349 size_t n1, n2;
350 PyObject *result;
352 if (!PyArg_ParseTuple(args, "s:strxfrm", &s))
353 return NULL;
355 /* assume no change in size, first */
356 n1 = strlen(s) + 1;
357 buf = PyMem_Malloc(n1);
358 if (!buf)
359 return PyErr_NoMemory();
360 n2 = strxfrm(buf, s, n1);
361 if (n2 > n1) {
362 /* more space needed */
363 buf = PyMem_Realloc(buf, n2);
364 if (!buf)
365 return PyErr_NoMemory();
366 strxfrm(buf, s, n2);
368 result = PyString_FromString(buf);
369 PyMem_Free(buf);
370 return result;
373 #if defined(MS_WINDOWS)
374 static PyObject*
375 PyLocale_getdefaultlocale(PyObject* self)
377 char encoding[100];
378 char locale[100];
380 PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
382 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
383 LOCALE_SISO639LANGNAME,
384 locale, sizeof(locale))) {
385 Py_ssize_t i = strlen(locale);
386 locale[i++] = '_';
387 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
388 LOCALE_SISO3166CTRYNAME,
389 locale+i, (int)(sizeof(locale)-i)))
390 return Py_BuildValue("ss", locale, encoding);
393 /* If we end up here, this windows version didn't know about
394 ISO639/ISO3166 names (it's probably Windows 95). Return the
395 Windows language identifier instead (a hexadecimal number) */
397 locale[0] = '0';
398 locale[1] = 'x';
399 if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
400 locale+2, sizeof(locale)-2)) {
401 return Py_BuildValue("ss", locale, encoding);
404 /* cannot determine the language code (very unlikely) */
405 Py_INCREF(Py_None);
406 return Py_BuildValue("Os", Py_None, encoding);
408 #endif
410 #if defined(__APPLE__)
412 ** Find out what the current script is.
413 ** Donated by Fredrik Lundh.
415 static char *mac_getscript(void)
417 CFStringEncoding enc = CFStringGetSystemEncoding();
418 static CFStringRef name = NULL;
419 /* Return the code name for the encodings for which we have codecs. */
420 switch(enc) {
421 case kCFStringEncodingMacRoman: return "mac-roman";
422 case kCFStringEncodingMacGreek: return "mac-greek";
423 case kCFStringEncodingMacCyrillic: return "mac-cyrillic";
424 case kCFStringEncodingMacTurkish: return "mac-turkish";
425 case kCFStringEncodingMacIcelandic: return "mac-icelandic";
426 /* XXX which one is mac-latin2? */
428 if (!name) {
429 /* This leaks an object. */
430 name = CFStringConvertEncodingToIANACharSetName(enc);
432 return (char *)CFStringGetCStringPtr(name, 0);
435 static PyObject*
436 PyLocale_getdefaultlocale(PyObject* self)
438 return Py_BuildValue("Os", Py_None, mac_getscript());
440 #endif
442 #ifdef HAVE_LANGINFO_H
443 #define LANGINFO(X) {#X, X}
444 struct langinfo_constant{
445 char* name;
446 int value;
447 } langinfo_constants[] =
449 /* These constants should exist on any langinfo implementation */
450 LANGINFO(DAY_1),
451 LANGINFO(DAY_2),
452 LANGINFO(DAY_3),
453 LANGINFO(DAY_4),
454 LANGINFO(DAY_5),
455 LANGINFO(DAY_6),
456 LANGINFO(DAY_7),
458 LANGINFO(ABDAY_1),
459 LANGINFO(ABDAY_2),
460 LANGINFO(ABDAY_3),
461 LANGINFO(ABDAY_4),
462 LANGINFO(ABDAY_5),
463 LANGINFO(ABDAY_6),
464 LANGINFO(ABDAY_7),
466 LANGINFO(MON_1),
467 LANGINFO(MON_2),
468 LANGINFO(MON_3),
469 LANGINFO(MON_4),
470 LANGINFO(MON_5),
471 LANGINFO(MON_6),
472 LANGINFO(MON_7),
473 LANGINFO(MON_8),
474 LANGINFO(MON_9),
475 LANGINFO(MON_10),
476 LANGINFO(MON_11),
477 LANGINFO(MON_12),
479 LANGINFO(ABMON_1),
480 LANGINFO(ABMON_2),
481 LANGINFO(ABMON_3),
482 LANGINFO(ABMON_4),
483 LANGINFO(ABMON_5),
484 LANGINFO(ABMON_6),
485 LANGINFO(ABMON_7),
486 LANGINFO(ABMON_8),
487 LANGINFO(ABMON_9),
488 LANGINFO(ABMON_10),
489 LANGINFO(ABMON_11),
490 LANGINFO(ABMON_12),
492 #ifdef RADIXCHAR
493 /* The following are not available with glibc 2.0 */
494 LANGINFO(RADIXCHAR),
495 LANGINFO(THOUSEP),
496 /* YESSTR and NOSTR are deprecated in glibc, since they are
497 a special case of message translation, which should be rather
498 done using gettext. So we don't expose it to Python in the
499 first place.
500 LANGINFO(YESSTR),
501 LANGINFO(NOSTR),
503 LANGINFO(CRNCYSTR),
504 #endif
506 LANGINFO(D_T_FMT),
507 LANGINFO(D_FMT),
508 LANGINFO(T_FMT),
509 LANGINFO(AM_STR),
510 LANGINFO(PM_STR),
512 /* The following constants are available only with XPG4, but...
513 AIX 3.2. only has CODESET.
514 OpenBSD doesn't have CODESET but has T_FMT_AMPM, and doesn't have
515 a few of the others.
516 Solution: ifdef-test them all. */
517 #ifdef CODESET
518 LANGINFO(CODESET),
519 #endif
520 #ifdef T_FMT_AMPM
521 LANGINFO(T_FMT_AMPM),
522 #endif
523 #ifdef ERA
524 LANGINFO(ERA),
525 #endif
526 #ifdef ERA_D_FMT
527 LANGINFO(ERA_D_FMT),
528 #endif
529 #ifdef ERA_D_T_FMT
530 LANGINFO(ERA_D_T_FMT),
531 #endif
532 #ifdef ERA_T_FMT
533 LANGINFO(ERA_T_FMT),
534 #endif
535 #ifdef ALT_DIGITS
536 LANGINFO(ALT_DIGITS),
537 #endif
538 #ifdef YESEXPR
539 LANGINFO(YESEXPR),
540 #endif
541 #ifdef NOEXPR
542 LANGINFO(NOEXPR),
543 #endif
544 #ifdef _DATE_FMT
545 /* This is not available in all glibc versions that have CODESET. */
546 LANGINFO(_DATE_FMT),
547 #endif
548 {0, 0}
551 PyDoc_STRVAR(nl_langinfo__doc__,
552 "nl_langinfo(key) -> string\n"
553 "Return the value for the locale information associated with key.");
555 static PyObject*
556 PyLocale_nl_langinfo(PyObject* self, PyObject* args)
558 int item, i;
559 if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
560 return NULL;
561 /* Check whether this is a supported constant. GNU libc sometimes
562 returns numeric values in the char* return value, which would
563 crash PyString_FromString. */
564 for (i = 0; langinfo_constants[i].name; i++)
565 if (langinfo_constants[i].value == item) {
566 /* Check NULL as a workaround for GNU libc's returning NULL
567 instead of an empty string for nl_langinfo(ERA). */
568 const char *result = nl_langinfo(item);
569 return PyString_FromString(result != NULL ? result : "");
571 PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
572 return NULL;
574 #endif /* HAVE_LANGINFO_H */
576 #ifdef HAVE_LIBINTL_H
578 PyDoc_STRVAR(gettext__doc__,
579 "gettext(msg) -> string\n"
580 "Return translation of msg.");
582 static PyObject*
583 PyIntl_gettext(PyObject* self, PyObject *args)
585 char *in;
586 if (!PyArg_ParseTuple(args, "z", &in))
587 return 0;
588 return PyString_FromString(gettext(in));
591 PyDoc_STRVAR(dgettext__doc__,
592 "dgettext(domain, msg) -> string\n"
593 "Return translation of msg in domain.");
595 static PyObject*
596 PyIntl_dgettext(PyObject* self, PyObject *args)
598 char *domain, *in;
599 if (!PyArg_ParseTuple(args, "zz", &domain, &in))
600 return 0;
601 return PyString_FromString(dgettext(domain, in));
604 PyDoc_STRVAR(dcgettext__doc__,
605 "dcgettext(domain, msg, category) -> string\n"
606 "Return translation of msg in domain and category.");
608 static PyObject*
609 PyIntl_dcgettext(PyObject *self, PyObject *args)
611 char *domain, *msgid;
612 int category;
613 if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
614 return 0;
615 return PyString_FromString(dcgettext(domain,msgid,category));
618 PyDoc_STRVAR(textdomain__doc__,
619 "textdomain(domain) -> string\n"
620 "Set the C library's textdmain to domain, returning the new domain.");
622 static PyObject*
623 PyIntl_textdomain(PyObject* self, PyObject* args)
625 char *domain;
626 if (!PyArg_ParseTuple(args, "z", &domain))
627 return 0;
628 domain = textdomain(domain);
629 if (!domain) {
630 PyErr_SetFromErrno(PyExc_OSError);
631 return NULL;
633 return PyString_FromString(domain);
636 PyDoc_STRVAR(bindtextdomain__doc__,
637 "bindtextdomain(domain, dir) -> string\n"
638 "Bind the C library's domain to dir.");
640 static PyObject*
641 PyIntl_bindtextdomain(PyObject* self,PyObject*args)
643 char *domain,*dirname;
644 if (!PyArg_ParseTuple(args, "zz", &domain, &dirname))
645 return 0;
646 dirname = bindtextdomain(domain, dirname);
647 if (!dirname) {
648 PyErr_SetFromErrno(PyExc_OSError);
649 return NULL;
651 return PyString_FromString(dirname);
654 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
655 PyDoc_STRVAR(bind_textdomain_codeset__doc__,
656 "bind_textdomain_codeset(domain, codeset) -> string\n"
657 "Bind the C library's domain to codeset.");
659 static PyObject*
660 PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
662 char *domain,*codeset;
663 if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
664 return NULL;
665 codeset = bind_textdomain_codeset(domain, codeset);
666 if (codeset)
667 return PyString_FromString(codeset);
668 Py_RETURN_NONE;
670 #endif
672 #endif
674 static struct PyMethodDef PyLocale_Methods[] = {
675 {"setlocale", (PyCFunction) PyLocale_setlocale,
676 METH_VARARGS, setlocale__doc__},
677 {"localeconv", (PyCFunction) PyLocale_localeconv,
678 METH_NOARGS, localeconv__doc__},
679 {"strcoll", (PyCFunction) PyLocale_strcoll,
680 METH_VARARGS, strcoll__doc__},
681 {"strxfrm", (PyCFunction) PyLocale_strxfrm,
682 METH_VARARGS, strxfrm__doc__},
683 #if defined(MS_WINDOWS) || defined(__APPLE__)
684 {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
685 #endif
686 #ifdef HAVE_LANGINFO_H
687 {"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
688 METH_VARARGS, nl_langinfo__doc__},
689 #endif
690 #ifdef HAVE_LIBINTL_H
691 {"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,
692 gettext__doc__},
693 {"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,
694 dgettext__doc__},
695 {"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,
696 dcgettext__doc__},
697 {"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,
698 textdomain__doc__},
699 {"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,
700 bindtextdomain__doc__},
701 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
702 {"bind_textdomain_codeset",(PyCFunction)PyIntl_bind_textdomain_codeset,
703 METH_VARARGS, bind_textdomain_codeset__doc__},
704 #endif
705 #endif
706 {NULL, NULL}
709 PyMODINIT_FUNC
710 init_locale(void)
712 PyObject *m, *d, *x;
713 #ifdef HAVE_LANGINFO_H
714 int i;
715 #endif
717 m = Py_InitModule("_locale", PyLocale_Methods);
718 if (m == NULL)
719 return;
721 d = PyModule_GetDict(m);
723 x = PyInt_FromLong(LC_CTYPE);
724 PyDict_SetItemString(d, "LC_CTYPE", x);
725 Py_XDECREF(x);
727 x = PyInt_FromLong(LC_TIME);
728 PyDict_SetItemString(d, "LC_TIME", x);
729 Py_XDECREF(x);
731 x = PyInt_FromLong(LC_COLLATE);
732 PyDict_SetItemString(d, "LC_COLLATE", x);
733 Py_XDECREF(x);
735 x = PyInt_FromLong(LC_MONETARY);
736 PyDict_SetItemString(d, "LC_MONETARY", x);
737 Py_XDECREF(x);
739 #ifdef LC_MESSAGES
740 x = PyInt_FromLong(LC_MESSAGES);
741 PyDict_SetItemString(d, "LC_MESSAGES", x);
742 Py_XDECREF(x);
743 #endif /* LC_MESSAGES */
745 x = PyInt_FromLong(LC_NUMERIC);
746 PyDict_SetItemString(d, "LC_NUMERIC", x);
747 Py_XDECREF(x);
749 x = PyInt_FromLong(LC_ALL);
750 PyDict_SetItemString(d, "LC_ALL", x);
751 Py_XDECREF(x);
753 x = PyInt_FromLong(CHAR_MAX);
754 PyDict_SetItemString(d, "CHAR_MAX", x);
755 Py_XDECREF(x);
757 Error = PyErr_NewException("locale.Error", NULL, NULL);
758 PyDict_SetItemString(d, "Error", Error);
760 x = PyString_FromString(locale__doc__);
761 PyDict_SetItemString(d, "__doc__", x);
762 Py_XDECREF(x);
764 #ifdef HAVE_LANGINFO_H
765 for (i = 0; langinfo_constants[i].name; i++) {
766 PyModule_AddIntConstant(m, langinfo_constants[i].name,
767 langinfo_constants[i].value);
769 #endif
773 Local variables:
774 c-basic-offset: 4
775 indent-tabs-mode: nil
776 End: