ionelmc/python-manhole — pull request #38 by nirs (2014-10-26 18:45:46+00:00)
Title: Cleanup _get_original

The previous code had few issues:

- We try to import possibly non-exiting modules on each call, which is
expensive, looking up the the module in the entire import path. This
is also pointless since the module is not expected to appear after we
found that it was not available.

- Do pointless lookups, becuase older lookups overwrite previous
lookups. For example, if gevent is available, we would lookup twice,
overwriting the pure Python lookup with gevent lookup. If both gevent
and eventlet are available, we would do 3 lookups and return the
eventlet lookup.

- Check for SynatxError on import looks wrong. I could not find the
code that raise this in the gevent and evetlet.

- _get_original interface was strage, accepting a string, instead of
the expected module and name arguemtns, as used by
gevent.monkey.get_original.

Now we use simpler and more efficient solution:

- We try to import eventlet or gevent only once
- We define _get_original either using eventlet, gevent or our
implementaion.
- We do only single lookup per call
- _get_original accpets module and name arguments