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


Python standard_library.install_hooks方法代码示例

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


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

示例1: install_hooks

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def install_hooks():
    """
    This function installs the future.standard_library import hook into
    sys.meta_path.
    """
    if PY3:
        return

    install_aliases()

    flog.debug('sys.meta_path was: {0}'.format(sys.meta_path))
    flog.debug('Installing hooks ...')

    # Add it unless it's there already
    newhook = RenameImport(RENAMES)
    if not detect_hooks():
        sys.meta_path.append(newhook)
    flog.debug('sys.meta_path is now: {0}'.format(sys.meta_path)) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:20,代码来源:__init__.py

示例2: detect_hooks

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def detect_hooks():
    """
    Returns True if the import hooks are installed, False if not.
    """
    flog.debug('Detecting hooks ...')
    present = any([hasattr(hook, 'RENAMER') for hook in sys.meta_path])
    if present:
        flog.debug('Detected.')
    else:
        flog.debug('Not detected.')
    return present


# As of v0.12, this no longer happens implicitly:
# if not PY3:
#     install_hooks() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:__init__.py

示例3: test_remove_hooks_then_requests

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def test_remove_hooks_then_requests(self):
        code = """
            from future import standard_library
            standard_library.install_hooks()

            import builtins
            import http.client
            import html.parser
            """
        with write_module(code, self.tempdir):
            import test_imports_future_stdlib
            standard_library.remove_hooks()
            try:
                import requests
            except ImportError:
                print("Requests doesn't seem to be available. Skipping requests test ...")
            else:
                r = requests.get('http://google.com')
                self.assertTrue(r)
            self.assertTrue(True) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:22,代码来源:test_requests.py

示例4: __enter__

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def __enter__(self):
        # flog.debug('Entering hooks context manager')
        self.old_sys_modules = copy.copy(sys.modules)
        self.hooks_were_installed = detect_hooks()
        # self.scrubbed = scrub_py2_sys_modules()
        install_hooks()
        return self 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:9,代码来源:__init__.py

示例5: __exit__

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def __exit__(self, *args):
        if self.hooks_were_installed:
            install_hooks()
        # restore_sys_modules(self.scrubbed) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:6,代码来源:__init__.py

示例6: enable_hooks

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def enable_hooks():
    """
    Deprecated. Use install_hooks() instead. This will be removed by
    ``future`` v1.0.
    """
    install_hooks() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:8,代码来源:__init__.py

示例7: transform

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_hooks [as 别名]
def transform(self, node, results):
        # TODO: add a blank line between any __future__ imports and this?
        touch_import_top(u'future', u'standard_library', node)
        # TODO: also add standard_library.install_hooks() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:fix_add_future_standard_library_import.py


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