Simplify import process for zoneinfo backport across entire project

This commit is contained in:
Will Thong 2023-07-26 12:37:30 +01:00
commit 3602afadbb
2 changed files with 4 additions and 10 deletions

View file

@ -10,7 +10,7 @@ from jinja2 import Environment, FileSystemLoader
try:
import zoneinfo
except ModuleNotFoundError:
import backports.zoneinfo
from backports import zoneinfo
try:
import readline # NOQA
@ -161,10 +161,7 @@ def ask(question, answer=str, default=None, length=None):
def ask_timezone(question, default, tzurl):
"""Prompt for time zone and validate input"""
try:
tz_dict = {tz.lower(): tz for tz in zoneinfo.available_timezones()}
except NameError:
tz_dict = {tz.lower(): tz for tz in backports.zoneinfo.available_timezones()}
tz_dict = {tz.lower(): tz for tz in zoneinfo.available_timezones()}
while True:
r = ask(question, str, default)
r = r.strip().replace(" ", "_").lower()

View file

@ -21,7 +21,7 @@ import dateutil.parser
try:
import zoneinfo
except ModuleNotFoundError:
import backports.zoneinfo
from backports import zoneinfo
from markupsafe import Markup
@ -921,10 +921,7 @@ class FileSystemWatcher:
def set_date_tzinfo(d, tz_name=None):
"""Set the timezone for dates that don't have tzinfo"""
if tz_name and not d.tzinfo:
try:
timezone = zoneinfo.ZoneInfo(tz_name)
except NameError:
timezone = backports.zoneinfo.ZoneInfo(tz_name)
timezone = zoneinfo.ZoneInfo(tz_name)
d = d.replace(tzinfo=timezone)
return SafeDatetime(
d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond, d.tzinfo