Skip to content

Commit b01e53d

Browse files
committed
raise NotImplementedError for unavailable mitigation APIs
1 parent 64af05c commit b01e53d

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

Modules/clinic/pyexpat.c.h

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/pyexpat.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,6 @@ pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, PyTypeObject *cls,
11821182
}
11831183
#endif
11841184

1185-
#if XML_COMBINED_VERSION >= 20702
11861185
/*[clinic input]
11871186
@permit_long_summary
11881187
@permit_long_docstring_body
@@ -1213,6 +1212,7 @@ pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl(xmlparseobject *self,
12131212
float max_factor)
12141213
/*[clinic end generated code: output=6e44bd48c9b112a0 input=23ca8b8f7de04462]*/
12151214
{
1215+
#if XML_COMBINED_VERSION >= 20702
12161216
assert(self->itself != NULL);
12171217
if (XML_SetAllocTrackerMaximumAmplification(self->itself, max_factor) == XML_TRUE) {
12181218
Py_RETURN_NONE;
@@ -1231,6 +1231,12 @@ pyexpat_xmlparser_SetAllocTrackerMaximumAmplification_impl(xmlparseobject *self,
12311231
? "'max_factor' must be at least 1.0"
12321232
: "parser must be a root parser";
12331233
return set_invalid_arg(state, self, message);
1234+
#else
1235+
PyErr_SetString(PyExc_NotImplementedError,
1236+
"SetAllocTrackerMaximumAmplification() requires "
1237+
"Expat 2.7.2 or later");
1238+
return NULL;
1239+
#endif
12341240
}
12351241

12361242
/*[clinic input]
@@ -1253,6 +1259,7 @@ pyexpat_xmlparser_SetAllocTrackerActivationThreshold_impl(xmlparseobject *self,
12531259
unsigned long long threshold)
12541260
/*[clinic end generated code: output=bed7e93207ba08c5 input=8453509a137a47c0]*/
12551261
{
1262+
#if XML_COMBINED_VERSION >= 20702
12561263
assert(self->itself != NULL);
12571264
if (XML_SetAllocTrackerActivationThreshold(self->itself, threshold) == XML_TRUE) {
12581265
Py_RETURN_NONE;
@@ -1262,8 +1269,13 @@ pyexpat_xmlparser_SetAllocTrackerActivationThreshold_impl(xmlparseobject *self,
12621269
// by ExternalEntityParserCreate()).
12631270
pyexpat_state *state = PyType_GetModuleState(cls);
12641271
return set_invalid_arg(state, self, "parser must be a root parser");
1265-
}
1272+
#else
1273+
PyErr_SetString(PyExc_NotImplementedError,
1274+
"SetAllocTrackerActivationThreshold() requires "
1275+
"Expat 2.7.2 or later");
1276+
return NULL;
12661277
#endif
1278+
}
12671279

12681280
static struct PyMethodDef xmlparse_methods[] = {
12691281
PYEXPAT_XMLPARSER_PARSE_METHODDEF

0 commit comments

Comments
 (0)