Revert "Bump apscheduler from 3.10.1 to 3.10.4 (#2133)"

This reverts commit 2c42150799.
This commit is contained in:
dependabot[bot] 2023-08-24 12:10:08 -07:00 committed by JonnyWong16
parent 1b26775ec6
commit 80e6131a0d
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
11 changed files with 825 additions and 855 deletions

View file

@ -1,9 +1,9 @@
import logging
# -*- coding: utf-8 -*-
import os
import time
import datetime
import calendar
import warnings
import pytz_deprecation_shim as pds
try:
import zoneinfo # pragma: no cover
@ -12,7 +12,35 @@ except ImportError:
from tzlocal import windows_tz
log = logging.getLogger("tzlocal")
class ZoneInfoNotFoundError(pds.UnknownTimeZoneError, zoneinfo.ZoneInfoNotFoundError):
"""An exception derived from both pytz and zoneinfo
This exception will be trappable both by pytz expecting clients and
zoneinfo expecting clients.
"""
def get_system_offset():
"""Get system's timezone offset using built-in library time.
For the Timezone constants (altzone, daylight, timezone, and tzname), the
value is determined by the timezone rules in effect at module load time or
the last time tzset() is called and may be incorrect for times in the past.
To keep compatibility with Windows, we're always importing time module here.
"""
localtime = calendar.timegm(time.localtime())
gmtime = calendar.timegm(time.gmtime())
offset = gmtime - localtime
# We could get the localtime and gmtime on either side of a second switch
# so we check that the difference is less than one minute, because nobody
# has that small DST differences.
if abs(offset - time.altzone) < 60:
return -time.altzone # pragma: no cover
else:
return -time.timezone # pragma: no cover
def get_tz_offset(tz):
@ -20,27 +48,19 @@ def get_tz_offset(tz):
return int(datetime.datetime.now(tz).utcoffset().total_seconds())
def assert_tz_offset(tz, error=True):
def assert_tz_offset(tz):
"""Assert that system's timezone offset equals to the timezone offset found.
If they don't match, we probably have a misconfiguration, for example, an
incorrect timezone set in /etc/timezone file in systemd distributions.
If error is True, this method will raise a ValueError, otherwise it will
emit a warning.
"""
incorrect timezone set in /etc/timezone file in systemd distributions."""
tz_offset = get_tz_offset(tz)
system_offset = calendar.timegm(time.localtime()) - calendar.timegm(time.gmtime())
# No one has timezone offsets less than a minute, so this should be close enough:
if abs(tz_offset - system_offset) > 60:
system_offset = get_system_offset()
if tz_offset != system_offset:
msg = (
"Timezone offset does not match system offset: {} != {}. "
"Please, check your config files."
).format(tz_offset, system_offset)
if error:
raise ValueError(msg)
warnings.warn(msg)
raise ValueError(msg)
def _tz_name_from_env(tzenv=None):
@ -50,8 +70,6 @@ def _tz_name_from_env(tzenv=None):
if not tzenv:
return None
log.debug(f"Found a TZ environment: {tzenv}")
if tzenv[0] == ":":
tzenv = tzenv[1:]
@ -74,9 +92,6 @@ def _tz_name_from_env(tzenv=None):
# Indeed
return parts[-1]
log.debug("TZ does not contain a time zone name")
return None
def _tz_from_env(tzenv=None):
if tzenv is None:
@ -97,16 +112,17 @@ def _tz_from_env(tzenv=None):
# Nope, not a standard timezone name, just take the filename
tzname = tzenv.split(os.sep)[-1]
with open(tzenv, "rb") as tzfile:
return zoneinfo.ZoneInfo.from_file(tzfile, key=tzname)
zone = zoneinfo.ZoneInfo.from_file(tzfile, key=tzname)
return pds.wrap_zone(zone)
# TZ must specify a zoneinfo zone.
try:
tz = zoneinfo.ZoneInfo(tzenv)
tz = pds.timezone(tzenv)
# That worked, so we return this:
return tz
except zoneinfo.ZoneInfoNotFoundError:
except pds.UnknownTimeZoneError:
# Nope, it's something like "PST4DST" etc, we can't handle that.
raise zoneinfo.ZoneInfoNotFoundError(
raise ZoneInfoNotFoundError(
"tzlocal() does not support non-zoneinfo timezones like %s. \n"
"Please use a timezone in the form of Continent/City" % tzenv
"Please use a timezone in the form of Continent/City"
) from None