weixin_39747383 2020-11-19 12:24
浏览 0

Invalid plugin can cause RIDE to crash hard

Originally submitted to Google Code by bryan.oakley on 2 Nov 2010

I have a plugin that, when present in my system, prevents RIDE from starting up.

The culprit seems to be the method importclasses inside pluginloader.py. The offending code appears to be this:


    return [ cls for _, cls in
             inspect.getmembers(module, predicate=inspect.isclass) ]

In spite of the predicate, it appears to be returning things that are not classes. When I put some debug code in I'm seeing this when I print out each item: (notice the last line is printing out a dict rather than a class -- a dict defined in a library imported by the plugin)

... cls= <class 'testrunner.TestRunner'> cls= <class 'TestSuiteTreeCtrl.TestSuiteTreeCtrl'> cls= {'target': 'src/servicetest', 'lib': 'src/servicetest/lib', 'python': 'src/servicetest/python', 'root': 'src/servicetest', 'conf': 'src/servicetest/conf', 'robot': 'src/servicetest/robot', 'robot_report': 'src/servicetest/report/robot'}

Here's the specific error message I get: Traceback (most recent call last): File "/opt/orbitz-st-3.1-B4/bin/ride.py", line 22, in <module> main(sys.argv[1:]) File "/opt/orbitz-st-3.1-B4/lib/python-2.5/site-packages/robotide/init.py", line 48, in main run(*args) File "/opt/orbitz-st-3.1-B4/lib/python-2.5/site-packages/robotide/init.py", line 57, in _run ride = RIDE(inpath) File "/opt/orbitz-st-3.1-B4/lib/python-2.5/site-packages/robotide/application/application.py", line 34, in init wx.App.init(self, redirect=False) File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/core.py", line 7978, in init self.BootstrapApp() File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/core.py", line 7552, in BootstrapApp return _core.PyApp_BootstrapApp(args, *kwargs) File "/opt/orbitz-st-3.1-B4/lib/python-2.5/site-packages/robotide/application/application.py", line 43, in OnInit context.getcoreplugins()) File "/opt/orbitz-st-3.1-B4/lib/python-2.5/site-packages/robotide/application/pluginloader.py", line 30, in init standardclasses + self.findclasses(loaddirs) ] File "/opt/orbitz-st-3.1-B4/lib/python-2.5/site-packages/robotide/application/pluginloader.py", line 42, in _findclasses if issubclass(cls, Plugin) and cls is not Plugin: TypeError: issubclass() arg 1 must be a class

  • 写回答

6条回答 默认 最新

  • weixin_39747383 2020-11-19 12:24
    关注

    Originally submitted to Google Code by bryan.oakley on 2 Nov 2010

    To duplicate this, create a plugin with the following contents:

    from robotide.pluginapi import Plugin

    class DotDict(dict): def getattr(self, attr): return self.get(attr, None) setattr=dict.setitem delattr=dict.delitem

    class EmptyPlugin(Plugin): pass

    foo=DotDict({"one":1, "two":2})

    Loading that same code manually yields surprising results:

    $ PYTHONPATH=/opt/orbitz-st/lib/python/site-packages python2.5 Python 2.5.2 (r252:60911, Aug 28 2008, 13:13:37) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import junk >>> import inspect >>> inspect.getmembers(junk, predicate=inspect.isclass) [('DotDict', <class 'junk.DotDict'>), ('EmptyPlugin', <class 'junk.EmptyPlugin'>), ('Plugin', <class 'robotide.pluginapi.plugin.Plugin'>), ('foo', {'two': 2, 'one': 1})]

    Notice how it includes the instance of the DotDict in the results. That is why the plugin loader is throwing an error.

    评论

报告相同问题?