mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 21:51:14 -07:00
Update pytz to 2018.6
Update the pytz library files to those from the 2018.6 release.
This commit is contained in:
parent
c08cec40cb
commit
71cb2d9c4c
609 changed files with 4505 additions and 209 deletions
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2003-2009 Stuart Bishop <stuart@stuartbishop.net>
|
Copyright (c) 2003-2018 Stuart Bishop <stuart@stuartbishop.net>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
|
|
@ -87,13 +87,13 @@ localized time using the standard ``astimezone()`` method:
|
||||||
Unfortunately using the tzinfo argument of the standard datetime
|
Unfortunately using the tzinfo argument of the standard datetime
|
||||||
constructors ''does not work'' with pytz for many timezones.
|
constructors ''does not work'' with pytz for many timezones.
|
||||||
|
|
||||||
>>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt)
|
>>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt) # /!\ Does not work this way!
|
||||||
'2002-10-27 12:00:00 LMT+0020'
|
'2002-10-27 12:00:00 LMT+0020'
|
||||||
|
|
||||||
It is safe for timezones without daylight saving transitions though, such
|
It is safe for timezones without daylight saving transitions though, such
|
||||||
as UTC:
|
as UTC:
|
||||||
|
|
||||||
>>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=pytz.utc).strftime(fmt)
|
>>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=pytz.utc).strftime(fmt) # /!\ Not recommended except for UTC
|
||||||
'2002-10-27 12:00:00 UTC+0000'
|
'2002-10-27 12:00:00 UTC+0000'
|
||||||
|
|
||||||
The preferred way of dealing with times is to always work in UTC,
|
The preferred way of dealing with times is to always work in UTC,
|
||||||
|
@ -134,19 +134,21 @@ section for more details)
|
||||||
>>> dt2.strftime(fmt)
|
>>> dt2.strftime(fmt)
|
||||||
'2002-10-27 01:30:00 EST-0500'
|
'2002-10-27 01:30:00 EST-0500'
|
||||||
|
|
||||||
Converting between timezones also needs special attention. We also need
|
Converting between timezones is more easily done, using the
|
||||||
to use the ``normalize()`` method to ensure the conversion is correct.
|
standard astimezone method.
|
||||||
|
|
||||||
>>> utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899))
|
>>> utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899))
|
||||||
>>> utc_dt.strftime(fmt)
|
>>> utc_dt.strftime(fmt)
|
||||||
'2006-03-26 21:34:59 UTC+0000'
|
'2006-03-26 21:34:59 UTC+0000'
|
||||||
>>> au_tz = timezone('Australia/Sydney')
|
>>> au_tz = timezone('Australia/Sydney')
|
||||||
>>> au_dt = au_tz.normalize(utc_dt.astimezone(au_tz))
|
>>> au_dt = utc_dt.astimezone(au_tz)
|
||||||
>>> au_dt.strftime(fmt)
|
>>> au_dt.strftime(fmt)
|
||||||
'2006-03-27 08:34:59 AEDT+1100'
|
'2006-03-27 08:34:59 AEDT+1100'
|
||||||
>>> utc_dt2 = utc.normalize(au_dt.astimezone(utc))
|
>>> utc_dt2 = au_dt.astimezone(utc)
|
||||||
>>> utc_dt2.strftime(fmt)
|
>>> utc_dt2.strftime(fmt)
|
||||||
'2006-03-26 21:34:59 UTC+0000'
|
'2006-03-26 21:34:59 UTC+0000'
|
||||||
|
>>> utc_dt == utc_dt2
|
||||||
|
True
|
||||||
|
|
||||||
You can take shortcuts when dealing with the UTC side of timezone
|
You can take shortcuts when dealing with the UTC side of timezone
|
||||||
conversions. ``normalize()`` and ``localize()`` are not really
|
conversions. ``normalize()`` and ``localize()`` are not really
|
||||||
|
@ -178,7 +180,7 @@ parameter to the ``utcoffset()``, ``dst()`` && ``tzname()`` methods.
|
||||||
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
||||||
|
|
||||||
The ``is_dst`` parameter is ignored for most timestamps. It is only used
|
The ``is_dst`` parameter is ignored for most timestamps. It is only used
|
||||||
during DST transition ambiguous periods to resulve that ambiguity.
|
during DST transition ambiguous periods to resolve that ambiguity.
|
||||||
|
|
||||||
>>> tz.utcoffset(normal, is_dst=True)
|
>>> tz.utcoffset(normal, is_dst=True)
|
||||||
datetime.timedelta(-1, 77400)
|
datetime.timedelta(-1, 77400)
|
||||||
|
@ -472,9 +474,9 @@ True
|
||||||
True
|
True
|
||||||
>>> 'Canada/Eastern' in common_timezones
|
>>> 'Canada/Eastern' in common_timezones
|
||||||
True
|
True
|
||||||
>>> 'US/Pacific-New' in all_timezones
|
>>> 'Australia/Yancowinna' in all_timezones
|
||||||
True
|
True
|
||||||
>>> 'US/Pacific-New' in common_timezones
|
>>> 'Australia/Yancowinna' in common_timezones
|
||||||
False
|
False
|
||||||
|
|
||||||
Both ``common_timezones`` and ``all_timezones`` are alphabetically
|
Both ``common_timezones`` and ``all_timezones`` are alphabetically
|
||||||
|
@ -510,6 +512,15 @@ Europe/Zurich
|
||||||
Europe/Zurich
|
Europe/Zurich
|
||||||
|
|
||||||
|
|
||||||
|
Internationalization - i18n/l10n
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Pytz is an interface to the IANA database, which uses ASCII names. The `Unicode Consortium's Unicode Locales (CLDR) <http://cldr.unicode.org>`_
|
||||||
|
project provides translations. Thomas Khyn's
|
||||||
|
`l18n <https://pypi.org/project/l18n/>`_ package can be used to access
|
||||||
|
these translations from Python.
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
|
@ -527,12 +538,13 @@ Latest Versions
|
||||||
|
|
||||||
This package will be updated after releases of the Olson timezone
|
This package will be updated after releases of the Olson timezone
|
||||||
database. The latest version can be downloaded from the `Python Package
|
database. The latest version can be downloaded from the `Python Package
|
||||||
Index <http://pypi.python.org/pypi/pytz/>`_. The code that is used
|
Index <https://pypi.org/project/pytz/>`_. The code that is used
|
||||||
to generate this distribution is hosted on launchpad.net and available
|
to generate this distribution is hosted on launchpad.net and available
|
||||||
using the `Bazaar version control system <http://bazaar-vcs.org>`_
|
using git::
|
||||||
using::
|
|
||||||
|
|
||||||
bzr branch lp:pytz
|
git clone https://git.launchpad.net/pytz
|
||||||
|
|
||||||
|
A mirror on github is also available at https://github.com/stub42/pytz
|
||||||
|
|
||||||
Announcements of new releases are made on
|
Announcements of new releases are made on
|
||||||
`Launchpad <https://launchpad.net/pytz>`_, and the
|
`Launchpad <https://launchpad.net/pytz>`_, and the
|
||||||
|
@ -543,7 +555,7 @@ hosted there.
|
||||||
Bugs, Feature Requests & Patches
|
Bugs, Feature Requests & Patches
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Bugs can be reported using `Launchpad <https://bugs.launchpad.net/pytz>`_.
|
Bugs can be reported using `Launchpad <https://bugs.launchpad.net/pytz>`__.
|
||||||
|
|
||||||
|
|
||||||
Issues & Limitations
|
Issues & Limitations
|
||||||
|
|
|
@ -8,9 +8,22 @@ See the datetime section of the Python Library Reference for information
|
||||||
on how to use these modules.
|
on how to use these modules.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import datetime
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
from pytz.exceptions import AmbiguousTimeError
|
||||||
|
from pytz.exceptions import InvalidTimeError
|
||||||
|
from pytz.exceptions import NonExistentTimeError
|
||||||
|
from pytz.exceptions import UnknownTimeZoneError
|
||||||
|
from pytz.lazy import LazyDict, LazyList, LazySet
|
||||||
|
from pytz.tzinfo import unpickler, BaseTzInfo
|
||||||
|
from pytz.tzfile import build_tzinfo
|
||||||
|
|
||||||
|
|
||||||
# The IANA (nee Olson) database is updated several times a year.
|
# The IANA (nee Olson) database is updated several times a year.
|
||||||
OLSON_VERSION = '2016f'
|
OLSON_VERSION = '2018f'
|
||||||
VERSION = '2016.6.1' # Switching to pip compatible version numbering.
|
VERSION = '2018.6' # pip compatible version number.
|
||||||
__version__ = VERSION
|
__version__ = VERSION
|
||||||
|
|
||||||
OLSEN_VERSION = OLSON_VERSION # Old releases had this misspelling
|
OLSEN_VERSION = OLSON_VERSION # Old releases had this misspelling
|
||||||
|
@ -21,23 +34,11 @@ __all__ = [
|
||||||
'NonExistentTimeError', 'UnknownTimeZoneError',
|
'NonExistentTimeError', 'UnknownTimeZoneError',
|
||||||
'all_timezones', 'all_timezones_set',
|
'all_timezones', 'all_timezones_set',
|
||||||
'common_timezones', 'common_timezones_set',
|
'common_timezones', 'common_timezones_set',
|
||||||
|
'BaseTzInfo',
|
||||||
]
|
]
|
||||||
|
|
||||||
import sys, datetime, os.path, gettext
|
|
||||||
|
|
||||||
from pytz.exceptions import AmbiguousTimeError
|
if sys.version_info[0] > 2: # Python 3.x
|
||||||
from pytz.exceptions import InvalidTimeError
|
|
||||||
from pytz.exceptions import NonExistentTimeError
|
|
||||||
from pytz.exceptions import UnknownTimeZoneError
|
|
||||||
from pytz.lazy import LazyDict, LazyList, LazySet
|
|
||||||
from pytz.tzinfo import unpickler
|
|
||||||
from pytz.tzfile import build_tzinfo, _byte_string
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
unicode
|
|
||||||
|
|
||||||
except NameError: # Python 3.x
|
|
||||||
|
|
||||||
# Python 3.x doesn't have unicode(), making writing code
|
# Python 3.x doesn't have unicode(), making writing code
|
||||||
# for Python 2.3 and Python 3.x a pain.
|
# for Python 2.3 and Python 3.x a pain.
|
||||||
|
@ -52,8 +53,11 @@ except NameError: # Python 3.x
|
||||||
...
|
...
|
||||||
UnicodeEncodeError: ...
|
UnicodeEncodeError: ...
|
||||||
"""
|
"""
|
||||||
|
if type(s) == bytes:
|
||||||
|
s = s.decode('ASCII')
|
||||||
|
else:
|
||||||
s.encode('ASCII') # Raise an exception if not ASCII
|
s.encode('ASCII') # Raise an exception if not ASCII
|
||||||
return s # But return the original string - not a byte string.
|
return s # But the string - not a byte string.
|
||||||
|
|
||||||
else: # Python 2.x
|
else: # Python 2.x
|
||||||
|
|
||||||
|
@ -76,11 +80,18 @@ def open_resource(name):
|
||||||
|
|
||||||
Uses the pkg_resources module if available and no standard file
|
Uses the pkg_resources module if available and no standard file
|
||||||
found at the calculated location.
|
found at the calculated location.
|
||||||
|
|
||||||
|
It is possible to specify different location for zoneinfo
|
||||||
|
subdir by using the PYTZ_TZDATADIR environment variable.
|
||||||
"""
|
"""
|
||||||
name_parts = name.lstrip('/').split('/')
|
name_parts = name.lstrip('/').split('/')
|
||||||
for part in name_parts:
|
for part in name_parts:
|
||||||
if part == os.path.pardir or os.path.sep in part:
|
if part == os.path.pardir or os.path.sep in part:
|
||||||
raise ValueError('Bad path segment: %r' % part)
|
raise ValueError('Bad path segment: %r' % part)
|
||||||
|
zoneinfo_dir = os.environ.get('PYTZ_TZDATADIR', None)
|
||||||
|
if zoneinfo_dir is not None:
|
||||||
|
filename = os.path.join(zoneinfo_dir, *name_parts)
|
||||||
|
else:
|
||||||
filename = os.path.join(os.path.dirname(__file__),
|
filename = os.path.join(os.path.dirname(__file__),
|
||||||
'zoneinfo', *name_parts)
|
'zoneinfo', *name_parts)
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
|
@ -106,23 +117,9 @@ def resource_exists(name):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Enable this when we get some translations?
|
|
||||||
# We want an i18n API that is useful to programs using Python's gettext
|
|
||||||
# module, as well as the Zope3 i18n package. Perhaps we should just provide
|
|
||||||
# the POT file and translations, and leave it up to callers to make use
|
|
||||||
# of them.
|
|
||||||
#
|
|
||||||
# t = gettext.translation(
|
|
||||||
# 'pytz', os.path.join(os.path.dirname(__file__), 'locales'),
|
|
||||||
# fallback=True
|
|
||||||
# )
|
|
||||||
# def _(timezone_name):
|
|
||||||
# """Translate a timezone name using the current locale, returning Unicode"""
|
|
||||||
# return t.ugettext(timezone_name)
|
|
||||||
|
|
||||||
|
|
||||||
_tzinfo_cache = {}
|
_tzinfo_cache = {}
|
||||||
|
|
||||||
|
|
||||||
def timezone(zone):
|
def timezone(zone):
|
||||||
r''' Return a datetime.tzinfo implementation for the given timezone
|
r''' Return a datetime.tzinfo implementation for the given timezone
|
||||||
|
|
||||||
|
@ -192,7 +189,7 @@ ZERO = datetime.timedelta(0)
|
||||||
HOUR = datetime.timedelta(hours=1)
|
HOUR = datetime.timedelta(hours=1)
|
||||||
|
|
||||||
|
|
||||||
class UTC(datetime.tzinfo):
|
class UTC(BaseTzInfo):
|
||||||
"""UTC
|
"""UTC
|
||||||
|
|
||||||
Optimized UTC implementation. It unpickles using the single module global
|
Optimized UTC implementation. It unpickles using the single module global
|
||||||
|
@ -288,7 +285,6 @@ def _p(*args):
|
||||||
_p.__safe_for_unpickling__ = True
|
_p.__safe_for_unpickling__ = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _CountryTimezoneDict(LazyDict):
|
class _CountryTimezoneDict(LazyDict):
|
||||||
"""Map ISO 3166 country code to a list of timezone names commonly used
|
"""Map ISO 3166 country code to a list of timezone names commonly used
|
||||||
in that country.
|
in that country.
|
||||||
|
@ -418,18 +414,18 @@ def FixedOffset(offset, _tzinfos = {}):
|
||||||
>>> one = FixedOffset(-330)
|
>>> one = FixedOffset(-330)
|
||||||
>>> one
|
>>> one
|
||||||
pytz.FixedOffset(-330)
|
pytz.FixedOffset(-330)
|
||||||
>>> one.utcoffset(datetime.datetime.now())
|
>>> str(one.utcoffset(datetime.datetime.now()))
|
||||||
datetime.timedelta(-1, 66600)
|
'-1 day, 18:30:00'
|
||||||
>>> one.dst(datetime.datetime.now())
|
>>> str(one.dst(datetime.datetime.now()))
|
||||||
datetime.timedelta(0)
|
'0:00:00'
|
||||||
|
|
||||||
>>> two = FixedOffset(1380)
|
>>> two = FixedOffset(1380)
|
||||||
>>> two
|
>>> two
|
||||||
pytz.FixedOffset(1380)
|
pytz.FixedOffset(1380)
|
||||||
>>> two.utcoffset(datetime.datetime.now())
|
>>> str(two.utcoffset(datetime.datetime.now()))
|
||||||
datetime.timedelta(0, 82800)
|
'23:00:00'
|
||||||
>>> two.dst(datetime.datetime.now())
|
>>> str(two.dst(datetime.datetime.now()))
|
||||||
datetime.timedelta(0)
|
'0:00:00'
|
||||||
|
|
||||||
The datetime.timedelta must be between the range of -1 and 1 day,
|
The datetime.timedelta must be between the range of -1 and 1 day,
|
||||||
non-inclusive.
|
non-inclusive.
|
||||||
|
@ -482,14 +478,13 @@ FixedOffset.__safe_for_unpickling__ = True
|
||||||
|
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
import doctest, os, sys
|
import doctest
|
||||||
sys.path.insert(0, os.pardir)
|
sys.path.insert(0, os.pardir)
|
||||||
import pytz
|
import pytz
|
||||||
return doctest.testmod(pytz)
|
return doctest.testmod(pytz)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
_test()
|
_test()
|
||||||
|
|
||||||
all_timezones = \
|
all_timezones = \
|
||||||
['Africa/Abidjan',
|
['Africa/Abidjan',
|
||||||
'Africa/Accra',
|
'Africa/Accra',
|
||||||
|
@ -676,6 +671,7 @@ all_timezones = \
|
||||||
'America/Porto_Acre',
|
'America/Porto_Acre',
|
||||||
'America/Porto_Velho',
|
'America/Porto_Velho',
|
||||||
'America/Puerto_Rico',
|
'America/Puerto_Rico',
|
||||||
|
'America/Punta_Arenas',
|
||||||
'America/Rainy_River',
|
'America/Rainy_River',
|
||||||
'America/Rankin_Inlet',
|
'America/Rankin_Inlet',
|
||||||
'America/Recife',
|
'America/Recife',
|
||||||
|
@ -731,6 +727,7 @@ all_timezones = \
|
||||||
'Asia/Aqtobe',
|
'Asia/Aqtobe',
|
||||||
'Asia/Ashgabat',
|
'Asia/Ashgabat',
|
||||||
'Asia/Ashkhabad',
|
'Asia/Ashkhabad',
|
||||||
|
'Asia/Atyrau',
|
||||||
'Asia/Baghdad',
|
'Asia/Baghdad',
|
||||||
'Asia/Bahrain',
|
'Asia/Bahrain',
|
||||||
'Asia/Baku',
|
'Asia/Baku',
|
||||||
|
@ -751,6 +748,7 @@ all_timezones = \
|
||||||
'Asia/Dili',
|
'Asia/Dili',
|
||||||
'Asia/Dubai',
|
'Asia/Dubai',
|
||||||
'Asia/Dushanbe',
|
'Asia/Dushanbe',
|
||||||
|
'Asia/Famagusta',
|
||||||
'Asia/Gaza',
|
'Asia/Gaza',
|
||||||
'Asia/Harbin',
|
'Asia/Harbin',
|
||||||
'Asia/Hebron',
|
'Asia/Hebron',
|
||||||
|
@ -816,6 +814,7 @@ all_timezones = \
|
||||||
'Asia/Vientiane',
|
'Asia/Vientiane',
|
||||||
'Asia/Vladivostok',
|
'Asia/Vladivostok',
|
||||||
'Asia/Yakutsk',
|
'Asia/Yakutsk',
|
||||||
|
'Asia/Yangon',
|
||||||
'Asia/Yekaterinburg',
|
'Asia/Yekaterinburg',
|
||||||
'Asia/Yerevan',
|
'Asia/Yerevan',
|
||||||
'Atlantic/Azores',
|
'Atlantic/Azores',
|
||||||
|
@ -861,7 +860,6 @@ all_timezones = \
|
||||||
'CST6CDT',
|
'CST6CDT',
|
||||||
'Canada/Atlantic',
|
'Canada/Atlantic',
|
||||||
'Canada/Central',
|
'Canada/Central',
|
||||||
'Canada/East-Saskatchewan',
|
|
||||||
'Canada/Eastern',
|
'Canada/Eastern',
|
||||||
'Canada/Mountain',
|
'Canada/Mountain',
|
||||||
'Canada/Newfoundland',
|
'Canada/Newfoundland',
|
||||||
|
@ -955,6 +953,7 @@ all_timezones = \
|
||||||
'Europe/Samara',
|
'Europe/Samara',
|
||||||
'Europe/San_Marino',
|
'Europe/San_Marino',
|
||||||
'Europe/Sarajevo',
|
'Europe/Sarajevo',
|
||||||
|
'Europe/Saratov',
|
||||||
'Europe/Simferopol',
|
'Europe/Simferopol',
|
||||||
'Europe/Skopje',
|
'Europe/Skopje',
|
||||||
'Europe/Sofia',
|
'Europe/Sofia',
|
||||||
|
@ -1072,7 +1071,6 @@ all_timezones = \
|
||||||
'US/Michigan',
|
'US/Michigan',
|
||||||
'US/Mountain',
|
'US/Mountain',
|
||||||
'US/Pacific',
|
'US/Pacific',
|
||||||
'US/Pacific-New',
|
|
||||||
'US/Samoa',
|
'US/Samoa',
|
||||||
'UTC',
|
'UTC',
|
||||||
'Universal',
|
'Universal',
|
||||||
|
@ -1252,6 +1250,7 @@ common_timezones = \
|
||||||
'America/Port_of_Spain',
|
'America/Port_of_Spain',
|
||||||
'America/Porto_Velho',
|
'America/Porto_Velho',
|
||||||
'America/Puerto_Rico',
|
'America/Puerto_Rico',
|
||||||
|
'America/Punta_Arenas',
|
||||||
'America/Rainy_River',
|
'America/Rainy_River',
|
||||||
'America/Rankin_Inlet',
|
'America/Rankin_Inlet',
|
||||||
'America/Recife',
|
'America/Recife',
|
||||||
|
@ -1301,6 +1300,7 @@ common_timezones = \
|
||||||
'Asia/Aqtau',
|
'Asia/Aqtau',
|
||||||
'Asia/Aqtobe',
|
'Asia/Aqtobe',
|
||||||
'Asia/Ashgabat',
|
'Asia/Ashgabat',
|
||||||
|
'Asia/Atyrau',
|
||||||
'Asia/Baghdad',
|
'Asia/Baghdad',
|
||||||
'Asia/Bahrain',
|
'Asia/Bahrain',
|
||||||
'Asia/Baku',
|
'Asia/Baku',
|
||||||
|
@ -1317,6 +1317,7 @@ common_timezones = \
|
||||||
'Asia/Dili',
|
'Asia/Dili',
|
||||||
'Asia/Dubai',
|
'Asia/Dubai',
|
||||||
'Asia/Dushanbe',
|
'Asia/Dushanbe',
|
||||||
|
'Asia/Famagusta',
|
||||||
'Asia/Gaza',
|
'Asia/Gaza',
|
||||||
'Asia/Hebron',
|
'Asia/Hebron',
|
||||||
'Asia/Ho_Chi_Minh',
|
'Asia/Ho_Chi_Minh',
|
||||||
|
@ -1351,7 +1352,6 @@ common_timezones = \
|
||||||
'Asia/Pyongyang',
|
'Asia/Pyongyang',
|
||||||
'Asia/Qatar',
|
'Asia/Qatar',
|
||||||
'Asia/Qyzylorda',
|
'Asia/Qyzylorda',
|
||||||
'Asia/Rangoon',
|
|
||||||
'Asia/Riyadh',
|
'Asia/Riyadh',
|
||||||
'Asia/Sakhalin',
|
'Asia/Sakhalin',
|
||||||
'Asia/Samarkand',
|
'Asia/Samarkand',
|
||||||
|
@ -1372,6 +1372,7 @@ common_timezones = \
|
||||||
'Asia/Vientiane',
|
'Asia/Vientiane',
|
||||||
'Asia/Vladivostok',
|
'Asia/Vladivostok',
|
||||||
'Asia/Yakutsk',
|
'Asia/Yakutsk',
|
||||||
|
'Asia/Yangon',
|
||||||
'Asia/Yekaterinburg',
|
'Asia/Yekaterinburg',
|
||||||
'Asia/Yerevan',
|
'Asia/Yerevan',
|
||||||
'Atlantic/Azores',
|
'Atlantic/Azores',
|
||||||
|
@ -1444,6 +1445,7 @@ common_timezones = \
|
||||||
'Europe/Samara',
|
'Europe/Samara',
|
||||||
'Europe/San_Marino',
|
'Europe/San_Marino',
|
||||||
'Europe/Sarajevo',
|
'Europe/Sarajevo',
|
||||||
|
'Europe/Saratov',
|
||||||
'Europe/Simferopol',
|
'Europe/Simferopol',
|
||||||
'Europe/Skopje',
|
'Europe/Skopje',
|
||||||
'Europe/Sofia',
|
'Europe/Sofia',
|
||||||
|
@ -1489,7 +1491,6 @@ common_timezones = \
|
||||||
'Pacific/Guadalcanal',
|
'Pacific/Guadalcanal',
|
||||||
'Pacific/Guam',
|
'Pacific/Guam',
|
||||||
'Pacific/Honolulu',
|
'Pacific/Honolulu',
|
||||||
'Pacific/Johnston',
|
|
||||||
'Pacific/Kiritimati',
|
'Pacific/Kiritimati',
|
||||||
'Pacific/Kosrae',
|
'Pacific/Kosrae',
|
||||||
'Pacific/Kwajalein',
|
'Pacific/Kwajalein',
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
try:
|
try:
|
||||||
from UserDict import DictMixin
|
from collections.abc import Mapping as DictMixin
|
||||||
except ImportError:
|
except ImportError: # Python < 3.3
|
||||||
|
try:
|
||||||
|
from UserDict import DictMixin # Python 2
|
||||||
|
except ImportError: # Python 3.0-3.3
|
||||||
from collections import Mapping as DictMixin
|
from collections import Mapping as DictMixin
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +16,7 @@ _fill_lock = RLock()
|
||||||
class LazyDict(DictMixin):
|
class LazyDict(DictMixin):
|
||||||
"""Dictionary populated on first use."""
|
"""Dictionary populated on first use."""
|
||||||
data = None
|
data = None
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if self.data is None:
|
if self.data is None:
|
||||||
_fill_lock.acquire()
|
_fill_lock.acquire()
|
||||||
|
|
|
@ -5,12 +5,23 @@ Used for testing against as they are only correct for the years
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from datetime import tzinfo, timedelta, datetime
|
from datetime import tzinfo, timedelta, datetime
|
||||||
from pytz import utc, UTC, HOUR, ZERO
|
from pytz import HOUR, ZERO, UTC
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'FixedOffset',
|
||||||
|
'LocalTimezone',
|
||||||
|
'USTimeZone',
|
||||||
|
'Eastern',
|
||||||
|
'Central',
|
||||||
|
'Mountain',
|
||||||
|
'Pacific',
|
||||||
|
'UTC'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# A class building tzinfo objects for fixed-offset time zones.
|
# A class building tzinfo objects for fixed-offset time zones.
|
||||||
# Note that FixedOffset(0, "UTC") is a different way to build a
|
# Note that FixedOffset(0, "UTC") is a different way to build a
|
||||||
# UTC tzinfo object.
|
# UTC tzinfo object.
|
||||||
|
|
||||||
class FixedOffset(tzinfo):
|
class FixedOffset(tzinfo):
|
||||||
"""Fixed offset in minutes east from UTC."""
|
"""Fixed offset in minutes east from UTC."""
|
||||||
|
|
||||||
|
@ -27,7 +38,6 @@ class FixedOffset(tzinfo):
|
||||||
def dst(self, dt):
|
def dst(self, dt):
|
||||||
return ZERO
|
return ZERO
|
||||||
|
|
||||||
# A class capturing the platform's idea of local time.
|
|
||||||
|
|
||||||
import time as _time
|
import time as _time
|
||||||
|
|
||||||
|
@ -39,6 +49,8 @@ else:
|
||||||
|
|
||||||
DSTDIFF = DSTOFFSET - STDOFFSET
|
DSTDIFF = DSTOFFSET - STDOFFSET
|
||||||
|
|
||||||
|
|
||||||
|
# A class capturing the platform's idea of local time.
|
||||||
class LocalTimezone(tzinfo):
|
class LocalTimezone(tzinfo):
|
||||||
|
|
||||||
def utcoffset(self, dt):
|
def utcoffset(self, dt):
|
||||||
|
@ -66,7 +78,6 @@ class LocalTimezone(tzinfo):
|
||||||
|
|
||||||
Local = LocalTimezone()
|
Local = LocalTimezone()
|
||||||
|
|
||||||
# A complete implementation of current DST rules for major US time zones.
|
|
||||||
|
|
||||||
def first_sunday_on_or_after(dt):
|
def first_sunday_on_or_after(dt):
|
||||||
days_to_go = 6 - dt.weekday()
|
days_to_go = 6 - dt.weekday()
|
||||||
|
@ -74,12 +85,15 @@ def first_sunday_on_or_after(dt):
|
||||||
dt += timedelta(days_to_go)
|
dt += timedelta(days_to_go)
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
|
|
||||||
# In the US, DST starts at 2am (standard time) on the first Sunday in April.
|
# In the US, DST starts at 2am (standard time) on the first Sunday in April.
|
||||||
DSTSTART = datetime(1, 4, 1, 2)
|
DSTSTART = datetime(1, 4, 1, 2)
|
||||||
# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct.
|
# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct.
|
||||||
# which is the first Sunday on or after Oct 25.
|
# which is the first Sunday on or after Oct 25.
|
||||||
DSTEND = datetime(1, 10, 25, 1)
|
DSTEND = datetime(1, 10, 25, 1)
|
||||||
|
|
||||||
|
|
||||||
|
# A complete implementation of current DST rules for major US time zones.
|
||||||
class USTimeZone(tzinfo):
|
class USTimeZone(tzinfo):
|
||||||
|
|
||||||
def __init__(self, hours, reprname, stdname, dstname):
|
def __init__(self, hours, reprname, stdname, dstname):
|
||||||
|
@ -124,4 +138,3 @@ Eastern = USTimeZone(-5, "Eastern", "EST", "EDT")
|
||||||
Central = USTimeZone(-6, "Central", "CST", "CDT")
|
Central = USTimeZone(-6, "Central", "CST", "CDT")
|
||||||
Mountain = USTimeZone(-7, "Mountain", "MST", "MDT")
|
Mountain = USTimeZone(-7, "Mountain", "MST", "MDT")
|
||||||
Pacific = USTimeZone(-8, "Pacific", "PST", "PDT")
|
Pacific = USTimeZone(-8, "Pacific", "PST", "PDT")
|
||||||
|
|
||||||
|
|
|
@ -3,26 +3,25 @@
|
||||||
$Id: tzfile.py,v 1.8 2004/06/03 00:15:24 zenzen Exp $
|
$Id: tzfile.py,v 1.8 2004/06/03 00:15:24 zenzen Exp $
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
from datetime import datetime
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from struct import unpack, calcsize
|
from struct import unpack, calcsize
|
||||||
|
|
||||||
from pytz.tzinfo import StaticTzInfo, DstTzInfo, memorized_ttinfo
|
from pytz.tzinfo import StaticTzInfo, DstTzInfo, memorized_ttinfo
|
||||||
from pytz.tzinfo import memorized_datetime, memorized_timedelta
|
from pytz.tzinfo import memorized_datetime, memorized_timedelta
|
||||||
|
|
||||||
|
|
||||||
def _byte_string(s):
|
def _byte_string(s):
|
||||||
"""Cast a string or byte string to an ASCII byte string."""
|
"""Cast a string or byte string to an ASCII byte string."""
|
||||||
return s.encode('ASCII')
|
return s.encode('ASCII')
|
||||||
|
|
||||||
_NULL = _byte_string('\0')
|
_NULL = _byte_string('\0')
|
||||||
|
|
||||||
|
|
||||||
def _std_string(s):
|
def _std_string(s):
|
||||||
"""Cast a string or byte string to an ASCII string."""
|
"""Cast a string or byte string to an ASCII string."""
|
||||||
return str(s.decode('ASCII'))
|
return str(s.decode('ASCII'))
|
||||||
|
|
||||||
|
|
||||||
def build_tzinfo(zone, fp):
|
def build_tzinfo(zone, fp):
|
||||||
head_fmt = '>4s c 15x 6l'
|
head_fmt = '>4s c 15x 6l'
|
||||||
head_size = calcsize(head_fmt)
|
head_size = calcsize(head_fmt)
|
||||||
|
@ -133,5 +132,3 @@ if __name__ == '__main__':
|
||||||
tz = build_tzinfo('US/Eastern',
|
tz = build_tzinfo('US/Eastern',
|
||||||
open(os.path.join(base, 'US', 'Eastern'), 'rb'))
|
open(os.path.join(base, 'US', 'Eastern'), 'rb'))
|
||||||
pprint(tz._utc_transition_times)
|
pprint(tz._utc_transition_times)
|
||||||
#print tz.asPython(4)
|
|
||||||
#print tz.transitions_mapping
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ from pytz.exceptions import AmbiguousTimeError, NonExistentTimeError
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
_timedelta_cache = {}
|
_timedelta_cache = {}
|
||||||
|
|
||||||
|
|
||||||
def memorized_timedelta(seconds):
|
def memorized_timedelta(seconds):
|
||||||
'''Create only one instance of each distinct timedelta'''
|
'''Create only one instance of each distinct timedelta'''
|
||||||
try:
|
try:
|
||||||
|
@ -24,6 +26,8 @@ def memorized_timedelta(seconds):
|
||||||
|
|
||||||
_epoch = datetime.utcfromtimestamp(0)
|
_epoch = datetime.utcfromtimestamp(0)
|
||||||
_datetime_cache = {0: _epoch}
|
_datetime_cache = {0: _epoch}
|
||||||
|
|
||||||
|
|
||||||
def memorized_datetime(seconds):
|
def memorized_datetime(seconds):
|
||||||
'''Create only one instance of each distinct datetime'''
|
'''Create only one instance of each distinct datetime'''
|
||||||
try:
|
try:
|
||||||
|
@ -36,6 +40,8 @@ def memorized_datetime(seconds):
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
_ttinfo_cache = {}
|
_ttinfo_cache = {}
|
||||||
|
|
||||||
|
|
||||||
def memorized_ttinfo(*args):
|
def memorized_ttinfo(*args):
|
||||||
'''Create only one instance of each distinct tuple'''
|
'''Create only one instance of each distinct tuple'''
|
||||||
try:
|
try:
|
||||||
|
@ -51,6 +57,7 @@ def memorized_ttinfo(*args):
|
||||||
|
|
||||||
_notime = memorized_timedelta(0)
|
_notime = memorized_timedelta(0)
|
||||||
|
|
||||||
|
|
||||||
def _to_seconds(td):
|
def _to_seconds(td):
|
||||||
'''Convert a timedelta to seconds'''
|
'''Convert a timedelta to seconds'''
|
||||||
return td.seconds + td.days * 24 * 60 * 60
|
return td.seconds + td.days * 24 * 60 * 60
|
||||||
|
@ -154,12 +161,18 @@ class DstTzInfo(BaseTzInfo):
|
||||||
timezone definition.
|
timezone definition.
|
||||||
'''
|
'''
|
||||||
# Overridden in subclass
|
# Overridden in subclass
|
||||||
_utc_transition_times = None # Sorted list of DST transition times in UTC
|
|
||||||
_transition_info = None # [(utcoffset, dstoffset, tzname)] corresponding
|
# Sorted list of DST transition times, UTC
|
||||||
# to _utc_transition_times entries
|
_utc_transition_times = None
|
||||||
|
|
||||||
|
# [(utcoffset, dstoffset, tzname)] corresponding to
|
||||||
|
# _utc_transition_times entries
|
||||||
|
_transition_info = None
|
||||||
|
|
||||||
zone = None
|
zone = None
|
||||||
|
|
||||||
# Set in __init__
|
# Set in __init__
|
||||||
|
|
||||||
_tzinfos = None
|
_tzinfos = None
|
||||||
_dst = None # DST offset
|
_dst = None # DST offset
|
||||||
|
|
||||||
|
@ -170,7 +183,8 @@ class DstTzInfo(BaseTzInfo):
|
||||||
else:
|
else:
|
||||||
_tzinfos = {}
|
_tzinfos = {}
|
||||||
self._tzinfos = _tzinfos
|
self._tzinfos = _tzinfos
|
||||||
self._utcoffset, self._dst, self._tzname = self._transition_info[0]
|
self._utcoffset, self._dst, self._tzname = (
|
||||||
|
self._transition_info[0])
|
||||||
_tzinfos[self._transition_info[0]] = self
|
_tzinfos[self._transition_info[0]] = self
|
||||||
for inf in self._transition_info[1:]:
|
for inf in self._transition_info[1:]:
|
||||||
if inf not in _tzinfos:
|
if inf not in _tzinfos:
|
||||||
|
@ -178,8 +192,8 @@ class DstTzInfo(BaseTzInfo):
|
||||||
|
|
||||||
def fromutc(self, dt):
|
def fromutc(self, dt):
|
||||||
'''See datetime.tzinfo.fromutc'''
|
'''See datetime.tzinfo.fromutc'''
|
||||||
if (dt.tzinfo is not None
|
if (dt.tzinfo is not None and
|
||||||
and getattr(dt.tzinfo, '_tzinfos', None) is not self._tzinfos):
|
getattr(dt.tzinfo, '_tzinfos', None) is not self._tzinfos):
|
||||||
raise ValueError('fromutc: dt.tzinfo is not self')
|
raise ValueError('fromutc: dt.tzinfo is not self')
|
||||||
dt = dt.replace(tzinfo=None)
|
dt = dt.replace(tzinfo=None)
|
||||||
idx = max(0, bisect_right(self._utc_transition_times, dt) - 1)
|
idx = max(0, bisect_right(self._utc_transition_times, dt) - 1)
|
||||||
|
@ -337,8 +351,8 @@ class DstTzInfo(BaseTzInfo):
|
||||||
# obtain the correct timezone by winding the clock back.
|
# obtain the correct timezone by winding the clock back.
|
||||||
else:
|
else:
|
||||||
return self.localize(
|
return self.localize(
|
||||||
dt - timedelta(hours=6), is_dst=False) + timedelta(hours=6)
|
dt - timedelta(hours=6),
|
||||||
|
is_dst=False) + timedelta(hours=6)
|
||||||
|
|
||||||
# If we get this far, we have multiple possible timezones - this
|
# If we get this far, we have multiple possible timezones - this
|
||||||
# is an ambiguous case occuring during the end-of-DST transition.
|
# is an ambiguous case occuring during the end-of-DST transition.
|
||||||
|
@ -351,8 +365,7 @@ class DstTzInfo(BaseTzInfo):
|
||||||
# Filter out the possiblilities that don't match the requested
|
# Filter out the possiblilities that don't match the requested
|
||||||
# is_dst
|
# is_dst
|
||||||
filtered_possible_loc_dt = [
|
filtered_possible_loc_dt = [
|
||||||
p for p in possible_loc_dt
|
p for p in possible_loc_dt if bool(p.tzinfo._dst) == is_dst
|
||||||
if bool(p.tzinfo._dst) == is_dst
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Hopefully we only have one possibility left. Return it.
|
# Hopefully we only have one possibility left. Return it.
|
||||||
|
@ -374,7 +387,8 @@ class DstTzInfo(BaseTzInfo):
|
||||||
# i.e., behave like end-of-DST transition
|
# i.e., behave like end-of-DST transition
|
||||||
dates = {} # utc -> local
|
dates = {} # utc -> local
|
||||||
for local_dt in filtered_possible_loc_dt:
|
for local_dt in filtered_possible_loc_dt:
|
||||||
utc_time = local_dt.replace(tzinfo=None) - local_dt.tzinfo._utcoffset
|
utc_time = (
|
||||||
|
local_dt.replace(tzinfo=None) - local_dt.tzinfo._utcoffset)
|
||||||
assert utc_time not in dates
|
assert utc_time not in dates
|
||||||
dates[utc_time] = local_dt
|
dates[utc_time] = local_dt
|
||||||
return dates[[min, max][not is_dst](dates)]
|
return dates[[min, max][not is_dst](dates)]
|
||||||
|
@ -389,11 +403,11 @@ class DstTzInfo(BaseTzInfo):
|
||||||
>>> tz = timezone('America/St_Johns')
|
>>> tz = timezone('America/St_Johns')
|
||||||
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
||||||
|
|
||||||
>>> tz.utcoffset(ambiguous, is_dst=False)
|
>>> str(tz.utcoffset(ambiguous, is_dst=False))
|
||||||
datetime.timedelta(-1, 73800)
|
'-1 day, 20:30:00'
|
||||||
|
|
||||||
>>> tz.utcoffset(ambiguous, is_dst=True)
|
>>> str(tz.utcoffset(ambiguous, is_dst=True))
|
||||||
datetime.timedelta(-1, 77400)
|
'-1 day, 21:30:00'
|
||||||
|
|
||||||
>>> try:
|
>>> try:
|
||||||
... tz.utcoffset(ambiguous)
|
... tz.utcoffset(ambiguous)
|
||||||
|
@ -421,19 +435,19 @@ class DstTzInfo(BaseTzInfo):
|
||||||
|
|
||||||
>>> normal = datetime(2009, 9, 1)
|
>>> normal = datetime(2009, 9, 1)
|
||||||
|
|
||||||
>>> tz.dst(normal)
|
>>> str(tz.dst(normal))
|
||||||
datetime.timedelta(0, 3600)
|
'1:00:00'
|
||||||
>>> tz.dst(normal, is_dst=False)
|
>>> str(tz.dst(normal, is_dst=False))
|
||||||
datetime.timedelta(0, 3600)
|
'1:00:00'
|
||||||
>>> tz.dst(normal, is_dst=True)
|
>>> str(tz.dst(normal, is_dst=True))
|
||||||
datetime.timedelta(0, 3600)
|
'1:00:00'
|
||||||
|
|
||||||
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
||||||
|
|
||||||
>>> tz.dst(ambiguous, is_dst=False)
|
>>> str(tz.dst(ambiguous, is_dst=False))
|
||||||
datetime.timedelta(0)
|
'0:00:00'
|
||||||
>>> tz.dst(ambiguous, is_dst=True)
|
>>> str(tz.dst(ambiguous, is_dst=True))
|
||||||
datetime.timedelta(0, 3600)
|
'1:00:00'
|
||||||
>>> try:
|
>>> try:
|
||||||
... tz.dst(ambiguous)
|
... tz.dst(ambiguous)
|
||||||
... except AmbiguousTimeError:
|
... except AmbiguousTimeError:
|
||||||
|
@ -512,7 +526,6 @@ class DstTzInfo(BaseTzInfo):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def unpickler(zone, utcoffset=None, dstoffset=None, tzname=None):
|
def unpickler(zone, utcoffset=None, dstoffset=None, tzname=None):
|
||||||
"""Factory function for unpickling pytz tzinfo instances.
|
"""Factory function for unpickling pytz tzinfo instances.
|
||||||
|
|
||||||
|
@ -549,8 +562,8 @@ def unpickler(zone, utcoffset=None, dstoffset=None, tzname=None):
|
||||||
# get changed from the initial guess by the database maintainers to
|
# get changed from the initial guess by the database maintainers to
|
||||||
# match reality when this information is discovered.
|
# match reality when this information is discovered.
|
||||||
for localized_tz in tz._tzinfos.values():
|
for localized_tz in tz._tzinfos.values():
|
||||||
if (localized_tz._utcoffset == utcoffset
|
if (localized_tz._utcoffset == utcoffset and
|
||||||
and localized_tz._dst == dstoffset):
|
localized_tz._dst == dstoffset):
|
||||||
return localized_tz
|
return localized_tz
|
||||||
|
|
||||||
# This (utcoffset, dstoffset) information has been removed from the
|
# This (utcoffset, dstoffset) information has been removed from the
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue