本文整理汇总了Python中imp.PY_FROZEN属性的典型用法代码示例。如果您正苦于以下问题:Python imp.PY_FROZEN属性的具体用法?Python imp.PY_FROZEN怎么用?Python imp.PY_FROZEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类imp
的用法示例。
在下文中一共展示了imp.PY_FROZEN属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_py_frozen
# 需要导入模块: import imp [as 别名]
# 或者: from imp import PY_FROZEN [as 别名]
def test_py_frozen(self):
imp.find_module('bar', ['foo']).AndReturn((None, 'bar',
(None, None, imp.PY_FROZEN)))
self.mox.ReplayAll()
self.assertIsNone(self.hook.find_module('foo.bar', ['foo']))
示例2: get_module_constant
# 需要导入模块: import imp [as 别名]
# 或者: from imp import PY_FROZEN [as 别名]
def get_module_constant(module, symbol, default=-1, paths=None):
"""Find 'module' by searching 'paths', and extract 'symbol'
Return 'None' if 'module' does not exist on 'paths', or it does not define
'symbol'. If the module defines 'symbol' as a constant, return the
constant. Otherwise, return 'default'."""
try:
f, path, (suffix, mode, kind) = find_module(module, paths)
except ImportError:
# Module doesn't exist
return None
try:
if kind==PY_COMPILED:
f.read(8) # skip magic & date
code = marshal.load(f)
elif kind==PY_FROZEN:
code = imp.get_frozen_object(module)
elif kind==PY_SOURCE:
code = compile(f.read(), path, 'exec')
else:
# Not something we can parse; we'll have to import it. :(
if module not in sys.modules:
imp.load_module(module, f, path, (suffix, mode, kind))
return getattr(sys.modules[module], symbol, None)
finally:
if f:
f.close()
return extract_constant(code, symbol, default)
示例3: get_module_constant
# 需要导入模块: import imp [as 别名]
# 或者: from imp import PY_FROZEN [as 别名]
def get_module_constant(module, symbol, default=-1, paths=None):
"""Find 'module' by searching 'paths', and extract 'symbol'
Return 'None' if 'module' does not exist on 'paths', or it does not define
'symbol'. If the module defines 'symbol' as a constant, return the
constant. Otherwise, return 'default'."""
try:
f, path, (suffix, mode, kind) = find_module(module, paths)
except ImportError:
# Module doesn't exist
return None
try:
if kind == PY_COMPILED:
f.read(8) # skip magic & date
code = marshal.load(f)
elif kind == PY_FROZEN:
code = imp.get_frozen_object(module)
elif kind == PY_SOURCE:
code = compile(f.read(), path, 'exec')
else:
# Not something we can parse; we'll have to import it. :(
if module not in sys.modules:
imp.load_module(module, f, path, (suffix, mode, kind))
return getattr(sys.modules[module], symbol, None)
finally:
if f:
f.close()
return extract_constant(code, symbol, default)
示例4: get_module_constant
# 需要导入模块: import imp [as 别名]
# 或者: from imp import PY_FROZEN [as 别名]
def get_module_constant(module, symbol, default=-1, paths=None):
"""Find 'module' by searching 'paths', and extract 'symbol'
Return 'None' if 'module' does not exist on 'paths', or it does not define
'symbol'. If the module defines 'symbol' as a constant, return the
constant. Otherwise, return 'default'."""
try:
f, path, (suffix,mode,kind) = find_module(module,paths)
except ImportError:
# Module doesn't exist
return None
try:
if kind==PY_COMPILED:
f.read(8) # skip magic & date
code = marshal.load(f)
elif kind==PY_FROZEN:
code = imp.get_frozen_object(module)
elif kind==PY_SOURCE:
code = compile(f.read(), path, 'exec')
else:
# Not something we can parse; we'll have to import it. :(
if module not in sys.modules:
imp.load_module(module,f,path,(suffix,mode,kind))
return getattr(sys.modules[module],symbol,None)
finally:
if f:
f.close()
return extract_constant(code,symbol,default)
示例5: test_flags
# 需要导入模块: import imp [as 别名]
# 或者: from imp import PY_FROZEN [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)
示例6: get_module_constant
# 需要导入模块: import imp [as 别名]
# 或者: from imp import PY_FROZEN [as 别名]
def get_module_constant(module, symbol, default=-1, paths=None):
"""Find 'module' by searching 'paths', and extract 'symbol'
Return 'None' if 'module' does not exist on 'paths', or it does not define
'symbol'. If the module defines 'symbol' as a constant, return the
constant. Otherwise, return 'default'."""
try:
f, path, (suffix, mode, kind) = find_module(module, paths)
except ImportError:
# Module doesn't exist
return None
try:
if kind == PY_COMPILED:
f.read(8) # skip magic & date
code = marshal.load(f)
elif kind == PY_FROZEN:
code = imp.get_frozen_object(module)
elif kind == PY_SOURCE:
code = compile(f.read(), path, 'exec')
else:
# Not something we can parse; we'll have to import it. :(
if module not in sys.modules:
imp.load_module(module, f, path, (suffix, mode, kind))
return getattr(sys.modules[module], symbol, None)
finally:
if f:
f.close()
return extract_constant(code, symbol, default)