LCOV - code coverage report
Current view: top level - Modules/clinic - pyexpat.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 107 150 71.3 %
Date: 2022-07-07 18:19:46 Functions: 8 10 80.0 %

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

Generated by: LCOV version 1.14