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


Python utils.PY3属性代码示例

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


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

示例1: scrub_py2_sys_modules

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def scrub_py2_sys_modules():
    """
    Removes any Python 2 standard library modules from ``sys.modules`` that
    would interfere with Py3-style imports using import hooks. Examples are
    modules with the same names (like urllib or email).

    (Note that currently import hooks are disabled for modules like these
    with ambiguous names anyway ...)
    """
    if PY3:
        return {}
    scrubbed = {}
    for modulename in REPLACED_MODULES & set(RENAMES.keys()):
        if not modulename in sys.modules:
            continue

        module = sys.modules[modulename]

        if is_py2_stdlib_module(module):
            flog.debug('Deleting (Py2) {} from sys.modules'.format(modulename))
            scrubbed[modulename] = sys.modules[modulename]
            del sys.modules[modulename]
    return scrubbed 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:__init__.py

示例2: install_hooks

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

示例3: remove_hooks

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def remove_hooks(scrub_sys_modules=False):
    """
    This function removes the import hook from sys.meta_path.
    """
    if PY3:
        return
    flog.debug('Uninstalling hooks ...')
    # Loop backwards, so deleting items keeps the ordering:
    for i, hook in list(enumerate(sys.meta_path))[::-1]:
        if hasattr(hook, 'RENAMER'):
            del sys.meta_path[i]

    # Explicit is better than implicit. In the future the interface should
    # probably change so that scrubbing the import hooks requires a separate
    # function call. Left as is for now for backward compatibility with
    # v0.11.x.
    if scrub_sys_modules:
        scrub_future_sys_modules() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:20,代码来源:__init__.py

示例4: detect_hooks

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

示例5: test_setdefault_atomic

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def test_setdefault_atomic(self):
        # Issue #13521: setdefault() calls __hash__ and __eq__ only once.
        class Hashed(object):
            def __init__(self):
                self.hash_count = 0
                self.eq_count = 0
            def __hash__(self):
                self.hash_count += 1
                return 42
            def __eq__(self, other):
                self.eq_count += 1
                return id(self) == id(other)
        hashed1 = Hashed()
        y = dict({hashed1: 5})
        hashed2 = Hashed()
        y.setdefault(hashed2, [])
        self.assertEqual(hashed1.hash_count, 1)
        if PY3:
            self.assertEqual(hashed2.hash_count, 1)
            self.assertEqual(hashed1.eq_count + hashed2.eq_count, 1) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:22,代码来源:test_olddict.py

示例6: sendall

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def sendall(self, data):
        # self.data += bytes(data)
        olddata = self.data
        assert isinstance(olddata, bytes)
        if utils.PY3:
            self.data += data
        else:
            if isinstance(data, type(u'')):     # i.e. unicode
                newdata = data.encode('ascii')
            elif isinstance(data, type(b'')):   # native string type. FIXME!
                newdata = bytes(data)
            elif isinstance(data, bytes):
                newdata = data
            elif isinstance(data, array.array):
                newdata = data.tostring()
            else:
                newdata = bytes(b'').join(chr(d) for d in bytes(data))
            self.data += newdata 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:20,代码来源:test_httplib.py

示例7: test_send

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def test_send(self):
        expected = bytes(b'this is a test this is only a test')
        conn = client.HTTPConnection('example.com')
        sock = FakeSocket(None)
        conn.sock = sock
        conn.send(expected)
        self.assertEqual(expected, sock.data)
        sock.data = bytes(b'')
        if utils.PY3:
            mydata = array.array('b', expected)
        else:
            mydata = array.array(b'b', expected)
        conn.send(mydata)
        self.assertEqual(expected, sock.data)
        sock.data = bytes(b'')
        conn.send(io.BytesIO(expected))
        self.assertEqual(expected, sock.data) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:19,代码来源:test_httplib.py

示例8: is_py2_stdlib_module

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def is_py2_stdlib_module(m):
    """
    Tries to infer whether the module m is from the Python 2 standard library.
    This may not be reliable on all systems.
    """
    if PY3:
        return False
    if not 'stdlib_path' in is_py2_stdlib_module.__dict__:
        stdlib_files = [contextlib.__file__, os.__file__, copy.__file__]
        stdlib_paths = [os.path.split(f)[0] for f in stdlib_files]
        if not len(set(stdlib_paths)) == 1:
            # This seems to happen on travis-ci.org. Very strange. We'll try to
            # ignore it.
            flog.warn('Multiple locations found for the Python standard '
                         'library: %s' % stdlib_paths)
        # Choose the first one arbitrarily
        is_py2_stdlib_module.stdlib_path = stdlib_paths[0]

    if m.__name__ in sys.builtin_module_names:
        return True

    if hasattr(m, '__file__'):
        modpath = os.path.split(m.__file__)
        if (modpath[0].startswith(is_py2_stdlib_module.stdlib_path) and
            'site-packages' not in modpath[0]):
            return True

    return False 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:30,代码来源:__init__.py

示例9: u

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def u(text):
    if utils.PY3:
        return text
    else:
        return text.decode('unicode_escape') 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:7,代码来源:surrogateescape.py

示例10: b

# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import PY3 [as 别名]
def b(data):
    if utils.PY3:
        return data.encode('latin1')
    else:
        return data 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:7,代码来源:surrogateescape.py


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