PHP 8.2.30
Preview: serial.py Size: 3.52 KB
/opt/hc_python/lib/python3.12/site-packages/dns/serial.py

# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

"""Serial Number Arthimetic from RFC 1982"""


class Serial:
    def __init__(self, value: int, bits: int = 32):
        self.value = value % 2**bits
        self.bits = bits

    def __repr__(self):
        return f"dns.serial.Serial({self.value}, {self.bits})"

    def __eq__(self, other):
        if isinstance(other, int):
            other = Serial(other, self.bits)
        elif not isinstance(other, Serial) or other.bits != self.bits:
            return NotImplemented
        return self.value == other.value

    def __ne__(self, other):
        if isinstance(other, int):
            other = Serial(other, self.bits)
        elif not isinstance(other, Serial) or other.bits != self.bits:
            return NotImplemented
        return self.value != other.value

    def __lt__(self, other):
        if isinstance(other, int):
            other = Serial(other, self.bits)
        elif not isinstance(other, Serial) or other.bits != self.bits:
            return NotImplemented
        if self.value < other.value and other.value - self.value < 2 ** (self.bits - 1):
            return True
        elif self.value > other.value and self.value - other.value > 2 ** (
            self.bits - 1
        ):
            return True
        else:
            return False

    def __le__(self, other):
        return self == other or self < other

    def __gt__(self, other):
        if isinstance(other, int):
            other = Serial(other, self.bits)
        elif not isinstance(other, Serial) or other.bits != self.bits:
            return NotImplemented
        if self.value < other.value and other.value - self.value > 2 ** (self.bits - 1):
            return True
        elif self.value > other.value and self.value - other.value < 2 ** (
            self.bits - 1
        ):
            return True
        else:
            return False

    def __ge__(self, other):
        return self == other or self > other

    def __add__(self, other):
        v = self.value
        if isinstance(other, Serial):
            delta = other.value
        elif isinstance(other, int):
            delta = other
        else:
            raise ValueError
        if abs(delta) > (2 ** (self.bits - 1) - 1):
            raise ValueError
        v += delta
        v = v % 2**self.bits
        return Serial(v, self.bits)

    def __iadd__(self, other):
        v = self.value
        if isinstance(other, Serial):
            delta = other.value
        elif isinstance(other, int):
            delta = other
        else:
            raise ValueError
        if abs(delta) > (2 ** (self.bits - 1) - 1):
            raise ValueError
        v += delta
        v = v % 2**self.bits
        self.value = v
        return self

    def __sub__(self, other):
        v = self.value
        if isinstance(other, Serial):
            delta = other.value
        elif isinstance(other, int):
            delta = other
        else:
            raise ValueError
        if abs(delta) > (2 ** (self.bits - 1) - 1):
            raise ValueError
        v -= delta
        v = v % 2**self.bits
        return Serial(v, self.bits)

    def __isub__(self, other):
        v = self.value
        if isinstance(other, Serial):
            delta = other.value
        elif isinstance(other, int):
            delta = other
        else:
            raise ValueError
        if abs(delta) > (2 ** (self.bits - 1) - 1):
            raise ValueError
        v -= delta
        v = v % 2**self.bits
        self.value = v
        return self

Directory Contents

Dirs: 4 × Files: 56

Name Size Perms Modified Actions
- drwxr-xr-x 2025-04-04 08:02:00
Edit Download
quic DIR
- drwxr-xr-x 2025-04-04 08:02:00
Edit Download
rdtypes DIR
- drwxr-xr-x 2025-04-04 08:02:00
Edit Download
- drwxr-xr-x 2025-04-04 08:02:00
Edit Download
2.73 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
30.10 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
17.43 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
40.74 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
1.76 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
3.88 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
16.69 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
4.14 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
3.60 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
5.81 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.69 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.09 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
1.97 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
5.64 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.49 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
6.40 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
66.59 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
41.78 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
3.91 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
9.88 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
12.37 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.67 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
0 B lrw-r--r-- 2025-04-04 08:02:00
Edit Download
54.98 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
4.06 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
30.29 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.91 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
16.27 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
7.27 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
10.99 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
72.00 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
3.74 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
8.96 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
3.52 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
9.00 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
23.03 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
22.06 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
11.15 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.57 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.91 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
11.96 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
1.88 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
11.49 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
8.67 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.76 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
12.96 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
50.87 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
27.27 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
690 B lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.34 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
8.84 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
5.12 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.43 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
2.40 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
8.27 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download
1.62 KB lrw-r--r-- 2025-04-04 08:02:00
Edit Download

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