Find a named subclass of a base class.

    Uses only the class name without namespace.
339432
def find_subclass(base: type, name: str) -> type:
    
    class_candidates = [klass
                        for klass in all_subclasses(base)
                        if klass.__name__ == name
                        ]
    if len(class_candidates) == 0:
        raise RuntimeError("No \"{0}\" subclass of \"{1}\".".format(base.__name__, name))
    elif len(class_candidates) > 1:
        raise RuntimeError("Multiple \"{0}\" subclasses of \"{1}\".".format(base.__name__, name))
    return class_candidates[0]
1028166
def find_by_namespace(name)
      names = name.to_s.split(':')
      raise "invalid task namespace" unless names.any?

      namespace = names.join(":")

      #puts "searching for task #{namespace}"
      klass, task = ::Thor::Util.find_class_and_task_by_namespace(namespace, fallback = false)
    end
526482
def GetClass(self, *args, **kwargs):
        

        cname = args[0] if args else kwargs['ClassName']
        try:
            cc = self.classes[self.default_namespace][cname]
        except KeyError:
            if self.conn is None:
                ce = CIMError(CIM_ERR_NOT_FOUND, cname)
                raise ce
            cc = self.conn.GetClass(*args, **kwargs)
            try:
                self.classes[self.default_namespace][cc.classname] = cc
            except KeyError:
                self.classes[self.default_namespace] = \
                    NocaseDict({cc.classname: cc})
        if 'LocalOnly' in kwargs and not kwargs['LocalOnly']:
            if cc.superclass:
                try:
                    del kwargs['ClassName']
                except KeyError:
                    pass
                if args:
                    args = args[1:]
                super_ = self.GetClass(cc.superclass, *args, **kwargs)
                for prop in super_.properties.values():
                    if prop.name not in cc.properties:
                        cc.properties[prop.name] = prop
                for meth in super_.methods.values():
                    if meth.name not in cc.methods:
                        cc.methods[meth.name] = meth
        return cc
1326943
static public function findClass($name, $type=null, $namespaces=null)
	{
	    $name = StringHelper::toClassName($name);
	    if (!$namespaces && strpos($name, '\\') !== false && class_exists($name)) {
	        return $name;
	    }
	    
	    $class_names = [];
	    if (!empty($type)) {
	        $type = StringHelper::toCamelCase($type);
	        if ($pos = strpos($name, '\\')) {
	            $class_names[] = $type . '\\' . $name . $type;
	            $class_names[] = $type . '\\' . $name;
	            
	            $name = substr($name, 0, $pos) . '\\' . $type . '\\' . substr($name, $pos+1);
	        } else {
	            $name = $type . '\\' . $name;
	        }
	        $class_names[] = $name;
	        $class_names[] = $name . $type;
		} else {
		    $class_names[] = $name;
		}
		
		if ($namespaces) {
            $namespaces = (array)static::formatNamespace($namespaces);
		} else {
            //$namespaces = array_unique(array_merge((array)$namespaces, static::getNamespaces()));
		    $namespaces = static::getNamespaces();
		}
		
		foreach ($namespaces as $nss) {
		    foreach ($class_names as $class) { 
		        if (class_exists($nss . $class)) {
		            return $nss . $class;
		        }
		    }
		}
		
		return null;
	}
1125377
public Class<?> getClassByName(String name) throws ClassNotFoundException {
		Class<?> ret = getClassByNameOrNull(name);
		if (ret == null) {
			throw new ClassNotFoundException("Class " + name + " not found");
		}
		return ret;
	}
159542
protected final Class findClass(final String name)
			throws ClassNotFoundException {
		try {
			if (name == null) {
				return null;
			}

			if (name.startsWith("java.") || name.startsWith("sun.reflect")) {
				return ClassLoader.getSystemClassLoader().loadClass(name);
			}

			final String searchClass = name.replace('.', '/') + ".class";
			final CThreadContext context = CThreadContext.getInstance();
			final String cpName = CClassLoader.CCLASSLOADER_NAMESPACE + name;

			List lPriorLoader = (List) context.get(cpName);

			if (lPriorLoader == null) {
				lPriorLoader = new Vector();
				context.set(cpName, lPriorLoader);
			}

			if (lPriorLoader.contains(this.toString())) {
				return null;
			}

			lPriorLoader.add(this.toString());

			if (CClassLoader.sl(CClassLoader.DEBUG)) {
				CClassLoader.log("Searching " + name + " in " + this.getPath(),
						CClassLoader.DEBUG);
			}

			final WeakReference cache = (WeakReference) this.cacheMap.get(name);
			if (cache != null) {
				final Class c = (Class) cache.get();
				if (c != null) {
					return c;
				}
			}

			// first check if this class as a mandatory loader
			if (!this.booAlone) {
				CClassLoader loader = null;

				for (final Iterator it = CClassLoader.mandatoryLoadersMap
						.entrySet().iterator(); it.hasNext();) {
					final Entry entry = (Entry) it.next();
					loader = (CClassLoader) entry.getValue();

					if (loader.classesMap.containsKey(searchClass)) {
						if (loader != this) {
							break;
						}
						loader = null;
						break;
					}
					loader = null;
				}

				if (loader != null) {
					final Class c = loader.findClass(name);
					if (c != null) {
						return c;
					}
				}
			}

			// second search in this repository
			byte buffer[] = null;

			final URL urlToResource = (URL) this.classesMap.get(searchClass);

			if (urlToResource != null) {
				buffer = CClassLoader.loadByteArray(urlToResource);
			}

			if (buffer != null) {
				if (CClassLoader.sl(CClassLoader.DEBUG)) {
					CClassLoader.log(
							"Loaded " + name + " in " + this.getPath(),
							CClassLoader.DEBUG);
				}

				Class c = null;
				c = this.findLoadedClass(name);

				if (c == null) {
					try {
						c = this.defineClass(name, buffer, 0, buffer.length);
					} catch (final LinkageError e) {
						c = this.findLoadedClass(name);

						if (c == null) {
							throw new ClassNotFoundException(name
									+ " was not found !");
						}
					}
				}

				if (c != null) {
					return c;
				}
			}

			// then search in each children
			final List tmpLoader = new ArrayList();

			for (final Iterator it = this.childrenMap.entrySet().iterator(); it
					.hasNext();) {
				final Entry entry = (Entry) it.next();
				final CClassLoader child = (CClassLoader) entry.getValue();

				if (lPriorLoader.contains(child.toString())) {
					continue;
				}

				tmpLoader.add(child);
			}

			for (final Iterator it = tmpLoader.iterator(); it.hasNext();) {
				final Object element = it.next();
				final CClassLoader child = (CClassLoader) element;
				final Class c = child.findClass(name);

				if (c != null) {
					return c;
				}
			}

			// then follow to parents
			if ((this != CClassLoader.getRootLoader())
					&& !this.booDoNotForwardToParent) {
				if (lPriorLoader.contains(this.getParent().toString())) {
					return null;
				} else {
					if (this.getParent() instanceof CClassLoader) {
						return ((CClassLoader) this.getParent())
								.findClass(name);
					} else {
						return this.getParent().loadClass(name);
					}
				}
			} else {
				try {
					ClassLoader contextLoader = CClassLoader.getContextLoader();
					if (contextLoader == null) {
						contextLoader = CClassLoader.getRootLoader()
								.getParent();
					}
					final Class c = contextLoader.loadClass(name);
					if (c != null) {
						return c;
					}
				} catch (Throwable e) {
					final Class c = CClassLoader.getRootLoader().getParent()
							.loadClass(name);
					if (c != null) {
						return c;
					}
				}
				throw new ClassNotFoundException(name);
			}
		} catch (ClassNotFoundException e) {
			throw e;
		} catch (NoClassDefFoundError e) {
			throw e;
		} catch (Throwable e) {
			throw new ClassNotFoundException(name, e);
		}
	}
616945
def find_lexer_class_by_name(_alias):
    
    if not _alias:
        raise ClassNotFound('no lexer for alias %r found' % _alias)
    # lookup builtin lexers
    for module_name, name, aliases, _, _ in itervalues(LEXERS):
        if _alias.lower() in aliases:
            if name not in _lexer_cache:
                _load_lexers(module_name)
            return _lexer_cache[name]
    # continue with lexers from setuptools entrypoints
    for cls in find_plugin_lexers():
        if _alias.lower() in cls.aliases:
            return cls
    raise ClassNotFound('no lexer for alias %r found' % _alias)
1253806
private static Class<?> findClass(String className, ClassLoader classLoader) throws ClassNotFoundException {
        try {
            Class<?> spiClass;
            if (classLoader == null) {
                spiClass = Class.forName(className);
            } else {
                try {
                    spiClass = Class.forName(className, false, classLoader);
                } catch (ClassNotFoundException ex) {
                    spiClass = Class.forName(className);
                }
            }
            return spiClass;
        } catch (ClassNotFoundException x) {
            throw x;
        } catch (Exception x) {
            throw new ClassNotFoundException("Factory " + className + " could not be instantiated: " + x, x);
        }
    }
1344743
public ClassDocImpl lookupClass(String name) {
        ClassSymbol c = getClassSymbol(name);
        if (c != null) {
            return getClassDoc(c);
        } else {
            return null;
        }
    }
154383
def find_class(name, classes):
    """"""
    name = name.lower()
    cls = next((c for c in classes if c.configuration_key == name), None)
    if cls is None:
        raise ValueError("No class named '%s' could be found" % name)
    return cls
986551
public Class<?> findClass(String className) throws ClassNotFoundException {
        for (String skip : SKIP_CLASSES) {
            if (skip.equals(className)) {
                return null;
            }
        }

        for (ClassLoader classLoader : getClassLoaders()) {
            try {
                return classLoader.loadClass(className);
            } catch (ClassNotFoundException e) {
                // ignore
            }
        }
        return Class.forName(className);
    }
120105
def _get_base_class_names(frame):
    
    co, lasti = frame.f_code, frame.f_lasti
    code = co.co_code

    extends = []
    for (op, oparg) in op_stream(code, lasti):
        if op in dis.hasconst:
            if type(co.co_consts[oparg]) == str:
                extends = []
        elif op in dis.hasname:
            if dis.opname[op] == 'LOAD_NAME':
                extends.append(('name', co.co_names[oparg]))
            if dis.opname[op] == 'LOAD_ATTR':
                extends.append(('attr', co.co_names[oparg]))
            if dis.opname[op] == 'LOAD_GLOBAL':
                extends.append(('name', co.co_names[oparg]))

    items = []
    previous_item = []
    for t, s in extends:
        if t == 'name':
            if previous_item:
                items.append(previous_item)
            previous_item = [s]
        else:
            previous_item += [s]
    if previous_item:
        items.append(previous_item)
    return items
1075453
private <T extends Describable<T>>
    Descriptor<T> findDescriptor(String shortClassName, Collection<? extends Descriptor<T>> descriptors) {
        String name = '.'+shortClassName;
        for (Descriptor<T> d : descriptors) {
            if(d.clazz.getName().endsWith(name))
                return d;
        }
        return null;
    }
1006612
def get_class(self, name):
        
        for i in self.classes.class_def:
            if i.get_name() == name:
                return i
        return None
627647
def get_superclass(self, class_):
        
        if not class_.is_loaded or class_.superclass_name is None:
            return None
        return self.get_class(class_.superclass_name)
684616
protected Class findClass(String name) throws ClassNotFoundException {
        if (delegatationLoader==null) return super.findClass(name);
        return delegatationLoader.loadClass(name);
    }
914679
def isinstance(self, instance, class_name):
        """"""
        if isinstance(instance, BaseNode):
            klass = self.dynamic_node_classes.get(class_name, None)
            if klass:
                return isinstance(instance, klass)
            # Not an instance of a class in the registry
            return False
        else:
            raise TypeError("This function can only be used for BaseNode objects")