initial
This commit is contained in:
24
lib/__init__.py
Normal file
24
lib/__init__.py
Normal 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
|
||||
Reference in New Issue
Block a user