All Samples(152) | Call(149) | Derive(0) | Import(3)
Return an absolute path to the source or compiled file for an object. The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.
def getabsfile(object, _filename=None):
"""Return an absolute path to the source or compiled file for an object.
The idea is for each object to have a unique origin, so this routine
normalizes the result as much as possible."""
if _filename is None:
_filename = getsourcefile(object) or getfile(object)
return os.path.normcase(os.path.abspath(_filename))
# HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We
# simply monkeypatch inspect with code copied from python 2.4.
if sys.version_info[:2] == (2,3):
from inspect import ismodule, getabsfile, modulesbyfile
def getmodule(object):
"""Return the module an object was defined in, or None if not found."""
if ismodule(object):
return object
if hasattr(object, '__module__'):
return sys.modules.get(object.__module__)
try:
file = getabsfile(object)
if hasattr(module, '__file__'):
modulesbyfile[
os.path.realpath(
getabsfile(module))] = module.__name__
if file in modulesbyfile:
return sys.modules.get(modulesbyfile[file])
main = sys.modules['__main__']
# run contents of file through pager starting at line
# where the object is defined
ofile = inspect.getabsfile(obj)
if (ofile.endswith('.so') or ofile.endswith('.dll')):
print 'File %r is binary, not printing.' % ofile
binary_file = False
try:
try:
fname = inspect.getabsfile(obj)
except TypeError:
# For an instance, the file that matters is where its class was
# declared.
if hasattr(obj,'__class__'):
fname = inspect.getabsfile(obj.__class__)
src/i/p/ipython-0.10/IPython/OInspect.py ipython(Download)
# HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We
# simply monkeypatch inspect with code copied from python 2.4.
if sys.version_info[:2] == (2,3):
from inspect import ismodule, getabsfile, modulesbyfile
def getmodule(object):
"""Return the module an object was defined in, or None if not found."""
if ismodule(object):
return object
if hasattr(object, '__module__'):
return sys.modules.get(object.__module__)
try:
file = getabsfile(object)
if hasattr(module, '__file__'):
modulesbyfile[
os.path.realpath(
getabsfile(module))] = module.__name__
if file in modulesbyfile:
return sys.modules.get(modulesbyfile[file])
main = sys.modules['__main__']
# run contents of file through pager starting at line
# where the object is defined
ofile = inspect.getabsfile(obj)
if (ofile.endswith('.so') or ofile.endswith('.dll')):
print 'File %r is binary, not printing.' % ofile
binary_file = False
try:
try:
fname = inspect.getabsfile(obj)
except TypeError:
# For an instance, the file that matters is where its class was
# declared.
if hasattr(obj,'__class__'):
fname = inspect.getabsfile(obj.__class__)
src/a/x/Axiom-0.6.0/axiom/item.py Axiom(Download)
import gc from zope.interface import implements, Interface from inspect import getabsfile from weakref import WeakValueDictionary from twisted.python import log
otherT = _typeNameToMostRecentClass[T.typeName]
if (otherT.__name__ == T.__name__
and getabsfile(T) == getabsfile(otherT)
and T.__module__ != otherT.__module__):
if len(T.__module__) < len(otherT.__module__):