我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用imp.is_builtin()。
def is_stdlib_name(self, modname): """Return ``True`` if `modname` appears to come from the standard library.""" if imp.is_builtin(modname) != 0: return True module = sys.modules.get(modname) if module is None: return False # six installs crap with no __file__ modpath = getattr(module, '__file__', '') if 'site-packages' in modpath: return False for dirname in self.STDLIB_DIRS: if os.path.commonprefix((dirname, modpath)) == dirname: return True return False
def find_builtin_module(self, name): # XXX frozen packages? if imp.is_builtin(name): return None, '', ('', '', BUILTIN_MODULE) if imp.is_frozen(name): return None, '', ('', '', FROZEN_MODULE) return None
def is_builtin(self, name): return imp.is_builtin(name)
def find_builtin_module(self, name): # XXX frozen packages? if self.hooks.is_builtin(name): return None, '', ('', '', BUILTIN_MODULE) if self.hooks.is_frozen(name): return None, '', ('', '', FROZEN_MODULE) return None
def get(self, fullname): if isinstance(fullname, str) and is_builtin(fullname) != 0: raise ImportError() imp = self._raw_get(fullname) if not imp.exists: raise ImportError() return imp