| 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 a start tag\n" |
| 222 |
"for an element with many attributes), not all of the text may be available."); |
| 223 |
|
| 224 |
#define PYEXPAT_XMLPARSER_GETINPUTCONTEXT_METHODDEF \ |
| 225 |
{"GetInputContext", (PyCFunction)pyexpat_xmlparser_GetInputContext, METH_NOARGS, pyexpat_xmlparser_GetInputContext__doc__}, |
| 226 |
|
| 227 |
static PyObject * |
| 228 |
pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self); |
| 229 |
|
| 230 |
static PyObject * |
| 231 |
pyexpat_xmlparser_GetInputContext(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 232 |
{ |
| 233 |
return pyexpat_xmlparser_GetInputContext_impl((xmlparseobject *)self); |
| 234 |
} |
| 235 |
|
| 236 |
PyDoc_STRVAR(pyexpat_xmlparser_ExternalEntityParserCreate__doc__, |
| 237 |
"ExternalEntityParserCreate($self, context, encoding=<unrepresentable>,\n" |
| 238 |
" /)\n" |
| 239 |
"--\n" |
| 240 |
"\n" |
| 241 |
"Create a parser for parsing an external entity based on the information passed to the ExternalEntityRefHandler."); |
| 242 |
|
| 243 |
#define PYEXPAT_XMLPARSER_EXTERNALENTITYPARSERCREATE_METHODDEF \ |
| 244 |
{"ExternalEntityParserCreate", _PyCFunction_CAST(pyexpat_xmlparser_ExternalEntityParserCreate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_ExternalEntityParserCreate__doc__}, |
| 245 |
|
| 246 |
static PyObject * |
| 247 |
pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self, |
| 248 |
PyTypeObject *cls, |
| 249 |
const char *context, |
| 250 |
const char *encoding); |
| 251 |
|
| 252 |
static PyObject * |
| 253 |
pyexpat_xmlparser_ExternalEntityParserCreate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 254 |
{ |
| 255 |
PyObject *return_value = NULL; |
| 256 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 257 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 258 |
#else |
| 259 |
# define KWTUPLE NULL |
| 260 |
#endif |
| 261 |
|
| 262 |
static const char * const _keywords[] = {"", "", NULL}; |
| 263 |
static _PyArg_Parser _parser = { |
| 264 |
.keywords = _keywords, |
| 265 |
.fname = "ExternalEntityParserCreate", |
| 266 |
.kwtuple = KWTUPLE, |
| 267 |
}; |
| 268 |
#undef KWTUPLE |
| 269 |
PyObject *argsbuf[2]; |
| 270 |
const char *context; |
| 271 |
const char *encoding = NULL; |
| 272 |
|
| 273 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 274 |
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 275 |
if (!args) { |
| 276 |
goto exit; |
| 277 |
} |
| 278 |
if (args[0] == Py_None) { |
| 279 |
context = NULL; |
| 280 |
} |
| 281 |
else if (PyUnicode_Check(args[0])) { |
| 282 |
Py_ssize_t context_length; |
| 283 |
context = PyUnicode_AsUTF8AndSize(args[0], &context_length); |
| 284 |
if (context == NULL) { |
| 285 |
goto exit; |
| 286 |
} |
| 287 |
if (strlen(context) != (size_t)context_length) { |
| 288 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 289 |
goto exit; |
| 290 |
} |
| 291 |
} |
| 292 |
else { |
| 293 |
_PyArg_BadArgument("ExternalEntityParserCreate", "argument 1", "str or None", args[0]); |
| 294 |
goto exit; |
| 295 |
} |
| 296 |
if (nargs < 2) { |
| 297 |
goto skip_optional_posonly; |
| 298 |
} |
| 299 |
if (!PyUnicode_Check(args[1])) { |
| 300 |
_PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]); |
| 301 |
goto exit; |
| 302 |
} |
| 303 |
Py_ssize_t encoding_length; |
| 304 |
encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); |
| 305 |
if (encoding == NULL) { |
| 306 |
goto exit; |
| 307 |
} |
| 308 |
if (strlen(encoding) != (size_t)encoding_length) { |
| 309 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 310 |
goto exit; |
| 311 |
} |
| 312 |
skip_optional_posonly: |
| 313 |
return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl((xmlparseobject *)self, cls, context, encoding); |
| 314 |
|
| 315 |
exit: |
| 316 |
return return_value; |
| 317 |
} |
| 318 |
|
| 319 |
PyDoc_STRVAR(pyexpat_xmlparser_SetParamEntityParsing__doc__, |
| 320 |
"SetParamEntityParsing($self, flag, /)\n" |
| 321 |
"--\n" |
| 322 |
"\n" |
| 323 |
"Controls parsing of parameter entities (including the external DTD subset).\n" |
| 324 |
"\n" |
| 325 |
"Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n" |
| 326 |
"XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n" |
| 327 |
"XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n" |
| 328 |
"was successful."); |
| 329 |
|
| 330 |
#define PYEXPAT_XMLPARSER_SETPARAMENTITYPARSING_METHODDEF \ |
| 331 |
{"SetParamEntityParsing", (PyCFunction)pyexpat_xmlparser_SetParamEntityParsing, METH_O, pyexpat_xmlparser_SetParamEntityParsing__doc__}, |
| 332 |
|
| 333 |
static PyObject * |
| 334 |
pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag); |
| 335 |
|
| 336 |
static PyObject * |
| 337 |
pyexpat_xmlparser_SetParamEntityParsing(PyObject *self, PyObject *arg) |
| 338 |
{ |
| 339 |
PyObject *return_value = NULL; |
| 340 |
int flag; |
| 341 |
|
| 342 |
flag = PyLong_AsInt(arg); |
| 343 |
if (flag == -1 && PyErr_Occurred()) { |
| 344 |
goto exit; |
| 345 |
} |
| 346 |
return_value = pyexpat_xmlparser_SetParamEntityParsing_impl((xmlparseobject *)self, flag); |
| 347 |
|
| 348 |
exit: |
| 349 |
return return_value; |
| 350 |
} |
| 351 |
|
| 352 |
#if (XML_COMBINED_VERSION >= 19505) |
| 353 |
|
| 354 |
PyDoc_STRVAR(pyexpat_xmlparser_UseForeignDTD__doc__, |
| 355 |
"UseForeignDTD($self, flag=True, /)\n" |
| 356 |
"--\n" |
| 357 |
"\n" |
| 358 |
"Allows the application to provide an artificial external subset if one is not specified as part of the document instance.\n" |
| 359 |
"\n" |
| 360 |
"This readily allows the use of a \'default\' document type controlled by the\n" |
| 361 |
"application, while still getting the advantage of providing document type\n" |
| 362 |
"information to the parser. \'flag\' defaults to True if not provided."); |
| 363 |
|
| 364 |
#define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF \ |
| 365 |
{"UseForeignDTD", _PyCFunction_CAST(pyexpat_xmlparser_UseForeignDTD), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_UseForeignDTD__doc__}, |
| 366 |
|
| 367 |
static PyObject * |
| 368 |
pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, PyTypeObject *cls, |
| 369 |
int flag); |
| 370 |
|
| 371 |
static PyObject * |
| 372 |
pyexpat_xmlparser_UseForeignDTD(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 373 |
{ |
| 374 |
PyObject *return_value = NULL; |
| 375 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 376 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 377 |
#else |
| 378 |
# define KWTUPLE NULL |
| 379 |
#endif |
| 380 |
|
| 381 |
static const char * const _keywords[] = {"", NULL}; |
| 382 |
static _PyArg_Parser _parser = { |
| 383 |
.keywords = _keywords, |
| 384 |
.fname = "UseForeignDTD", |
| 385 |
.kwtuple = KWTUPLE, |
| 386 |
}; |
| 387 |
#undef KWTUPLE |
| 388 |
PyObject *argsbuf[1]; |
| 389 |
int flag = 1; |
| 390 |
|
| 391 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 392 |
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 393 |
if (!args) { |
| 394 |
goto exit; |
| 395 |
} |
| 396 |
if (nargs < 1) { |
| 397 |
goto skip_optional_posonly; |
| 398 |
} |
| 399 |
flag = PyObject_IsTrue(args[0]); |
| 400 |
if (flag < 0) { |
| 401 |
goto exit; |
| 402 |
} |
| 403 |
skip_optional_posonly: |
| 404 |
return_value = pyexpat_xmlparser_UseForeignDTD_impl((xmlparseobject *)self, cls, flag); |
| 405 |
|
| 406 |
exit: |
| 407 |
return return_value; |
| 408 |
} |
| 409 |
|
| 410 |
#endif /* (XML_COMBINED_VERSION >= 19505) */ |
| 411 |
|
| 412 |
#if (XML_COMBINED_VERSION >= 20702) |
| 413 |
|
| 414 |
PyDoc_STRVAR(pyexpat_xmlparser_SetAllocTrackerActivationThreshold__doc__, |
| 415 |
"SetAllocTrackerActivationThreshold($self, threshold, /)\n" |
| 416 |
"--\n" |
| 417 |
"\n" |
| 418 |
"Sets the number of allocated bytes of dynamic memory needed to activate protection against disproportionate use of RAM.\n" |
| 419 |
"\n" |
| 420 |
"By default, parser objects have an allocation activation threshold of 64 MiB."); |
| 421 |
|
| 422 |
#define PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF \ |
| 423 |
{"SetAllocTrackerActivationThreshold", _PyCFunction_CAST(pyexpat_xmlparser_SetAllocTrackerActivationThreshold), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_SetAllocTrackerActivationThreshold__doc__}, |
| 424 |
|
| 425 |
static PyObject * |
| 426 |
pyexpat_xmlparser_SetAllocTrackerActivationThreshold_impl(xmlparseobject *self, |
| 427 |
PyTypeObject *cls, |
| 428 |
unsigned long long threshold); |
| 429 |
|
| 430 |
static PyObject * |
| 431 |
pyexpat_xmlparser_SetAllocTrackerActivationThreshold(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 432 |
{ |
| 433 |
PyObject *return_value = NULL; |
| 434 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 435 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 436 |
#else |
| 437 |
# define KWTUPLE NULL |
| 438 |
#endif |
| 439 |
|
| 440 |
static const char * const _keywords[] = {"", NULL}; |
| 441 |
static _PyArg_Parser _parser = { |
| 442 |
.keywords = _keywords, |
| 443 |
.fname = "SetAllocTrackerActivationThreshold", |
| 444 |
.kwtuple = KWTUPLE, |
| 445 |
}; |
| 446 |
#undef KWTUPLE |
| 447 |
PyObject *argsbuf[1]; |
| 448 |
unsigned long long threshold; |
| 449 |
|
| 450 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 451 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 452 |
if (!args) { |
| 453 |
goto exit; |
| 454 |
} |
| 455 |
if (!_PyLong_UnsignedLongLong_Converter(args[0], &threshold)) { |
| 456 |
goto exit; |
| 457 |
} |
| 458 |
return_value = pyexpat_xmlparser_SetAllocTrackerActivationThreshold_impl((xmlparseobject *)self, cls, threshold); |
| 459 |
|
| 460 |
exit: |
| 461 |
return return_value; |
| 462 |
} |
| 463 |
|
| 464 |
#endif /* (XML_COMBINED_VERSION >= 20702) */ |
| 465 |
|
| 466 |
#if (XML_COMBINED_VERSION >= 20702) |
| 467 |
|
| 468 |
PyDoc_STRVAR(pyexpat_xmlparser_SetAllocTrackerMaximumAmplification__doc__, |
| 469 |
"SetAllocTrackerMaximumAmplification($self, max_factor, /)\n" |
| 470 |
"--\n" |
| 471 |
"\n" |
| 472 |
"Sets the maximum amplification factor between direct input and bytes of dynamic memory allocated.\n" |
| 473 |
"\n" |
| 474 |
"The amplification factor is calculated as \"allocated / direct\" while parsing,\n" |
| 475 |
"where \"direct\" is the number of bytes read from the primary document in parsing\n" |
| 476 |
"and \"allocated\" is the number of bytes of dynamic memory allocated in the parser\n" |
| 477 |
"hierarchy.\n" |
| 478 |
"\n" |
| 479 |
"The \'max_factor\' value must be a non-NaN floating point value greater than\n" |
| 480 |
"or equal to 1.0. Amplification factors greater than 100.0 can be observed\n" |
| 481 |
"near the start of parsing even with benign files in practice. In particular,\n" |
| 482 |
"the activation threshold should be carefully chosen to avoid false positives.\n" |
| 483 |
"\n" |
| 484 |
"By default, parser objects have a maximum amplification factor of 100.0."); |
| 485 |
|
| 486 |
#define PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF \ |
| 487 |
{"SetAllocTrackerMaximumAmplification", _PyCFunction_CAST(pyexpat_xmlparser_SetAllocTrackerMaximumAmplification), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pyexpat_xmlparser_SetAllocTrackerMaximumAmplification__doc__}, |
| 488 |
|
| 489 |
static PyObject * |
| 490 |
pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl(xmlparseobject *self, |
| 491 |
PyTypeObject *cls, |
| 492 |
float max_factor); |
| 493 |
|
| 494 |
static PyObject * |
| 495 |
pyexpat_xmlparser_SetAllocTrackerMaximumAmplification(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 496 |
{ |
| 497 |
PyObject *return_value = NULL; |
| 498 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 499 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 500 |
#else |
| 501 |
# define KWTUPLE NULL |
| 502 |
#endif |
| 503 |
|
| 504 |
static const char * const _keywords[] = {"", NULL}; |
| 505 |
static _PyArg_Parser _parser = { |
| 506 |
.keywords = _keywords, |
| 507 |
.fname = "SetAllocTrackerMaximumAmplification", |
| 508 |
.kwtuple = KWTUPLE, |
| 509 |
}; |
| 510 |
#undef KWTUPLE |
| 511 |
PyObject *argsbuf[1]; |
| 512 |
float max_factor; |
| 513 |
|
| 514 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 515 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 516 |
if (!args) { |
| 517 |
goto exit; |
| 518 |
} |
| 519 |
if (PyFloat_CheckExact(args[0])) { |
| 520 |
max_factor = (float) (PyFloat_AS_DOUBLE(args[0])); |
| 521 |
} |
| 522 |
else |
| 523 |
{ |
| 524 |
max_factor = (float) PyFloat_AsDouble(args[0]); |
| 525 |
if (max_factor == -1.0 && PyErr_Occurred()) { |
| 526 |
goto exit; |
| 527 |
} |
| 528 |
} |
| 529 |
return_value = pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl((xmlparseobject *)self, cls, max_factor); |
| 530 |
|
| 531 |
exit: |
| 532 |
return return_value; |
| 533 |
} |
| 534 |
|
| 535 |
#endif /* (XML_COMBINED_VERSION >= 20702) */ |
| 536 |
|
| 537 |
PyDoc_STRVAR(pyexpat_ParserCreate__doc__, |
| 538 |
"ParserCreate($module, /, encoding=None, namespace_separator=None,\n" |
| 539 |
" intern=<unrepresentable>)\n" |
| 540 |
"--\n" |
| 541 |
"\n" |
| 542 |
"Return a new XML parser object."); |
| 543 |
|
| 544 |
#define PYEXPAT_PARSERCREATE_METHODDEF \ |
| 545 |
{"ParserCreate", _PyCFunction_CAST(pyexpat_ParserCreate), METH_FASTCALL|METH_KEYWORDS, pyexpat_ParserCreate__doc__}, |
| 546 |
|
| 547 |
static PyObject * |
| 548 |
pyexpat_ParserCreate_impl(PyObject *module, const char *encoding, |
| 549 |
const char *namespace_separator, PyObject *intern); |
| 550 |
|
| 551 |
static PyObject * |
| 552 |
pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 553 |
{ |
| 554 |
PyObject *return_value = NULL; |
| 555 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 556 |
|
| 557 |
#define NUM_KEYWORDS 3 |
| 558 |
static struct { |
| 559 |
PyGC_Head _this_is_not_used; |
| 560 |
PyObject_VAR_HEAD |
| 561 |
Py_hash_t ob_hash; |
| 562 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 563 |
} _kwtuple = { |
| 564 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 565 |
.ob_hash = -1, |
| 566 |
.ob_item = { &_Py_ID(encoding), &_Py_ID(namespace_separator), &_Py_ID(intern), }, |
| 567 |
}; |
| 568 |
#undef NUM_KEYWORDS |
| 569 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 570 |
|
| 571 |
#else // !Py_BUILD_CORE |
| 572 |
# define KWTUPLE NULL |
| 573 |
#endif // !Py_BUILD_CORE |
| 574 |
|
| 575 |
static const char * const _keywords[] = {"encoding", "namespace_separator", "intern", NULL}; |
| 576 |
static _PyArg_Parser _parser = { |
| 577 |
.keywords = _keywords, |
| 578 |
.fname = "ParserCreate", |
| 579 |
.kwtuple = KWTUPLE, |
| 580 |
}; |
| 581 |
#undef KWTUPLE |
| 582 |
PyObject *argsbuf[3]; |
| 583 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 584 |
const char *encoding = NULL; |
| 585 |
const char *namespace_separator = NULL; |
| 586 |
PyObject *intern = NULL; |
| 587 |
|
| 588 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 589 |
/*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 590 |
if (!args) { |
| 591 |
goto exit; |
| 592 |
} |
| 593 |
if (!noptargs) { |
| 594 |
goto skip_optional_pos; |
| 595 |
} |
| 596 |
if (args[0]) { |
| 597 |
if (args[0] == Py_None) { |
| 598 |
encoding = NULL; |
| 599 |
} |
| 600 |
else if (PyUnicode_Check(args[0])) { |
| 601 |
Py_ssize_t encoding_length; |
| 602 |
encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); |
| 603 |
if (encoding == NULL) { |
| 604 |
goto exit; |
| 605 |
} |
| 606 |
if (strlen(encoding) != (size_t)encoding_length) { |
| 607 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 608 |
goto exit; |
| 609 |
} |
| 610 |
} |
| 611 |
else { |
| 612 |
_PyArg_BadArgument("ParserCreate", "argument 'encoding'", "str or None", args[0]); |
| 613 |
goto exit; |
| 614 |
} |
| 615 |
if (!--noptargs) { |
| 616 |
goto skip_optional_pos; |
| 617 |
} |
| 618 |
} |
| 619 |
if (args[1]) { |
| 620 |
if (args[1] == Py_None) { |
| 621 |
namespace_separator = NULL; |
| 622 |
} |
| 623 |
else if (PyUnicode_Check(args[1])) { |
| 624 |
Py_ssize_t namespace_separator_length; |
| 625 |
namespace_separator = PyUnicode_AsUTF8AndSize(args[1], &namespace_separator_length); |
| 626 |
if (namespace_separator == NULL) { |
| 627 |
goto exit; |
| 628 |
} |
| 629 |
if (strlen(namespace_separator) != (size_t)namespace_separator_length) { |
| 630 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 631 |
goto exit; |
| 632 |
} |
| 633 |
} |
| 634 |
else { |
| 635 |
_PyArg_BadArgument("ParserCreate", "argument 'namespace_separator'", "str or None", args[1]); |
| 636 |
goto exit; |
| 637 |
} |
| 638 |
if (!--noptargs) { |
| 639 |
goto skip_optional_pos; |
| 640 |
} |
| 641 |
} |
| 642 |
intern = args[2]; |
| 643 |
skip_optional_pos: |
| 644 |
return_value = pyexpat_ParserCreate_impl(module, encoding, namespace_separator, intern); |
| 645 |
|
| 646 |
exit: |
| 647 |
return return_value; |
| 648 |
} |
| 649 |
|
| 650 |
PyDoc_STRVAR(pyexpat_ErrorString__doc__, |
| 651 |
"ErrorString($module, code, /)\n" |
| 652 |
"--\n" |
| 653 |
"\n" |
| 654 |
"Returns string error for given number."); |
| 655 |
|
| 656 |
#define PYEXPAT_ERRORSTRING_METHODDEF \ |
| 657 |
{"ErrorString", (PyCFunction)pyexpat_ErrorString, METH_O, pyexpat_ErrorString__doc__}, |
| 658 |
|
| 659 |
static PyObject * |
| 660 |
pyexpat_ErrorString_impl(PyObject *module, long code); |
| 661 |
|
| 662 |
static PyObject * |
| 663 |
pyexpat_ErrorString(PyObject *module, PyObject *arg) |
| 664 |
{ |
| 665 |
PyObject *return_value = NULL; |
| 666 |
long code; |
| 667 |
|
| 668 |
code = PyLong_AsLong(arg); |
| 669 |
if (code == -1 && PyErr_Occurred()) { |
| 670 |
goto exit; |
| 671 |
} |
| 672 |
return_value = pyexpat_ErrorString_impl(module, code); |
| 673 |
|
| 674 |
exit: |
| 675 |
return return_value; |
| 676 |
} |
| 677 |
|
| 678 |
#ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF |
| 679 |
#define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF |
| 680 |
#endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ |
| 681 |
|
| 682 |
#ifndef PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF |
| 683 |
#define PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF |
| 684 |
#endif /* !defined(PYEXPAT_XMLPARSER_SETALLOCTRACKERACTIVATIONTHRESHOLD_METHODDEF) */ |
| 685 |
|
| 686 |
#ifndef PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF |
| 687 |
#define PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF |
| 688 |
#endif /* !defined(PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF) */ |
| 689 |
/*[clinic end generated code: output=e73935658c04c83e input=a9049054013a1b77]*/ |