mirror of
https://github.com/sileht/bird-lg.git
synced 2024-11-26 08:44:43 +01:00
PEP8 compliance
This commit is contained in:
parent
8e55d6aac2
commit
c67f4644ae
13
toolbox.py
13
toolbox.py
|
@ -28,18 +28,21 @@ resolv = resolver.Resolver()
|
|||
resolv.timeout = 0.5
|
||||
resolv.lifetime = 1
|
||||
|
||||
|
||||
def resolve(n, q):
|
||||
return str(resolv.query(n,q)[0])
|
||||
return str(resolv.query(n, q)[0])
|
||||
|
||||
|
||||
def mask_is_valid(n):
|
||||
if not n:
|
||||
return True
|
||||
try:
|
||||
mask = int(n)
|
||||
return ( mask >= 1 and mask <= 128)
|
||||
return (mask >= 1 and mask <= 128)
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def ipv4_is_valid(n):
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, n)
|
||||
|
@ -47,6 +50,7 @@ def ipv4_is_valid(n):
|
|||
except socket.error:
|
||||
return False
|
||||
|
||||
|
||||
def ipv6_is_valid(n):
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, n)
|
||||
|
@ -54,12 +58,14 @@ def ipv6_is_valid(n):
|
|||
except socket.error:
|
||||
return False
|
||||
|
||||
|
||||
def save_cache_pickle(filename, data):
|
||||
output = open(filename, 'wb')
|
||||
pickle.dump(data, output)
|
||||
output.close()
|
||||
|
||||
def load_cache_pickle(filename, default = None):
|
||||
|
||||
def load_cache_pickle(filename, default=None):
|
||||
try:
|
||||
pkl_file = open(filename, 'rb')
|
||||
except IOError:
|
||||
|
@ -71,6 +77,7 @@ def load_cache_pickle(filename, default = None):
|
|||
pkl_file.close()
|
||||
return data
|
||||
|
||||
|
||||
def unescape(s):
|
||||
want_unicode = False
|
||||
if isinstance(s, unicode):
|
||||
|
|
Loading…
Reference in a new issue