diff options
| author | Mads Jensen <mje@inducks.org> | 2017-03-09 16:17:41 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-28 14:07:55 -0400 |
| commit | 550cb3a365dee4edfdd1563224d5304de2a57fda (patch) | |
| tree | fb532f38774ff7619edd2a4532c3daae1ee0ac5a /django/http/response.py | |
| parent | 43a4835edf32c57eb74c0eb207c276734a34abcf (diff) | |
Fixed #27818 -- Replaced try/except/pass with contextlib.suppress().
Diffstat (limited to 'django/http/response.py')
| -rw-r--r-- | django/http/response.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/django/http/response.py b/django/http/response.py index 1083fd7dca..384de9fb84 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -3,6 +3,7 @@ import json import re import sys import time +from contextlib import suppress from email.header import Header from http.client import responses from urllib.parse import urlparse @@ -136,10 +137,8 @@ class HttpResponseBase: self._headers[header.lower()] = (header, value) def __delitem__(self, header): - try: + with suppress(KeyError): del self._headers[header.lower()] - except KeyError: - pass def __getitem__(self, header): return self._headers[header.lower()][1] @@ -238,10 +237,8 @@ class HttpResponseBase: # See http://blog.dscpl.com.au/2012/10/obligations-for-calling-close-on.html def close(self): for closable in self._closable_objects: - try: + with suppress(Exception): closable.close() - except Exception: - pass self.closed = True signals.request_finished.send(sender=self._handler_class) @@ -307,10 +304,8 @@ class HttpResponse(HttpResponseBase): if hasattr(value, '__iter__') and not isinstance(value, (bytes, str)): content = b''.join(self.make_bytes(chunk) for chunk in value) if hasattr(value, 'close'): - try: + with suppress(Exception): value.close() - except Exception: - pass else: content = self.make_bytes(value) # Create a list of properly encoded bytestrings to support write(). |
