diff options
| author | Tim Graham <timograham@gmail.com> | 2017-09-07 08:16:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-07 08:16:21 -0400 |
| commit | 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch) | |
| tree | 1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/contrib/sessions | |
| parent | 8b2515a450ef376b9205029090af0a79c8341bd7 (diff) | |
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda
because try/except performs better.
Diffstat (limited to 'django/contrib/sessions')
| -rw-r--r-- | django/contrib/sessions/backends/base.py | 5 | ||||
| -rw-r--r-- | django/contrib/sessions/backends/file.py | 9 |
2 files changed, 9 insertions, 5 deletions
diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py index 3ff79b7a39..64955b8bb7 100644 --- a/django/contrib/sessions/backends/base.py +++ b/django/contrib/sessions/backends/base.py @@ -1,7 +1,6 @@ import base64 import logging import string -from contextlib import suppress from datetime import datetime, timedelta from django.conf import settings @@ -263,8 +262,10 @@ class SessionBase: """ if value is None: # Remove any custom expiration for this session. - with suppress(KeyError): + try: del self['_session_expiry'] + except KeyError: + pass return if isinstance(value, timedelta): value = timezone.now() + value diff --git a/django/contrib/sessions/backends/file.py b/django/contrib/sessions/backends/file.py index 540228b790..0a724f7e0a 100644 --- a/django/contrib/sessions/backends/file.py +++ b/django/contrib/sessions/backends/file.py @@ -3,7 +3,6 @@ import logging import os import shutil import tempfile -from contextlib import suppress from django.conf import settings from django.contrib.sessions.backends.base import ( @@ -156,7 +155,7 @@ class SessionStore(SessionBase): # See ticket #8616. dir, prefix = os.path.split(session_file_name) - with suppress(OSError, IOError, EOFError): + try: output_file_fd, output_file_name = tempfile.mkstemp(dir=dir, prefix=prefix + '_out_') renamed = False try: @@ -173,6 +172,8 @@ class SessionStore(SessionBase): finally: if not renamed: os.unlink(output_file_name) + except (OSError, IOError, EOFError): + pass def exists(self, session_key): return os.path.exists(self._key_to_file(session_key)) @@ -182,8 +183,10 @@ class SessionStore(SessionBase): if self.session_key is None: return session_key = self.session_key - with suppress(OSError): + try: os.unlink(self._key_to_file(session_key)) + except OSError: + pass def clean(self): pass |
