本文整理汇总了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))
示例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()
示例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)
示例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
示例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)
示例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()
示例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()