@@ -3034,8 +3034,7 @@ static struct PyModuleDef _elementtreemodule = {
30343034PyMODINIT_FUNC
30353035PyInit__elementtree (void )
30363036{
3037- PyObject * m ;
3038- PyObject * g ;
3037+ PyObject * m , * g , * temp ;
30393038 char * bootstrap ;
30403039
30413040 /* Initialize object types */
@@ -3067,10 +3066,6 @@ PyInit__elementtree(void)
30673066 PyDict_SetItemString (g , "__builtins__" , PyEval_GetBuiltins ());
30683067
30693068 bootstrap = (
3070-
3071- "from copy import deepcopy\n"
3072- "from xml.etree import ElementPath\n"
3073-
30743069 "def iter(node, tag=None):\n" /* helper */
30753070 " if tag == '*':\n"
30763071 " tag = None\n"
@@ -3094,8 +3089,14 @@ PyInit__elementtree(void)
30943089 if (!PyRun_String (bootstrap , Py_file_input , g , NULL ))
30953090 return NULL ;
30963091
3097- elementpath_obj = PyDict_GetItemString (g , "ElementPath" );
3098- elementtree_deepcopy_obj = PyDict_GetItemString (g , "deepcopy" );
3092+ if (!(temp = PyImport_ImportModule ("copy" )))
3093+ return NULL ;
3094+ elementtree_deepcopy_obj = PyObject_GetAttrString (temp , "deepcopy" );
3095+ Py_XDECREF (temp );
3096+
3097+ if (!(elementpath_obj = PyImport_ImportModule ("xml.etree.ElementPath" )))
3098+ return NULL ;
3099+
30993100 elementtree_iter_obj = PyDict_GetItemString (g , "iter" );
31003101 elementtree_itertext_obj = PyDict_GetItemString (g , "itertext" );
31013102
0 commit comments