本文整理匯總了Python中imp.init_builtin方法的典型用法代碼示例。如果您正苦於以下問題:Python imp.init_builtin方法的具體用法?Python imp.init_builtin怎麽用?Python imp.init_builtin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類imp
的用法示例。
在下文中一共展示了imp.init_builtin方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_module
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_builtin [as 別名]
def load_module(self, name, stuff):
file, filename, info = stuff
(suff, mode, type) = info
try:
if type == BUILTIN_MODULE:
return self.hooks.init_builtin(name)
if type == FROZEN_MODULE:
return self.hooks.init_frozen(name)
if type == C_EXTENSION:
m = self.hooks.load_dynamic(name, filename, file)
elif type == PY_SOURCE:
m = self.hooks.load_source(name, filename, file)
elif type == PY_COMPILED:
m = self.hooks.load_compiled(name, filename, file)
elif type == PKG_DIRECTORY:
m = self.hooks.load_package(name, filename, file)
else:
raise ImportError, "Unrecognized module type (%r) for %s" % \
(type, name)
finally:
if file: file.close()
m.__file__ = filename
return m
示例2: init_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_builtin [as 別名]
def init_builtin(self, name): return imp.init_builtin(name)
示例3: test_is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_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")
示例4: test_init_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_builtin [as 別名]
def test_init_builtin(self):
r = imp.init_builtin("c_Pickle")
self.assertEqual(r,None)
r = imp.init_builtin("2345")
self.assertEqual(r,None)
r = imp.init_builtin("xxxx")
self.assertEqual(r,None)
r = imp.init_builtin("^$%$#@")
self.assertEqual(r,None)
r = imp.init_builtin("_locale")
self.assertTrue(r!=None)
示例5: test_is_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_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: test_init_builtin
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_builtin [as 別名]
def test_init_builtin(self):
r = imp.init_builtin("c_Pickle")
self.assertEqual(r,None)
r = imp.init_builtin("2345")
self.assertEqual(r,None)
r = imp.init_builtin("xxxx")
self.assertEqual(r,None)
r = imp.init_builtin("^$%$#@")
self.assertEqual(r,None)
r = imp.init_builtin("_locale")
self.assertTrue(r!=None)
示例7: getmod
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import init_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)