Read WSGI app/Gateway path string and import application module.
351388
def resolve(cls, full_path):
        """"""
        mod_path, _, app_path = full_path.partition(':')
        app = getattr(import_module(mod_path), app_path or 'application')

        with contextlib.suppress(TypeError):
            if issubclass(app, server.Gateway):
                return GatewayYo(app)

        return cls(app)
624179
def _parse_application_section(cfg, parser, section):
    '''
    
    '''
    try:
        sys.path.append(cfg.get(section, 'pythonpath'))
    except ConfigParser.NoOptionError:
        pass

    module = cfg.get(section, 'import')
    name = cfg.get(section, 'name')
    try:
        applications.load(module, name)
    except ImportError as e:
        raise error.FeatError(
            "Loading application %s.%s failed, requested from section %s" %
            (module, name, section, ), cause=e)
614244
def classify_import(module_name, application_directories=('.',)):
    
    # Only really care about the first part of the path
    base, _, _ = module_name.partition('.')
    found, module_path, is_builtin = _get_module_info(
        base, application_directories,
    )
    if base == '__future__':
        return ImportType.FUTURE
    # Relative imports: `from .foo import bar`
    elif base == '':
        return ImportType.APPLICATION
    # If imp tells us it is builtin, it is builtin
    elif is_builtin:
        return ImportType.BUILTIN
    # If the module path exists in the project directories
    elif _module_path_is_local_and_is_not_symlinked(
            module_path, application_directories,
    ):
        return ImportType.APPLICATION
    # Otherwise we assume it is a system module or a third party module
    elif (
            found and
            PACKAGES_PATH not in module_path and
            not _due_to_pythonpath(module_path)
    ):
        return ImportType.BUILTIN
    else:
        return ImportType.THIRD_PARTY
1019725
def _import_csv(self, path):
        """"""

        # If path is not set, do nothing
        if not path:
            return

        # Get csv info

        try:
            dialect, has_header, digest_types, encoding = \
                self.main_window.interfaces.get_csv_import_info(path)

        except IOError:
            msg = _("Error opening file {filepath}.").format(filepath=path)
            post_command_event(self.main_window, self.StatusBarMsg, text=msg)
            return

        except TypeError:
            return  # Import is aborted or empty

        return CsvInterface(self.main_window,
                            path, dialect, digest_types, has_header, encoding)
446870
def get_modules(root_path):
    """"""
    for dir_path, dir_names, file_names in os.walk(root_path):
        assert dir_path[:len(root_path)] == root_path
        subdir_path = dir_path[len(root_path):]
        package_parts = list(filter(lambda x: x, subdir_path.split('/')))
        for name in file_names:
            if name.endswith('.py'):
                path = os.path.join(dir_path, name)
                pkgpath = '.'.join(package_parts)
                modpath = (pkgpath if name == '__init__.py' else
                           '.'.join(package_parts + [name[:-3]]))
                try:
                    node = ast.parse(open(path).read())
                except SyntaxError:
                    print('ERROR: Invalid syntax in %s' % path, file=sys.stderr)
                else:
                    yield (pkgpath, modpath, path, node)
415199
def autodiscover_modules():
    
    import imp
    from django.conf import settings

    for app in settings.INSTALLED_APPS:
        try:
            __import__(app)
            app_path = sys.modules[app].__path__
        except AttributeError:
            continue
        try:
            imp.find_module('permissions', app_path)
        except ImportError:
            continue
        __import__("%s.permissions" % app)
        app_path = sys.modules["%s.permissions" % app]
    LOADING = False
370025
def _caller_path(index):  # type: (int) -> str
    
    module = None
    stack = inspect.stack()
    while not module:
        if index >= len(stack):
            raise RuntimeError("Cannot find import path")
        frame = stack[index]
        module = inspect.getmodule(frame[0])
        index += 1
    filename = module.__file__
    path = os.path.dirname(os.path.realpath(filename))
    return path
1279575
def load(name, base_path=None):
    """"""
    if '/' in name:
        return load_location(name, base_path, module=True)

    return importer.import_symbol(name, base_path)
1330507
def load_from_file(module_path):
    
    from imp import load_module, PY_SOURCE

    imported = None
    if module_path:
        with open(module_path, 'r') as openfile:
            imported = load_module('mod', openfile, module_path, ('imported', 'r', PY_SOURCE))
    return imported
1181853
def import_module(module_name):
    """"""
    import sys, os
    import importlib
    sys.path.append(os.path.dirname(__file__))
    return importlib.import_module(module_name)
1162134
def get_environ(self):
        """"""
        req = self.req
        env = {
            # set a non-standard environ entry so the WSGI app can know what
            # the *real* server protocol is (and what features to support).
            # See http://www.faqs.org/rfcs/rfc2145.html.
            'ACTUAL_SERVER_PROTOCOL': req.server.protocol,
            'PATH_INFO': req.path,
            'QUERY_STRING': req.qs,
            'REMOTE_ADDR': req.conn.remote_addr or '',
            'REMOTE_PORT': str(req.conn.remote_port or ''),
            'REQUEST_METHOD': req.method,
            'REQUEST_URI': req.uri,
            'SCRIPT_NAME': '',
            'SERVER_NAME': req.server.server_name,
            # Bah. "SERVER_PROTOCOL" is actually the REQUEST protocol.
            'SERVER_PROTOCOL': req.request_protocol,
            'SERVER_SOFTWARE': req.server.software,
            'wsgi.errors': sys.stderr,
            'wsgi.input': req.rfile,
            'wsgi.multiprocess': False,
            'wsgi.multithread': True,
            'wsgi.run_once': False,
            'wsgi.url_scheme': req.scheme,
            'wsgi.version': (1, 0),
            }
        
        if isinstance(req.server.bind_addr, basestring):
            # AF_UNIX. This isn't really allowed by WSGI, which doesn't
            # address unix domain sockets. But it's better than nothing.
            env["SERVER_PORT"] = ""
        else:
            env["SERVER_PORT"] = str(req.server.bind_addr[1])
        
        # Request headers
        for k, v in req.inheaders.iteritems():
            env["HTTP_" + k.upper().replace("-", "_")] = v
        
        # CONTENT_TYPE/CONTENT_LENGTH
        ct = env.pop("HTTP_CONTENT_TYPE", None)
        if ct is not None:
            env["CONTENT_TYPE"] = ct
        cl = env.pop("HTTP_CONTENT_LENGTH", None)
        if cl is not None:
            env["CONTENT_LENGTH"] = cl
        
        if req.conn.ssl_env:
            env.update(req.conn.ssl_env)
        
        return env
587638
def application(self, name, context_root, path):
	
		
		
		return Application(self.__endpoint, name, context_root, path)
525930
def appname(path=None):
    
    if path is None:
        path = sys.argv[0]
    name = os.path.basename(os.path.splitext(path)[0])
    if name == 'mod_wsgi':
        name = 'nvn_web'                                                                        # pragma: no cover
    return name
101474
def read(self, module_name):
        
        self.parser.read("{}/{}.ini".format(self.path, module_name.split(".")[-1]))
538283
def modulePath(self):
        
        base_path = os.path.dirname(self.filepath())
        module_path = self.importPath()

        module_path = os.path.expanduser(os.path.expandvars(module_path))
        if module_path.startswith('.'):
            module_path = os.path.abspath(os.path.join(base_path, module_path))

        return module_path
1028667
def _read_import_root_map_file(path):
    """"""
    if os.path.exists(path):
      with open(path, 'r') as fp:
        return dict({import_path: root for import_path, root in
                     (x.strip().split('\t') for x in fp.readlines())})
    else:
      return {}
642967
def import_module(module_path):
    
    if six.PY2:
        try:
            return importlib.import_module(module_path)
        except ImportError:
            tb = sys.exc_info()[2]
            stack = traceback.extract_tb(tb, 3)
            if len(stack) > 2:
                raise
    else:
        from importlib import find_loader
        if find_loader(module_path):
            return importlib.import_module(module_path)