Debian Codegraph @

Modules/clinic/pyexpat.c.h

raw
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_long.h" // _PyLong_UnsignedLongLong_Converter()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(pyexpat_xmlparser_SetReparseDeferralEnabled__doc__,
13 "SetReparseDeferralEnabled($self, enabled, /)\n"
14 "--\n"
15 "\n"
16 "Enable/Disable reparse deferral; enabled by default with Expat >=2.6.0.");
17
18 #define PYEXPAT_XMLPARSER_SETREPARSEDEFERRALENABLED_METHODDEF \
19 {"SetReparseDeferralEnabled", (PyCFunction)pyexpat_xmlparser_SetReparseDeferralEnabled, METH_O, pyexpat_xmlparser_SetReparseDeferralEnabled__doc__},
20
21 static PyObject *
22 pyexpat_xmlparser_SetReparseDeferralEnabled_impl(xmlparseobject *self,
23 int enabled);
24
25 static PyObject *
26 pyexpat_xmlparser_SetReparseDeferralEnabled(PyObject *self, PyObject *arg)
27 {
28 PyObject *return_value = NULL;
29 int enabled;
30
31 enabled = PyObject_IsTrue(arg);
32 if (enabled < 0) {
33 goto exit;
34 }
35 return_value = pyexpat_xmlparser_SetReparseDeferralEnabled_impl((xmlparseobject *)self, enabled);
36
37 exit:
38 return return_value;
39 }
40
41 PyDoc_STRVAR(pyexpat_xmlparser_GetReparseDeferralEnabled__doc__,
42 "GetReparseDeferralEnabled($self, /)\n"
43 "--\n"
44 "\n"
45 "Retrieve reparse deferral enabled status; always returns false with Expat <2.6.0.");
46
47 #define PYEXPAT_XMLPARSER_GETREPARSEDEFERRALENABLED_METHODDEF \
48 {"GetReparseDeferralEnabled", (PyCFunction)pyexpat_xmlparser_GetReparseDeferralEnabled, METH_NOARGS, pyexpat_xmlparser_GetReparseDeferralEnabled__doc__},
49
50 static PyObject *
51 pyexpat_xmlparser_GetReparseDeferralEnabled_impl(xmlparseobject *self);
52
53 static PyObject *
54 pyexpat_xmlparser_GetReparseDeferralEnabled(PyObject *self, PyObject *Py_UNUSED(ignored))
55 {
56 return pyexpat_xmlparser_GetReparseDeferralEnabled_impl((xmlparseobject *)self);
57 }
58
59 PyDoc_STRVAR(pyexpat_xmlparser_Parse__doc__,
60 "Parse($self, data, isfinal=False, /)\n"
61 "--\n"
62 "\n"
63 "Parse XML data.\n"
64 "\n"
65 "\'isfinal\' should be true at end of input.");
66
67 #define PYEXPAT_XMLPARSER_PARSE_METHODDEF \
68 {"Parse", _PyCFunction_CAST(pyexpat_xmlparser_Parse), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_Parse__doc__},
69
70 static PyObject *
71 pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
72 PyObject *data, int isfinal);
73
74 static PyObject *
75 pyexpat_xmlparser_Parse(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
76 {
77 PyObject *return_value = NULL;
78 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
79 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
80 #else
81 # define KWTUPLE NULL
82 #endif
83
84 static const char * const _keywords[] = {"", "", NULL};
85 static _PyArg_Parser _parser = {
86 .keywords = _keywords,
87 .fname = "Parse",
88 .kwtuple = KWTUPLE,
89 };
90 #undef KWTUPLE
91 PyObject *argsbuf[2];
92 PyObject *data;
93 int isfinal = 0;
94
95 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
96 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
97 if (!args) {
98 goto exit;
99 }
100 data = args[0];
101 if (nargs < 2) {
102 goto skip_optional_posonly;
103 }
104 isfinal = PyObject_IsTrue(args[1]);
105 if (isfinal < 0) {
106 goto exit;
107 }
108 skip_optional_posonly:
109 return_value = pyexpat_xmlparser_Parse_impl((xmlparseobject *)self, cls, data, isfinal);
110
111 exit:
112 return return_value;
113 }
114
115 PyDoc_STRVAR(pyexpat_xmlparser_ParseFile__doc__,
116 "ParseFile($self, file, /)\n"
117 "--\n"
118 "\n"
119 "Parse XML data from file-like object.");
120
121 #define PYEXPAT_XMLPARSER_PARSEFILE_METHODDEF \
122 {"ParseFile", _PyCFunction_CAST(pyexpat_xmlparser_ParseFile), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_ParseFile__doc__},
123
124 static PyObject *
125 pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
126 PyObject *file);
127
128 static PyObject *
129 pyexpat_xmlparser_ParseFile(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
130 {
131 PyObject *return_value = NULL;
132 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
133 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
134 #else
135 # define KWTUPLE NULL
136 #endif
137
138 static const char * const _keywords[] = {"", NULL};
139 static _PyArg_Parser _parser = {
140 .keywords = _keywords,
141 .fname = "ParseFile",
142 .kwtuple = KWTUPLE,
143 };
144 #undef KWTUPLE
145 PyObject *argsbuf[1];
146 PyObject *file;
147
148 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
149 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
150 if (!args) {
151 goto exit;
152 }
153 file = args[0];
154 return_value = pyexpat_xmlparser_ParseFile_impl((xmlparseobject *)self, cls, file);
155
156 exit:
157 return return_value;
158 }
159
160 PyDoc_STRVAR(pyexpat_xmlparser_SetBase__doc__,
161 "SetBase($self, base, /)\n"
162 "--\n"
163 "\n"
164 "Set the base URL for the parser.");
165
166 #define PYEXPAT_XMLPARSER_SETBASE_METHODDEF \
167 {"SetBase", (PyCFunction)pyexpat_xmlparser_SetBase, METH_O, pyexpat_xmlparser_SetBase__doc__},
168
169 static PyObject *
170 pyexpat_xmlparser_SetBase_impl(xmlparseobject *self, const char *base);
171
172 static PyObject *
173 pyexpat_xmlparser_SetBase(PyObject *self, PyObject *arg)
174 {
175 PyObject *return_value = NULL;
176 const char *base;
177
178 if (!PyUnicode_Check(arg)) {
179 _PyArg_BadArgument("SetBase", "argument", "str", arg);
180 goto exit;
181 }
182 Py_ssize_t base_length;
183 base = PyUnicode_AsUTF8AndSize(arg, &base_length);
184 if (base == NULL) {
185 goto exit;
186 }
187 if (strlen(base) != (size_t)base_length) {
188 PyErr_SetString(PyExc_ValueError, "embedded null character");
189 goto exit;
190 }
191 return_value = pyexpat_xmlparser_SetBase_impl((xmlparseobject *)self, base);
192
193 exit:
194 return return_value;
195 }
196
197 PyDoc_STRVAR(pyexpat_xmlparser_GetBase__doc__,
198 "GetBase($self, /)\n"
199 "--\n"
200 "\n"
201 "Return base URL string for the parser.");
202
203 #define PYEXPAT_XMLPARSER_GETBASE_METHODDEF \
204 {"GetBase", (PyCFunction)pyexpat_xmlparser_GetBase, METH_NOARGS, pyexpat_xmlparser_GetBase__doc__},
205
206 static PyObject *
207 pyexpat_xmlparser_GetBase_impl(xmlparseobject *self);
208
209 static PyObject *
210 pyexpat_xmlparser_GetBase(PyObject *self, PyObject *Py_UNUSED(ignored))
211 {
212 return pyexpat_xmlparser_GetBase_impl((xmlparseobject *)self);
213 }
214
215 PyDoc_STRVAR(pyexpat_xmlparser_GetInputContext__doc__,
216 "GetInputContext($self, /)\n"
217 "--\n"
218 "\n"
219 "Return the untranslated text of the input that caused the current event.\n"
220 "\n"
221 "If the event was generated by a large amount of text (such as\n"
222 "a start tag for an element with many attributes), not all of the\n"
223 "text may be available.");
224
225 #define PYEXPAT_XMLPARSER_GETINPUTCONTEXT_METHODDEF \
226 {"GetInputContext", (PyCFunction)pyexpat_xmlparser_GetInputContext, METH_NOARGS, pyexpat_xmlparser_GetInputContext__doc__},
227
228 static PyObject *
229 pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self);
230
231 static PyObject *
232 pyexpat_xmlparser_GetInputContext(PyObject *self, PyObject *Py_UNUSED(ignored))
233 {
234 return pyexpat_xmlparser_GetInputContext_impl((xmlparseobject *)self);
235 }
236
237 PyDoc_STRVAR(pyexpat_xmlparser_ExternalEntityParserCreate__doc__,
238 "ExternalEntityParserCreate($self, context, encoding=<unrepresentable>,\n"
239 " /)\n"
240 "--\n"
241 "\n"
242 "Create a parser for parsing an external entity based on the information passed to the ExternalEntityRefHandler.");
243
244 #define PYEXPAT_XMLPARSER_EXTERNALENTITYPARSERCREATE_METHODDEF \
245 {"ExternalEntityParserCreate", _PyCFunction_CAST(pyexpat_xmlparser_ExternalEntityParserCreate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_ExternalEntityParserCreate__doc__},
246
247 static PyObject *
248 pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self,
249 PyTypeObject *cls,
250 const char *context,
251 const char *encoding);
252
253 static PyObject *
254 pyexpat_xmlparser_ExternalEntityParserCreate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
255 {
256 PyObject *return_value = NULL;
257 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
258 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
259 #else
260 # define KWTUPLE NULL
261 #endif
262
263 static const char * const _keywords[] = {"", "", NULL};
264 static _PyArg_Parser _parser = {
265 .keywords = _keywords,
266 .fname = "ExternalEntityParserCreate",
267 .kwtuple = KWTUPLE,
268 };
269 #undef KWTUPLE
270 PyObject *argsbuf[2];
271 const char *context;
272 const char *encoding = NULL;
273
274 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
275 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
276 if (!args) {
277 goto exit;
278 }
279 if (args[0] == Py_None) {
280 context = NULL;
281 }
282 else if (PyUnicode_Check(args[0])) {
283 Py_ssize_t context_length;
284 context = PyUnicode_AsUTF8AndSize(args[0], &context_length);
285 if (context == NULL) {
286 goto exit;
287 }
288 if (strlen(context) != (size_t)context_length) {
289 PyErr_SetString(PyExc_ValueError, "embedded null character");
290 goto exit;
291 }
292 }
293 else {
294 _PyArg_BadArgument("ExternalEntityParserCreate", "argument 1", "str or None", args[0]);
295 goto exit;
296 }
297 if (nargs < 2) {
298 goto skip_optional_posonly;
299 }
300 if (!PyUnicode_Check(args[1])) {
301 _PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]);
302 goto exit;
303 }
304 Py_ssize_t encoding_length;
305 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
306 if (encoding == NULL) {
307 goto exit;
308 }
309 if (strlen(encoding) != (size_t)encoding_length) {
310 PyErr_SetString(PyExc_ValueError, "embedded null character");
311 goto exit;
312 }
313 skip_optional_posonly:
314 return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl((xmlparseobject *)self, cls, context, encoding);
315
316 exit:
317 return return_value;
318 }
319
320 PyDoc_STRVAR(pyexpat_xmlparser_SetParamEntityParsing__doc__,
321 "SetParamEntityParsing($self, flag, /)\n"
322 "--\n"
323 "\n"
324 "Controls parsing of parameter entities (including the external DTD subset).\n"
325 "\n"
326 "Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n"
327 "XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n"
328 "XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n"
329 "was successful.");
330
331 #define PYEXPAT_XMLPARSER_SETPARAMENTITYPARSING_METHODDEF \
332 {"SetParamEntityParsing", (PyCFunction)pyexpat_xmlparser_SetParamEntityParsing, METH_O, pyexpat_xmlparser_SetParamEntityParsing__doc__},
333
334 static PyObject *
335 pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag);
336
337 static PyObject *
338 pyexpat_xmlparser_SetParamEntityParsing(PyObject *self, PyObject *arg)
339 {
340 PyObject *return_value = NULL;
341 int flag;
342
343 flag = PyLong_AsInt(arg);
344 if (flag == -1 && PyErr_Occurred()) {
345 goto exit;
346 }
347 return_value = pyexpat_xmlparser_SetParamEntityParsing_impl((xmlparseobject *)self, flag);
348
349 exit:
350 return return_value;
351 }
352
353 #if (XML_COMBINED_VERSION >= 19505)
354
355 PyDoc_STRVAR(pyexpat_xmlparser_UseForeignDTD__doc__,
356 "UseForeignDTD($self, flag=True, /)\n"
357 "--\n"
358 "\n"
359 "Allows the application to provide an artificial external subset if one is not specified as part of the document instance.\n"
360 "\n"
361 "This readily allows the use of a \'default\' document type controlled\n"
362 "by the application, while still getting the advantage of providing\n"
363 "document type information to the parser. \'flag\' defaults to True if\n"
364 "not provided.");
365
366 #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF \
367 {"UseForeignDTD", _PyCFunction_CAST(pyexpat_xmlparser_UseForeignDTD), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_UseForeignDTD__doc__},
368
369 static PyObject *
370 pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, PyTypeObject *cls,
371 int flag);
372
373 static PyObject *
374 pyexpat_xmlparser_UseForeignDTD(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
375 {
376 PyObject *return_value = NULL;
377 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
378 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
379 #else
380 # define KWTUPLE NULL
381 #endif
382
383 static const char * const _keywords[] = {"", NULL};
384 static _PyArg_Parser _parser = {
385 .keywords = _keywords,
386 .fname = "UseForeignDTD",
387 .kwtuple = KWTUPLE,
388 };
389 #undef KWTUPLE
390 PyObject *argsbuf[1];
391 int flag = 1;
392
393 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
394 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
395 if (!args) {
396 goto exit;
397 }
398 if (nargs < 1) {
399 goto skip_optional_posonly;
400 }
401 flag = PyObject_IsTrue(args[0]);
402 if (flag < 0) {
403 goto exit;
404 }
405 skip_optional_posonly:
406 return_value = pyexpat_xmlparser_UseForeignDTD_impl((xmlparseobject *)self, cls, flag);
407
408 exit:
409 return return_value;
410 }
411
412 #endif /* (XML_COMBINED_VERSION >= 19505) */
413
414 #if (XML_COMBINED_VERSION >= 20400)
415
416 PyDoc_STRVAR(pyexpat_xmlparser_SetBillionLaughsAttackProtectionActivationThreshold__doc__,
417 "SetBillionLaughsAttackProtectionActivationThreshold($self, threshold, /)\n"
418 "--\n"
419 "\n"
420 "Sets the number of output bytes needed to activate protection against billion laughs attacks.\n"
421 "\n"
422 "The number of output bytes includes amplification from entity expansion\n"
423 "and reading DTD files.\n"
424 "\n"
425 "Parser objects usually have a protection activation threshold of 8 MiB,\n"
426 "but the actual default value depends on the underlying Expat library.\n"
427 "\n"
428 "Activation thresholds below 4 MiB are known to break support for DITA 1.3\n"
429 "payload and are hence not recommended.");
430
431 #define PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONACTIVATIONTHRESHOLD_METHODDEF \
432 {"SetBillionLaughsAttackProtectionActivationThreshold", _PyCFunction_CAST(pyexpat_xmlparser_SetBillionLaughsAttackProtectionActivationThreshold), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_SetBillionLaughsAttackProtectionActivationThreshold__doc__},
433
434 static PyObject *
435 pyexpat_xmlparser_SetBillionLaughsAttackProtectionActivationThreshold_impl(xmlparseobject *self,
436 PyTypeObject *cls,
437 unsigned long long threshold);
438
439 static PyObject *
440 pyexpat_xmlparser_SetBillionLaughsAttackProtectionActivationThreshold(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
441 {
442 PyObject *return_value = NULL;
443 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
444 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
445 #else
446 # define KWTUPLE NULL
447 #endif
448
449 static const char * const _keywords[] = {"", NULL};
450 static _PyArg_Parser _parser = {
451 .keywords = _keywords,
452 .fname = "SetBillionLaughsAttackProtectionActivationThreshold",
453 .kwtuple = KWTUPLE,
454 };
455 #undef KWTUPLE
456 PyObject *argsbuf[1];
457 unsigned long long threshold;
458
459 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
460 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
461 if (!args) {
462 goto exit;
463 }
464 if (!_PyLong_UnsignedLongLong_Converter(args[0], &threshold)) {
465 goto exit;
466 }
467 return_value = pyexpat_xmlparser_SetBillionLaughsAttackProtectionActivationThreshold_impl((xmlparseobject *)self, cls, threshold);
468
469 exit:
470 return return_value;
471 }
472
473 #endif /* (XML_COMBINED_VERSION >= 20400) */
474
475 #if (XML_COMBINED_VERSION >= 20400)
476
477 PyDoc_STRVAR(pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification__doc__,
478 "SetBillionLaughsAttackProtectionMaximumAmplification($self, max_factor,\n"
479 " /)\n"
480 "--\n"
481 "\n"
482 "Sets the maximum tolerated amplification factor for protection against billion laughs attacks.\n"
483 "\n"
484 "The amplification factor is calculated as \"(direct + indirect) / direct\"\n"
485 "while parsing, where \"direct\" is the number of bytes read from the primary\n"
486 "document in parsing and \"indirect\" is the number of bytes added by expanding\n"
487 "entities and reading external DTD files, combined.\n"
488 "\n"
489 "The \'max_factor\' value must be a non-NaN floating point value greater than\n"
490 "or equal to 1.0. Amplification factors greater than 30,000 can be observed\n"
491 "in the middle of parsing even with benign files in practice. In particular,\n"
492 "the activation threshold should be carefully chosen to avoid false positives.\n"
493 "\n"
494 "Parser objects usually have a maximum amplification factor of 100,\n"
495 "but the actual default value depends on the underlying Expat library.");
496
497 #define PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONMAXIMUMAMPLIFICATION_METHODDEF \
498 {"SetBillionLaughsAttackProtectionMaximumAmplification", _PyCFunction_CAST(pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification__doc__},
499
500 static PyObject *
501 pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification_impl(xmlparseobject *self,
502 PyTypeObject *cls,
503 float max_factor);
504
505 static PyObject *
506 pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
507 {
508 PyObject *return_value = NULL;
509 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
510 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
511 #else
512 # define KWTUPLE NULL
513 #endif
514
515 static const char * const _keywords[] = {"", NULL};
516 static _PyArg_Parser _parser = {
517 .keywords = _keywords,
518 .fname = "SetBillionLaughsAttackProtectionMaximumAmplification",
519 .kwtuple = KWTUPLE,
520 };
521 #undef KWTUPLE
522 PyObject *argsbuf[1];
523 float max_factor;
524
525 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
526 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
527 if (!args) {
528 goto exit;
529 }
530 if (PyFloat_CheckExact(args[0])) {
531 max_factor = (float) (PyFloat_AS_DOUBLE(args[0]));
532 }
533 else
534 {
535 max_factor = (float) PyFloat_AsDouble(args[0]);
536 if (max_factor == -1.0 && PyErr_Occurred()) {
537 goto exit;
538 }
539 }
540 return_value = pyexpat_xmlparser_SetBillionLaughsAttackProtectionMaximumAmplification_impl((xmlparseobject *)self, cls, max_factor);
541
542 exit:
543 return return_value;
544 }
545
546 #endif /* (XML_COMBINED_VERSION >= 20400) */
547
548 #if (XML_COMBINED_VERSION >= 20702)
549
550 PyDoc_STRVAR(pyexpat_xmlparser_SetAllocTrackerActivationThreshold__doc__,
551 "SetAllocTrackerActivationThreshold($self, threshold, /)\n"
552 "--\n"
553 "\n"
554 "Sets the number of allocated bytes of dynamic memory needed to activate protection against disproportionate use of RAM.\n"
555 "\n"
556 "Parser objects usually have an allocation activation threshold of 64 MiB,\n"
557 "but the actual default value depends on the underlying Expat library.");
558
559 #define PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF \
560 {"SetAllocTrackerActivationThreshold", _PyCFunction_CAST(pyexpat_xmlparser_SetAllocTrackerActivationThreshold), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_SetAllocTrackerActivationThreshold__doc__},
561
562 static PyObject *
563 pyexpat_xmlparser_SetAllocTrackerActivationThreshold_impl(xmlparseobject *self,
564 PyTypeObject *cls,
565 unsigned long long threshold);
566
567 static PyObject *
568 pyexpat_xmlparser_SetAllocTrackerActivationThreshold(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
569 {
570 PyObject *return_value = NULL;
571 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
572 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
573 #else
574 # define KWTUPLE NULL
575 #endif
576
577 static const char * const _keywords[] = {"", NULL};
578 static _PyArg_Parser _parser = {
579 .keywords = _keywords,
580 .fname = "SetAllocTrackerActivationThreshold",
581 .kwtuple = KWTUPLE,
582 };
583 #undef KWTUPLE
584 PyObject *argsbuf[1];
585 unsigned long long threshold;
586
587 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
588 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
589 if (!args) {
590 goto exit;
591 }
592 if (!_PyLong_UnsignedLongLong_Converter(args[0], &threshold)) {
593 goto exit;
594 }
595 return_value = pyexpat_xmlparser_SetAllocTrackerActivationThreshold_impl((xmlparseobject *)self, cls, threshold);
596
597 exit:
598 return return_value;
599 }
600
601 #endif /* (XML_COMBINED_VERSION >= 20702) */
602
603 #if (XML_COMBINED_VERSION >= 20702)
604
605 PyDoc_STRVAR(pyexpat_xmlparser_SetAllocTrackerMaximumAmplification__doc__,
606 "SetAllocTrackerMaximumAmplification($self, max_factor, /)\n"
607 "--\n"
608 "\n"
609 "Sets the maximum amplification factor between direct input and bytes of dynamic memory allocated.\n"
610 "\n"
611 "The amplification factor is calculated as \"allocated / direct\" while\n"
612 "parsing, where \"direct\" is the number of bytes read from the primary\n"
613 "document in parsing and \"allocated\" is the number of bytes of\n"
614 "dynamic memory allocated in the parser hierarchy.\n"
615 "\n"
616 "The \'max_factor\' value must be a non-NaN floating point value\n"
617 "greater than or equal to 1.0. Amplification factors greater than\n"
618 "100.0 can be observed near the start of parsing even with benign\n"
619 "files in practice. In particular, the activation threshold should\n"
620 "be carefully chosen to avoid false positives.\n"
621 "\n"
622 "Parser objects usually have a maximum amplification factor of 100,\n"
623 "but the actual default value depends on the underlying Expat library.");
624
625 #define PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF \
626 {"SetAllocTrackerMaximumAmplification", _PyCFunction_CAST(pyexpat_xmlparser_SetAllocTrackerMaximumAmplification), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_SetAllocTrackerMaximumAmplification__doc__},
627
628 static PyObject *
629 pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl(xmlparseobject *self,
630 PyTypeObject *cls,
631 float max_factor);
632
633 static PyObject *
634 pyexpat_xmlparser_SetAllocTrackerMaximumAmplification(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
635 {
636 PyObject *return_value = NULL;
637 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
638 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
639 #else
640 # define KWTUPLE NULL
641 #endif
642
643 static const char * const _keywords[] = {"", NULL};
644 static _PyArg_Parser _parser = {
645 .keywords = _keywords,
646 .fname = "SetAllocTrackerMaximumAmplification",
647 .kwtuple = KWTUPLE,
648 };
649 #undef KWTUPLE
650 PyObject *argsbuf[1];
651 float max_factor;
652
653 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
654 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
655 if (!args) {
656 goto exit;
657 }
658 if (PyFloat_CheckExact(args[0])) {
659 max_factor = (float) (PyFloat_AS_DOUBLE(args[0]));
660 }
661 else
662 {
663 max_factor = (float) PyFloat_AsDouble(args[0]);
664 if (max_factor == -1.0 && PyErr_Occurred()) {
665 goto exit;
666 }
667 }
668 return_value = pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl((xmlparseobject *)self, cls, max_factor);
669
670 exit:
671 return return_value;
672 }
673
674 #endif /* (XML_COMBINED_VERSION >= 20702) */
675
676 PyDoc_STRVAR(pyexpat_ParserCreate__doc__,
677 "ParserCreate($module, /, encoding=None, namespace_separator=None,\n"
678 " intern=<unrepresentable>)\n"
679 "--\n"
680 "\n"
681 "Return a new XML parser object.");
682
683 #define PYEXPAT_PARSERCREATE_METHODDEF \
684 {"ParserCreate", _PyCFunction_CAST(pyexpat_ParserCreate), METH_FASTCALL|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
685
686 static PyObject *
687 pyexpat_ParserCreate_impl(PyObject *module, const char *encoding,
688 const char *namespace_separator, PyObject *intern);
689
690 static PyObject *
691 pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
692 {
693 PyObject *return_value = NULL;
694 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
695
696 #define NUM_KEYWORDS 3
697 static struct {
698 PyGC_Head _this_is_not_used;
699 PyObject_VAR_HEAD
700 Py_hash_t ob_hash;
701 PyObject *ob_item[NUM_KEYWORDS];
702 } _kwtuple = {
703 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
704 .ob_hash = -1,
705 .ob_item = { &_Py_ID(encoding), &_Py_ID(namespace_separator), &_Py_ID(intern), },
706 };
707 #undef NUM_KEYWORDS
708 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
709
710 #else // !Py_BUILD_CORE
711 # define KWTUPLE NULL
712 #endif // !Py_BUILD_CORE
713
714 static const char * const _keywords[] = {"encoding", "namespace_separator", "intern", NULL};
715 static _PyArg_Parser _parser = {
716 .keywords = _keywords,
717 .fname = "ParserCreate",
718 .kwtuple = KWTUPLE,
719 };
720 #undef KWTUPLE
721 PyObject *argsbuf[3];
722 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
723 const char *encoding = NULL;
724 const char *namespace_separator = NULL;
725 PyObject *intern = NULL;
726
727 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
728 /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
729 if (!args) {
730 goto exit;
731 }
732 if (!noptargs) {
733 goto skip_optional_pos;
734 }
735 if (args[0]) {
736 if (args[0] == Py_None) {
737 encoding = NULL;
738 }
739 else if (PyUnicode_Check(args[0])) {
740 Py_ssize_t encoding_length;
741 encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
742 if (encoding == NULL) {
743 goto exit;
744 }
745 if (strlen(encoding) != (size_t)encoding_length) {
746 PyErr_SetString(PyExc_ValueError, "embedded null character");
747 goto exit;
748 }
749 }
750 else {
751 _PyArg_BadArgument("ParserCreate", "argument 'encoding'", "str or None", args[0]);
752 goto exit;
753 }
754 if (!--noptargs) {
755 goto skip_optional_pos;
756 }
757 }
758 if (args[1]) {
759 if (args[1] == Py_None) {
760 namespace_separator = NULL;
761 }
762 else if (PyUnicode_Check(args[1])) {
763 Py_ssize_t namespace_separator_length;
764 namespace_separator = PyUnicode_AsUTF8AndSize(args[1], &namespace_separator_length);
765 if (namespace_separator == NULL) {
766 goto exit;
767 }
768 if (strlen(namespace_separator) != (size_t)namespace_separator_length) {
769 PyErr_SetString(PyExc_ValueError, "embedded null character");
770 goto exit;
771 }
772 }
773 else {
774 _PyArg_BadArgument("ParserCreate", "argument 'namespace_separator'", "str or None", args[1]);
775 goto exit;
776 }
777 if (!--noptargs) {
778 goto skip_optional_pos;
779 }
780 }
781 intern = args[2];
782 skip_optional_pos:
783 return_value = pyexpat_ParserCreate_impl(module, encoding, namespace_separator, intern);
784
785 exit:
786 return return_value;
787 }
788
789 PyDoc_STRVAR(pyexpat_ErrorString__doc__,
790 "ErrorString($module, code, /)\n"
791 "--\n"
792 "\n"
793 "Returns string error for given number.");
794
795 #define PYEXPAT_ERRORSTRING_METHODDEF \
796 {"ErrorString", (PyCFunction)pyexpat_ErrorString, METH_O, pyexpat_ErrorString__doc__},
797
798 static PyObject *
799 pyexpat_ErrorString_impl(PyObject *module, long code);
800
801 static PyObject *
802 pyexpat_ErrorString(PyObject *module, PyObject *arg)
803 {
804 PyObject *return_value = NULL;
805 long code;
806
807 code = PyLong_AsLong(arg);
808 if (code == -1 && PyErr_Occurred()) {
809 goto exit;
810 }
811 return_value = pyexpat_ErrorString_impl(module, code);
812
813 exit:
814 return return_value;
815 }
816
817 #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
818 #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
819 #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */
820
821 #ifndef PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONACTIVATIONTHRESHOLD_METHODDEF
822 #define PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONACTIVATIONTHRESHOLD_METHODDEF
823 #endif /* !defined(PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONACTIVATIONTHRESHOLD_METHODDEF) */
824
825 #ifndef PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONMAXIMUMAMPLIFICATION_METHODDEF
826 #define PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONMAXIMUMAMPLIFICATION_METHODDEF
827 #endif /* !defined(PYEXPAT_XMLPARSER_SETBILLIONLAUGHSATTACKPROTECTIONMAXIMUMAMPLIFICATION_METHODDEF) */
828
829 #ifndef PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF
830 #define PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF
831 #endif /* !defined(PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF) */
832
833 #ifndef PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF
834 #define PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF
835 #endif /* !defined(PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF) */
836 /*[clinic end generated code: output=b03765d16720ab5e input=a9049054013a1b77]*/