Return a class by importing its module from a fully qualified string.
171562
def import_class_by_string(name):
    """"""
    components = name.split('.')
    clazz = components.pop()
    mod = __import__('.'.join(components))

    components += [clazz]
    for comp in components[1:]:
        mod = getattr(mod, comp)

    return mod
1181853
def import_module(module_name):
    """"""
    import sys, os
    import importlib
    sys.path.append(os.path.dirname(__file__))
    return importlib.import_module(module_name)
1242729
def get_import_for_type(t):
    """"""
    t_as_string = to_str(t)
    if not is_identifier(t_as_string):
        # this class expanded into something other than a single identifier
        # we can ignore it.  This is the case when we encounter something
        # like the configman.converter.str_to_classes_in_namespaces
        # InnerClassList.  We can safely ignore these things here.
        return (None, None)
    if '.' in t_as_string:
        parts = t_as_string.split('.')
        return ('.'.join(parts[:-1]), parts[-1])
    else:
        if t_as_string in known_mapping_str_to_type:
            return (None, None)
        return (None, t_as_string)
1201558
def _import_module(self, s):
        
        mod = __import__(s)
        parts = s.split('.')
        for part in parts[1:]:
            mod = getattr(mod, part)
        return mod
545759
def resolve(str_or_obj):
    """"""
    from rope.base.utils.pycompat import string_types
    if not isinstance(str_or_obj, string_types):
        return str_or_obj
    if '.' not in str_or_obj:
        str_or_obj += '.'
    mod_name, obj_name = str_or_obj.rsplit('.', 1)
    __import__(mod_name)
    mod = sys.modules[mod_name]
    return getattr(mod, obj_name) if obj_name else mod
1034874
def load_class(self, classname):
        

        module_list = self._get_module_list()

        for module in module_list:
            try:
                return import_class(classname, module.__name__)
            except (AttributeError, ImportError):
                pass

        raise ImportError("Class '{0}' could not be loaded.".format(classname))
523756
def import_from_string(import_string):
    
    import_split = import_string.split(".")
    import_class = import_split[-1]
    module_path = ".".join(import_split[:-1])
    mod = __import__(module_path, fromlist=[import_class])
    klass = getattr(mod, import_class)
    return klass
844805
def get_class(classname):
    
    parts = classname.split('.')
    module = ".".join(parts[:-1])
    m = __import__(module)
    for comp in parts[1:]:
        m = getattr(m, comp)
    return m
600838
def import_class(klass):
    ''''''
    mod = __import__(klass.rpartition('.')[0])
    for segment in klass.split('.')[1:-1]:
        mod = getattr(mod, segment)
    return getattr(mod, klass.rpartition('.')[2])
126847
def import_class(clspath):
    
    modpath, clsname = split_clspath(clspath)
    __import__(modpath)
    module = sys.modules[modpath]
    return getattr(module, clsname)
378561
def import_from_string(value):
    """"""
    value = value.replace('-', '_')
    try:
        module_path, class_name = value.rsplit('.', 1)
        module = import_module(module_path)
        return getattr(module, class_name)
    except (ImportError, AttributeError) as ex:
        raise ImportError("Could not import '{}'. {}: {}.".format(
            value, ex.__class__.__name__, ex))
1259762
def from_string(string: str):
        

        spec = Spec()
        parse_context = {"current_subpackage": None}
        for line in string.splitlines():
            spec, parse_context = _parse(spec, parse_context, line)
        return spec
191754
def str_to_class(s):
    """"""
    lst = s.split(".")
    klass = lst[-1]
    mod_list = lst[:-1]
    module = ".".join(mod_list)
    try:
        mod = __import__(module)
        if hasattr(mod, klass):
            return getattr(mod, klass)
        else:
            return None
    except ImportError:
        return None
411343
def import_name_or_class(name):
    "  "

    if isinstance(name, str):

        # for "a.b.c.d" -> [ 'a.b.c', 'd' ]
        module_name, object_name = name.rsplit('.',1)
        # __import__ loads the multi-level of module, but returns
        # the top level, which we have to descend into
        mod = __import__(module_name)

        components = name.split('.')

        for comp in components[1:]: # Already got the top level, so start at 1

            mod = getattr(mod, comp)
        return mod
    else:
        return name
1092971
def _get_imported_module(self, module_name):
        """"""
        # if imported module on module_set add to list
        imp_mod = self.by_name.get(module_name)
        if imp_mod:
            return imp_mod

        # last part of import section might not be a module
        # remove last section
        no_obj = module_name.rsplit('.', 1)[0]
        imp_mod2 = self.by_name.get(no_obj)
        if imp_mod2:
            return imp_mod2

        # special case for __init__
        if module_name in self.pkgs:
            pkg_name = module_name  + ".__init__"
            return self.by_name[pkg_name]

        if no_obj in self.pkgs:
            pkg_name = no_obj +  ".__init__"
            return self.by_name[pkg_name]
166730
def load_module(name):
    

    spec = importlib.util.find_spec(name)
    mod = importlib.util.module_from_spec(spec)
    mod.__spec__ = spec
    mod.__loader__ = spec.loader
    spec.loader.exec_module(mod)
    return mod
943056
def str_to_application_class(self, an_app_key):
        """"""
        try:
            app_class = str_to_python_object(self.apps[an_app_key])
        except KeyError:
            app_class = str_to_python_object(an_app_key)
        try:
            self.application_defaults = DotDict(
                app_class.get_application_defaults()
            )
        except AttributeError:
            # no get_application_defaults, skip this step
            pass
        return app_class