Re: _namemapper: check error from PyImport_ImportModule

"R. Tyler Ballance" <[email protected]>
Newsgroups gmane.comp.python.cheetah
Message-ID <20090607191504.GB15900@starfruit>
On Sun, Jun 07, 2009 at 04:03:03PM -0300, Bogdano Arendartchuk wrote:
> 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'm assuming by your mentioning of the level parameter you're talking
about Python 2.6 and up.


> >
> > 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)

Fair enough, I'll write a quick regression test for this and then apply
the patch


-- 
-R. Tyler Ballance
Slide, Inc.

------------------------------------------------------------------------------
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

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkosEbgACgkQFCbH3D9R4W/Z8wCgtffogi9+PiF8TSVJagyYDYOG
WY4An3uxGQuu33V2ux/tpKOcGj5Ln1Hk
=BzBq
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.