當前位置: 首頁>>代碼示例>>Python>>正文


Python imp.C_BUILTIN屬性代碼示例

本文整理匯總了Python中imp.C_BUILTIN屬性的典型用法代碼示例。如果您正苦於以下問題:Python imp.C_BUILTIN屬性的具體用法?Python imp.C_BUILTIN怎麽用?Python imp.C_BUILTIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在imp的用法示例。


在下文中一共展示了imp.C_BUILTIN屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: find_module

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def find_module(self, name, path, parent=None):
        if parent is not None:
            # assert path is not None
            fullname = parent.__name__+'.'+name
        else:
            fullname = name
        if fullname in self.excludes:
            self.msgout(3, "find_module -> Excluded", fullname)
            raise ImportError, name

        if path is None:
            if name in sys.builtin_module_names:
                return (None, None, ("", "", imp.C_BUILTIN))

            path = self.path
        return imp.find_module(name, path) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:18,代碼來源:modulefinder.py

示例2: find_module

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def find_module(self, name, path, parent=None):
        if parent is not None:
            # assert path is not None
            fullname = parent.__name__ + '.' + name
        else:
            fullname = name
        if fullname in self.excludes:
            self.msgout(3, "find_module -> Excluded", fullname)
            raise ImportError(name)

        if path is None:
            if name in sys.builtin_module_names:
                return (None, None, ("", "", imp.C_BUILTIN))

            path = self.path
        return imp.find_module(name, path) 
開發者ID:thebjorn,項目名稱:pydeps,代碼行數:18,代碼來源:mf27.py

示例3: find_module

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def find_module(self, name, path, parent=None):
        if parent is not None:
            # assert path is not None
            fullname = parent.__name__+'.'+name
        else:
            fullname = name
        if fullname in self.excludes:
            self.msgout(3, "find_module -> Excluded", fullname)
            raise ImportError(name)

        if path is None:
            if name in sys.builtin_module_names:
                return (None, None, ("", "", imp.C_BUILTIN))

            path = self.path
        return imp.find_module(name, path) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:modulefinder.py

示例4: test_c_builtin

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def test_c_builtin(self):
    imp.find_module('bar', ['foo']).AndReturn((None, 'bar',
                                               (None, None, imp.C_BUILTIN)))
    self.mox.ReplayAll()
    self.assertIsNone(self.hook.find_module('foo.bar', ['foo'])) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:7,代碼來源:sandbox_test.py

示例5: test_flags

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def test_flags(self):
        self.assertEqual(imp.SEARCH_ERROR,0)
        self.assertEqual(imp.PY_SOURCE,1)
        self.assertEqual(imp.PY_COMPILED,2)
        self.assertEqual(imp.C_EXTENSION,3)
        self.assertEqual(imp.PY_RESOURCE,4)
        self.assertEqual(imp.PKG_DIRECTORY,5)
        self.assertEqual(imp.C_BUILTIN,6)
        self.assertEqual(imp.PY_FROZEN,7)
        self.assertEqual(imp.PY_CODERESOURCE,8) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_imp.py

示例6: get_handler

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def get_handler():
    if "IOPIPE_HANDLER" not in os.environ or not os.environ["IOPIPE_HANDLER"]:
        raise ValueError("No value specified in IOPIPE_HANDLER environment variable")

    try:
        module_path, handler_name = os.environ["IOPIPE_HANDLER"].rsplit(".", 1)
    except ValueError:
        raise ValueError(
            "Improperly formated handler value: %s" % os.environ["IOPIPE_HANDLER"]
        )

    module_path = module_path.replace("/", ".")
    file_handle, pathname, desc = None, None, None

    try:
        for segment in module_path.split("."):
            if pathname is not None:
                pathname = [pathname]

            file_handle, pathname, desc = imp.find_module(segment, pathname)

        if file_handle is None:
            module_type = desc[2]
            if module_type == imp.C_BUILTIN:
                raise ImportError(
                    "Cannot use built-in module %s as a handler module" % module_path
                )

        module = imp.load_module(module_path, file_handle, pathname, desc)
    except Exception as e:
        raise ImportError("Failed to import module: %s" % module_path)
    finally:
        if file_handle is not None:
            file_handle.close()

    try:
        handler = getattr(module, handler_name)
    except AttributeError as e:
        raise AttributeError("No handler %s in module %s" % (handler_name, module_path))

    return handler 
開發者ID:iopipe,項目名稱:iopipe-python,代碼行數:43,代碼來源:handler.py

示例7: _file_from_modpath

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def _file_from_modpath(modpath, path=None, context=None):
    """given a mod path (ie splited module / package name), return the
    corresponding file

    this function is used internally, see `file_from_modpath`'s
    documentation for more information
    """
    assert len(modpath) > 0
    if context is not None:
        try:
            mtype, mp_filename = _module_file(modpath, [context])
        except ImportError:
            mtype, mp_filename = _module_file(modpath, path)
    else:
        mtype, mp_filename = _module_file(modpath, path)
    if mtype == PY_COMPILED:
        try:
            return get_source_file(mp_filename)
        except NoSourceFile:
            return mp_filename
    elif mtype == C_BUILTIN:
        # integrated builtin module
        return None
    elif mtype == PKG_DIRECTORY:
        mp_filename = _has_init(mp_filename)
    return mp_filename 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:28,代碼來源:modutils.py

示例8: find_module

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def find_module(self, fullname, path=None):
    if (fullname in _WHITE_LIST_C_MODULES or
        any(regex.match(fullname) for regex in self._enabled_regexes)):
      return None
    if self._module_type(fullname, path) in [imp.C_EXTENSION, imp.C_BUILTIN]:
      return self
    return None 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:9,代碼來源:sandbox.py

示例9: _get_handler

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def _get_handler(handler):
    try:
        (modname, fname) = handler.rsplit('.', 1)
    except ValueError as e:
        fault = FaultException("Bad handler '{}'".format(handler), str(e), None)
        request_handler = make_fault_handler(fault)
        return request_handler

    file_handle, pathname, desc = None, None, None
    try:
        # Recursively loading handler in nested directories
        for segment in modname.split('.'):
            if pathname is not None:
                pathname = [pathname]
            file_handle, pathname, desc = imp.find_module(segment, pathname)
        if file_handle is None:
            module_type = desc[2]
            if module_type == imp.C_BUILTIN:
                fault = FaultException("Cannot use built-in module {} as a handler module".format(modname), None, None)
                request_handler = make_fault_handler(fault)
                return request_handler
        m = imp.load_module(modname, file_handle, pathname, desc)
    except ImportError as e:
        fault = FaultException("Unable to import module '{}'".format(modname), str(e), None)
        request_handler = make_fault_handler(fault)
        return request_handler
    except SyntaxError as e:
        trace = "File \"%s\" Line %s\n\t%s" % (e.filename, e.lineno, e.text)
        fault = FaultException("Syntax error in module '{}'".format(modname), str(e), trace)
        request_handler = make_fault_handler(fault)
        return request_handler
    finally:
        if file_handle is not None:
            file_handle.close()

    try:
        request_handler = getattr(m, fname)
    except AttributeError as e:
        fault = FaultException("Handler '{}' missing on module '{}'".format(fname, modname), str(e), None)
        request_handler = make_fault_handler(fault)
    return request_handler 
開發者ID:triggermesh,項目名稱:knative-lambda-runtime,代碼行數:43,代碼來源:bootstrap.py

示例10: getmod

# 需要導入模塊: import imp [as 別名]
# 或者: from imp import C_BUILTIN [as 別名]
def getmod(self, nm, isbuiltin=imp.is_builtin):
        if isbuiltin(nm):
            mod = imp.load_module(nm, None, nm, ('', '', imp.C_BUILTIN))
            return mod
        return None 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:7,代碼來源:ImportManager.py


注:本文中的imp.C_BUILTIN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。