mabels-ipaddress 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. mabels_ipaddress-0.2.7/PKG-INFO +13 -0
  2. mabels_ipaddress-0.2.7/pyproject.toml +25 -0
  3. mabels_ipaddress-0.2.7/setup.cfg +4 -0
  4. mabels_ipaddress-0.2.7/src/ip_address/__init__.py +28 -0
  5. mabels_ipaddress-0.2.7/src/ip_address/ip_bits.py +120 -0
  6. mabels_ipaddress-0.2.7/src/ip_address/ip_version.py +9 -0
  7. mabels_ipaddress-0.2.7/src/ip_address/ipaddress.py +891 -0
  8. mabels_ipaddress-0.2.7/src/ip_address/ipv4.py +169 -0
  9. mabels_ipaddress-0.2.7/src/ip_address/ipv6.py +151 -0
  10. mabels_ipaddress-0.2.7/src/ip_address/ipv6_loopback.py +40 -0
  11. mabels_ipaddress-0.2.7/src/ip_address/ipv6_mapped.py +87 -0
  12. mabels_ipaddress-0.2.7/src/ip_address/ipv6_unspec.py +44 -0
  13. mabels_ipaddress-0.2.7/src/ip_address/prefix.py +117 -0
  14. mabels_ipaddress-0.2.7/src/ip_address/prefix128.py +26 -0
  15. mabels_ipaddress-0.2.7/src/ip_address/prefix32.py +21 -0
  16. mabels_ipaddress-0.2.7/src/ip_address/rle.py +60 -0
  17. mabels_ipaddress-0.2.7/src/mabels_ipaddress.egg-info/PKG-INFO +13 -0
  18. mabels_ipaddress-0.2.7/src/mabels_ipaddress.egg-info/SOURCES.txt +28 -0
  19. mabels_ipaddress-0.2.7/src/mabels_ipaddress.egg-info/dependency_links.txt +1 -0
  20. mabels_ipaddress-0.2.7/src/mabels_ipaddress.egg-info/requires.txt +4 -0
  21. mabels_ipaddress-0.2.7/src/mabels_ipaddress.egg-info/top_level.txt +1 -0
  22. mabels_ipaddress-0.2.7/tests/test_ipaddress.py +211 -0
  23. mabels_ipaddress-0.2.7/tests/test_ipv4.py +623 -0
  24. mabels_ipaddress-0.2.7/tests/test_ipv6.py +368 -0
  25. mabels_ipaddress-0.2.7/tests/test_ipv6_loopback.py +34 -0
  26. mabels_ipaddress-0.2.7/tests/test_ipv6_mapped.py +72 -0
  27. mabels_ipaddress-0.2.7/tests/test_ipv6_unspec.py +33 -0
  28. mabels_ipaddress-0.2.7/tests/test_prefix128.py +31 -0
  29. mabels_ipaddress-0.2.7/tests/test_prefix32.py +118 -0
  30. mabels_ipaddress-0.2.7/tests/test_rle.py +56 -0
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: mabels-ipaddress
3
+ Version: 0.2.7
4
+ Summary: ipaddress handles ipv4 and ipv6
5
+ Author-email: Meno Abels <meno.abels@adviser.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/mabels/ipaddress
8
+ Project-URL: Repository, https://github.com/mabels/ipaddress.git
9
+ Keywords: ip,ipv4,ipv6
10
+ Requires-Python: >=3.9
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest>=7.0; extra == "dev"
13
+ Requires-Dist: black>=24.0; extra == "dev"
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mabels-ipaddress"
7
+ version = "0.2.7"
8
+ description = "ipaddress handles ipv4 and ipv6"
9
+ license = { text = "MIT" }
10
+ authors = [{ name = "Meno Abels", email = "meno.abels@adviser.com" }]
11
+ requires-python = ">=3.9"
12
+ keywords = ["ip", "ipv4", "ipv6"]
13
+
14
+ [project.urls]
15
+ Homepage = "https://github.com/mabels/ipaddress"
16
+ Repository = "https://github.com/mabels/ipaddress.git"
17
+
18
+ [project.optional-dependencies]
19
+ dev = ["pytest>=7.0", "black>=24.0"]
20
+
21
+ [tool.setuptools.packages.find]
22
+ where = ["src"]
23
+
24
+ [tool.pytest.ini_options]
25
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ from .ip_bits import IpBits
2
+ from .ip_version import IpVersion
3
+ from .ipaddress import IPAddress, ResultIntParts
4
+ from .ipv4 import Ipv4
5
+ from .ipv6 import Ipv6
6
+ from .ipv6_loopback import Ipv6Loopback
7
+ from .ipv6_mapped import Ipv6Mapped
8
+ from .ipv6_unspec import Ipv6Unspec
9
+ from .prefix import Prefix
10
+ from .prefix32 import Prefix32
11
+ from .prefix128 import Prefix128
12
+ from .rle import Rle
13
+
14
+ __all__ = [
15
+ "IpBits",
16
+ "IpVersion",
17
+ "IPAddress",
18
+ "ResultIntParts",
19
+ "Ipv4",
20
+ "Ipv6",
21
+ "Ipv6Loopback",
22
+ "Ipv6Mapped",
23
+ "Ipv6Unspec",
24
+ "Prefix",
25
+ "Prefix32",
26
+ "Prefix128",
27
+ "Rle",
28
+ ]
@@ -0,0 +1,120 @@
1
+ from typing import Callable, List, Optional
2
+
3
+ from .ip_version import IpVersion
4
+ from .rle import Rle
5
+
6
+ ToString = Callable[["IpBits", int], str]
7
+
8
+
9
+ class IpBits:
10
+ _v4: Optional["IpBits"] = None
11
+ _v6: Optional["IpBits"] = None
12
+
13
+ def __init__(self) -> None:
14
+ self.version: IpVersion
15
+ self.vt_as_compressed_string: ToString
16
+ self.vt_as_uncompressed_string: ToString
17
+ self.bits: int = 0
18
+ self.part_bits: int = 0
19
+ self.dns_bits: int = 0
20
+ self.rev_domain: str = ""
21
+ self.part_mod: int = 0
22
+ self.host_ofs: int = 0 # ipv4=1, ipv6=0
23
+
24
+ def clone(self) -> "IpBits":
25
+ return self
26
+
27
+ def parts(self, bu: int) -> List[int]:
28
+ vec: List[int] = []
29
+ my = bu
30
+ part_mod = 1 << self.part_bits
31
+ for _ in range(self.bits // self.part_bits):
32
+ vec.append(my % part_mod)
33
+ my = my >> self.part_bits
34
+ vec.reverse()
35
+ return vec
36
+
37
+ def as_compressed_string(self, bu: int) -> str:
38
+ return self.vt_as_compressed_string(self, bu)
39
+
40
+ def as_uncompressed_string(self, bu: int) -> str:
41
+ return self.vt_as_uncompressed_string(self, bu)
42
+
43
+ def dns_part_format(self, i: int) -> str:
44
+ if self.version == IpVersion.V4:
45
+ return f"{i}"
46
+ return format(i, "x")
47
+
48
+ @staticmethod
49
+ def v4() -> "IpBits":
50
+ if IpBits._v4:
51
+ return IpBits._v4
52
+ my = IpBits()
53
+ IpBits._v4 = my
54
+ my.version = IpVersion.V4
55
+ my.vt_as_compressed_string = IpBits.ipv4_as_compressed
56
+ my.vt_as_uncompressed_string = IpBits.ipv4_as_compressed
57
+ my.bits = 32
58
+ my.part_bits = 8
59
+ my.dns_bits = 8
60
+ my.rev_domain = "in-addr.arpa"
61
+ my.part_mod = 1 << 8
62
+ my.host_ofs = 1
63
+ return my
64
+
65
+ @staticmethod
66
+ def v6() -> "IpBits":
67
+ if IpBits._v6:
68
+ return IpBits._v6
69
+ my = IpBits()
70
+ IpBits._v6 = my
71
+ my.version = IpVersion.V6
72
+ my.vt_as_compressed_string = IpBits.ipv6_as_compressed
73
+ my.vt_as_uncompressed_string = IpBits.ipv6_as_uncompressed
74
+ my.bits = 128
75
+ my.part_bits = 16
76
+ my.dns_bits = 4
77
+ my.rev_domain = "ip6.arpa"
78
+ my.part_mod = 1 << 16
79
+ my.host_ofs = 0
80
+ return my
81
+
82
+ @staticmethod
83
+ def ipv4_as_compressed(ip_bits: "IpBits", host_address: int) -> str:
84
+ ret = ""
85
+ sep = ""
86
+ for part in ip_bits.parts(host_address):
87
+ ret += sep
88
+ ret += f"{part}"
89
+ sep = "."
90
+ return ret
91
+
92
+ @staticmethod
93
+ def ipv6_as_compressed(ip_bits: "IpBits", host_address: int) -> str:
94
+ ret = ""
95
+ colon = ""
96
+ done = False
97
+ for rle in Rle.code(ip_bits.parts(host_address)):
98
+ for _ in range(rle.cnt):
99
+ if done or not (rle.part == 0 and rle.max):
100
+ ret += f"{colon}{format(rle.part, 'x')}"
101
+ colon = ":"
102
+ elif rle.part == 0 and rle.max:
103
+ ret += "::"
104
+ colon = ""
105
+ done = True
106
+ break
107
+ return ret
108
+
109
+ @staticmethod
110
+ def ipv6_as_uncompressed(ip_bits: "IpBits", host_address: int) -> str:
111
+ ret = ""
112
+ sep = ""
113
+ for part in ip_bits.parts(host_address):
114
+ ret += sep
115
+ ret += format(0x10000 + part, "x")[1:]
116
+ sep = ":"
117
+ return ret
118
+
119
+
120
+ __all__ = ["IpBits", "ToString"]
@@ -0,0 +1,9 @@
1
+ from enum import IntEnum
2
+
3
+
4
+ class IpVersion(IntEnum):
5
+ V4 = 4
6
+ V6 = 6
7
+
8
+
9
+ __all__ = ["IpVersion"]