annotate Modules/_localemodule.c @ 79675:c0a2294de787 2.7

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