本文整理匯總了Python中imp.is_builtin方法的典型用法代碼示例。如果您正苦於以下問題:Python imp.is_builtin方法的具體用法?Python imp.is_builtin怎麽用?Python imp.is_builtin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類imp
的用法示例。
在下文中一共展示了imp.is_builtin方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_sys_path_none_builtins
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def test_sys_path_none_builtins(self):
prevPath = sys.path
#import some builtin modules not previously imported
try:
sys.path = prevPath + [None]
if not imp.is_builtin('copy_reg'):
self.assertTrue('copy_reg' not in sys.modules.keys())
import datetime
import copy_reg
self.assertTrue('datetime' in sys.modules.keys())
self.assertTrue('copy_reg' in sys.modules.keys())
sys.path = [None]
if not imp.is_builtin('binascii'):
self.assertTrue('binascii' not in sys.modules.keys())
import datetime
import copy_reg
import binascii
self.assertTrue('datetime' in sys.modules.keys())
self.assertTrue('copy_reg' in sys.modules.keys())
self.assertTrue('binascii' in sys.modules.keys())
finally:
sys.path = prevPath
示例2: find_builtin_module
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
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
示例3: is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def is_builtin(self, name): return imp.is_builtin(name)
示例4: test_is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def test_is_builtin(self):
self.assertEqual(imp.is_builtin("xxx"),0)
self.assertEqual(imp.is_builtin("12324"),0)
self.assertEqual(imp.is_builtin("&*^^"),0)
self.assertEqual(imp.is_builtin("dir"),0)
self.assertEqual(imp.is_builtin("__doc__"),0)
self.assertEqual(imp.is_builtin("__name__"),0)
self.assertEqual(imp.is_builtin("_locle"),0)
self.assertEqual(imp.is_builtin("cPickle"),1)
self.assertEqual(imp.is_builtin("_random"),1)
if is_posix:
self.assertEqual(imp.is_builtin("posix"),1)
else:
self.assertEqual(imp.is_builtin("nt"),1)
self.assertEqual(imp.is_builtin("thread"),1)
# there are a several differences between ironpython and cpython
if is_cli:
self.assertEqual(imp.is_builtin("copy_reg"),1)
else:
self.assertEqual(imp.is_builtin("copy_reg"),0)
# supposedly you can't re-init these
self.assertEqual(imp.is_builtin("sys"), -1)
self.assertEqual(imp.is_builtin("__builtin__"), -1)
self.assertEqual(imp.is_builtin("exceptions"), -1)
imp.init_builtin("sys")
imp.init_builtin("__builtin__")
imp.init_builtin("exceptions")
示例5: test_is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def test_is_builtin(self):
self.assertEqual(imp.is_builtin("xxx"),0)
self.assertEqual(imp.is_builtin("12324"),0)
self.assertEqual(imp.is_builtin("&*^^"),0)
self.assertEqual(imp.is_builtin("dir"),0)
self.assertEqual(imp.is_builtin("__doc__"),0)
self.assertEqual(imp.is_builtin("__name__"),0)
self.assertEqual(imp.is_builtin("_locle"),0)
if is_cli:
self.assertEqual(imp.is_builtin("_pickle"),0)
else:
self.assertEqual(imp.is_builtin("_pickle"),1)
self.assertEqual(imp.is_builtin("_random"),1)
# nt module disabled in Silverlight
if is_posix:
self.assertEqual(imp.is_builtin("posix"),1)
else:
self.assertEqual(imp.is_builtin("nt"),1)
self.assertEqual(imp.is_builtin("_thread"),1)
# there are a several differences between ironpython and cpython
if is_cli:
self.assertEqual(imp.is_builtin("copyreg"),1)
else:
self.assertEqual(imp.is_builtin("copyreg"),0)
# supposedly you can't re-init these
self.assertEqual(imp.is_builtin("sys"), -1)
self.assertEqual(imp.is_builtin("builtins"), -1)
imp.init_builtin("sys")
imp.init_builtin("builtins")
示例6: get
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
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
示例7: test_imp_is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def test_imp_is_builtin(self):
self.assertTrue(all(imp.is_builtin(mod)
for mod in ['sys', '__builtin__', 'imp']))
self.assertFalse(imp.is_builtin('os'))
示例8: is_stdlib_name
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def is_stdlib_name(modname):
"""
Return :data:`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 = os.path.abspath(getattr(module, '__file__', ''))
return is_stdlib_path(modpath)
示例9: getmod
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def getmod(self, nm, isbuiltin=imp.is_builtin):
if isbuiltin(nm):
return depend.modules.BuiltinModule(nm)
return None
示例10: getmod
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def getmod(self, nm, isbuiltin=imp.is_builtin):
# Return initialized built-in module object or None
# if there is no built-in module with that name.
return imp.init_builtin(nm)
示例11: test_imp_is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import is_builtin [as 別名]
def test_imp_is_builtin(self):
self.assertTrue(all(imp.is_builtin(mod)
for mod in ['sys', '__builtin__']))
self.assertFalse(imp.is_builtin('os'))