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