summaryrefslogtreecommitdiff
path: root/django/core/cache
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-01-25 10:13:08 -0500
committerGitHub <noreply@github.com>2017-01-25 10:13:08 -0500
commit632c4ffd9cb1da273303bcd8005fff216506c795 (patch)
tree4e475379e7e210a513789513021720b8b4808f7c /django/core/cache
parent3f0c4fe18fe9850bb2f56be138012add4b54873d (diff)
Refs #23919 -- Replaced errno checking with PEP 3151 exceptions.
Diffstat (limited to 'django/core/cache')
-rw-r--r--django/core/cache/backends/filebased.py21
1 files changed, 7 insertions, 14 deletions
diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py
index ae5b48c054..896f798e95 100644
--- a/django/core/cache/backends/filebased.py
+++ b/django/core/cache/backends/filebased.py
@@ -1,5 +1,4 @@
"File-based cache backend"
-import errno
import glob
import hashlib
import os
@@ -34,9 +33,8 @@ class FileBasedCache(BaseCache):
with open(fname, 'rb') as f:
if not self._is_expired(f):
return pickle.loads(zlib.decompress(f.read()))
- except IOError as e:
- if e.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
+ pass
return default
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
@@ -64,11 +62,9 @@ class FileBasedCache(BaseCache):
return
try:
os.remove(fname)
- except OSError as e:
- # ENOENT can happen if the cache file is removed (by another
- # process) after the os.path.exists check.
- if e.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
+ # The file may have been removed by another process.
+ pass
def has_key(self, key, version=None):
fname = self._key_to_file(key, version)
@@ -99,11 +95,8 @@ class FileBasedCache(BaseCache):
if not os.path.exists(self._dir):
try:
os.makedirs(self._dir, 0o700)
- except OSError as e:
- if e.errno != errno.EEXIST:
- raise EnvironmentError(
- "Cache directory '%s' does not exist "
- "and could not be created'" % self._dir)
+ except FileExistsError:
+ pass
def _key_to_file(self, key, version=None):
"""