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