Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change exceptions to python3 syntax. #10680

Merged
merged 1 commit into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions v2/ansible/playbook/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def post_validate(self, all_vars=dict(), fail_on_undefined=True):
# 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())

Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def find_plugin(self, name, suffixes=None):
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)):
Expand Down
4 changes: 2 additions & 2 deletions v2/ansible/plugins/action/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _early_needs_tmp_path(self):
# FIXME: modified from original, needs testing? Since this is now inside
# the action plugin, it should make it just this simple
return getattr(self, 'TRANSFERS_FILES', False)

def _late_needs_tmp_path(self, tmp, module_style):
'''
Determines if a temp path is required after some early actions have already taken place.
Expand Down Expand Up @@ -223,7 +223,7 @@ def _transfer_data(self, remote_path, data):
#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))

Expand Down
6 changes: 3 additions & 3 deletions v2/ansible/plugins/action/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run(self, tmp=None, task_vars=dict()):
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)

###############################################################################################
Expand Down Expand Up @@ -270,7 +270,7 @@ def run(self, tmp=None, task_vars=dict()):
if module_return.get('changed') == True:
changed = True

# the file module returns the file path as 'path', but
# the file module returns the file path as 'path', but
# the copy module uses 'dest', so add it if it's not there
if 'path' in module_return and 'dest' not in module_return:
module_return['dest'] = module_return['path']
Expand All @@ -297,7 +297,7 @@ def _create_content_tempfile(self, content):
content = to_bytes(content)
try:
f.write(content)
except Exception, err:
except Exception as err:
os.remove(content_tempfile)
raise Exception(err)
finally:
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/action/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run(self, tmp=None, task_vars=dict()):
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'?
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/action/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run(self, tmp=None, task_vars=dict()):
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)
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/connections/accelerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def connect(self, allow_ssh=True):
# 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)
Expand Down
8 changes: 4 additions & 4 deletions v2/ansible/plugins/connections/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _connect_uncached(self):
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:
Expand All @@ -197,7 +197,7 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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:
Expand Down Expand Up @@ -284,7 +284,7 @@ def put_file(self, in_path, out_path):

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:
Expand All @@ -308,7 +308,7 @@ def fetch_file(self, in_path, out_path):

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:
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/connections/winrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def exec_command(self, cmd, tmp_path, sudo_user=None, sudoable=False, executable
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'))
Expand Down
4 changes: 2 additions & 2 deletions v2/ansible/plugins/lookup/csvfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def read_csv(self, filename, key, delimiter, dflt=None, col=1):
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
Expand Down Expand Up @@ -61,7 +61,7 @@ def run(self, terms, variables=None, **kwargs):
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':
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/lookup/dnstxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(self, terms, variables=None, **kwargs):
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))
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/lookup/first_found.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run(self, terms, variables, **kwargs):
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):
Expand Down
4 changes: 2 additions & 2 deletions v2/ansible/plugins/lookup/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run(self, terms, variables, **kwargs):
paramvals['chars'] = use_chars
else:
paramvals[name] = value
except (ValueError, AssertionError), e:
except (ValueError, AssertionError) as e:
raise AnsibleError(e)

length = paramvals['length']
Expand All @@ -99,7 +99,7 @@ def run(self, terms, variables, **kwargs):
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("'",'')
Expand Down
4 changes: 2 additions & 2 deletions v2/ansible/plugins/lookup/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def run(self, terms, inject=None, **kwargs):
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

Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/strategies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _queue_task(self, host, task, task_vars, connection_info):

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
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/plugins/strategies/free.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def run(self, iterator, connection_info):
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)
Expand Down
4 changes: 2 additions & 2 deletions v2/ansible/template/safe_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def generic_visit(self, node, inside_call=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
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/utils/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions v2/ansible/utils/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion v2/ansible/vars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _load_inventory_file(self, path, loader):

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
Expand Down
4 changes: 2 additions & 2 deletions v2/samples/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def _read_worker_result(cur_worker):
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
Expand Down
8 changes: 4 additions & 4 deletions v2/samples/multi_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def _read_worker_result(cur_worker):
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
Expand All @@ -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
Expand Down