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,21 +1,20 @@
import logging
import os
import re
import sys
import warnings
from datetime import timezone
import pytz_deprecation_shim as pds
from tzlocal import utils
if sys.version_info >= (3, 9):
import zoneinfo # pragma: no cover
from zoneinfo import ZoneInfo # pragma: no cover
else:
from backports import zoneinfo # pragma: no cover
from backports.zoneinfo import ZoneInfo # pragma: no cover
_cache_tz = None
_cache_tz_name = None
log = logging.getLogger("tzlocal")
def _get_localzone_name(_root="/"):
"""Tries to find the local timezone configuration.
@ -33,21 +32,14 @@ def _get_localzone_name(_root="/"):
# Are we under Termux on Android?
if os.path.exists(os.path.join(_root, "system/bin/getprop")):
log.debug("This looks like Termux")
import subprocess
try:
androidtz = (
subprocess.check_output(["getprop", "persist.sys.timezone"])
.strip()
.decode()
)
return androidtz
except (OSError, subprocess.CalledProcessError):
# proot environment or failed to getprop
log.debug("It's not termux?")
pass
androidtz = (
subprocess.check_output(["getprop", "persist.sys.timezone"])
.strip()
.decode()
)
return androidtz
# Now look for distribution specific configuration files
# that contain the timezone name.
@ -58,11 +50,10 @@ def _get_localzone_name(_root="/"):
for configfile in ("etc/timezone", "var/db/zoneinfo"):
tzpath = os.path.join(_root, configfile)
try:
with open(tzpath) as tzfile:
with open(tzpath, "rt") as tzfile:
data = tzfile.read()
log.debug(f"{tzpath} found, contents:\n {data}")
etctz = data.strip("/ \t\r\n")
etctz = data.strip('/ \t\r\n')
if not etctz:
# Empty file, skip
continue
@ -77,7 +68,7 @@ def _get_localzone_name(_root="/"):
found_configs[tzpath] = etctz.replace(" ", "_")
except (OSError, UnicodeDecodeError):
except (IOError, UnicodeDecodeError):
# File doesn't exist or is a directory, or it's a binary file.
continue
@ -95,7 +86,6 @@ def _get_localzone_name(_root="/"):
try:
with open(tzpath, "rt") as tzfile:
data = tzfile.readlines()
log.debug(f"{tzpath} found, contents:\n {data}")
for line in data:
# Look for the ZONE= setting.
@ -105,13 +95,13 @@ def _get_localzone_name(_root="/"):
match = timezone_re.match(line)
if match is not None:
# Some setting existed
line = line[match.end() :]
line = line[match.end():]
etctz = line[: end_re.search(line).start()]
# We found a timezone
found_configs[tzpath] = etctz.replace(" ", "_")
except (OSError, UnicodeDecodeError):
except (IOError, UnicodeDecodeError):
# UnicodeDecode handles when clock is symlink to /etc/localtime
continue
@ -119,34 +109,30 @@ def _get_localzone_name(_root="/"):
# see manpage of localtime(5) and timedatectl(1)
tzpath = os.path.join(_root, "etc/localtime")
if os.path.exists(tzpath) and os.path.islink(tzpath):
log.debug(f"{tzpath} found")
etctz = os.path.realpath(tzpath)
etctz = realtzpath = os.path.realpath(tzpath)
start = etctz.find("/") + 1
while start != 0:
etctz = etctz[start:]
try:
zoneinfo.ZoneInfo(etctz)
pds.timezone(etctz)
tzinfo = f"{tzpath} is a symlink to"
found_configs[tzinfo] = etctz.replace(" ", "_")
# Only need first valid relative path in simlink.
break
except zoneinfo.ZoneInfoNotFoundError:
except pds.UnknownTimeZoneError:
pass
start = etctz.find("/") + 1
if len(found_configs) > 0:
log.debug(f"{len(found_configs)} found:\n {found_configs}")
# We found some explicit config of some sort!
if len(found_configs) > 1:
# Uh-oh, multiple configs. See if they match:
unique_tzs = set()
zoneinfopath = os.path.join(_root, "usr", "share", "zoneinfo")
directory_depth = len(zoneinfopath.split(os.path.sep))
zoneinfo = os.path.join(_root, "usr", "share", "zoneinfo")
directory_depth = len(zoneinfo.split(os.path.sep))
for tzname in found_configs.values():
# Look them up in /usr/share/zoneinfo, and find what they
# really point to:
path = os.path.realpath(os.path.join(zoneinfopath, *tzname.split("/")))
path = os.path.realpath(os.path.join(zoneinfo, *tzname.split("/")))
real_zone_name = "/".join(path.split(os.path.sep)[directory_depth:])
unique_tzs.add(real_zone_name)
@ -155,7 +141,7 @@ def _get_localzone_name(_root="/"):
for key, value in found_configs.items():
message += f"{key}: {value}\n"
message += "Fix the configuration, or set the time zone in a TZ environment variable.\n"
raise zoneinfo.ZoneInfoNotFoundError(message)
raise utils.ZoneInfoNotFoundError(message)
# We found exactly one config! Use it.
return list(found_configs.values())[0]
@ -179,25 +165,24 @@ def _get_localzone(_root="/"):
tzname = _get_localzone_name(_root)
if tzname is None:
# No explicit setting existed. Use localtime
log.debug("No explicit setting existed. Use localtime")
for filename in ("etc/localtime", "usr/local/etc/localtime"):
tzpath = os.path.join(_root, filename)
if not os.path.exists(tzpath):
continue
with open(tzpath, "rb") as tzfile:
tz = zoneinfo.ZoneInfo.from_file(tzfile, key="local")
tz = pds.wrap_zone(ZoneInfo.from_file(tzfile, key="local"))
break
else:
warnings.warn("Can not find any timezone configuration, defaulting to UTC.")
tz = timezone.utc
else:
tz = zoneinfo.ZoneInfo(tzname)
tz = pds.timezone(tzname)
if _root == "/":
# We are using a file in etc to name the timezone.
# Verify that the timezone specified there is actually used:
utils.assert_tz_offset(tz, error=False)
utils.assert_tz_offset(tz)
return tz