Change exceptions to python3 syntax.
This commit is contained in:
parent
62c08d96e5
commit
6747f82547
22 changed files with 38 additions and 38 deletions
|
@ -270,9 +270,9 @@ class Base:
|
|||
# and assign the massaged value back to the attribute field
|
||||
setattr(self, name, value)
|
||||
|
||||
except (TypeError, ValueError), e:
|
||||
except (TypeError, ValueError) as e:
|
||||
raise AnsibleParserError("the field '%s' has an invalid value (%s), and could not be converted to an %s. Error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds())
|
||||
except UndefinedError, e:
|
||||
except UndefinedError as e:
|
||||
if fail_on_undefined:
|
||||
raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined. The error was: %s" % (name,e), obj=self.get_ds())
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ class PluginLoader:
|
|||
if os.path.isdir(path):
|
||||
try:
|
||||
full_paths = (os.path.join(path, f) for f in os.listdir(path))
|
||||
except OSError,e:
|
||||
except OSError as e:
|
||||
d = Display()
|
||||
d.warning("Error accessing plugin paths: %s" % str(e))
|
||||
for full_path in (f for f in full_paths if os.path.isfile(f)):
|
||||
|
|
|
@ -223,7 +223,7 @@ class ActionBase:
|
|||
#else:
|
||||
# data = data.encode('utf-8')
|
||||
afo.write(data)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
#raise AnsibleError("failure encoding into utf-8: %s" % str(e))
|
||||
raise AnsibleError("failure writing module data to temporary file for transfer: %s" % str(e))
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class ActionModule(ActionBase):
|
|||
else:
|
||||
content_tempfile = self._create_content_tempfile(content)
|
||||
source = content_tempfile
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
return dict(failed=True, msg="could not write content temp file: %s" % err)
|
||||
|
||||
###############################################################################################
|
||||
|
@ -297,7 +297,7 @@ class ActionModule(ActionBase):
|
|||
content = to_bytes(content)
|
||||
try:
|
||||
f.write(content)
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
os.remove(content_tempfile)
|
||||
raise Exception(err)
|
||||
finally:
|
||||
|
|
|
@ -68,7 +68,7 @@ class ActionModule(ActionBase):
|
|||
seconds = int(self._task.args['seconds'])
|
||||
duration_unit = 'seconds'
|
||||
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
return dict(failed=True, msg="non-integer value given for prompt duration:\n%s" % str(e))
|
||||
|
||||
# Is 'prompt' a key in 'args'?
|
||||
|
|
|
@ -102,7 +102,7 @@ class ActionModule(ActionBase):
|
|||
with open(source, 'r') as f:
|
||||
template_data = f.read()
|
||||
resultant = templar.template(template_data, preserve_trailing_newlines=True)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
return dict(failed=True, msg=type(e).__name__ + ": " + str(e))
|
||||
|
||||
local_checksum = checksum_s(resultant)
|
||||
|
|
|
@ -140,7 +140,7 @@ class Connection(object):
|
|||
# shutdown, so we'll reconnect.
|
||||
wrong_user = True
|
||||
|
||||
except AnsibleError, e:
|
||||
except AnsibleError as e:
|
||||
if allow_ssh:
|
||||
if "WRONG_USER" in e:
|
||||
vvv("Switching users, waiting for the daemon on %s to shutdown completely..." % self.host)
|
||||
|
|
|
@ -170,7 +170,7 @@ class Connection(object):
|
|||
key_filename=key_filename, password=self.password,
|
||||
timeout=self.runner.timeout, port=self.port)
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
|
||||
msg = str(e)
|
||||
if "PID check failed" in msg:
|
||||
|
@ -197,7 +197,7 @@ class Connection(object):
|
|||
self.ssh.get_transport().set_keepalive(5)
|
||||
chan = self.ssh.get_transport().open_session()
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
|
||||
msg = "Failed to open session"
|
||||
if len(str(e)) > 0:
|
||||
|
@ -284,7 +284,7 @@ class Connection(object):
|
|||
|
||||
try:
|
||||
self.sftp = self.ssh.open_sftp()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise errors.AnsibleError("failed to open a SFTP connection (%s)" % e)
|
||||
|
||||
try:
|
||||
|
@ -308,7 +308,7 @@ class Connection(object):
|
|||
|
||||
try:
|
||||
self.sftp = self._connect_sftp()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise errors.AnsibleError("failed to open a SFTP connection (%s)", e)
|
||||
|
||||
try:
|
||||
|
|
|
@ -147,7 +147,7 @@ class Connection(object):
|
|||
cmd_parts = powershell._encode_script(script, as_list=True)
|
||||
try:
|
||||
result = self._winrm_exec(cmd_parts[0], cmd_parts[1:], from_exec=True)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise errors.AnsibleError("failed to exec cmd %s" % cmd)
|
||||
return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
|
||||
|
|
|
@ -33,7 +33,7 @@ class LookupModule(LookupBase):
|
|||
for row in creader:
|
||||
if row[0] == key:
|
||||
return row[int(col)]
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise AnsibleError("csvfile: %s" % str(e))
|
||||
|
||||
return dflt
|
||||
|
@ -61,7 +61,7 @@ class LookupModule(LookupBase):
|
|||
name, value = param.split('=')
|
||||
assert(name in paramvals)
|
||||
paramvals[name] = value
|
||||
except (ValueError, AssertionError), e:
|
||||
except (ValueError, AssertionError) as e:
|
||||
raise AnsibleError(e)
|
||||
|
||||
if paramvals['delimiter'] == 'TAB':
|
||||
|
|
|
@ -59,7 +59,7 @@ class LookupModule(LookupBase):
|
|||
string = 'NXDOMAIN'
|
||||
except dns.resolver.Timeout:
|
||||
string = ''
|
||||
except dns.exception.DNSException, e:
|
||||
except dns.exception.DNSException as e:
|
||||
raise AnsibleError("dns.resolver unhandled exception", e)
|
||||
|
||||
ret.append(''.join(string))
|
||||
|
|
|
@ -177,7 +177,7 @@ class LookupModule(LookupBase):
|
|||
for fn in total_search:
|
||||
try:
|
||||
fn = templar.template(fn)
|
||||
except (AnsibleUndefinedVariable, UndefinedError), e:
|
||||
except (AnsibleUndefinedVariable, UndefinedError) as e:
|
||||
continue
|
||||
|
||||
if os.path.isabs(fn) and os.path.exists(fn):
|
||||
|
|
|
@ -85,7 +85,7 @@ class LookupModule(LookupBase):
|
|||
paramvals['chars'] = use_chars
|
||||
else:
|
||||
paramvals[name] = value
|
||||
except (ValueError, AssertionError), e:
|
||||
except (ValueError, AssertionError) as e:
|
||||
raise AnsibleError(e)
|
||||
|
||||
length = paramvals['length']
|
||||
|
@ -99,7 +99,7 @@ class LookupModule(LookupBase):
|
|||
if not os.path.isdir(pathdir):
|
||||
try:
|
||||
os.makedirs(pathdir, mode=0700)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
raise AnsibleError("cannot create the path for the password lookup: %s (error was %s)" % (pathdir, str(e)))
|
||||
|
||||
chars = "".join([getattr(string,c,c) for c in use_chars]).replace('"','').replace("'",'')
|
||||
|
|
|
@ -31,10 +31,10 @@ class LookupModule(LookupBase):
|
|||
try:
|
||||
r = urllib2.Request(term)
|
||||
response = urllib2.urlopen(r)
|
||||
except URLError, e:
|
||||
except URLError as e:
|
||||
utils.warnings("Failed lookup url for %s : %s" % (term, str(e)))
|
||||
continue
|
||||
except HTTPError, e:
|
||||
except HTTPError as e:
|
||||
utils.warnings("Recieved HTTP error for %s : %s" % (term, str(e)))
|
||||
continue
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ class StrategyBase:
|
|||
|
||||
self._pending_results += 1
|
||||
main_q.put((host, task, self._loader.get_basedir(), task_vars, connection_info, module_loader), block=False)
|
||||
except (EOFError, IOError, AssertionError), e:
|
||||
except (EOFError, IOError, AssertionError) as e:
|
||||
# most likely an abort
|
||||
debug("got an error while queuing: %s" % e)
|
||||
return
|
||||
|
|
|
@ -139,7 +139,7 @@ class StrategyModule(StrategyBase):
|
|||
try:
|
||||
results = self._wait_on_pending_results(iterator)
|
||||
host_results.extend(results)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# FIXME: ctrl+c can cause some failures here, so catch them
|
||||
# with the appropriate error type
|
||||
print("wtf: %s" % e)
|
||||
|
|
|
@ -105,13 +105,13 @@ def safe_eval(expr, locals={}, include_exceptions=False):
|
|||
return (result, None)
|
||||
else:
|
||||
return result
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
# special handling for syntax errors, we just return
|
||||
# the expression string back as-is
|
||||
if include_exceptions:
|
||||
return (expr, None)
|
||||
return expr
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if include_exceptions:
|
||||
return (expr, e)
|
||||
return expr
|
||||
|
|
|
@ -64,7 +64,7 @@ def secure_hash(filename, hash_func=sha1):
|
|||
digest.update(block)
|
||||
block = infile.read(blocksize)
|
||||
infile.close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
raise errors.AnsibleError("error while accessing the file %s, error was: %s" % (filename, e))
|
||||
return digest.hexdigest()
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ def read_vault_file(vault_password_file):
|
|||
try:
|
||||
# STDERR not captured to make it easier for users to prompt for input in their scripts
|
||||
p = subprocess.Popen(this_path, stdout=subprocess.PIPE)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
raise AnsibleError("Problem running vault password script %s (%s). If this is not a script, remove the executable bit from the file." % (' '.join(this_path), e))
|
||||
stdout, stderr = p.communicate()
|
||||
vault_pass = stdout.strip('\r\n')
|
||||
|
@ -49,7 +49,7 @@ def read_vault_file(vault_password_file):
|
|||
f = open(this_path, "rb")
|
||||
vault_pass=f.read().strip()
|
||||
f.close()
|
||||
except (OSError, IOError), e:
|
||||
except (OSError, IOError) as e:
|
||||
raise AnsibleError("Could not read vault password file %s: %s" % (this_path, e))
|
||||
|
||||
return vault_pass
|
||||
|
|
|
@ -243,7 +243,7 @@ class VariableManager:
|
|||
|
||||
try:
|
||||
names = loader.list_directory(path)
|
||||
except os.error, err:
|
||||
except os.error as err:
|
||||
raise AnsibleError("This folder cannot be listed: %s: %s." % (path, err.strerror))
|
||||
|
||||
# evaluate files in a stable order rather than whatever
|
||||
|
|
|
@ -59,10 +59,10 @@ def results(pipe, workers):
|
|||
time.sleep(0.01)
|
||||
continue
|
||||
pipe.send(result)
|
||||
except (IOError, EOFError, KeyboardInterrupt), e:
|
||||
except (IOError, EOFError, KeyboardInterrupt) as e:
|
||||
debug("got a breaking error: %s" % e)
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e)
|
||||
traceback.print_exc()
|
||||
break
|
||||
|
|
|
@ -55,10 +55,10 @@ def results(final_q, workers):
|
|||
time.sleep(0.01)
|
||||
continue
|
||||
final_q.put(result, block=False)
|
||||
except (IOError, EOFError, KeyboardInterrupt), e:
|
||||
except (IOError, EOFError, KeyboardInterrupt) as e:
|
||||
debug("got a breaking error: %s" % e)
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e)
|
||||
traceback.print_exc()
|
||||
break
|
||||
|
@ -77,10 +77,10 @@ def worker(main_q, res_q, loader):
|
|||
time.sleep(0.01)
|
||||
except Queue.Empty:
|
||||
pass
|
||||
except (IOError, EOFError, KeyboardInterrupt), e:
|
||||
except (IOError, EOFError, KeyboardInterrupt) as e:
|
||||
debug("got a breaking error: %s" % e)
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
debug("EXCEPTION DURING WORKER PROCESSING: %s" % e)
|
||||
traceback.print_exc()
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue