1
0
Fork 0
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:
dsx 2015-01-21 12:03:55 -05:00
parent 8e55d6aac2
commit c67f4644ae

View file

@ -28,18 +28,21 @@ resolv = resolver.Resolver()
resolv.timeout = 0.5 resolv.timeout = 0.5
resolv.lifetime = 1 resolv.lifetime = 1
def resolve(n, q): def resolve(n, q):
return str(resolv.query(n,q)[0]) return str(resolv.query(n, q)[0])
def mask_is_valid(n): def mask_is_valid(n):
if not n: if not n:
return True return True
try: try:
mask = int(n) mask = int(n)
return ( mask >= 1 and mask <= 128) return (mask >= 1 and mask <= 128)
except: except:
return False return False
def ipv4_is_valid(n): def ipv4_is_valid(n):
try: try:
socket.inet_pton(socket.AF_INET, n) socket.inet_pton(socket.AF_INET, n)
@ -47,6 +50,7 @@ def ipv4_is_valid(n):
except socket.error: except socket.error:
return False return False
def ipv6_is_valid(n): def ipv6_is_valid(n):
try: try:
socket.inet_pton(socket.AF_INET6, n) socket.inet_pton(socket.AF_INET6, n)
@ -54,12 +58,14 @@ def ipv6_is_valid(n):
except socket.error: except socket.error:
return False return False
def save_cache_pickle(filename, data): def save_cache_pickle(filename, data):
output = open(filename, 'wb') output = open(filename, 'wb')
pickle.dump(data, output) pickle.dump(data, output)
output.close() output.close()
def load_cache_pickle(filename, default = None):
def load_cache_pickle(filename, default=None):
try: try:
pkl_file = open(filename, 'rb') pkl_file = open(filename, 'rb')
except IOError: except IOError:
@ -71,6 +77,7 @@ def load_cache_pickle(filename, default = None):
pkl_file.close() pkl_file.close()
return data return data
def unescape(s): def unescape(s):
want_unicode = False want_unicode = False
if isinstance(s, unicode): if isinstance(s, unicode):