annotate Modules/_localemodule.c @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents e3ae5b00ba15
children 771064b4466f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
2 Copyright (C) 1997, 2002, 2003, 2007, 2008 Martin von Loewis
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 documentation for any purpose and without fee is hereby granted,
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 provided that the above copyright notice appear in all copies.
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 This software comes with no warranty. Use at your own risk.
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
9
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 ******************************************************************/
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
56637
7ae6d5e4f798 Merged revisions 75537,75539 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56013
diff changeset
12 #define PY_SSIZE_T_CLEAN
13914
693b61581746 Clean up compiler warning exposed by GCC's -Wall option: make sure
Fred Drake <fdrake@acm.org>
parents: 13817
diff changeset
13 #include "Python.h"
693b61581746 Clean up compiler warning exposed by GCC's -Wall option: make sure
Fred Drake <fdrake@acm.org>
parents: 13817
diff changeset
14
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #include <stdio.h>
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 #include <locale.h>
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #include <string.h>
8524
47bf3bb9556e Added <ctype.h>, needed for Windows.
Guido van Rossum <guido@python.org>
parents: 8182
diff changeset
18 #include <ctype.h>
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
19
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
20 #ifdef HAVE_ERRNO_H
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
21 #include <errno.h>
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
22 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
23
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
24 #ifdef HAVE_LANGINFO_H
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
25 #include <langinfo.h>
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
26 #endif
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
27
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
28 #ifdef HAVE_LIBINTL_H
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
29 #include <libintl.h>
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
30 #endif
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
31
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
32 #ifdef HAVE_WCHAR_H
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
33 #include <wchar.h>
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
34 #endif
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
35
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
36 #if defined(MS_WINDOWS)
24233
11c4253698dc WINDOWS_LEAN_AND_MEAN: There is no such symbol, although a very few
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
37 #define WIN32_LEAN_AND_MEAN
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
38 #include <windows.h>
8182
de7fc66c0b4f Type casts, and added a strdup() declaration for the Mac.
Guido van Rossum <guido@python.org>
parents: 6797
diff changeset
39 #endif
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
41 PyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 static PyObject *Error;
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
45 /* Convert a char* to a Unicode object according to the current locale */
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
46 static PyObject*
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
47 str2uni(const char* s)
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
48 {
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
49 #ifdef HAVE_BROKEN_MBSTOWCS
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
50 size_t needed = strlen(s);
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
51 #else
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
52 size_t needed = mbstowcs(NULL, s, 0);
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
53 #endif
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
54 size_t res1;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
55 wchar_t smallbuf[30];
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
56 wchar_t *dest;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
57 PyObject *res2;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
58 if (needed == (size_t)-1) {
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
59 PyErr_SetString(PyExc_ValueError, "Cannot convert byte to string");
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
60 return NULL;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
61 }
45715
94053b27a352 Fix another buffer overflow.
Martin v. Löwis <martin@v.loewis.de>
parents: 45712
diff changeset
62 if (needed*sizeof(wchar_t) < sizeof(smallbuf))
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
63 dest = smallbuf;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
64 else {
45711
c27aabae06fd Properly size memory blocks in units of wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45710
diff changeset
65 dest = PyMem_Malloc((needed+1)*sizeof(wchar_t));
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
66 if (!dest)
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
67 return PyErr_NoMemory();
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
68 }
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
69 /* This shouldn't fail now */
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
70 res1 = mbstowcs(dest, s, needed+1);
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
71 #ifdef HAVE_BROKEN_MBSTOWCS
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
72 assert(res1 != (size_t)-1);
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
73 #else
45712
9a727c9f9baa Fix typo in assertion.
Martin v. Löwis <martin@v.loewis.de>
parents: 45711
diff changeset
74 assert(res1 == needed);
48987
f83dccf417f0 Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48563
diff changeset
75 #endif
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
76 res2 = PyUnicode_FromWideChar(dest, res1);
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
77 if (dest != smallbuf)
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
78 PyMem_Free(dest);
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
79 return res2;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
80 }
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
81
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 /* support functions for formatting floating point numbers */
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
84 PyDoc_STRVAR(setlocale__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
85 "(integer,string=None) -> string. Activates/queries locale processing.");
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 /* the grouping is terminated by either 0 or CHAR_MAX */
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
89 copy_grouping(char* s)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
91 int i;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
92 PyObject *result, *val = NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
93
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
94 if (s[0] == '\0')
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
95 /* empty string: no grouping at all */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
96 return PyList_New(0);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
97
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
98 for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
99 ; /* nothing */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
100
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
101 result = PyList_New(i+1);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
102 if (!result)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
103 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
104
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
105 i = -1;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
106 do {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
107 i++;
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
108 val = PyLong_FromLong(s[i]);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
109 if (!val)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
110 break;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
111 if (PyList_SetItem(result, i, val)) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
112 Py_DECREF(val);
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
113 val = NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
114 break;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
115 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
116 } while (s[i] != '\0' && s[i] != CHAR_MAX);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
117
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
118 if (!val) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
119 Py_DECREF(result);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
120 return NULL;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 }
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
122
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
123 return result;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
127 PyLocale_setlocale(PyObject* self, PyObject* args)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
129 int category;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
130 char *locale = NULL, *result;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
131 PyObject *result_object;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
132
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
133 if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
134 return NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
135
57531
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
136 #if defined(MS_WINDOWS)
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
137 if (category < LC_MIN || category > LC_MAX)
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
138 {
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
139 PyErr_SetString(Error, "invalid locale category");
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
140 return NULL;
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
141 }
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
142 #endif
280369677602 Merged revisions 76626 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 56908
diff changeset
143
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
144 if (locale) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
145 /* set locale */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
146 result = setlocale(category, locale);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
147 if (!result) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
148 /* operation failed, no setting was changed */
30306
41ff2c13ea4a Use de_DE in example, change message for unknown locale. Fixes #797447.
Martin v. Löwis <martin@v.loewis.de>
parents: 29992
diff changeset
149 PyErr_SetString(Error, "unsupported locale setting");
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
150 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
151 }
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
152 result_object = str2uni(result);
29992
35ccfc140cac Fix [ 776721 ] locale.setlocale() leaks
Mark Hammond <mhammond@skippinet.com.au>
parents: 28174
diff changeset
153 if (!result_object)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
154 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
155 } else {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
156 /* get locale */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
157 result = setlocale(category, NULL);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
158 if (!result) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
159 PyErr_SetString(Error, "locale query failed");
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
160 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
161 }
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
162 result_object = str2uni(result);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 }
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
164 return result_object;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
167 PyDoc_STRVAR(localeconv__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
168 "() -> dict. Returns numeric and monetary locale-specific parameters.");
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 static PyObject*
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22330
diff changeset
171 PyLocale_localeconv(PyObject* self)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
173 PyObject* result;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
174 struct lconv *l;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
175 PyObject *x;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
176
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
177 result = PyDict_New();
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
178 if (!result)
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
179 return NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
180
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
181 /* if LC_NUMERIC is different in the C library, use saved value */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
182 l = localeconv();
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
183
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
184 /* hopefully, the localeconv result survives the C library calls
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
185 involved herein */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
186
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
187 #define RESULT_STRING(s)\
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
188 x = str2uni(l->s); \
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
189 if (!x) goto failed;\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
190 PyDict_SetItemString(result, #s, x);\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
191 Py_XDECREF(x)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
192
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
193 #define RESULT_INT(i)\
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
194 x = PyLong_FromLong(l->i);\
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
195 if (!x) goto failed;\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
196 PyDict_SetItemString(result, #i, x);\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
197 Py_XDECREF(x)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 /* Numeric information */
32305
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
200 RESULT_STRING(decimal_point);
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
201 RESULT_STRING(thousands_sep);
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
202 x = copy_grouping(l->grouping);
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
203 if (!x)
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
204 goto failed;
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
205 PyDict_SetItemString(result, "grouping", x);
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
206 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
207
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
208 /* Monetary information */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
209 RESULT_STRING(int_curr_symbol);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
210 RESULT_STRING(currency_symbol);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
211 RESULT_STRING(mon_decimal_point);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
212 RESULT_STRING(mon_thousands_sep);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
213 x = copy_grouping(l->mon_grouping);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
214 if (!x)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
215 goto failed;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
216 PyDict_SetItemString(result, "mon_grouping", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
217 Py_XDECREF(x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
218 RESULT_STRING(positive_sign);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
219 RESULT_STRING(negative_sign);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
220 RESULT_INT(int_frac_digits);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
221 RESULT_INT(frac_digits);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
222 RESULT_INT(p_cs_precedes);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
223 RESULT_INT(p_sep_by_space);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
224 RESULT_INT(n_cs_precedes);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
225 RESULT_INT(n_sep_by_space);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
226 RESULT_INT(p_sign_posn);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
227 RESULT_INT(n_sign_posn);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
228 return result;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
230 failed:
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
231 Py_XDECREF(result);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
232 Py_XDECREF(x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
233 return NULL;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
236 #if defined(HAVE_WCSCOLL)
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
237 PyDoc_STRVAR(strcoll__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
238 "string,string -> int. Compares two strings according to the locale.");
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
239
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
241 PyLocale_strcoll(PyObject* self, PyObject* args)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 {
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
243 PyObject *os1, *os2, *result = NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
244 wchar_t *ws1 = NULL, *ws2 = NULL;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
245
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
246 if (!PyArg_ParseTuple(args, "UU:strcoll", &os1, &os2))
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
247 return NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
248 /* Convert the unicode strings to wchar[]. */
65157
e3ae5b00ba15 PyUnicode_AsWideCharString() takes a PyObject*, not a PyUnicodeObject*
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65009
diff changeset
249 ws1 = PyUnicode_AsWideCharString(os1, NULL);
65009
ac8d9cac3033 Issue #9979: Use PyUnicode_AsWideCharString() for _locale.strcoll()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64271
diff changeset
250 if (ws1 == NULL)
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
251 goto done;
65157
e3ae5b00ba15 PyUnicode_AsWideCharString() takes a PyObject*, not a PyUnicodeObject*
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65009
diff changeset
252 ws2 = PyUnicode_AsWideCharString(os2, NULL);
65009
ac8d9cac3033 Issue #9979: Use PyUnicode_AsWideCharString() for _locale.strcoll()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64271
diff changeset
253 if (ws2 == NULL)
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
254 goto done;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
255 /* Collate the strings. */
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
256 result = PyLong_FromLong(wcscoll(ws1, ws2));
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
257 done:
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
258 /* Deallocate everything. */
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
259 if (ws1) PyMem_FREE(ws1);
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
260 if (ws2) PyMem_FREE(ws2);
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
261 return result;
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
262 }
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
263 #endif
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
264
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
265 #ifdef HAVE_WCSXFRM
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
266 PyDoc_STRVAR(strxfrm__doc__,
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48987
diff changeset
267 "strxfrm(string) -> string.\n\
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48987
diff changeset
268 \n\
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 48987
diff changeset
269 Return a string that can be used as a key for locale-aware comparisons.");
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
270
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
272 PyLocale_strxfrm(PyObject* self, PyObject* args)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 {
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
274 Py_UNICODE *s0;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
275 Py_ssize_t n0;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
276 wchar_t *s, *buf = NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
277 size_t n1, n2;
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
278 PyObject *result = NULL;
64271
867699c9b63f Issue 8781: On systems a signed 4-byte wchar_t and a 4-byte Py_UNICODE, use memcpy to convert between the two (as already done when wchar_t is unsigned)
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 62262
diff changeset
279 #if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
280 Py_ssize_t i;
56908
b6cc0134af31 Merged revisions 75877 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56637
diff changeset
281 #endif
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
282
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
283 if (!PyArg_ParseTuple(args, "u#:strxfrm", &s0, &n0))
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
284 return NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
285
64271
867699c9b63f Issue 8781: On systems a signed 4-byte wchar_t and a 4-byte Py_UNICODE, use memcpy to convert between the two (as already done when wchar_t is unsigned)
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 62262
diff changeset
286 #if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
867699c9b63f Issue 8781: On systems a signed 4-byte wchar_t and a 4-byte Py_UNICODE, use memcpy to convert between the two (as already done when wchar_t is unsigned)
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 62262
diff changeset
287 s = (wchar_t *) s0;
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
288 #else
45711
c27aabae06fd Properly size memory blocks in units of wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45710
diff changeset
289 s = PyMem_Malloc((n0+1)*sizeof(wchar_t));
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
290 if (!s)
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
291 return PyErr_NoMemory();
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
292 for (i=0; i<=n0; i++)
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
293 s[i] = s0[i];
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
294 #endif
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
295
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
296 /* assume no change in size, first */
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
297 n1 = wcslen(s) + 1;
45711
c27aabae06fd Properly size memory blocks in units of wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45710
diff changeset
298 buf = PyMem_Malloc(n1*sizeof(wchar_t));
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
299 if (!buf) {
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
300 PyErr_NoMemory();
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
301 goto exit;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
302 }
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
303 n2 = wcsxfrm(buf, s, n1);
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
304 if (n2 >= n1) {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
305 /* more space needed */
45711
c27aabae06fd Properly size memory blocks in units of wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 45710
diff changeset
306 buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
307 if (!buf) {
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
308 PyErr_NoMemory();
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
309 goto exit;
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
310 }
54266
435bca0781e3 Merged revisions 72844 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 51244
diff changeset
311 n2 = wcsxfrm(buf, s, n2+1);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
312 }
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
313 result = PyUnicode_FromWideChar(buf, n2);
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
314 exit:
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
315 if (buf) PyMem_Free(buf);
64271
867699c9b63f Issue 8781: On systems a signed 4-byte wchar_t and a 4-byte Py_UNICODE, use memcpy to convert between the two (as already done when wchar_t is unsigned)
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 62262
diff changeset
316 #if Py_UNICODE_SIZE != SIZEOF_WCHAR_T
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
317 PyMem_Free(s);
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
318 #endif
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
319 return result;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 }
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
321 #endif
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
322
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
323 #if defined(MS_WINDOWS)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
324 static PyObject*
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22330
diff changeset
325 PyLocale_getdefaultlocale(PyObject* self)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
326 {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
327 char encoding[100];
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
328 char locale[100];
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
329
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20008
diff changeset
330 PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
331
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
332 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
333 LOCALE_SISO639LANGNAME,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
334 locale, sizeof(locale))) {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
335 Py_ssize_t i = strlen(locale);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
336 locale[i++] = '_';
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
337 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
338 LOCALE_SISO3166CTRYNAME,
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
339 locale+i, (int)(sizeof(locale)-i)))
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
340 return Py_BuildValue("ss", locale, encoding);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
341 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
342
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
343 /* If we end up here, this windows version didn't know about
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
344 ISO639/ISO3166 names (it's probably Windows 95). Return the
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
345 Windows language identifier instead (a hexadecimal number) */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
346
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
347 locale[0] = '0';
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
348 locale[1] = 'x';
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
349 if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
350 locale+2, sizeof(locale)-2)) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
351 return Py_BuildValue("ss", locale, encoding);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
352 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
353
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
354 /* cannot determine the language code (very unlikely) */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
355 Py_INCREF(Py_None);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
356 return Py_BuildValue("Os", Py_None, encoding);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
357 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
358 #endif
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
359
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
360 #ifdef HAVE_LANGINFO_H
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
361 #define LANGINFO(X) {#X, X}
47680
b5e02775fffc Merged revisions 64226 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
362 static struct langinfo_constant{
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
363 char* name;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
364 int value;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
365 } langinfo_constants[] =
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
366 {
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
367 /* These constants should exist on any langinfo implementation */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
368 LANGINFO(DAY_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
369 LANGINFO(DAY_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
370 LANGINFO(DAY_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
371 LANGINFO(DAY_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
372 LANGINFO(DAY_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
373 LANGINFO(DAY_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
374 LANGINFO(DAY_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
375
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
376 LANGINFO(ABDAY_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
377 LANGINFO(ABDAY_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
378 LANGINFO(ABDAY_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
379 LANGINFO(ABDAY_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
380 LANGINFO(ABDAY_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
381 LANGINFO(ABDAY_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
382 LANGINFO(ABDAY_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
383
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
384 LANGINFO(MON_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
385 LANGINFO(MON_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
386 LANGINFO(MON_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
387 LANGINFO(MON_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
388 LANGINFO(MON_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
389 LANGINFO(MON_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
390 LANGINFO(MON_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
391 LANGINFO(MON_8),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
392 LANGINFO(MON_9),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
393 LANGINFO(MON_10),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
394 LANGINFO(MON_11),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
395 LANGINFO(MON_12),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
396
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
397 LANGINFO(ABMON_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
398 LANGINFO(ABMON_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
399 LANGINFO(ABMON_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
400 LANGINFO(ABMON_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
401 LANGINFO(ABMON_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
402 LANGINFO(ABMON_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
403 LANGINFO(ABMON_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
404 LANGINFO(ABMON_8),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
405 LANGINFO(ABMON_9),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
406 LANGINFO(ABMON_10),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
407 LANGINFO(ABMON_11),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
408 LANGINFO(ABMON_12),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
409
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
410 #ifdef RADIXCHAR
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
411 /* The following are not available with glibc 2.0 */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
412 LANGINFO(RADIXCHAR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
413 LANGINFO(THOUSEP),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
414 /* YESSTR and NOSTR are deprecated in glibc, since they are
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
415 a special case of message translation, which should be rather
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
416 done using gettext. So we don't expose it to Python in the
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
417 first place.
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
418 LANGINFO(YESSTR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
419 LANGINFO(NOSTR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
420 */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
421 LANGINFO(CRNCYSTR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
422 #endif
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
423
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
424 LANGINFO(D_T_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
425 LANGINFO(D_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
426 LANGINFO(T_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
427 LANGINFO(AM_STR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
428 LANGINFO(PM_STR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
429
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
430 /* The following constants are available only with XPG4, but...
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
431 AIX 3.2. only has CODESET.
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
432 OpenBSD doesn't have CODESET but has T_FMT_AMPM, and doesn't have
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
433 a few of the others.
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
434 Solution: ifdef-test them all. */
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
435 #ifdef CODESET
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
436 LANGINFO(CODESET),
22603
2868e9a9e280 Don't imply XPG4 constants from CODESET presence. Fixes #534153.
Martin v. Löwis <martin@v.loewis.de>
parents: 22561
diff changeset
437 #endif
2868e9a9e280 Don't imply XPG4 constants from CODESET presence. Fixes #534153.
Martin v. Löwis <martin@v.loewis.de>
parents: 22561
diff changeset
438 #ifdef T_FMT_AMPM
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
439 LANGINFO(T_FMT_AMPM),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
440 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
441 #ifdef ERA
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
442 LANGINFO(ERA),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
443 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
444 #ifdef ERA_D_FMT
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
445 LANGINFO(ERA_D_FMT),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
446 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
447 #ifdef ERA_D_T_FMT
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
448 LANGINFO(ERA_D_T_FMT),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
449 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
450 #ifdef ERA_T_FMT
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
451 LANGINFO(ERA_T_FMT),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
452 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
453 #ifdef ALT_DIGITS
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
454 LANGINFO(ALT_DIGITS),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
455 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
456 #ifdef YESEXPR
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
457 LANGINFO(YESEXPR),
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
458 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
459 #ifdef NOEXPR
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
460 LANGINFO(NOEXPR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
461 #endif
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
462 #ifdef _DATE_FMT
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
463 /* This is not available in all glibc versions that have CODESET. */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
464 LANGINFO(_DATE_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
465 #endif
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
466 {0, 0}
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
467 };
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
468
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
469 PyDoc_STRVAR(nl_langinfo__doc__,
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
470 "nl_langinfo(key) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
471 "Return the value for the locale information associated with key.");
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
472
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
473 static PyObject*
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
474 PyLocale_nl_langinfo(PyObject* self, PyObject* args)
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
475 {
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
476 int item, i;
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
477 if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
478 return NULL;
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
479 /* Check whether this is a supported constant. GNU libc sometimes
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
480 returns numeric values in the char* return value, which would
42864
1b1f7ca3fd49 Use unicode
Neal Norwitz <nnorwitz@gmail.com>
parents: 42735
diff changeset
481 crash PyUnicode_FromString. */
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
482 for (i = 0; langinfo_constants[i].name; i++)
31746
671adee6a3e3 Bug #920575: Add a workaround for GNU libc nl_langinfo()'s returning NULL.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30982
diff changeset
483 if (langinfo_constants[i].value == item) {
671adee6a3e3 Bug #920575: Add a workaround for GNU libc nl_langinfo()'s returning NULL.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30982
diff changeset
484 /* Check NULL as a workaround for GNU libc's returning NULL
671adee6a3e3 Bug #920575: Add a workaround for GNU libc nl_langinfo()'s returning NULL.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30982
diff changeset
485 instead of an empty string for nl_langinfo(ERA). */
671adee6a3e3 Bug #920575: Add a workaround for GNU libc nl_langinfo()'s returning NULL.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30982
diff changeset
486 const char *result = nl_langinfo(item);
43698
d46a31f5c5df Get the locale and pwd tests working on the Solaris box where there
Neal Norwitz <nnorwitz@gmail.com>
parents: 42864
diff changeset
487 result = result != NULL ? result : "";
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
488 return str2uni(result);
31746
671adee6a3e3 Bug #920575: Add a workaround for GNU libc nl_langinfo()'s returning NULL.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30982
diff changeset
489 }
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
490 PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
491 return NULL;
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
492 }
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
493 #endif /* HAVE_LANGINFO_H */
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
494
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
495 #ifdef HAVE_LIBINTL_H
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
496
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
497 PyDoc_STRVAR(gettext__doc__,
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
498 "gettext(msg) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
499 "Return translation of msg.");
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
500
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
501 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
502 PyIntl_gettext(PyObject* self, PyObject *args)
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
503 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
504 char *in;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
505 if (!PyArg_ParseTuple(args, "s", &in))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
506 return 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
507 return str2uni(gettext(in));
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
508 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
509
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
510 PyDoc_STRVAR(dgettext__doc__,
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
511 "dgettext(domain, msg) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
512 "Return translation of msg in domain.");
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
513
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
514 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
515 PyIntl_dgettext(PyObject* self, PyObject *args)
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
516 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
517 char *domain, *in;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
518 if (!PyArg_ParseTuple(args, "zs", &domain, &in))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
519 return 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
520 return str2uni(dgettext(domain, in));
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
521 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
522
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
523 PyDoc_STRVAR(dcgettext__doc__,
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
524 "dcgettext(domain, msg, category) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
525 "Return translation of msg in domain and category.");
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
526
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
527 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
528 PyIntl_dcgettext(PyObject *self, PyObject *args)
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
529 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
530 char *domain, *msgid;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
531 int category;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
532 if (!PyArg_ParseTuple(args, "zsi", &domain, &msgid, &category))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
533 return 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
534 return str2uni(dcgettext(domain,msgid,category));
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
535 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
536
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
537 PyDoc_STRVAR(textdomain__doc__,
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
538 "textdomain(domain) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
539 "Set the C library's textdmain to domain, returning the new domain.");
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
540
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
541 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
542 PyIntl_textdomain(PyObject* self, PyObject* args)
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
543 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
544 char *domain;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
545 if (!PyArg_ParseTuple(args, "z", &domain))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
546 return 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
547 domain = textdomain(domain);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
548 if (!domain) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
549 PyErr_SetFromErrno(PyExc_OSError);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
550 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
551 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
552 return str2uni(domain);
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
553 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
554
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
555 PyDoc_STRVAR(bindtextdomain__doc__,
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
556 "bindtextdomain(domain, dir) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
557 "Bind the C library's domain to dir.");
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
558
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
559 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
560 PyIntl_bindtextdomain(PyObject* self,PyObject*args)
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
561 {
62262
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
562 char *domain, *dirname, *current_dirname;
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
563 PyObject *dirname_obj, *dirname_bytes = NULL, *result;
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
564 if (!PyArg_ParseTuple(args, "sO", &domain, &dirname_obj))
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
565 return 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
566 if (!strlen(domain)) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
567 PyErr_SetString(Error, "domain must be a non-empty string");
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
568 return 0;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
569 }
62262
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
570 if (dirname_obj != Py_None) {
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
571 if (!PyUnicode_FSConverter(dirname_obj, &dirname_bytes))
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
572 return NULL;
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
573 dirname = PyBytes_AsString(dirname_bytes);
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
574 } else {
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
575 dirname_bytes = NULL;
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
576 dirname = NULL;
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
577 }
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
578 current_dirname = bindtextdomain(domain, dirname);
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
579 if (current_dirname == NULL) {
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
580 Py_XDECREF(dirname_bytes);
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
581 PyErr_SetFromErrno(PyExc_OSError);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
582 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
583 }
62262
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
584 result = str2uni(current_dirname);
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
585 Py_XDECREF(dirname_bytes);
bd8a1fd4c316 locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61466
diff changeset
586 return result;
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
587 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
588
32794
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
589 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
590 PyDoc_STRVAR(bind_textdomain_codeset__doc__,
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
591 "bind_textdomain_codeset(domain, codeset) -> string\n"
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
592 "Bind the C library's domain to codeset.");
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
593
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
594 static PyObject*
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
595 PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
596 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
597 char *domain,*codeset;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
598 if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
599 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
600 codeset = bind_textdomain_codeset(domain, codeset);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
601 if (codeset)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
602 return str2uni(codeset);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
603 Py_RETURN_NONE;
32794
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
604 }
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
605 #endif
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
606
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
607 #endif
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
608
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 static struct PyMethodDef PyLocale_Methods[] = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
610 {"setlocale", (PyCFunction) PyLocale_setlocale,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
611 METH_VARARGS, setlocale__doc__},
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
612 {"localeconv", (PyCFunction) PyLocale_localeconv,
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22330
diff changeset
613 METH_NOARGS, localeconv__doc__},
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
614 #ifdef HAVE_WCSCOLL
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
615 {"strcoll", (PyCFunction) PyLocale_strcoll,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
616 METH_VARARGS, strcoll__doc__},
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
617 #endif
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
618 #ifdef HAVE_WCSXFRM
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
619 {"strxfrm", (PyCFunction) PyLocale_strxfrm,
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
620 METH_VARARGS, strxfrm__doc__},
45710
45050d376d57 Use wchar_t functions in _locale module.
Martin v. Löwis <martin@v.loewis.de>
parents: 44099
diff changeset
621 #endif
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
622 #if defined(MS_WINDOWS)
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22330
diff changeset
623 {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
624 #endif
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
625 #ifdef HAVE_LANGINFO_H
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
626 {"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
627 METH_VARARGS, nl_langinfo__doc__},
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
628 #endif
23343
03b1e989b1d9 Guard gettext and friends with HAVE_LIBINTL_H. Fixes #549907.
Martin v. Löwis <martin@v.loewis.de>
parents: 23177
diff changeset
629 #ifdef HAVE_LIBINTL_H
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
630 {"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
631 gettext__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
632 {"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
633 dgettext__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
634 {"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
635 dcgettext__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
636 {"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
637 textdomain__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
638 {"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
639 bindtextdomain__doc__},
32794
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
640 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
641 {"bind_textdomain_codeset",(PyCFunction)PyIntl_bind_textdomain_codeset,
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
642 METH_VARARGS, bind_textdomain_codeset__doc__},
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
643 #endif
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
644 #endif
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 {NULL, NULL}
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 };
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
647
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
648
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
649 static struct PyModuleDef _localemodule = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
650 PyModuleDef_HEAD_INIT,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
651 "_locale",
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
652 locale__doc__,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
653 -1,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
654 PyLocale_Methods,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
655 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
656 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
657 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
658 NULL
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
659 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
660
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24233
diff changeset
661 PyMODINIT_FUNC
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
662 PyInit__locale(void)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
663 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
664 PyObject *m, *d, *x;
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
665 #ifdef HAVE_LANGINFO_H
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
666 int i;
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
667 #endif
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
668
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
669 m = PyModule_Create(&_localemodule);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 34640
diff changeset
670 if (m == NULL)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
671 return NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
672
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
673 d = PyModule_GetDict(m);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
674
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
675 x = PyLong_FromLong(LC_CTYPE);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
676 PyDict_SetItemString(d, "LC_CTYPE", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
677 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
678
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
679 x = PyLong_FromLong(LC_TIME);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
680 PyDict_SetItemString(d, "LC_TIME", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
681 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
682
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
683 x = PyLong_FromLong(LC_COLLATE);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
684 PyDict_SetItemString(d, "LC_COLLATE", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
685 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
686
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
687 x = PyLong_FromLong(LC_MONETARY);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
688 PyDict_SetItemString(d, "LC_MONETARY", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
689 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
690
6797
954417191fbf LC_MESSAGES is not defined on all systems; use #ifdef LC_MESSAGES.
Guido van Rossum <guido@python.org>
parents: 6596
diff changeset
691 #ifdef LC_MESSAGES
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
692 x = PyLong_FromLong(LC_MESSAGES);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
693 PyDict_SetItemString(d, "LC_MESSAGES", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
694 Py_XDECREF(x);
6797
954417191fbf LC_MESSAGES is not defined on all systems; use #ifdef LC_MESSAGES.
Guido van Rossum <guido@python.org>
parents: 6596
diff changeset
695 #endif /* LC_MESSAGES */
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
696
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
697 x = PyLong_FromLong(LC_NUMERIC);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
698 PyDict_SetItemString(d, "LC_NUMERIC", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
699 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
700
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
701 x = PyLong_FromLong(LC_ALL);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
702 PyDict_SetItemString(d, "LC_ALL", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
703 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
704
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43698
diff changeset
705 x = PyLong_FromLong(CHAR_MAX);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
706 PyDict_SetItemString(d, "CHAR_MAX", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
707 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
708
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
709 Error = PyErr_NewException("locale.Error", NULL, NULL);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
710 PyDict_SetItemString(d, "Error", Error);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
711
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
712 #ifdef HAVE_LANGINFO_H
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
713 for (i = 0; langinfo_constants[i].name; i++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
714 PyModule_AddIntConstant(m, langinfo_constants[i].name,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
715 langinfo_constants[i].value);
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
716 }
19278
1afc3116c602 Fix portability problems with glibc 2.0, as reported in #449157.
Martin v. Löwis <martin@v.loewis.de>
parents: 19143
diff changeset
717 #endif
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45715
diff changeset
718 return m;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
719 }
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
720
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57531
diff changeset
721 /*
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
722 Local variables:
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
723 c-basic-offset: 4
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
724 indent-tabs-mode: nil
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
725 End:
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
726 */