Commit d71f7221 authored by Tanner Prestegard's avatar Tanner Prestegard

cleanup of utility functions

parent 50dc2dfb
......@@ -14,6 +14,7 @@ SUPEREVENT_PREFIXES = ['S', 'GW']
superevent_prefix_regex = re.compile(r'^({prefixes})\d+'.format(
prefixes="|".join(SUPEREVENT_PREFIXES)))
# Decorator for class methods so that they work for events or superevents
def event_or_superevent(func):
@wraps(func)
......@@ -35,7 +36,7 @@ def handle_str_or_list_arg(arg, arg_name):
elif isinstance(arg, list):
pass
else:
raise TypeError("{0} arg is {1}, should be str or list" \
raise TypeError("{0} arg is {1}, should be str or list"
.format(arg_name, type(arg)))
return arg
......@@ -50,7 +51,7 @@ def cleanListInput(list_arg):
stringified_value = str(list_arg)
return stringified_value
if not isinstance(list_arg, six.string_types):
stringified_list = ','.join(map(str,list_arg))
stringified_list = ','.join(map(str, list_arg))
return stringified_list
......@@ -66,15 +67,15 @@ def get_dt_from_openssl_output(s):
# So we first have to split off the bit after the equal sign.
try:
date_string = s.split('=')[1].strip()
except:
err = 'Openssl output not understood.'
except Exception as e:
err = 'Openssl output not understood: {0}'.format(e)
return dt, err
# Next, attempt to parse the date with strptime.
try:
dt = datetime.strptime(date_string, "%b %d %H:%M:%S %Y %Z")
except:
err = 'Could not parse time string from openssl.'
except Exception as e:
err = 'Could not parse time string from openssl: {0}'.format(e)
return dt, err
return dt, err
......@@ -124,7 +125,7 @@ class safe_netrc(netrc):
file)
if (prop.st_mode & (stat.S_IRWXG | stat.S_IRWXO)):
raise NetrcParseError(
"~/.netrc access too permissive: access"
" permissions must restrict access to only"
" the owner", file)
"~/.netrc access too permissive: access"
" permissions must restrict access to only"
" the owner", file)
return netrc._parse(self, file, fp, *args, **kwargs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment