PHP 8.2.30
Preview: _version_info.py Size: 2.11 KB
//opt/alt/python37/lib/python3.7/site-packages/attr/_version_info.py

from __future__ import absolute_import, division, print_function

from functools import total_ordering

from ._funcs import astuple
from ._make import attrib, attrs


@total_ordering
@attrs(eq=False, order=False, slots=True, frozen=True)
class VersionInfo(object):
    """
    A version object that can be compared to tuple of length 1--4:

    >>> attr.VersionInfo(19, 1, 0, "final")  <= (19, 2)
    True
    >>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1)
    True
    >>> vi = attr.VersionInfo(19, 2, 0, "final")
    >>> vi < (19, 1, 1)
    False
    >>> vi < (19,)
    False
    >>> vi == (19, 2,)
    True
    >>> vi == (19, 2, 1)
    False

    .. versionadded:: 19.2
    """

    year = attrib(type=int)
    minor = attrib(type=int)
    micro = attrib(type=int)
    releaselevel = attrib(type=str)

    @classmethod
    def _from_version_string(cls, s):
        """
        Parse *s* and return a _VersionInfo.
        """
        v = s.split(".")
        if len(v) == 3:
            v.append("final")

        return cls(
            year=int(v[0]), minor=int(v[1]), micro=int(v[2]), releaselevel=v[3]
        )

    def _ensure_tuple(self, other):
        """
        Ensure *other* is a tuple of a valid length.

        Returns a possibly transformed *other* and ourselves as a tuple of
        the same length as *other*.
        """

        if self.__class__ is other.__class__:
            other = astuple(other)

        if not isinstance(other, tuple):
            raise NotImplementedError

        if not (1 <= len(other) <= 4):
            raise NotImplementedError

        return astuple(self)[: len(other)], other

    def __eq__(self, other):
        try:
            us, them = self._ensure_tuple(other)
        except NotImplementedError:
            return NotImplemented

        return us == them

    def __lt__(self, other):
        try:
            us, them = self._ensure_tuple(other)
        except NotImplementedError:
            return NotImplemented

        # Since alphabetically "dev0" < "final" < "post1" < "post2", we don't
        # have to do anything special with releaselevel for now.
        return us < them

Directory Contents

Dirs: 1 × Files: 22

Name Size Perms Modified Actions
- drwxr-xr-x 2024-03-03 23:11:35
Edit Download
2.97 KB lrw-r--r-- 2021-02-18 15:38:25
Edit Download
382 B lrw-r--r-- 2021-02-19 07:15:51
Edit Download
1.90 KB lrw-r--r-- 2021-04-30 12:38:44
Edit Download
540 B lrw-r--r-- 2021-02-19 07:15:51
Edit Download
1.07 KB lrw-r--r-- 2020-03-29 07:56:49
Edit Download
216 B lrw-r--r-- 2021-02-19 07:15:51
Edit Download
0 B lrw-r--r-- 2018-07-12 10:28:53
Edit Download
1.40 KB lrw-r--r-- 2020-07-20 10:43:42
Edit Download
574 B lrw-r--r-- 2021-04-06 04:14:02
Edit Download
11.23 KB lrw-r--r-- 2020-07-20 10:43:42
Edit Download
1.83 KB lrw-r--r-- 2021-02-19 07:15:51
Edit Download
4.04 KB lrw-r--r-- 2021-05-06 07:03:24
Edit Download
318 B lrw-r--r-- 2021-05-01 12:26:39
Edit Download
7.38 KB lrw-r--r-- 2021-02-27 09:49:47
Edit Download
514 B lrw-r--r-- 2019-10-17 08:29:00
Edit Download
13.08 KB lrw-r--r-- 2021-05-06 14:11:04
Edit Download
95.45 KB lrw-r--r-- 2021-05-05 08:05:42
Edit Download
3.98 KB lrw-r--r-- 2021-04-12 12:35:56
Edit Download
2.11 KB lrw-r--r-- 2020-03-29 07:56:49
Edit Download
209 B lrw-r--r-- 2020-03-29 07:56:49
Edit Download
1.58 KB lrw-r--r-- 2021-05-07 09:20:15
Edit Download
14.49 KB lrw-r--r-- 2021-05-05 08:25:16
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).