|
@@ -30,7 +30,7 @@ def get_current_app(frame=None):
|
|
|
frame = inspect.currentframe().f_back
|
|
frame = inspect.currentframe().f_back
|
|
|
|
|
|
|
|
while frame:
|
|
while frame:
|
|
|
- module = getmodule_wrapper(frame.f_code)
|
|
|
|
|
|
|
+ module = inspect.getmodule(frame.f_code)
|
|
|
if not module:
|
|
if not module:
|
|
|
raise Exception(("No module for code %s (frame %s). Perhaps you have an old " +
|
|
raise Exception(("No module for code %s (frame %s). Perhaps you have an old " +
|
|
|
".pyc file hanging around?") % (repr(frame.f_code), repr(frame)))
|
|
".pyc file hanging around?") % (repr(frame.f_code), repr(frame)))
|
|
@@ -49,71 +49,3 @@ def get_app_for_module(module):
|
|
|
if module.__name__.startswith(app) and not module.__name__.startswith("desktop.lib"):
|
|
if module.__name__.startswith(app) and not module.__name__.startswith("desktop.lib"):
|
|
|
return app
|
|
return app
|
|
|
return None
|
|
return None
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def getmodule_wrapper(obj):
|
|
|
|
|
- """
|
|
|
|
|
- inspect.getmodule() does not work with symlink well before Python 2.5. It
|
|
|
|
|
- uses realpath() to determine the locations of sys.modules.
|
|
|
|
|
-
|
|
|
|
|
- So we borrow the getmodule() code from Python 2.5 and do it ourselves.
|
|
|
|
|
- """
|
|
|
|
|
- if sys.version_info >= (2, 5):
|
|
|
|
|
- return inspect.getmodule(obj)
|
|
|
|
|
- return getmodule_2_5(obj)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-#
|
|
|
|
|
-# The following is taken from Python-2.5.4's inspect.py.
|
|
|
|
|
-#
|
|
|
|
|
-modulesbyfile = {}
|
|
|
|
|
-_filesbymodname = {}
|
|
|
|
|
-
|
|
|
|
|
-def getmodule_2_5(object, _filename=None):
|
|
|
|
|
- """Return the module an object was defined in, or None if not found."""
|
|
|
|
|
- global modulesbyfile
|
|
|
|
|
- global _filesbymodname
|
|
|
|
|
-
|
|
|
|
|
- if inspect.ismodule(object):
|
|
|
|
|
- return object
|
|
|
|
|
- if hasattr(object, '__module__'):
|
|
|
|
|
- return sys.modules.get(object.__module__)
|
|
|
|
|
- # Try the filename to modulename cache
|
|
|
|
|
- if _filename is not None and _filename in modulesbyfile:
|
|
|
|
|
- return sys.modules.get(modulesbyfile[_filename])
|
|
|
|
|
- # Try the cache again with the absolute file name
|
|
|
|
|
- try:
|
|
|
|
|
- file = inspect.getabsfile(object)
|
|
|
|
|
- except TypeError:
|
|
|
|
|
- return None
|
|
|
|
|
- if file in modulesbyfile:
|
|
|
|
|
- return sys.modules.get(modulesbyfile[file])
|
|
|
|
|
- # Update the filename to module name cache and check yet again
|
|
|
|
|
- # Copy sys.modules in order to cope with changes while iterating
|
|
|
|
|
- for modname, module in sys.modules.items():
|
|
|
|
|
- if inspect.ismodule(module) and hasattr(module, '__file__'):
|
|
|
|
|
- f = module.__file__
|
|
|
|
|
- if f == _filesbymodname.get(modname, None):
|
|
|
|
|
- # Have already mapped this module, so skip it
|
|
|
|
|
- continue
|
|
|
|
|
- _filesbymodname[modname] = f
|
|
|
|
|
- f = inspect.getabsfile(module)
|
|
|
|
|
- # Always map to the name the module knows itself by
|
|
|
|
|
- modulesbyfile[f] = modulesbyfile[
|
|
|
|
|
- os.path.realpath(f)] = module.__name__
|
|
|
|
|
- if file in modulesbyfile:
|
|
|
|
|
- return sys.modules.get(modulesbyfile[file])
|
|
|
|
|
- # Check the main module
|
|
|
|
|
- main = sys.modules['__main__']
|
|
|
|
|
- if not hasattr(object, '__name__'):
|
|
|
|
|
- return None
|
|
|
|
|
- if hasattr(main, object.__name__):
|
|
|
|
|
- mainobject = getattr(main, object.__name__)
|
|
|
|
|
- if mainobject is object:
|
|
|
|
|
- return main
|
|
|
|
|
- # Check builtins
|
|
|
|
|
- builtin = sys.modules['__builtin__']
|
|
|
|
|
- if hasattr(builtin, object.__name__):
|
|
|
|
|
- builtinobject = getattr(builtin, object.__name__)
|
|
|
|
|
- if builtinobject is object:
|
|
|
|
|
- return builtin
|
|
|