1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9
10
11 PyDoc_STRVAR(_locale_setlocale__doc__,
12 "setlocale($module, category, locale=<unrepresentable>, /)\n"
13 "--\n"
14 "\n"
15 "Activates/queries locale processing.");
16
17 #define _LOCALE_SETLOCALE_METHODDEF \
18 {"setlocale", _PyCFunction_CAST(_locale_setlocale), METH_FASTCALL, _locale_setlocale__doc__},
19
20 static PyObject *
21 _locale_setlocale_impl(PyObject *module, int category, const char *locale);
22
23 static PyObject *
24 _locale_setlocale(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
25 {
26 PyObject *return_value = NULL;
27 int category;
28 const char *locale = NULL;
29
30 if (!_PyArg_CheckPositional("setlocale", nargs, 1, 2)) {
31 goto exit;
32 }
33 category = _PyLong_AsInt(args[0]);
34 if (category == -1 && PyErr_Occurred()) {
35 goto exit;
36 }
37 if (nargs < 2) {
38 goto skip_optional;
39 }
40 if (args[1] == Py_None) {
41 locale = NULL;
42 }
43 else if (PyUnicode_Check(args[1])) {
44 Py_ssize_t locale_length;
45 locale = PyUnicode_AsUTF8AndSize(args[1], &locale_length);
46 if (locale == NULL) {
47 goto exit;
48 }
49 if (strlen(locale) != (size_t)locale_length) {
50 PyErr_SetString(PyExc_ValueError, "embedded null character");
51 goto exit;
52 }
53 }
54 else {
55 _PyArg_BadArgument("setlocale", "argument 2", "str or None", args[1]);
56 goto exit;
57 }
58 skip_optional:
59 return_value = _locale_setlocale_impl(module, category, locale);
60
61 exit:
62 return return_value;
63 }
64
65 PyDoc_STRVAR(_locale_localeconv__doc__,
66 "localeconv($module, /)\n"
67 "--\n"
68 "\n"
69 "Returns numeric and monetary locale-specific parameters.");
70
71 #define _LOCALE_LOCALECONV_METHODDEF \
72 {"localeconv", (PyCFunction)_locale_localeconv, METH_NOARGS, _locale_localeconv__doc__},
73
74 static PyObject *
75 _locale_localeconv_impl(PyObject *module);
76
77 static PyObject *
78 _locale_localeconv(PyObject *module, PyObject *Py_UNUSED(ignored))
79 {
80 return _locale_localeconv_impl(module);
81 }
82
83 #if defined(HAVE_WCSCOLL)
84
85 PyDoc_STRVAR(_locale_strcoll__doc__,
86 "strcoll($module, os1, os2, /)\n"
87 "--\n"
88 "\n"
89 "Compares two strings according to the locale.");
90
91 #define _LOCALE_STRCOLL_METHODDEF \
92 {"strcoll", _PyCFunction_CAST(_locale_strcoll), METH_FASTCALL, _locale_strcoll__doc__},
93
94 static PyObject *
95 _locale_strcoll_impl(PyObject *module, PyObject *os1, PyObject *os2);
96
97 static PyObject *
98 _locale_strcoll(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
99 {
100 PyObject *return_value = NULL;
101 PyObject *os1;
102 PyObject *os2;
103
104 if (!_PyArg_CheckPositional("strcoll", nargs, 2, 2)) {
105 goto exit;
106 }
107 if (!PyUnicode_Check(args[0])) {
108 _PyArg_BadArgument("strcoll", "argument 1", "str", args[0]);
109 goto exit;
110 }
111 if (PyUnicode_READY(args[0]) == -1) {
112 goto exit;
113 }
114 os1 = args[0];
115 if (!PyUnicode_Check(args[1])) {
116 _PyArg_BadArgument("strcoll", "argument 2", "str", args[1]);
117 goto exit;
118 }
119 if (PyUnicode_READY(args[1]) == -1) {
120 goto exit;
121 }
122 os2 = args[1];
123 return_value = _locale_strcoll_impl(module, os1, os2);
124
125 exit:
126 return return_value;
127 }
128
129 #endif /* defined(HAVE_WCSCOLL) */
130
131 #if defined(HAVE_WCSXFRM)
132
133 PyDoc_STRVAR(_locale_strxfrm__doc__,
134 "strxfrm($module, string, /)\n"
135 "--\n"
136 "\n"
137 "Return a string that can be used as a key for locale-aware comparisons.");
138
139 #define _LOCALE_STRXFRM_METHODDEF \
140 {"strxfrm", (PyCFunction)_locale_strxfrm, METH_O, _locale_strxfrm__doc__},
141
142 static PyObject *
143 _locale_strxfrm_impl(PyObject *module, PyObject *str);
144
145 static PyObject *
146 _locale_strxfrm(PyObject *module, PyObject *arg)
147 {
148 PyObject *return_value = NULL;
149 PyObject *str;
150
151 if (!PyUnicode_Check(arg)) {
152 _PyArg_BadArgument("strxfrm", "argument", "str", arg);
153 goto exit;
154 }
155 if (PyUnicode_READY(arg) == -1) {
156 goto exit;
157 }
158 str = arg;
159 return_value = _locale_strxfrm_impl(module, str);
160
161 exit:
162 return return_value;
163 }
164
165 #endif /* defined(HAVE_WCSXFRM) */
166
167 #if defined(MS_WINDOWS)
168
169 PyDoc_STRVAR(_locale__getdefaultlocale__doc__,
170 "_getdefaultlocale($module, /)\n"
171 "--\n"
172 "\n");
173
174 #define _LOCALE__GETDEFAULTLOCALE_METHODDEF \
175 {"_getdefaultlocale", (PyCFunction)_locale__getdefaultlocale, METH_NOARGS, _locale__getdefaultlocale__doc__},
176
177 static PyObject *
178 _locale__getdefaultlocale_impl(PyObject *module);
179
180 static PyObject *
181 _locale__getdefaultlocale(PyObject *module, PyObject *Py_UNUSED(ignored))
182 {
183 return _locale__getdefaultlocale_impl(module);
184 }
185
186 #endif /* defined(MS_WINDOWS) */
187
188 #if defined(HAVE_LANGINFO_H)
189
190 PyDoc_STRVAR(_locale_nl_langinfo__doc__,
191 "nl_langinfo($module, key, /)\n"
192 "--\n"
193 "\n"
194 "Return the value for the locale information associated with key.");
195
196 #define _LOCALE_NL_LANGINFO_METHODDEF \
197 {"nl_langinfo", (PyCFunction)_locale_nl_langinfo, METH_O, _locale_nl_langinfo__doc__},
198
199 static PyObject *
200 _locale_nl_langinfo_impl(PyObject *module, int item);
201
202 static PyObject *
203 _locale_nl_langinfo(PyObject *module, PyObject *arg)
204 {
205 PyObject *return_value = NULL;
206 int item;
207
208 item = _PyLong_AsInt(arg);
209 if (item == -1 && PyErr_Occurred()) {
210 goto exit;
211 }
212 return_value = _locale_nl_langinfo_impl(module, item);
213
214 exit:
215 return return_value;
216 }
217
218 #endif /* defined(HAVE_LANGINFO_H) */
219
220 #if defined(HAVE_LIBINTL_H)
221
222 PyDoc_STRVAR(_locale_gettext__doc__,
223 "gettext($module, msg, /)\n"
224 "--\n"
225 "\n"
226 "gettext(msg) -> string\n"
227 "\n"
228 "Return translation of msg.");
229
230 #define _LOCALE_GETTEXT_METHODDEF \
231 {"gettext", (PyCFunction)_locale_gettext, METH_O, _locale_gettext__doc__},
232
233 static PyObject *
234 _locale_gettext_impl(PyObject *module, const char *in);
235
236 static PyObject *
237 _locale_gettext(PyObject *module, PyObject *arg)
238 {
239 PyObject *return_value = NULL;
240 const char *in;
241
242 if (!PyUnicode_Check(arg)) {
243 _PyArg_BadArgument("gettext", "argument", "str", arg);
244 goto exit;
245 }
246 Py_ssize_t in_length;
247 in = PyUnicode_AsUTF8AndSize(arg, &in_length);
248 if (in == NULL) {
249 goto exit;
250 }
251 if (strlen(in) != (size_t)in_length) {
252 PyErr_SetString(PyExc_ValueError, "embedded null character");
253 goto exit;
254 }
255 return_value = _locale_gettext_impl(module, in);
256
257 exit:
258 return return_value;
259 }
260
261 #endif /* defined(HAVE_LIBINTL_H) */
262
263 #if defined(HAVE_LIBINTL_H)
264
265 PyDoc_STRVAR(_locale_dgettext__doc__,
266 "dgettext($module, domain, msg, /)\n"
267 "--\n"
268 "\n"
269 "dgettext(domain, msg) -> string\n"
270 "\n"
271 "Return translation of msg in domain.");
272
273 #define _LOCALE_DGETTEXT_METHODDEF \
274 {"dgettext", _PyCFunction_CAST(_locale_dgettext), METH_FASTCALL, _locale_dgettext__doc__},
275
276 static PyObject *
277 _locale_dgettext_impl(PyObject *module, const char *domain, const char *in);
278
279 static PyObject *
280 _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
281 {
282 PyObject *return_value = NULL;
283 const char *domain;
284 const char *in;
285
286 if (!_PyArg_CheckPositional("dgettext", nargs, 2, 2)) {
287 goto exit;
288 }
289 if (args[0] == Py_None) {
290 domain = NULL;
291 }
292 else if (PyUnicode_Check(args[0])) {
293 Py_ssize_t domain_length;
294 domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
295 if (domain == NULL) {
296 goto exit;
297 }
298 if (strlen(domain) != (size_t)domain_length) {
299 PyErr_SetString(PyExc_ValueError, "embedded null character");
300 goto exit;
301 }
302 }
303 else {
304 _PyArg_BadArgument("dgettext", "argument 1", "str or None", args[0]);
305 goto exit;
306 }
307 if (!PyUnicode_Check(args[1])) {
308 _PyArg_BadArgument("dgettext", "argument 2", "str", args[1]);
309 goto exit;
310 }
311 Py_ssize_t in_length;
312 in = PyUnicode_AsUTF8AndSize(args[1], &in_length);
313 if (in == NULL) {
314 goto exit;
315 }
316 if (strlen(in) != (size_t)in_length) {
317 PyErr_SetString(PyExc_ValueError, "embedded null character");
318 goto exit;
319 }
320 return_value = _locale_dgettext_impl(module, domain, in);
321
322 exit:
323 return return_value;
324 }
325
326 #endif /* defined(HAVE_LIBINTL_H) */
327
328 #if defined(HAVE_LIBINTL_H)
329
330 PyDoc_STRVAR(_locale_dcgettext__doc__,
331 "dcgettext($module, domain, msg, category, /)\n"
332 "--\n"
333 "\n"
334 "Return translation of msg in domain and category.");
335
336 #define _LOCALE_DCGETTEXT_METHODDEF \
337 {"dcgettext", _PyCFunction_CAST(_locale_dcgettext), METH_FASTCALL, _locale_dcgettext__doc__},
338
339 static PyObject *
340 _locale_dcgettext_impl(PyObject *module, const char *domain,
341 const char *msgid, int category);
342
343 static PyObject *
344 _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
345 {
346 PyObject *return_value = NULL;
347 const char *domain;
348 const char *msgid;
349 int category;
350
351 if (!_PyArg_CheckPositional("dcgettext", nargs, 3, 3)) {
352 goto exit;
353 }
354 if (args[0] == Py_None) {
355 domain = NULL;
356 }
357 else if (PyUnicode_Check(args[0])) {
358 Py_ssize_t domain_length;
359 domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
360 if (domain == NULL) {
361 goto exit;
362 }
363 if (strlen(domain) != (size_t)domain_length) {
364 PyErr_SetString(PyExc_ValueError, "embedded null character");
365 goto exit;
366 }
367 }
368 else {
369 _PyArg_BadArgument("dcgettext", "argument 1", "str or None", args[0]);
370 goto exit;
371 }
372 if (!PyUnicode_Check(args[1])) {
373 _PyArg_BadArgument("dcgettext", "argument 2", "str", args[1]);
374 goto exit;
375 }
376 Py_ssize_t msgid_length;
377 msgid = PyUnicode_AsUTF8AndSize(args[1], &msgid_length);
378 if (msgid == NULL) {
379 goto exit;
380 }
381 if (strlen(msgid) != (size_t)msgid_length) {
382 PyErr_SetString(PyExc_ValueError, "embedded null character");
383 goto exit;
384 }
385 category = _PyLong_AsInt(args[2]);
386 if (category == -1 && PyErr_Occurred()) {
387 goto exit;
388 }
389 return_value = _locale_dcgettext_impl(module, domain, msgid, category);
390
391 exit:
392 return return_value;
393 }
394
395 #endif /* defined(HAVE_LIBINTL_H) */
396
397 #if defined(HAVE_LIBINTL_H)
398
399 PyDoc_STRVAR(_locale_textdomain__doc__,
400 "textdomain($module, domain, /)\n"
401 "--\n"
402 "\n"
403 "Set the C library\'s textdmain to domain, returning the new domain.");
404
405 #define _LOCALE_TEXTDOMAIN_METHODDEF \
406 {"textdomain", (PyCFunction)_locale_textdomain, METH_O, _locale_textdomain__doc__},
407
408 static PyObject *
409 _locale_textdomain_impl(PyObject *module, const char *domain);
410
411 static PyObject *
412 _locale_textdomain(PyObject *module, PyObject *arg)
413 {
414 PyObject *return_value = NULL;
415 const char *domain;
416
417 if (arg == Py_None) {
418 domain = NULL;
419 }
420 else if (PyUnicode_Check(arg)) {
421 Py_ssize_t domain_length;
422 domain = PyUnicode_AsUTF8AndSize(arg, &domain_length);
423 if (domain == NULL) {
424 goto exit;
425 }
426 if (strlen(domain) != (size_t)domain_length) {
427 PyErr_SetString(PyExc_ValueError, "embedded null character");
428 goto exit;
429 }
430 }
431 else {
432 _PyArg_BadArgument("textdomain", "argument", "str or None", arg);
433 goto exit;
434 }
435 return_value = _locale_textdomain_impl(module, domain);
436
437 exit:
438 return return_value;
439 }
440
441 #endif /* defined(HAVE_LIBINTL_H) */
442
443 #if defined(HAVE_LIBINTL_H)
444
445 PyDoc_STRVAR(_locale_bindtextdomain__doc__,
446 "bindtextdomain($module, domain, dir, /)\n"
447 "--\n"
448 "\n"
449 "Bind the C library\'s domain to dir.");
450
451 #define _LOCALE_BINDTEXTDOMAIN_METHODDEF \
452 {"bindtextdomain", _PyCFunction_CAST(_locale_bindtextdomain), METH_FASTCALL, _locale_bindtextdomain__doc__},
453
454 static PyObject *
455 _locale_bindtextdomain_impl(PyObject *module, const char *domain,
456 PyObject *dirname_obj);
457
458 static PyObject *
459 _locale_bindtextdomain(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
460 {
461 PyObject *return_value = NULL;
462 const char *domain;
463 PyObject *dirname_obj;
464
465 if (!_PyArg_CheckPositional("bindtextdomain", nargs, 2, 2)) {
466 goto exit;
467 }
468 if (!PyUnicode_Check(args[0])) {
469 _PyArg_BadArgument("bindtextdomain", "argument 1", "str", args[0]);
470 goto exit;
471 }
472 Py_ssize_t domain_length;
473 domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
474 if (domain == NULL) {
475 goto exit;
476 }
477 if (strlen(domain) != (size_t)domain_length) {
478 PyErr_SetString(PyExc_ValueError, "embedded null character");
479 goto exit;
480 }
481 dirname_obj = args[1];
482 return_value = _locale_bindtextdomain_impl(module, domain, dirname_obj);
483
484 exit:
485 return return_value;
486 }
487
488 #endif /* defined(HAVE_LIBINTL_H) */
489
490 #if defined(HAVE_LIBINTL_H) && defined(HAVE_BIND_TEXTDOMAIN_CODESET)
491
492 PyDoc_STRVAR(_locale_bind_textdomain_codeset__doc__,
493 "bind_textdomain_codeset($module, domain, codeset, /)\n"
494 "--\n"
495 "\n"
496 "Bind the C library\'s domain to codeset.");
497
498 #define _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF \
499 {"bind_textdomain_codeset", _PyCFunction_CAST(_locale_bind_textdomain_codeset), METH_FASTCALL, _locale_bind_textdomain_codeset__doc__},
500
501 static PyObject *
502 _locale_bind_textdomain_codeset_impl(PyObject *module, const char *domain,
503 const char *codeset);
504
505 static PyObject *
506 _locale_bind_textdomain_codeset(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
507 {
508 PyObject *return_value = NULL;
509 const char *domain;
510 const char *codeset;
511
512 if (!_PyArg_CheckPositional("bind_textdomain_codeset", nargs, 2, 2)) {
513 goto exit;
514 }
515 if (!PyUnicode_Check(args[0])) {
516 _PyArg_BadArgument("bind_textdomain_codeset", "argument 1", "str", args[0]);
517 goto exit;
518 }
519 Py_ssize_t domain_length;
520 domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
521 if (domain == NULL) {
522 goto exit;
523 }
524 if (strlen(domain) != (size_t)domain_length) {
525 PyErr_SetString(PyExc_ValueError, "embedded null character");
526 goto exit;
527 }
528 if (args[1] == Py_None) {
529 codeset = NULL;
530 }
531 else if (PyUnicode_Check(args[1])) {
532 Py_ssize_t codeset_length;
533 codeset = PyUnicode_AsUTF8AndSize(args[1], &codeset_length);
534 if (codeset == NULL) {
535 goto exit;
536 }
537 if (strlen(codeset) != (size_t)codeset_length) {
538 PyErr_SetString(PyExc_ValueError, "embedded null character");
539 goto exit;
540 }
541 }
542 else {
543 _PyArg_BadArgument("bind_textdomain_codeset", "argument 2", "str or None", args[1]);
544 goto exit;
545 }
546 return_value = _locale_bind_textdomain_codeset_impl(module, domain, codeset);
547
548 exit:
549 return return_value;
550 }
551
552 #endif /* defined(HAVE_LIBINTL_H) && defined(HAVE_BIND_TEXTDOMAIN_CODESET) */
553
554 PyDoc_STRVAR(_locale_getencoding__doc__,
555 "getencoding($module, /)\n"
556 "--\n"
557 "\n"
558 "Get the current locale encoding.");
559
560 #define _LOCALE_GETENCODING_METHODDEF \
561 {"getencoding", (PyCFunction)_locale_getencoding, METH_NOARGS, _locale_getencoding__doc__},
562
563 static PyObject *
564 _locale_getencoding_impl(PyObject *module);
565
566 static PyObject *
567 _locale_getencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
568 {
569 return _locale_getencoding_impl(module);
570 }
571
572 #ifndef _LOCALE_STRCOLL_METHODDEF
573 #define _LOCALE_STRCOLL_METHODDEF
574 #endif /* !defined(_LOCALE_STRCOLL_METHODDEF) */
575
576 #ifndef _LOCALE_STRXFRM_METHODDEF
577 #define _LOCALE_STRXFRM_METHODDEF
578 #endif /* !defined(_LOCALE_STRXFRM_METHODDEF) */
579
580 #ifndef _LOCALE__GETDEFAULTLOCALE_METHODDEF
581 #define _LOCALE__GETDEFAULTLOCALE_METHODDEF
582 #endif /* !defined(_LOCALE__GETDEFAULTLOCALE_METHODDEF) */
583
584 #ifndef _LOCALE_NL_LANGINFO_METHODDEF
585 #define _LOCALE_NL_LANGINFO_METHODDEF
586 #endif /* !defined(_LOCALE_NL_LANGINFO_METHODDEF) */
587
588 #ifndef _LOCALE_GETTEXT_METHODDEF
589 #define _LOCALE_GETTEXT_METHODDEF
590 #endif /* !defined(_LOCALE_GETTEXT_METHODDEF) */
591
592 #ifndef _LOCALE_DGETTEXT_METHODDEF
593 #define _LOCALE_DGETTEXT_METHODDEF
594 #endif /* !defined(_LOCALE_DGETTEXT_METHODDEF) */
595
596 #ifndef _LOCALE_DCGETTEXT_METHODDEF
597 #define _LOCALE_DCGETTEXT_METHODDEF
598 #endif /* !defined(_LOCALE_DCGETTEXT_METHODDEF) */
599
600 #ifndef _LOCALE_TEXTDOMAIN_METHODDEF
601 #define _LOCALE_TEXTDOMAIN_METHODDEF
602 #endif /* !defined(_LOCALE_TEXTDOMAIN_METHODDEF) */
603
604 #ifndef _LOCALE_BINDTEXTDOMAIN_METHODDEF
605 #define _LOCALE_BINDTEXTDOMAIN_METHODDEF
606 #endif /* !defined(_LOCALE_BINDTEXTDOMAIN_METHODDEF) */
607
608 #ifndef _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
609 #define _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
610 #endif /* !defined(_LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF) */
611 /*[clinic end generated code: output=406842c3441559cb input=a9049054013a1b77]*/