annotate Modules/_localemodule.c @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents e907da825169
children e38335d4df91 783d4044dc2d
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 /***********************************************************
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
2 Copyright (C) 1997, 2002, 2003 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
13914
693b61581746 Clean up compiler warning exposed by GCC's -Wall option: make sure
Fred Drake <fdrake@acm.org>
parents: 13817
diff changeset
12 #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
13
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 #include <stdio.h>
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #include <locale.h>
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 #include <string.h>
8524
47bf3bb9556e Added <ctype.h>, needed for Windows.
Guido van Rossum <guido@python.org>
parents: 8182
diff changeset
17 #include <ctype.h>
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
18
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
19 #ifdef HAVE_ERRNO_H
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
20 #include <errno.h>
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
21 #endif
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
22
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
23 #ifdef HAVE_LANGINFO_H
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
24 #include <langinfo.h>
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
25 #endif
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
26
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
27 #ifdef HAVE_LIBINTL_H
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
28 #include <libintl.h>
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
29 #endif
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
30
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
31 #ifdef HAVE_WCHAR_H
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
32 #include <wchar.h>
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
33 #endif
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
34
30982
e543b3f0d906 Got rid of macglue.h, replacing it by pymactoolbox.h where relevant.
Jack Jansen <jack.jansen@cwi.nl>
parents: 30978
diff changeset
35 #if defined(__APPLE__)
32689
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
36 #include <CoreFoundation/CoreFoundation.h>
30982
e543b3f0d906 Got rid of macglue.h, replacing it by pymactoolbox.h where relevant.
Jack Jansen <jack.jansen@cwi.nl>
parents: 30978
diff changeset
37 #endif
e543b3f0d906 Got rid of macglue.h, replacing it by pymactoolbox.h where relevant.
Jack Jansen <jack.jansen@cwi.nl>
parents: 30978
diff changeset
38
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
39 #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
40 #define WIN32_LEAN_AND_MEAN
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
41 #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
42 #endif
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
16946
31e302e94da8 RISCOS changes by dschwertberger
Guido van Rossum <guido@python.org>
parents: 14869
diff changeset
44 #ifdef RISCOS
31e302e94da8 RISCOS changes by dschwertberger
Guido van Rossum <guido@python.org>
parents: 14869
diff changeset
45 char *strdup(const char *);
31e302e94da8 RISCOS changes by dschwertberger
Guido van Rossum <guido@python.org>
parents: 14869
diff changeset
46 #endif
31e302e94da8 RISCOS changes by dschwertberger
Guido van Rossum <guido@python.org>
parents: 14869
diff changeset
47
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
48 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
49
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 static PyObject *Error;
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 /* 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
53
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
54 PyDoc_STRVAR(setlocale__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
55 "(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
56
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 /* 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
58 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
59 copy_grouping(char* s)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
61 int i;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
62 PyObject *result, *val = NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
63
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
64 if (s[0] == '\0')
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
65 /* empty string: no grouping at all */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
66 return PyList_New(0);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
67
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
68 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
69 ; /* nothing */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
70
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
71 result = PyList_New(i+1);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
72 if (!result)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
73 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
74
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
75 i = -1;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
76 do {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
77 i++;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
78 val = PyInt_FromLong(s[i]);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
79 if (!val)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
80 break;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
81 if (PyList_SetItem(result, i, val)) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
82 Py_DECREF(val);
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
83 val = NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
84 break;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
85 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
86 } while (s[i] != '\0' && s[i] != CHAR_MAX);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
87
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
88 if (!val) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
89 Py_DECREF(result);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
90 return NULL;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 }
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
92
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
93 return result;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 static void
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
97 fixup_ulcase(void)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
99 PyObject *mods, *strop, *string, *ulo;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
100 unsigned char ul[256];
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
101 int n, c;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
102
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
103 /* find the string and strop modules */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
104 mods = PyImport_GetModuleDict();
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
105 if (!mods)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
106 return;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
107 string = PyDict_GetItemString(mods, "string");
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
108 if (string)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
109 string = PyModule_GetDict(string);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
110 strop=PyDict_GetItemString(mods, "strop");
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
111 if (strop)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
112 strop = PyModule_GetDict(strop);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
113 if (!string && !strop)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
114 return;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
116 /* create uppercase map string */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
117 n = 0;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
118 for (c = 0; c < 256; c++) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
119 if (isupper(c))
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
120 ul[n++] = c;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
121 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
122 ulo = PyString_FromStringAndSize((const char *)ul, n);
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
123 if (!ulo)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
124 return;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
125 if (string)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
126 PyDict_SetItemString(string, "uppercase", ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
127 if (strop)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
128 PyDict_SetItemString(strop, "uppercase", ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
129 Py_DECREF(ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
130
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
131 /* create lowercase string */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
132 n = 0;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
133 for (c = 0; c < 256; c++) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
134 if (islower(c))
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
135 ul[n++] = c;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
136 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
137 ulo = PyString_FromStringAndSize((const char *)ul, n);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
138 if (!ulo)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
139 return;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
140 if (string)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
141 PyDict_SetItemString(string, "lowercase", ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
142 if (strop)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
143 PyDict_SetItemString(strop, "lowercase", ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
144 Py_DECREF(ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
145
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
146 /* create letters string */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
147 n = 0;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
148 for (c = 0; c < 256; c++) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
149 if (isalpha(c))
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
150 ul[n++] = c;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
151 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
152 ulo = PyString_FromStringAndSize((const char *)ul, n);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
153 if (!ulo)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
154 return;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
155 if (string)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
156 PyDict_SetItemString(string, "letters", ulo);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
157 Py_DECREF(ulo);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 }
19735
f56c91820fae Patch #449815: Set filesystemencoding based on CODESET.
Martin v. Löwis <martin@v.loewis.de>
parents: 19278
diff changeset
159
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
161 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
162 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
163 int category;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
164 char *locale = NULL, *result;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
165 PyObject *result_object;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
166
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
167 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
168 return NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
169
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
170 if (locale) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
171 /* set locale */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
172 result = setlocale(category, locale);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
173 if (!result) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
174 /* 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
175 PyErr_SetString(Error, "unsupported locale setting");
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
176 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
177 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
178 result_object = PyString_FromString(result);
29992
35ccfc140cac Fix [ 776721 ] locale.setlocale() leaks
Mark Hammond <mhammond@skippinet.com.au>
parents: 28174
diff changeset
179 if (!result_object)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
180 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
181 /* record changes to LC_CTYPE */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
182 if (category == LC_CTYPE || category == LC_ALL)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
183 fixup_ulcase();
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
184 /* things that got wrong up to here are ignored */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
185 PyErr_Clear();
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
186 } else {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
187 /* get locale */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
188 result = setlocale(category, NULL);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
189 if (!result) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
190 PyErr_SetString(Error, "locale query failed");
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
191 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
192 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
193 result_object = PyString_FromString(result);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 }
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
195 return result_object;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
198 PyDoc_STRVAR(localeconv__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
199 "() -> 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
200
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 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
202 PyLocale_localeconv(PyObject* self)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
204 PyObject* result;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
205 struct lconv *l;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
206 PyObject *x;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
207
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
208 result = PyDict_New();
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
209 if (!result)
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
210 return NULL;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
211
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
212 /* 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
213 l = localeconv();
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
214
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
215 /* hopefully, the localeconv result survives the C library calls
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
216 involved herein */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
217
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
218 #define RESULT_STRING(s)\
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
219 x = PyString_FromString(l->s);\
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
220 if (!x) goto failed;\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
221 PyDict_SetItemString(result, #s, x);\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
222 Py_XDECREF(x)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
223
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
224 #define RESULT_INT(i)\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
225 x = PyInt_FromLong(l->i);\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
226 if (!x) goto failed;\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
227 PyDict_SetItemString(result, #i, x);\
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
228 Py_XDECREF(x)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 /* Numeric information */
32305
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
231 RESULT_STRING(decimal_point);
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
232 RESULT_STRING(thousands_sep);
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
233 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
234 if (!x)
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
235 goto failed;
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31746
diff changeset
236 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
237 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
238
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
239 /* Monetary information */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
240 RESULT_STRING(int_curr_symbol);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
241 RESULT_STRING(currency_symbol);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
242 RESULT_STRING(mon_decimal_point);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
243 RESULT_STRING(mon_thousands_sep);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
244 x = copy_grouping(l->mon_grouping);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
245 if (!x)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
246 goto failed;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
247 PyDict_SetItemString(result, "mon_grouping", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
248 Py_XDECREF(x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
249 RESULT_STRING(positive_sign);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
250 RESULT_STRING(negative_sign);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
251 RESULT_INT(int_frac_digits);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
252 RESULT_INT(frac_digits);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
253 RESULT_INT(p_cs_precedes);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
254 RESULT_INT(p_sep_by_space);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
255 RESULT_INT(n_cs_precedes);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
256 RESULT_INT(n_sep_by_space);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
257 RESULT_INT(p_sign_posn);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
258 RESULT_INT(n_sign_posn);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
259 return result;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
260
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
261 failed:
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
262 Py_XDECREF(result);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
263 Py_XDECREF(x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
264 return NULL;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
267 PyDoc_STRVAR(strcoll__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
268 "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
269
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
271 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
272 {
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
273 #if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
274 char *s1,*s2;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
275
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
276 if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
277 return NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
278 return PyInt_FromLong(strcoll(s1, s2));
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
279 #else
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
280 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
281 wchar_t *ws1 = NULL, *ws2 = NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
282 int rel1 = 0, rel2 = 0, len1, len2;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
283
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38232
diff changeset
284 if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
285 return NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
286 /* If both arguments are byte strings, use strcoll. */
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
287 if (PyString_Check(os1) && PyString_Check(os2))
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
288 return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
289 PyString_AS_STRING(os2)));
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
290 /* If neither argument is unicode, it's an error. */
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
291 if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
292 PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
293 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
294 /* Convert the non-unicode argument to unicode. */
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
295 if (!PyUnicode_Check(os1)) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
296 os1 = PyUnicode_FromObject(os1);
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
297 if (!os1)
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
298 return NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
299 rel1 = 1;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
300 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
301 if (!PyUnicode_Check(os2)) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
302 os2 = PyUnicode_FromObject(os2);
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
303 if (!os2) {
48026
e907da825169 #3303: fix crash with invalid Py_DECREF in strcoll().
Georg Brandl <georg@python.org>
parents: 48025
diff changeset
304 if (rel1) {
e907da825169 #3303: fix crash with invalid Py_DECREF in strcoll().
Georg Brandl <georg@python.org>
parents: 48025
diff changeset
305 Py_DECREF(os1);
e907da825169 #3303: fix crash with invalid Py_DECREF in strcoll().
Georg Brandl <georg@python.org>
parents: 48025
diff changeset
306 }
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
307 return NULL;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
308 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
309 rel2 = 1;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
310 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
311 /* Convert the unicode strings to wchar[]. */
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
312 len1 = PyUnicode_GET_SIZE(os1) + 1;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
313 ws1 = PyMem_MALLOC(len1 * sizeof(wchar_t));
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
314 if (!ws1) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
315 PyErr_NoMemory();
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
316 goto done;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
317 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
318 if (PyUnicode_AsWideChar((PyUnicodeObject*)os1, ws1, len1) == -1)
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
319 goto done;
34016
264e45baacd5 Correct the handling of 0-termination of PyUnicode_AsWideChar()
Marc-André Lemburg <mal@egenix.com>
parents: 33303
diff changeset
320 ws1[len1 - 1] = 0;
264e45baacd5 Correct the handling of 0-termination of PyUnicode_AsWideChar()
Marc-André Lemburg <mal@egenix.com>
parents: 33303
diff changeset
321 len2 = PyUnicode_GET_SIZE(os2) + 1;
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
322 ws2 = PyMem_MALLOC(len2 * sizeof(wchar_t));
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
323 if (!ws2) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
324 PyErr_NoMemory();
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
325 goto done;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
326 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
327 if (PyUnicode_AsWideChar((PyUnicodeObject*)os2, ws2, len2) == -1)
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
328 goto done;
34016
264e45baacd5 Correct the handling of 0-termination of PyUnicode_AsWideChar()
Marc-André Lemburg <mal@egenix.com>
parents: 33303
diff changeset
329 ws2[len2 - 1] = 0;
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
330 /* Collate the strings. */
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
331 result = PyInt_FromLong(wcscoll(ws1, ws2));
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
332 done:
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
333 /* Deallocate everything. */
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
334 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
335 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
336 if (rel1) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
337 Py_DECREF(os1);
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
338 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
339 if (rel2) {
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
340 Py_DECREF(os2);
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
341 }
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
342 return result;
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
343 #endif
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
344 }
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
345
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
347 PyDoc_STRVAR(strxfrm__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
348 "string -> string. Returns a string that behaves for cmp locale-aware.");
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
349
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 static PyObject*
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
351 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
352 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
353 char *s, *buf;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
354 size_t n1, n2;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
355 PyObject *result;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
356
13439
968a006e5480 - _getdefaultlocale shouldn't accept arguments
Fredrik Lundh <fredrik@pythonware.com>
parents: 13438
diff changeset
357 if (!PyArg_ParseTuple(args, "s:strxfrm", &s))
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
358 return NULL;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
359
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
360 /* assume no change in size, first */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
361 n1 = strlen(s) + 1;
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
362 buf = PyMem_Malloc(n1);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
363 if (!buf)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
364 return PyErr_NoMemory();
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 38716
diff changeset
365 n2 = strxfrm(buf, s, n1) + 1;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
366 if (n2 > n1) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
367 /* more space needed */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
368 buf = PyMem_Realloc(buf, n2);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
369 if (!buf)
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
370 return PyErr_NoMemory();
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
371 strxfrm(buf, s, n2);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
372 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
373 result = PyString_FromString(buf);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
374 PyMem_Free(buf);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
375 return result;
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 }
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
377
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
378 #if defined(MS_WINDOWS)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
379 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
380 PyLocale_getdefaultlocale(PyObject* self)
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
381 {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
382 char encoding[100];
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
383 char locale[100];
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
384
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20008
diff changeset
385 PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
386
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
387 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
388 LOCALE_SISO639LANGNAME,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
389 locale, sizeof(locale))) {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
390 Py_ssize_t i = strlen(locale);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
391 locale[i++] = '_';
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
392 if (GetLocaleInfo(LOCALE_USER_DEFAULT,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
393 LOCALE_SISO3166CTRYNAME,
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
394 locale+i, (int)(sizeof(locale)-i)))
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
395 return Py_BuildValue("ss", locale, encoding);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
396 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
397
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
398 /* 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
399 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
400 Windows language identifier instead (a hexadecimal number) */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
401
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
402 locale[0] = '0';
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
403 locale[1] = 'x';
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
404 if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
405 locale+2, sizeof(locale)-2)) {
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
406 return Py_BuildValue("ss", locale, encoding);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
407 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
408
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
409 /* cannot determine the language code (very unlikely) */
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
410 Py_INCREF(Py_None);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
411 return Py_BuildValue("Os", Py_None, encoding);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
412 }
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
413 #endif
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
414
26415
d58824ceb35d Patch #632973: Implement _getdefaultlocale for OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
415 #if defined(__APPLE__)
32689
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
416 /*
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
417 ** Find out what the current script is.
33303
521b8795df9b Fix the spelling of Fredrik Lundh's last name (unless there really is a
Brett Cannon <bcannon@gmail.com>
parents: 32794
diff changeset
418 ** Donated by Fredrik Lundh.
32689
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
419 */
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
420 static char *mac_getscript(void)
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
421 {
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
422 CFStringEncoding enc = CFStringGetSystemEncoding();
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
423 static CFStringRef name = NULL;
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
424 /* Return the code name for the encodings for which we have codecs. */
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
425 switch(enc) {
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
426 case kCFStringEncodingMacRoman: return "mac-roman";
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
427 case kCFStringEncodingMacGreek: return "mac-greek";
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
428 case kCFStringEncodingMacCyrillic: return "mac-cyrillic";
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
429 case kCFStringEncodingMacTurkish: return "mac-turkish";
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
430 case kCFStringEncodingMacIcelandic: return "mac-icelandic";
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
431 /* XXX which one is mac-latin2? */
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
432 }
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
433 if (!name) {
34640
636d6d433b62 Fix grammatical typo in a comment.
Brett Cannon <bcannon@gmail.com>
parents: 34016
diff changeset
434 /* This leaks an object. */
32689
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
435 name = CFStringConvertEncodingToIANACharSetName(enc);
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
436 }
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
437 return (char *)CFStringGetCStringPtr(name, 0);
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
438 }
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
439
13618
086947cd202c Implemented getdefaultlocale() for macintosh, after an idea by Fredrik.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13439
diff changeset
440 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
441 PyLocale_getdefaultlocale(PyObject* self)
13618
086947cd202c Implemented getdefaultlocale() for macintosh, after an idea by Fredrik.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13439
diff changeset
442 {
32689
577a9e4c82fb Moved PyMac_GetScript() to _localemodule, which is the only place where
Jack Jansen <jack.jansen@cwi.nl>
parents: 32305
diff changeset
443 return Py_BuildValue("Os", Py_None, mac_getscript());
13618
086947cd202c Implemented getdefaultlocale() for macintosh, after an idea by Fredrik.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13439
diff changeset
444 }
086947cd202c Implemented getdefaultlocale() for macintosh, after an idea by Fredrik.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13439
diff changeset
445 #endif
086947cd202c Implemented getdefaultlocale() for macintosh, after an idea by Fredrik.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13439
diff changeset
446
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
447 #ifdef HAVE_LANGINFO_H
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
448 #define LANGINFO(X) {#X, X}
47678
a35da94e05fc Make more symbols static.
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
449 static struct langinfo_constant{
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
450 char* name;
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
451 int value;
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
452 } langinfo_constants[] =
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
453 {
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
454 /* These constants should exist on any langinfo implementation */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
455 LANGINFO(DAY_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
456 LANGINFO(DAY_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
457 LANGINFO(DAY_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
458 LANGINFO(DAY_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
459 LANGINFO(DAY_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
460 LANGINFO(DAY_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
461 LANGINFO(DAY_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
462
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
463 LANGINFO(ABDAY_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
464 LANGINFO(ABDAY_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
465 LANGINFO(ABDAY_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
466 LANGINFO(ABDAY_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
467 LANGINFO(ABDAY_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
468 LANGINFO(ABDAY_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
469 LANGINFO(ABDAY_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
470
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
471 LANGINFO(MON_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
472 LANGINFO(MON_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
473 LANGINFO(MON_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
474 LANGINFO(MON_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
475 LANGINFO(MON_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
476 LANGINFO(MON_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
477 LANGINFO(MON_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
478 LANGINFO(MON_8),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
479 LANGINFO(MON_9),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
480 LANGINFO(MON_10),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
481 LANGINFO(MON_11),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
482 LANGINFO(MON_12),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
483
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
484 LANGINFO(ABMON_1),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
485 LANGINFO(ABMON_2),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
486 LANGINFO(ABMON_3),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
487 LANGINFO(ABMON_4),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
488 LANGINFO(ABMON_5),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
489 LANGINFO(ABMON_6),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
490 LANGINFO(ABMON_7),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
491 LANGINFO(ABMON_8),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
492 LANGINFO(ABMON_9),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
493 LANGINFO(ABMON_10),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
494 LANGINFO(ABMON_11),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
495 LANGINFO(ABMON_12),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
496
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
497 #ifdef RADIXCHAR
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
498 /* The following are not available with glibc 2.0 */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
499 LANGINFO(RADIXCHAR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
500 LANGINFO(THOUSEP),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
501 /* 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
502 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
503 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
504 first place.
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
505 LANGINFO(YESSTR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
506 LANGINFO(NOSTR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
507 */
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
508 LANGINFO(CRNCYSTR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
509 #endif
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
510
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
511 LANGINFO(D_T_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
512 LANGINFO(D_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
513 LANGINFO(T_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
514 LANGINFO(AM_STR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
515 LANGINFO(PM_STR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
516
23177
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
517 /* 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
518 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
519 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
520 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
521 Solution: ifdef-test them all. */
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
522 #ifdef CODESET
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
523 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
524 #endif
2868e9a9e280 Don't imply XPG4 constants from CODESET presence. Fixes #534153.
Martin v. Löwis <martin@v.loewis.de>
parents: 22561
diff changeset
525 #ifdef T_FMT_AMPM
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
526 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
527 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
528 #ifdef ERA
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
529 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
530 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
531 #ifdef ERA_D_FMT
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
532 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
533 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
534 #ifdef ERA_D_T_FMT
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
535 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
536 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
537 #ifdef ERA_T_FMT
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
538 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
539 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
540 #ifdef ALT_DIGITS
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
541 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
542 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
543 #ifdef YESEXPR
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
544 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
545 #endif
ef73ff7a989e Patch #546194: Check constants individually. Fixes 534143 on OpenBSD.
Martin v. Löwis <martin@v.loewis.de>
parents: 22611
diff changeset
546 #ifdef NOEXPR
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
547 LANGINFO(NOEXPR),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
548 #endif
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
549 #ifdef _DATE_FMT
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
550 /* 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
551 LANGINFO(_DATE_FMT),
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
552 #endif
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
553 {0, 0}
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
554 };
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
555
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
556 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
557 "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
558 "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
559
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
560 static PyObject*
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
561 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
562 {
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
563 int item, i;
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
564 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
565 return NULL;
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
566 /* 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
567 returns numeric values in the char* return value, which would
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
568 crash PyString_FromString. */
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
569 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
570 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
571 /* 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
572 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
573 const char *result = nl_langinfo(item);
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
574 return PyString_FromString(result != NULL ? 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
575 }
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
576 PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
577 return NULL;
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
578 }
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
579 #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
580
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
581 #ifdef HAVE_LIBINTL_H
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
582
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
583 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
584 "gettext(msg) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
585 "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
586
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
587 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
588 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
589 {
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
590 char *in;
48025
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
591 if (!PyArg_ParseTuple(args, "s", &in))
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
592 return 0;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
593 return PyString_FromString(gettext(in));
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
594 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
595
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
596 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
597 "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
598 "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
599
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
600 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
601 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
602 {
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
603 char *domain, *in;
48025
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
604 if (!PyArg_ParseTuple(args, "zs", &domain, &in))
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
605 return 0;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
606 return PyString_FromString(dgettext(domain, in));
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
607 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
608
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
609 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
610 "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
611 "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
612
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
613 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
614 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
615 {
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
616 char *domain, *msgid;
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
617 int category;
48025
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
618 if (!PyArg_ParseTuple(args, "zsi", &domain, &msgid, &category))
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
619 return 0;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
620 return PyString_FromString(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
621 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
622
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
623 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
624 "textdomain(domain) -> string\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
625 "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
626
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
627 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
628 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
629 {
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
630 char *domain;
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
631 if (!PyArg_ParseTuple(args, "z", &domain))
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
632 return 0;
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
633 domain = textdomain(domain);
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
634 if (!domain) {
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
635 PyErr_SetFromErrno(PyExc_OSError);
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
636 return NULL;
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
637 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
638 return PyString_FromString(domain);
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
639 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
640
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23343
diff changeset
641 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
642 "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
643 "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
644
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
645 static PyObject*
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
646 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
647 {
48025
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
648 char *domain, *dirname;
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
649 if (!PyArg_ParseTuple(args, "sz", &domain, &dirname))
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
650 return 0;
48025
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
651 if (!strlen(domain)) {
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
652 PyErr_SetString(Error, "domain must be a non-empty string");
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
653 return 0;
33c6af69ae0f #3302: fix segfaults when passing None for arguments that can't
Georg Brandl <georg@python.org>
parents: 47678
diff changeset
654 }
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
655 dirname = bindtextdomain(domain, dirname);
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
656 if (!dirname) {
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
657 PyErr_SetFromErrno(PyExc_OSError);
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
658 return NULL;
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
659 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
660 return PyString_FromString(dirname);
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
661 }
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
662
32794
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
663 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
664 PyDoc_STRVAR(bind_textdomain_codeset__doc__,
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
665 "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
666 "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
667
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
668 static PyObject*
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
669 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
670 {
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
671 char *domain,*codeset;
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
672 if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
673 return NULL;
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
674 codeset = bind_textdomain_codeset(domain, codeset);
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
675 if (codeset)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
676 return PyString_FromString(codeset);
32794
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
677 Py_RETURN_NONE;
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
678 }
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
679 #endif
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
680
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
681 #endif
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
682
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
683 static struct PyMethodDef PyLocale_Methods[] = {
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
684 {"setlocale", (PyCFunction) PyLocale_setlocale,
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
685 METH_VARARGS, setlocale__doc__},
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
686 {"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
687 METH_NOARGS, localeconv__doc__},
13817
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
688 {"strcoll", (PyCFunction) PyLocale_strcoll,
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
689 METH_VARARGS, strcoll__doc__},
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
690 {"strxfrm", (PyCFunction) PyLocale_strxfrm,
3c0f75a2198f Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents: 13651
diff changeset
691 METH_VARARGS, strxfrm__doc__},
26415
d58824ceb35d Patch #632973: Implement _getdefaultlocale for OS X.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
692 #if defined(MS_WINDOWS) || defined(__APPLE__)
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22330
diff changeset
693 {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
694 #endif
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
695 #ifdef HAVE_LANGINFO_H
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
696 {"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
697 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
698 #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
699 #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
700 {"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
701 gettext__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
702 {"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
703 dgettext__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
704 {"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
705 dcgettext__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
706 {"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
707 textdomain__doc__},
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
708 {"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
709 bindtextdomain__doc__},
32794
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
710 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
711 {"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
712 METH_VARARGS, bind_textdomain_codeset__doc__},
0f9c39b3e5f0 This change implements the following gettext features, as
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 32689
diff changeset
713 #endif
22611
26785fe63cbb Expose C library's gettext. Fixes #516412.
Martin v. Löwis <martin@v.loewis.de>
parents: 22603
diff changeset
714 #endif
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
715 {NULL, NULL}
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
716 };
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
717
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24233
diff changeset
718 PyMODINIT_FUNC
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13618
diff changeset
719 init_locale(void)
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
720 {
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
721 PyObject *m, *d, *x;
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
722 #ifdef HAVE_LANGINFO_H
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
723 int i;
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
724 #endif
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
725
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
726 m = Py_InitModule("_locale", PyLocale_Methods);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 34640
diff changeset
727 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 34640
diff changeset
728 return;
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
729
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
730 d = PyModule_GetDict(m);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
731
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
732 x = PyInt_FromLong(LC_CTYPE);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
733 PyDict_SetItemString(d, "LC_CTYPE", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
734 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
735
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
736 x = PyInt_FromLong(LC_TIME);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
737 PyDict_SetItemString(d, "LC_TIME", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
738 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
739
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
740 x = PyInt_FromLong(LC_COLLATE);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
741 PyDict_SetItemString(d, "LC_COLLATE", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
742 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
743
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
744 x = PyInt_FromLong(LC_MONETARY);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
745 PyDict_SetItemString(d, "LC_MONETARY", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
746 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
747
6797
954417191fbf LC_MESSAGES is not defined on all systems; use #ifdef LC_MESSAGES.
Guido van Rossum <guido@python.org>
parents: 6596
diff changeset
748 #ifdef LC_MESSAGES
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
749 x = PyInt_FromLong(LC_MESSAGES);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
750 PyDict_SetItemString(d, "LC_MESSAGES", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
751 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
752 #endif /* LC_MESSAGES */
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
753
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
754 x = PyInt_FromLong(LC_NUMERIC);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
755 PyDict_SetItemString(d, "LC_NUMERIC", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
756 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
757
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
758 x = PyInt_FromLong(LC_ALL);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
759 PyDict_SetItemString(d, "LC_ALL", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
760 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
761
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
762 x = PyInt_FromLong(CHAR_MAX);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
763 PyDict_SetItemString(d, "CHAR_MAX", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
764 Py_XDECREF(x);
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
765
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
766 Error = PyErr_NewException("locale.Error", NULL, NULL);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
767 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
768
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
769 x = PyString_FromString(locale__doc__);
13438
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
770 PyDict_SetItemString(d, "__doc__", x);
ddf074ec6506 - added _getdefaultlocale implementation for WIN32
Fredrik Lundh <fredrik@pythonware.com>
parents: 13080
diff changeset
771 Py_XDECREF(x);
19125
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
772
f8b51c8ca082 Expose nl_langinfo through locale where available.
Martin v. Löwis <martin@v.loewis.de>
parents: 16946
diff changeset
773 #ifdef HAVE_LANGINFO_H
22330
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
774 for (i = 0; langinfo_constants[i].name; i++) {
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
775 PyModule_AddIntConstant(m, langinfo_constants[i].name,
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
776 langinfo_constants[i].value);
1a750fb93b16 backport loewis' checkin of
Michael W. Hudson <mwh@python.net>
parents: 21073
diff changeset
777 }
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
778 #endif
6596
f15f0fc38cb1 Martin von Loewis' _locale module (locale.py follows tomorrow).
Guido van Rossum <guido@python.org>
parents:
diff changeset
779 }
26739
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
780
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
781 /*
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
782 Local variables:
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
783 c-basic-offset: 4
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
784 indent-tabs-mode: nil
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
785 End:
c65e8cb91f4c Use wcscoll for _locale.strcoll if available.
Martin v. Löwis <martin@v.loewis.de>
parents: 26642
diff changeset
786 */