From: Geoff B. <geo...@gm...> - 2011-04-15 20:07:20
|
That would be one way to go, though it would require rewriting code that works fine under CPython. As I understand things, this is the "old way" to do it and sys.meta_path was introduced to make doing this sort of thing simpler and easier. Some of the problems with using __import__ are listed in the original PEP here: http://www.python.org/dev/peps/pep-0302 I'd like to establish whether this is a bug in Jython first, anyway... Regards, Geoff On Fri, Apr 15, 2011 at 9:37 PM, Pierre Thibault <pie...@gm...> wrote: > And what about changing the function at __builtins__.__import__ for your > own? > > 2011/4/15 Geoff Bache <geo...@gm...> >> >> Well yes, if all I wanted to do was add an extra location to the >> search path. But I'm trying to intercept and monitor the import >> mechanism (to help write CaptureMock, my capture-replay mocking >> framework). sys.meta_path is a documented part of Python and appeared >> to work in Jython also... >> >> Regards, >> Geoff >> >> On Fri, Apr 15, 2011 at 8:40 PM, Pierre Thibault >> <pie...@gm...> wrote: >> > Is it not more simple to simply add your path in System.getProperties >> > for >> > java.class.path? >> > >> > 2011/4/15 Geoff Bache <geo...@gm...> >> >> >> >> Hi all, >> >> >> >> I couldn't find anything in the docs for sys.meta_path to beware that >> >> it didn't work on java modules/packages, so I thought I'd ask here >> >> before reporting. >> >> >> >> Run the following code under Jython 2.5.2 >> >> >> >> import sys >> >> >> >> class A: >> >> def find_module(self, name, *args): >> >> print "Checking", name >> >> >> >> sys.meta_path = [ A() ] >> >> >> >> print "Importing xml.sax.handler..." >> >> import xml.sax.handler >> >> print "Importing javax.swing..." >> >> import javax.swing >> >> >> >> and note that when importing the Python module xml.sax.handler, >> >> "find_module" gets called for every submodule as expected. When >> >> importing javax.swing, it is called only once, on "javax", despite >> >> "javax.swing" also being added to sys.modules. This seems to be the >> >> case for any java package, i.e. only the top level interacts with >> >> sys.meta_path, which as it's usually something like "org" or "com" >> >> makes it not very useful. >> >> >> >> Regards, >> >> Geoff Bache >> >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> Benefiting from Server Virtualization: Beyond Initial Workload >> >> Consolidation -- Increasing the use of server virtualization is a top >> >> priority.Virtualization can reduce costs, simplify management, and >> >> improve >> >> application availability and disaster protection. Learn more about >> >> boosting >> >> the value of server virtualization. >> >> http://p.sf.net/sfu/vmware-sfdev2dev >> >> _______________________________________________ >> >> Jython-users mailing list >> >> Jyt...@li... >> >> https://lists.sourceforge.net/lists/listinfo/jython-users >> > >> > >> > >> > -- >> > >> > >> > A+ >> > >> > ------------- >> > Pierre >> > My blog and profile (http://pierrethibault.posterous.com) >> > YouTube page (http://www.youtube.com/user/tubetib) >> > Twitter (http://twitter.com/pierreth2) >> > >> > >> > >> > ------------------------------------------------------------------------------ >> > Benefiting from Server Virtualization: Beyond Initial Workload >> > Consolidation -- Increasing the use of server virtualization is a top >> > priority.Virtualization can reduce costs, simplify management, and >> > improve >> > application availability and disaster protection. Learn more about >> > boosting >> > the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev >> > _______________________________________________ >> > Jython-users mailing list >> > Jyt...@li... >> > https://lists.sourceforge.net/lists/listinfo/jython-users >> > >> > > > > > -- > > > A+ > > ------------- > Pierre > My blog and profile (http://pierrethibault.posterous.com) > YouTube page (http://www.youtube.com/user/tubetib) > Twitter (http://twitter.com/pierreth2) > > > ------------------------------------------------------------------------------ > Benefiting from Server Virtualization: Beyond Initial Workload > Consolidation -- Increasing the use of server virtualization is a top > priority.Virtualization can reduce costs, simplify management, and improve > application availability and disaster protection. Learn more about boosting > the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |