Downgrade tzlocal-2.1

This commit is contained in:
JonnyWong16 2021-10-15 09:05:54 -07:00
parent 5d46655507
commit ea398827cb
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
4 changed files with 33 additions and 46 deletions

View file

@ -1,16 +1,10 @@
import os import os
import pytz
import re import re
import sys
import warnings import warnings
from datetime import timezone
from tzlocal import utils from tzlocal import utils
if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
else:
from backports.zoneinfo import ZoneInfo, ZoneInfoNotFoundError
_cache_tz = None _cache_tz = None
@ -21,17 +15,17 @@ def _tz_from_env(tzenv):
# TZ specifies a file # TZ specifies a file
if os.path.isabs(tzenv) and os.path.exists(tzenv): if os.path.isabs(tzenv) and os.path.exists(tzenv):
with open(tzenv, 'rb') as tzfile: with open(tzenv, 'rb') as tzfile:
return ZoneInfo.from_file(tzfile, key='local') return pytz.tzfile.build_tzinfo('local', tzfile)
# TZ specifies a zoneinfo zone. # TZ specifies a zoneinfo zone.
try: try:
tz = ZoneInfo(tzenv) tz = pytz.timezone(tzenv)
# That worked, so we return this: # That worked, so we return this:
return tz return tz
except ZoneInfoNotFoundError: except pytz.UnknownTimeZoneError:
raise ZoneInfoNotFoundError( raise pytz.UnknownTimeZoneError(
"tzlocal() does not support non-zoneinfo timezones like %s. \n" "tzlocal() does not support non-zoneinfo timezones like %s. \n"
"Please use a timezone in the form of Continent/City") from None "Please use a timezone in the form of Continent/City")
def _try_tz_from_env(): def _try_tz_from_env():
@ -39,7 +33,7 @@ def _try_tz_from_env():
if tzenv: if tzenv:
try: try:
return _tz_from_env(tzenv) return _tz_from_env(tzenv)
except ZoneInfoNotFoundError: except pytz.UnknownTimeZoneError:
pass pass
@ -62,7 +56,7 @@ def _get_localzone(_root='/'):
if os.path.exists('/system/bin/getprop'): if os.path.exists('/system/bin/getprop'):
import subprocess import subprocess
androidtz = subprocess.check_output(['getprop', 'persist.sys.timezone']).strip().decode() androidtz = subprocess.check_output(['getprop', 'persist.sys.timezone']).strip().decode()
return ZoneInfo(androidtz) return pytz.timezone(androidtz)
# Now look for distribution specific configuration files # Now look for distribution specific configuration files
# that contain the timezone name. # that contain the timezone name.
@ -89,15 +83,15 @@ def _get_localzone(_root='/'):
etctz, dummy = etctz.split('#', 1) etctz, dummy = etctz.split('#', 1)
if not etctz: if not etctz:
continue continue
tz = ZoneInfo(etctz.replace(' ', '_')) tz = pytz.timezone(etctz.replace(' ', '_'))
if _root == '/': if _root == '/':
# We are using a file in etc to name the timezone. # We are using a file in etc to name the timezone.
# Verify that the timezone specified there is actually used: # Verify that the timezone specified there is actually used:
utils.assert_tz_offset(tz) utils.assert_tz_offset(tz)
return tz return tz
except (IOError, UnicodeDecodeError): except IOError:
# File doesn't exist or is a directory, or it's a binary file. # File doesn't exist or is a directory
continue continue
# CentOS has a ZONE setting in /etc/sysconfig/clock, # CentOS has a ZONE setting in /etc/sysconfig/clock,
@ -127,15 +121,15 @@ def _get_localzone(_root='/'):
etctz = line[:end_re.search(line).start()] etctz = line[:end_re.search(line).start()]
# We found a timezone # We found a timezone
tz = ZoneInfo(etctz.replace(' ', '_')) tz = pytz.timezone(etctz.replace(' ', '_'))
if _root == '/': if _root == '/':
# We are using a file in etc to name the timezone. # We are using a file in etc to name the timezone.
# Verify that the timezone specified there is actually used: # Verify that the timezone specified there is actually used:
utils.assert_tz_offset(tz) utils.assert_tz_offset(tz)
return tz return tz
except (IOError, UnicodeDecodeError) as e: except IOError:
# UnicodeDecode handles when clock is symlink to /etc/localtime # File doesn't exist or is a directory
continue continue
# systemd distributions use symlinks that include the zone name, # systemd distributions use symlinks that include the zone name,
@ -147,8 +141,8 @@ def _get_localzone(_root='/'):
while start != 0: while start != 0:
tzpath = tzpath[start:] tzpath = tzpath[start:]
try: try:
return ZoneInfo(tzpath) return pytz.timezone(tzpath)
except ZoneInfoNotFoundError: except pytz.UnknownTimeZoneError:
pass pass
start = tzpath.find("/")+1 start = tzpath.find("/")+1
@ -159,10 +153,10 @@ def _get_localzone(_root='/'):
if not os.path.exists(tzpath): if not os.path.exists(tzpath):
continue continue
with open(tzpath, 'rb') as tzfile: with open(tzpath, 'rb') as tzfile:
return ZoneInfo.from_file(tzfile, key='local') return pytz.tzfile.build_tzinfo('local', tzfile)
warnings.warn('Can not find any timezone configuration, defaulting to UTC.') warnings.warn('Can not find any timezone configuration, defaulting to UTC.')
return timezone.utc return pytz.utc
def get_localzone(): def get_localzone():
"""Get the computers configured local timezone, if any.""" """Get the computers configured local timezone, if any."""

View file

@ -1,18 +1,13 @@
import sys
try: try:
import _winreg as winreg import _winreg as winreg
except ImportError: except ImportError:
import winreg import winreg
import pytz
from tzlocal.windows_tz import win_tz from tzlocal.windows_tz import win_tz
from tzlocal import utils from tzlocal import utils
if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
else:
from backports.zoneinfo import ZoneInfo, ZoneInfoNotFoundError
_cache_tz = None _cache_tz = None
@ -86,7 +81,7 @@ def get_localzone_name():
# Return what we have. # Return what we have.
if timezone is None: if timezone is None:
raise ZoneInfoNotFoundError(tzkeyname) raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname)
return timezone return timezone
@ -95,7 +90,7 @@ def get_localzone():
"""Returns the zoneinfo-based tzinfo object that matches the Windows-configured timezone.""" """Returns the zoneinfo-based tzinfo object that matches the Windows-configured timezone."""
global _cache_tz global _cache_tz
if _cache_tz is None: if _cache_tz is None:
_cache_tz = ZoneInfo(get_localzone_name()) _cache_tz = pytz.timezone(get_localzone_name())
utils.assert_tz_offset(_cache_tz) utils.assert_tz_offset(_cache_tz)
return _cache_tz return _cache_tz
@ -104,6 +99,6 @@ def get_localzone():
def reload_localzone(): def reload_localzone():
"""Reload the cached localzone. You need to call this if the timezone has changed.""" """Reload the cached localzone. You need to call this if the timezone has changed."""
global _cache_tz global _cache_tz
_cache_tz = ZoneInfo(get_localzone_name()) _cache_tz = pytz.timezone(get_localzone_name())
utils.assert_tz_offset(_cache_tz) utils.assert_tz_offset(_cache_tz)
return _cache_tz return _cache_tz

View file

@ -104,7 +104,6 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Saratov Standard Time': 'Europe/Saratov', 'Saratov Standard Time': 'Europe/Saratov',
'Singapore Standard Time': 'Asia/Singapore', 'Singapore Standard Time': 'Asia/Singapore',
'South Africa Standard Time': 'Africa/Johannesburg', 'South Africa Standard Time': 'Africa/Johannesburg',
'South Sudan Standard Time': 'Africa/Juba',
'Sri Lanka Standard Time': 'Asia/Colombo', 'Sri Lanka Standard Time': 'Asia/Colombo',
'Sudan Standard Time': 'Africa/Khartoum', 'Sudan Standard Time': 'Africa/Khartoum',
'Syria Standard Time': 'Asia/Damascus', 'Syria Standard Time': 'Asia/Damascus',
@ -119,7 +118,7 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Turks And Caicos Standard Time': 'America/Grand_Turk', 'Turks And Caicos Standard Time': 'America/Grand_Turk',
'US Eastern Standard Time': 'America/Indianapolis', 'US Eastern Standard Time': 'America/Indianapolis',
'US Mountain Standard Time': 'America/Phoenix', 'US Mountain Standard Time': 'America/Phoenix',
'UTC': 'Etc/UTC', 'UTC': 'Etc/GMT',
'UTC+12': 'Etc/GMT-12', 'UTC+12': 'Etc/GMT-12',
'UTC+13': 'Etc/GMT-13', 'UTC+13': 'Etc/GMT-13',
'UTC-02': 'Etc/GMT+2', 'UTC-02': 'Etc/GMT+2',
@ -137,8 +136,7 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'West Asia Standard Time': 'Asia/Tashkent', 'West Asia Standard Time': 'Asia/Tashkent',
'West Bank Standard Time': 'Asia/Hebron', 'West Bank Standard Time': 'Asia/Hebron',
'West Pacific Standard Time': 'Pacific/Port_Moresby', 'West Pacific Standard Time': 'Pacific/Port_Moresby',
'Yakutsk Standard Time': 'Asia/Yakutsk', 'Yakutsk Standard Time': 'Asia/Yakutsk'}
'Yukon Standard Time': 'America/Whitehorse'}
# Old name for the win_tz variable: # Old name for the win_tz variable:
tz_names = win_tz tz_names = win_tz
@ -168,7 +166,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Africa/Gaborone': 'South Africa Standard Time', 'Africa/Gaborone': 'South Africa Standard Time',
'Africa/Harare': 'South Africa Standard Time', 'Africa/Harare': 'South Africa Standard Time',
'Africa/Johannesburg': 'South Africa Standard Time', 'Africa/Johannesburg': 'South Africa Standard Time',
'Africa/Juba': 'South Sudan Standard Time', 'Africa/Juba': 'E. Africa Standard Time',
'Africa/Kampala': 'E. Africa Standard Time', 'Africa/Kampala': 'E. Africa Standard Time',
'Africa/Khartoum': 'Sudan Standard Time', 'Africa/Khartoum': 'Sudan Standard Time',
'Africa/Kigali': 'South Africa Standard Time', 'Africa/Kigali': 'South Africa Standard Time',
@ -236,8 +234,8 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Creston': 'US Mountain Standard Time', 'America/Creston': 'US Mountain Standard Time',
'America/Cuiaba': 'Central Brazilian Standard Time', 'America/Cuiaba': 'Central Brazilian Standard Time',
'America/Curacao': 'SA Western Standard Time', 'America/Curacao': 'SA Western Standard Time',
'America/Danmarkshavn': 'Greenwich Standard Time', 'America/Danmarkshavn': 'UTC',
'America/Dawson': 'Yukon Standard Time', 'America/Dawson': 'Pacific Standard Time',
'America/Dawson_Creek': 'US Mountain Standard Time', 'America/Dawson_Creek': 'US Mountain Standard Time',
'America/Denver': 'Mountain Standard Time', 'America/Denver': 'Mountain Standard Time',
'America/Detroit': 'Eastern Standard Time', 'America/Detroit': 'Eastern Standard Time',
@ -347,14 +345,14 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Tortola': 'SA Western Standard Time', 'America/Tortola': 'SA Western Standard Time',
'America/Vancouver': 'Pacific Standard Time', 'America/Vancouver': 'Pacific Standard Time',
'America/Virgin': 'SA Western Standard Time', 'America/Virgin': 'SA Western Standard Time',
'America/Whitehorse': 'Yukon Standard Time', 'America/Whitehorse': 'Pacific Standard Time',
'America/Winnipeg': 'Central Standard Time', 'America/Winnipeg': 'Central Standard Time',
'America/Yakutat': 'Alaskan Standard Time', 'America/Yakutat': 'Alaskan Standard Time',
'America/Yellowknife': 'Mountain Standard Time', 'America/Yellowknife': 'Mountain Standard Time',
'Antarctica/Casey': 'Central Pacific Standard Time', 'Antarctica/Casey': 'Singapore Standard Time',
'Antarctica/Davis': 'SE Asia Standard Time', 'Antarctica/Davis': 'SE Asia Standard Time',
'Antarctica/DumontDUrville': 'West Pacific Standard Time', 'Antarctica/DumontDUrville': 'West Pacific Standard Time',
'Antarctica/Macquarie': 'Tasmania Standard Time', 'Antarctica/Macquarie': 'Central Pacific Standard Time',
'Antarctica/Mawson': 'West Asia Standard Time', 'Antarctica/Mawson': 'West Asia Standard Time',
'Antarctica/McMurdo': 'New Zealand Standard Time', 'Antarctica/McMurdo': 'New Zealand Standard Time',
'Antarctica/Palmer': 'SA Eastern Standard Time', 'Antarctica/Palmer': 'SA Eastern Standard Time',
@ -503,7 +501,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Canada/Newfoundland': 'Newfoundland Standard Time', 'Canada/Newfoundland': 'Newfoundland Standard Time',
'Canada/Pacific': 'Pacific Standard Time', 'Canada/Pacific': 'Pacific Standard Time',
'Canada/Saskatchewan': 'Canada Central Standard Time', 'Canada/Saskatchewan': 'Canada Central Standard Time',
'Canada/Yukon': 'Yukon Standard Time', 'Canada/Yukon': 'Pacific Standard Time',
'Chile/Continental': 'Pacific SA Standard Time', 'Chile/Continental': 'Pacific SA Standard Time',
'Chile/EasterIsland': 'Easter Island Standard Time', 'Chile/EasterIsland': 'Easter Island Standard Time',
'Cuba': 'Cuba Standard Time', 'Cuba': 'Cuba Standard Time',

View file

@ -44,7 +44,7 @@ soupsieve==2.2.1
tempora==4.1.2 tempora==4.1.2
tokenize-rt==4.1.0 tokenize-rt==4.1.0
tzdata==2021.2.post0 tzdata==2021.2.post0
tzlocal==3.0 tzlocal<3.0
urllib3==1.26.7 urllib3==1.26.7
webencodings==0.5.1 webencodings==0.5.1
websocket-client==1.2.1 websocket-client==1.2.1