diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-09 09:03:38 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-17 11:49:15 +0100 |
| commit | e6f82438d4e3750e8d299bfd79dac98eebe9f1e0 (patch) | |
| tree | 4ee0cbf2c0be9822416aa3d65105f35a9784fd94 /django/templatetags | |
| parent | 8d98f99a4ab5de6f2c730399f53eba8bf6bea470 (diff) | |
Refs #32365 -- Removed support for pytz timezones per deprecation timeline.
Diffstat (limited to 'django/templatetags')
| -rw-r--r-- | django/templatetags/tz.py | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/django/templatetags/tz.py b/django/templatetags/tz.py index cb7d22e5f2..92240b2a39 100644 --- a/django/templatetags/tz.py +++ b/django/templatetags/tz.py @@ -7,34 +7,12 @@ try: except ImportError: from backports import zoneinfo -from django.conf import settings from django.template import Library, Node, TemplateSyntaxError from django.utils import timezone register = Library() -# RemovedInDjango50Warning: shim to allow catching the exception in the calling -# scope if pytz is not installed. -class UnknownTimezoneException(BaseException): - pass - - -# RemovedInDjango50Warning -def timezone_constructor(tzname): - if settings.USE_DEPRECATED_PYTZ: - import pytz - - try: - return pytz.timezone(tzname) - except pytz.UnknownTimeZoneError: - raise UnknownTimezoneException - try: - return zoneinfo.ZoneInfo(tzname) - except zoneinfo.ZoneInfoNotFoundError: - raise UnknownTimezoneException - - # HACK: datetime instances cannot be assigned new attributes. Define a subclass # in order to define new attributes in do_timezone(). class datetimeobject(datetime): @@ -79,8 +57,7 @@ def do_timezone(value, arg): if timezone.is_naive(value): default_timezone = timezone.get_default_timezone() value = timezone.make_aware(value, default_timezone) - # Filters must never raise exceptions, and pytz' exceptions inherit - # Exception directly, not a specific subclass. So catch everything. + # Filters must never raise exceptionsm, so catch everything. except Exception: return "" @@ -89,8 +66,8 @@ def do_timezone(value, arg): tz = arg elif isinstance(arg, str): try: - tz = timezone_constructor(arg) - except UnknownTimezoneException: + tz = zoneinfo.ZoneInfo(arg) + except zoneinfo.ZoneInfoNotFoundError: return "" else: return "" |
