当前位置: 首页>>代码示例>>Python>>正文


Python imp.get_frozen_object方法代码示例

本文整理汇总了Python中imp.get_frozen_object方法的典型用法代码示例。如果您正苦于以下问题:Python imp.get_frozen_object方法的具体用法?Python imp.get_frozen_object怎么用?Python imp.get_frozen_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imp的用法示例。


在下文中一共展示了imp.get_frozen_object方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_module_constant

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [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) 
开发者ID:jpush,项目名称:jbox,代码行数:35,代码来源:depends.py

示例2: get_module_constant

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [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) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:34,代码来源:depends.py

示例3: get_frozen_object

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [as 别名]
def get_frozen_object(self, name): return imp.get_frozen_object(name) 
开发者ID:glmcdona,项目名称:meddle,代码行数:3,代码来源:ihooks.py

示例4: get_module_constant

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [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) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:35,代码来源:depends.py

示例5: test_get_frozen_object

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [as 别名]
def test_get_frozen_object(self):
        # frozen objects not supported, this always fails
        self.assertRaises(ImportError, imp.get_frozen_object, 'foo') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_imp.py

示例6: get_module_constant

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [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) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:34,代码来源:depends.py

示例7: get_frozen_object

# 需要导入模块: import imp [as 别名]
# 或者: from imp import get_frozen_object [as 别名]
def get_frozen_object(module, paths):
        return imp.get_frozen_object(module) 
开发者ID:pantsbuild,项目名称:pex,代码行数:4,代码来源:py27compat.py


注:本文中的imp.get_frozen_object方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。