Commits

Christian Heimes committed 260e76d

Added new functions to set global defaults

Comments (0)

Files changed (8)

 - Remove 'bomb protection' suffix from CAPI MAGIC
 - Don't support additional kwargs in _elementtree when XML_BOMB_PROTECTION
   is not available.
-- implement better and more flexibel get/set feature API in expat
+- Implement better and more flexibel get/set feature API in expat
+- Add module functions to set global settings
 
 
 defusedexpat 0.2

Modules26/pyexpat.c

 
 /* List of methods defined in the module */
 
+#ifdef XML_BOMB_PROTECTION
+PyDoc_STRVAR(pyexpat_set_reset_dtd_doc,
+"set_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_set_reset_dtd(PyObject *self, PyObject *args)
+{
+    PyObject *pre;
+    long value;
+    if (!PyArg_ParseTuple(args, "O:set_reset_dtd", &pre))
+        return NULL;
+    if ((value = (long)PyObject_IsTrue(pre)) == -1 ) {
+        return NULL;
+    }
+    if (!XML_SetFeatureDefault(XML_FEATURE_RESET_DTD, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_reset_dtd_doc,
+"get_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_get_reset_dtd(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_RESET_DTD, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyBool_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_expansions_doc,
+"set_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_expansions", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_expansions_doc,
+"get_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_indirections_doc,
+"set_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_indirections", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_indirections_doc,
+"get_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+#endif
+
+
 static struct PyMethodDef pyexpat_methods[] = {
     {"ParserCreate",    (PyCFunction)pyexpat_ParserCreate,
      METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
     {"ErrorString",     (PyCFunction)pyexpat_ErrorString,
      METH_VARARGS,      pyexpat_ErrorString__doc__},
-
+#ifdef XML_BOMB_PROTECTION
+    {"set_reset_dtd",  (PyCFunction)pyexpat_set_reset_dtd, METH_VARARGS,
+      pyexpat_set_reset_dtd_doc},
+    {"get_reset_dtd",  (PyCFunction)pyexpat_get_reset_dtd, METH_NOARGS,
+      pyexpat_get_reset_dtd_doc},
+    {"set_max_entity_expansions", (PyCFunction)pyexpat_set_max_entity_expansions,
+      METH_VARARGS, pyexpat_set_max_entity_expansions_doc},
+    {"get_max_entity_expansions", (PyCFunction)pyexpat_get_max_entity_expansions,
+      METH_NOARGS, pyexpat_get_max_entity_expansions_doc},
+    {"set_max_entity_indirections", (PyCFunction)pyexpat_set_max_entity_indirections,
+      METH_VARARGS, pyexpat_set_max_entity_indirections_doc},
+    {"get_max_entity_indirections", (PyCFunction)pyexpat_get_max_entity_indirections,
+      METH_NOARGS, pyexpat_get_max_entity_indirections_doc},
+#endif
     {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 };
 

Modules27/pyexpat.c

 
 /* List of methods defined in the module */
 
+#ifdef XML_BOMB_PROTECTION
+PyDoc_STRVAR(pyexpat_set_reset_dtd_doc,
+"set_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_set_reset_dtd(PyObject *self, PyObject *args)
+{
+    PyObject *pre;
+    long value;
+    if (!PyArg_ParseTuple(args, "O:set_reset_dtd", &pre))
+        return NULL;
+    if ((value = (long)PyObject_IsTrue(pre)) == -1 ) {
+        return NULL;
+    }
+    if (!XML_SetFeatureDefault(XML_FEATURE_RESET_DTD, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_reset_dtd_doc,
+"get_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_get_reset_dtd(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_RESET_DTD, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyBool_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_expansions_doc,
+"set_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_expansions", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_expansions_doc,
+"get_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_indirections_doc,
+"set_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_indirections", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_indirections_doc,
+"get_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+#endif
+
+
 static struct PyMethodDef pyexpat_methods[] = {
     {"ParserCreate",    (PyCFunction)pyexpat_ParserCreate,
      METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
     {"ErrorString",     (PyCFunction)pyexpat_ErrorString,
      METH_VARARGS,      pyexpat_ErrorString__doc__},
-
+#ifdef XML_BOMB_PROTECTION
+    {"set_reset_dtd",  (PyCFunction)pyexpat_set_reset_dtd, METH_VARARGS,
+      pyexpat_set_reset_dtd_doc},
+    {"get_reset_dtd",  (PyCFunction)pyexpat_get_reset_dtd, METH_NOARGS,
+      pyexpat_get_reset_dtd_doc},
+    {"set_max_entity_expansions", (PyCFunction)pyexpat_set_max_entity_expansions,
+      METH_VARARGS, pyexpat_set_max_entity_expansions_doc},
+    {"get_max_entity_expansions", (PyCFunction)pyexpat_get_max_entity_expansions,
+      METH_NOARGS, pyexpat_get_max_entity_expansions_doc},
+    {"set_max_entity_indirections", (PyCFunction)pyexpat_set_max_entity_indirections,
+      METH_VARARGS, pyexpat_set_max_entity_indirections_doc},
+    {"get_max_entity_indirections", (PyCFunction)pyexpat_get_max_entity_indirections,
+      METH_NOARGS, pyexpat_get_max_entity_indirections_doc},
+#endif
     {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 };
 

Modules31/pyexpat.c

 
 /* List of methods defined in the module */
 
+#ifdef XML_BOMB_PROTECTION
+PyDoc_STRVAR(pyexpat_set_reset_dtd_doc,
+"set_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_set_reset_dtd(PyObject *self, PyObject *args)
+{
+    PyObject *pre;
+    long value;
+    if (!PyArg_ParseTuple(args, "O:set_reset_dtd", &pre))
+        return NULL;
+    if ((value = (long)PyObject_IsTrue(pre)) == -1 ) {
+        return NULL;
+    }
+    if (!XML_SetFeatureDefault(XML_FEATURE_RESET_DTD, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_reset_dtd_doc,
+"get_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_get_reset_dtd(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_RESET_DTD, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyBool_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_expansions_doc,
+"set_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_expansions", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_expansions_doc,
+"get_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_indirections_doc,
+"set_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_indirections", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_indirections_doc,
+"get_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+#endif
+
+
 static struct PyMethodDef pyexpat_methods[] = {
     {"ParserCreate",    (PyCFunction)pyexpat_ParserCreate,
      METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
     {"ErrorString",     (PyCFunction)pyexpat_ErrorString,
      METH_VARARGS,      pyexpat_ErrorString__doc__},
-
+#ifdef XML_BOMB_PROTECTION
+    {"set_reset_dtd",  (PyCFunction)pyexpat_set_reset_dtd, METH_VARARGS,
+      pyexpat_set_reset_dtd_doc},
+    {"get_reset_dtd",  (PyCFunction)pyexpat_get_reset_dtd, METH_NOARGS,
+      pyexpat_get_reset_dtd_doc},
+    {"set_max_entity_expansions", (PyCFunction)pyexpat_set_max_entity_expansions,
+      METH_VARARGS, pyexpat_set_max_entity_expansions_doc},
+    {"get_max_entity_expansions", (PyCFunction)pyexpat_get_max_entity_expansions,
+      METH_NOARGS, pyexpat_get_max_entity_expansions_doc},
+    {"set_max_entity_indirections", (PyCFunction)pyexpat_set_max_entity_indirections,
+      METH_VARARGS, pyexpat_set_max_entity_indirections_doc},
+    {"get_max_entity_indirections", (PyCFunction)pyexpat_get_max_entity_indirections,
+      METH_NOARGS, pyexpat_get_max_entity_indirections_doc},
+#endif
     {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 };
 

Modules32/pyexpat.c

 
 /* List of methods defined in the module */
 
+#ifdef XML_BOMB_PROTECTION
+PyDoc_STRVAR(pyexpat_set_reset_dtd_doc,
+"set_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_set_reset_dtd(PyObject *self, PyObject *args)
+{
+    PyObject *pre;
+    long value;
+    if (!PyArg_ParseTuple(args, "O:set_reset_dtd", &pre))
+        return NULL;
+    if ((value = (long)PyObject_IsTrue(pre)) == -1 ) {
+        return NULL;
+    }
+    if (!XML_SetFeatureDefault(XML_FEATURE_RESET_DTD, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_reset_dtd_doc,
+"get_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_get_reset_dtd(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_RESET_DTD, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyBool_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_expansions_doc,
+"set_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_expansions", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_expansions_doc,
+"get_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_indirections_doc,
+"set_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_indirections", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_indirections_doc,
+"get_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+#endif
+
+
 static struct PyMethodDef pyexpat_methods[] = {
     {"ParserCreate",    (PyCFunction)pyexpat_ParserCreate,
      METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
     {"ErrorString",     (PyCFunction)pyexpat_ErrorString,
      METH_VARARGS,      pyexpat_ErrorString__doc__},
-
+#ifdef XML_BOMB_PROTECTION
+    {"set_reset_dtd",  (PyCFunction)pyexpat_set_reset_dtd, METH_VARARGS,
+      pyexpat_set_reset_dtd_doc},
+    {"get_reset_dtd",  (PyCFunction)pyexpat_get_reset_dtd, METH_NOARGS,
+      pyexpat_get_reset_dtd_doc},
+    {"set_max_entity_expansions", (PyCFunction)pyexpat_set_max_entity_expansions,
+      METH_VARARGS, pyexpat_set_max_entity_expansions_doc},
+    {"get_max_entity_expansions", (PyCFunction)pyexpat_get_max_entity_expansions,
+      METH_NOARGS, pyexpat_get_max_entity_expansions_doc},
+    {"set_max_entity_indirections", (PyCFunction)pyexpat_set_max_entity_indirections,
+      METH_VARARGS, pyexpat_set_max_entity_indirections_doc},
+    {"get_max_entity_indirections", (PyCFunction)pyexpat_get_max_entity_indirections,
+      METH_NOARGS, pyexpat_get_max_entity_indirections_doc},
+#endif
     {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 };
 

Modules33/pyexpat.c

 
 /* List of methods defined in the module */
 
+#ifdef XML_BOMB_PROTECTION
+PyDoc_STRVAR(pyexpat_set_reset_dtd_doc,
+"set_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_set_reset_dtd(PyObject *self, PyObject *args)
+{
+    PyObject *pre;
+    long value;
+    if (!PyArg_ParseTuple(args, "O:set_reset_dtd", &pre))
+        return NULL;
+    if ((value = (long)PyObject_IsTrue(pre)) == -1 ) {
+        return NULL;
+    }
+    if (!XML_SetFeatureDefault(XML_FEATURE_RESET_DTD, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_reset_dtd_doc,
+"get_reset_dtd(n)\n"
+);
+
+static PyObject *
+pyexpat_get_reset_dtd(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_RESET_DTD, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyBool_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_expansions_doc,
+"set_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_expansions", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_expansions_doc,
+"get_max_entity_expansions(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_expansions(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_EXPANSIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+
+PyDoc_STRVAR(pyexpat_set_max_entity_indirections_doc,
+"set_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_set_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!PyArg_ParseTuple(args, "l:set_max_entity_indirections", &value))
+        return NULL;
+    if (!XML_SetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+PyDoc_STRVAR(pyexpat_get_max_entity_indirections_doc,
+"get_max_entity_indirections(n)\n"
+);
+
+static PyObject *
+pyexpat_get_max_entity_indirections(PyObject *self, PyObject *args)
+{
+    long value;
+    if (!XML_GetFeatureDefault(XML_FEATURE_MAX_ENTITY_INDIRECTIONS, &value)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    return PyLong_FromLong(value);
+}
+#endif
+
+
 static struct PyMethodDef pyexpat_methods[] = {
     {"ParserCreate",    (PyCFunction)pyexpat_ParserCreate,
      METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
     {"ErrorString",     (PyCFunction)pyexpat_ErrorString,
      METH_VARARGS,      pyexpat_ErrorString__doc__},
-
+#ifdef XML_BOMB_PROTECTION
+    {"set_reset_dtd",  (PyCFunction)pyexpat_set_reset_dtd, METH_VARARGS,
+      pyexpat_set_reset_dtd_doc},
+    {"get_reset_dtd",  (PyCFunction)pyexpat_get_reset_dtd, METH_NOARGS,
+      pyexpat_get_reset_dtd_doc},
+    {"set_max_entity_expansions", (PyCFunction)pyexpat_set_max_entity_expansions,
+      METH_VARARGS, pyexpat_set_max_entity_expansions_doc},
+    {"get_max_entity_expansions", (PyCFunction)pyexpat_get_max_entity_expansions,
+      METH_NOARGS, pyexpat_get_max_entity_expansions_doc},
+    {"set_max_entity_indirections", (PyCFunction)pyexpat_set_max_entity_indirections,
+      METH_VARARGS, pyexpat_set_max_entity_indirections_doc},
+    {"get_max_entity_indirections", (PyCFunction)pyexpat_get_max_entity_indirections,
+      METH_NOARGS, pyexpat_get_max_entity_indirections_doc},
+#endif
     {NULL,       (PyCFunction)NULL, 0, NULL}            /* sentinel */
 };
 
 * XML_DEFAULT_MAX_ENTITY_EXPANSIONS
 * XML_BOMB_PROTECTION
 
+
+Modules functions
+..................
+
+* get_reset_dtd(), set_reset_dtd(bool)
+* get_max_entity_expansions(), set_max_entity_expansions(int)
+* get_max_entity_indirections(), et_max_entity_indirections(int)
+
+
 New CAPI members
 ................
 
                                                       repr(container))
                 self.fail(self._formatMessage(msg, standardMsg))
 
+    def setUp(self):
+        pyexpat.set_reset_dtd(False)
+        pyexpat.set_max_entity_expansions(
+            pyexpat.XML_DEFAULT_MAX_ENTITY_EXPANSIONS)
+        pyexpat.set_max_entity_indirections(
+            pyexpat.XML_DEFAULT_MAX_ENTITY_INDIRECTIONS)
 
     def test_xmlbomb_protection_available(self):
         self.assertTrue(pyexpat.XML_BOMB_PROTECTION)
 
+    def test_defaults(self):
+        self.assertEqual(pyexpat.get_reset_dtd(), False)
+        self.assertEqual(pyexpat.get_max_entity_expansions(),
+                         pyexpat.XML_DEFAULT_MAX_ENTITY_EXPANSIONS)
+        self.assertEqual(pyexpat.get_max_entity_indirections(),
+                         pyexpat.XML_DEFAULT_MAX_ENTITY_INDIRECTIONS)
+
+        pyexpat.set_reset_dtd(True)
+        pyexpat.set_max_entity_expansions(10)
+        pyexpat.set_max_entity_indirections(10)
+
+        self.assertEqual(pyexpat.get_reset_dtd(), True)
+        self.assertEqual(pyexpat.get_max_entity_expansions(), 10)
+        self.assertEqual(pyexpat.get_max_entity_indirections(), 10)
+
+        p = pyexpat.ParserCreate()
+        self.assertEqual(p.max_entity_indirections, 10)
+        self.assertEqual(p.max_entity_expansions, 10)
+        self.assertEqual(p.reset_dtd, True)
+
     def test_xmlbomb_exponential(self):
         # test that the maximum indirection limitation prevents exponential
         # entity expansion attacks (billion laughs). Every expansion increases