Coverage Report

Created: 2026-10-17 06:15

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