--- /dev/null
+/***********************************************************\r
+Copyright (C) 1997, 2002, 2003 Martin von Loewis\r
+\r
+Permission to use, copy, modify, and distribute this software and its\r
+documentation for any purpose and without fee is hereby granted,\r
+provided that the above copyright notice appear in all copies.\r
+\r
+This software comes with no warranty. Use at your own risk.\r
+\r
+******************************************************************/\r
+\r
+#include "Python.h"\r
+\r
+#include <stdio.h>\r
+#include <locale.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+\r
+#ifdef HAVE_ERRNO_H\r
+#include <errno.h>\r
+#endif\r
+\r
+#ifdef HAVE_LANGINFO_H\r
+#include <langinfo.h>\r
+#endif\r
+\r
+#ifdef HAVE_LIBINTL_H\r
+#include <libintl.h>\r
+#endif\r
+\r
+#ifdef HAVE_WCHAR_H\r
+#include <wchar.h>\r
+#endif\r
+\r
+#if defined(MS_WINDOWS)\r
+#define WIN32_LEAN_AND_MEAN\r
+#include <windows.h>\r
+#endif\r
+\r
+#ifdef RISCOS\r
+char *strdup(const char *);\r
+#endif\r
+\r
+PyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");\r
+\r
+static PyObject *Error;\r
+\r
+/* support functions for formatting floating point numbers */\r
+\r
+PyDoc_STRVAR(setlocale__doc__,\r
+"(integer,string=None) -> string. Activates/queries locale processing.");\r
+\r
+/* the grouping is terminated by either 0 or CHAR_MAX */\r
+static PyObject*\r
+copy_grouping(char* s)\r
+{\r
+ int i;\r
+ PyObject *result, *val = NULL;\r
+\r
+ if (s[0] == '\0')\r
+ /* empty string: no grouping at all */\r
+ return PyList_New(0);\r
+\r
+ for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)\r
+ ; /* nothing */\r
+\r
+ result = PyList_New(i+1);\r
+ if (!result)\r
+ return NULL;\r
+\r
+ i = -1;\r
+ do {\r
+ i++;\r
+ val = PyInt_FromLong(s[i]);\r
+ if (!val)\r
+ break;\r
+ if (PyList_SetItem(result, i, val)) {\r
+ Py_DECREF(val);\r
+ val = NULL;\r
+ break;\r
+ }\r
+ } while (s[i] != '\0' && s[i] != CHAR_MAX);\r
+\r
+ if (!val) {\r
+ Py_DECREF(result);\r
+ return NULL;\r
+ }\r
+\r
+ return result;\r
+}\r
+\r
+static void\r
+fixup_ulcase(void)\r
+{\r
+ PyObject *mods, *strop, *string, *ulo;\r
+ unsigned char ul[256];\r
+ int n, c;\r
+\r
+ /* find the string and strop modules */\r
+ mods = PyImport_GetModuleDict();\r
+ if (!mods)\r
+ return;\r
+ string = PyDict_GetItemString(mods, "string");\r
+ if (string)\r
+ string = PyModule_GetDict(string);\r
+ strop=PyDict_GetItemString(mods, "strop");\r
+ if (strop)\r
+ strop = PyModule_GetDict(strop);\r
+ if (!string && !strop)\r
+ return;\r
+\r
+ /* create uppercase map string */\r
+ n = 0;\r
+ for (c = 0; c < 256; c++) {\r
+ if (isupper(c))\r
+ ul[n++] = c;\r
+ }\r
+ ulo = PyString_FromStringAndSize((const char *)ul, n);\r
+ if (!ulo)\r
+ return;\r
+ if (string)\r
+ PyDict_SetItemString(string, "uppercase", ulo);\r
+ if (strop)\r
+ PyDict_SetItemString(strop, "uppercase", ulo);\r
+ Py_DECREF(ulo);\r
+\r
+ /* create lowercase string */\r
+ n = 0;\r
+ for (c = 0; c < 256; c++) {\r
+ if (islower(c))\r
+ ul[n++] = c;\r
+ }\r
+ ulo = PyString_FromStringAndSize((const char *)ul, n);\r
+ if (!ulo)\r
+ return;\r
+ if (string)\r
+ PyDict_SetItemString(string, "lowercase", ulo);\r
+ if (strop)\r
+ PyDict_SetItemString(strop, "lowercase", ulo);\r
+ Py_DECREF(ulo);\r
+\r
+ /* create letters string */\r
+ n = 0;\r
+ for (c = 0; c < 256; c++) {\r
+ if (isalpha(c))\r
+ ul[n++] = c;\r
+ }\r
+ ulo = PyString_FromStringAndSize((const char *)ul, n);\r
+ if (!ulo)\r
+ return;\r
+ if (string)\r
+ PyDict_SetItemString(string, "letters", ulo);\r
+ Py_DECREF(ulo);\r
+}\r
+\r
+static PyObject*\r
+PyLocale_setlocale(PyObject* self, PyObject* args)\r
+{\r
+ int category;\r
+ char *locale = NULL, *result;\r
+ PyObject *result_object;\r
+\r
+ if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))\r
+ return NULL;\r
+\r
+#if defined(MS_WINDOWS)\r
+ if (category < LC_MIN || category > LC_MAX)\r
+ {\r
+ PyErr_SetString(Error, "invalid locale category");\r
+ return NULL;\r
+ }\r
+#endif\r
+\r
+ if (locale) {\r
+ /* set locale */\r
+ result = setlocale(category, locale);\r
+ if (!result) {\r
+ /* operation failed, no setting was changed */\r
+ PyErr_SetString(Error, "unsupported locale setting");\r
+ return NULL;\r
+ }\r
+ result_object = PyString_FromString(result);\r
+ if (!result_object)\r
+ return NULL;\r
+ /* record changes to LC_CTYPE */\r
+ if (category == LC_CTYPE || category == LC_ALL)\r
+ fixup_ulcase();\r
+ /* things that got wrong up to here are ignored */\r
+ PyErr_Clear();\r
+ } else {\r
+ /* get locale */\r
+ result = setlocale(category, NULL);\r
+ if (!result) {\r
+ PyErr_SetString(Error, "locale query failed");\r
+ return NULL;\r
+ }\r
+ result_object = PyString_FromString(result);\r
+ }\r
+ return result_object;\r
+}\r
+\r
+PyDoc_STRVAR(localeconv__doc__,\r
+"() -> dict. Returns numeric and monetary locale-specific parameters.");\r
+\r
+static PyObject*\r
+PyLocale_localeconv(PyObject* self)\r
+{\r
+ PyObject* result;\r
+ struct lconv *l;\r
+ PyObject *x;\r
+\r
+ result = PyDict_New();\r
+ if (!result)\r
+ return NULL;\r
+\r
+ /* if LC_NUMERIC is different in the C library, use saved value */\r
+ l = localeconv();\r
+\r
+ /* hopefully, the localeconv result survives the C library calls\r
+ involved herein */\r
+\r
+#define RESULT_STRING(s)\\r
+ x = PyString_FromString(l->s);\\r
+ if (!x) goto failed;\\r
+ PyDict_SetItemString(result, #s, x);\\r
+ Py_XDECREF(x)\r
+\r
+#define RESULT_INT(i)\\r
+ x = PyInt_FromLong(l->i);\\r
+ if (!x) goto failed;\\r
+ PyDict_SetItemString(result, #i, x);\\r
+ Py_XDECREF(x)\r
+\r
+ /* Numeric information */\r
+ RESULT_STRING(decimal_point);\r
+ RESULT_STRING(thousands_sep);\r
+ x = copy_grouping(l->grouping);\r
+ if (!x)\r
+ goto failed;\r
+ PyDict_SetItemString(result, "grouping", x);\r
+ Py_XDECREF(x);\r
+\r
+ /* Monetary information */\r
+ RESULT_STRING(int_curr_symbol);\r
+ RESULT_STRING(currency_symbol);\r
+ RESULT_STRING(mon_decimal_point);\r
+ RESULT_STRING(mon_thousands_sep);\r
+ x = copy_grouping(l->mon_grouping);\r
+ if (!x)\r
+ goto failed;\r
+ PyDict_SetItemString(result, "mon_grouping", x);\r
+ Py_XDECREF(x);\r
+ RESULT_STRING(positive_sign);\r
+ RESULT_STRING(negative_sign);\r
+ RESULT_INT(int_frac_digits);\r
+ RESULT_INT(frac_digits);\r
+ RESULT_INT(p_cs_precedes);\r
+ RESULT_INT(p_sep_by_space);\r
+ RESULT_INT(n_cs_precedes);\r
+ RESULT_INT(n_sep_by_space);\r
+ RESULT_INT(p_sign_posn);\r
+ RESULT_INT(n_sign_posn);\r
+ return result;\r
+\r
+ failed:\r
+ Py_XDECREF(result);\r
+ Py_XDECREF(x);\r
+ return NULL;\r
+}\r
+\r
+PyDoc_STRVAR(strcoll__doc__,\r
+"string,string -> int. Compares two strings according to the locale.");\r
+\r
+static PyObject*\r
+PyLocale_strcoll(PyObject* self, PyObject* args)\r
+{\r
+#if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)\r
+ char *s1,*s2;\r
+\r
+ if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))\r
+ return NULL;\r
+ return PyInt_FromLong(strcoll(s1, s2));\r
+#else\r
+ PyObject *os1, *os2, *result = NULL;\r
+ wchar_t *ws1 = NULL, *ws2 = NULL;\r
+ int rel1 = 0, rel2 = 0, len1, len2;\r
+\r
+ if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))\r
+ return NULL;\r
+ /* If both arguments are byte strings, use strcoll. */\r
+ if (PyString_Check(os1) && PyString_Check(os2))\r
+ return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),\r
+ PyString_AS_STRING(os2)));\r
+ /* If neither argument is unicode, it's an error. */\r
+ if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {\r
+ PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");\r
+ }\r
+ /* Convert the non-unicode argument to unicode. */\r
+ if (!PyUnicode_Check(os1)) {\r
+ os1 = PyUnicode_FromObject(os1);\r
+ if (!os1)\r
+ return NULL;\r
+ rel1 = 1;\r
+ }\r
+ if (!PyUnicode_Check(os2)) {\r
+ os2 = PyUnicode_FromObject(os2);\r
+ if (!os2) {\r
+ if (rel1) {\r
+ Py_DECREF(os1);\r
+ }\r
+ return NULL;\r
+ }\r
+ rel2 = 1;\r
+ }\r
+ /* Convert the unicode strings to wchar[]. */\r
+ len1 = PyUnicode_GET_SIZE(os1) + 1;\r
+ ws1 = PyMem_NEW(wchar_t, len1);\r
+ if (!ws1) {\r
+ PyErr_NoMemory();\r
+ goto done;\r
+ }\r
+ if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)\r
+ goto done;\r
+ ws1[len1 - 1] = 0;\r
+ len2 = PyUnicode_GET_SIZE(os2) + 1;\r
+ ws2 = PyMem_NEW(wchar_t, len2);\r
+ if (!ws2) {\r
+ PyErr_NoMemory();\r
+ goto done;\r
+ }\r
+ if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)\r
+ goto done;\r
+ ws2[len2 - 1] = 0;\r
+ /* Collate the strings. */\r
+ result = PyInt_FromLong(wcscoll(ws1, ws2));\r
+ done:\r
+ /* Deallocate everything. */\r
+ if (ws1) PyMem_FREE(ws1);\r
+ if (ws2) PyMem_FREE(ws2);\r
+ if (rel1) {\r
+ Py_DECREF(os1);\r
+ }\r
+ if (rel2) {\r
+ Py_DECREF(os2);\r
+ }\r
+ return result;\r
+#endif\r
+}\r
+\r
+\r
+PyDoc_STRVAR(strxfrm__doc__,\r
+"string -> string. Returns a string that behaves for cmp locale-aware.");\r
+\r
+static PyObject*\r
+PyLocale_strxfrm(PyObject* self, PyObject* args)\r
+{\r
+ char *s, *buf;\r
+ size_t n1, n2;\r
+ PyObject *result;\r
+\r
+ if (!PyArg_ParseTuple(args, "s:strxfrm", &s))\r
+ return NULL;\r
+\r
+ /* assume no change in size, first */\r
+ n1 = strlen(s) + 1;\r
+ buf = PyMem_Malloc(n1);\r
+ if (!buf)\r
+ return PyErr_NoMemory();\r
+ n2 = strxfrm(buf, s, n1) + 1;\r
+ if (n2 > n1) {\r
+ /* more space needed */\r
+ buf = PyMem_Realloc(buf, n2);\r
+ if (!buf)\r
+ return PyErr_NoMemory();\r
+ strxfrm(buf, s, n2);\r
+ }\r
+ result = PyString_FromString(buf);\r
+ PyMem_Free(buf);\r
+ return result;\r
+}\r
+\r
+#if defined(MS_WINDOWS)\r
+static PyObject*\r
+PyLocale_getdefaultlocale(PyObject* self)\r
+{\r
+ char encoding[100];\r
+ char locale[100];\r
+\r
+ PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());\r
+\r
+ if (GetLocaleInfo(LOCALE_USER_DEFAULT,\r
+ LOCALE_SISO639LANGNAME,\r
+ locale, sizeof(locale))) {\r
+ Py_ssize_t i = strlen(locale);\r
+ locale[i++] = '_';\r
+ if (GetLocaleInfo(LOCALE_USER_DEFAULT,\r
+ LOCALE_SISO3166CTRYNAME,\r
+ locale+i, (int)(sizeof(locale)-i)))\r
+ return Py_BuildValue("ss", locale, encoding);\r
+ }\r
+\r
+ /* If we end up here, this windows version didn't know about\r
+ ISO639/ISO3166 names (it's probably Windows 95). Return the\r
+ Windows language identifier instead (a hexadecimal number) */\r
+\r
+ locale[0] = '0';\r
+ locale[1] = 'x';\r
+ if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,\r
+ locale+2, sizeof(locale)-2)) {\r
+ return Py_BuildValue("ss", locale, encoding);\r
+ }\r
+\r
+ /* cannot determine the language code (very unlikely) */\r
+ Py_INCREF(Py_None);\r
+ return Py_BuildValue("Os", Py_None, encoding);\r
+}\r
+#endif\r
+\r
+#ifdef HAVE_LANGINFO_H\r
+#define LANGINFO(X) {#X, X}\r
+static struct langinfo_constant{\r
+ char* name;\r
+ int value;\r
+} langinfo_constants[] =\r
+{\r
+ /* These constants should exist on any langinfo implementation */\r
+ LANGINFO(DAY_1),\r
+ LANGINFO(DAY_2),\r
+ LANGINFO(DAY_3),\r
+ LANGINFO(DAY_4),\r
+ LANGINFO(DAY_5),\r
+ LANGINFO(DAY_6),\r
+ LANGINFO(DAY_7),\r
+\r
+ LANGINFO(ABDAY_1),\r
+ LANGINFO(ABDAY_2),\r
+ LANGINFO(ABDAY_3),\r
+ LANGINFO(ABDAY_4),\r
+ LANGINFO(ABDAY_5),\r
+ LANGINFO(ABDAY_6),\r
+ LANGINFO(ABDAY_7),\r
+\r
+ LANGINFO(MON_1),\r
+ LANGINFO(MON_2),\r
+ LANGINFO(MON_3),\r
+ LANGINFO(MON_4),\r
+ LANGINFO(MON_5),\r
+ LANGINFO(MON_6),\r
+ LANGINFO(MON_7),\r
+ LANGINFO(MON_8),\r
+ LANGINFO(MON_9),\r
+ LANGINFO(MON_10),\r
+ LANGINFO(MON_11),\r
+ LANGINFO(MON_12),\r
+\r
+ LANGINFO(ABMON_1),\r
+ LANGINFO(ABMON_2),\r
+ LANGINFO(ABMON_3),\r
+ LANGINFO(ABMON_4),\r
+ LANGINFO(ABMON_5),\r
+ LANGINFO(ABMON_6),\r
+ LANGINFO(ABMON_7),\r
+ LANGINFO(ABMON_8),\r
+ LANGINFO(ABMON_9),\r
+ LANGINFO(ABMON_10),\r
+ LANGINFO(ABMON_11),\r
+ LANGINFO(ABMON_12),\r
+\r
+#ifdef RADIXCHAR\r
+ /* The following are not available with glibc 2.0 */\r
+ LANGINFO(RADIXCHAR),\r
+ LANGINFO(THOUSEP),\r
+ /* YESSTR and NOSTR are deprecated in glibc, since they are\r
+ a special case of message translation, which should be rather\r
+ done using gettext. So we don't expose it to Python in the\r
+ first place.\r
+ LANGINFO(YESSTR),\r
+ LANGINFO(NOSTR),\r
+ */\r
+ LANGINFO(CRNCYSTR),\r
+#endif\r
+\r
+ LANGINFO(D_T_FMT),\r
+ LANGINFO(D_FMT),\r
+ LANGINFO(T_FMT),\r
+ LANGINFO(AM_STR),\r
+ LANGINFO(PM_STR),\r
+\r
+ /* The following constants are available only with XPG4, but...\r
+ AIX 3.2. only has CODESET.\r
+ OpenBSD doesn't have CODESET but has T_FMT_AMPM, and doesn't have\r
+ a few of the others.\r
+ Solution: ifdef-test them all. */\r
+#ifdef CODESET\r
+ LANGINFO(CODESET),\r
+#endif\r
+#ifdef T_FMT_AMPM\r
+ LANGINFO(T_FMT_AMPM),\r
+#endif\r
+#ifdef ERA\r
+ LANGINFO(ERA),\r
+#endif\r
+#ifdef ERA_D_FMT\r
+ LANGINFO(ERA_D_FMT),\r
+#endif\r
+#ifdef ERA_D_T_FMT\r
+ LANGINFO(ERA_D_T_FMT),\r
+#endif\r
+#ifdef ERA_T_FMT\r
+ LANGINFO(ERA_T_FMT),\r
+#endif\r
+#ifdef ALT_DIGITS\r
+ LANGINFO(ALT_DIGITS),\r
+#endif\r
+#ifdef YESEXPR\r
+ LANGINFO(YESEXPR),\r
+#endif\r
+#ifdef NOEXPR\r
+ LANGINFO(NOEXPR),\r
+#endif\r
+#ifdef _DATE_FMT\r
+ /* This is not available in all glibc versions that have CODESET. */\r
+ LANGINFO(_DATE_FMT),\r
+#endif\r
+ {0, 0}\r
+};\r
+\r
+PyDoc_STRVAR(nl_langinfo__doc__,\r
+"nl_langinfo(key) -> string\n"\r
+"Return the value for the locale information associated with key.");\r
+\r
+static PyObject*\r
+PyLocale_nl_langinfo(PyObject* self, PyObject* args)\r
+{\r
+ int item, i;\r
+ if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))\r
+ return NULL;\r
+ /* Check whether this is a supported constant. GNU libc sometimes\r
+ returns numeric values in the char* return value, which would\r
+ crash PyString_FromString. */\r
+ for (i = 0; langinfo_constants[i].name; i++)\r
+ if (langinfo_constants[i].value == item) {\r
+ /* Check NULL as a workaround for GNU libc's returning NULL\r
+ instead of an empty string for nl_langinfo(ERA). */\r
+ const char *result = nl_langinfo(item);\r
+ return PyString_FromString(result != NULL ? result : "");\r
+ }\r
+ PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");\r
+ return NULL;\r
+}\r
+#endif /* HAVE_LANGINFO_H */\r
+\r
+#ifdef HAVE_LIBINTL_H\r
+\r
+PyDoc_STRVAR(gettext__doc__,\r
+"gettext(msg) -> string\n"\r
+"Return translation of msg.");\r
+\r
+static PyObject*\r
+PyIntl_gettext(PyObject* self, PyObject *args)\r
+{\r
+ char *in;\r
+ if (!PyArg_ParseTuple(args, "s", &in))\r
+ return 0;\r
+ return PyString_FromString(gettext(in));\r
+}\r
+\r
+PyDoc_STRVAR(dgettext__doc__,\r
+"dgettext(domain, msg) -> string\n"\r
+"Return translation of msg in domain.");\r
+\r
+static PyObject*\r
+PyIntl_dgettext(PyObject* self, PyObject *args)\r
+{\r
+ char *domain, *in;\r
+ if (!PyArg_ParseTuple(args, "zs", &domain, &in))\r
+ return 0;\r
+ return PyString_FromString(dgettext(domain, in));\r
+}\r
+\r
+PyDoc_STRVAR(dcgettext__doc__,\r
+"dcgettext(domain, msg, category) -> string\n"\r
+"Return translation of msg in domain and category.");\r
+\r
+static PyObject*\r
+PyIntl_dcgettext(PyObject *self, PyObject *args)\r
+{\r
+ char *domain, *msgid;\r
+ int category;\r
+ if (!PyArg_ParseTuple(args, "zsi", &domain, &msgid, &category))\r
+ return 0;\r
+ return PyString_FromString(dcgettext(domain,msgid,category));\r
+}\r
+\r
+PyDoc_STRVAR(textdomain__doc__,\r
+"textdomain(domain) -> string\n"\r
+"Set the C library's textdmain to domain, returning the new domain.");\r
+\r
+static PyObject*\r
+PyIntl_textdomain(PyObject* self, PyObject* args)\r
+{\r
+ char *domain;\r
+ if (!PyArg_ParseTuple(args, "z", &domain))\r
+ return 0;\r
+ domain = textdomain(domain);\r
+ if (!domain) {\r
+ PyErr_SetFromErrno(PyExc_OSError);\r
+ return NULL;\r
+ }\r
+ return PyString_FromString(domain);\r
+}\r
+\r
+PyDoc_STRVAR(bindtextdomain__doc__,\r
+"bindtextdomain(domain, dir) -> string\n"\r
+"Bind the C library's domain to dir.");\r
+\r
+static PyObject*\r
+PyIntl_bindtextdomain(PyObject* self,PyObject*args)\r
+{\r
+ char *domain, *dirname;\r
+ if (!PyArg_ParseTuple(args, "sz", &domain, &dirname))\r
+ return 0;\r
+ if (!strlen(domain)) {\r
+ PyErr_SetString(Error, "domain must be a non-empty string");\r
+ return 0;\r
+ }\r
+ dirname = bindtextdomain(domain, dirname);\r
+ if (!dirname) {\r
+ PyErr_SetFromErrno(PyExc_OSError);\r
+ return NULL;\r
+ }\r
+ return PyString_FromString(dirname);\r
+}\r
+\r
+#ifdef HAVE_BIND_TEXTDOMAIN_CODESET\r
+PyDoc_STRVAR(bind_textdomain_codeset__doc__,\r
+"bind_textdomain_codeset(domain, codeset) -> string\n"\r
+"Bind the C library's domain to codeset.");\r
+\r
+static PyObject*\r
+PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)\r
+{\r
+ char *domain,*codeset;\r
+ if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))\r
+ return NULL;\r
+ codeset = bind_textdomain_codeset(domain, codeset);\r
+ if (codeset)\r
+ return PyString_FromString(codeset);\r
+ Py_RETURN_NONE;\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
+static struct PyMethodDef PyLocale_Methods[] = {\r
+ {"setlocale", (PyCFunction) PyLocale_setlocale,\r
+ METH_VARARGS, setlocale__doc__},\r
+ {"localeconv", (PyCFunction) PyLocale_localeconv,\r
+ METH_NOARGS, localeconv__doc__},\r
+ {"strcoll", (PyCFunction) PyLocale_strcoll,\r
+ METH_VARARGS, strcoll__doc__},\r
+ {"strxfrm", (PyCFunction) PyLocale_strxfrm,\r
+ METH_VARARGS, strxfrm__doc__},\r
+#if defined(MS_WINDOWS)\r
+ {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},\r
+#endif\r
+#ifdef HAVE_LANGINFO_H\r
+ {"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,\r
+ METH_VARARGS, nl_langinfo__doc__},\r
+#endif\r
+#ifdef HAVE_LIBINTL_H\r
+ {"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,\r
+ gettext__doc__},\r
+ {"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,\r
+ dgettext__doc__},\r
+ {"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,\r
+ dcgettext__doc__},\r
+ {"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,\r
+ textdomain__doc__},\r
+ {"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,\r
+ bindtextdomain__doc__},\r
+#ifdef HAVE_BIND_TEXTDOMAIN_CODESET\r
+ {"bind_textdomain_codeset",(PyCFunction)PyIntl_bind_textdomain_codeset,\r
+ METH_VARARGS, bind_textdomain_codeset__doc__},\r
+#endif\r
+#endif\r
+ {NULL, NULL}\r
+};\r
+\r
+PyMODINIT_FUNC\r
+init_locale(void)\r
+{\r
+ PyObject *m, *d, *x;\r
+#ifdef HAVE_LANGINFO_H\r
+ int i;\r
+#endif\r
+\r
+ m = Py_InitModule("_locale", PyLocale_Methods);\r
+ if (m == NULL)\r
+ return;\r
+\r
+ d = PyModule_GetDict(m);\r
+\r
+ x = PyInt_FromLong(LC_CTYPE);\r
+ PyDict_SetItemString(d, "LC_CTYPE", x);\r
+ Py_XDECREF(x);\r
+\r
+ x = PyInt_FromLong(LC_TIME);\r
+ PyDict_SetItemString(d, "LC_TIME", x);\r
+ Py_XDECREF(x);\r
+\r
+ x = PyInt_FromLong(LC_COLLATE);\r
+ PyDict_SetItemString(d, "LC_COLLATE", x);\r
+ Py_XDECREF(x);\r
+\r
+ x = PyInt_FromLong(LC_MONETARY);\r
+ PyDict_SetItemString(d, "LC_MONETARY", x);\r
+ Py_XDECREF(x);\r
+\r
+#ifdef LC_MESSAGES\r
+ x = PyInt_FromLong(LC_MESSAGES);\r
+ PyDict_SetItemString(d, "LC_MESSAGES", x);\r
+ Py_XDECREF(x);\r
+#endif /* LC_MESSAGES */\r
+\r
+ x = PyInt_FromLong(LC_NUMERIC);\r
+ PyDict_SetItemString(d, "LC_NUMERIC", x);\r
+ Py_XDECREF(x);\r
+\r
+ x = PyInt_FromLong(LC_ALL);\r
+ PyDict_SetItemString(d, "LC_ALL", x);\r
+ Py_XDECREF(x);\r
+\r
+ x = PyInt_FromLong(CHAR_MAX);\r
+ PyDict_SetItemString(d, "CHAR_MAX", x);\r
+ Py_XDECREF(x);\r
+\r
+ Error = PyErr_NewException("locale.Error", NULL, NULL);\r
+ PyDict_SetItemString(d, "Error", Error);\r
+\r
+ x = PyString_FromString(locale__doc__);\r
+ PyDict_SetItemString(d, "__doc__", x);\r
+ Py_XDECREF(x);\r
+\r
+#ifdef HAVE_LANGINFO_H\r
+ for (i = 0; langinfo_constants[i].name; i++) {\r
+ PyModule_AddIntConstant(m, langinfo_constants[i].name,\r
+ langinfo_constants[i].value);\r
+ }\r
+#endif\r
+}\r
+\r
+/*\r
+Local variables:\r
+c-basic-offset: 4\r
+indent-tabs-mode: nil\r
+End:\r
+*/\r