mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
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:
parent
2ac931d6c9
commit
0c6ce31f76
24 changed files with 51 additions and 51 deletions
12
lib/ansible/plugins/cache/jsonfile.py
vendored
12
lib/ansible/plugins/cache/jsonfile.py
vendored
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue