From 5d20ad6365a31e1302ddbfed5825412ae834f8eb Mon Sep 17 00:00:00 2001 From: ilya Date: Sat, 29 Jun 2024 19:07:49 +0300 Subject: [PATCH 1/2] Fix issues. All tests is passed for this code. https://github.com/tehmaze/ipcalc/issues/67 https://github.com/tehmaze/ipcalc/issues/68 --- ipcalc.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ipcalc.py b/ipcalc.py index a471e9b..fc6d2e2 100644 --- a/ipcalc.py +++ b/ipcalc.py @@ -163,6 +163,11 @@ def __init__(self, ip, mask=None, version=0): self.mask = (limit - count) else: raise ValueError('Invalid netmask') + + #hard fix https://github.com/tehmaze/ipcalc/issues/67 + if self.v != 6 and len(self.dq) > 15 and ':' in self.dq: + self.v = 6 + # Validate subnet size if self.v == 6: self.dq = self._itodq(self.ip) @@ -291,9 +296,12 @@ def _dqtoi_ipv6(self, dq): hx.insert(ix, '0') elif dq.endswith('::'): pass - elif '' in hx: - raise ValueError('%s: IPv6 address invalid: ' - 'compressed format detected in full notation' % dq) + + # hide to fix https://github.com/tehmaze/ipcalc/issues/68 + # elif '' in hx: + # raise ValueError('%s: IPv6 address invalid: ' + # 'compressed format detected in full notation' % dq) + ip = '' hx = [x == '' and '0' or x for x in hx] for h in hx: From 699cd1ea0e6296758092b175a9539e5b2411c5f3 Mon Sep 17 00:00:00 2001 From: ilya Date: Sat, 29 Jun 2024 22:13:29 +0300 Subject: [PATCH 2/2] Fix issues. https://github.com/tehmaze/ipcalc/issues/67 https://github.com/tehmaze/ipcalc/issues/68 All tests (https://github.com/tehmaze/ipcalc/pull/69) is passed for this code. May be this fix will be useful. --- ipcalc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipcalc.py b/ipcalc.py index fc6d2e2..17ce9b7 100644 --- a/ipcalc.py +++ b/ipcalc.py @@ -165,7 +165,7 @@ def __init__(self, ip, mask=None, version=0): raise ValueError('Invalid netmask') #hard fix https://github.com/tehmaze/ipcalc/issues/67 - if self.v != 6 and len(self.dq) > 15 and ':' in self.dq: + if self.v != 6 and (len(self.dq) > 15 or ':' in self.dq): self.v = 6 # Validate subnet size