Use 'except ... as' syntax

This syntax works on Python 2.6 through 3.x.  lib/ansible/module_utils
(and lib/ansible/modules) need to support Python 2.4, so I didn't touch
those.
This commit is contained in:
Marius Gedminas 2015-08-27 09:16:11 +03:00
parent 2ac931d6c9
commit 0c6ce31f76
24 changed files with 51 additions and 51 deletions

View file

@ -45,7 +45,7 @@ class CacheModule(BaseCacheModule):
if not os.path.exists(self._cache_dir):
try:
os.makedirs(self._cache_dir)
except (OSError,IOError), e:
except (OSError,IOError) as e:
self._display.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, str(e)))
return None
@ -60,7 +60,7 @@ class CacheModule(BaseCacheModule):
cachefile = "%s/%s" % (self._cache_dir, key)
try:
f = codecs.open(cachefile, 'r', encoding='utf-8')
except (OSError,IOError), e:
except (OSError,IOError) as e:
self._display.warning("error while trying to read %s : %s" % (cachefile, str(e)))
pass
else:
@ -81,7 +81,7 @@ class CacheModule(BaseCacheModule):
cachefile = "%s/%s" % (self._cache_dir, key)
try:
f = codecs.open(cachefile, 'w', encoding='utf-8')
except (OSError,IOError), e:
except (OSError,IOError) as e:
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
pass
else:
@ -94,7 +94,7 @@ class CacheModule(BaseCacheModule):
cachefile = "%s/%s" % (self._cache_dir, key)
try:
st = os.stat(cachefile)
except (OSError,IOError), e:
except (OSError,IOError) as e:
if e.errno == errno.ENOENT:
return False
else:
@ -126,7 +126,7 @@ class CacheModule(BaseCacheModule):
try:
st = os.stat(cachefile)
return True
except (OSError,IOError), e:
except (OSError,IOError) as e:
if e.errno == errno.ENOENT:
return False
else:
@ -137,7 +137,7 @@ class CacheModule(BaseCacheModule):
del self._cache[key]
try:
os.remove("%s/%s" % (self._cache_dir, key))
except (OSError,IOError), e:
except (OSError,IOError) as e:
pass #TODO: only pass on non existing?
def flush(self):