cleanup of utility functions

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