• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(804)  |  Call(773)  |  Derive(0)  |  Import(31)
Return the module an object was defined in, or None if not found.

        def getmodule(object, _filename=None):
    """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 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 = getabsfile(object, _filename)
    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 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 = 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
        


src/i/p/ipython-py3k-HEAD/IPython/core/ultratb.py   ipython-py3k(Download)
import types
 
# For purposes of monkeypatching inspect to fix a bug in it.
from inspect import getsourcefile, getfile, getmodule,\
     ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode
 
# IPython's own modules
        # XXX: can this ever be false?
        globals_dict = object.f_globals
    else:
        module = getmodule(object, file)
        if module:
            globals_dict = module.__dict__
    lines = linecache.getlines(file, globals_dict)

src/a/p/Apydia-0.0.2/apydia/descriptors.py   Apydia(Download)
import logging
import sys
from os.path import split
from inspect import ismodule, isclass, isfunction, ismethod, isbuiltin, \
                    getmodule, getsourcefile, findsource, getdoc, \
                    getcomments, getargspec, formatargspec
 
    def root_module_basedir(module):
        module = getmodule(module)
        if "." in module.__name__:
            module = sys.modules[module.__name__.split(".")[0]]
            return split(getsourcefile(module))[0]
        else:
            return split(getsourcefile(module))[0]
            def gen_keys(keys):
                for key in keys:
                    if not key.startswith("_"):
                        m = getmodule(d[key])
                        if m in (None, self.value):
                            yield key
            keys = list(gen_keys(keys))
        else:
            keys = []
 
        members = dict()
        for key in keys:
            value = getattr(self.value, key, None)
            module = getmodule(value)

src/i/n/IntPy-0.1.3/src/__init__.py   IntPy(Download)
def _test():
    from doctest import DocTestSuite
    from inspect import getmodule
    from os import walk
    from os.path import abspath, dirname, join
    from unittest import TestSuite, TextTestRunner
    test_suite = TestSuite()
    for root, dirs, files in walk(dirname(abspath(__file__))):
        module_files = [join(root, file) for file in files if \
            file.endswith(".py")]
        test_suite.addTests(DocTestSuite(getmodule(None, file)) for file in \

src/b/r/brian-HEAD/trunk/brian/unused/credits.py   brian(Download)
 
from types import StringType
 
from inspect import getmodule,getsource
import re
 
def credits(obj=None):
        return dict(authors=list(set(authors)))
    else:
        d={}
        m=getmodule(obj) # does not seem to work!
        try:
            d.update(m.__credits__)
        except:

src/b/r/brian-HEAD/brian/unused/credits.py   brian(Download)
 
from types import StringType
 
from inspect import getmodule,getsource
import re
 
def credits(obj=None):
        return dict(authors=list(set(authors)))
    else:
        d={}
        m=getmodule(obj) # does not seem to work!
        try:
            d.update(m.__credits__)
        except:

src/t/r/TracNav-4.1/tracnav/tracnav.py   TracNav(Download)
    def get_macro_description(self, name):
        from inspect import getdoc, getmodule
        return getdoc(getmodule(self))
 
    def get_htdocs_dirs(self):
        from pkg_resources import resource_filename
        return [('tracnav', resource_filename(__name__, 'htdocs'))]

src/d/i/digest-HEAD/lib/reportlab/graphics/shapes.py   digest(Download)
def _addObjImport(obj,I,n=None):
    '''add an import of obj's class to a dictionary of imports''' #'
    from inspect import getmodule
    c = obj.__class__
    m = getmodule(c).__name__
    n = n or c.__name__
    if not I.has_key(m):

src/p/r/productiontrack-HEAD/pt1/tools/reportlab/graphics/shapes.py   productiontrack(Download)
def _addObjImport(obj,I,n=None):
    '''add an import of obj's class to a dictionary of imports''' #'
    from inspect import getmodule
    c = obj.__class__
    m = getmodule(c).__name__
    n = n or c.__name__
    if not I.has_key(m):

src/l/u/ludibrio-HEAD/ludibrio/traceroute.py   ludibrio(Download)
from inspect import getframeinfo, getmodule
from sys import _getframe
import traceback
from ludibrio._testdouble import _ProxyToAlias
from helpers import frame_out_of_context
 
class TraceRoute(_ProxyToAlias):

src/p/r/productiontrack-HEAD/tools/reportlab/graphics/shapes.py   productiontrack(Download)
def _addObjImport(obj,I,n=None):
    '''add an import of obj's class to a dictionary of imports''' #'
    from inspect import getmodule
    c = obj.__class__
    m = getmodule(c).__name__
    n = n or c.__name__
    if not I.has_key(m):

  1 | 2 | 3 | 4  Next