This commit is contained in:
Holger Sielaff
2025-08-27 09:55:55 +02:00
commit 90c0ff61ed
107 changed files with 8535 additions and 0 deletions

24
lib/__init__.py Normal file
View File

@@ -0,0 +1,24 @@
def ip_in_net(ip, network):
ipaddr = int(''.join(['%02x' % int(x) for x in ip.split('.')]), 16)
netaddr, bits = network.split('/')
netmask = int(''.join(['%02x' % int(x) for x in netaddr.split('.')]), 16)
mask = (0xffffffff << (32 - int(bits))) & 0xffffffff
return (ipaddr & mask) == (netmask & mask)
def human_size(num, suffix=''):
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < 1024.0:
return "%3.1f %s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
class FactoryMixin:
_instance = None
@classmethod
def factory(cls, *args, **kwargs):
if not cls._instance:
cls._instance = cls(*args, **kwargs)
return cls._instance