Helper function for walking import calls when searching for classes by
    string names.
496328
def my_import(name):
    
    mod = __import__(name)
    components = name.split('.')
    for comp in components[1:]:
        mod = getattr(mod, comp)
    return mod
815162
@Nullable
	public Import find(@Nonnull final String typeName) {
		Check.notEmpty(typeName, "typeName");
		Import ret = null;
		final Type type = new Type(typeName);
		for (final Import imp : imports) {
			if (imp.getType().getName().equals(type.getName())) {
				ret = imp;
				break;
			}
		}
		if (ret == null) {
			final Type javaLangType = Type.evaluateJavaLangType(typeName);
			if (javaLangType != null) {
				ret = Import.of(javaLangType);
			}
		}
		return ret;
	}
744603
def discover(package, cls_match_func):
    
    matched_classes = set()

    for _, module_name, _ in pkgutil.walk_packages(
            package.__path__,
            prefix=package.__name__ + '.',
    ):
        module = __import__(module_name, fromlist=[str('__trash')], level=0)

        # Check all the classes in that module
        for _, imported_class in inspect.getmembers(module, inspect.isclass):
            # Don't include things that are only there due to a side-effect of
            # importing
            if imported_class.__module__ != module.__name__:
                continue

            if cls_match_func(imported_class):
                matched_classes.add(imported_class)

    return matched_classes
1109437
def find_classes_in_module(module, clstypes):
    
    classes = []
    for item in dir(module):
        item = getattr(module, item)
        try:
            for cls in clstypes:
                if issubclass(item, cls) and item != cls:
                    classes.append(item)
        except Exception as e:
            pass
    return classes
716082
def query_walkers():
    """"""
    return [
        import_string(walker)() if isinstance(walker, six.string_types)
        else walker() for walker in current_app.config[
            'COLLECTIONS_QUERY_WALKERS']
    ]
315470
function imports($imported_classes = []) {
    $imports = [];

    if ($imported_classes) {
      // Sort the imported classes.
      sort($imported_classes);

      foreach ($imported_classes as $fully_qualified_class_name) {
        $fully_qualified_class_name = ltrim($fully_qualified_class_name, '\\');
        $imports[] = "use $fully_qualified_class_name;";
      }

      $imports[] = '';
    }

    return $imports;
  }
433493
def import_from_string(path, slient=True):
    
    names = path.split(".")
    for i in range(len(names), 0, -1):
        p1 = ".".join(names[0:i])
        module = import_module(p1)
        if module:
            p2 = ".".join(names[i:])
            if p2:
                return select(module, p2, slient=slient)
            else:
                return module
    name = names[0]
    names = names[1:]
    module = get_caller_locals().get(name)
    if module and names:
        return select(module, ".".join(names), slient=slient)
    if module:
        return module
    module = get_caller_globals().get(name)
    if module and names:
        return select(module, ".".join(names), slient=slient)
    if module:
        return module
    if slient:
        return None
    else:
        raise ImportError("Import {path} failed.".format(path=path))
1021795
function getLanguageForClass(classNames) {
    return Immutable.List(classNames)
        .map(function(cl) {
            // Markdown
            if (cl.search('lang-') === 0) {
                return cl.slice('lang-'.length);
            }

            // Asciidoc
            if (cl.search('language-') === 0) {
                return cl.slice('language-'.length);
            }

            return null;
        })
        .find(function(cl) {
            return Boolean(cl);
        });
}
615569
def generate_import_from(module_, names):
        
        regular_names = [n for n in names if "::" not in n]
        as_names = [n for n in names if "::" in n]

        line = ""
        if len(regular_names) > 0:
            slots = {"m": module_, "n": ", ".join(sorted(regular_names))}
            line = "from %(m)s import %(n)s" % slots
            if len(line) > LINE_LENGTH_LIMIT:
                slots["n"] = INDENT + (",\n" + INDENT).join(sorted(regular_names)) + ","
                line = "from %(m)s import (\n%(n)s\n)" % slots
            if len(as_names) > 0:
                line += "\n"

        for as_name in as_names:
            a, n = as_name.split("::")
            line += "from %(m)s import %(n)s as %(a)s" % {"m": module_, "n": n, "a": a}
        return line
30053
def import_class(import_str):
    """"""
    mod_str, _sep, class_str = import_str.rpartition('.')
    try:
        __import__(mod_str)
        return getattr(sys.modules[mod_str], class_str)
    except (ValueError, AttributeError):
        raise ImportError('Class %s cannot be found (%s)' %
                          (class_str,
                           traceback.format_exception(*sys.exc_info())))
769703
function parseImportLine (line) {
  if (IS_IMPORT.test(line)) {
    // could be either depending on whether default import was before or after named imports
    const [, default0, named, default1] = IMPORT.exec(line)
    const defaultImport = default0 || default1
    const namedImports = []
    if (named) {
      let next
      while ((next = NAMED_IMPORTS.exec(named)) != null) {
        const [, src, importedAs] = next
        namedImports.push([src, importedAs || src]) // if no alternate name, use default name
      }
    }

    return [defaultImport, namedImports]
  } else {
    return null
  }
}
1234816
def enumerate_import_methods(tokens):
    
    global_imports = enumerate_global_imports(tokens)
    out = []
    for item in global_imports:
        for index, tok in enumerate(tokens):
            try:
                next_tok = tokens[index+1]
                try:
                    next_next_tok = tokens[index+2]
                except IndexError:
                    # Pretend it is a newline
                    next_next_tok = (54, '\n', (1, 1), (1, 2), '#\n')
            except IndexError: # Last token, no biggie
                # Pretend it is a newline here too
                next_tok = (54, '\n', (1, 1), (1, 2), '#\n')
            token_type = tok[0]
            token_string = tok[1]
            if token_string == item:
                if next_tok[1] == '.': # We're calling a method
                    module_method = "%s.%s" % (token_string, next_next_tok[1])
                    if module_method not in out:
                        out.append(module_method)
    return out
193651
def get_imported_modules(self, module):
    """"""
    for name, member in inspect.getmembers(module):
      if inspect.ismodule(member):
        yield name, member
1135857
def _get_imports_m(self, data_types, default_imports):
        """"""
        if not isinstance(data_types, list):
            data_types = [data_types]

        import_classes = default_imports

        for data_type in data_types:
            import_classes.append(fmt_class_prefix(data_type))

            if data_type.parent_type:
                import_classes.append(fmt_class_prefix(data_type.parent_type))

            if is_struct_type(
                    data_type) and data_type.has_enumerated_subtypes():
                for _, subtype in data_type.get_all_subtypes_with_tags():
                    import_classes.append(fmt_class_prefix(subtype))

            for field in data_type.all_fields:
                data_type, _ = unwrap_nullable(field.data_type)

                # unpack list or map
                while is_list_type(data_type) or is_map_type(data_type):
                    data_type = (data_type.value_data_type if
                        is_map_type(data_type) else data_type.data_type)

                if is_user_defined_type(data_type):
                    import_classes.append(fmt_class_prefix(data_type))

        if import_classes:
            import_classes = list(set(import_classes))
            import_classes.sort()

        return import_classes
1166135
def import_class(import_str):
    """"""
    mod_str, _sep, class_str = import_str.rpartition(".")
    __import__(mod_str)
    return getattr(sys.modules[mod_str], class_str)
718131
def import_cls(cls_name):
    
    path_components = cls_name.split('.')
    module = __import__('.'.join(path_components[:-1]),
                        locals(),
                        globals(),
                        fromlist=path_components[-1:])
    return getattr(module, path_components[-1])
1135020
def find_import_star(node):
    """"""
    return (
        isinstance(node, ast.ImportFrom)
        and '*' in h.importfrom_names(node.names)
    )