diff options
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(). |
