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,17 +28,20 @@ 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:
@ -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,22 +58,25 @@ def ipv6_is_valid(n):
except socket.error: except socket.error:
return False 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 save_cache_pickle(filename, data):
try: output = open(filename, 'wb')
pkl_file = open(filename, 'rb') pickle.dump(data, output)
except IOError: output.close()
return default
try:
data = pickle.load(pkl_file) def load_cache_pickle(filename, default=None):
except: try:
data = default pkl_file = open(filename, 'rb')
pkl_file.close() except IOError:
return data return default
try:
data = pickle.load(pkl_file)
except:
data = default
pkl_file.close()
return data
def unescape(s): def unescape(s):
want_unicode = False want_unicode = False