Add stuck initiatives audit report

This commit is contained in:
Ezra
2026-04-03 22:42:06 +00:00
parent dc3d975c2f
commit 56aa692d1c
1267 changed files with 1263232 additions and 0 deletions

View File

@@ -0,0 +1,548 @@
Metadata-Version: 2.4
Name: croniter
Version: 6.2.2
Summary: croniter provides iteration for datetime object with cron like format
Project-URL: Homepage, https://github.com/pallets-eco/croniter
Author-email: Matsumoto Taichi <taichino@gmail.com>, kiorky <kiorky@cryptelium.net>, Ash Berlin-Taylor <ash@apache.org>, Jarek Potiuk <jarek@potiuk.com>
License-Expression: MIT
License-File: LICENSE
Keywords: cron,datetime,iterator
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Requires-Dist: python-dateutil
Description-Content-Type: text/x-rst
Introduction
============
.. contents::
croniter provides iteration for the datetime object with a cron like format.
::
_ _
___ _ __ ___ _ __ (_) |_ ___ _ __
/ __| '__/ _ \| '_ \| | __/ _ \ '__|
| (__| | | (_) | | | | | || __/ |
\___|_| \___/|_| |_|_|\__\___|_|
Website: https://github.com/pallets-eco/croniter
Build Badge
===========
.. image:: https://github.com/pallets-eco/croniter/actions/workflows/cicd.yml/badge.svg
:target: https://github.com/pallets-eco/croniter/actions/workflows/cicd.yml
Pallets Community Ecosystem
===========================
.. important::
This project is part of the Pallets Community Ecosystem. Pallets is the open
source organization that maintains Flask; Pallets-Eco enables community
maintenance of Flask extensions. If you are interested in helping maintain
this project, please reach out on the `Pallets Discord server
<https://discord.gg/pallets>`_.
Usage
============
A simple example::
>>> from croniter import croniter
>>> from datetime import datetime
>>> base = datetime(2010, 1, 25, 4, 46)
>>> iter = croniter('*/5 * * * *', base) # every 5 minutes
>>> print(iter.get_next(datetime)) # 2010-01-25 04:50:00
>>> print(iter.get_next(datetime)) # 2010-01-25 04:55:00
>>> print(iter.get_next(datetime)) # 2010-01-25 05:00:00
>>>
>>> iter = croniter('2 4 * * mon,fri', base) # 04:02 on every Monday and Friday
>>> print(iter.get_next(datetime)) # 2010-01-26 04:02:00
>>> print(iter.get_next(datetime)) # 2010-01-30 04:02:00
>>> print(iter.get_next(datetime)) # 2010-02-02 04:02:00
>>>
>>> iter = croniter('2 4 1 * wed', base) # 04:02 on every Wednesday OR on 1st day of month
>>> print(iter.get_next(datetime)) # 2010-01-27 04:02:00
>>> print(iter.get_next(datetime)) # 2010-02-01 04:02:00
>>> print(iter.get_next(datetime)) # 2010-02-03 04:02:00
>>>
>>> iter = croniter('2 4 1 * wed', base, day_or=False) # 04:02 on every 1st day of the month if it is a Wednesday
>>> print(iter.get_next(datetime)) # 2010-09-01 04:02:00
>>> print(iter.get_next(datetime)) # 2010-12-01 04:02:00
>>> print(iter.get_next(datetime)) # 2011-06-01 04:02:00
>>>
>>> iter = croniter('0 0 * * sat#1,sun#2', base) # 1st Saturday, and 2nd Sunday of the month
>>> print(iter.get_next(datetime)) # 2010-02-06 00:00:00
>>>
>>> iter = croniter('0 0 * * 5#3,L5', base) # 3rd and last Friday of the month
>>> print(iter.get_next(datetime)) # 2010-01-29 00:00:00
>>> print(iter.get_next(datetime)) # 2010-02-19 00:00:00
All you need to know is how to use the constructor and the ``get_next``
method, the signature of these methods are listed below::
>>> def __init__(self, cron_format, start_time=time.time(), day_or=True)
croniter iterates along with ``cron_format`` from ``start_time``.
``cron_format`` is **min hour day month day_of_week**, you can refer to
http://en.wikipedia.org/wiki/Cron for more details. The ``day_or``
switch is used to control how croniter handles **day** and **day_of_week**
entries. Default option is the cron behaviour, which connects those
values using **OR**. If the switch is set to False, the values are connected
using **AND**. This behaves like fcron and enables you to e.g. define a job that
executes each 2nd Friday of a month by setting the days of month and the
weekday.
::
>>> def get_next(self, ret_type=float)
get_next calculates the next value according to the cron expression and
returns an object of type ``ret_type``. ``ret_type`` should be a ``float`` or a
``datetime`` object.
Supported added for ``get_prev`` method. (>= 0.2.0)::
>>> base = datetime(2010, 8, 25)
>>> itr = croniter('0 0 1 * *', base)
>>> print(itr.get_prev(datetime)) # 2010-08-01 00:00:00
>>> print(itr.get_prev(datetime)) # 2010-07-01 00:00:00
>>> print(itr.get_prev(datetime)) # 2010-06-01 00:00:00
You can validate your crons using ``is_valid`` class method. (>= 0.3.18)::
>>> croniter.is_valid('0 0 1 * *') # True
>>> croniter.is_valid('0 wrong_value 1 * *') # False
Strict validation
-----------------
By default, ``is_valid`` and ``expand`` only check that each field is within its own range
(e.g. day 1-31, month 1-12). They do not cross-validate fields, so expressions like
``0 0 31 2 *`` (February 31st) are considered valid even though they can never match a real date.
Use ``strict=True`` to enable cross-field validation that rejects impossible day/month
combinations::
>>> croniter.is_valid('0 0 31 2 *') # True (default: syntax only)
>>> croniter.is_valid('0 0 31 2 *', strict=True) # False (Feb has at most 29 days)
>>> croniter.is_valid('0 0 31 4 *', strict=True) # False (Apr has 30 days)
>>> croniter.is_valid('0 0 30 1,2 *', strict=True) # True (day 30 is valid in Jan)
When ``strict=True`` and the expression does not include a year field, February is assumed to
have 29 days (since leap years exist)::
>>> croniter.is_valid('0 0 29 2 *', strict=True) # True (leap years exist)
If the expression includes a year field (7-field format), leap year status is determined from
the specified years::
>>> croniter.is_valid('0 0 29 2 * 0 2024', strict=True) # True (2024 is a leap year)
>>> croniter.is_valid('0 0 29 2 * 0 2023', strict=True) # False (2023 is not)
>>> croniter.is_valid('0 0 29 2 * 0 2023-2025', strict=True) # True (2024 in range is a leap year)
For 5- or 6-field expressions, you can pass ``strict_year`` to provide the year(s) for
leap year checking without adding a year field to the expression::
>>> croniter.is_valid('0 0 29 2 *', strict=True, strict_year=2024) # True (leap year)
>>> croniter.is_valid('0 0 29 2 *', strict=True, strict_year=2023) # False (not a leap year)
>>> croniter.is_valid('0 0 29 2 *', strict=True, strict_year=[2023, 2024]) # True (2024 is a leap year)
The ``strict`` and ``strict_year`` parameters are also available on ``expand()``::
>>> croniter.expand('0 0 31 2 *', strict=True) # raises CroniterBadCronError
Nearest weekday (W)
===================
The ``W`` character is supported in the day-of-month field to specify the nearest weekday
(Monday-Friday) to the given day. Both ``nW`` and ``Wn`` formats are accepted::
>>> base = datetime(2024, 6, 1)
>>> itr = croniter('0 9 15W * *', base)
>>> itr.get_next(datetime) # Jun 15 2024 is Saturday -> fires on Friday 14th
datetime.datetime(2024, 6, 14, 9, 0)
Rules:
- If the specified day falls on a weekday, the trigger fires on that day.
- If the specified day falls on Saturday, the trigger fires on the preceding Friday.
- If the specified day falls on Sunday, the trigger fires on the following Monday.
- The nearest weekday never crosses month boundaries. If the 1st is a Saturday, the trigger
fires on Monday the 3rd. If the last day of the month is a Sunday, the trigger fires on the
preceding Friday.
- ``W`` can only be used with a single day value, not in a range or list.
Examples::
>>> croniter('0 9 1W * *', datetime(2024, 5, 31)).get_next(datetime) # Jun 1 is Sat -> Mon 3rd
datetime.datetime(2024, 6, 3, 9, 0)
>>> croniter('0 9 W15 * *', datetime(2024, 1, 1)).get_next(datetime) # Wn format also works
datetime.datetime(2024, 1, 15, 9, 0)
Day-of-month and day-of-week
============================
When both the day-of-month and day-of-week fields are restricted (not ``*``),
the default POSIX cron behavior is to match when **either** field matches (OR).
This is controlled by the ``day_or`` parameter::
>>> # OR (default): fires on every Wednesday OR on the 1st of the month
>>> iter = croniter('2 4 1 * wed', datetime(2010, 1, 25))
>>> print(iter.get_next(datetime)) # 2010-01-27 04:02:00 (Wed)
>>> print(iter.get_next(datetime)) # 2010-02-01 04:02:00 (1st)
>>> # AND: fires only on the 1st of the month IF it is a Wednesday
>>> iter = croniter('2 4 1 * wed', datetime(2010, 1, 25), day_or=False)
>>> print(iter.get_next(datetime)) # 2010-09-01 04:02:00 (Wed AND 1st)
This can be used to express patterns like "the first Tuesday of the month"
by combining a day range with a weekday::
>>> # First Tuesday of each month: days 1-7 AND Tuesday
>>> iter = croniter('1 1 1-7 * 2', datetime(2024, 7, 12), day_or=False)
>>> print(iter.get_next(datetime)) # 2024-08-06 01:01:00
>>> print(iter.get_next(datetime)) # 2024-09-03 01:01:00
>>> print(iter.get_next(datetime)) # 2024-10-01 01:01:00
>>> print(iter.get_next(datetime)) # 2024-11-05 01:01:00
Vixie cron bug compatibility
----------------------------
Some vixie/ISC cron implementations have a `known bug
<https://crontab.guru/cron-bug.html>`_ where expressions that start with
``*`` in the day-of-month or day-of-week field (e.g. ``*/32,1-7``) use AND
logic instead of OR, even though those fields are technically restricted.
If you need to replicate this behavior (e.g. ``*/32,1-7`` as a hack for days
1-7), use ``implement_cron_bug=True``::
>>> iter = croniter('1 1 */32,1-7 * 2', datetime(2024, 7, 12), implement_cron_bug=True)
>>> print(iter.get_next(datetime)) # 2024-08-06 01:01:00
>>> print(iter.get_next(datetime)) # 2024-09-03 01:01:00
About DST
=========
Be sure to init your croniter instance with a TZ aware datetime for this to work!
Example using zoneinfo::
>>> import zoneinfo
>>> tz = zoneinfo.ZoneInfo("Europe/Berlin")
>>> local_date = datetime(2017, 3, 26, tzinfo=tz)
>>> val = croniter('0 0 * * *', local_date).get_next(datetime)
Example using pytz::
>>> import pytz
>>> tz = pytz.timezone("Europe/Paris")
>>> local_date = tz.localize(datetime(2017, 3, 26))
>>> val = croniter('0 0 * * *', local_date).get_next(datetime)
Example using python_dateutil::
>>> import dateutil.tz
>>> tz = dateutil.tz.gettz('Asia/Tokyo')
>>> local_date = datetime(2017, 3, 26, tzinfo=tz)
>>> val = croniter('0 0 * * *', local_date).get_next(datetime)
Example using python built in module::
>>> from datetime import datetime, timezone
>>> local_date = datetime(2017, 3, 26, tzinfo=timezone.utc)
>>> val = croniter('0 0 * * *', local_date).get_next(datetime)
About second repeats
=====================
Croniter is able to do second repetition crontabs form and by default seconds are the 6th field::
>>> base = datetime(2012, 4, 6, 13, 26, 10)
>>> itr = croniter('* * * * * 15,25', base)
>>> itr.get_next(datetime) # 4/6 13:26:15
>>> itr.get_next(datetime) # 4/6 13:26:25
>>> itr.get_next(datetime) # 4/6 13:27:15
You can also note that this expression will repeat every second from the start datetime.::
>>> croniter('* * * * * *', local_date).get_next(datetime)
You can also use seconds as first field::
>>> itr = croniter('15,25 * * * * *', base, second_at_beginning=True)
About year
===========
Croniter also support year field.
Year presents at the seventh field, which is after second repetition.
The range of year field is from 1970 to 2099.
To ignore second repetition, simply set second to ``0`` or any other const::
>>> base = datetime(2012, 4, 6, 2, 6, 59)
>>> itr = croniter('0 0 1 1 * 0 2020/2', base)
>>> itr.get_next(datetime) # 2020 1/1 0:0:0
>>> itr.get_next(datetime) # 2022 1/1 0:0:0
>>> itr.get_next(datetime) # 2024 1/1 0:0:0
Support for start_time shifts
==============================
See https://github.com/pallets-eco/croniter/pull/76,
You can set start_time=, then expand_from_start_time=True for your generations to be computed from start_time instead of calendar days::
>>> from pprint import pprint
>>> iter = croniter('0 0 */7 * *', start_time=datetime(2024, 7, 11), expand_from_start_time=True);pprint([iter.get_next(datetime) for a in range(10)])
[datetime.datetime(2024, 7, 18, 0, 0),
datetime.datetime(2024, 7, 25, 0, 0),
datetime.datetime(2024, 8, 4, 0, 0),
datetime.datetime(2024, 8, 11, 0, 0),
datetime.datetime(2024, 8, 18, 0, 0),
datetime.datetime(2024, 8, 25, 0, 0),
datetime.datetime(2024, 9, 4, 0, 0),
datetime.datetime(2024, 9, 11, 0, 0),
datetime.datetime(2024, 9, 18, 0, 0),
datetime.datetime(2024, 9, 25, 0, 0)]
>>> # INSTEAD OF THE DEFAULT BEHAVIOR:
>>> iter = croniter('0 0 */7 * *', start_time=datetime(2024, 7, 11), expand_from_start_time=False);pprint([iter.get_next(datetime) for a in range(10)])
[datetime.datetime(2024, 7, 15, 0, 0),
datetime.datetime(2024, 7, 22, 0, 0),
datetime.datetime(2024, 7, 29, 0, 0),
datetime.datetime(2024, 8, 1, 0, 0),
datetime.datetime(2024, 8, 8, 0, 0),
datetime.datetime(2024, 8, 15, 0, 0),
datetime.datetime(2024, 8, 22, 0, 0),
datetime.datetime(2024, 8, 29, 0, 0),
datetime.datetime(2024, 9, 1, 0, 0),
datetime.datetime(2024, 9, 8, 0, 0)]
Testing if a date matches a crontab
===================================
Test for a match with (>=0.3.32)::
>>> croniter.match("0 0 * * *", datetime(2019, 1, 14, 0, 0, 0, 0))
True
>>> croniter.match("0 0 * * *", datetime(2019, 1, 14, 0, 2, 0, 0))
False
>>>
>>> croniter.match("2 4 1 * wed", datetime(2019, 1, 1, 4, 2, 0, 0)) # 04:02 on every Wednesday OR on 1st day of month
True
>>> croniter.match("2 4 1 * wed", datetime(2019, 1, 1, 4, 2, 0, 0), day_or=False) # 04:02 on every 1st day of the month if it is a Wednesday
False
By default, ``match`` uses a precision of **60 seconds** for standard 5-field cron
expressions and **1 second** for 6-field expressions (with seconds). This means a
datetime up to 60 (or 1) seconds after the scheduled time will still match.
You can override this with the ``precision_in_seconds`` parameter::
>>> # With default precision (60s), 59 seconds past midnight still matches
>>> croniter.match("0 0 * * *", datetime(2019, 1, 14, 0, 0, 59, 0))
True
>>> # With precision=1, only an exact match within 1 second works
>>> croniter.match("0 0 * * *", datetime(2019, 1, 14, 0, 0, 59, 0), precision_in_seconds=1)
False
Testing if a crontab matches in datetime range
==============================================
Test for a match_range with (>=2.0.3)::
>>> croniter.match_range("0 0 * * *", datetime(2019, 1, 13, 0, 59, 0, 0), datetime(2019, 1, 14, 0, 1, 0, 0))
True
>>> croniter.match_range("0 0 * * *", datetime(2019, 1, 13, 0, 1, 0, 0), datetime(2019, 1, 13, 0, 59, 0, 0))
False
>>> croniter.match_range("2 4 1 * wed", datetime(2019, 1, 1, 3, 2, 0, 0), datetime(2019, 1, 1, 5, 1, 0, 0))
# 04:02 on every Wednesday OR on 1st day of month
True
>>> croniter.match_range("2 4 1 * wed", datetime(2019, 1, 1, 3, 2, 0, 0), datetime(2019, 1, 1, 5, 2, 0, 0), day_or=False)
# 04:02 on every 1st day of the month if it is a Wednesday
False
The ``precision_in_seconds`` parameter is also available on ``match_range``.
Gaps between date matches
=========================
For performance reasons, croniter limits the amount of CPU cycles spent attempting to find the next match.
Starting in v0.3.35, this behavior is configurable via the ``max_years_between_matches`` parameter, and the default window has been increased from 1 year to 50 years.
The defaults should be fine for many use cases.
Applications that evaluate multiple cron expressions or handle cron expressions from untrusted sources or end-users should use this parameter.
Iterating over sparse cron expressions can result in increased CPU consumption or a raised ``CroniterBadDateError`` exception which indicates that croniter has given up attempting to find the next (or previous) match.
Explicitly specifying ``max_years_between_matches`` provides a way to limit CPU utilization and simplifies the iterable interface by eliminating the need for ``CroniterBadDateError``.
The difference in the iterable interface is based on the reasoning that whenever ``max_years_between_matches`` is explicitly agreed upon, there is no need for croniter to signal that it has given up; simply stopping the iteration is preferable.
This example matches 4 AM Friday, January 1st.
Since January 1st isn't often a Friday, there may be a few years between each occurrence.
Setting the limit to 15 years ensures all matches::
>>> it = croniter("0 4 1 1 fri", datetime(2000,1,1), day_or=False, max_years_between_matches=15).all_next(datetime)
>>> for i in range(5):
... print(next(it))
...
2010-01-01 04:00:00
2016-01-01 04:00:00
2021-01-01 04:00:00
2027-01-01 04:00:00
2038-01-01 04:00:00
However, when only concerned with dates within the next 5 years, simply set ``max_years_between_matches=5`` in the above example.
This will result in no matches found, but no additional cycles will be wasted on unwanted matches far in the future.
Iterating over a range using cron
=================================
Find matches within a range using the ``croniter_range()`` function. This is much like the builtin ``range(start,stop,step)`` function, but for dates. The `step` argument is a cron expression.
Added in (>=0.3.34)
List the first Saturday of every month in 2019::
>>> from croniter import croniter_range
>>> for dt in croniter_range(datetime(2019, 1, 1), datetime(2019, 12, 31), "0 0 * * sat#1"):
>>> print(dt)
Hashed expressions
==================
croniter supports Jenkins-style hashed expressions, using the "H" definition keyword and the required hash_id keyword argument.
Hashed expressions remain consistent, given the same hash_id, but different hash_ids will evaluate completely different to each other.
This allows, for example, for an even distribution of differently-named jobs without needing to manually spread them out.
>>> itr = croniter("H H * * *", hash_id="hello")
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 10, 11, 10)
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 11, 11, 10)
>>> itr = croniter("H H * * *", hash_id="hello")
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 10, 11, 10)
>>> itr = croniter("H H * * *", hash_id="bonjour")
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 10, 20, 52)
Random expressions
==================
Random "R" definition keywords are supported, and remain consistent only within their croniter() instance.
>>> itr = croniter("R R * * *")
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 10, 22, 56)
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 11, 22, 56)
>>> itr = croniter("R R * * *")
>>> itr.get_next(datetime)
datetime.datetime(2021, 4, 11, 4, 19)
Note about Ranges
=================
Note that as a deviation from cron standard, croniter is somehow laxist with ranges and will allow ranges of ``Jan-Dec``, & ``Sun-Sat`` in reverse way and interpret them as following examples:
- ``Apr-Jan``: from April to january
- ``Sat-Sun``: Saturday, Sunday
- ``Wed-Sun``: Wednesday to Saturday, Sunday
Please note that if a /step is given, it will be respected.
Note about Sunday
=================
Note that as a deviation from cron standard, croniter like numerous cron implementations supports ``SUNDAY`` to be expressed as ``DAY7``, allowing such expressions:
- ``0 0 * * 7``
- ``0 0 * * 6-7``
- ``0 0 * * 6,7``
Keyword expressions
===================
Vixie cron-style "@" keyword expressions are supported.
What they evaluate to depends on whether you supply hash_id: no hash_id corresponds to Vixie cron definitions (exact times, minute resolution), while with hash_id corresponds to Jenkins definitions (hashed within the period, second resolution).
============ ============ ================
Keyword No hash_id With hash_id
============ ============ ================
@midnight 0 0 * * * H H(0-2) * * * H
@hourly 0 * * * * H * * * * H
@daily 0 0 * * * H H * * * H
@weekly 0 0 * * 0 H H * * H H
@monthly 0 0 1 * * H H H * * H
@yearly 0 0 1 1 * H H H H * H
@annually 0 0 1 1 * H H H H * H
============ ============ ================
Upgrading
==========
To 2.0.0
---------
- Install or upgrade pytz by using version specified requirements/base.txt if you have it installed `<=2021.1`.
Develop this package
====================
::
git clone https://github.com/pallets-eco/croniter.git
cd croniter
virtualenv --no-site-packages venv3
venv3/bin/pip install --upgrade -r requirements/test.txt -r requirements/lint.txt -r requirements/format.txt -r requirements/tox.txt
venv3/bin/black src/
venv3/bin/isort src/
venv3/bin/tox --current-env -e fmt,lint,test
Make a new release
====================
We use zest.fullreleaser, a great release infrastructure.
Do and follow these instructions
::
venv3/bin/pip install --upgrade -r requirements/release.txt
./release.sh
Contributors
===============
Thanks to all who have contributed to this project!
If you have contributed and your name is not listed below please let us know.
- Aarni Koskela (akx)
- ashb
- bdrung
- chris-baynes
- djmitche
- evanpurkhiser
- GreatCombinator
- Hinnack
- ipartola
- jlsandell
- kiorky
- lowell80 (Kintyre)
- mag009
- mrmachine
- potiuk
- Ryan Finnie (rfinnie)
- salitaba
- scop
- shazow
- yuzawa-san
- zed2015

View File

@@ -0,0 +1,26 @@
croniter-6.2.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
croniter-6.2.2.dist-info/METADATA,sha256=ZQtG0pp4gRDwT9razY4QYif1l-VPfulizpujJY5eBPE,22532
croniter-6.2.2.dist-info/RECORD,,
croniter-6.2.2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
croniter-6.2.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
croniter-6.2.2.dist-info/licenses/LICENSE,sha256=qPlS5sa7MLDPz3HDBOOTEWDSqbV41u3fpcwYyDLhftM,1064
croniter/__init__.py,sha256=Xm46VekwiEdBWfQ7EX3p15g5MkftJU-dXBKkZHLkFug,842
croniter/__pycache__/__init__.cpython-312.pyc,,
croniter/__pycache__/croniter.cpython-312.pyc,,
croniter/croniter.py,sha256=GKy--m5Cj5Gow-Q2u50UCE7GK2hIJzJcN3kG_4Htb8w,58523
croniter/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
croniter/tests/__pycache__/__init__.cpython-312.pyc,,
croniter/tests/__pycache__/base.cpython-312.pyc,,
croniter/tests/__pycache__/test_croniter.cpython-312.pyc,,
croniter/tests/__pycache__/test_croniter_dst_repetition.cpython-312.pyc,,
croniter/tests/__pycache__/test_croniter_hash.cpython-312.pyc,,
croniter/tests/__pycache__/test_croniter_random.cpython-312.pyc,,
croniter/tests/__pycache__/test_croniter_range.cpython-312.pyc,,
croniter/tests/__pycache__/test_croniter_speed.cpython-312.pyc,,
croniter/tests/base.py,sha256=mORYAtDxDQm1iAgheuLifIG5WVUQF7e5qX5lM9VKoCU,256
croniter/tests/test_croniter.py,sha256=wUuqtj9CLZwh_m6JyBKKgvobVmLMqrlF5jDPJMIrIis,113290
croniter/tests/test_croniter_dst_repetition.py,sha256=NwU7FyoUbE_8RiI122WXfKZfLYeDPFdlBpseibTwFa0,1686
croniter/tests/test_croniter_hash.py,sha256=ZTY_gYdSzoWobRX2tAVJFLzLP0Yo1-15rGnNgbU5klA,20762
croniter/tests/test_croniter_random.py,sha256=73zIRxasiPQUgDDK4Z81uEengA9x39qy4MYaY2YQfco,2010
croniter/tests/test_croniter_range.py,sha256=904QGe9jKiAyGQrfbMONxiQqcmvqjYqX4LES5YHk8UU,8486
croniter/tests/test_croniter_speed.py,sha256=wlm3RZZ8LhKgKRskgNudo9T1U5pmfqyt3okKkLVdlW0,3342

View File

@@ -0,0 +1,4 @@
Wheel-Version: 1.0
Generator: hatchling 1.29.0
Root-Is-Purelib: true
Tag: py3-none-any

View File

@@ -0,0 +1,7 @@
Copyright (C) 2010-2012 Matsumoto Taichi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,41 @@
from . import croniter as cron_m
from .croniter import (
DAY_FIELD,
HOUR_FIELD,
MINUTE_FIELD,
MONTH_FIELD,
OVERFLOW32B_MODE,
SECOND_FIELD,
UTC_DT,
YEAR_FIELD,
CroniterBadCronError,
CroniterBadDateError,
CroniterBadTypeRangeError,
CroniterError,
CroniterNotAlphaError,
CroniterUnsupportedSyntaxError,
croniter,
croniter_range,
datetime_to_timestamp,
)
__all__ = [
"DAY_FIELD",
"HOUR_FIELD",
"MINUTE_FIELD",
"MONTH_FIELD",
"OVERFLOW32B_MODE",
"SECOND_FIELD",
"UTC_DT",
"YEAR_FIELD",
"CroniterBadCronError",
"CroniterBadDateError",
"CroniterBadTypeRangeError",
"CroniterError",
"CroniterNotAlphaError",
"CroniterUnsupportedSyntaxError",
"cron_m",
"croniter",
"croniter_range",
"datetime_to_timestamp",
]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
import typing
import unittest
class TestCase(unittest.TestCase):
"""
We use this base class for all the tests in this package.
If necessary, we can put common utility or setup code in here.
"""
maxDiff: typing.Optional[int] = 10**10

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
#!/usr/bin/env python
"""
All related DST croniter tests are isolated here.
"""
# -*- coding: utf-8 -*-
import os
import time
import unittest
from datetime import datetime
from croniter import cron_m, croniter
from croniter.tests import base
ORIG_OVERFLOW32B_MODE = cron_m.OVERFLOW32B_MODE
class CroniterDST138Test(base.TestCase):
"""
See https://github.com/kiorky/croniter/issues/138.
"""
_tz = "UTC"
def setUp(self):
self._time = os.environ.setdefault("TZ", "")
self.base = datetime(2024, 1, 25, 4, 46)
self.iter = croniter("*/5 * * * *", self.base)
self.results = [
datetime(2024, 1, 25, 4, 50),
datetime(2024, 1, 25, 4, 55),
datetime(2024, 1, 25, 5, 0),
]
self.tzname, self.timezone = time.tzname, time.timezone
def tearDown(self):
cron_m.OVERFLOW32B_MODE = ORIG_OVERFLOW32B_MODE
if not self._time:
del os.environ["TZ"]
else:
os.environ["TZ"] = self._time
time.tzset()
def test_issue_138_dt_to_ts_32b(self):
"""
test local tz, forcing 32b mode.
"""
self._test(m32b=True)
def test_issue_138_dt_to_ts_n(self):
"""
test local tz, forcing non 32b mode.
"""
self._test(m32b=False)
def _test(self, tz="UTC", m32b=True):
cron_m.OVERFLOW32B_MODE = m32b
os.environ["TZ"] = tz
time.tzset()
res = [self.iter.get_next(datetime) for i in range(3)]
self.assertEqual(res, self.results)
class CroniterDST138TestLocal(CroniterDST138Test):
_tz = "UTC-8"
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,557 @@
import random
import unittest
import uuid
from datetime import datetime, timedelta
from croniter import CroniterBadCronError, CroniterNotAlphaError, croniter
from croniter.tests import base
class CroniterHashBase(base.TestCase):
epoch = datetime(2020, 1, 1, 0, 0)
hash_id = "hello"
def _test_iter(
self, definition, expectations, delta, epoch=None, hash_id=None, next_type=None
):
if epoch is None:
epoch = self.epoch
if hash_id is None:
hash_id = self.hash_id
if next_type is None:
next_type = datetime
if not isinstance(expectations, (list, tuple)):
expectations = (expectations,)
obj = croniter(definition, epoch, hash_id=hash_id)
testval = obj.get_next(next_type)
self.assertIn(testval, expectations)
if delta is not None:
self.assertEqual(obj.get_next(next_type), testval + delta)
class CroniterHashTest(CroniterHashBase):
def test_hash_hourly(self):
"""Test manually-defined hourly"""
self._test_iter("H * * * *", datetime(2020, 1, 1, 0, 10), timedelta(hours=1))
def test_hash_daily(self):
"""Test manually-defined daily"""
self._test_iter("H H * * *", datetime(2020, 1, 1, 11, 10), timedelta(days=1))
def test_hash_weekly(self):
"""Test manually-defined weekly"""
# croniter 1.0.5 changes the defined weekly range from (0, 6)
# to (0, 7), to match cron's behavior that Sunday is 0 or 7.
# This changes the hash, so test for either.
self._test_iter(
"H H * * H",
(datetime(2020, 1, 3, 11, 10), datetime(2020, 1, 5, 11, 10)),
timedelta(weeks=1),
)
def test_hash_monthly(self):
"""Test manually-defined monthly"""
self._test_iter("H H H * *", datetime(2020, 1, 1, 11, 10), timedelta(days=31))
def test_hash_yearly(self):
"""Test manually-defined yearly"""
self._test_iter("H H H H *", datetime(2020, 9, 1, 11, 10), timedelta(days=365))
def test_hash_second(self):
"""Test seconds
If a sixth field is provided, seconds are included in the datetime()
"""
self._test_iter("H H * * * H", datetime(2020, 1, 1, 11, 10, 32), timedelta(days=1))
def test_hash_year(self):
"""Test years
provide a seventh field as year
"""
self._test_iter("H H * * * H H", datetime(2066, 1, 1, 11, 10, 32), timedelta(days=1))
def test_hash_id_change(self):
"""Test a different hash_id returns different results given same definition and epoch"""
self._test_iter("H H * * *", datetime(2020, 1, 1, 11, 10), timedelta(days=1))
self._test_iter(
"H H * * *", datetime(2020, 1, 1, 0, 24), timedelta(days=1), hash_id="different id"
)
def test_hash_epoch_change(self):
"""Test a different epoch returns different results given same definition and hash_id"""
self._test_iter("H H * * *", datetime(2020, 1, 1, 11, 10), timedelta(days=1))
self._test_iter(
"H H * * *",
datetime(2011, 11, 12, 11, 10),
timedelta(days=1),
epoch=datetime(2011, 11, 11, 11, 11),
)
def test_hash_range(self):
"""Test a hashed range definition"""
self._test_iter("H H H(3-5) * *", datetime(2020, 1, 5, 11, 10), timedelta(days=31))
self._test_iter(
"H H * * * 0 H(2025-2030)", datetime(2029, 1, 1, 11, 10), timedelta(days=1)
)
def test_hash_division(self):
"""Test a hashed division definition"""
self._test_iter("H H/3 * * *", datetime(2020, 1, 1, 2, 10), timedelta(hours=3))
self._test_iter(
"H H H H * H H/2", datetime(2020, 9, 1, 11, 10, 32), timedelta(days=365 * 2)
)
def test_hash_range_division(self):
"""Test a hashed range + division definition"""
self._test_iter("H(30-59)/10 H * * *", datetime(2020, 1, 1, 11, 30), timedelta(minutes=10))
def test_hash_invalid_range(self):
"""Test validation logic for range_begin and range_end values"""
try:
self._test_iter(
"H(11-10) H * * *", datetime(2020, 1, 1, 11, 31), timedelta(minutes=10)
)
except CroniterBadCronError as ex:
self.assertEqual(str(ex), "Range end must be greater than range begin")
def test_hash_id_bytes(self):
"""Test hash_id as a bytes object"""
self._test_iter(
"H H * * *",
datetime(2020, 1, 1, 14, 53),
timedelta(days=1),
hash_id=b"\x01\x02\x03\x04",
)
def test_hash_float(self):
"""Test result as a float object"""
self._test_iter("H H * * *", 1577877000.0, (60 * 60 * 24), next_type=float)
def test_invalid_definition(self):
"""Test an invalid definition raises CroniterNotAlphaError"""
with self.assertRaises(CroniterNotAlphaError):
croniter("X X * * *", self.epoch, hash_id=self.hash_id)
def test_invalid_hash_id_type(self):
"""Test an invalid hash_id type raises TypeError"""
with self.assertRaises(TypeError):
croniter("H H * * *", self.epoch, hash_id={1: 2})
def test_invalid_divisor(self):
"""Test an invalid divisor type raises CroniterBadCronError"""
with self.assertRaises(CroniterBadCronError):
croniter("* * H/0 * *", self.epoch, hash_id=self.hash_id)
class CroniterWordAliasTest(CroniterHashBase):
def test_hash_word_midnight(self):
"""Test built-in @midnight
@midnight is actually up to 3 hours after midnight, not exactly midnight
"""
self._test_iter("@midnight", datetime(2020, 1, 1, 2, 10, 32), timedelta(days=1))
def test_hash_word_hourly(self):
"""Test built-in @hourly"""
self._test_iter("@hourly", datetime(2020, 1, 1, 0, 10, 32), timedelta(hours=1))
def test_hash_word_daily(self):
"""Test built-in @daily"""
self._test_iter("@daily", datetime(2020, 1, 1, 11, 10, 32), timedelta(days=1))
def test_hash_word_weekly(self):
"""Test built-in @weekly"""
# croniter 1.0.5 changes the defined weekly range from (0, 6)
# to (0, 7), to match cron's behavior that Sunday is 0 or 7.
# This changes the hash, so test for either.
self._test_iter(
"@weekly",
(datetime(2020, 1, 3, 11, 10, 32), datetime(2020, 1, 5, 11, 10, 32)),
timedelta(weeks=1),
)
def test_hash_word_monthly(self):
"""Test built-in @monthly"""
self._test_iter("@monthly", datetime(2020, 1, 1, 11, 10, 32), timedelta(days=31))
def test_hash_word_yearly(self):
"""Test built-in @yearly"""
self._test_iter("@yearly", datetime(2020, 9, 1, 11, 10, 32), timedelta(days=365))
def test_hash_word_annually(self):
"""Test built-in @annually
@annually is the same as @yearly
"""
obj_annually = croniter("@annually", self.epoch, hash_id=self.hash_id)
obj_yearly = croniter("@yearly", self.epoch, hash_id=self.hash_id)
self.assertEqual(obj_annually.get_next(datetime), obj_yearly.get_next(datetime))
self.assertEqual(obj_annually.get_next(datetime), obj_yearly.get_next(datetime))
class CroniterHashExpanderBase(base.TestCase):
def setUp(self):
_rd = random.Random()
_rd.seed(100)
self.HASH_IDS = [uuid.UUID(int=_rd.getrandbits(128)).bytes for _ in range(350)]
class CroniterHashExpanderExpandMinutesTest(CroniterHashExpanderBase):
MIN_VALUE = 0
MAX_VALUE = 59
TOTAL = 60
def test_expand_minutes(self):
minutes = set()
expression = "H * * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
minutes.add(expanded[0][0][0])
assert len(minutes) == self.TOTAL
assert min(minutes) == self.MIN_VALUE
assert max(minutes) == self.MAX_VALUE
def test_expand_minutes_range_2_minutes(self):
minutes = set()
expression = "H/2 * * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_minutes = expanded[0][0]
assert len(_minutes) == 30
minutes.update(_minutes)
assert len(minutes) == self.TOTAL
assert min(minutes) == self.MIN_VALUE
assert max(minutes) == self.MAX_VALUE
def test_expand_minutes_range_3_minutes(self):
minutes = set()
expression = "H/3 * * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_minutes = expanded[0][0]
assert len(_minutes) == 20
minutes.update(_minutes)
assert len(minutes) == self.TOTAL
assert min(minutes) == self.MIN_VALUE
assert max(minutes) == self.MAX_VALUE
def test_expand_minutes_range_15_minutes(self):
minutes = set()
expression = "H/15 * * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_minutes = expanded[0][0]
assert len(_minutes) == 4
minutes.update(_minutes)
assert len(minutes) == self.TOTAL
assert min(minutes) == self.MIN_VALUE
assert max(minutes) == self.MAX_VALUE
def test_expand_minutes_with_full_range(self):
minutes = set()
expression = "H(0-59) * * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
minutes.add(expanded[0][0][0])
assert len(minutes) == self.TOTAL
assert min(minutes) == self.MIN_VALUE
assert max(minutes) == self.MAX_VALUE
class CroniterHashExpanderExpandHoursTest(CroniterHashExpanderBase):
MIN_VALUE = 0
MAX_VALUE = 23
TOTAL = 24
def test_expand_hours(self):
hours = set()
expression = "H H * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
hours.add(expanded[0][1][0])
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
assert max(hours) == self.MAX_VALUE
def test_expand_hours_range_every_2_hours(self):
hours = set()
expression = "H H/2 * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_hours = expanded[0][1]
assert len(_hours) == 12
hours.update(_hours)
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
assert max(hours) == self.MAX_VALUE
def test_expand_hours_range_4_hours(self):
hours = set()
expression = "H H/4 * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_hours = expanded[0][1]
assert len(_hours) == 6
hours.update(_hours)
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
assert max(hours) == self.MAX_VALUE
def test_expand_hours_range_8_hours(self):
hours = set()
expression = "H H/8 * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_hours = expanded[0][1]
assert len(_hours) == 3
hours.update(_hours)
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
assert max(hours) == self.MAX_VALUE
def test_expand_hours_range_10_hours(self):
hours = set()
expression = "H H/10 * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_hours = expanded[0][1]
assert len(_hours) in {2, 3}
hours.update(_hours)
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
assert max(hours) == self.MAX_VALUE
def test_expand_hours_range_12_hours(self):
hours = set()
expression = "H H/12 * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_hours = expanded[0][1]
assert len(_hours) == 2
hours.update(_hours)
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
assert max(hours) == self.MAX_VALUE
def test_expand_hours_with_full_range(self):
minutes = set()
expression = "* H(0-23) * * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
minutes.add(expanded[0][1][0])
assert len(minutes) == self.TOTAL
assert min(minutes) == self.MIN_VALUE
assert max(minutes) == self.MAX_VALUE
class CroniterHashExpanderExpandMonthDaysTest(CroniterHashExpanderBase):
MIN_VALUE = 1
MAX_VALUE = 31
TOTAL = 31
def test_expand_month_days(self):
month_days = set()
expression = "H H H * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
month_days.add(expanded[0][2][0])
assert len(month_days) == self.TOTAL
assert min(month_days) == self.MIN_VALUE
assert max(month_days) == self.MAX_VALUE
def test_expand_month_days_range_2_days(self):
month_days = set()
expression = "0 0 H/2 * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_days = expanded[0][2]
assert len(_days) in {15, 16}
month_days.update(_days)
assert len(month_days) == self.TOTAL
assert min(month_days) == self.MIN_VALUE
assert max(month_days) == self.MAX_VALUE
def test_expand_month_days_range_5_days(self):
month_days = set()
expression = "H H H/5 * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_days = expanded[0][2]
assert len(_days) in {6, 7}
month_days.update(_days)
assert len(month_days) == self.TOTAL
assert min(month_days) == self.MIN_VALUE
assert max(month_days) == self.MAX_VALUE
def test_expand_month_days_range_12_days(self):
month_days = set()
expression = "H H H/12 * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_days = expanded[0][2]
assert len(_days) in {2, 3}
month_days.update(_days)
assert len(month_days) == self.TOTAL
assert min(month_days) == self.MIN_VALUE
assert max(month_days) == self.MAX_VALUE
def test_expand_month_days_with_full_range(self):
month_days = set()
expression = "* * H(1-31) * *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
month_days.add(expanded[0][2][0])
assert len(month_days) == self.TOTAL
assert min(month_days) == self.MIN_VALUE
assert max(month_days) == self.MAX_VALUE
class CroniterHashExpanderExpandMonthTest(CroniterHashExpanderBase):
MIN_VALUE = 1
MAX_VALUE = 12
TOTAL = 12
def test_expand_month_days(self):
month_days = set()
expression = "H H * H *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
month_days.add(expanded[0][3][0])
assert len(month_days) == self.TOTAL
assert min(month_days) == self.MIN_VALUE
assert max(month_days) == self.MAX_VALUE
def test_expand_month_days_range_2_months(self):
months = set()
expression = "H H * H/2 *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_months = expanded[0][3]
assert len(_months) == 6
months.update(_months)
assert len(months) == self.TOTAL
assert min(months) == self.MIN_VALUE
assert max(months) == self.MAX_VALUE
def test_expand_month_days_range_3_months(self):
months = set()
expression = "H H * H/3 *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_months = expanded[0][3]
assert len(_months) == 4
months.update(_months)
assert len(months) == self.TOTAL
assert min(months) == self.MIN_VALUE
assert max(months) == self.MAX_VALUE
def test_expand_month_days_range_5_months(self):
months = set()
expression = "H H * H/5 *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_months = expanded[0][3]
assert len(_months) in {2, 3}
months.update(_months)
assert len(months) == self.TOTAL
assert min(months) == self.MIN_VALUE
assert max(months) == self.MAX_VALUE
def test_expand_months_with_full_range(self):
months = set()
expression = "* * * H(1-12) *"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
months.add(expanded[0][3][0])
assert len(months) == self.TOTAL
assert min(months) == self.MIN_VALUE
assert max(months) == self.MAX_VALUE
class CroniterHashExpanderExpandWeekDays(CroniterHashExpanderBase):
MIN_VALUE = 0
MAX_VALUE = 6
TOTAL = 7
def test_expand_week_days(self):
week_days = set()
expression = "H H * * H"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
week_days.add(expanded[0][4][0])
assert len(week_days) == self.TOTAL
assert min(week_days) == self.MIN_VALUE
assert max(week_days) == self.MAX_VALUE
def test_expand_week_days_range_2_days(self):
days = set()
expression = "H H * * H/2"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_days = expanded[0][4]
assert len(_days) in {3, 4}
days.update(_days)
assert len(days) == self.TOTAL
assert min(days) == self.MIN_VALUE
assert max(days) == self.MAX_VALUE
def test_expand_week_days_range_4_days(self):
days = set()
expression = "H H * * H/4"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_days = expanded[0][4]
assert len(_days) in {1, 2}
days.update(_days)
assert len(days) == self.TOTAL
assert min(days) == self.MIN_VALUE
assert max(days) == self.MAX_VALUE
def test_expand_week_days_with_full_range(self):
days = set()
expression = "* * * * H(0-6)"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
days.add(expanded[0][4][0])
assert len(days) == self.TOTAL
assert min(days) == self.MIN_VALUE
assert max(days) == self.MAX_VALUE
class CroniterHashExpanderExpandYearsTest(CroniterHashExpanderBase):
def test_expand_years_by_division(self):
years = set()
year_min, year_max = croniter.RANGES[6]
expression = "* * * * * * H/10"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
assert len(expanded[0][6]) == 13
years.update(expanded[0][6])
assert len(years) == year_max - year_min + 1
assert min(years) == year_min
assert max(years) == year_max
def test_expand_years_by_range(self):
years = set()
expression = "* * * * * * H(2020-2030)"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
years.add(expanded[0][6][0])
assert len(years) == 11
assert min(years) == 2020
assert max(years) == 2030
def test_expand_years_by_range_and_division(self):
years = set()
expression = "* * * * * * H(2020-2050)/10"
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
years.update(expanded[0][6])
assert len(years) == 31
assert min(years) == 2020
assert max(years) == 2050
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,49 @@
import unittest
from datetime import datetime, timedelta
from croniter import croniter
from croniter.tests import base
class CroniterRandomTest(base.TestCase):
epoch = datetime(2020, 1, 1, 0, 0)
def test_random(self):
"""Test random definition"""
obj = croniter("R R * * *", self.epoch)
result_1 = obj.get_next(datetime)
self.assertGreaterEqual(result_1, datetime(2020, 1, 1, 0, 0))
self.assertLessEqual(result_1, datetime(2020, 1, 1, 0, 0) + timedelta(days=1))
result_2 = obj.get_next(datetime)
self.assertGreaterEqual(result_2, datetime(2020, 1, 2, 0, 0))
self.assertLessEqual(result_2, datetime(2020, 1, 2, 0, 0) + timedelta(days=1))
def test_random_range(self):
"""Test random definition within a range"""
obj = croniter("R R R(10-20) * *", self.epoch)
result_1 = obj.get_next(datetime)
self.assertGreaterEqual(result_1, datetime(2020, 1, 10, 0, 0))
self.assertLessEqual(result_1, datetime(2020, 1, 10, 0, 0) + timedelta(days=11))
result_2 = obj.get_next(datetime)
self.assertGreaterEqual(result_2, datetime(2020, 2, 10, 0, 0))
self.assertLessEqual(result_2, datetime(2020, 2, 10, 0, 0) + timedelta(days=11))
def test_random_float(self):
"""Test random definition, float result"""
obj = croniter("R R * * *", self.epoch)
result_1 = obj.get_next(float)
self.assertGreaterEqual(result_1, 1577836800.0)
self.assertLessEqual(result_1, 1577836800.0 + (60 * 60 * 24))
result_2 = obj.get_next(float)
self.assertGreaterEqual(result_2, 1577923200.0)
self.assertLessEqual(result_2, 1577923200.0 + (60 * 60 * 24))
def test_random_with_year(self):
obj = croniter("* * * * * * R(2025-2030)", self.epoch)
result = obj.get_next(datetime)
self.assertGreaterEqual(result.year, 2025)
self.assertLessEqual(result.year, 2030)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,228 @@
#!/usr/bin/env python
import unittest
import zoneinfo
from datetime import datetime
import pytz
from croniter import (
CroniterBadCronError,
CroniterBadDateError,
CroniterBadTypeRangeError,
croniter,
croniter_range,
)
from croniter.tests import base
class mydatetime(datetime):
"""."""
class CroniterRangeTest(base.TestCase):
def test_1day_step(self):
start = datetime(2016, 12, 2)
stop = datetime(2016, 12, 10)
fwd = list(croniter_range(start, stop, "0 0 * * *"))
self.assertEqual(len(fwd), 9)
self.assertEqual(fwd[0], start)
self.assertEqual(fwd[-1], stop)
# Test the same, but in reverse
rev = list(croniter_range(stop, start, "0 0 * * *"))
self.assertEqual(len(rev), 9)
# Ensure forward/reverse are a mirror image
rev.reverse()
self.assertEqual(fwd, rev)
def test_1day_step_no_ends(self):
# Test without ends (exclusive)
start = datetime(2016, 12, 2)
stop = datetime(2016, 12, 10)
fwd = list(croniter_range(start, stop, "0 0 * * *", exclude_ends=True))
self.assertEqual(len(fwd), 7)
self.assertNotEqual(fwd[0], start)
self.assertNotEqual(fwd[-1], stop)
# Test the same, but in reverse
rev = list(croniter_range(stop, start, "0 0 * * *", exclude_ends=True))
self.assertEqual(len(rev), 7)
self.assertNotEqual(fwd[0], stop)
self.assertNotEqual(fwd[-1], start)
def test_1month_step(self):
start = datetime(1982, 1, 1)
stop = datetime(1983, 12, 31)
res = list(croniter_range(start, stop, "0 0 1 * *"))
self.assertEqual(len(res), 24)
self.assertEqual(res[0], start)
self.assertEqual(res[5].day, 1)
self.assertEqual(res[-1], datetime(1983, 12, 1))
def test_1minute_step_float(self):
start = datetime(2000, 1, 1, 0, 0)
stop = datetime(2000, 1, 1, 0, 1)
res = list(croniter_range(start, stop, "* * * * *", ret_type=float))
self.assertEqual(len(res), 2)
self.assertEqual(res[0], 946684800.0)
self.assertEqual(res[-1] - res[0], 60)
def test_auto_ret_type(self):
data = [
(datetime(2019, 1, 1), datetime(2020, 1, 1), datetime),
(1552252218.0, 1591823311.0, float),
]
for start, stop, rtype in data:
ret = list(croniter_range(start, stop, "0 0 * * *"))
self.assertIsInstance(ret[0], rtype)
def test_input_type_exceptions(self):
dt_start1 = datetime(2019, 1, 1)
dt_stop1 = datetime(2020, 1, 1)
f_start1 = 1552252218.0
f_stop1 = 1591823311.0
# Mix start/stop types
with self.assertRaises(TypeError):
list(croniter_range(dt_start1, f_stop1, "0 * * * *"), ret_type=datetime)
with self.assertRaises(TypeError):
list(croniter_range(f_start1, dt_stop1, "0 * * * *"))
def test_timezone_dst_pytz(self):
"""Test across DST transition, which technically is a timzone change in pytz."""
tz = pytz.timezone("America/New_York")
start = tz.localize(datetime(2020, 10, 30))
stop = tz.localize(datetime(2020, 11, 10))
res = list(croniter_range(start, stop, "0 0 * * *"))
self.assertNotEqual(res[0].tzinfo, res[-1].tzinfo)
self.assertEqual(len(res), 12)
def test_extra_hour_day_prio(self):
"""Test New York jumps forward: 2020-03-08 02:00 -> 03:00 (UTC-5 -> UTC-4)."""
tz = zoneinfo.ZoneInfo("America/New_York")
cron = "0 3 * * *"
start = datetime(2020, 3, 7, tzinfo=tz)
end = datetime(2020, 3, 11, tzinfo=tz)
ret = [i.isoformat() for i in croniter_range(start, end, cron)]
self.assertEqual(
ret,
[
"2020-03-07T03:00:00-05:00",
"2020-03-08T03:00:00-04:00",
"2020-03-09T03:00:00-04:00",
"2020-03-10T03:00:00-04:00",
],
)
def test_extra_hour_day_prio_pytz(self):
"""Test New York jumps forward: 2020-03-08 02:00 -> 03:00 (UTC-5 -> UTC-4)."""
def datetime_tz(*args, **kw):
"""Defined this in another branch. single-use-version"""
tzinfo = kw.pop("tzinfo")
return tzinfo.localize(datetime(*args))
tz = pytz.timezone("America/New_York")
cron = "0 3 * * *"
start = datetime_tz(2020, 3, 7, tzinfo=tz)
end = datetime_tz(2020, 3, 11, tzinfo=tz)
ret = [i.isoformat() for i in croniter_range(start, end, cron)]
self.assertEqual(
ret,
[
"2020-03-07T03:00:00-05:00",
"2020-03-08T03:00:00-04:00",
"2020-03-09T03:00:00-04:00",
"2020-03-10T03:00:00-04:00",
],
)
def test_issue145_getnext(self):
# Example of quarterly event cron schedule
start = datetime(2020, 9, 24)
cron = "0 13 8 1,4,7,10 wed"
with self.assertRaises(CroniterBadDateError):
it = croniter(cron, start, day_or=False, max_years_between_matches=1)
it.get_next()
# New functionality (0.3.35) allowing croniter to find spare matches of cron
# patterns across multiple years
it = croniter(cron, start, day_or=False, max_years_between_matches=5)
self.assertEqual(it.get_next(datetime), datetime(2025, 1, 8, 13))
def test_issue145_range(self):
cron = "0 13 8 1,4,7,10 wed"
matches = list(
croniter_range(datetime(2020, 1, 1), datetime(2020, 12, 31), cron, day_or=False)
)
self.assertEqual(len(matches), 3)
self.assertEqual(matches[0], datetime(2020, 1, 8, 13))
self.assertEqual(matches[1], datetime(2020, 4, 8, 13))
self.assertEqual(matches[2], datetime(2020, 7, 8, 13))
# No matches within this range; therefore expect empty list
matches = list(
croniter_range(datetime(2020, 9, 30), datetime(2020, 10, 30), cron, day_or=False)
)
self.assertEqual(len(matches), 0)
def test_croniter_range_derived_class(self):
# trivial example extending croniter
class croniter_nosec(croniter):
"""Like croniter, but it forbids second-level cron expressions."""
@classmethod
def expand(cls, expr_format, *args, **kwargs):
if len(expr_format.split()) == 6:
raise CroniterBadCronError("Expected 'min hour day mon dow'")
return croniter.expand(expr_format, *args, **kwargs)
cron = "0 13 8 1,4,7,10 wed"
matches = list(
croniter_range(
datetime(2020, 1, 1),
datetime(2020, 12, 31),
cron,
day_or=False,
_croniter=croniter_nosec,
)
)
self.assertEqual(len(matches), 3)
cron = "0 1 8 1,15,L wed 15,45"
with self.assertRaises(CroniterBadCronError):
# Should fail using the custom class that forbids the seconds expression
croniter_nosec(cron)
with self.assertRaises(CroniterBadCronError):
# Should similarly fail because the custom class rejects seconds expr
i = croniter_range(
datetime(2020, 1, 1), datetime(2020, 12, 31), cron, _croniter=croniter_nosec
)
next(i)
def test_dt_types(self):
start = mydatetime(2020, 9, 24)
stop = datetime(2020, 9, 28)
try:
list(croniter_range(start, stop, "0 0 * * *"))
except CroniterBadTypeRangeError:
self.fail("should not be triggered")
def test_configure_second_location(self):
start = datetime(2016, 12, 2, 0, 0, 0)
stop = datetime(2016, 12, 2, 0, 1, 0)
fwd = list(croniter_range(start, stop, "*/20 * * * * *", second_at_beginning=True))
self.assertEqual(len(fwd), 4)
self.assertEqual(fwd[0], start)
self.assertEqual(fwd[-1], stop)
def test_year_range(self):
start = datetime(2010, 1, 1)
stop = datetime(2030, 1, 1)
fwd = list(croniter_range(start, stop, "0 0 1 1 ? 0 2020-2024,2028"))
self.assertEqual(len(fwd), 6)
self.assertEqual(fwd[0], datetime(2020, 1, 1))
self.assertEqual(fwd[-1], datetime(2028, 1, 1))
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,111 @@
#!/usr/bin/env python
import os
import unittest
import zoneinfo
from datetime import datetime
from timeit import Timer
from croniter import croniter
from croniter.tests import base
class CroniterSpeedTest(base.TestCase):
def run_long_test(self, iterations=1):
dt = datetime(2010, 1, 23, 12, 18)
itr = croniter("*/1 * * * *", dt)
for i in range(iterations): # ~ 58
itr.get_next()
itr = croniter("*/5 * * * *", dt)
for i in range(iterations):
itr.get_next()
dt = datetime(2010, 1, 24, 12, 2)
itr = croniter("0 */3 * * *", dt)
for i in range(iterations):
itr.get_next()
dt = datetime(2010, 2, 24, 12, 9)
itr = croniter("0 0 */3 * *", dt)
for i in range(iterations):
itr.get_next(datetime)
# test leap year
dt = datetime(1996, 2, 27)
itr = croniter("0 0 * * *", dt)
for i in range(iterations):
itr.get_next(datetime)
dt2 = datetime(2000, 2, 27)
itr2 = croniter("0 0 * * *", dt2)
for i in range(iterations):
itr2.get_next(datetime)
dt = datetime(2010, 2, 25)
itr = croniter("0 0 * * sat", dt)
for i in range(iterations):
itr.get_next(datetime)
dt = datetime(2010, 1, 25)
itr = croniter("0 0 1 * wed", dt)
for i in range(iterations):
itr.get_next(datetime)
dt = datetime(2010, 1, 25)
itr = croniter("0 0 1 * *", dt)
for i in range(iterations):
itr.get_next()
dt = datetime(2010, 8, 25, 15, 56)
itr = croniter("*/1 * * * *", dt)
for i in range(iterations):
itr.get_prev(datetime)
dt = datetime(2010, 8, 25, 15, 0)
itr = croniter("*/1 * * * *", dt)
for i in range(iterations):
itr.get_prev(datetime)
dt = datetime(2010, 8, 25, 0, 0)
itr = croniter("*/1 * * * *", dt)
for i in range(iterations):
itr.get_prev(datetime)
dt = datetime(2010, 8, 25, 15, 56)
itr = croniter("0 0 * * sat,sun", dt)
for i in range(iterations):
itr.get_prev(datetime)
dt = datetime(2010, 2, 25)
itr = croniter("0 0 * * 7", dt)
for i in range(iterations):
itr.get_prev(datetime)
# dst regression test
tz = zoneinfo.ZoneInfo("Europe/Bucharest")
offsets = set()
dst_cron = "15 0,3 * 3 *"
dst_iters = int(2 * 31 * (iterations / 40))
dt = datetime(2010, 1, 25, tzinfo=tz)
itr = croniter(dst_cron, dt)
for i in range(dst_iters):
d = itr.get_next(datetime)
offsets.add(d.utcoffset())
itr = croniter(dst_cron, dt)
for i in range(dst_iters):
d = itr.get_prev(datetime)
offsets.add(d.utcoffset())
def test_not_long_time(self):
iterations = int(os.environ.get("CRONITER_TEST_SPEED_ITERATIONS", "40"))
globs = globals()
globs.update(locals())
t = Timer("self.run_long_test(iterations)", globals=globs)
limit = 80
ret = t.timeit(limit)
self.assertTrue(ret < limit, f"Regression in croniter speed detected ({ret} {limit}).")
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import sys
try:
from ._version import version as __version__
except ImportError:
__version__ = 'unknown'
__all__ = ['easter', 'parser', 'relativedelta', 'rrule', 'tz',
'utils', 'zoneinfo']
def __getattr__(name):
import importlib
if name in __all__:
return importlib.import_module("." + name, __name__)
raise AttributeError(
"module {!r} has not attribute {!r}".format(__name__, name)
)
def __dir__():
# __dir__ should include all the lazy-importable modules as well.
return [x for x in globals() if x not in sys.modules] + __all__

View File

@@ -0,0 +1,43 @@
"""
Common code used in multiple modules.
"""
class weekday(object):
__slots__ = ["weekday", "n"]
def __init__(self, weekday, n=None):
self.weekday = weekday
self.n = n
def __call__(self, n):
if n == self.n:
return self
else:
return self.__class__(self.weekday, n)
def __eq__(self, other):
try:
if self.weekday != other.weekday or self.n != other.n:
return False
except AttributeError:
return False
return True
def __hash__(self):
return hash((
self.weekday,
self.n,
))
def __ne__(self, other):
return not (self == other)
def __repr__(self):
s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
if not self.n:
return s
else:
return "%s(%+d)" % (s, self.n)
# vim:ts=4:sw=4:et

View File

@@ -0,0 +1,4 @@
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = '2.9.0.post0'
__version_tuple__ = version_tuple = (2, 9, 0)

View File

@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
"""
This module offers a generic Easter computing method for any given year, using
Western, Orthodox or Julian algorithms.
"""
import datetime
__all__ = ["easter", "EASTER_JULIAN", "EASTER_ORTHODOX", "EASTER_WESTERN"]
EASTER_JULIAN = 1
EASTER_ORTHODOX = 2
EASTER_WESTERN = 3
def easter(year, method=EASTER_WESTERN):
"""
This method was ported from the work done by GM Arts,
on top of the algorithm by Claus Tondering, which was
based in part on the algorithm of Ouding (1940), as
quoted in "Explanatory Supplement to the Astronomical
Almanac", P. Kenneth Seidelmann, editor.
This algorithm implements three different Easter
calculation methods:
1. Original calculation in Julian calendar, valid in
dates after 326 AD
2. Original method, with date converted to Gregorian
calendar, valid in years 1583 to 4099
3. Revised method, in Gregorian calendar, valid in
years 1583 to 4099 as well
These methods are represented by the constants:
* ``EASTER_JULIAN = 1``
* ``EASTER_ORTHODOX = 2``
* ``EASTER_WESTERN = 3``
The default method is method 3.
More about the algorithm may be found at:
`GM Arts: Easter Algorithms <http://www.gmarts.org/index.php?go=415>`_
and
`The Calendar FAQ: Easter <https://www.tondering.dk/claus/cal/easter.php>`_
"""
if not (1 <= method <= 3):
raise ValueError("invalid method")
# g - Golden year - 1
# c - Century
# h - (23 - Epact) mod 30
# i - Number of days from March 21 to Paschal Full Moon
# j - Weekday for PFM (0=Sunday, etc)
# p - Number of days from March 21 to Sunday on or before PFM
# (-6 to 28 methods 1 & 3, to 56 for method 2)
# e - Extra days to add for method 2 (converting Julian
# date to Gregorian date)
y = year
g = y % 19
e = 0
if method < 3:
# Old method
i = (19*g + 15) % 30
j = (y + y//4 + i) % 7
if method == 2:
# Extra dates to convert Julian to Gregorian date
e = 10
if y > 1600:
e = e + y//100 - 16 - (y//100 - 16)//4
else:
# New method
c = y//100
h = (c - c//4 - (8*c + 13)//25 + 19*g + 15) % 30
i = h - (h//28)*(1 - (h//28)*(29//(h + 1))*((21 - g)//11))
j = (y + y//4 + i + 2 - c + c//4) % 7
# p can be from -6 to 56 corresponding to dates 22 March to 23 May
# (later dates apply to method 2, although 23 May never actually occurs)
p = i - j + e
d = 1 + (p + 27 + (p + 6)//40) % 31
m = 3 + (p + 26)//30
return datetime.date(int(y), int(m), int(d))

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
from ._parser import parse, parser, parserinfo, ParserError
from ._parser import DEFAULTPARSER, DEFAULTTZPARSER
from ._parser import UnknownTimezoneWarning
from ._parser import __doc__
from .isoparser import isoparser, isoparse
__all__ = ['parse', 'parser', 'parserinfo',
'isoparse', 'isoparser',
'ParserError',
'UnknownTimezoneWarning']
###
# Deprecate portions of the private interface so that downstream code that
# is improperly relying on it is given *some* notice.
def __deprecated_private_func(f):
from functools import wraps
import warnings
msg = ('{name} is a private function and may break without warning, '
'it will be moved and or renamed in future versions.')
msg = msg.format(name=f.__name__)
@wraps(f)
def deprecated_func(*args, **kwargs):
warnings.warn(msg, DeprecationWarning)
return f(*args, **kwargs)
return deprecated_func
def __deprecate_private_class(c):
import warnings
msg = ('{name} is a private class and may break without warning, '
'it will be moved and or renamed in future versions.')
msg = msg.format(name=c.__name__)
class private_class(c):
__doc__ = c.__doc__
def __init__(self, *args, **kwargs):
warnings.warn(msg, DeprecationWarning)
super(private_class, self).__init__(*args, **kwargs)
private_class.__name__ = c.__name__
return private_class
from ._parser import _timelex, _resultbase
from ._parser import _tzparser, _parsetz
_timelex = __deprecate_private_class(_timelex)
_tzparser = __deprecate_private_class(_tzparser)
_resultbase = __deprecate_private_class(_resultbase)
_parsetz = __deprecated_private_func(_parsetz)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,416 @@
# -*- coding: utf-8 -*-
"""
This module offers a parser for ISO-8601 strings
It is intended to support all valid date, time and datetime formats per the
ISO-8601 specification.
..versionadded:: 2.7.0
"""
from datetime import datetime, timedelta, time, date
import calendar
from dateutil import tz
from functools import wraps
import re
import six
__all__ = ["isoparse", "isoparser"]
def _takes_ascii(f):
@wraps(f)
def func(self, str_in, *args, **kwargs):
# If it's a stream, read the whole thing
str_in = getattr(str_in, 'read', lambda: str_in)()
# If it's unicode, turn it into bytes, since ISO-8601 only covers ASCII
if isinstance(str_in, six.text_type):
# ASCII is the same in UTF-8
try:
str_in = str_in.encode('ascii')
except UnicodeEncodeError as e:
msg = 'ISO-8601 strings should contain only ASCII characters'
six.raise_from(ValueError(msg), e)
return f(self, str_in, *args, **kwargs)
return func
class isoparser(object):
def __init__(self, sep=None):
"""
:param sep:
A single character that separates date and time portions. If
``None``, the parser will accept any single character.
For strict ISO-8601 adherence, pass ``'T'``.
"""
if sep is not None:
if (len(sep) != 1 or ord(sep) >= 128 or sep in '0123456789'):
raise ValueError('Separator must be a single, non-numeric ' +
'ASCII character')
sep = sep.encode('ascii')
self._sep = sep
@_takes_ascii
def isoparse(self, dt_str):
"""
Parse an ISO-8601 datetime string into a :class:`datetime.datetime`.
An ISO-8601 datetime string consists of a date portion, followed
optionally by a time portion - the date and time portions are separated
by a single character separator, which is ``T`` in the official
standard. Incomplete date formats (such as ``YYYY-MM``) may *not* be
combined with a time portion.
Supported date formats are:
Common:
- ``YYYY``
- ``YYYY-MM``
- ``YYYY-MM-DD`` or ``YYYYMMDD``
Uncommon:
- ``YYYY-Www`` or ``YYYYWww`` - ISO week (day defaults to 0)
- ``YYYY-Www-D`` or ``YYYYWwwD`` - ISO week and day
The ISO week and day numbering follows the same logic as
:func:`datetime.date.isocalendar`.
Supported time formats are:
- ``hh``
- ``hh:mm`` or ``hhmm``
- ``hh:mm:ss`` or ``hhmmss``
- ``hh:mm:ss.ssssss`` (Up to 6 sub-second digits)
Midnight is a special case for `hh`, as the standard supports both
00:00 and 24:00 as a representation. The decimal separator can be
either a dot or a comma.
.. caution::
Support for fractional components other than seconds is part of the
ISO-8601 standard, but is not currently implemented in this parser.
Supported time zone offset formats are:
- `Z` (UTC)
- `±HH:MM`
- `±HHMM`
- `±HH`
Offsets will be represented as :class:`dateutil.tz.tzoffset` objects,
with the exception of UTC, which will be represented as
:class:`dateutil.tz.tzutc`. Time zone offsets equivalent to UTC (such
as `+00:00`) will also be represented as :class:`dateutil.tz.tzutc`.
:param dt_str:
A string or stream containing only an ISO-8601 datetime string
:return:
Returns a :class:`datetime.datetime` representing the string.
Unspecified components default to their lowest value.
.. warning::
As of version 2.7.0, the strictness of the parser should not be
considered a stable part of the contract. Any valid ISO-8601 string
that parses correctly with the default settings will continue to
parse correctly in future versions, but invalid strings that
currently fail (e.g. ``2017-01-01T00:00+00:00:00``) are not
guaranteed to continue failing in future versions if they encode
a valid date.
.. versionadded:: 2.7.0
"""
components, pos = self._parse_isodate(dt_str)
if len(dt_str) > pos:
if self._sep is None or dt_str[pos:pos + 1] == self._sep:
components += self._parse_isotime(dt_str[pos + 1:])
else:
raise ValueError('String contains unknown ISO components')
if len(components) > 3 and components[3] == 24:
components[3] = 0
return datetime(*components) + timedelta(days=1)
return datetime(*components)
@_takes_ascii
def parse_isodate(self, datestr):
"""
Parse the date portion of an ISO string.
:param datestr:
The string portion of an ISO string, without a separator
:return:
Returns a :class:`datetime.date` object
"""
components, pos = self._parse_isodate(datestr)
if pos < len(datestr):
raise ValueError('String contains unknown ISO ' +
'components: {!r}'.format(datestr.decode('ascii')))
return date(*components)
@_takes_ascii
def parse_isotime(self, timestr):
"""
Parse the time portion of an ISO string.
:param timestr:
The time portion of an ISO string, without a separator
:return:
Returns a :class:`datetime.time` object
"""
components = self._parse_isotime(timestr)
if components[0] == 24:
components[0] = 0
return time(*components)
@_takes_ascii
def parse_tzstr(self, tzstr, zero_as_utc=True):
"""
Parse a valid ISO time zone string.
See :func:`isoparser.isoparse` for details on supported formats.
:param tzstr:
A string representing an ISO time zone offset
:param zero_as_utc:
Whether to return :class:`dateutil.tz.tzutc` for zero-offset zones
:return:
Returns :class:`dateutil.tz.tzoffset` for offsets and
:class:`dateutil.tz.tzutc` for ``Z`` and (if ``zero_as_utc`` is
specified) offsets equivalent to UTC.
"""
return self._parse_tzstr(tzstr, zero_as_utc=zero_as_utc)
# Constants
_DATE_SEP = b'-'
_TIME_SEP = b':'
_FRACTION_REGEX = re.compile(b'[\\.,]([0-9]+)')
def _parse_isodate(self, dt_str):
try:
return self._parse_isodate_common(dt_str)
except ValueError:
return self._parse_isodate_uncommon(dt_str)
def _parse_isodate_common(self, dt_str):
len_str = len(dt_str)
components = [1, 1, 1]
if len_str < 4:
raise ValueError('ISO string too short')
# Year
components[0] = int(dt_str[0:4])
pos = 4
if pos >= len_str:
return components, pos
has_sep = dt_str[pos:pos + 1] == self._DATE_SEP
if has_sep:
pos += 1
# Month
if len_str - pos < 2:
raise ValueError('Invalid common month')
components[1] = int(dt_str[pos:pos + 2])
pos += 2
if pos >= len_str:
if has_sep:
return components, pos
else:
raise ValueError('Invalid ISO format')
if has_sep:
if dt_str[pos:pos + 1] != self._DATE_SEP:
raise ValueError('Invalid separator in ISO string')
pos += 1
# Day
if len_str - pos < 2:
raise ValueError('Invalid common day')
components[2] = int(dt_str[pos:pos + 2])
return components, pos + 2
def _parse_isodate_uncommon(self, dt_str):
if len(dt_str) < 4:
raise ValueError('ISO string too short')
# All ISO formats start with the year
year = int(dt_str[0:4])
has_sep = dt_str[4:5] == self._DATE_SEP
pos = 4 + has_sep # Skip '-' if it's there
if dt_str[pos:pos + 1] == b'W':
# YYYY-?Www-?D?
pos += 1
weekno = int(dt_str[pos:pos + 2])
pos += 2
dayno = 1
if len(dt_str) > pos:
if (dt_str[pos:pos + 1] == self._DATE_SEP) != has_sep:
raise ValueError('Inconsistent use of dash separator')
pos += has_sep
dayno = int(dt_str[pos:pos + 1])
pos += 1
base_date = self._calculate_weekdate(year, weekno, dayno)
else:
# YYYYDDD or YYYY-DDD
if len(dt_str) - pos < 3:
raise ValueError('Invalid ordinal day')
ordinal_day = int(dt_str[pos:pos + 3])
pos += 3
if ordinal_day < 1 or ordinal_day > (365 + calendar.isleap(year)):
raise ValueError('Invalid ordinal day' +
' {} for year {}'.format(ordinal_day, year))
base_date = date(year, 1, 1) + timedelta(days=ordinal_day - 1)
components = [base_date.year, base_date.month, base_date.day]
return components, pos
def _calculate_weekdate(self, year, week, day):
"""
Calculate the day of corresponding to the ISO year-week-day calendar.
This function is effectively the inverse of
:func:`datetime.date.isocalendar`.
:param year:
The year in the ISO calendar
:param week:
The week in the ISO calendar - range is [1, 53]
:param day:
The day in the ISO calendar - range is [1 (MON), 7 (SUN)]
:return:
Returns a :class:`datetime.date`
"""
if not 0 < week < 54:
raise ValueError('Invalid week: {}'.format(week))
if not 0 < day < 8: # Range is 1-7
raise ValueError('Invalid weekday: {}'.format(day))
# Get week 1 for the specific year:
jan_4 = date(year, 1, 4) # Week 1 always has January 4th in it
week_1 = jan_4 - timedelta(days=jan_4.isocalendar()[2] - 1)
# Now add the specific number of weeks and days to get what we want
week_offset = (week - 1) * 7 + (day - 1)
return week_1 + timedelta(days=week_offset)
def _parse_isotime(self, timestr):
len_str = len(timestr)
components = [0, 0, 0, 0, None]
pos = 0
comp = -1
if len_str < 2:
raise ValueError('ISO time too short')
has_sep = False
while pos < len_str and comp < 5:
comp += 1
if timestr[pos:pos + 1] in b'-+Zz':
# Detect time zone boundary
components[-1] = self._parse_tzstr(timestr[pos:])
pos = len_str
break
if comp == 1 and timestr[pos:pos+1] == self._TIME_SEP:
has_sep = True
pos += 1
elif comp == 2 and has_sep:
if timestr[pos:pos+1] != self._TIME_SEP:
raise ValueError('Inconsistent use of colon separator')
pos += 1
if comp < 3:
# Hour, minute, second
components[comp] = int(timestr[pos:pos + 2])
pos += 2
if comp == 3:
# Fraction of a second
frac = self._FRACTION_REGEX.match(timestr[pos:])
if not frac:
continue
us_str = frac.group(1)[:6] # Truncate to microseconds
components[comp] = int(us_str) * 10**(6 - len(us_str))
pos += len(frac.group())
if pos < len_str:
raise ValueError('Unused components in ISO string')
if components[0] == 24:
# Standard supports 00:00 and 24:00 as representations of midnight
if any(component != 0 for component in components[1:4]):
raise ValueError('Hour may only be 24 at 24:00:00.000')
return components
def _parse_tzstr(self, tzstr, zero_as_utc=True):
if tzstr == b'Z' or tzstr == b'z':
return tz.UTC
if len(tzstr) not in {3, 5, 6}:
raise ValueError('Time zone offset must be 1, 3, 5 or 6 characters')
if tzstr[0:1] == b'-':
mult = -1
elif tzstr[0:1] == b'+':
mult = 1
else:
raise ValueError('Time zone offset requires sign')
hours = int(tzstr[1:3])
if len(tzstr) == 3:
minutes = 0
else:
minutes = int(tzstr[(4 if tzstr[3:4] == self._TIME_SEP else 3):])
if zero_as_utc and hours == 0 and minutes == 0:
return tz.UTC
else:
if minutes > 59:
raise ValueError('Invalid minutes in time zone offset')
if hours > 23:
raise ValueError('Invalid hours in time zone offset')
return tz.tzoffset(None, mult * (hours * 60 + minutes) * 60)
DEFAULT_ISOPARSER = isoparser()
isoparse = DEFAULT_ISOPARSER.isoparse

View File

@@ -0,0 +1,599 @@
# -*- coding: utf-8 -*-
import datetime
import calendar
import operator
from math import copysign
from six import integer_types
from warnings import warn
from ._common import weekday
MO, TU, WE, TH, FR, SA, SU = weekdays = tuple(weekday(x) for x in range(7))
__all__ = ["relativedelta", "MO", "TU", "WE", "TH", "FR", "SA", "SU"]
class relativedelta(object):
"""
The relativedelta type is designed to be applied to an existing datetime and
can replace specific components of that datetime, or represents an interval
of time.
It is based on the specification of the excellent work done by M.-A. Lemburg
in his
`mx.DateTime <https://www.egenix.com/products/python/mxBase/mxDateTime/>`_ extension.
However, notice that this type does *NOT* implement the same algorithm as
his work. Do *NOT* expect it to behave like mx.DateTime's counterpart.
There are two different ways to build a relativedelta instance. The
first one is passing it two date/datetime classes::
relativedelta(datetime1, datetime2)
The second one is passing it any number of the following keyword arguments::
relativedelta(arg1=x,arg2=y,arg3=z...)
year, month, day, hour, minute, second, microsecond:
Absolute information (argument is singular); adding or subtracting a
relativedelta with absolute information does not perform an arithmetic
operation, but rather REPLACES the corresponding value in the
original datetime with the value(s) in relativedelta.
years, months, weeks, days, hours, minutes, seconds, microseconds:
Relative information, may be negative (argument is plural); adding
or subtracting a relativedelta with relative information performs
the corresponding arithmetic operation on the original datetime value
with the information in the relativedelta.
weekday:
One of the weekday instances (MO, TU, etc) available in the
relativedelta module. These instances may receive a parameter N,
specifying the Nth weekday, which could be positive or negative
(like MO(+1) or MO(-2)). Not specifying it is the same as specifying
+1. You can also use an integer, where 0=MO. This argument is always
relative e.g. if the calculated date is already Monday, using MO(1)
or MO(-1) won't change the day. To effectively make it absolute, use
it in combination with the day argument (e.g. day=1, MO(1) for first
Monday of the month).
leapdays:
Will add given days to the date found, if year is a leap
year, and the date found is post 28 of february.
yearday, nlyearday:
Set the yearday or the non-leap year day (jump leap days).
These are converted to day/month/leapdays information.
There are relative and absolute forms of the keyword
arguments. The plural is relative, and the singular is
absolute. For each argument in the order below, the absolute form
is applied first (by setting each attribute to that value) and
then the relative form (by adding the value to the attribute).
The order of attributes considered when this relativedelta is
added to a datetime is:
1. Year
2. Month
3. Day
4. Hours
5. Minutes
6. Seconds
7. Microseconds
Finally, weekday is applied, using the rule described above.
For example
>>> from datetime import datetime
>>> from dateutil.relativedelta import relativedelta, MO
>>> dt = datetime(2018, 4, 9, 13, 37, 0)
>>> delta = relativedelta(hours=25, day=1, weekday=MO(1))
>>> dt + delta
datetime.datetime(2018, 4, 2, 14, 37)
First, the day is set to 1 (the first of the month), then 25 hours
are added, to get to the 2nd day and 14th hour, finally the
weekday is applied, but since the 2nd is already a Monday there is
no effect.
"""
def __init__(self, dt1=None, dt2=None,
years=0, months=0, days=0, leapdays=0, weeks=0,
hours=0, minutes=0, seconds=0, microseconds=0,
year=None, month=None, day=None, weekday=None,
yearday=None, nlyearday=None,
hour=None, minute=None, second=None, microsecond=None):
if dt1 and dt2:
# datetime is a subclass of date. So both must be date
if not (isinstance(dt1, datetime.date) and
isinstance(dt2, datetime.date)):
raise TypeError("relativedelta only diffs datetime/date")
# We allow two dates, or two datetimes, so we coerce them to be
# of the same type
if (isinstance(dt1, datetime.datetime) !=
isinstance(dt2, datetime.datetime)):
if not isinstance(dt1, datetime.datetime):
dt1 = datetime.datetime.fromordinal(dt1.toordinal())
elif not isinstance(dt2, datetime.datetime):
dt2 = datetime.datetime.fromordinal(dt2.toordinal())
self.years = 0
self.months = 0
self.days = 0
self.leapdays = 0
self.hours = 0
self.minutes = 0
self.seconds = 0
self.microseconds = 0
self.year = None
self.month = None
self.day = None
self.weekday = None
self.hour = None
self.minute = None
self.second = None
self.microsecond = None
self._has_time = 0
# Get year / month delta between the two
months = (dt1.year - dt2.year) * 12 + (dt1.month - dt2.month)
self._set_months(months)
# Remove the year/month delta so the timedelta is just well-defined
# time units (seconds, days and microseconds)
dtm = self.__radd__(dt2)
# If we've overshot our target, make an adjustment
if dt1 < dt2:
compare = operator.gt
increment = 1
else:
compare = operator.lt
increment = -1
while compare(dt1, dtm):
months += increment
self._set_months(months)
dtm = self.__radd__(dt2)
# Get the timedelta between the "months-adjusted" date and dt1
delta = dt1 - dtm
self.seconds = delta.seconds + delta.days * 86400
self.microseconds = delta.microseconds
else:
# Check for non-integer values in integer-only quantities
if any(x is not None and x != int(x) for x in (years, months)):
raise ValueError("Non-integer years and months are "
"ambiguous and not currently supported.")
# Relative information
self.years = int(years)
self.months = int(months)
self.days = days + weeks * 7
self.leapdays = leapdays
self.hours = hours
self.minutes = minutes
self.seconds = seconds
self.microseconds = microseconds
# Absolute information
self.year = year
self.month = month
self.day = day
self.hour = hour
self.minute = minute
self.second = second
self.microsecond = microsecond
if any(x is not None and int(x) != x
for x in (year, month, day, hour,
minute, second, microsecond)):
# For now we'll deprecate floats - later it'll be an error.
warn("Non-integer value passed as absolute information. " +
"This is not a well-defined condition and will raise " +
"errors in future versions.", DeprecationWarning)
if isinstance(weekday, integer_types):
self.weekday = weekdays[weekday]
else:
self.weekday = weekday
yday = 0
if nlyearday:
yday = nlyearday
elif yearday:
yday = yearday
if yearday > 59:
self.leapdays = -1
if yday:
ydayidx = [31, 59, 90, 120, 151, 181, 212,
243, 273, 304, 334, 366]
for idx, ydays in enumerate(ydayidx):
if yday <= ydays:
self.month = idx+1
if idx == 0:
self.day = yday
else:
self.day = yday-ydayidx[idx-1]
break
else:
raise ValueError("invalid year day (%d)" % yday)
self._fix()
def _fix(self):
if abs(self.microseconds) > 999999:
s = _sign(self.microseconds)
div, mod = divmod(self.microseconds * s, 1000000)
self.microseconds = mod * s
self.seconds += div * s
if abs(self.seconds) > 59:
s = _sign(self.seconds)
div, mod = divmod(self.seconds * s, 60)
self.seconds = mod * s
self.minutes += div * s
if abs(self.minutes) > 59:
s = _sign(self.minutes)
div, mod = divmod(self.minutes * s, 60)
self.minutes = mod * s
self.hours += div * s
if abs(self.hours) > 23:
s = _sign(self.hours)
div, mod = divmod(self.hours * s, 24)
self.hours = mod * s
self.days += div * s
if abs(self.months) > 11:
s = _sign(self.months)
div, mod = divmod(self.months * s, 12)
self.months = mod * s
self.years += div * s
if (self.hours or self.minutes or self.seconds or self.microseconds
or self.hour is not None or self.minute is not None or
self.second is not None or self.microsecond is not None):
self._has_time = 1
else:
self._has_time = 0
@property
def weeks(self):
return int(self.days / 7.0)
@weeks.setter
def weeks(self, value):
self.days = self.days - (self.weeks * 7) + value * 7
def _set_months(self, months):
self.months = months
if abs(self.months) > 11:
s = _sign(self.months)
div, mod = divmod(self.months * s, 12)
self.months = mod * s
self.years = div * s
else:
self.years = 0
def normalized(self):
"""
Return a version of this object represented entirely using integer
values for the relative attributes.
>>> relativedelta(days=1.5, hours=2).normalized()
relativedelta(days=+1, hours=+14)
:return:
Returns a :class:`dateutil.relativedelta.relativedelta` object.
"""
# Cascade remainders down (rounding each to roughly nearest microsecond)
days = int(self.days)
hours_f = round(self.hours + 24 * (self.days - days), 11)
hours = int(hours_f)
minutes_f = round(self.minutes + 60 * (hours_f - hours), 10)
minutes = int(minutes_f)
seconds_f = round(self.seconds + 60 * (minutes_f - minutes), 8)
seconds = int(seconds_f)
microseconds = round(self.microseconds + 1e6 * (seconds_f - seconds))
# Constructor carries overflow back up with call to _fix()
return self.__class__(years=self.years, months=self.months,
days=days, hours=hours, minutes=minutes,
seconds=seconds, microseconds=microseconds,
leapdays=self.leapdays, year=self.year,
month=self.month, day=self.day,
weekday=self.weekday, hour=self.hour,
minute=self.minute, second=self.second,
microsecond=self.microsecond)
def __add__(self, other):
if isinstance(other, relativedelta):
return self.__class__(years=other.years + self.years,
months=other.months + self.months,
days=other.days + self.days,
hours=other.hours + self.hours,
minutes=other.minutes + self.minutes,
seconds=other.seconds + self.seconds,
microseconds=(other.microseconds +
self.microseconds),
leapdays=other.leapdays or self.leapdays,
year=(other.year if other.year is not None
else self.year),
month=(other.month if other.month is not None
else self.month),
day=(other.day if other.day is not None
else self.day),
weekday=(other.weekday if other.weekday is not None
else self.weekday),
hour=(other.hour if other.hour is not None
else self.hour),
minute=(other.minute if other.minute is not None
else self.minute),
second=(other.second if other.second is not None
else self.second),
microsecond=(other.microsecond if other.microsecond
is not None else
self.microsecond))
if isinstance(other, datetime.timedelta):
return self.__class__(years=self.years,
months=self.months,
days=self.days + other.days,
hours=self.hours,
minutes=self.minutes,
seconds=self.seconds + other.seconds,
microseconds=self.microseconds + other.microseconds,
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
if not isinstance(other, datetime.date):
return NotImplemented
elif self._has_time and not isinstance(other, datetime.datetime):
other = datetime.datetime.fromordinal(other.toordinal())
year = (self.year or other.year)+self.years
month = self.month or other.month
if self.months:
assert 1 <= abs(self.months) <= 12
month += self.months
if month > 12:
year += 1
month -= 12
elif month < 1:
year -= 1
month += 12
day = min(calendar.monthrange(year, month)[1],
self.day or other.day)
repl = {"year": year, "month": month, "day": day}
for attr in ["hour", "minute", "second", "microsecond"]:
value = getattr(self, attr)
if value is not None:
repl[attr] = value
days = self.days
if self.leapdays and month > 2 and calendar.isleap(year):
days += self.leapdays
ret = (other.replace(**repl)
+ datetime.timedelta(days=days,
hours=self.hours,
minutes=self.minutes,
seconds=self.seconds,
microseconds=self.microseconds))
if self.weekday:
weekday, nth = self.weekday.weekday, self.weekday.n or 1
jumpdays = (abs(nth) - 1) * 7
if nth > 0:
jumpdays += (7 - ret.weekday() + weekday) % 7
else:
jumpdays += (ret.weekday() - weekday) % 7
jumpdays *= -1
ret += datetime.timedelta(days=jumpdays)
return ret
def __radd__(self, other):
return self.__add__(other)
def __rsub__(self, other):
return self.__neg__().__radd__(other)
def __sub__(self, other):
if not isinstance(other, relativedelta):
return NotImplemented # In case the other object defines __rsub__
return self.__class__(years=self.years - other.years,
months=self.months - other.months,
days=self.days - other.days,
hours=self.hours - other.hours,
minutes=self.minutes - other.minutes,
seconds=self.seconds - other.seconds,
microseconds=self.microseconds - other.microseconds,
leapdays=self.leapdays or other.leapdays,
year=(self.year if self.year is not None
else other.year),
month=(self.month if self.month is not None else
other.month),
day=(self.day if self.day is not None else
other.day),
weekday=(self.weekday if self.weekday is not None else
other.weekday),
hour=(self.hour if self.hour is not None else
other.hour),
minute=(self.minute if self.minute is not None else
other.minute),
second=(self.second if self.second is not None else
other.second),
microsecond=(self.microsecond if self.microsecond
is not None else
other.microsecond))
def __abs__(self):
return self.__class__(years=abs(self.years),
months=abs(self.months),
days=abs(self.days),
hours=abs(self.hours),
minutes=abs(self.minutes),
seconds=abs(self.seconds),
microseconds=abs(self.microseconds),
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
def __neg__(self):
return self.__class__(years=-self.years,
months=-self.months,
days=-self.days,
hours=-self.hours,
minutes=-self.minutes,
seconds=-self.seconds,
microseconds=-self.microseconds,
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
def __bool__(self):
return not (not self.years and
not self.months and
not self.days and
not self.hours and
not self.minutes and
not self.seconds and
not self.microseconds and
not self.leapdays and
self.year is None and
self.month is None and
self.day is None and
self.weekday is None and
self.hour is None and
self.minute is None and
self.second is None and
self.microsecond is None)
# Compatibility with Python 2.x
__nonzero__ = __bool__
def __mul__(self, other):
try:
f = float(other)
except TypeError:
return NotImplemented
return self.__class__(years=int(self.years * f),
months=int(self.months * f),
days=int(self.days * f),
hours=int(self.hours * f),
minutes=int(self.minutes * f),
seconds=int(self.seconds * f),
microseconds=int(self.microseconds * f),
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
__rmul__ = __mul__
def __eq__(self, other):
if not isinstance(other, relativedelta):
return NotImplemented
if self.weekday or other.weekday:
if not self.weekday or not other.weekday:
return False
if self.weekday.weekday != other.weekday.weekday:
return False
n1, n2 = self.weekday.n, other.weekday.n
if n1 != n2 and not ((not n1 or n1 == 1) and (not n2 or n2 == 1)):
return False
return (self.years == other.years and
self.months == other.months and
self.days == other.days and
self.hours == other.hours and
self.minutes == other.minutes and
self.seconds == other.seconds and
self.microseconds == other.microseconds and
self.leapdays == other.leapdays and
self.year == other.year and
self.month == other.month and
self.day == other.day and
self.hour == other.hour and
self.minute == other.minute and
self.second == other.second and
self.microsecond == other.microsecond)
def __hash__(self):
return hash((
self.weekday,
self.years,
self.months,
self.days,
self.hours,
self.minutes,
self.seconds,
self.microseconds,
self.leapdays,
self.year,
self.month,
self.day,
self.hour,
self.minute,
self.second,
self.microsecond,
))
def __ne__(self, other):
return not self.__eq__(other)
def __div__(self, other):
try:
reciprocal = 1 / float(other)
except TypeError:
return NotImplemented
return self.__mul__(reciprocal)
__truediv__ = __div__
def __repr__(self):
l = []
for attr in ["years", "months", "days", "leapdays",
"hours", "minutes", "seconds", "microseconds"]:
value = getattr(self, attr)
if value:
l.append("{attr}={value:+g}".format(attr=attr, value=value))
for attr in ["year", "month", "day", "weekday",
"hour", "minute", "second", "microsecond"]:
value = getattr(self, attr)
if value is not None:
l.append("{attr}={value}".format(attr=attr, value=repr(value)))
return "{classname}({attrs})".format(classname=self.__class__.__name__,
attrs=", ".join(l))
def _sign(x):
return int(copysign(1, x))
# vim:ts=4:sw=4:et

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from .tz import *
from .tz import __doc__
__all__ = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
"tzstr", "tzical", "tzwin", "tzwinlocal", "gettz",
"enfold", "datetime_ambiguous", "datetime_exists",
"resolve_imaginary", "UTC", "DeprecatedTzFormatWarning"]
class DeprecatedTzFormatWarning(Warning):
"""Warning raised when time zones are parsed from deprecated formats."""

View File

@@ -0,0 +1,419 @@
from six import PY2
from functools import wraps
from datetime import datetime, timedelta, tzinfo
ZERO = timedelta(0)
__all__ = ['tzname_in_python2', 'enfold']
def tzname_in_python2(namefunc):
"""Change unicode output into bytestrings in Python 2
tzname() API changed in Python 3. It used to return bytes, but was changed
to unicode strings
"""
if PY2:
@wraps(namefunc)
def adjust_encoding(*args, **kwargs):
name = namefunc(*args, **kwargs)
if name is not None:
name = name.encode()
return name
return adjust_encoding
else:
return namefunc
# The following is adapted from Alexander Belopolsky's tz library
# https://github.com/abalkin/tz
if hasattr(datetime, 'fold'):
# This is the pre-python 3.6 fold situation
def enfold(dt, fold=1):
"""
Provides a unified interface for assigning the ``fold`` attribute to
datetimes both before and after the implementation of PEP-495.
:param fold:
The value for the ``fold`` attribute in the returned datetime. This
should be either 0 or 1.
:return:
Returns an object for which ``getattr(dt, 'fold', 0)`` returns
``fold`` for all versions of Python. In versions prior to
Python 3.6, this is a ``_DatetimeWithFold`` object, which is a
subclass of :py:class:`datetime.datetime` with the ``fold``
attribute added, if ``fold`` is 1.
.. versionadded:: 2.6.0
"""
return dt.replace(fold=fold)
else:
class _DatetimeWithFold(datetime):
"""
This is a class designed to provide a PEP 495-compliant interface for
Python versions before 3.6. It is used only for dates in a fold, so
the ``fold`` attribute is fixed at ``1``.
.. versionadded:: 2.6.0
"""
__slots__ = ()
def replace(self, *args, **kwargs):
"""
Return a datetime with the same attributes, except for those
attributes given new values by whichever keyword arguments are
specified. Note that tzinfo=None can be specified to create a naive
datetime from an aware datetime with no conversion of date and time
data.
This is reimplemented in ``_DatetimeWithFold`` because pypy3 will
return a ``datetime.datetime`` even if ``fold`` is unchanged.
"""
argnames = (
'year', 'month', 'day', 'hour', 'minute', 'second',
'microsecond', 'tzinfo'
)
for arg, argname in zip(args, argnames):
if argname in kwargs:
raise TypeError('Duplicate argument: {}'.format(argname))
kwargs[argname] = arg
for argname in argnames:
if argname not in kwargs:
kwargs[argname] = getattr(self, argname)
dt_class = self.__class__ if kwargs.get('fold', 1) else datetime
return dt_class(**kwargs)
@property
def fold(self):
return 1
def enfold(dt, fold=1):
"""
Provides a unified interface for assigning the ``fold`` attribute to
datetimes both before and after the implementation of PEP-495.
:param fold:
The value for the ``fold`` attribute in the returned datetime. This
should be either 0 or 1.
:return:
Returns an object for which ``getattr(dt, 'fold', 0)`` returns
``fold`` for all versions of Python. In versions prior to
Python 3.6, this is a ``_DatetimeWithFold`` object, which is a
subclass of :py:class:`datetime.datetime` with the ``fold``
attribute added, if ``fold`` is 1.
.. versionadded:: 2.6.0
"""
if getattr(dt, 'fold', 0) == fold:
return dt
args = dt.timetuple()[:6]
args += (dt.microsecond, dt.tzinfo)
if fold:
return _DatetimeWithFold(*args)
else:
return datetime(*args)
def _validate_fromutc_inputs(f):
"""
The CPython version of ``fromutc`` checks that the input is a ``datetime``
object and that ``self`` is attached as its ``tzinfo``.
"""
@wraps(f)
def fromutc(self, dt):
if not isinstance(dt, datetime):
raise TypeError("fromutc() requires a datetime argument")
if dt.tzinfo is not self:
raise ValueError("dt.tzinfo is not self")
return f(self, dt)
return fromutc
class _tzinfo(tzinfo):
"""
Base class for all ``dateutil`` ``tzinfo`` objects.
"""
def is_ambiguous(self, dt):
"""
Whether or not the "wall time" of a given datetime is ambiguous in this
zone.
:param dt:
A :py:class:`datetime.datetime`, naive or time zone aware.
:return:
Returns ``True`` if ambiguous, ``False`` otherwise.
.. versionadded:: 2.6.0
"""
dt = dt.replace(tzinfo=self)
wall_0 = enfold(dt, fold=0)
wall_1 = enfold(dt, fold=1)
same_offset = wall_0.utcoffset() == wall_1.utcoffset()
same_dt = wall_0.replace(tzinfo=None) == wall_1.replace(tzinfo=None)
return same_dt and not same_offset
def _fold_status(self, dt_utc, dt_wall):
"""
Determine the fold status of a "wall" datetime, given a representation
of the same datetime as a (naive) UTC datetime. This is calculated based
on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all
datetimes, and that this offset is the actual number of hours separating
``dt_utc`` and ``dt_wall``.
:param dt_utc:
Representation of the datetime as UTC
:param dt_wall:
Representation of the datetime as "wall time". This parameter must
either have a `fold` attribute or have a fold-naive
:class:`datetime.tzinfo` attached, otherwise the calculation may
fail.
"""
if self.is_ambiguous(dt_wall):
delta_wall = dt_wall - dt_utc
_fold = int(delta_wall == (dt_utc.utcoffset() - dt_utc.dst()))
else:
_fold = 0
return _fold
def _fold(self, dt):
return getattr(dt, 'fold', 0)
def _fromutc(self, dt):
"""
Given a timezone-aware datetime in a given timezone, calculates a
timezone-aware datetime in a new timezone.
Since this is the one time that we *know* we have an unambiguous
datetime object, we take this opportunity to determine whether the
datetime is ambiguous and in a "fold" state (e.g. if it's the first
occurrence, chronologically, of the ambiguous datetime).
:param dt:
A timezone-aware :class:`datetime.datetime` object.
"""
# Re-implement the algorithm from Python's datetime.py
dtoff = dt.utcoffset()
if dtoff is None:
raise ValueError("fromutc() requires a non-None utcoffset() "
"result")
# The original datetime.py code assumes that `dst()` defaults to
# zero during ambiguous times. PEP 495 inverts this presumption, so
# for pre-PEP 495 versions of python, we need to tweak the algorithm.
dtdst = dt.dst()
if dtdst is None:
raise ValueError("fromutc() requires a non-None dst() result")
delta = dtoff - dtdst
dt += delta
# Set fold=1 so we can default to being in the fold for
# ambiguous dates.
dtdst = enfold(dt, fold=1).dst()
if dtdst is None:
raise ValueError("fromutc(): dt.dst gave inconsistent "
"results; cannot convert")
return dt + dtdst
@_validate_fromutc_inputs
def fromutc(self, dt):
"""
Given a timezone-aware datetime in a given timezone, calculates a
timezone-aware datetime in a new timezone.
Since this is the one time that we *know* we have an unambiguous
datetime object, we take this opportunity to determine whether the
datetime is ambiguous and in a "fold" state (e.g. if it's the first
occurrence, chronologically, of the ambiguous datetime).
:param dt:
A timezone-aware :class:`datetime.datetime` object.
"""
dt_wall = self._fromutc(dt)
# Calculate the fold status given the two datetimes.
_fold = self._fold_status(dt, dt_wall)
# Set the default fold value for ambiguous dates
return enfold(dt_wall, fold=_fold)
class tzrangebase(_tzinfo):
"""
This is an abstract base class for time zones represented by an annual
transition into and out of DST. Child classes should implement the following
methods:
* ``__init__(self, *args, **kwargs)``
* ``transitions(self, year)`` - this is expected to return a tuple of
datetimes representing the DST on and off transitions in standard
time.
A fully initialized ``tzrangebase`` subclass should also provide the
following attributes:
* ``hasdst``: Boolean whether or not the zone uses DST.
* ``_dst_offset`` / ``_std_offset``: :class:`datetime.timedelta` objects
representing the respective UTC offsets.
* ``_dst_abbr`` / ``_std_abbr``: Strings representing the timezone short
abbreviations in DST and STD, respectively.
* ``_hasdst``: Whether or not the zone has DST.
.. versionadded:: 2.6.0
"""
def __init__(self):
raise NotImplementedError('tzrangebase is an abstract base class')
def utcoffset(self, dt):
isdst = self._isdst(dt)
if isdst is None:
return None
elif isdst:
return self._dst_offset
else:
return self._std_offset
def dst(self, dt):
isdst = self._isdst(dt)
if isdst is None:
return None
elif isdst:
return self._dst_base_offset
else:
return ZERO
@tzname_in_python2
def tzname(self, dt):
if self._isdst(dt):
return self._dst_abbr
else:
return self._std_abbr
def fromutc(self, dt):
""" Given a datetime in UTC, return local time """
if not isinstance(dt, datetime):
raise TypeError("fromutc() requires a datetime argument")
if dt.tzinfo is not self:
raise ValueError("dt.tzinfo is not self")
# Get transitions - if there are none, fixed offset
transitions = self.transitions(dt.year)
if transitions is None:
return dt + self.utcoffset(dt)
# Get the transition times in UTC
dston, dstoff = transitions
dston -= self._std_offset
dstoff -= self._std_offset
utc_transitions = (dston, dstoff)
dt_utc = dt.replace(tzinfo=None)
isdst = self._naive_isdst(dt_utc, utc_transitions)
if isdst:
dt_wall = dt + self._dst_offset
else:
dt_wall = dt + self._std_offset
_fold = int(not isdst and self.is_ambiguous(dt_wall))
return enfold(dt_wall, fold=_fold)
def is_ambiguous(self, dt):
"""
Whether or not the "wall time" of a given datetime is ambiguous in this
zone.
:param dt:
A :py:class:`datetime.datetime`, naive or time zone aware.
:return:
Returns ``True`` if ambiguous, ``False`` otherwise.
.. versionadded:: 2.6.0
"""
if not self.hasdst:
return False
start, end = self.transitions(dt.year)
dt = dt.replace(tzinfo=None)
return (end <= dt < end + self._dst_base_offset)
def _isdst(self, dt):
if not self.hasdst:
return False
elif dt is None:
return None
transitions = self.transitions(dt.year)
if transitions is None:
return False
dt = dt.replace(tzinfo=None)
isdst = self._naive_isdst(dt, transitions)
# Handle ambiguous dates
if not isdst and self.is_ambiguous(dt):
return not self._fold(dt)
else:
return isdst
def _naive_isdst(self, dt, transitions):
dston, dstoff = transitions
dt = dt.replace(tzinfo=None)
if dston < dstoff:
isdst = dston <= dt < dstoff
else:
isdst = not dstoff <= dt < dston
return isdst
@property
def _dst_base_offset(self):
return self._dst_offset - self._std_offset
__hash__ = None
def __ne__(self, other):
return not (self == other)
def __repr__(self):
return "%s(...)" % self.__class__.__name__
__reduce__ = object.__reduce__

View File

@@ -0,0 +1,80 @@
from datetime import timedelta
import weakref
from collections import OrderedDict
from six.moves import _thread
class _TzSingleton(type):
def __init__(cls, *args, **kwargs):
cls.__instance = None
super(_TzSingleton, cls).__init__(*args, **kwargs)
def __call__(cls):
if cls.__instance is None:
cls.__instance = super(_TzSingleton, cls).__call__()
return cls.__instance
class _TzFactory(type):
def instance(cls, *args, **kwargs):
"""Alternate constructor that returns a fresh instance"""
return type.__call__(cls, *args, **kwargs)
class _TzOffsetFactory(_TzFactory):
def __init__(cls, *args, **kwargs):
cls.__instances = weakref.WeakValueDictionary()
cls.__strong_cache = OrderedDict()
cls.__strong_cache_size = 8
cls._cache_lock = _thread.allocate_lock()
def __call__(cls, name, offset):
if isinstance(offset, timedelta):
key = (name, offset.total_seconds())
else:
key = (name, offset)
instance = cls.__instances.get(key, None)
if instance is None:
instance = cls.__instances.setdefault(key,
cls.instance(name, offset))
# This lock may not be necessary in Python 3. See GH issue #901
with cls._cache_lock:
cls.__strong_cache[key] = cls.__strong_cache.pop(key, instance)
# Remove an item if the strong cache is overpopulated
if len(cls.__strong_cache) > cls.__strong_cache_size:
cls.__strong_cache.popitem(last=False)
return instance
class _TzStrFactory(_TzFactory):
def __init__(cls, *args, **kwargs):
cls.__instances = weakref.WeakValueDictionary()
cls.__strong_cache = OrderedDict()
cls.__strong_cache_size = 8
cls.__cache_lock = _thread.allocate_lock()
def __call__(cls, s, posix_offset=False):
key = (s, posix_offset)
instance = cls.__instances.get(key, None)
if instance is None:
instance = cls.__instances.setdefault(key,
cls.instance(s, posix_offset))
# This lock may not be necessary in Python 3. See GH issue #901
with cls.__cache_lock:
cls.__strong_cache[key] = cls.__strong_cache.pop(key, instance)
# Remove an item if the strong cache is overpopulated
if len(cls.__strong_cache) > cls.__strong_cache_size:
cls.__strong_cache.popitem(last=False)
return instance

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,370 @@
# -*- coding: utf-8 -*-
"""
This module provides an interface to the native time zone data on Windows,
including :py:class:`datetime.tzinfo` implementations.
Attempting to import this module on a non-Windows platform will raise an
:py:obj:`ImportError`.
"""
# This code was originally contributed by Jeffrey Harris.
import datetime
import struct
from six.moves import winreg
from six import text_type
try:
import ctypes
from ctypes import wintypes
except ValueError:
# ValueError is raised on non-Windows systems for some horrible reason.
raise ImportError("Running tzwin on non-Windows system")
from ._common import tzrangebase
__all__ = ["tzwin", "tzwinlocal", "tzres"]
ONEWEEK = datetime.timedelta(7)
TZKEYNAMENT = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones"
TZKEYNAME9X = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones"
TZLOCALKEYNAME = r"SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
def _settzkeyname():
handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
try:
winreg.OpenKey(handle, TZKEYNAMENT).Close()
TZKEYNAME = TZKEYNAMENT
except WindowsError:
TZKEYNAME = TZKEYNAME9X
handle.Close()
return TZKEYNAME
TZKEYNAME = _settzkeyname()
class tzres(object):
"""
Class for accessing ``tzres.dll``, which contains timezone name related
resources.
.. versionadded:: 2.5.0
"""
p_wchar = ctypes.POINTER(wintypes.WCHAR) # Pointer to a wide char
def __init__(self, tzres_loc='tzres.dll'):
# Load the user32 DLL so we can load strings from tzres
user32 = ctypes.WinDLL('user32')
# Specify the LoadStringW function
user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
wintypes.UINT,
wintypes.LPWSTR,
ctypes.c_int)
self.LoadStringW = user32.LoadStringW
self._tzres = ctypes.WinDLL(tzres_loc)
self.tzres_loc = tzres_loc
def load_name(self, offset):
"""
Load a timezone name from a DLL offset (integer).
>>> from dateutil.tzwin import tzres
>>> tzr = tzres()
>>> print(tzr.load_name(112))
'Eastern Standard Time'
:param offset:
A positive integer value referring to a string from the tzres dll.
.. note::
Offsets found in the registry are generally of the form
``@tzres.dll,-114``. The offset in this case is 114, not -114.
"""
resource = self.p_wchar()
lpBuffer = ctypes.cast(ctypes.byref(resource), wintypes.LPWSTR)
nchar = self.LoadStringW(self._tzres._handle, offset, lpBuffer, 0)
return resource[:nchar]
def name_from_string(self, tzname_str):
"""
Parse strings as returned from the Windows registry into the time zone
name as defined in the registry.
>>> from dateutil.tzwin import tzres
>>> tzr = tzres()
>>> print(tzr.name_from_string('@tzres.dll,-251'))
'Dateline Daylight Time'
>>> print(tzr.name_from_string('Eastern Standard Time'))
'Eastern Standard Time'
:param tzname_str:
A timezone name string as returned from a Windows registry key.
:return:
Returns the localized timezone string from tzres.dll if the string
is of the form `@tzres.dll,-offset`, else returns the input string.
"""
if not tzname_str.startswith('@'):
return tzname_str
name_splt = tzname_str.split(',-')
try:
offset = int(name_splt[1])
except:
raise ValueError("Malformed timezone string.")
return self.load_name(offset)
class tzwinbase(tzrangebase):
"""tzinfo class based on win32's timezones available in the registry."""
def __init__(self):
raise NotImplementedError('tzwinbase is an abstract base class')
def __eq__(self, other):
# Compare on all relevant dimensions, including name.
if not isinstance(other, tzwinbase):
return NotImplemented
return (self._std_offset == other._std_offset and
self._dst_offset == other._dst_offset and
self._stddayofweek == other._stddayofweek and
self._dstdayofweek == other._dstdayofweek and
self._stdweeknumber == other._stdweeknumber and
self._dstweeknumber == other._dstweeknumber and
self._stdhour == other._stdhour and
self._dsthour == other._dsthour and
self._stdminute == other._stdminute and
self._dstminute == other._dstminute and
self._std_abbr == other._std_abbr and
self._dst_abbr == other._dst_abbr)
@staticmethod
def list():
"""Return a list of all time zones known to the system."""
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
with winreg.OpenKey(handle, TZKEYNAME) as tzkey:
result = [winreg.EnumKey(tzkey, i)
for i in range(winreg.QueryInfoKey(tzkey)[0])]
return result
def display(self):
"""
Return the display name of the time zone.
"""
return self._display
def transitions(self, year):
"""
For a given year, get the DST on and off transition times, expressed
always on the standard time side. For zones with no transitions, this
function returns ``None``.
:param year:
The year whose transitions you would like to query.
:return:
Returns a :class:`tuple` of :class:`datetime.datetime` objects,
``(dston, dstoff)`` for zones with an annual DST transition, or
``None`` for fixed offset zones.
"""
if not self.hasdst:
return None
dston = picknthweekday(year, self._dstmonth, self._dstdayofweek,
self._dsthour, self._dstminute,
self._dstweeknumber)
dstoff = picknthweekday(year, self._stdmonth, self._stddayofweek,
self._stdhour, self._stdminute,
self._stdweeknumber)
# Ambiguous dates default to the STD side
dstoff -= self._dst_base_offset
return dston, dstoff
def _get_hasdst(self):
return self._dstmonth != 0
@property
def _dst_base_offset(self):
return self._dst_base_offset_
class tzwin(tzwinbase):
"""
Time zone object created from the zone info in the Windows registry
These are similar to :py:class:`dateutil.tz.tzrange` objects in that
the time zone data is provided in the format of a single offset rule
for either 0 or 2 time zone transitions per year.
:param: name
The name of a Windows time zone key, e.g. "Eastern Standard Time".
The full list of keys can be retrieved with :func:`tzwin.list`.
"""
def __init__(self, name):
self._name = name
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
tzkeyname = text_type("{kn}\\{name}").format(kn=TZKEYNAME, name=name)
with winreg.OpenKey(handle, tzkeyname) as tzkey:
keydict = valuestodict(tzkey)
self._std_abbr = keydict["Std"]
self._dst_abbr = keydict["Dlt"]
self._display = keydict["Display"]
# See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
tup = struct.unpack("=3l16h", keydict["TZI"])
stdoffset = -tup[0]-tup[1] # Bias + StandardBias * -1
dstoffset = stdoffset-tup[2] # + DaylightBias * -1
self._std_offset = datetime.timedelta(minutes=stdoffset)
self._dst_offset = datetime.timedelta(minutes=dstoffset)
# for the meaning see the win32 TIME_ZONE_INFORMATION structure docs
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx
(self._stdmonth,
self._stddayofweek, # Sunday = 0
self._stdweeknumber, # Last = 5
self._stdhour,
self._stdminute) = tup[4:9]
(self._dstmonth,
self._dstdayofweek, # Sunday = 0
self._dstweeknumber, # Last = 5
self._dsthour,
self._dstminute) = tup[12:17]
self._dst_base_offset_ = self._dst_offset - self._std_offset
self.hasdst = self._get_hasdst()
def __repr__(self):
return "tzwin(%s)" % repr(self._name)
def __reduce__(self):
return (self.__class__, (self._name,))
class tzwinlocal(tzwinbase):
"""
Class representing the local time zone information in the Windows registry
While :class:`dateutil.tz.tzlocal` makes system calls (via the :mod:`time`
module) to retrieve time zone information, ``tzwinlocal`` retrieves the
rules directly from the Windows registry and creates an object like
:class:`dateutil.tz.tzwin`.
Because Windows does not have an equivalent of :func:`time.tzset`, on
Windows, :class:`dateutil.tz.tzlocal` instances will always reflect the
time zone settings *at the time that the process was started*, meaning
changes to the machine's time zone settings during the run of a program
on Windows will **not** be reflected by :class:`dateutil.tz.tzlocal`.
Because ``tzwinlocal`` reads the registry directly, it is unaffected by
this issue.
"""
def __init__(self):
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
with winreg.OpenKey(handle, TZLOCALKEYNAME) as tzlocalkey:
keydict = valuestodict(tzlocalkey)
self._std_abbr = keydict["StandardName"]
self._dst_abbr = keydict["DaylightName"]
try:
tzkeyname = text_type('{kn}\\{sn}').format(kn=TZKEYNAME,
sn=self._std_abbr)
with winreg.OpenKey(handle, tzkeyname) as tzkey:
_keydict = valuestodict(tzkey)
self._display = _keydict["Display"]
except OSError:
self._display = None
stdoffset = -keydict["Bias"]-keydict["StandardBias"]
dstoffset = stdoffset-keydict["DaylightBias"]
self._std_offset = datetime.timedelta(minutes=stdoffset)
self._dst_offset = datetime.timedelta(minutes=dstoffset)
# For reasons unclear, in this particular key, the day of week has been
# moved to the END of the SYSTEMTIME structure.
tup = struct.unpack("=8h", keydict["StandardStart"])
(self._stdmonth,
self._stdweeknumber, # Last = 5
self._stdhour,
self._stdminute) = tup[1:5]
self._stddayofweek = tup[7]
tup = struct.unpack("=8h", keydict["DaylightStart"])
(self._dstmonth,
self._dstweeknumber, # Last = 5
self._dsthour,
self._dstminute) = tup[1:5]
self._dstdayofweek = tup[7]
self._dst_base_offset_ = self._dst_offset - self._std_offset
self.hasdst = self._get_hasdst()
def __repr__(self):
return "tzwinlocal()"
def __str__(self):
# str will return the standard name, not the daylight name.
return "tzwinlocal(%s)" % repr(self._std_abbr)
def __reduce__(self):
return (self.__class__, ())
def picknthweekday(year, month, dayofweek, hour, minute, whichweek):
""" dayofweek == 0 means Sunday, whichweek 5 means last instance """
first = datetime.datetime(year, month, 1, hour, minute)
# This will work if dayofweek is ISO weekday (1-7) or Microsoft-style (0-6),
# Because 7 % 7 = 0
weekdayone = first.replace(day=((dayofweek - first.isoweekday()) % 7) + 1)
wd = weekdayone + ((whichweek - 1) * ONEWEEK)
if (wd.month != month):
wd -= ONEWEEK
return wd
def valuestodict(key):
"""Convert a registry key's values to a dictionary."""
dout = {}
size = winreg.QueryInfoKey(key)[1]
tz_res = None
for i in range(size):
key_name, value, dtype = winreg.EnumValue(key, i)
if dtype == winreg.REG_DWORD or dtype == winreg.REG_DWORD_LITTLE_ENDIAN:
# If it's a DWORD (32-bit integer), it's stored as unsigned - convert
# that to a proper signed integer
if value & (1 << 31):
value = value - (1 << 32)
elif dtype == winreg.REG_SZ:
# If it's a reference to the tzres DLL, load the actual string
if value.startswith('@tzres'):
tz_res = tz_res or tzres()
value = tz_res.name_from_string(value)
value = value.rstrip('\x00') # Remove trailing nulls
dout[key_name] = value
return dout

View File

@@ -0,0 +1,2 @@
# tzwin has moved to dateutil.tz.win
from .tz.win import *

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
"""
This module offers general convenience and utility functions for dealing with
datetimes.
.. versionadded:: 2.7.0
"""
from __future__ import unicode_literals
from datetime import datetime, time
def today(tzinfo=None):
"""
Returns a :py:class:`datetime` representing the current day at midnight
:param tzinfo:
The time zone to attach (also used to determine the current day).
:return:
A :py:class:`datetime.datetime` object representing the current day
at midnight.
"""
dt = datetime.now(tzinfo)
return datetime.combine(dt.date(), time(0, tzinfo=tzinfo))
def default_tzinfo(dt, tzinfo):
"""
Sets the ``tzinfo`` parameter on naive datetimes only
This is useful for example when you are provided a datetime that may have
either an implicit or explicit time zone, such as when parsing a time zone
string.
.. doctest::
>>> from dateutil.tz import tzoffset
>>> from dateutil.parser import parse
>>> from dateutil.utils import default_tzinfo
>>> dflt_tz = tzoffset("EST", -18000)
>>> print(default_tzinfo(parse('2014-01-01 12:30 UTC'), dflt_tz))
2014-01-01 12:30:00+00:00
>>> print(default_tzinfo(parse('2014-01-01 12:30'), dflt_tz))
2014-01-01 12:30:00-05:00
:param dt:
The datetime on which to replace the time zone
:param tzinfo:
The :py:class:`datetime.tzinfo` subclass instance to assign to
``dt`` if (and only if) it is naive.
:return:
Returns an aware :py:class:`datetime.datetime`.
"""
if dt.tzinfo is not None:
return dt
else:
return dt.replace(tzinfo=tzinfo)
def within_delta(dt1, dt2, delta):
"""
Useful for comparing two datetimes that may have a negligible difference
to be considered equal.
"""
delta = abs(delta)
difference = dt1 - dt2
return -delta <= difference <= delta

View File

@@ -0,0 +1,167 @@
# -*- coding: utf-8 -*-
import warnings
import json
from tarfile import TarFile
from pkgutil import get_data
from io import BytesIO
from dateutil.tz import tzfile as _tzfile
__all__ = ["get_zonefile_instance", "gettz", "gettz_db_metadata"]
ZONEFILENAME = "dateutil-zoneinfo.tar.gz"
METADATA_FN = 'METADATA'
class tzfile(_tzfile):
def __reduce__(self):
return (gettz, (self._filename,))
def getzoneinfofile_stream():
try:
return BytesIO(get_data(__name__, ZONEFILENAME))
except IOError as e: # TODO switch to FileNotFoundError?
warnings.warn("I/O error({0}): {1}".format(e.errno, e.strerror))
return None
class ZoneInfoFile(object):
def __init__(self, zonefile_stream=None):
if zonefile_stream is not None:
with TarFile.open(fileobj=zonefile_stream) as tf:
self.zones = {zf.name: tzfile(tf.extractfile(zf), filename=zf.name)
for zf in tf.getmembers()
if zf.isfile() and zf.name != METADATA_FN}
# deal with links: They'll point to their parent object. Less
# waste of memory
links = {zl.name: self.zones[zl.linkname]
for zl in tf.getmembers() if
zl.islnk() or zl.issym()}
self.zones.update(links)
try:
metadata_json = tf.extractfile(tf.getmember(METADATA_FN))
metadata_str = metadata_json.read().decode('UTF-8')
self.metadata = json.loads(metadata_str)
except KeyError:
# no metadata in tar file
self.metadata = None
else:
self.zones = {}
self.metadata = None
def get(self, name, default=None):
"""
Wrapper for :func:`ZoneInfoFile.zones.get`. This is a convenience method
for retrieving zones from the zone dictionary.
:param name:
The name of the zone to retrieve. (Generally IANA zone names)
:param default:
The value to return in the event of a missing key.
.. versionadded:: 2.6.0
"""
return self.zones.get(name, default)
# The current API has gettz as a module function, although in fact it taps into
# a stateful class. So as a workaround for now, without changing the API, we
# will create a new "global" class instance the first time a user requests a
# timezone. Ugly, but adheres to the api.
#
# TODO: Remove after deprecation period.
_CLASS_ZONE_INSTANCE = []
def get_zonefile_instance(new_instance=False):
"""
This is a convenience function which provides a :class:`ZoneInfoFile`
instance using the data provided by the ``dateutil`` package. By default, it
caches a single instance of the ZoneInfoFile object and returns that.
:param new_instance:
If ``True``, a new instance of :class:`ZoneInfoFile` is instantiated and
used as the cached instance for the next call. Otherwise, new instances
are created only as necessary.
:return:
Returns a :class:`ZoneInfoFile` object.
.. versionadded:: 2.6
"""
if new_instance:
zif = None
else:
zif = getattr(get_zonefile_instance, '_cached_instance', None)
if zif is None:
zif = ZoneInfoFile(getzoneinfofile_stream())
get_zonefile_instance._cached_instance = zif
return zif
def gettz(name):
"""
This retrieves a time zone from the local zoneinfo tarball that is packaged
with dateutil.
:param name:
An IANA-style time zone name, as found in the zoneinfo file.
:return:
Returns a :class:`dateutil.tz.tzfile` time zone object.
.. warning::
It is generally inadvisable to use this function, and it is only
provided for API compatibility with earlier versions. This is *not*
equivalent to ``dateutil.tz.gettz()``, which selects an appropriate
time zone based on the inputs, favoring system zoneinfo. This is ONLY
for accessing the dateutil-specific zoneinfo (which may be out of
date compared to the system zoneinfo).
.. deprecated:: 2.6
If you need to use a specific zoneinfofile over the system zoneinfo,
instantiate a :class:`dateutil.zoneinfo.ZoneInfoFile` object and call
:func:`dateutil.zoneinfo.ZoneInfoFile.get(name)` instead.
Use :func:`get_zonefile_instance` to retrieve an instance of the
dateutil-provided zoneinfo.
"""
warnings.warn("zoneinfo.gettz() will be removed in future versions, "
"to use the dateutil-provided zoneinfo files, instantiate a "
"ZoneInfoFile object and use ZoneInfoFile.zones.get() "
"instead. See the documentation for details.",
DeprecationWarning)
if len(_CLASS_ZONE_INSTANCE) == 0:
_CLASS_ZONE_INSTANCE.append(ZoneInfoFile(getzoneinfofile_stream()))
return _CLASS_ZONE_INSTANCE[0].zones.get(name)
def gettz_db_metadata():
""" Get the zonefile metadata
See `zonefile_metadata`_
:returns:
A dictionary with the database metadata
.. deprecated:: 2.6
See deprecation warning in :func:`zoneinfo.gettz`. To get metadata,
query the attribute ``zoneinfo.ZoneInfoFile.metadata``.
"""
warnings.warn("zoneinfo.gettz_db_metadata() will be removed in future "
"versions, to use the dateutil-provided zoneinfo files, "
"ZoneInfoFile object and query the 'metadata' attribute "
"instead. See the documentation for details.",
DeprecationWarning)
if len(_CLASS_ZONE_INSTANCE) == 0:
_CLASS_ZONE_INSTANCE.append(ZoneInfoFile(getzoneinfofile_stream()))
return _CLASS_ZONE_INSTANCE[0].metadata

View File

@@ -0,0 +1,75 @@
import logging
import os
import tempfile
import shutil
import json
from subprocess import check_call, check_output
from tarfile import TarFile
from dateutil.zoneinfo import METADATA_FN, ZONEFILENAME
def rebuild(filename, tag=None, format="gz", zonegroups=[], metadata=None):
"""Rebuild the internal timezone info in dateutil/zoneinfo/zoneinfo*tar*
filename is the timezone tarball from ``ftp.iana.org/tz``.
"""
tmpdir = tempfile.mkdtemp()
zonedir = os.path.join(tmpdir, "zoneinfo")
moduledir = os.path.dirname(__file__)
try:
with TarFile.open(filename) as tf:
for name in zonegroups:
tf.extract(name, tmpdir)
filepaths = [os.path.join(tmpdir, n) for n in zonegroups]
_run_zic(zonedir, filepaths)
# write metadata file
with open(os.path.join(zonedir, METADATA_FN), 'w') as f:
json.dump(metadata, f, indent=4, sort_keys=True)
target = os.path.join(moduledir, ZONEFILENAME)
with TarFile.open(target, "w:%s" % format) as tf:
for entry in os.listdir(zonedir):
entrypath = os.path.join(zonedir, entry)
tf.add(entrypath, entry)
finally:
shutil.rmtree(tmpdir)
def _run_zic(zonedir, filepaths):
"""Calls the ``zic`` compiler in a compatible way to get a "fat" binary.
Recent versions of ``zic`` default to ``-b slim``, while older versions
don't even have the ``-b`` option (but default to "fat" binaries). The
current version of dateutil does not support Version 2+ TZif files, which
causes problems when used in conjunction with "slim" binaries, so this
function is used to ensure that we always get a "fat" binary.
"""
try:
help_text = check_output(["zic", "--help"])
except OSError as e:
_print_on_nosuchfile(e)
raise
if b"-b " in help_text:
bloat_args = ["-b", "fat"]
else:
bloat_args = []
check_call(["zic"] + bloat_args + ["-d", zonedir] + filepaths)
def _print_on_nosuchfile(e):
"""Print helpful troubleshooting message
e is an exception raised by subprocess.check_call()
"""
if e.errno == 2:
logging.error(
"Could not find zic. Perhaps you need to install "
"libc-bin or some other package that provides it, "
"or it's not in your PATH?")

View File

@@ -0,0 +1,54 @@
Copyright 2017- Paul Ganssle <paul@ganssle.io>
Copyright 2017- dateutil contributors (see AUTHORS file)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
The above license applies to all contributions after 2017-12-01, as well as
all contributions that have been re-licensed (see AUTHORS file for the list of
contributors who have re-licensed their code).
--------------------------------------------------------------------------------
dateutil - Extensions to the standard Python datetime module.
Copyright (c) 2003-2011 - Gustavo Niemeyer <gustavo@niemeyer.net>
Copyright (c) 2012-2014 - Tomi Pieviläinen <tomi.pievilainen@iki.fi>
Copyright (c) 2014-2016 - Yaron de Leeuw <me@jarondl.net>
Copyright (c) 2015- - Paul Ganssle <paul@ganssle.io>
Copyright (c) 2015- - dateutil contributors (see AUTHORS file)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The above BSD License Applies to all code, even that also covered by Apache 2.0.

View File

@@ -0,0 +1,204 @@
Metadata-Version: 2.1
Name: python-dateutil
Version: 2.9.0.post0
Summary: Extensions to the standard Python datetime module
Home-page: https://github.com/dateutil/dateutil
Author: Gustavo Niemeyer
Author-email: gustavo@niemeyer.net
Maintainer: Paul Ganssle
Maintainer-email: dateutil@python.org
License: Dual License
Project-URL: Documentation, https://dateutil.readthedocs.io/en/stable/
Project-URL: Source, https://github.com/dateutil/dateutil
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: !=3.0.*,!=3.1.*,!=3.2.*,>=2.7
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: six >=1.5
dateutil - powerful extensions to datetime
==========================================
|pypi| |support| |licence|
|gitter| |readthedocs|
|travis| |appveyor| |pipelines| |coverage|
.. |pypi| image:: https://img.shields.io/pypi/v/python-dateutil.svg?style=flat-square
:target: https://pypi.org/project/python-dateutil/
:alt: pypi version
.. |support| image:: https://img.shields.io/pypi/pyversions/python-dateutil.svg?style=flat-square
:target: https://pypi.org/project/python-dateutil/
:alt: supported Python version
.. |travis| image:: https://img.shields.io/travis/dateutil/dateutil/master.svg?style=flat-square&label=Travis%20Build
:target: https://travis-ci.org/dateutil/dateutil
:alt: travis build status
.. |appveyor| image:: https://img.shields.io/appveyor/ci/dateutil/dateutil/master.svg?style=flat-square&logo=appveyor
:target: https://ci.appveyor.com/project/dateutil/dateutil
:alt: appveyor build status
.. |pipelines| image:: https://dev.azure.com/pythondateutilazure/dateutil/_apis/build/status/dateutil.dateutil?branchName=master
:target: https://dev.azure.com/pythondateutilazure/dateutil/_build/latest?definitionId=1&branchName=master
:alt: azure pipelines build status
.. |coverage| image:: https://codecov.io/gh/dateutil/dateutil/branch/master/graphs/badge.svg?branch=master
:target: https://codecov.io/gh/dateutil/dateutil?branch=master
:alt: Code coverage
.. |gitter| image:: https://badges.gitter.im/dateutil/dateutil.svg
:alt: Join the chat at https://gitter.im/dateutil/dateutil
:target: https://gitter.im/dateutil/dateutil
.. |licence| image:: https://img.shields.io/pypi/l/python-dateutil.svg?style=flat-square
:target: https://pypi.org/project/python-dateutil/
:alt: licence
.. |readthedocs| image:: https://img.shields.io/readthedocs/dateutil/latest.svg?style=flat-square&label=Read%20the%20Docs
:alt: Read the documentation at https://dateutil.readthedocs.io/en/latest/
:target: https://dateutil.readthedocs.io/en/latest/
The `dateutil` module provides powerful extensions to
the standard `datetime` module, available in Python.
Installation
============
`dateutil` can be installed from PyPI using `pip` (note that the package name is
different from the importable name)::
pip install python-dateutil
Download
========
dateutil is available on PyPI
https://pypi.org/project/python-dateutil/
The documentation is hosted at:
https://dateutil.readthedocs.io/en/stable/
Code
====
The code and issue tracker are hosted on GitHub:
https://github.com/dateutil/dateutil/
Features
========
* Computing of relative deltas (next month, next year,
next Monday, last week of month, etc);
* Computing of relative deltas between two given
date and/or datetime objects;
* Computing of dates based on very flexible recurrence rules,
using a superset of the `iCalendar <https://www.ietf.org/rfc/rfc2445.txt>`_
specification. Parsing of RFC strings is supported as well.
* Generic parsing of dates in almost any string format;
* Timezone (tzinfo) implementations for tzfile(5) format
files (/etc/localtime, /usr/share/zoneinfo, etc), TZ
environment string (in all known formats), iCalendar
format files, given ranges (with help from relative deltas),
local machine timezone, fixed offset timezone, UTC timezone,
and Windows registry-based time zones.
* Internal up-to-date world timezone information based on
Olson's database.
* Computing of Easter Sunday dates for any given year,
using Western, Orthodox or Julian algorithms;
* A comprehensive test suite.
Quick example
=============
Here's a snapshot, just to give an idea about the power of the
package. For more examples, look at the documentation.
Suppose you want to know how much time is left, in
years/months/days/etc, before the next easter happening on a
year with a Friday 13th in August, and you want to get today's
date out of the "date" unix system command. Here is the code:
.. code-block:: python3
>>> from dateutil.relativedelta import *
>>> from dateutil.easter import *
>>> from dateutil.rrule import *
>>> from dateutil.parser import *
>>> from datetime import *
>>> now = parse("Sat Oct 11 17:13:46 UTC 2003")
>>> today = now.date()
>>> year = rrule(YEARLY,dtstart=now,bymonth=8,bymonthday=13,byweekday=FR)[0].year
>>> rdelta = relativedelta(easter(year), today)
>>> print("Today is: %s" % today)
Today is: 2003-10-11
>>> print("Year with next Aug 13th on a Friday is: %s" % year)
Year with next Aug 13th on a Friday is: 2004
>>> print("How far is the Easter of that year: %s" % rdelta)
How far is the Easter of that year: relativedelta(months=+6)
>>> print("And the Easter of that year is: %s" % (today+rdelta))
And the Easter of that year is: 2004-04-11
Being exactly 6 months ahead was **really** a coincidence :)
Contributing
============
We welcome many types of contributions - bug reports, pull requests (code, infrastructure or documentation fixes). For more information about how to contribute to the project, see the ``CONTRIBUTING.md`` file in the repository.
Author
======
The dateutil module was written by Gustavo Niemeyer <gustavo@niemeyer.net>
in 2003.
It is maintained by:
* Gustavo Niemeyer <gustavo@niemeyer.net> 2003-2011
* Tomi Pieviläinen <tomi.pievilainen@iki.fi> 2012-2014
* Yaron de Leeuw <me@jarondl.net> 2014-2016
* Paul Ganssle <paul@ganssle.io> 2015-
Starting with version 2.4.1 and running until 2.8.2, all source and binary
distributions will be signed by a PGP key that has, at the very least, been
signed by the key which made the previous release. A table of release signing
keys can be found below:
=========== ============================
Releases Signing key fingerprint
=========== ============================
2.4.1-2.8.2 `6B49 ACBA DCF6 BD1C A206 67AB CD54 FCE3 D964 BEFB`_
=========== ============================
New releases *may* have signed tags, but binary and source distributions
uploaded to PyPI will no longer have GPG signatures attached.
Contact
=======
Our mailing list is available at `dateutil@python.org <https://mail.python.org/mailman/listinfo/dateutil>`_. As it is hosted by the PSF, it is subject to the `PSF code of
conduct <https://www.python.org/psf/conduct/>`_.
License
=======
All contributions after December 1, 2017 released under dual license - either `Apache 2.0 License <https://www.apache.org/licenses/LICENSE-2.0>`_ or the `BSD 3-Clause License <https://opensource.org/licenses/BSD-3-Clause>`_. Contributions before December 1, 2017 - except those those explicitly relicensed - are released only under the BSD 3-Clause License.
.. _6B49 ACBA DCF6 BD1C A206 67AB CD54 FCE3 D964 BEFB:
https://pgp.mit.edu/pks/lookup?op=vindex&search=0xCD54FCE3D964BEFB

View File

@@ -0,0 +1,44 @@
dateutil/__init__.py,sha256=Mqam67WO9IkTmUFyI66vS6IoSXTp9G388DadH2LCMLY,620
dateutil/__pycache__/__init__.cpython-312.pyc,,
dateutil/__pycache__/_common.cpython-312.pyc,,
dateutil/__pycache__/_version.cpython-312.pyc,,
dateutil/__pycache__/easter.cpython-312.pyc,,
dateutil/__pycache__/relativedelta.cpython-312.pyc,,
dateutil/__pycache__/rrule.cpython-312.pyc,,
dateutil/__pycache__/tzwin.cpython-312.pyc,,
dateutil/__pycache__/utils.cpython-312.pyc,,
dateutil/_common.py,sha256=77w0yytkrxlYbSn--lDVPUMabUXRR9I3lBv_vQRUqUY,932
dateutil/_version.py,sha256=BV031OxDDAmy58neUg5yyqLkLaqIw7ibK9As3jiMib0,166
dateutil/easter.py,sha256=dyBi-lKvimH1u_k6p7Z0JJK72QhqVtVBsqByvpEPKvc,2678
dateutil/parser/__init__.py,sha256=wWk6GFuxTpjoggCGtgkceJoti4pVjl4_fHQXpNOaSYg,1766
dateutil/parser/__pycache__/__init__.cpython-312.pyc,,
dateutil/parser/__pycache__/_parser.cpython-312.pyc,,
dateutil/parser/__pycache__/isoparser.cpython-312.pyc,,
dateutil/parser/_parser.py,sha256=7klDdyicksQB_Xgl-3UAmBwzCYor1AIZqklIcT6dH_8,58796
dateutil/parser/isoparser.py,sha256=8Fy999bnCd1frSdOYuOraWfJTtd5W7qQ51NwNuH_hXM,13233
dateutil/relativedelta.py,sha256=IY_mglMjoZbYfrvloTY2ce02aiVjPIkiZfqgNTZRfuA,24903
dateutil/rrule.py,sha256=KJzKlaCd1jEbu4A38ZltslaoAUh9nSbdbOFdjp70Kew,66557
dateutil/tz/__init__.py,sha256=F-Mz13v6jYseklQf9Te9J6nzcLDmq47gORa61K35_FA,444
dateutil/tz/__pycache__/__init__.cpython-312.pyc,,
dateutil/tz/__pycache__/_common.cpython-312.pyc,,
dateutil/tz/__pycache__/_factories.cpython-312.pyc,,
dateutil/tz/__pycache__/tz.cpython-312.pyc,,
dateutil/tz/__pycache__/win.cpython-312.pyc,,
dateutil/tz/_common.py,sha256=cgzDTANsOXvEc86cYF77EsliuSab8Puwpsl5-bX3_S4,12977
dateutil/tz/_factories.py,sha256=unb6XQNXrPMveksTCU-Ag8jmVZs4SojoPUcAHpWnrvU,2569
dateutil/tz/tz.py,sha256=EUnEdMfeThXiY6l4sh9yBabZ63_POzy01zSsh9thn1o,62855
dateutil/tz/win.py,sha256=xJszWgSwE1xPx_HJj4ZkepyukC_hNy016WMcXhbRaB8,12935
dateutil/tzwin.py,sha256=7Ar4vdQCnnM0mKR3MUjbIKsZrBVfHgdwsJZc_mGYRew,59
dateutil/utils.py,sha256=dKCchEw8eObi0loGTx91unBxm_7UGlU3v_FjFMdqwYM,1965
dateutil/zoneinfo/__init__.py,sha256=KYg0pthCMjcp5MXSEiBJn3nMjZeNZav7rlJw5-tz1S4,5889
dateutil/zoneinfo/__pycache__/__init__.cpython-312.pyc,,
dateutil/zoneinfo/__pycache__/rebuild.cpython-312.pyc,,
dateutil/zoneinfo/dateutil-zoneinfo.tar.gz,sha256=0-pS57bpaN4NiE3xKIGTWW-pW4A9tPkqGCeac5gARHU,156400
dateutil/zoneinfo/rebuild.py,sha256=MiqYzCIHvNbMH-LdRYLv-4T0EIA7hDKt5GLR0IRTLdI,2392
python_dateutil-2.9.0.post0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
python_dateutil-2.9.0.post0.dist-info/LICENSE,sha256=ugD1Gg2SgjtaHN4n2LW50jIeZ-2NqbwWPv-W1eF-V34,2889
python_dateutil-2.9.0.post0.dist-info/METADATA,sha256=qdQ22jIr6AgzL5jYgyWZjofLaTpniplp_rTPrXKabpM,8354
python_dateutil-2.9.0.post0.dist-info/RECORD,,
python_dateutil-2.9.0.post0.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
python_dateutil-2.9.0.post0.dist-info/top_level.txt,sha256=4tjdWkhRZvF7LA_BYe_L9gB2w_p2a-z5y6ArjaRkot8,9
python_dateutil-2.9.0.post0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1

View File

@@ -0,0 +1,6 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.42.0)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any

View File

@@ -0,0 +1,18 @@
Copyright (c) 2010-2024 Benjamin Peterson
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,43 @@
Metadata-Version: 2.1
Name: six
Version: 1.17.0
Summary: Python 2 and 3 compatibility utilities
Home-page: https://github.com/benjaminp/six
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*
License-File: LICENSE
.. image:: https://img.shields.io/pypi/v/six.svg
:target: https://pypi.org/project/six/
:alt: six on PyPI
.. image:: https://readthedocs.org/projects/six/badge/?version=latest
:target: https://six.readthedocs.io/
:alt: six's documentation on Read the Docs
.. image:: https://img.shields.io/badge/license-MIT-green.svg
:target: https://github.com/benjaminp/six/blob/master/LICENSE
:alt: MIT License badge
Six is a Python 2 and 3 compatibility library. It provides utility functions
for smoothing over the differences between the Python versions with the goal of
writing Python code that is compatible on both Python versions. See the
documentation for more information on what is provided.
Six supports Python 2.7 and 3.3+. It is contained in only one Python
file, so it can be easily copied into your project. (The copyright and license
notice must be retained.)
Online documentation is at https://six.readthedocs.io/.
Bugs can be reported to https://github.com/benjaminp/six. The code can also
be found there.

View File

@@ -0,0 +1,8 @@
__pycache__/six.cpython-312.pyc,,
six-1.17.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
six-1.17.0.dist-info/LICENSE,sha256=Q3W6IOK5xsTnytKUCmKP2Q6VzD1Q7pKq51VxXYuh-9A,1066
six-1.17.0.dist-info/METADATA,sha256=ViBCB4wnUlSfbYp8htvF3XCAiKe-bYBnLsewcQC3JGg,1658
six-1.17.0.dist-info/RECORD,,
six-1.17.0.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
six-1.17.0.dist-info/top_level.txt,sha256=_iVH_iYEtEXnD8nYGQYpYFUvkUW9sEO1GYbkeKSAais,4
six.py,sha256=xRyR9wPT1LNpbJI8tf7CE-BeddkhU5O--sfy-mo5BN8,34703

View File

@@ -0,0 +1,6 @@
Wheel-Version: 1.0
Generator: setuptools (75.6.0)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any

File diff suppressed because it is too large Load Diff