Replace pytz dependency with zoneinfo. Fix #2958 (#3161)

This commit is contained in:
Will Thong 2023-07-26 16:29:43 +01:00 committed by GitHub
commit 1d2bf8e96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 23 deletions

View file

@ -7,7 +7,10 @@ from typing import Mapping
from jinja2 import Environment, FileSystemLoader
import pytz
try:
import zoneinfo
except ModuleNotFoundError:
from backports import zoneinfo
try:
import readline # NOQA
@ -17,8 +20,8 @@ except ImportError:
try:
import tzlocal
_DEFAULT_TIMEZONE = tzlocal.get_localzone().zone
except ImportError:
_DEFAULT_TIMEZONE = 'Europe/Rome'
except ModuleNotFoundError:
_DEFAULT_TIMEZONE = "Europe/Rome"
from pelican import __version__
@ -158,16 +161,15 @@ def ask(question, answer=str, default=None, length=None):
def ask_timezone(question, default, tzurl):
"""Prompt for time zone and validate input"""
lower_tz = [tz.lower() for tz in pytz.all_timezones]
tz_dict = {tz.lower(): tz for tz in zoneinfo.available_timezones()}
while True:
r = ask(question, str, default)
r = r.strip().replace(' ', '_').lower()
if r in lower_tz:
r = pytz.all_timezones[lower_tz.index(r)]
r = r.strip().replace(" ", "_").lower()
if r in tz_dict.keys():
r = tz_dict[r]
break
else:
print('Please enter a valid time zone:\n'
' (check [{}])'.format(tzurl))
print("Please enter a valid time zone:\n" " (check [{}])".format(tzurl))
return r