ยปCore Development>Code coverage>Modules/_localemodule.c

Python code coverage for Modules/_localemodule.c

#countcontent
1n/a/***********************************************************
2n/aCopyright (C) 1997, 2002, 2003, 2007, 2008 Martin von Loewis
3n/a
4n/aPermission to use, copy, modify, and distribute this software and its
5n/adocumentation for any purpose and without fee is hereby granted,
6n/aprovided that the above copyright notice appear in all copies.
7n/a
8n/aThis software comes with no warranty. Use at your own risk.
9n/a
10n/a******************************************************************/
11n/a
12n/a#define PY_SSIZE_T_CLEAN
13n/a#include "Python.h"
14n/a
15n/a#include <stdio.h>
16n/a#include <locale.h>
17n/a#include <string.h>
18n/a#include <ctype.h>
19n/a
20n/a#ifdef HAVE_ERRNO_H
21n/a#include <errno.h>
22n/a#endif
23n/a
24n/a#ifdef HAVE_LANGINFO_H
25n/a#include <langinfo.h>
26n/a#endif
27n/a
28n/a#ifdef HAVE_LIBINTL_H
29n/a#include <libintl.h>
30n/a#endif
31n/a
32n/a#ifdef HAVE_WCHAR_H
33n/a#include <wchar.h>
34n/a#endif
35n/a
36n/a#if defined(MS_WINDOWS)
37n/a#define WIN32_LEAN_AND_MEAN
38n/a#include <windows.h>
39n/a#endif
40n/a
41n/aPyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");
42n/a
43n/astatic PyObject *Error;
44n/a
45n/a/* support functions for formatting floating point numbers */
46n/a
47n/aPyDoc_STRVAR(setlocale__doc__,
48n/a"(integer,string=None) -> string. Activates/queries locale processing.");
49n/a
50n/a/* the grouping is terminated by either 0 or CHAR_MAX */
51n/astatic PyObject*
52n/acopy_grouping(const char* s)
53n/a{
54n/a int i;
55n/a PyObject *result, *val = NULL;
56n/a
57n/a if (s[0] == '\0') {
58n/a /* empty string: no grouping at all */
59n/a return PyList_New(0);
60n/a }
61n/a
62n/a for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)
63n/a ; /* nothing */
64n/a
65n/a result = PyList_New(i+1);
66n/a if (!result)
67n/a return NULL;
68n/a
69n/a i = -1;
70n/a do {
71n/a i++;
72n/a val = PyLong_FromLong(s[i]);
73n/a if (!val)
74n/a break;
75n/a if (PyList_SetItem(result, i, val)) {
76n/a Py_DECREF(val);
77n/a val = NULL;
78n/a break;
79n/a }
80n/a } while (s[i] != '\0' && s[i] != CHAR_MAX);
81n/a
82n/a if (!val) {
83n/a Py_DECREF(result);
84n/a return NULL;
85n/a }
86n/a
87n/a return result;
88n/a}
89n/a
90n/astatic PyObject*
91n/aPyLocale_setlocale(PyObject* self, PyObject* args)
92n/a{
93n/a int category;
94n/a char *locale = NULL, *result;
95n/a PyObject *result_object;
96n/a
97n/a if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
98n/a return NULL;
99n/a
100n/a#if defined(MS_WINDOWS)
101n/a if (category < LC_MIN || category > LC_MAX)
102n/a {
103n/a PyErr_SetString(Error, "invalid locale category");
104n/a return NULL;
105n/a }
106n/a#endif
107n/a
108n/a if (locale) {
109n/a /* set locale */
110n/a result = setlocale(category, locale);
111n/a if (!result) {
112n/a /* operation failed, no setting was changed */
113n/a PyErr_SetString(Error, "unsupported locale setting");
114n/a return NULL;
115n/a }
116n/a result_object = PyUnicode_DecodeLocale(result, NULL);
117n/a if (!result_object)
118n/a return NULL;
119n/a } else {
120n/a /* get locale */
121n/a result = setlocale(category, NULL);
122n/a if (!result) {
123n/a PyErr_SetString(Error, "locale query failed");
124n/a return NULL;
125n/a }
126n/a result_object = PyUnicode_DecodeLocale(result, NULL);
127n/a }
128n/a return result_object;
129n/a}
130n/a
131n/aPyDoc_STRVAR(localeconv__doc__,
132n/a"() -> dict. Returns numeric and monetary locale-specific parameters.");
133n/a
134n/astatic PyObject*
135n/aPyLocale_localeconv(PyObject* self)
136n/a{
137n/a PyObject* result;
138n/a struct lconv *l;
139n/a PyObject *x;
140n/a
141n/a result = PyDict_New();
142n/a if (!result)
143n/a return NULL;
144n/a
145n/a /* if LC_NUMERIC is different in the C library, use saved value */
146n/a l = localeconv();
147n/a
148n/a /* hopefully, the localeconv result survives the C library calls
149n/a involved herein */
150n/a
151n/a#define RESULT(key, obj)\
152n/a do { \
153n/a if (obj == NULL) \
154n/a goto failed; \
155n/a if (PyDict_SetItemString(result, key, obj) < 0) { \
156n/a Py_DECREF(obj); \
157n/a goto failed; \
158n/a } \
159n/a Py_DECREF(obj); \
160n/a } while (0)
161n/a
162n/a#define RESULT_STRING(s)\
163n/a do { \
164n/a x = PyUnicode_DecodeLocale(l->s, NULL); \
165n/a RESULT(#s, x); \
166n/a } while (0)
167n/a
168n/a#define RESULT_INT(i)\
169n/a do { \
170n/a x = PyLong_FromLong(l->i); \
171n/a RESULT(#i, x); \
172n/a } while (0)
173n/a
174n/a /* Numeric information */
175n/a RESULT_STRING(decimal_point);
176n/a RESULT_STRING(thousands_sep);
177n/a x = copy_grouping(l->grouping);
178n/a RESULT("grouping", x);
179n/a
180n/a /* Monetary information */
181n/a RESULT_STRING(int_curr_symbol);
182n/a RESULT_STRING(currency_symbol);
183n/a RESULT_STRING(mon_decimal_point);
184n/a RESULT_STRING(mon_thousands_sep);
185n/a x = copy_grouping(l->mon_grouping);
186n/a RESULT("mon_grouping", x);
187n/a
188n/a RESULT_STRING(positive_sign);
189n/a RESULT_STRING(negative_sign);
190n/a RESULT_INT(int_frac_digits);
191n/a RESULT_INT(frac_digits);
192n/a RESULT_INT(p_cs_precedes);
193n/a RESULT_INT(p_sep_by_space);
194n/a RESULT_INT(n_cs_precedes);
195n/a RESULT_INT(n_sep_by_space);
196n/a RESULT_INT(p_sign_posn);
197n/a RESULT_INT(n_sign_posn);
198n/a return result;
199n/a
200n/a failed:
201n/a Py_XDECREF(result);
202n/a return NULL;
203n/a}
204n/a
205n/a#if defined(HAVE_WCSCOLL)
206n/aPyDoc_STRVAR(strcoll__doc__,
207n/a"string,string -> int. Compares two strings according to the locale.");
208n/a
209n/astatic PyObject*
210n/aPyLocale_strcoll(PyObject* self, PyObject* args)
211n/a{
212n/a PyObject *os1, *os2, *result = NULL;
213n/a wchar_t *ws1 = NULL, *ws2 = NULL;
214n/a
215n/a if (!PyArg_ParseTuple(args, "UU:strcoll", &os1, &os2))
216n/a return NULL;
217n/a /* Convert the unicode strings to wchar[]. */
218n/a ws1 = PyUnicode_AsWideCharString(os1, NULL);
219n/a if (ws1 == NULL)
220n/a goto done;
221n/a ws2 = PyUnicode_AsWideCharString(os2, NULL);
222n/a if (ws2 == NULL)
223n/a goto done;
224n/a /* Collate the strings. */
225n/a result = PyLong_FromLong(wcscoll(ws1, ws2));
226n/a done:
227n/a /* Deallocate everything. */
228n/a if (ws1) PyMem_FREE(ws1);
229n/a if (ws2) PyMem_FREE(ws2);
230n/a return result;
231n/a}
232n/a#endif
233n/a
234n/a#ifdef HAVE_WCSXFRM
235n/aPyDoc_STRVAR(strxfrm__doc__,
236n/a"strxfrm(string) -> string.\n\
237n/a\n\
238n/aReturn a string that can be used as a key for locale-aware comparisons.");
239n/a
240n/astatic PyObject*
241n/aPyLocale_strxfrm(PyObject* self, PyObject* args)
242n/a{
243n/a PyObject *str;
244n/a Py_ssize_t n1;
245n/a wchar_t *s = NULL, *buf = NULL;
246n/a size_t n2;
247n/a PyObject *result = NULL;
248n/a
249n/a if (!PyArg_ParseTuple(args, "U:strxfrm", &str))
250n/a return NULL;
251n/a
252n/a s = PyUnicode_AsWideCharString(str, &n1);
253n/a if (s == NULL)
254n/a goto exit;
255n/a
256n/a /* assume no change in size, first */
257n/a n1 = n1 + 1;
258n/a buf = PyMem_New(wchar_t, n1);
259n/a if (!buf) {
260n/a PyErr_NoMemory();
261n/a goto exit;
262n/a }
263n/a n2 = wcsxfrm(buf, s, n1);
264n/a if (n2 >= (size_t)n1) {
265n/a /* more space needed */
266n/a wchar_t * new_buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
267n/a if (!new_buf) {
268n/a PyErr_NoMemory();
269n/a goto exit;
270n/a }
271n/a buf = new_buf;
272n/a n2 = wcsxfrm(buf, s, n2+1);
273n/a }
274n/a result = PyUnicode_FromWideChar(buf, n2);
275n/aexit:
276n/a if (buf)
277n/a PyMem_Free(buf);
278n/a if (s)
279n/a PyMem_Free(s);
280n/a return result;
281n/a}
282n/a#endif
283n/a
284n/a#if defined(MS_WINDOWS)
285n/astatic PyObject*
286n/aPyLocale_getdefaultlocale(PyObject* self)
287n/a{
288n/a char encoding[100];
289n/a char locale[100];
290n/a
291n/a PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
292n/a
293n/a if (GetLocaleInfo(LOCALE_USER_DEFAULT,
294n/a LOCALE_SISO639LANGNAME,
295n/a locale, sizeof(locale))) {
296n/a Py_ssize_t i = strlen(locale);
297n/a locale[i++] = '_';
298n/a if (GetLocaleInfo(LOCALE_USER_DEFAULT,
299n/a LOCALE_SISO3166CTRYNAME,
300n/a locale+i, (int)(sizeof(locale)-i)))
301n/a return Py_BuildValue("ss", locale, encoding);
302n/a }
303n/a
304n/a /* If we end up here, this windows version didn't know about
305n/a ISO639/ISO3166 names (it's probably Windows 95). Return the
306n/a Windows language identifier instead (a hexadecimal number) */
307n/a
308n/a locale[0] = '0';
309n/a locale[1] = 'x';
310n/a if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
311n/a locale+2, sizeof(locale)-2)) {
312n/a return Py_BuildValue("ss", locale, encoding);
313n/a }
314n/a
315n/a /* cannot determine the language code (very unlikely) */
316n/a Py_INCREF(Py_None);
317n/a return Py_BuildValue("Os", Py_None, encoding);
318n/a}
319n/a#endif
320n/a
321n/a#ifdef HAVE_LANGINFO_H
322n/a#define LANGINFO(X) {#X, X}
323n/astatic struct langinfo_constant{
324n/a char* name;
325n/a int value;
326n/a} langinfo_constants[] =
327n/a{
328n/a /* These constants should exist on any langinfo implementation */
329n/a LANGINFO(DAY_1),
330n/a LANGINFO(DAY_2),
331n/a LANGINFO(DAY_3),
332n/a LANGINFO(DAY_4),
333n/a LANGINFO(DAY_5),
334n/a LANGINFO(DAY_6),
335n/a LANGINFO(DAY_7),
336n/a
337n/a LANGINFO(ABDAY_1),
338n/a LANGINFO(ABDAY_2),
339n/a LANGINFO(ABDAY_3),
340n/a LANGINFO(ABDAY_4),
341n/a LANGINFO(ABDAY_5),
342n/a LANGINFO(ABDAY_6),
343n/a LANGINFO(ABDAY_7),
344n/a
345n/a LANGINFO(MON_1),
346n/a LANGINFO(MON_2),
347n/a LANGINFO(MON_3),
348n/a LANGINFO(MON_4),
349n/a LANGINFO(MON_5),
350n/a LANGINFO(MON_6),
351n/a LANGINFO(MON_7),
352n/a LANGINFO(MON_8),
353n/a LANGINFO(MON_9),
354n/a LANGINFO(MON_10),
355n/a LANGINFO(MON_11),
356n/a LANGINFO(MON_12),
357n/a
358n/a LANGINFO(ABMON_1),
359n/a LANGINFO(ABMON_2),
360n/a LANGINFO(ABMON_3),
361n/a LANGINFO(ABMON_4),
362n/a LANGINFO(ABMON_5),
363n/a LANGINFO(ABMON_6),
364n/a LANGINFO(ABMON_7),
365n/a LANGINFO(ABMON_8),
366n/a LANGINFO(ABMON_9),
367n/a LANGINFO(ABMON_10),
368n/a LANGINFO(ABMON_11),
369n/a LANGINFO(ABMON_12),
370n/a
371n/a#ifdef RADIXCHAR
372n/a /* The following are not available with glibc 2.0 */
373n/a LANGINFO(RADIXCHAR),
374n/a LANGINFO(THOUSEP),
375n/a /* YESSTR and NOSTR are deprecated in glibc, since they are
376n/a a special case of message translation, which should be rather
377n/a done using gettext. So we don't expose it to Python in the
378n/a first place.
379n/a LANGINFO(YESSTR),
380n/a LANGINFO(NOSTR),
381n/a */
382n/a LANGINFO(CRNCYSTR),
383n/a#endif
384n/a
385n/a LANGINFO(D_T_FMT),
386n/a LANGINFO(D_FMT),
387n/a LANGINFO(T_FMT),
388n/a LANGINFO(AM_STR),
389n/a LANGINFO(PM_STR),
390n/a
391n/a /* The following constants are available only with XPG4, but...
392n/a AIX 3.2. only has CODESET.
393n/a OpenBSD doesn't have CODESET but has T_FMT_AMPM, and doesn't have
394n/a a few of the others.
395n/a Solution: ifdef-test them all. */
396n/a#ifdef CODESET
397n/a LANGINFO(CODESET),
398n/a#endif
399n/a#ifdef T_FMT_AMPM
400n/a LANGINFO(T_FMT_AMPM),
401n/a#endif
402n/a#ifdef ERA
403n/a LANGINFO(ERA),
404n/a#endif
405n/a#ifdef ERA_D_FMT
406n/a LANGINFO(ERA_D_FMT),
407n/a#endif
408n/a#ifdef ERA_D_T_FMT
409n/a LANGINFO(ERA_D_T_FMT),
410n/a#endif
411n/a#ifdef ERA_T_FMT
412n/a LANGINFO(ERA_T_FMT),
413n/a#endif
414n/a#ifdef ALT_DIGITS
415n/a LANGINFO(ALT_DIGITS),
416n/a#endif
417n/a#ifdef YESEXPR
418n/a LANGINFO(YESEXPR),
419n/a#endif
420n/a#ifdef NOEXPR
421n/a LANGINFO(NOEXPR),
422n/a#endif
423n/a#ifdef _DATE_FMT
424n/a /* This is not available in all glibc versions that have CODESET. */
425n/a LANGINFO(_DATE_FMT),
426n/a#endif
427n/a {0, 0}
428n/a};
429n/a
430n/aPyDoc_STRVAR(nl_langinfo__doc__,
431n/a"nl_langinfo(key) -> string\n"
432n/a"Return the value for the locale information associated with key.");
433n/a
434n/astatic PyObject*
435n/aPyLocale_nl_langinfo(PyObject* self, PyObject* args)
436n/a{
437n/a int item, i;
438n/a if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
439n/a return NULL;
440n/a /* Check whether this is a supported constant. GNU libc sometimes
441n/a returns numeric values in the char* return value, which would
442n/a crash PyUnicode_FromString. */
443n/a for (i = 0; langinfo_constants[i].name; i++)
444n/a if (langinfo_constants[i].value == item) {
445n/a /* Check NULL as a workaround for GNU libc's returning NULL
446n/a instead of an empty string for nl_langinfo(ERA). */
447n/a const char *result = nl_langinfo(item);
448n/a result = result != NULL ? result : "";
449n/a return PyUnicode_DecodeLocale(result, NULL);
450n/a }
451n/a PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
452n/a return NULL;
453n/a}
454n/a#endif /* HAVE_LANGINFO_H */
455n/a
456n/a#ifdef HAVE_LIBINTL_H
457n/a
458n/aPyDoc_STRVAR(gettext__doc__,
459n/a"gettext(msg) -> string\n"
460n/a"Return translation of msg.");
461n/a
462n/astatic PyObject*
463n/aPyIntl_gettext(PyObject* self, PyObject *args)
464n/a{
465n/a char *in;
466n/a if (!PyArg_ParseTuple(args, "s", &in))
467n/a return 0;
468n/a return PyUnicode_DecodeLocale(gettext(in), NULL);
469n/a}
470n/a
471n/aPyDoc_STRVAR(dgettext__doc__,
472n/a"dgettext(domain, msg) -> string\n"
473n/a"Return translation of msg in domain.");
474n/a
475n/astatic PyObject*
476n/aPyIntl_dgettext(PyObject* self, PyObject *args)
477n/a{
478n/a char *domain, *in;
479n/a if (!PyArg_ParseTuple(args, "zs", &domain, &in))
480n/a return 0;
481n/a return PyUnicode_DecodeLocale(dgettext(domain, in), NULL);
482n/a}
483n/a
484n/aPyDoc_STRVAR(dcgettext__doc__,
485n/a"dcgettext(domain, msg, category) -> string\n"
486n/a"Return translation of msg in domain and category.");
487n/a
488n/astatic PyObject*
489n/aPyIntl_dcgettext(PyObject *self, PyObject *args)
490n/a{
491n/a char *domain, *msgid;
492n/a int category;
493n/a if (!PyArg_ParseTuple(args, "zsi", &domain, &msgid, &category))
494n/a return 0;
495n/a return PyUnicode_DecodeLocale(dcgettext(domain,msgid,category), NULL);
496n/a}
497n/a
498n/aPyDoc_STRVAR(textdomain__doc__,
499n/a"textdomain(domain) -> string\n"
500n/a"Set the C library's textdmain to domain, returning the new domain.");
501n/a
502n/astatic PyObject*
503n/aPyIntl_textdomain(PyObject* self, PyObject* args)
504n/a{
505n/a char *domain;
506n/a if (!PyArg_ParseTuple(args, "z", &domain))
507n/a return 0;
508n/a domain = textdomain(domain);
509n/a if (!domain) {
510n/a PyErr_SetFromErrno(PyExc_OSError);
511n/a return NULL;
512n/a }
513n/a return PyUnicode_DecodeLocale(domain, NULL);
514n/a}
515n/a
516n/aPyDoc_STRVAR(bindtextdomain__doc__,
517n/a"bindtextdomain(domain, dir) -> string\n"
518n/a"Bind the C library's domain to dir.");
519n/a
520n/astatic PyObject*
521n/aPyIntl_bindtextdomain(PyObject* self,PyObject*args)
522n/a{
523n/a char *domain, *dirname, *current_dirname;
524n/a PyObject *dirname_obj, *dirname_bytes = NULL, *result;
525n/a if (!PyArg_ParseTuple(args, "sO", &domain, &dirname_obj))
526n/a return 0;
527n/a if (!strlen(domain)) {
528n/a PyErr_SetString(Error, "domain must be a non-empty string");
529n/a return 0;
530n/a }
531n/a if (dirname_obj != Py_None) {
532n/a if (!PyUnicode_FSConverter(dirname_obj, &dirname_bytes))
533n/a return NULL;
534n/a dirname = PyBytes_AsString(dirname_bytes);
535n/a } else {
536n/a dirname_bytes = NULL;
537n/a dirname = NULL;
538n/a }
539n/a current_dirname = bindtextdomain(domain, dirname);
540n/a if (current_dirname == NULL) {
541n/a Py_XDECREF(dirname_bytes);
542n/a PyErr_SetFromErrno(PyExc_OSError);
543n/a return NULL;
544n/a }
545n/a result = PyUnicode_DecodeLocale(current_dirname, NULL);
546n/a Py_XDECREF(dirname_bytes);
547n/a return result;
548n/a}
549n/a
550n/a#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
551n/aPyDoc_STRVAR(bind_textdomain_codeset__doc__,
552n/a"bind_textdomain_codeset(domain, codeset) -> string\n"
553n/a"Bind the C library's domain to codeset.");
554n/a
555n/astatic PyObject*
556n/aPyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
557n/a{
558n/a char *domain,*codeset;
559n/a if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
560n/a return NULL;
561n/a codeset = bind_textdomain_codeset(domain, codeset);
562n/a if (codeset)
563n/a return PyUnicode_DecodeLocale(codeset, NULL);
564n/a Py_RETURN_NONE;
565n/a}
566n/a#endif
567n/a
568n/a#endif
569n/a
570n/astatic struct PyMethodDef PyLocale_Methods[] = {
571n/a {"setlocale", (PyCFunction) PyLocale_setlocale,
572n/a METH_VARARGS, setlocale__doc__},
573n/a {"localeconv", (PyCFunction) PyLocale_localeconv,
574n/a METH_NOARGS, localeconv__doc__},
575n/a#ifdef HAVE_WCSCOLL
576n/a {"strcoll", (PyCFunction) PyLocale_strcoll,
577n/a METH_VARARGS, strcoll__doc__},
578n/a#endif
579n/a#ifdef HAVE_WCSXFRM
580n/a {"strxfrm", (PyCFunction) PyLocale_strxfrm,
581n/a METH_VARARGS, strxfrm__doc__},
582n/a#endif
583n/a#if defined(MS_WINDOWS)
584n/a {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
585n/a#endif
586n/a#ifdef HAVE_LANGINFO_H
587n/a {"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
588n/a METH_VARARGS, nl_langinfo__doc__},
589n/a#endif
590n/a#ifdef HAVE_LIBINTL_H
591n/a {"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,
592n/a gettext__doc__},
593n/a {"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,
594n/a dgettext__doc__},
595n/a {"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,
596n/a dcgettext__doc__},
597n/a {"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,
598n/a textdomain__doc__},
599n/a {"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,
600n/a bindtextdomain__doc__},
601n/a#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
602n/a {"bind_textdomain_codeset",(PyCFunction)PyIntl_bind_textdomain_codeset,
603n/a METH_VARARGS, bind_textdomain_codeset__doc__},
604n/a#endif
605n/a#endif
606n/a {NULL, NULL}
607n/a};
608n/a
609n/a
610n/astatic struct PyModuleDef _localemodule = {
611n/a PyModuleDef_HEAD_INIT,
612n/a "_locale",
613n/a locale__doc__,
614n/a -1,
615n/a PyLocale_Methods,
616n/a NULL,
617n/a NULL,
618n/a NULL,
619n/a NULL
620n/a};
621n/a
622n/aPyMODINIT_FUNC
623n/aPyInit__locale(void)
624n/a{
625n/a PyObject *m;
626n/a#ifdef HAVE_LANGINFO_H
627n/a int i;
628n/a#endif
629n/a
630n/a m = PyModule_Create(&_localemodule);
631n/a if (m == NULL)
632n/a return NULL;
633n/a
634n/a PyModule_AddIntMacro(m, LC_CTYPE);
635n/a PyModule_AddIntMacro(m, LC_TIME);
636n/a PyModule_AddIntMacro(m, LC_COLLATE);
637n/a PyModule_AddIntMacro(m, LC_MONETARY);
638n/a
639n/a#ifdef LC_MESSAGES
640n/a PyModule_AddIntMacro(m, LC_MESSAGES);
641n/a#endif /* LC_MESSAGES */
642n/a
643n/a PyModule_AddIntMacro(m, LC_NUMERIC);
644n/a PyModule_AddIntMacro(m, LC_ALL);
645n/a PyModule_AddIntMacro(m, CHAR_MAX);
646n/a
647n/a Error = PyErr_NewException("locale.Error", NULL, NULL);
648n/a if (Error == NULL) {
649n/a Py_DECREF(m);
650n/a return NULL;
651n/a }
652n/a PyModule_AddObject(m, "Error", Error);
653n/a
654n/a#ifdef HAVE_LANGINFO_H
655n/a for (i = 0; langinfo_constants[i].name; i++) {
656n/a PyModule_AddIntConstant(m, langinfo_constants[i].name,
657n/a langinfo_constants[i].value);
658n/a }
659n/a#endif
660n/a
661n/a if (PyErr_Occurred()) {
662n/a Py_DECREF(m);
663n/a return NULL;
664n/a }
665n/a return m;
666n/a}
667n/a
668n/a/*
669n/aLocal variables:
670n/ac-basic-offset: 4
671n/aindent-tabs-mode: nil
672n/aEnd:
673n/a*/