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


Python standard_library.install_aliases方法代码示例

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


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

示例1: install_hooks

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [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: test_urllib_refactor

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [as 别名]
def test_urllib_refactor(self):
        # Code like this using urllib is refactored by futurize --stage2 to use
        # the new Py3 module names, but ``future`` doesn't support urllib yet.
        before = """
        import urllib

        URL = 'http://pypi.python.org/pypi/future/json'
        package = 'future'
        r = urllib.urlopen(URL.format(package))
        data = r.read()
        """
        after = """
        from future import standard_library
        standard_library.install_aliases()
        import urllib.request
        
        URL = 'http://pypi.python.org/pypi/future/json'
        package = 'future'
        r = urllib.request.urlopen(URL.format(package))
        data = r.read()
        """
        self.convert_check(before, after) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:24,代码来源:test_futurize.py

示例3: strip_future_imports

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [as 别名]
def strip_future_imports(self, code):
        """
        Strips any of these import lines:

            from __future__ import <anything>
            from future <anything>
            from future.<anything>
            from builtins <anything>

        or any line containing:
            install_hooks()
        or:
            install_aliases()

        Limitation: doesn't handle imports split across multiple lines like
        this:

            from __future__ import (absolute_import, division, print_function,
                                    unicode_literals)
        """
        output = []
        # We need .splitlines(keepends=True), which doesn't exist on Py2,
        # so we use this instead:
        for line in code.split('\n'):
            if not (line.startswith('from __future__ import ')
                    or line.startswith('from future ')
                    or line.startswith('from builtins ')
                    or 'install_hooks()' in line
                    or 'install_aliases()' in line
                    # but don't match "from future_builtins" :)
                    or line.startswith('from future.')):
                output.append(line)
        return '\n'.join(output) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:35,代码来源:base.py

示例4: setUp

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [as 别名]
def setUp(self):
        self.interpreter = sys.executable
        standard_library.install_aliases()
        super(TestStandardLibraryReorganization, self).setUp() 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:6,代码来源:test_standard_library.py

示例5: test_urllib_imports_install_aliases

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [as 别名]
def test_urllib_imports_install_aliases(self):
        with standard_library.suspend_hooks():
            standard_library.install_aliases()
            import urllib
            import urllib.parse
            import urllib.request
            import urllib.robotparser
            import urllib.error
            import urllib.response
            self.assertTrue(True) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:12,代码来源:test_standard_library.py

示例6: test_all_imports

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [as 别名]
def test_all_imports(self):
        before = """
        import math
        import os
        l = range(10)
        assert isinstance(l, list)
        print 'Hello'
        for i in xrange(100):
            pass
        print('Hello')
        """
        after = """
        from __future__ import unicode_literals
        from __future__ import print_function
        from __future__ import division
        from __future__ import absolute_import
        from future import standard_library
        standard_library.install_aliases()
        from builtins import range
        from builtins import *
        import math
        import os
        l = list(range(10))
        assert isinstance(l, list)
        print('Hello')
        for i in range(100):
            pass
        print('Hello')
        """
        self.convert_check(before, after, all_imports=True) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:32,代码来源:test_futurize.py

示例7: setUp

# 需要导入模块: from future import standard_library [as 别名]
# 或者: from future.standard_library import install_aliases [as 别名]
def setUp(self):
        """
        The outputs from the various futurize stages should have the
        following headers:
        """
        # After stage1:
        # TODO: use this form after implementing a fixer to consolidate
        #       __future__ imports into a single line:
        # self.headers1 = """
        # from __future__ import absolute_import, division, print_function
        # """
        self.headers1 = reformat_code("""
        from __future__ import absolute_import
        from __future__ import division
        from __future__ import print_function
        """)

        # After stage2 --all-imports:
        # TODO: use this form after implementing a fixer to consolidate
        #       __future__ imports into a single line:
        # self.headers2 = """
        # from __future__ import (absolute_import, division,
        #                         print_function, unicode_literals)
        # from future import standard_library
        # from future.builtins import *
        # """
        self.headers2 = reformat_code("""
        from __future__ import absolute_import
        from __future__ import division
        from __future__ import print_function
        from __future__ import unicode_literals
        from future import standard_library
        standard_library.install_aliases()
        from builtins import *
        """)
        self.interpreters = [sys.executable]
        self.tempdir = tempfile.mkdtemp() + os.path.sep
        pypath = os.getenv('PYTHONPATH')
        if pypath:
            self.env = {'PYTHONPATH': os.getcwd() + os.pathsep + pypath}
        else:
            self.env = {'PYTHONPATH': os.getcwd()} 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:44,代码来源:base.py


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