diff --git a/v2/ansible/playbook/base.py b/v2/ansible/playbook/base.py index e834d3b7296..c6a9d9a0513 100644 --- a/v2/ansible/playbook/base.py +++ b/v2/ansible/playbook/base.py @@ -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()) diff --git a/v2/ansible/plugins/__init__.py b/v2/ansible/plugins/__init__.py index a55059f1b7b..d16eecd3c39 100644 --- a/v2/ansible/plugins/__init__.py +++ b/v2/ansible/plugins/__init__.py @@ -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)): diff --git a/v2/ansible/plugins/action/__init__.py b/v2/ansible/plugins/action/__init__.py index 2f56c4df582..0e98bbc5b75 100644 --- a/v2/ansible/plugins/action/__init__.py +++ b/v2/ansible/plugins/action/__init__.py @@ -122,7 +122,7 @@ class ActionBase: # 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. @@ -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)) diff --git a/v2/ansible/plugins/action/copy.py b/v2/ansible/plugins/action/copy.py index ece8b5b11b0..6db130ad7f3 100644 --- a/v2/ansible/plugins/action/copy.py +++ b/v2/ansible/plugins/action/copy.py @@ -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) ############################################################################################### @@ -270,7 +270,7 @@ class ActionModule(ActionBase): 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'] @@ -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: diff --git a/v2/ansible/plugins/action/pause.py b/v2/ansible/plugins/action/pause.py index 9c6075e1011..c56e6654b1b 100644 --- a/v2/ansible/plugins/action/pause.py +++ b/v2/ansible/plugins/action/pause.py @@ -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'? diff --git a/v2/ansible/plugins/action/template.py b/v2/ansible/plugins/action/template.py index 76b2e78a737..f82cbb37667 100644 --- a/v2/ansible/plugins/action/template.py +++ b/v2/ansible/plugins/action/template.py @@ -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) diff --git a/v2/ansible/plugins/connections/accelerate.py b/v2/ansible/plugins/connections/accelerate.py index a31124e119f..13012aa9299 100644 --- a/v2/ansible/plugins/connections/accelerate.py +++ b/v2/ansible/plugins/connections/accelerate.py @@ -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) diff --git a/v2/ansible/plugins/connections/paramiko_ssh.py b/v2/ansible/plugins/connections/paramiko_ssh.py index 4bb06e01c36..81470f657c8 100644 --- a/v2/ansible/plugins/connections/paramiko_ssh.py +++ b/v2/ansible/plugins/connections/paramiko_ssh.py @@ -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: diff --git a/v2/ansible/plugins/connections/winrm.py b/v2/ansible/plugins/connections/winrm.py index d6e51710b5f..57d26ce6188 100644 --- a/v2/ansible/plugins/connections/winrm.py +++ b/v2/ansible/plugins/connections/winrm.py @@ -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')) diff --git a/v2/ansible/plugins/lookup/csvfile.py b/v2/ansible/plugins/lookup/csvfile.py index 87757399ce5..e5fb9a45121 100644 --- a/v2/ansible/plugins/lookup/csvfile.py +++ b/v2/ansible/plugins/lookup/csvfile.py @@ -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': diff --git a/v2/ansible/plugins/lookup/dnstxt.py b/v2/ansible/plugins/lookup/dnstxt.py index 7100f8d96df..75222927c79 100644 --- a/v2/ansible/plugins/lookup/dnstxt.py +++ b/v2/ansible/plugins/lookup/dnstxt.py @@ -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)) diff --git a/v2/ansible/plugins/lookup/first_found.py b/v2/ansible/plugins/lookup/first_found.py index 0ed26880150..b1d655b8114 100644 --- a/v2/ansible/plugins/lookup/first_found.py +++ b/v2/ansible/plugins/lookup/first_found.py @@ -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): diff --git a/v2/ansible/plugins/lookup/password.py b/v2/ansible/plugins/lookup/password.py index 6e13410e1ab..7e812a38c5f 100644 --- a/v2/ansible/plugins/lookup/password.py +++ b/v2/ansible/plugins/lookup/password.py @@ -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("'",'') diff --git a/v2/ansible/plugins/lookup/url.py b/v2/ansible/plugins/lookup/url.py index c907bfbce39..1b9c5c0d808 100644 --- a/v2/ansible/plugins/lookup/url.py +++ b/v2/ansible/plugins/lookup/url.py @@ -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 diff --git a/v2/ansible/plugins/strategies/__init__.py b/v2/ansible/plugins/strategies/__init__.py index afbc373f4f3..c5b3dd0f066 100644 --- a/v2/ansible/plugins/strategies/__init__.py +++ b/v2/ansible/plugins/strategies/__init__.py @@ -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 diff --git a/v2/ansible/plugins/strategies/free.py b/v2/ansible/plugins/strategies/free.py index 4fd8a132018..d0506d37dda 100644 --- a/v2/ansible/plugins/strategies/free.py +++ b/v2/ansible/plugins/strategies/free.py @@ -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) diff --git a/v2/ansible/template/safe_eval.py b/v2/ansible/template/safe_eval.py index ba377054d7a..c52ef398d76 100644 --- a/v2/ansible/template/safe_eval.py +++ b/v2/ansible/template/safe_eval.py @@ -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 diff --git a/v2/ansible/utils/hashing.py b/v2/ansible/utils/hashing.py index 0b2edd434bc..2c7dd534fcb 100644 --- a/v2/ansible/utils/hashing.py +++ b/v2/ansible/utils/hashing.py @@ -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() diff --git a/v2/ansible/utils/vault.py b/v2/ansible/utils/vault.py index 04634aa377b..5c704afac59 100644 --- a/v2/ansible/utils/vault.py +++ b/v2/ansible/utils/vault.py @@ -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 diff --git a/v2/ansible/vars/__init__.py b/v2/ansible/vars/__init__.py index eb75d9c9929..183116ea2d8 100644 --- a/v2/ansible/vars/__init__.py +++ b/v2/ansible/vars/__init__.py @@ -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 diff --git a/v2/samples/multi.py b/v2/samples/multi.py index ca4c8b68f74..dce61430594 100644 --- a/v2/samples/multi.py +++ b/v2/samples/multi.py @@ -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 diff --git a/v2/samples/multi_queues.py b/v2/samples/multi_queues.py index 8eb80366076..9e8f22b9a94 100644 --- a/v2/samples/multi_queues.py +++ b/v2/samples/multi_queues.py @@ -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