_localemodule.c.h 16 KB

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