(root)/
Python-3.12.0/
Modules/
clinic/
pyexpat.c.h
       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(pyexpat_xmlparser_Parse__doc__,
      12  "Parse($self, data, isfinal=False, /)\n"
      13  "--\n"
      14  "\n"
      15  "Parse XML data.\n"
      16  "\n"
      17  "`isfinal\' should be true at end of input.");
      18  
      19  #define PYEXPAT_XMLPARSER_PARSE_METHODDEF    \
      20      {"Parse", _PyCFunction_CAST(pyexpat_xmlparser_Parse), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_Parse__doc__},
      21  
      22  static PyObject *
      23  pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
      24                               PyObject *data, int isfinal);
      25  
      26  static PyObject *
      27  pyexpat_xmlparser_Parse(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      28  {
      29      PyObject *return_value = NULL;
      30      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      31      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
      32      #else
      33      #  define KWTUPLE NULL
      34      #endif
      35  
      36      static const char * const _keywords[] = {"", "", NULL};
      37      static _PyArg_Parser _parser = {
      38          .keywords = _keywords,
      39          .fname = "Parse",
      40          .kwtuple = KWTUPLE,
      41      };
      42      #undef KWTUPLE
      43      PyObject *argsbuf[2];
      44      PyObject *data;
      45      int isfinal = 0;
      46  
      47      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
      48      if (!args) {
      49          goto exit;
      50      }
      51      data = args[0];
      52      if (nargs < 2) {
      53          goto skip_optional_posonly;
      54      }
      55      isfinal = PyObject_IsTrue(args[1]);
      56      if (isfinal < 0) {
      57          goto exit;
      58      }
      59  skip_optional_posonly:
      60      return_value = pyexpat_xmlparser_Parse_impl(self, cls, data, isfinal);
      61  
      62  exit:
      63      return return_value;
      64  }
      65  
      66  PyDoc_STRVAR(pyexpat_xmlparser_ParseFile__doc__,
      67  "ParseFile($self, file, /)\n"
      68  "--\n"
      69  "\n"
      70  "Parse XML data from file-like object.");
      71  
      72  #define PYEXPAT_XMLPARSER_PARSEFILE_METHODDEF    \
      73      {"ParseFile", _PyCFunction_CAST(pyexpat_xmlparser_ParseFile), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_ParseFile__doc__},
      74  
      75  static PyObject *
      76  pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
      77                                   PyObject *file);
      78  
      79  static PyObject *
      80  pyexpat_xmlparser_ParseFile(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      81  {
      82      PyObject *return_value = NULL;
      83      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      84      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
      85      #else
      86      #  define KWTUPLE NULL
      87      #endif
      88  
      89      static const char * const _keywords[] = {"", NULL};
      90      static _PyArg_Parser _parser = {
      91          .keywords = _keywords,
      92          .fname = "ParseFile",
      93          .kwtuple = KWTUPLE,
      94      };
      95      #undef KWTUPLE
      96      PyObject *argsbuf[1];
      97      PyObject *file;
      98  
      99      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
     100      if (!args) {
     101          goto exit;
     102      }
     103      file = args[0];
     104      return_value = pyexpat_xmlparser_ParseFile_impl(self, cls, file);
     105  
     106  exit:
     107      return return_value;
     108  }
     109  
     110  PyDoc_STRVAR(pyexpat_xmlparser_SetBase__doc__,
     111  "SetBase($self, base, /)\n"
     112  "--\n"
     113  "\n"
     114  "Set the base URL for the parser.");
     115  
     116  #define PYEXPAT_XMLPARSER_SETBASE_METHODDEF    \
     117      {"SetBase", (PyCFunction)pyexpat_xmlparser_SetBase, METH_O, pyexpat_xmlparser_SetBase__doc__},
     118  
     119  static PyObject *
     120  pyexpat_xmlparser_SetBase_impl(xmlparseobject *self, const char *base);
     121  
     122  static PyObject *
     123  pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *arg)
     124  {
     125      PyObject *return_value = NULL;
     126      const char *base;
     127  
     128      if (!PyUnicode_Check(arg)) {
     129          _PyArg_BadArgument("SetBase", "argument", "str", arg);
     130          goto exit;
     131      }
     132      Py_ssize_t base_length;
     133      base = PyUnicode_AsUTF8AndSize(arg, &base_length);
     134      if (base == NULL) {
     135          goto exit;
     136      }
     137      if (strlen(base) != (size_t)base_length) {
     138          PyErr_SetString(PyExc_ValueError, "embedded null character");
     139          goto exit;
     140      }
     141      return_value = pyexpat_xmlparser_SetBase_impl(self, base);
     142  
     143  exit:
     144      return return_value;
     145  }
     146  
     147  PyDoc_STRVAR(pyexpat_xmlparser_GetBase__doc__,
     148  "GetBase($self, /)\n"
     149  "--\n"
     150  "\n"
     151  "Return base URL string for the parser.");
     152  
     153  #define PYEXPAT_XMLPARSER_GETBASE_METHODDEF    \
     154      {"GetBase", (PyCFunction)pyexpat_xmlparser_GetBase, METH_NOARGS, pyexpat_xmlparser_GetBase__doc__},
     155  
     156  static PyObject *
     157  pyexpat_xmlparser_GetBase_impl(xmlparseobject *self);
     158  
     159  static PyObject *
     160  pyexpat_xmlparser_GetBase(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
     161  {
     162      return pyexpat_xmlparser_GetBase_impl(self);
     163  }
     164  
     165  PyDoc_STRVAR(pyexpat_xmlparser_GetInputContext__doc__,
     166  "GetInputContext($self, /)\n"
     167  "--\n"
     168  "\n"
     169  "Return the untranslated text of the input that caused the current event.\n"
     170  "\n"
     171  "If the event was generated by a large amount of text (such as a start tag\n"
     172  "for an element with many attributes), not all of the text may be available.");
     173  
     174  #define PYEXPAT_XMLPARSER_GETINPUTCONTEXT_METHODDEF    \
     175      {"GetInputContext", (PyCFunction)pyexpat_xmlparser_GetInputContext, METH_NOARGS, pyexpat_xmlparser_GetInputContext__doc__},
     176  
     177  static PyObject *
     178  pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self);
     179  
     180  static PyObject *
     181  pyexpat_xmlparser_GetInputContext(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
     182  {
     183      return pyexpat_xmlparser_GetInputContext_impl(self);
     184  }
     185  
     186  PyDoc_STRVAR(pyexpat_xmlparser_ExternalEntityParserCreate__doc__,
     187  "ExternalEntityParserCreate($self, context, encoding=<unrepresentable>,\n"
     188  "                           /)\n"
     189  "--\n"
     190  "\n"
     191  "Create a parser for parsing an external entity based on the information passed to the ExternalEntityRefHandler.");
     192  
     193  #define PYEXPAT_XMLPARSER_EXTERNALENTITYPARSERCREATE_METHODDEF    \
     194      {"ExternalEntityParserCreate", _PyCFunction_CAST(pyexpat_xmlparser_ExternalEntityParserCreate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_ExternalEntityParserCreate__doc__},
     195  
     196  static PyObject *
     197  pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self,
     198                                                    PyTypeObject *cls,
     199                                                    const char *context,
     200                                                    const char *encoding);
     201  
     202  static PyObject *
     203  pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     204  {
     205      PyObject *return_value = NULL;
     206      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     207      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
     208      #else
     209      #  define KWTUPLE NULL
     210      #endif
     211  
     212      static const char * const _keywords[] = {"", "", NULL};
     213      static _PyArg_Parser _parser = {
     214          .keywords = _keywords,
     215          .fname = "ExternalEntityParserCreate",
     216          .kwtuple = KWTUPLE,
     217      };
     218      #undef KWTUPLE
     219      PyObject *argsbuf[2];
     220      const char *context;
     221      const char *encoding = NULL;
     222  
     223      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
     224      if (!args) {
     225          goto exit;
     226      }
     227      if (args[0] == Py_None) {
     228          context = NULL;
     229      }
     230      else if (PyUnicode_Check(args[0])) {
     231          Py_ssize_t context_length;
     232          context = PyUnicode_AsUTF8AndSize(args[0], &context_length);
     233          if (context == NULL) {
     234              goto exit;
     235          }
     236          if (strlen(context) != (size_t)context_length) {
     237              PyErr_SetString(PyExc_ValueError, "embedded null character");
     238              goto exit;
     239          }
     240      }
     241      else {
     242          _PyArg_BadArgument("ExternalEntityParserCreate", "argument 1", "str or None", args[0]);
     243          goto exit;
     244      }
     245      if (nargs < 2) {
     246          goto skip_optional_posonly;
     247      }
     248      if (!PyUnicode_Check(args[1])) {
     249          _PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]);
     250          goto exit;
     251      }
     252      Py_ssize_t encoding_length;
     253      encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
     254      if (encoding == NULL) {
     255          goto exit;
     256      }
     257      if (strlen(encoding) != (size_t)encoding_length) {
     258          PyErr_SetString(PyExc_ValueError, "embedded null character");
     259          goto exit;
     260      }
     261  skip_optional_posonly:
     262      return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl(self, cls, context, encoding);
     263  
     264  exit:
     265      return return_value;
     266  }
     267  
     268  PyDoc_STRVAR(pyexpat_xmlparser_SetParamEntityParsing__doc__,
     269  "SetParamEntityParsing($self, flag, /)\n"
     270  "--\n"
     271  "\n"
     272  "Controls parsing of parameter entities (including the external DTD subset).\n"
     273  "\n"
     274  "Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n"
     275  "XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n"
     276  "XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n"
     277  "was successful.");
     278  
     279  #define PYEXPAT_XMLPARSER_SETPARAMENTITYPARSING_METHODDEF    \
     280      {"SetParamEntityParsing", (PyCFunction)pyexpat_xmlparser_SetParamEntityParsing, METH_O, pyexpat_xmlparser_SetParamEntityParsing__doc__},
     281  
     282  static PyObject *
     283  pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag);
     284  
     285  static PyObject *
     286  pyexpat_xmlparser_SetParamEntityParsing(xmlparseobject *self, PyObject *arg)
     287  {
     288      PyObject *return_value = NULL;
     289      int flag;
     290  
     291      flag = _PyLong_AsInt(arg);
     292      if (flag == -1 && PyErr_Occurred()) {
     293          goto exit;
     294      }
     295      return_value = pyexpat_xmlparser_SetParamEntityParsing_impl(self, flag);
     296  
     297  exit:
     298      return return_value;
     299  }
     300  
     301  #if (XML_COMBINED_VERSION >= 19505)
     302  
     303  PyDoc_STRVAR(pyexpat_xmlparser_UseForeignDTD__doc__,
     304  "UseForeignDTD($self, flag=True, /)\n"
     305  "--\n"
     306  "\n"
     307  "Allows the application to provide an artificial external subset if one is not specified as part of the document instance.\n"
     308  "\n"
     309  "This readily allows the use of a \'default\' document type controlled by the\n"
     310  "application, while still getting the advantage of providing document type\n"
     311  "information to the parser. \'flag\' defaults to True if not provided.");
     312  
     313  #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF    \
     314      {"UseForeignDTD", _PyCFunction_CAST(pyexpat_xmlparser_UseForeignDTD), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_UseForeignDTD__doc__},
     315  
     316  static PyObject *
     317  pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, PyTypeObject *cls,
     318                                       int flag);
     319  
     320  static PyObject *
     321  pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     322  {
     323      PyObject *return_value = NULL;
     324      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     325      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
     326      #else
     327      #  define KWTUPLE NULL
     328      #endif
     329  
     330      static const char * const _keywords[] = {"", NULL};
     331      static _PyArg_Parser _parser = {
     332          .keywords = _keywords,
     333          .fname = "UseForeignDTD",
     334          .kwtuple = KWTUPLE,
     335      };
     336      #undef KWTUPLE
     337      PyObject *argsbuf[1];
     338      int flag = 1;
     339  
     340      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     341      if (!args) {
     342          goto exit;
     343      }
     344      if (nargs < 1) {
     345          goto skip_optional_posonly;
     346      }
     347      flag = PyObject_IsTrue(args[0]);
     348      if (flag < 0) {
     349          goto exit;
     350      }
     351  skip_optional_posonly:
     352      return_value = pyexpat_xmlparser_UseForeignDTD_impl(self, cls, flag);
     353  
     354  exit:
     355      return return_value;
     356  }
     357  
     358  #endif /* (XML_COMBINED_VERSION >= 19505) */
     359  
     360  PyDoc_STRVAR(pyexpat_ParserCreate__doc__,
     361  "ParserCreate($module, /, encoding=None, namespace_separator=None,\n"
     362  "             intern=<unrepresentable>)\n"
     363  "--\n"
     364  "\n"
     365  "Return a new XML parser object.");
     366  
     367  #define PYEXPAT_PARSERCREATE_METHODDEF    \
     368      {"ParserCreate", _PyCFunction_CAST(pyexpat_ParserCreate), METH_FASTCALL|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
     369  
     370  static PyObject *
     371  pyexpat_ParserCreate_impl(PyObject *module, const char *encoding,
     372                            const char *namespace_separator, PyObject *intern);
     373  
     374  static PyObject *
     375  pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     376  {
     377      PyObject *return_value = NULL;
     378      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     379  
     380      #define NUM_KEYWORDS 3
     381      static struct {
     382          PyGC_Head _this_is_not_used;
     383          PyObject_VAR_HEAD
     384          PyObject *ob_item[NUM_KEYWORDS];
     385      } _kwtuple = {
     386          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     387          .ob_item = { &_Py_ID(encoding), &_Py_ID(namespace_separator), &_Py_ID(intern), },
     388      };
     389      #undef NUM_KEYWORDS
     390      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     391  
     392      #else  // !Py_BUILD_CORE
     393      #  define KWTUPLE NULL
     394      #endif  // !Py_BUILD_CORE
     395  
     396      static const char * const _keywords[] = {"encoding", "namespace_separator", "intern", NULL};
     397      static _PyArg_Parser _parser = {
     398          .keywords = _keywords,
     399          .fname = "ParserCreate",
     400          .kwtuple = KWTUPLE,
     401      };
     402      #undef KWTUPLE
     403      PyObject *argsbuf[3];
     404      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     405      const char *encoding = NULL;
     406      const char *namespace_separator = NULL;
     407      PyObject *intern = NULL;
     408  
     409      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf);
     410      if (!args) {
     411          goto exit;
     412      }
     413      if (!noptargs) {
     414          goto skip_optional_pos;
     415      }
     416      if (args[0]) {
     417          if (args[0] == Py_None) {
     418              encoding = NULL;
     419          }
     420          else if (PyUnicode_Check(args[0])) {
     421              Py_ssize_t encoding_length;
     422              encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
     423              if (encoding == NULL) {
     424                  goto exit;
     425              }
     426              if (strlen(encoding) != (size_t)encoding_length) {
     427                  PyErr_SetString(PyExc_ValueError, "embedded null character");
     428                  goto exit;
     429              }
     430          }
     431          else {
     432              _PyArg_BadArgument("ParserCreate", "argument 'encoding'", "str or None", args[0]);
     433              goto exit;
     434          }
     435          if (!--noptargs) {
     436              goto skip_optional_pos;
     437          }
     438      }
     439      if (args[1]) {
     440          if (args[1] == Py_None) {
     441              namespace_separator = NULL;
     442          }
     443          else if (PyUnicode_Check(args[1])) {
     444              Py_ssize_t namespace_separator_length;
     445              namespace_separator = PyUnicode_AsUTF8AndSize(args[1], &namespace_separator_length);
     446              if (namespace_separator == NULL) {
     447                  goto exit;
     448              }
     449              if (strlen(namespace_separator) != (size_t)namespace_separator_length) {
     450                  PyErr_SetString(PyExc_ValueError, "embedded null character");
     451                  goto exit;
     452              }
     453          }
     454          else {
     455              _PyArg_BadArgument("ParserCreate", "argument 'namespace_separator'", "str or None", args[1]);
     456              goto exit;
     457          }
     458          if (!--noptargs) {
     459              goto skip_optional_pos;
     460          }
     461      }
     462      intern = args[2];
     463  skip_optional_pos:
     464      return_value = pyexpat_ParserCreate_impl(module, encoding, namespace_separator, intern);
     465  
     466  exit:
     467      return return_value;
     468  }
     469  
     470  PyDoc_STRVAR(pyexpat_ErrorString__doc__,
     471  "ErrorString($module, code, /)\n"
     472  "--\n"
     473  "\n"
     474  "Returns string error for given number.");
     475  
     476  #define PYEXPAT_ERRORSTRING_METHODDEF    \
     477      {"ErrorString", (PyCFunction)pyexpat_ErrorString, METH_O, pyexpat_ErrorString__doc__},
     478  
     479  static PyObject *
     480  pyexpat_ErrorString_impl(PyObject *module, long code);
     481  
     482  static PyObject *
     483  pyexpat_ErrorString(PyObject *module, PyObject *arg)
     484  {
     485      PyObject *return_value = NULL;
     486      long code;
     487  
     488      code = PyLong_AsLong(arg);
     489      if (code == -1 && PyErr_Occurred()) {
     490          goto exit;
     491      }
     492      return_value = pyexpat_ErrorString_impl(module, code);
     493  
     494  exit:
     495      return return_value;
     496  }
     497  
     498  #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
     499      #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
     500  #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */
     501  /*[clinic end generated code: output=63efc62e24a7b5a7 input=a9049054013a1b77]*/