Python get class by name

25 Python code examples are found related to " get class by name". 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.
Example 1
Source File: viberwrapper-indicator.py    From viberwrapper-indicator with GNU General Public License v2.0 6 votes vote down vote up
def get_client_by_class_name(self, class_name):
        XTools.Instance().get_display().sync()
        window = None

        for win_id in self.get_client_list():
            try:
                win = self.create_window_from_id(win_id)
                wclass = win.get_wm_class()
                if wclass is not None and (class_name in wclass[0] or class_name in wclass[1]):
                    window = win
                    break
            except BadWindow:
                printf("Error getting client's WM_CLASS of window 0x%08x\n", win_id)
                pass

        return window 
Example 2
Source File: viberwrapper-indicator.py    From viberwrapper-indicator with GNU General Public License v2.0 6 votes vote down vote up
def get_window_by_class_name(self, class_name):
        XTools.Instance().get_display().sync()
        window = None

        for win in self.root.query_tree().children:
            try:
                window_wm_class = win.get_wm_class()
                if window_wm_class is not None:
                    if class_name in window_wm_class[0] or class_name in window_wm_class[1]:
                        window = self.display.create_resource_object('window', win.id)
                        break
            except BadWindow:
                printf("Error getting window's WM_CLASS of window 0x%08x\n", win.id)
                pass

        return window 
Example 3
Source File: helpers.py    From ecommerce with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_processor_class_by_name(name):
    """Return the payment processor class corresponding to the specified name.

    Arguments:
        name (string): The name of a payment processor.

    Returns:
        class: The payment processor class with the given name.

    Raises:
        ProcessorNotFoundError: If no payment processor with the given name exists.
    """
    for path in settings.PAYMENT_PROCESSORS:
        processor_class = get_processor_class(path)

        if name == processor_class.NAME:
            return processor_class

    raise exceptions.ProcessorNotFoundError(
        exceptions.PROCESSOR_NOT_FOUND_DEVELOPER_MESSAGE.format(name=name)
    ) 
Example 4
Source File: Parser.py    From AdvancedHTMLParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
def getElementsByClassName(self, className, root='root', useIndex=True):
        '''
            getElementsByClassName - Searches and returns all elements containing a given class name.


                @param className <str> - One or more space-separated class names

                @param root <AdvancedTag/'root'> - Search starting at a specific node, if provided. if string 'root', the root of the parsed tree will be used.

                @param useIndex <bool> If useIndex is True and class names are indexed [see constructor] only the index will be used. Otherwise a full search is performed.
        '''
        (root, isFromRoot) = self._handleRootArg(root)

        if useIndex is True and self.indexClassNames is True:

            elements = self._classNameMap.get(className, [])

            if isFromRoot is False:
                _hasTagInParentLine = self._hasTagInParentLine
                elements = [x for x in elements if _hasTagInParentLine(x, root)]

            return TagCollection(elements)

        return AdvancedHTMLParser.getElementsByClassName(self, className, root) 
Example 5
Source File: resource_registry.py    From kube-web-view with GNU General Public License v3.0 6 votes vote down vote up
def get_class_by_plural_name(
        self,
        plural: str,
        namespaced: bool,
        default=throw_exception,
        api_version: str = None,
    ):
        _types = (
            self.namespaced_resource_types
            if namespaced
            else self.cluster_resource_types
        )
        clazz = None
        for c in await _types:
            if c.endpoint == plural and (c.version == api_version or not api_version):
                clazz = c
                break
        if not clazz and default is throw_exception:
            raise ResourceTypeNotFound(plural, namespaced)
        return clazz 
Example 6
Source File: __init__.py    From platypush with MIT License 5 votes vote down vote up
def get_plugin_class_by_name(plugin_name):
    """ Gets the class of a plugin by name (e.g. "music.mpd" or "media.vlc") """

    module = get_plugin_module_by_name(plugin_name)
    if not module:
        return

    class_name = getattr(module, ''.join([_.capitalize() for _ in plugin_name.split('.')]) + 'Plugin')
    try:
        return getattr(module, ''.join([_.capitalize() for _ in plugin_name.split('.')]) + 'Plugin')
    except Exception as e:
        logger.error('Cannot import class {}: {}'.format(class_name, str(e)))
        return None 
Example 7
Source File: __init__.py    From can-prog with MIT License 5 votes vote down vote up
def get_protocol_class_by_name(name):
    if name == 'stm32':
        return stm32.STM32Protocol
    else:
        raise NotImplementedError('unknown protocol type') 
Example 8
Source File: jdwp-shellifier.py    From WebAppSec with Apache License 2.0 5 votes vote down vote up
def get_class_by_name(self, name):
        for entry in self.classes:
            if entry["signature"].lower() == name.lower() :
                return entry
        return None 
Example 9
Source File: App.py    From PyFlow with Apache License 2.0 5 votes vote down vote up
def getToolClassByName(self, packageName, toolName, toolClass=DockTool):
        registeredTools = GET_TOOLS()
        for ToolClass in registeredTools[packageName]:
            if issubclass(ToolClass, toolClass):
                if ToolClass.name() == toolName:
                    return ToolClass
        return None 
Example 10
Source File: GraphBase.py    From PyFlow with Apache License 2.0 5 votes vote down vote up
def getNodesByClassName(self, className):
        """Returns a list of nodes filtered by class name
        :param className: Class name of target nodes
        :type className: str
        :rtype: list(:class:`~PyFlow.Core.NodeBase.NodeBase`)
        """
        nodes = []
        for i in self.getNodesList():
            if i.__class__.__name__ == className:
                nodes.append(i)
        return nodes 
Example 11
Source File: __init__.py    From gntp with MIT License 5 votes vote down vote up
def get_index_class_by_name(name):
    name_to_lookup_index_class = {
        'nmslib': NMSLookupIndex,
        'faiss': FAISSLookupIndex,
        'faiss-cpu': FAISSLookupIndex,
        'random': RandomLookupIndex,
        'exact': ExactKNNLookupIndex,
        'brute': BruteKNNLookupIndex,
        'symbol': SymbolLookupIndex,
    }

    if name not in name_to_lookup_index_class:
        raise ModuleNotFoundError

    return name_to_lookup_index_class[name] 
Example 12
Source File: vray2rs.py    From anima with MIT License 5 votes vote down vote up
def get_super_class_id_by_name(cls, class_name):
        """returns the super class id of the given class

        :param str class_name: Class Name
        :return:
        """
        c = cls.get_class_by_name(class_name)
        return c.SuperClassId 
Example 13
Source File: vray2rs.py    From anima with MIT License 5 votes vote down vote up
def get_class_by_name(cls, class_name):
        """returns the class_id from the given class_name

        :param str class_name: The class name
        :return MaxPlus.Class_ID:
        """
        for c in MaxPlus.PluginManager.GetClassList().Classes:
            if c.Name == class_name:
                return c 
Example 14
Source File: vray2rs.py    From anima with MIT License 5 votes vote down vote up
def get_class_id_by_name(cls, class_name):
        """returns the class_id from the given class_name

        :param str class_name: The class name
        :return MaxPlus.Class_ID:
        """
        c = cls.get_class_by_name(class_name)
        return c.ClassId 
Example 15
Source File: __init__.py    From pyTSon_plugins with GNU General Public License v3.0 5 votes vote down vote up
def getWidgetByClassName(self, name):
        QApp = QApplication.instance()
        widgets = QApp.topLevelWidgets()
        widgets = widgets + QApp.allWidgets()
        for x in widgets:
            if str(x.__class__) == name: return x 
Example 16
Source File: xosbase_header.py    From xos with Apache License 2.0 5 votes vote down vote up
def get_model_class_by_name(cls, name):
        all_models = django.apps.apps.get_models(include_auto_created=False)
        all_models_by_name = {}
        for model in all_models:
            all_models_by_name[model.__name__] = model

        return all_models_by_name.get(name) 
Example 17
Source File: Tags.py    From AdvancedHTMLParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
def getPeersByClassName(self, className):
        '''
            getPeersByClassName - Gets peers (elements on same level) with a given class name

            @param className - classname must contain this name

            @return - None if no parent element (error condition), otherwise a TagCollection of peers that matched.
        '''
        peers = self.peers
        if peers is None:
            return None
        return TagCollection([peer for peer in peers if peer.hasClass(className)]) 
Example 18
Source File: common_util.py    From monasca-analytics with Apache License 2.0 5 votes vote down vote up
def get_sml_class_by_name(class_name):
    """Gets the sml class by class name.

    :type class_name: str
    :param class_name: name of the sml class requested.
    :raises: MonanasNoSuchIngestorError -- if no sml class found.
    :raises: MonanasDuplicateIngestorError -- if the system has multiple sml
                                              algorithms of the same class
                                              name.
    """
    return get_class_by_name(class_name, const.SMLS) 
Example 19
Source File: common_util.py    From monasca-analytics with Apache License 2.0 5 votes vote down vote up
def get_source_class_by_name(class_name):
    """Gets the source class by class name.

    :type class_name: str
    :param class_name: name of the source class requested.
    :raises: MonanasNoSuchIngestorError -- if no source class found.
    :raises: MonanasDuplicateIngestorError -- if the system has multiple
    source of the same class name.
    """
    return get_class_by_name(class_name, const.SOURCES) 
Example 20
Source File: common_util.py    From monasca-analytics with Apache License 2.0 5 votes vote down vote up
def get_ingestor_class_by_name(class_name):
    """Gets the ingestor class by class name.

    :type class_name: str
    :param class_name: name of the ingestor class requested.
    :raises: MonanasNoSuchIngestorError -- if no ingestor class found.
    :raises: MonanasDuplicateIngestorError -- if the system has multiple
    ingestors of the same class name.
    """
    return get_class_by_name(class_name, const.INGESTORS) 
Example 21
Source File: common_util.py    From monasca-analytics with Apache License 2.0 5 votes vote down vote up
def get_voter_class_by_name(class_name):
    """Gets the voter class by class name.

    :type class_name: str
    :param class_name: name of the voter class requested.
    :raises: MonanasNoSuchIngestorError -- If no voter class found.
    :raises: MonanasDuplicateIngestorError: If the system has multiple
             voter of the same class name.
    """
    return get_class_by_name(class_name, const.VOTERS) 
Example 22
Source File: common_util.py    From monasca-analytics with Apache License 2.0 5 votes vote down vote up
def get_class_by_name(class_name, class_type=None):
    """Gets the class by class name.

    :type class_name: str
    :param class_name: a class name to look for
    :type class_type: str
    :param class_type: the type of the class to look for
                       (e.g. data_sources, ingestors, etc.).
    :returns: class -- the source class requested.
    :raises: MonanasNoSuchSourceError -- If no source class found.
    :raises: MonanasDuplicateSourceError -- If the system has multiple sources
    of the same class name.
    """
    classes = get_available_classes(class_type)
    if class_type:
        clazz = list(filter(lambda t_class: t_class.__name__ == class_name,
                            classes[class_type]))
    else:
        for c_type in classes.keys():
            clazz = list(filter(lambda t_class: t_class.__name__ == class_name,
                                classes[c_type]))
            if clazz:
                break
    if not clazz:
        raise err.MonanasNoSuchClassError(class_name)
    elif len(clazz) > 1:
        raise err.MonanasDuplicateClassError(class_name)
    else:
        return clazz[0]