當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.PY2屬性代碼示例

本文整理匯總了Python中future.utils.PY2屬性的典型用法代碼示例。如果您正苦於以下問題:Python utils.PY2屬性的具體用法?Python utils.PY2怎麽用?Python utils.PY2使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在future.utils的用法示例。


在下文中一共展示了utils.PY2屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __new__

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def __new__(cls, offset, name=_Omitted):
        if not isinstance(offset, timedelta):
            raise TypeError("offset must be a timedelta")
        if name is cls._Omitted:
            if not offset:
                return cls.utc
            name = None
        elif not isinstance(name, str):
            ###
            # For Python-Future:
            if PY2 and isinstance(name, native_str):
                name = name.decode()
            else:
                raise TypeError("name must be a string")
            ###
        if not cls._minoffset <= offset <= cls._maxoffset:
            raise ValueError("offset must be a timedelta"
                             " strictly between -timedelta(hours=24) and"
                             " timedelta(hours=24).")
        if (offset.microseconds != 0 or
            offset.seconds % 60 != 0):
            raise ValueError("offset must be a timedelta"
                             " representing a whole number of minutes")
        return cls._create(offset, name) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:26,代碼來源:datetime.py

示例2: test_suspend_hooks

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def test_suspend_hooks(self):
        """
        Code like the try/except block here appears in Pyflakes v0.6.1. This
        method tests whether suspend_hooks() works as advertised.
        """
        example_PY2_check = False
        with standard_library.suspend_hooks():
            # An example of fragile import code that we don't want to break:
            try:
                import builtins
            except ImportError:
                example_PY2_check = True
        if utils.PY2:
            self.assertTrue(example_PY2_check)
        else:
            self.assertFalse(example_PY2_check)
        # The import should succeed again now:
        import builtins 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:20,代碼來源:test_standard_library.py

示例3: test_call_with_args_does_nothing

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def test_call_with_args_does_nothing(self):
        if utils.PY2:
            from __builtin__ import super as builtin_super
        else:
            from builtins import super as builtin_super
        class Base(object):
            def calc(self,value):
                return 2 * value
        class Sub1(Base):
            def calc(self,value):
                return 7 + super().calc(value)
        class Sub2(Base):
            def calc(self,value):
                return super().calc(value) - 1
        class Diamond(Sub1,Sub2):
            def calc(self,value):
                return 3 * super().calc(value)
        for cls in (Base,Sub1,Sub2,Diamond,):
            obj = cls()
            self.assertSuperEquals(builtin_super(cls), super(cls))
            self.assertSuperEquals(builtin_super(cls,obj), super(cls,obj)) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:23,代碼來源:test_magicsuper.py

示例4: test_startswith

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def test_startswith(self):
        s = str('abcd')
        self.assertTrue(s.startswith('a'))
        self.assertTrue(s.startswith(('a', 'd')))
        self.assertTrue(s.startswith(str('ab')))
        if utils.PY2:
            # We allow this, because e.g. Python 2 os.path.join concatenates
            # its arg with a byte-string '/' indiscriminately.
            self.assertFalse(s.startswith(b'A'))
            self.assertTrue(s.startswith(b'a'))
        with self.assertRaises(TypeError) as cm:
            self.assertFalse(s.startswith(bytes(b'A')))
        with self.assertRaises(TypeError) as cm:
            s.startswith((bytes(b'A'), bytes(b'B')))
        with self.assertRaises(TypeError) as cm:
            s.startswith(65) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:18,代碼來源:test_str.py

示例5: test_mul

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def test_mul(self):
        s = str(u'ABC')
        c = s * 4
        self.assertTrue(isinstance(c, str))
        self.assertEqual(c, u'ABCABCABCABC')
        d = s * int(4)
        self.assertTrue(isinstance(d, str))
        self.assertEqual(d, u'ABCABCABCABC')
        if utils.PY2:
            e = s * long(4)
            self.assertTrue(isinstance(e, str))
            self.assertEqual(e, u'ABCABCABCABC')
        with self.assertRaises(TypeError):
            s * 3.3
        with self.assertRaises(TypeError):
            s * (3.3 + 3j) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:18,代碼來源:test_str.py

示例6: test_rmul

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def test_rmul(self):
        s = str(u'XYZ')
        c = 3 * s
        self.assertTrue(isinstance(c, str))
        self.assertEqual(c, u'XYZXYZXYZ')
        d = s * int(3)
        self.assertTrue(isinstance(d, str))
        self.assertEqual(d, u'XYZXYZXYZ')
        if utils.PY2:
            e = long(3) * s
            self.assertTrue(isinstance(e, str))
            self.assertEqual(e, u'XYZXYZXYZ')
        with self.assertRaises(TypeError):
            3.3 * s
        with self.assertRaises(TypeError):
            (3.3 + 3j) * s 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:18,代碼來源:test_str.py

示例7: _safe_readinto

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def _safe_readinto(self, b):
        """Same as _safe_read, but for reading into a buffer."""
        total_bytes = 0
        mvb = memoryview(b)
        while total_bytes < len(b):
            if MAXAMOUNT < len(mvb):
                temp_mvb = mvb[0:MAXAMOUNT]
                if PY2:
                    data = self.fp.read(len(temp_mvb))
                    n = len(data)
                    temp_mvb[:n] = data
                else:
                    n = self.fp.readinto(temp_mvb)
            else:
                if PY2:
                    data = self.fp.read(len(mvb))
                    n = len(data)
                    mvb[:n] = data
                else:
                    n = self.fp.readinto(mvb)
            if not n:
                raise IncompleteRead(bytes(mvb[0:total_bytes]), len(b))
            mvb = mvb[n:]
            total_bytes += n
        return total_bytes 
開發者ID:alfa-addon,項目名稱:addon,代碼行數:27,代碼來源:client.py

示例8: idle_cpu_count

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def idle_cpu_count(mincpu=1):
    """Estimate number of idle CPUs, for use by multiprocessing code
    needing to determine how many processes can be run without excessive
    load. This function uses :func:`os.getloadavg` which is only available
    under a Unix OS.

    Parameters
    ----------
    mincpu : int
      Minimum number of CPUs to report, independent of actual estimate

    Returns
    -------
    idle : int
      Estimate of number of idle CPUs
    """

    if PY2:
        ncpu = mp.cpu_count()
    else:
        ncpu = os.cpu_count()
    idle = int(ncpu - np.floor(os.getloadavg()[0]))
    return max(mincpu, idle) 
開發者ID:alphacsc,項目名稱:alphacsc,代碼行數:25,代碼來源:util.py

示例9: idle_cpu_count

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def idle_cpu_count(mincpu=1):
    """Estimate number of idle CPUs.

    Estimate number of idle CPUs, for use by multiprocessing code
    needing to determine how many processes can be run without excessive
    load. This function uses :func:`os.getloadavg` which is only available
    under a Unix OS.

    Parameters
    ----------
    mincpu : int
      Minimum number of CPUs to report, independent of actual estimate

    Returns
    -------
    idle : int
      Estimate of number of idle CPUs
    """

    if PY2:
        ncpu = mp.cpu_count()
    else:
        ncpu = os.cpu_count()
    idle = int(ncpu - np.floor(os.getloadavg()[0]))
    return max(mincpu, idle) 
開發者ID:bwohlberg,項目名稱:sporco,代碼行數:27,代碼來源:util.py

示例10: readinto

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def readinto(self, b):
        if self.fp is None:
            return 0

        if self._method == "HEAD":
            self._close_conn()
            return 0

        if self.chunked:
            return self._readinto_chunked(b)

        if self.length is not None:
            if len(b) > self.length:
                # clip the read to the "end of response"
                b = memoryview(b)[0:self.length]

        # we do not use _safe_read() here because this may be a .will_close
        # connection, and the user is reading more bytes than will be provided
        # (for example, reading in 1k chunks)

        if PY2:
            data = self.fp.read(len(b))
            n = len(data)
            b[:n] = data
        else:
            n = self.fp.readinto(b)

        if not n and b:
            # Ideally, we would raise IncompleteRead if the content-length
            # wasn't satisfied, but it might break compatibility.
            self._close_conn()
        elif self.length is not None:
            self.length -= n
            if not self.length:
                self._close_conn()
        return n 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:38,代碼來源:client.py

示例11: __repr__

# 需要導入模塊: from future import utils [as 別名]
# 或者: from future.utils import PY2 [as 別名]
def __repr__(self):
        if PY2 and isinstance(self.value, unicode):
            val = str(self.value)    # make it a newstr to remove the u prefix
        else:
            val = self.value
        return '<%s: %s=%s>' % (self.__class__.__name__,
                                str(self.key), repr(val)) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:9,代碼來源:cookies.py


注:本文中的future.utils.PY2屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。