Python pyclbr.readmodule_ex() Examples

The following are 23 code examples of pyclbr.readmodule_ex(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyclbr , or try the search function .
Example #1
Source File: ClassBrowser.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError:
            return []
        items = []
        self.classes = {}
        for key, cl in dict.items():
            if cl.module == name:
                s = key
                if hasattr(cl, 'super') and cl.super:
                    supers = []
                    for sup in cl.super:
                        if type(sup) is type(''):
                            sname = sup
                        else:
                            sname = sup.name
                            if sup.module != cl.module:
                                sname = "%s.%s" % (sup.module, sname)
                        supers.append(sname)
                    s = s + "(%s)" % ", ".join(supers)
                items.append((cl.lineno, s))
                self.classes[s] = cl
        items.sort()
        list = []
        for item, s in items:
            list.append(s)
        return list 
Example #2
Source File: test_pyclbr.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #3
Source File: test_pyclbr.py    From android_universal with MIT License 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #4
Source File: shell_view.py    From Email_My_PC with MIT License 5 votes vote down vote up
def get_clbr_for_file(path):
    try:
        objects = clbr_modules[path]
    except KeyError:
        dir, filename = os.path.split(path)
        base, ext = os.path.splitext(filename)
        objects = pyclbr.readmodule_ex(base, [dir])
        clbr_modules[path] = objects
    return objects

# Our COM interfaces.

# Base class for a shell folder.
# All child classes use a simple PIDL of the form:
#  "object_type\0object_name[\0extra ...]" 
Example #5
Source File: test_pyclbr.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #6
Source File: loader.py    From unishark with Apache License 2.0 5 votes vote down vote up
def _inspect_module(pkg_name, mod_name):
        full_mod_name = mod_name if not pkg_name else '.'.join((pkg_name, mod_name))
        return pyclbr.readmodule_ex(full_mod_name)  # return module_content 
Example #7
Source File: ClassBrowser.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError:
            return []
        items = []
        self.classes = {}
        for key, cl in dict.items():
            if cl.module == name:
                s = key
                if hasattr(cl, 'super') and cl.super:
                    supers = []
                    for sup in cl.super:
                        if type(sup) is type(''):
                            sname = sup
                        else:
                            sname = sup.name
                            if sup.module != cl.module:
                                sname = "%s.%s" % (sup.module, sname)
                        supers.append(sname)
                    s = s + "(%s)" % ", ".join(supers)
                items.append((cl.lineno, s))
                self.classes[s] = cl
        items.sort()
        list = []
        for item, s in items:
            list.append(s)
        return list 
Example #8
Source File: test_pyclbr.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #9
Source File: ClassBrowser.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError:
            return []
        items = []
        self.classes = {}
        for key, cl in dict.items():
            if cl.module == name:
                s = key
                if hasattr(cl, 'super') and cl.super:
                    supers = []
                    for sup in cl.super:
                        if type(sup) is type(''):
                            sname = sup
                        else:
                            sname = sup.name
                            if sup.module != cl.module:
                                sname = "%s.%s" % (sup.module, sname)
                        supers.append(sname)
                    s = s + "(%s)" % ", ".join(supers)
                items.append((cl.lineno, s))
                self.classes[s] = cl
        items.sort()
        list = []
        for item, s in items:
            list.append(s)
        return list 
Example #10
Source File: test_pyclbr.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #11
Source File: utils.py    From masakari with Apache License 2.0 5 votes vote down vote up
def monkey_patch():
    """If the CONF.monkey_patch set as True,
    this function patches a decorator
    for all functions in specified modules.
    You can set decorators for each modules
    using CONF.monkey_patch_modules.
    The format is "Module path:Decorator function".

    name - name of the function
    function - object of the function
    """
    # If CONF.monkey_patch is not True, this function do nothing.
    if not CONF.monkey_patch:
        return
    if six.PY2:
        is_method = inspect.ismethod
    else:
        def is_method(obj):
            # Unbound methods became regular functions on Python 3
            return inspect.ismethod(obj) or inspect.isfunction(obj)
    # Get list of modules and decorators
    for module_and_decorator in CONF.monkey_patch_modules:
        module, decorator_name = module_and_decorator.split(':')
        # import decorator function
        decorator = importutils.import_class(decorator_name)
        __import__(module)
        # Retrieve module information using pyclbr
        module_data = pyclbr.readmodule_ex(module)
        for key, value in module_data.items():
            # set the decorator for the class methods
            if isinstance(value, pyclbr.Class):
                clz = importutils.import_class("%s.%s" % (module, key))
                for method, func in inspect.getmembers(clz, is_method):
                    setattr(clz, method,
                            decorator("%s.%s.%s" % (module, key,
                                                    method), func))
            # set the decorator for the function
            if isinstance(value, pyclbr.Function):
                func = importutils.import_class("%s.%s" % (module, key))
                setattr(sys.modules[module], key,
                        decorator("%s.%s" % (module, key), func)) 
Example #12
Source File: shell_view.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def get_clbr_for_file(path):
    try:
        objects = clbr_modules[path]
    except KeyError:
        dir, filename = os.path.split(path)
        base, ext = os.path.splitext(filename)
        objects = pyclbr.readmodule_ex(base, [dir])
        clbr_modules[path] = objects
    return objects

# Our COM interfaces.

# Base class for a shell folder.
# All child classes use a simple PIDL of the form:
#  "object_type\0object_name[\0extra ...]" 
Example #13
Source File: test_pyclbr.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #14
Source File: ClassBrowser.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError:
            return []
        items = []
        self.classes = {}
        for key, cl in dict.items():
            if cl.module == name:
                s = key
                if hasattr(cl, 'super') and cl.super:
                    supers = []
                    for sup in cl.super:
                        if type(sup) is type(''):
                            sname = sup
                        else:
                            sname = sup.name
                            if sup.module != cl.module:
                                sname = "%s.%s" % (sup.module, sname)
                        supers.append(sname)
                    s = s + "(%s)" % ", ".join(supers)
                items.append((cl.lineno, s))
                self.classes[s] = cl
        items.sort()
        list = []
        for item, s in items:
            list.append(s)
        return list 
Example #15
Source File: test_pyclbr.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #16
Source File: ClassBrowser.py    From oss-ftp with MIT License 5 votes vote down vote up
def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError:
            return []
        items = []
        self.classes = {}
        for key, cl in dict.items():
            if cl.module == name:
                s = key
                if hasattr(cl, 'super') and cl.super:
                    supers = []
                    for sup in cl.super:
                        if type(sup) is type(''):
                            sname = sup
                        else:
                            sname = sup.name
                            if sup.module != cl.module:
                                sname = "%s.%s" % (sup.module, sname)
                        supers.append(sname)
                    s = s + "(%s)" % ", ".join(supers)
                items.append((cl.lineno, s))
                self.classes[s] = cl
        items.sort()
        list = []
        for item, s in items:
            list.append(s)
        return list 
Example #17
Source File: test_pyclbr.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #18
Source File: ClassBrowser.py    From BinderFilter with MIT License 5 votes vote down vote up
def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError, msg:
            return [] 
Example #19
Source File: test_pyclbr.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #20
Source File: test_pyclbr.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_issue_14798(self):
        # test ImportError is raised when the first part of a dotted name is
        # not a package
        self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') 
Example #21
Source File: ModuleBrowser.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _MakeRoot(self):
        path = self.GetDocument().GetPathName()
        if not path:
            return HierListCLBRErrorRoot("Error: Can not browse a file until it is saved")
        else:
            mod, path = pywin.framework.scriptutils.GetPackageModuleName(path)
            if self.bDirty:
                what = "Refreshing"
                # Hack for pyclbr being too smart
                try:
                    del pyclbr._modules[mod]
                except (KeyError, AttributeError):
                    pass
            else:
                what = "Building"
            win32ui.SetStatusText("%s class list - please wait..." % (what,), 1)
            win32ui.DoWaitCursor(1)
            try:
                reader = pyclbr.readmodule_ex # new version post 1.5.2
            except AttributeError:
                reader = pyclbr.readmodule
            try:
                data = reader(mod, [path])
                if data:
                    return HierListCLBRModule(mod, data)
                else:
                    return HierListCLBRErrorRoot("No Python classes in module.")

            finally:
                win32ui.DoWaitCursor(0)
                win32ui.SetStatusText(win32ui.LoadString(afxres.AFX_IDS_IDLEMESSAGE)) 
Example #22
Source File: browseProjects.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GetSubList(self):
		mod, path = pywin.framework.scriptutils.GetPackageModuleName(self.path)
		win32ui.SetStatusText("Building class list - please wait...", 1)
		win32ui.DoWaitCursor(1)
		try:
			try:
				reader = pyclbr.readmodule_ex # Post 1.5.2 interface.
				extra_msg = " or functions"
			except AttributeError:
				reader = pyclbr.readmodule
				extra_msg = ""
			data = reader(mod, [path])
			if data:
				ret = []
				for item in data.itervalues():
					if item.__class__ != pyclbr.Class: # ie, it is a pyclbr Function instance (only introduced post 1.5.2)
						ret.append(HLICLBRFunction( item, " (function)" ) )
					else:
						ret.append(HLICLBRClass( item, " (class)") )
				ret.sort()
				return ret
			else:
				return [HLIErrorItem("No Python classes%s in module." % (extra_msg,))]
		finally:
			win32ui.DoWaitCursor(0)
			win32ui.SetStatusText(win32ui.LoadString(afxres.AFX_IDS_IDLEMESSAGE)) 
Example #23
Source File: utils.py    From manila with Apache License 2.0 4 votes vote down vote up
def monkey_patch():
    """Patch decorator.

    If the Flags.monkey_patch set as True,
    this function patches a decorator
    for all functions in specified modules.
    You can set decorators for each modules
    using CONF.monkey_patch_modules.
    The format is "Module path:Decorator function".
    Example: 'manila.api.ec2.cloud:' \
     manila.openstack.common.notifier.api.notify_decorator'

    Parameters of the decorator is as follows.
    (See manila.openstack.common.notifier.api.notify_decorator)

    name - name of the function
    function - object of the function
    """
    # If CONF.monkey_patch is not True, this function do nothing.
    if not CONF.monkey_patch:
        return
    # Get list of modules and decorators
    for module_and_decorator in CONF.monkey_patch_modules:
        module, decorator_name = module_and_decorator.split(':')
        # import decorator function
        decorator = importutils.import_class(decorator_name)
        __import__(module)
        # Retrieve module information using pyclbr
        module_data = pyclbr.readmodule_ex(module)
        for key in module_data.keys():
            # set the decorator for the class methods
            if isinstance(module_data[key], pyclbr.Class):
                clz = importutils.import_class("%s.%s" % (module, key))
                # NOTE(vponomaryov): we need to distinguish class methods types
                # for py2 and py3, because the concept of 'unbound methods' has
                # been removed from the python3.x
                if six.PY3:
                    member_type = inspect.isfunction
                else:
                    member_type = inspect.ismethod
                for method, func in inspect.getmembers(clz, member_type):
                    setattr(
                        clz, method,
                        decorator("%s.%s.%s" % (module, key, method), func))
            # set the decorator for the function
            if isinstance(module_data[key], pyclbr.Function):
                func = importutils.import_class("%s.%s" % (module, key))
                setattr(sys.modules[module], key,
                        decorator("%s.%s" % (module, key), func))