Re: _namemapper: check error from PyImport_ImportModule
Bogdano Arendartchuk <[email protected]>
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
2009/6/7 R. Tyler Ballance <[email protected]>: > > Interesting, do you have a test case that causes the import of `pprint` > to raise an exception like this? Notice myimport lacks the 'level' parameter: import __builtin__ real_import = __builtin__.__import__ def myimport(name, g=None, l=None, fl=[]): return real_import(name, g, l, fl) __builtin__.__import__ = myimport import Cheetah._namemapper > > I would also say that using PyErr_Occurred() and making sure the > exception propagated further up is a better idea than just returning (or > just calling Py_FatalError()) > Please don't call Py_FatalError() for it, it would not give the chance to the interpreter to handle the pending exception from __import__ and would make debugging harder (as it was in my case). When using the patch, the following traceback is shown: Traceback (most recent call last): File "crash.py", line 6, in <module> import Cheetah._namemapper File "crash.py", line 4, in myimport return real_import(name, g, l, fl) TypeError: myimport() takes at most 4 arguments (5 given) ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get