diff options
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/backends/base.py | 11 | ||||
| -rw-r--r-- | django/template/defaultfilters.py | 9 |
2 files changed, 11 insertions, 9 deletions
diff --git a/django/template/backends/base.py b/django/template/backends/base.py index 4156365b97..c47c95e51e 100644 --- a/django/template/backends/base.py +++ b/django/template/backends/base.py @@ -1,5 +1,3 @@ -from contextlib import suppress - from django.core.exceptions import ( ImproperlyConfigured, SuspiciousFileOperation, ) @@ -75,8 +73,9 @@ class BaseEngine: directory traversal attacks. """ for template_dir in self.template_dirs: - # SuspiciousFileOperation occurs if the jointed path is located - # outside of this template_dir (it might be inside another one, - # so this isn't fatal). - with suppress(SuspiciousFileOperation): + try: yield safe_join(template_dir, template_name) + except SuspiciousFileOperation: + # The joined path was located outside of this template_dir + # (it might be inside another one, so this isn't fatal). + pass diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index b18b41c293..b172be6239 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -1,7 +1,6 @@ """Default variable filters.""" import random as random_module import re -from contextlib import suppress from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation from functools import wraps from operator import itemgetter @@ -609,7 +608,7 @@ def unordered_list(value, autoescape=True): def walk_items(item_list): item_iterator = iter(item_list) - with suppress(StopIteration): + try: item = next(item_iterator) while True: try: @@ -628,6 +627,8 @@ def unordered_list(value, autoescape=True): continue yield item, None item = next_item + except StopIteration: + pass def list_formatter(item_list, tabs=1): indent = '\t' * tabs @@ -877,9 +878,11 @@ def pluralize(value, arg='s'): except ValueError: # Invalid string that's not a number. pass except TypeError: # Value isn't a string or a number; maybe it's a list? - with suppress(TypeError): # len() of unsized object. + try: if len(value) != 1: return plural_suffix + except TypeError: # len() of unsized object. + pass return singular_suffix |
