reconstruct the relative import, now the generated code looks better

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10629 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Haoyu Bai 2008-07-02 07:08:00 +00:00
commit 9fc127d68b

View file

@ -701,14 +701,17 @@ public:
* code conditional on the python version.
*/
Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL);
Printv(f_shadow, tab4, "from os.path import dirname\n", NULL);
Printv(f_shadow, tab4, "import imp\n", NULL);
Printv(f_shadow, tab4, "try:\n", NULL);
Printf(f_shadow, tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
Printf(f_shadow, tab8 "%s = imp.load_module('%s', fp, pathname, description)\n", module, module);
Printv(f_shadow, tab4, "except:\n", NULL);
Printf(f_shadow, tab8, "if fp is not None: fp.close()\n", NULL);
Printv(f_shadow, tab4, "del fp, pathname, description, imp, dirname\n", NULL);
Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
Printv(f_shadow, tab8, "import imp\n", NULL);
Printv(f_shadow, tab8, "try:\n", NULL);
Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
Printf(f_shadow, tab4 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
Printv(f_shadow, tab8, "finally:\n", NULL);
Printv(f_shadow, tab4 tab8, "if fp is not None: fp.close()\n", NULL);
Printv(f_shadow, tab8, "return _mod\n", NULL);
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
Printv(f_shadow, "else:\n", NULL);
Printf(f_shadow, tab4 "import %s\n", module);