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