Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- parrot/lib/python3.10/site-packages/certifi/__pycache__/core.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/scipy/ndimage/tests/__pycache__/test_ni_support.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_fourier.py +137 -0
- parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_morphology.py +0 -0
- parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_ni_support.py +77 -0
- parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_splines.py +65 -0
- parrot/lib/python3.10/site-packages/typer-0.12.5.dist-info/INSTALLER +1 -0
- parrot/lib/python3.10/site-packages/typer-0.12.5.dist-info/entry_points.txt +3 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/AUTHORS +59 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/INSTALLER +1 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/LICENSE +29 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/METADATA +295 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/RECORD +83 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/REQUESTED +0 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/WHEEL +5 -0
- vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/top_level.txt +1 -0
- vllm/lib/python3.10/site-packages/dateutil/__init__.py +24 -0
- vllm/lib/python3.10/site-packages/dateutil/_common.py +43 -0
- vllm/lib/python3.10/site-packages/dateutil/_version.py +4 -0
- vllm/lib/python3.10/site-packages/dateutil/easter.py +89 -0
- vllm/lib/python3.10/site-packages/dateutil/relativedelta.py +599 -0
- vllm/lib/python3.10/site-packages/dateutil/rrule.py +1737 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/__init__.py +12 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/_common.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/_factories.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/tz.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/win.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/_common.py +419 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/_factories.py +80 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/tz.py +1849 -0
- vllm/lib/python3.10/site-packages/dateutil/tz/win.py +370 -0
- vllm/lib/python3.10/site-packages/dateutil/tzwin.py +2 -0
- vllm/lib/python3.10/site-packages/dateutil/utils.py +71 -0
- vllm/lib/python3.10/site-packages/dateutil/zoneinfo/rebuild.py +75 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/CH/A.py +59 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/CH/__init__.py +22 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/CH/__pycache__/A.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/CH/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/A.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/AAAA.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/HTTPS.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/IPSECKEY.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/KX.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/NAPTR.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/NSAP.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/NSAP_PTR.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/PX.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/SRV.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/SVCB.cpython-310.pyc +0 -0
parrot/lib/python3.10/site-packages/certifi/__pycache__/core.cpython-310.pyc
ADDED
|
Binary file (2.1 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/scipy/ndimage/tests/__pycache__/test_ni_support.cpython-310.pyc
ADDED
|
Binary file (1.86 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_fourier.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from numpy import fft
|
| 3 |
+
from numpy.testing import (assert_almost_equal, assert_array_almost_equal,
|
| 4 |
+
assert_equal)
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
from scipy import ndimage
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestNdimageFourier:
|
| 12 |
+
|
| 13 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15), (1, 10)])
|
| 14 |
+
@pytest.mark.parametrize('dtype, dec', [(np.float32, 6), (np.float64, 14)])
|
| 15 |
+
def test_fourier_gaussian_real01(self, shape, dtype, dec):
|
| 16 |
+
a = np.zeros(shape, dtype)
|
| 17 |
+
a[0, 0] = 1.0
|
| 18 |
+
a = fft.rfft(a, shape[0], 0)
|
| 19 |
+
a = fft.fft(a, shape[1], 1)
|
| 20 |
+
a = ndimage.fourier_gaussian(a, [5.0, 2.5], shape[0], 0)
|
| 21 |
+
a = fft.ifft(a, shape[1], 1)
|
| 22 |
+
a = fft.irfft(a, shape[0], 0)
|
| 23 |
+
assert_almost_equal(ndimage.sum(a), 1, decimal=dec)
|
| 24 |
+
|
| 25 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15)])
|
| 26 |
+
@pytest.mark.parametrize('dtype, dec', [(np.complex64, 6), (np.complex128, 14)])
|
| 27 |
+
def test_fourier_gaussian_complex01(self, shape, dtype, dec):
|
| 28 |
+
a = np.zeros(shape, dtype)
|
| 29 |
+
a[0, 0] = 1.0
|
| 30 |
+
a = fft.fft(a, shape[0], 0)
|
| 31 |
+
a = fft.fft(a, shape[1], 1)
|
| 32 |
+
a = ndimage.fourier_gaussian(a, [5.0, 2.5], -1, 0)
|
| 33 |
+
a = fft.ifft(a, shape[1], 1)
|
| 34 |
+
a = fft.ifft(a, shape[0], 0)
|
| 35 |
+
assert_almost_equal(ndimage.sum(a.real), 1.0, decimal=dec)
|
| 36 |
+
|
| 37 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15), (1, 10)])
|
| 38 |
+
@pytest.mark.parametrize('dtype, dec', [(np.float32, 6), (np.float64, 14)])
|
| 39 |
+
def test_fourier_uniform_real01(self, shape, dtype, dec):
|
| 40 |
+
a = np.zeros(shape, dtype)
|
| 41 |
+
a[0, 0] = 1.0
|
| 42 |
+
a = fft.rfft(a, shape[0], 0)
|
| 43 |
+
a = fft.fft(a, shape[1], 1)
|
| 44 |
+
a = ndimage.fourier_uniform(a, [5.0, 2.5], shape[0], 0)
|
| 45 |
+
a = fft.ifft(a, shape[1], 1)
|
| 46 |
+
a = fft.irfft(a, shape[0], 0)
|
| 47 |
+
assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec)
|
| 48 |
+
|
| 49 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15)])
|
| 50 |
+
@pytest.mark.parametrize('dtype, dec', [(np.complex64, 6), (np.complex128, 14)])
|
| 51 |
+
def test_fourier_uniform_complex01(self, shape, dtype, dec):
|
| 52 |
+
a = np.zeros(shape, dtype)
|
| 53 |
+
a[0, 0] = 1.0
|
| 54 |
+
a = fft.fft(a, shape[0], 0)
|
| 55 |
+
a = fft.fft(a, shape[1], 1)
|
| 56 |
+
a = ndimage.fourier_uniform(a, [5.0, 2.5], -1, 0)
|
| 57 |
+
a = fft.ifft(a, shape[1], 1)
|
| 58 |
+
a = fft.ifft(a, shape[0], 0)
|
| 59 |
+
assert_almost_equal(ndimage.sum(a.real), 1.0, decimal=dec)
|
| 60 |
+
|
| 61 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15)])
|
| 62 |
+
@pytest.mark.parametrize('dtype, dec', [(np.float32, 4), (np.float64, 11)])
|
| 63 |
+
def test_fourier_shift_real01(self, shape, dtype, dec):
|
| 64 |
+
expected = np.arange(shape[0] * shape[1], dtype=dtype)
|
| 65 |
+
expected.shape = shape
|
| 66 |
+
a = fft.rfft(expected, shape[0], 0)
|
| 67 |
+
a = fft.fft(a, shape[1], 1)
|
| 68 |
+
a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
|
| 69 |
+
a = fft.ifft(a, shape[1], 1)
|
| 70 |
+
a = fft.irfft(a, shape[0], 0)
|
| 71 |
+
assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1], decimal=dec)
|
| 72 |
+
assert_array_almost_equal(a.imag, np.zeros(shape), decimal=dec)
|
| 73 |
+
|
| 74 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15)])
|
| 75 |
+
@pytest.mark.parametrize('dtype, dec', [(np.complex64, 4), (np.complex128, 11)])
|
| 76 |
+
def test_fourier_shift_complex01(self, shape, dtype, dec):
|
| 77 |
+
expected = np.arange(shape[0] * shape[1], dtype=dtype)
|
| 78 |
+
expected.shape = shape
|
| 79 |
+
a = fft.fft(expected, shape[0], 0)
|
| 80 |
+
a = fft.fft(a, shape[1], 1)
|
| 81 |
+
a = ndimage.fourier_shift(a, [1, 1], -1, 0)
|
| 82 |
+
a = fft.ifft(a, shape[1], 1)
|
| 83 |
+
a = fft.ifft(a, shape[0], 0)
|
| 84 |
+
assert_array_almost_equal(a.real[1:, 1:], expected[:-1, :-1], decimal=dec)
|
| 85 |
+
assert_array_almost_equal(a.imag, np.zeros(shape), decimal=dec)
|
| 86 |
+
|
| 87 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15), (1, 10)])
|
| 88 |
+
@pytest.mark.parametrize('dtype, dec', [(np.float32, 5), (np.float64, 14)])
|
| 89 |
+
def test_fourier_ellipsoid_real01(self, shape, dtype, dec):
|
| 90 |
+
a = np.zeros(shape, dtype)
|
| 91 |
+
a[0, 0] = 1.0
|
| 92 |
+
a = fft.rfft(a, shape[0], 0)
|
| 93 |
+
a = fft.fft(a, shape[1], 1)
|
| 94 |
+
a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
|
| 95 |
+
shape[0], 0)
|
| 96 |
+
a = fft.ifft(a, shape[1], 1)
|
| 97 |
+
a = fft.irfft(a, shape[0], 0)
|
| 98 |
+
assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec)
|
| 99 |
+
|
| 100 |
+
@pytest.mark.parametrize('shape', [(32, 16), (31, 15)])
|
| 101 |
+
@pytest.mark.parametrize('dtype, dec', [(np.complex64, 5), (np.complex128, 14)])
|
| 102 |
+
def test_fourier_ellipsoid_complex01(self, shape, dtype, dec):
|
| 103 |
+
a = np.zeros(shape, dtype)
|
| 104 |
+
a[0, 0] = 1.0
|
| 105 |
+
a = fft.fft(a, shape[0], 0)
|
| 106 |
+
a = fft.fft(a, shape[1], 1)
|
| 107 |
+
a = ndimage.fourier_ellipsoid(a, [5.0, 2.5], -1, 0)
|
| 108 |
+
a = fft.ifft(a, shape[1], 1)
|
| 109 |
+
a = fft.ifft(a, shape[0], 0)
|
| 110 |
+
assert_almost_equal(ndimage.sum(a.real), 1.0, decimal=dec)
|
| 111 |
+
|
| 112 |
+
def test_fourier_ellipsoid_unimplemented_ndim(self):
|
| 113 |
+
# arrays with ndim > 3 raise NotImplementedError
|
| 114 |
+
x = np.ones((4, 6, 8, 10), dtype=np.complex128)
|
| 115 |
+
with pytest.raises(NotImplementedError):
|
| 116 |
+
ndimage.fourier_ellipsoid(x, 3)
|
| 117 |
+
|
| 118 |
+
def test_fourier_ellipsoid_1d_complex(self):
|
| 119 |
+
# expected result of 1d ellipsoid is the same as for fourier_uniform
|
| 120 |
+
for shape in [(32, ), (31, )]:
|
| 121 |
+
for type_, dec in zip([np.complex64, np.complex128], [5, 14]):
|
| 122 |
+
x = np.ones(shape, dtype=type_)
|
| 123 |
+
a = ndimage.fourier_ellipsoid(x, 5, -1, 0)
|
| 124 |
+
b = ndimage.fourier_uniform(x, 5, -1, 0)
|
| 125 |
+
assert_array_almost_equal(a, b, decimal=dec)
|
| 126 |
+
|
| 127 |
+
@pytest.mark.parametrize('shape', [(0, ), (0, 10), (10, 0)])
|
| 128 |
+
@pytest.mark.parametrize('dtype', [np.float32, np.float64,
|
| 129 |
+
np.complex64, np.complex128])
|
| 130 |
+
@pytest.mark.parametrize('test_func',
|
| 131 |
+
[ndimage.fourier_ellipsoid,
|
| 132 |
+
ndimage.fourier_gaussian,
|
| 133 |
+
ndimage.fourier_uniform])
|
| 134 |
+
def test_fourier_zero_length_dims(self, shape, dtype, test_func):
|
| 135 |
+
a = np.ones(shape, dtype)
|
| 136 |
+
b = test_func(a, 3)
|
| 137 |
+
assert_equal(a, b)
|
parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_morphology.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_ni_support.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from .._ni_support import _get_output
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@pytest.mark.parametrize(
|
| 8 |
+
'dtype',
|
| 9 |
+
[
|
| 10 |
+
# String specifiers
|
| 11 |
+
'f4', 'float32', 'complex64', 'complex128',
|
| 12 |
+
# Type and dtype specifiers
|
| 13 |
+
np.float32, float, np.dtype('f4'),
|
| 14 |
+
# Derive from input
|
| 15 |
+
None,
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
def test_get_output_basic(dtype):
|
| 19 |
+
shape = (2, 3)
|
| 20 |
+
|
| 21 |
+
input_ = np.zeros(shape, 'float32')
|
| 22 |
+
|
| 23 |
+
# For None, derive dtype from input
|
| 24 |
+
expected_dtype = 'float32' if dtype is None else dtype
|
| 25 |
+
|
| 26 |
+
# Output is dtype-specifier, retrieve shape from input
|
| 27 |
+
result = _get_output(dtype, input_)
|
| 28 |
+
assert result.shape == shape
|
| 29 |
+
assert result.dtype == np.dtype(expected_dtype)
|
| 30 |
+
|
| 31 |
+
# Output is dtype specifier, with explicit shape, overriding input
|
| 32 |
+
result = _get_output(dtype, input_, shape=(3, 2))
|
| 33 |
+
assert result.shape == (3, 2)
|
| 34 |
+
assert result.dtype == np.dtype(expected_dtype)
|
| 35 |
+
|
| 36 |
+
# Output is pre-allocated array, return directly
|
| 37 |
+
output = np.zeros(shape, dtype)
|
| 38 |
+
result = _get_output(output, input_)
|
| 39 |
+
assert result is output
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_get_output_complex():
|
| 43 |
+
shape = (2, 3)
|
| 44 |
+
|
| 45 |
+
input_ = np.zeros(shape)
|
| 46 |
+
|
| 47 |
+
# None, promote input type to complex
|
| 48 |
+
result = _get_output(None, input_, complex_output=True)
|
| 49 |
+
assert result.shape == shape
|
| 50 |
+
assert result.dtype == np.dtype('complex128')
|
| 51 |
+
|
| 52 |
+
# Explicit type, promote type to complex
|
| 53 |
+
with pytest.warns(UserWarning, match='promoting specified output dtype to complex'):
|
| 54 |
+
result = _get_output(float, input_, complex_output=True)
|
| 55 |
+
assert result.shape == shape
|
| 56 |
+
assert result.dtype == np.dtype('complex128')
|
| 57 |
+
|
| 58 |
+
# String specifier, simply verify complex output
|
| 59 |
+
result = _get_output('complex64', input_, complex_output=True)
|
| 60 |
+
assert result.shape == shape
|
| 61 |
+
assert result.dtype == np.dtype('complex64')
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_get_output_error_cases():
|
| 65 |
+
input_ = np.zeros((2, 3), 'float32')
|
| 66 |
+
|
| 67 |
+
# Two separate paths can raise the same error
|
| 68 |
+
with pytest.raises(RuntimeError, match='output must have complex dtype'):
|
| 69 |
+
_get_output('float32', input_, complex_output=True)
|
| 70 |
+
with pytest.raises(RuntimeError, match='output must have complex dtype'):
|
| 71 |
+
_get_output(np.zeros((2, 3)), input_, complex_output=True)
|
| 72 |
+
|
| 73 |
+
with pytest.raises(RuntimeError, match='output must have numeric dtype'):
|
| 74 |
+
_get_output('void', input_)
|
| 75 |
+
|
| 76 |
+
with pytest.raises(RuntimeError, match='shape not correct'):
|
| 77 |
+
_get_output(np.zeros((3, 2)), input_)
|
parrot/lib/python3.10/site-packages/scipy/ndimage/tests/test_splines.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for spline filtering."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from numpy.testing import assert_almost_equal
|
| 6 |
+
|
| 7 |
+
from scipy import ndimage
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_spline_knot_values(order):
|
| 11 |
+
"""Knot values to the right of a B-spline's center."""
|
| 12 |
+
knot_values = {0: [1],
|
| 13 |
+
1: [1],
|
| 14 |
+
2: [6, 1],
|
| 15 |
+
3: [4, 1],
|
| 16 |
+
4: [230, 76, 1],
|
| 17 |
+
5: [66, 26, 1]}
|
| 18 |
+
|
| 19 |
+
return knot_values[order]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def make_spline_knot_matrix(n, order, mode='mirror'):
|
| 23 |
+
"""Matrix to invert to find the spline coefficients."""
|
| 24 |
+
knot_values = get_spline_knot_values(order)
|
| 25 |
+
|
| 26 |
+
matrix = np.zeros((n, n))
|
| 27 |
+
for diag, knot_value in enumerate(knot_values):
|
| 28 |
+
indices = np.arange(diag, n)
|
| 29 |
+
if diag == 0:
|
| 30 |
+
matrix[indices, indices] = knot_value
|
| 31 |
+
else:
|
| 32 |
+
matrix[indices, indices - diag] = knot_value
|
| 33 |
+
matrix[indices - diag, indices] = knot_value
|
| 34 |
+
|
| 35 |
+
knot_values_sum = knot_values[0] + 2 * sum(knot_values[1:])
|
| 36 |
+
|
| 37 |
+
if mode == 'mirror':
|
| 38 |
+
start, step = 1, 1
|
| 39 |
+
elif mode == 'reflect':
|
| 40 |
+
start, step = 0, 1
|
| 41 |
+
elif mode == 'grid-wrap':
|
| 42 |
+
start, step = -1, -1
|
| 43 |
+
else:
|
| 44 |
+
raise ValueError(f'unsupported mode {mode}')
|
| 45 |
+
|
| 46 |
+
for row in range(len(knot_values) - 1):
|
| 47 |
+
for idx, knot_value in enumerate(knot_values[row + 1:]):
|
| 48 |
+
matrix[row, start + step*idx] += knot_value
|
| 49 |
+
matrix[-row - 1, -start - 1 - step*idx] += knot_value
|
| 50 |
+
|
| 51 |
+
return matrix / knot_values_sum
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@pytest.mark.parametrize('order', [0, 1, 2, 3, 4, 5])
|
| 55 |
+
@pytest.mark.parametrize('mode', ['mirror', 'grid-wrap', 'reflect'])
|
| 56 |
+
def test_spline_filter_vs_matrix_solution(order, mode):
|
| 57 |
+
n = 100
|
| 58 |
+
eye = np.eye(n, dtype=float)
|
| 59 |
+
spline_filter_axis_0 = ndimage.spline_filter1d(eye, axis=0, order=order,
|
| 60 |
+
mode=mode)
|
| 61 |
+
spline_filter_axis_1 = ndimage.spline_filter1d(eye, axis=1, order=order,
|
| 62 |
+
mode=mode)
|
| 63 |
+
matrix = make_spline_knot_matrix(n, order, mode=mode)
|
| 64 |
+
assert_almost_equal(eye, np.dot(spline_filter_axis_0, matrix))
|
| 65 |
+
assert_almost_equal(eye, np.dot(spline_filter_axis_1, matrix.T))
|
parrot/lib/python3.10/site-packages/typer-0.12.5.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
parrot/lib/python3.10/site-packages/typer-0.12.5.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
typer = typer.cli:main
|
| 3 |
+
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/AUTHORS
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GitPython was originally written by Michael Trier.
|
| 2 |
+
GitPython 0.2 was partially (re)written by Sebastian Thiel, based on 0.1.6 and git-dulwich.
|
| 3 |
+
|
| 4 |
+
Contributors are:
|
| 5 |
+
|
| 6 |
+
-Michael Trier <mtrier _at_ gmail.com>
|
| 7 |
+
-Alan Briolat
|
| 8 |
+
-Florian Apolloner <florian _at_ apolloner.eu>
|
| 9 |
+
-David Aguilar <davvid _at_ gmail.com>
|
| 10 |
+
-Jelmer Vernooij <jelmer _at_ samba.org>
|
| 11 |
+
-Steve Frécinaux <code _at_ istique.net>
|
| 12 |
+
-Kai Lautaportti <kai _at_ lautaportti.fi>
|
| 13 |
+
-Paul Sowden <paul _at_ idontsmoke.co.uk>
|
| 14 |
+
-Sebastian Thiel <byronimo _at_ gmail.com>
|
| 15 |
+
-Jonathan Chu <jonathan.chu _at_ me.com>
|
| 16 |
+
-Vincent Driessen <me _at_ nvie.com>
|
| 17 |
+
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
|
| 18 |
+
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
|
| 19 |
+
-Timothy B. Hartman <tbhartman _at_ gmail.com>
|
| 20 |
+
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>
|
| 21 |
+
-Peter Jones <pjones _at_ redhat.com>
|
| 22 |
+
-Anson Mansfield <anson.mansfield _at_ gmail.com>
|
| 23 |
+
-Ken Odegard <ken.odegard _at_ gmail.com>
|
| 24 |
+
-Alexis Horgix Chotard
|
| 25 |
+
-Piotr Babij <piotr.babij _at_ gmail.com>
|
| 26 |
+
-Mikuláš Poul <mikulaspoul _at_ gmail.com>
|
| 27 |
+
-Charles Bouchard-Légaré <cblegare.atl _at_ ntis.ca>
|
| 28 |
+
-Yaroslav Halchenko <debian _at_ onerussian.com>
|
| 29 |
+
-Tim Swast <swast _at_ google.com>
|
| 30 |
+
-William Luc Ritchie
|
| 31 |
+
-David Host <hostdm _at_ outlook.com>
|
| 32 |
+
-A. Jesse Jiryu Davis <jesse _at_ emptysquare.net>
|
| 33 |
+
-Steven Whitman <ninloot _at_ gmail.com>
|
| 34 |
+
-Stefan Stancu <stefan.stancu _at_ gmail.com>
|
| 35 |
+
-César Izurieta <cesar _at_ caih.org>
|
| 36 |
+
-Arthur Milchior <arthur _at_ milchior.fr>
|
| 37 |
+
-Anil Khatri <anil.soccer.khatri _at_ gmail.com>
|
| 38 |
+
-JJ Graham <thetwoj _at_ gmail.com>
|
| 39 |
+
-Ben Thayer <ben _at_ benthayer.com>
|
| 40 |
+
-Dries Kennes <admin _at_ dries007.net>
|
| 41 |
+
-Pratik Anurag <panurag247365 _at_ gmail.com>
|
| 42 |
+
-Harmon <harmon.public _at_ gmail.com>
|
| 43 |
+
-Liam Beguin <liambeguin _at_ gmail.com>
|
| 44 |
+
-Ram Rachum <ram _at_ rachum.com>
|
| 45 |
+
-Alba Mendez <me _at_ alba.sh>
|
| 46 |
+
-Robert Westman <robert _at_ byteflux.io>
|
| 47 |
+
-Hugo van Kemenade
|
| 48 |
+
-Hiroki Tokunaga <tokusan441 _at_ gmail.com>
|
| 49 |
+
-Julien Mauroy <pro.julien.mauroy _at_ gmail.com>
|
| 50 |
+
-Patrick Gerard
|
| 51 |
+
-Luke Twist <itsluketwist@gmail.com>
|
| 52 |
+
-Joseph Hale <me _at_ jhale.dev>
|
| 53 |
+
-Santos Gallegos <stsewd _at_ proton.me>
|
| 54 |
+
-Wenhan Zhu <wzhu.cosmos _at_ gmail.com>
|
| 55 |
+
-Eliah Kagan <eliah.kagan _at_ gmail.com>
|
| 56 |
+
-Ethan Lin <et.repositories _at_ gmail.com>
|
| 57 |
+
-Jonas Scharpf <jonas.scharpf _at_ checkmk.com>
|
| 58 |
+
|
| 59 |
+
Portions derived from other open source works and are clearly marked.
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (C) 2008, 2009 Michael Trier and contributors
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions
|
| 6 |
+
are met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright
|
| 9 |
+
notice, this list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
|
| 15 |
+
* Neither the name of the GitPython project nor the names of
|
| 16 |
+
its contributors may be used to endorse or promote products derived
|
| 17 |
+
from this software without specific prior written permission.
|
| 18 |
+
|
| 19 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 20 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 21 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 22 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 23 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 24 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 25 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 26 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 27 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 28 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 29 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/METADATA
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: GitPython
|
| 3 |
+
Version: 3.1.44
|
| 4 |
+
Summary: GitPython is a Python library used to interact with Git repositories
|
| 5 |
+
Home-page: https://github.com/gitpython-developers/GitPython
|
| 6 |
+
Author: Sebastian Thiel, Michael Trier
|
| 7 |
+
Author-email: byronimo@gmail.com, mtrier@gmail.com
|
| 8 |
+
License: BSD-3-Clause
|
| 9 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 10 |
+
Classifier: Environment :: Console
|
| 11 |
+
Classifier: Intended Audience :: Developers
|
| 12 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 13 |
+
Classifier: Operating System :: OS Independent
|
| 14 |
+
Classifier: Operating System :: POSIX
|
| 15 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 16 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 17 |
+
Classifier: Typing :: Typed
|
| 18 |
+
Classifier: Programming Language :: Python
|
| 19 |
+
Classifier: Programming Language :: Python :: 3
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 25 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 26 |
+
Requires-Python: >=3.7
|
| 27 |
+
Description-Content-Type: text/markdown
|
| 28 |
+
License-File: LICENSE
|
| 29 |
+
License-File: AUTHORS
|
| 30 |
+
Requires-Dist: gitdb<5,>=4.0.1
|
| 31 |
+
Requires-Dist: typing-extensions>=3.7.4.3; python_version < "3.8"
|
| 32 |
+
Provides-Extra: test
|
| 33 |
+
Requires-Dist: coverage[toml]; extra == "test"
|
| 34 |
+
Requires-Dist: ddt!=1.4.3,>=1.1.1; extra == "test"
|
| 35 |
+
Requires-Dist: mock; python_version < "3.8" and extra == "test"
|
| 36 |
+
Requires-Dist: mypy; extra == "test"
|
| 37 |
+
Requires-Dist: pre-commit; extra == "test"
|
| 38 |
+
Requires-Dist: pytest>=7.3.1; extra == "test"
|
| 39 |
+
Requires-Dist: pytest-cov; extra == "test"
|
| 40 |
+
Requires-Dist: pytest-instafail; extra == "test"
|
| 41 |
+
Requires-Dist: pytest-mock; extra == "test"
|
| 42 |
+
Requires-Dist: pytest-sugar; extra == "test"
|
| 43 |
+
Requires-Dist: typing-extensions; python_version < "3.11" and extra == "test"
|
| 44 |
+
Provides-Extra: doc
|
| 45 |
+
Requires-Dist: sphinx<7.2,>=7.1.2; extra == "doc"
|
| 46 |
+
Requires-Dist: sphinx_rtd_theme; extra == "doc"
|
| 47 |
+
Requires-Dist: sphinx-autodoc-typehints; extra == "doc"
|
| 48 |
+
|
| 49 |
+

|
| 50 |
+
[](https://readthedocs.org/projects/gitpython/?badge=stable)
|
| 51 |
+
[](https://repology.org/metapackage/python:gitpython/versions)
|
| 52 |
+
|
| 53 |
+
## [Gitoxide](https://github.com/Byron/gitoxide): A peek into the future…
|
| 54 |
+
|
| 55 |
+
I started working on GitPython in 2009, back in the days when Python was 'my thing' and I had great plans with it.
|
| 56 |
+
Of course, back in the days, I didn't really know what I was doing and this shows in many places. Somewhat similar to
|
| 57 |
+
Python this happens to be 'good enough', but at the same time is deeply flawed and broken beyond repair.
|
| 58 |
+
|
| 59 |
+
By now, GitPython is widely used and I am sure there is a good reason for that, it's something to be proud of and happy about.
|
| 60 |
+
The community is maintaining the software and is keeping it relevant for which I am absolutely grateful. For the time to come I am happy to continue maintaining GitPython, remaining hopeful that one day it won't be needed anymore.
|
| 61 |
+
|
| 62 |
+
More than 15 years after my first meeting with 'git' I am still in excited about it, and am happy to finally have the tools and
|
| 63 |
+
probably the skills to scratch that itch of mine: implement `git` in a way that makes tool creation a piece of cake for most.
|
| 64 |
+
|
| 65 |
+
If you like the idea and want to learn more, please head over to [gitoxide](https://github.com/Byron/gitoxide), an
|
| 66 |
+
implementation of 'git' in [Rust](https://www.rust-lang.org).
|
| 67 |
+
|
| 68 |
+
*(Please note that `gitoxide` is not currently available for use in Python, and that Rust is required.)*
|
| 69 |
+
|
| 70 |
+
## GitPython
|
| 71 |
+
|
| 72 |
+
GitPython is a python library used to interact with git repositories, high-level like git-porcelain,
|
| 73 |
+
or low-level like git-plumbing.
|
| 74 |
+
|
| 75 |
+
It provides abstractions of git objects for easy access of repository data often backed by calling the `git`
|
| 76 |
+
command-line program.
|
| 77 |
+
|
| 78 |
+
### DEVELOPMENT STATUS
|
| 79 |
+
|
| 80 |
+
This project is in **maintenance mode**, which means that
|
| 81 |
+
|
| 82 |
+
- …there will be no feature development, unless these are contributed
|
| 83 |
+
- …there will be no bug fixes, unless they are relevant to the safety of users, or contributed
|
| 84 |
+
- …issues will be responded to with waiting times of up to a month
|
| 85 |
+
|
| 86 |
+
The project is open to contributions of all kinds, as well as new maintainers.
|
| 87 |
+
|
| 88 |
+
### REQUIREMENTS
|
| 89 |
+
|
| 90 |
+
GitPython needs the `git` executable to be installed on the system and available in your
|
| 91 |
+
`PATH` for most operations. If it is not in your `PATH`, you can help GitPython find it
|
| 92 |
+
by setting the `GIT_PYTHON_GIT_EXECUTABLE=<path/to/git>` environment variable.
|
| 93 |
+
|
| 94 |
+
- Git (1.7.x or newer)
|
| 95 |
+
- Python >= 3.7
|
| 96 |
+
|
| 97 |
+
The list of dependencies are listed in `./requirements.txt` and `./test-requirements.txt`.
|
| 98 |
+
The installer takes care of installing them for you.
|
| 99 |
+
|
| 100 |
+
### INSTALL
|
| 101 |
+
|
| 102 |
+
GitPython and its required package dependencies can be installed in any of the following ways, all of which should typically be done in a [virtual environment](https://docs.python.org/3/tutorial/venv.html).
|
| 103 |
+
|
| 104 |
+
#### From PyPI
|
| 105 |
+
|
| 106 |
+
To obtain and install a copy [from PyPI](https://pypi.org/project/GitPython/), run:
|
| 107 |
+
|
| 108 |
+
```sh
|
| 109 |
+
pip install GitPython
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
(A distribution package can also be downloaded for manual installation at [the PyPI page](https://pypi.org/project/GitPython/).)
|
| 113 |
+
|
| 114 |
+
#### From downloaded source code
|
| 115 |
+
|
| 116 |
+
If you have downloaded the source code, run this from inside the unpacked `GitPython` directory:
|
| 117 |
+
|
| 118 |
+
```sh
|
| 119 |
+
pip install .
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
#### By cloning the source code repository
|
| 123 |
+
|
| 124 |
+
To clone the [the GitHub repository](https://github.com/gitpython-developers/GitPython) from source to work on the code, you can do it like so:
|
| 125 |
+
|
| 126 |
+
```sh
|
| 127 |
+
git clone https://github.com/gitpython-developers/GitPython
|
| 128 |
+
cd GitPython
|
| 129 |
+
./init-tests-after-clone.sh
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
On Windows, `./init-tests-after-clone.sh` can be run in a Git Bash shell.
|
| 133 |
+
|
| 134 |
+
If you are cloning [your own fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks), then replace the above `git clone` command with one that gives the URL of your fork. Or use this [`gh`](https://cli.github.com/) command (assuming you have `gh` and your fork is called `GitPython`):
|
| 135 |
+
|
| 136 |
+
```sh
|
| 137 |
+
gh repo clone GitPython
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
Having cloned the repo, create and activate your [virtual environment](https://docs.python.org/3/tutorial/venv.html).
|
| 141 |
+
|
| 142 |
+
Then make an [editable install](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs):
|
| 143 |
+
|
| 144 |
+
```sh
|
| 145 |
+
pip install -e ".[test]"
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
In the less common case that you do not want to install test dependencies, `pip install -e .` can be used instead.
|
| 149 |
+
|
| 150 |
+
#### With editable *dependencies* (not preferred, and rarely needed)
|
| 151 |
+
|
| 152 |
+
In rare cases, you may want to work on GitPython and one or both of its [gitdb](https://github.com/gitpython-developers/gitdb) and [smmap](https://github.com/gitpython-developers/smmap) dependencies at the same time, with changes in your local working copy of gitdb or smmap immediately reflected in the behavior of your local working copy of GitPython. This can be done by making editable installations of those dependencies in the same virtual environment where you install GitPython.
|
| 153 |
+
|
| 154 |
+
If you want to do that *and* you want the versions in GitPython's git submodules to be used, then pass `-e git/ext/gitdb` and/or `-e git/ext/gitdb/gitdb/ext/smmap` to `pip install`. This can be done in any order, and in separate `pip install` commands or the same one, so long as `-e` appears before *each* path. For example, you can install GitPython, gitdb, and smmap editably in the currently active virtual environment this way:
|
| 155 |
+
|
| 156 |
+
```sh
|
| 157 |
+
pip install -e ".[test]" -e git/ext/gitdb -e git/ext/gitdb/gitdb/ext/smmap
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
The submodules must have been cloned for that to work, but that will already be the case if you have run `./init-tests-after-clone.sh`. You can use `pip list` to check which packages are installed editably and which are installed normally.
|
| 161 |
+
|
| 162 |
+
To reiterate, this approach should only rarely be used. For most development it is preferable to allow the gitdb and smmap dependencices to be retrieved automatically from PyPI in their latest stable packaged versions.
|
| 163 |
+
|
| 164 |
+
### Limitations
|
| 165 |
+
|
| 166 |
+
#### Leakage of System Resources
|
| 167 |
+
|
| 168 |
+
GitPython is not suited for long-running processes (like daemons) as it tends to
|
| 169 |
+
leak system resources. It was written in a time where destructors (as implemented
|
| 170 |
+
in the `__del__` method) still ran deterministically.
|
| 171 |
+
|
| 172 |
+
In case you still want to use it in such a context, you will want to search the
|
| 173 |
+
codebase for `__del__` implementations and call these yourself when you see fit.
|
| 174 |
+
|
| 175 |
+
Another way assure proper cleanup of resources is to factor out GitPython into a
|
| 176 |
+
separate process which can be dropped periodically.
|
| 177 |
+
|
| 178 |
+
#### Windows support
|
| 179 |
+
|
| 180 |
+
See [Issue #525](https://github.com/gitpython-developers/GitPython/issues/525).
|
| 181 |
+
|
| 182 |
+
### RUNNING TESTS
|
| 183 |
+
|
| 184 |
+
_Important_: Right after cloning this repository, please be sure to have executed
|
| 185 |
+
the `./init-tests-after-clone.sh` script in the repository root. Otherwise
|
| 186 |
+
you will encounter test failures.
|
| 187 |
+
|
| 188 |
+
#### Install test dependencies
|
| 189 |
+
|
| 190 |
+
Ensure testing libraries are installed. This is taken care of already if you installed with:
|
| 191 |
+
|
| 192 |
+
```sh
|
| 193 |
+
pip install -e ".[test]"
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
If you had installed with a command like `pip install -e .` instead, you can still run
|
| 197 |
+
the above command to add the testing dependencies.
|
| 198 |
+
|
| 199 |
+
#### Test commands
|
| 200 |
+
|
| 201 |
+
To test, run:
|
| 202 |
+
|
| 203 |
+
```sh
|
| 204 |
+
pytest
|
| 205 |
+
```
|
| 206 |
+
|
| 207 |
+
To lint, and apply some linting fixes as well as automatic code formatting, run:
|
| 208 |
+
|
| 209 |
+
```sh
|
| 210 |
+
pre-commit run --all-files
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
This includes the linting and autoformatting done by Ruff, as well as some other checks.
|
| 214 |
+
|
| 215 |
+
To typecheck, run:
|
| 216 |
+
|
| 217 |
+
```sh
|
| 218 |
+
mypy
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
#### CI (and tox)
|
| 222 |
+
|
| 223 |
+
Style and formatting checks, and running tests on all the different supported Python versions, will be performed:
|
| 224 |
+
|
| 225 |
+
- Upon submitting a pull request.
|
| 226 |
+
- On each push, *if* you have a fork with GitHub Actions enabled.
|
| 227 |
+
- Locally, if you run [`tox`](https://tox.wiki/) (this skips any Python versions you don't have installed).
|
| 228 |
+
|
| 229 |
+
#### Configuration files
|
| 230 |
+
|
| 231 |
+
Specific tools are all configured in the `./pyproject.toml` file:
|
| 232 |
+
|
| 233 |
+
- `pytest` (test runner)
|
| 234 |
+
- `coverage.py` (code coverage)
|
| 235 |
+
- `ruff` (linter and formatter)
|
| 236 |
+
- `mypy` (type checker)
|
| 237 |
+
|
| 238 |
+
Orchestration tools:
|
| 239 |
+
|
| 240 |
+
- Configuration for `pre-commit` is in the `./.pre-commit-config.yaml` file.
|
| 241 |
+
- Configuration for `tox` is in `./tox.ini`.
|
| 242 |
+
- Configuration for GitHub Actions (CI) is in files inside `./.github/workflows/`.
|
| 243 |
+
|
| 244 |
+
### Contributions
|
| 245 |
+
|
| 246 |
+
Please have a look at the [contributions file][contributing].
|
| 247 |
+
|
| 248 |
+
### INFRASTRUCTURE
|
| 249 |
+
|
| 250 |
+
- [User Documentation](http://gitpython.readthedocs.org)
|
| 251 |
+
- [Questions and Answers](http://stackexchange.com/filters/167317/gitpython)
|
| 252 |
+
- Please post on Stack Overflow and use the `gitpython` tag
|
| 253 |
+
- [Issue Tracker](https://github.com/gitpython-developers/GitPython/issues)
|
| 254 |
+
- Post reproducible bugs and feature requests as a new issue.
|
| 255 |
+
Please be sure to provide the following information if posting bugs:
|
| 256 |
+
- GitPython version (e.g. `import git; git.__version__`)
|
| 257 |
+
- Python version (e.g. `python --version`)
|
| 258 |
+
- The encountered stack-trace, if applicable
|
| 259 |
+
- Enough information to allow reproducing the issue
|
| 260 |
+
|
| 261 |
+
### How to make a new release
|
| 262 |
+
|
| 263 |
+
1. Update/verify the **version** in the `VERSION` file.
|
| 264 |
+
2. Update/verify that the `doc/source/changes.rst` changelog file was updated. It should include a link to the forthcoming release page: `https://github.com/gitpython-developers/GitPython/releases/tag/<version>`
|
| 265 |
+
3. Commit everything.
|
| 266 |
+
4. Run `git tag -s <version>` to tag the version in Git.
|
| 267 |
+
5. _Optionally_ create and activate a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment). (Then the next step can install `build` and `twine`.)
|
| 268 |
+
6. Run `make release`.
|
| 269 |
+
7. Go to [GitHub Releases](https://github.com/gitpython-developers/GitPython/releases) and publish a new one with the recently pushed tag. Generate the changelog.
|
| 270 |
+
|
| 271 |
+
### Projects using GitPython
|
| 272 |
+
|
| 273 |
+
- [PyDriller](https://github.com/ishepard/pydriller)
|
| 274 |
+
- [Kivy Designer](https://github.com/kivy/kivy-designer)
|
| 275 |
+
- [Prowl](https://github.com/nettitude/Prowl)
|
| 276 |
+
- [Python Taint](https://github.com/python-security/pyt)
|
| 277 |
+
- [Buster](https://github.com/axitkhurana/buster)
|
| 278 |
+
- [git-ftp](https://github.com/ezyang/git-ftp)
|
| 279 |
+
- [Git-Pandas](https://github.com/wdm0006/git-pandas)
|
| 280 |
+
- [PyGitUp](https://github.com/msiemens/PyGitUp)
|
| 281 |
+
- [PyJFuzz](https://github.com/mseclab/PyJFuzz)
|
| 282 |
+
- [Loki](https://github.com/Neo23x0/Loki)
|
| 283 |
+
- [Omniwallet](https://github.com/OmniLayer/omniwallet)
|
| 284 |
+
- [GitViper](https://github.com/BeayemX/GitViper)
|
| 285 |
+
- [Git Gud](https://github.com/bthayer2365/git-gud)
|
| 286 |
+
|
| 287 |
+
### LICENSE
|
| 288 |
+
|
| 289 |
+
[3-Clause BSD License](https://opensource.org/license/bsd-3-clause/), also known as the New BSD License. See the [LICENSE file][license].
|
| 290 |
+
|
| 291 |
+
One file exclusively used for fuzz testing is subject to [a separate license, detailed here](./fuzzing/README.md#license).
|
| 292 |
+
This file is not included in the wheel or sdist packages published by the maintainers of GitPython.
|
| 293 |
+
|
| 294 |
+
[contributing]: https://github.com/gitpython-developers/GitPython/blob/main/CONTRIBUTING.md
|
| 295 |
+
[license]: https://github.com/gitpython-developers/GitPython/blob/main/LICENSE
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/RECORD
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GitPython-3.1.44.dist-info/AUTHORS,sha256=tZ9LuyBks2V2HKTPK7kCmtd9Guu_LyU1oZHvU0NiAok,2334
|
| 2 |
+
GitPython-3.1.44.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
GitPython-3.1.44.dist-info/LICENSE,sha256=hvyUwyGpr7wRUUcTURuv3tIl8lEA3MD3NQ6CvCMbi-s,1503
|
| 4 |
+
GitPython-3.1.44.dist-info/METADATA,sha256=0O_Fr2Y7A-DlPYhlbSxGjblBC2mWkw3USNUhyL80Ip8,13245
|
| 5 |
+
GitPython-3.1.44.dist-info/RECORD,,
|
| 6 |
+
GitPython-3.1.44.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 7 |
+
GitPython-3.1.44.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
| 8 |
+
GitPython-3.1.44.dist-info/top_level.txt,sha256=0hzDuIp8obv624V3GmbqsagBWkk8ohtGU-Bc1PmTT0o,4
|
| 9 |
+
git/__init__.py,sha256=nkQImgv-bWdiZOFDjzN-gbt93FoRHD0nY6_t9LQxy4Y,8899
|
| 10 |
+
git/__pycache__/__init__.cpython-310.pyc,,
|
| 11 |
+
git/__pycache__/cmd.cpython-310.pyc,,
|
| 12 |
+
git/__pycache__/compat.cpython-310.pyc,,
|
| 13 |
+
git/__pycache__/config.cpython-310.pyc,,
|
| 14 |
+
git/__pycache__/db.cpython-310.pyc,,
|
| 15 |
+
git/__pycache__/diff.cpython-310.pyc,,
|
| 16 |
+
git/__pycache__/exc.cpython-310.pyc,,
|
| 17 |
+
git/__pycache__/remote.cpython-310.pyc,,
|
| 18 |
+
git/__pycache__/types.cpython-310.pyc,,
|
| 19 |
+
git/__pycache__/util.cpython-310.pyc,,
|
| 20 |
+
git/cmd.py,sha256=QwiaBy0mFbi9xjRKhRgUVK-_-K6xVdFqh9l0cxPqPSc,67724
|
| 21 |
+
git/compat.py,sha256=y1E6y6O2q5r8clSlr8ZNmuIWG9nmHuehQEsVsmBffs8,4526
|
| 22 |
+
git/config.py,sha256=vTUlK6d8ORqFqjOv4Vbq_Hm-5mp-jOAt1dkq0IdzJ3U,34933
|
| 23 |
+
git/db.py,sha256=vIW9uWSbqu99zbuU2ZDmOhVOv1UPTmxrnqiCtRHCfjE,2368
|
| 24 |
+
git/diff.py,sha256=wmpMCIdMiVOqreGVPOGYyO4gFboGOAicyrvvI7PPjEg,27095
|
| 25 |
+
git/exc.py,sha256=Gc7g1pHpn8OmTse30NHmJVsBJ2CYH8LxaR8y8UA3lIM,7119
|
| 26 |
+
git/index/__init__.py,sha256=i-Nqb8Lufp9aFbmxpQBORmmQnjEVVM1Pn58fsQkyGgQ,406
|
| 27 |
+
git/index/__pycache__/__init__.cpython-310.pyc,,
|
| 28 |
+
git/index/__pycache__/base.cpython-310.pyc,,
|
| 29 |
+
git/index/__pycache__/fun.cpython-310.pyc,,
|
| 30 |
+
git/index/__pycache__/typ.cpython-310.pyc,,
|
| 31 |
+
git/index/__pycache__/util.cpython-310.pyc,,
|
| 32 |
+
git/index/base.py,sha256=nDD7XVLNbgBKpJMrrTVyHBy6NVLWgDkk7oUw6ZOegPc,60808
|
| 33 |
+
git/index/fun.py,sha256=37cA3DBC9vpAnSVu5TGA072SnoF5XZOkOukExwlejHs,16736
|
| 34 |
+
git/index/typ.py,sha256=uuKNwitUw83FhVaLSwo4pY7PHDQudtZTLJrLGym4jcI,6570
|
| 35 |
+
git/index/util.py,sha256=fULi7GPG-MvprKrRCD5c15GNdzku_1E38We0d97WB3A,3659
|
| 36 |
+
git/objects/__init__.py,sha256=O6ZL_olX7e5-8iIbKviRPkVSJxN37WA-EC0q9d48U5Y,637
|
| 37 |
+
git/objects/__pycache__/__init__.cpython-310.pyc,,
|
| 38 |
+
git/objects/__pycache__/base.cpython-310.pyc,,
|
| 39 |
+
git/objects/__pycache__/blob.cpython-310.pyc,,
|
| 40 |
+
git/objects/__pycache__/commit.cpython-310.pyc,,
|
| 41 |
+
git/objects/__pycache__/fun.cpython-310.pyc,,
|
| 42 |
+
git/objects/__pycache__/tag.cpython-310.pyc,,
|
| 43 |
+
git/objects/__pycache__/tree.cpython-310.pyc,,
|
| 44 |
+
git/objects/__pycache__/util.cpython-310.pyc,,
|
| 45 |
+
git/objects/base.py,sha256=0dqNkSRVH0mk0-7ZKIkGBK7iNYrzLTVxwQFUd6CagsE,10277
|
| 46 |
+
git/objects/blob.py,sha256=zwwq0KfOMYeP5J2tW5CQatoLyeqFRlfkxP1Vwx1h07s,1215
|
| 47 |
+
git/objects/commit.py,sha256=GH1_83C9t7RGTukwozTHDgvxYQPRjTHhPDkXJyBbJyo,30553
|
| 48 |
+
git/objects/fun.py,sha256=B4jCqhAjm6Hl79GK58FPzW1H9K6Wc7Tx0rssyWmAcEE,8935
|
| 49 |
+
git/objects/submodule/__init__.py,sha256=6xySp767LVz3UylWgUalntS_nGXRuVzXxDuFAv_Wc2c,303
|
| 50 |
+
git/objects/submodule/__pycache__/__init__.cpython-310.pyc,,
|
| 51 |
+
git/objects/submodule/__pycache__/base.cpython-310.pyc,,
|
| 52 |
+
git/objects/submodule/__pycache__/root.cpython-310.pyc,,
|
| 53 |
+
git/objects/submodule/__pycache__/util.cpython-310.pyc,,
|
| 54 |
+
git/objects/submodule/base.py,sha256=MQ-2xV8JznGwy2hLQv1aeQNgAkhBhgc5tdtClFL3DmE,63901
|
| 55 |
+
git/objects/submodule/root.py,sha256=5eTtYNHasqdPq6q0oDCPr7IaO6uAHL3b4DxMoiO2LhE,20246
|
| 56 |
+
git/objects/submodule/util.py,sha256=sQqAYaiSJdFkZa9NlAuK_wTsMNiS-kkQnQjvIoJtc_o,3509
|
| 57 |
+
git/objects/tag.py,sha256=jAGESnpmTEv-dLakPzheT5ILZFFArcItnXYqfxfDrgc,4441
|
| 58 |
+
git/objects/tree.py,sha256=jJH888SHiP4dGzE-ra1yenQOyya_0C_MkHr06c1gHpM,13849
|
| 59 |
+
git/objects/util.py,sha256=Nlza4zLgdPmr_Yasyvvs6c1rKtW_wMxI6wDmQpQ3ufw,23846
|
| 60 |
+
git/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 61 |
+
git/refs/__init__.py,sha256=DWlJNnsx-4jM_E-VycbP-FZUdn6iWhjnH_uZ_pZXBro,509
|
| 62 |
+
git/refs/__pycache__/__init__.cpython-310.pyc,,
|
| 63 |
+
git/refs/__pycache__/head.cpython-310.pyc,,
|
| 64 |
+
git/refs/__pycache__/log.cpython-310.pyc,,
|
| 65 |
+
git/refs/__pycache__/reference.cpython-310.pyc,,
|
| 66 |
+
git/refs/__pycache__/remote.cpython-310.pyc,,
|
| 67 |
+
git/refs/__pycache__/symbolic.cpython-310.pyc,,
|
| 68 |
+
git/refs/__pycache__/tag.cpython-310.pyc,,
|
| 69 |
+
git/refs/head.py,sha256=SGa3N301HfAi79X6UR5Mcg7mO9TnCH3Bk549kHlJVaQ,10513
|
| 70 |
+
git/refs/log.py,sha256=kXiuAgTo1DIuM_BfbDUk9gQ0YO-mutIMVdHv1_ES90o,12493
|
| 71 |
+
git/refs/reference.py,sha256=l6mhF4YLSEwtjz6b9PpOQH-fkng7EYWMaJhkjn-2jXA,5630
|
| 72 |
+
git/refs/remote.py,sha256=WwqV9T7BbYf3F_WZNUQivu9xktIIKGklCjDpwQrhD-A,2806
|
| 73 |
+
git/refs/symbolic.py,sha256=c8zOwaqzcg-J-rGrpuWdvh8zwMvSUqAHghd4vJoYG_s,34552
|
| 74 |
+
git/refs/tag.py,sha256=kgzV2vhpL4FD2TqHb0BJuMRAHgAvJF-TcoyWlaB-djQ,5010
|
| 75 |
+
git/remote.py,sha256=pYn9dAlz-QwvNMWXD1M57pMPQitthOM86qTRK_cpTqU,46786
|
| 76 |
+
git/repo/__init__.py,sha256=CILSVH36fX_WxVFSjD9o1WF5LgsNedPiJvSngKZqfVU,210
|
| 77 |
+
git/repo/__pycache__/__init__.cpython-310.pyc,,
|
| 78 |
+
git/repo/__pycache__/base.cpython-310.pyc,,
|
| 79 |
+
git/repo/__pycache__/fun.cpython-310.pyc,,
|
| 80 |
+
git/repo/base.py,sha256=0GU6nKNdT8SYjDI5Y5DeZ1zCEX3tHeq1VW2MSpne05g,59891
|
| 81 |
+
git/repo/fun.py,sha256=HSGC0-rqeKKx9fDg7JyQyMZgIwUWn-FnSZR_gRGpG-E,13573
|
| 82 |
+
git/types.py,sha256=MQzIDEOnoueXGsAJF_0MgUc_osH7Eu0Sw3DQofYzCVE,10272
|
| 83 |
+
git/util.py,sha256=2uAv34zZ_827-zJ3-D5ACrVH-4Q4EO_KLUTH23zi2AI,43770
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/REQUESTED
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (75.6.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
vllm/lib/python3.10/site-packages/GitPython-3.1.44.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
git
|
vllm/lib/python3.10/site-packages/dateutil/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
try:
|
| 5 |
+
from ._version import version as __version__
|
| 6 |
+
except ImportError:
|
| 7 |
+
__version__ = 'unknown'
|
| 8 |
+
|
| 9 |
+
__all__ = ['easter', 'parser', 'relativedelta', 'rrule', 'tz',
|
| 10 |
+
'utils', 'zoneinfo']
|
| 11 |
+
|
| 12 |
+
def __getattr__(name):
|
| 13 |
+
import importlib
|
| 14 |
+
|
| 15 |
+
if name in __all__:
|
| 16 |
+
return importlib.import_module("." + name, __name__)
|
| 17 |
+
raise AttributeError(
|
| 18 |
+
"module {!r} has not attribute {!r}".format(__name__, name)
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def __dir__():
|
| 23 |
+
# __dir__ should include all the lazy-importable modules as well.
|
| 24 |
+
return [x for x in globals() if x not in sys.modules] + __all__
|
vllm/lib/python3.10/site-packages/dateutil/_common.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Common code used in multiple modules.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class weekday(object):
|
| 7 |
+
__slots__ = ["weekday", "n"]
|
| 8 |
+
|
| 9 |
+
def __init__(self, weekday, n=None):
|
| 10 |
+
self.weekday = weekday
|
| 11 |
+
self.n = n
|
| 12 |
+
|
| 13 |
+
def __call__(self, n):
|
| 14 |
+
if n == self.n:
|
| 15 |
+
return self
|
| 16 |
+
else:
|
| 17 |
+
return self.__class__(self.weekday, n)
|
| 18 |
+
|
| 19 |
+
def __eq__(self, other):
|
| 20 |
+
try:
|
| 21 |
+
if self.weekday != other.weekday or self.n != other.n:
|
| 22 |
+
return False
|
| 23 |
+
except AttributeError:
|
| 24 |
+
return False
|
| 25 |
+
return True
|
| 26 |
+
|
| 27 |
+
def __hash__(self):
|
| 28 |
+
return hash((
|
| 29 |
+
self.weekday,
|
| 30 |
+
self.n,
|
| 31 |
+
))
|
| 32 |
+
|
| 33 |
+
def __ne__(self, other):
|
| 34 |
+
return not (self == other)
|
| 35 |
+
|
| 36 |
+
def __repr__(self):
|
| 37 |
+
s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
|
| 38 |
+
if not self.n:
|
| 39 |
+
return s
|
| 40 |
+
else:
|
| 41 |
+
return "%s(%+d)" % (s, self.n)
|
| 42 |
+
|
| 43 |
+
# vim:ts=4:sw=4:et
|
vllm/lib/python3.10/site-packages/dateutil/_version.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by setuptools_scm
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
__version__ = version = '2.9.0.post0'
|
| 4 |
+
__version_tuple__ = version_tuple = (2, 9, 0)
|
vllm/lib/python3.10/site-packages/dateutil/easter.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
This module offers a generic Easter computing method for any given year, using
|
| 4 |
+
Western, Orthodox or Julian algorithms.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import datetime
|
| 8 |
+
|
| 9 |
+
__all__ = ["easter", "EASTER_JULIAN", "EASTER_ORTHODOX", "EASTER_WESTERN"]
|
| 10 |
+
|
| 11 |
+
EASTER_JULIAN = 1
|
| 12 |
+
EASTER_ORTHODOX = 2
|
| 13 |
+
EASTER_WESTERN = 3
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def easter(year, method=EASTER_WESTERN):
|
| 17 |
+
"""
|
| 18 |
+
This method was ported from the work done by GM Arts,
|
| 19 |
+
on top of the algorithm by Claus Tondering, which was
|
| 20 |
+
based in part on the algorithm of Ouding (1940), as
|
| 21 |
+
quoted in "Explanatory Supplement to the Astronomical
|
| 22 |
+
Almanac", P. Kenneth Seidelmann, editor.
|
| 23 |
+
|
| 24 |
+
This algorithm implements three different Easter
|
| 25 |
+
calculation methods:
|
| 26 |
+
|
| 27 |
+
1. Original calculation in Julian calendar, valid in
|
| 28 |
+
dates after 326 AD
|
| 29 |
+
2. Original method, with date converted to Gregorian
|
| 30 |
+
calendar, valid in years 1583 to 4099
|
| 31 |
+
3. Revised method, in Gregorian calendar, valid in
|
| 32 |
+
years 1583 to 4099 as well
|
| 33 |
+
|
| 34 |
+
These methods are represented by the constants:
|
| 35 |
+
|
| 36 |
+
* ``EASTER_JULIAN = 1``
|
| 37 |
+
* ``EASTER_ORTHODOX = 2``
|
| 38 |
+
* ``EASTER_WESTERN = 3``
|
| 39 |
+
|
| 40 |
+
The default method is method 3.
|
| 41 |
+
|
| 42 |
+
More about the algorithm may be found at:
|
| 43 |
+
|
| 44 |
+
`GM Arts: Easter Algorithms <http://www.gmarts.org/index.php?go=415>`_
|
| 45 |
+
|
| 46 |
+
and
|
| 47 |
+
|
| 48 |
+
`The Calendar FAQ: Easter <https://www.tondering.dk/claus/cal/easter.php>`_
|
| 49 |
+
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
if not (1 <= method <= 3):
|
| 53 |
+
raise ValueError("invalid method")
|
| 54 |
+
|
| 55 |
+
# g - Golden year - 1
|
| 56 |
+
# c - Century
|
| 57 |
+
# h - (23 - Epact) mod 30
|
| 58 |
+
# i - Number of days from March 21 to Paschal Full Moon
|
| 59 |
+
# j - Weekday for PFM (0=Sunday, etc)
|
| 60 |
+
# p - Number of days from March 21 to Sunday on or before PFM
|
| 61 |
+
# (-6 to 28 methods 1 & 3, to 56 for method 2)
|
| 62 |
+
# e - Extra days to add for method 2 (converting Julian
|
| 63 |
+
# date to Gregorian date)
|
| 64 |
+
|
| 65 |
+
y = year
|
| 66 |
+
g = y % 19
|
| 67 |
+
e = 0
|
| 68 |
+
if method < 3:
|
| 69 |
+
# Old method
|
| 70 |
+
i = (19*g + 15) % 30
|
| 71 |
+
j = (y + y//4 + i) % 7
|
| 72 |
+
if method == 2:
|
| 73 |
+
# Extra dates to convert Julian to Gregorian date
|
| 74 |
+
e = 10
|
| 75 |
+
if y > 1600:
|
| 76 |
+
e = e + y//100 - 16 - (y//100 - 16)//4
|
| 77 |
+
else:
|
| 78 |
+
# New method
|
| 79 |
+
c = y//100
|
| 80 |
+
h = (c - c//4 - (8*c + 13)//25 + 19*g + 15) % 30
|
| 81 |
+
i = h - (h//28)*(1 - (h//28)*(29//(h + 1))*((21 - g)//11))
|
| 82 |
+
j = (y + y//4 + i + 2 - c + c//4) % 7
|
| 83 |
+
|
| 84 |
+
# p can be from -6 to 56 corresponding to dates 22 March to 23 May
|
| 85 |
+
# (later dates apply to method 2, although 23 May never actually occurs)
|
| 86 |
+
p = i - j + e
|
| 87 |
+
d = 1 + (p + 27 + (p + 6)//40) % 31
|
| 88 |
+
m = 3 + (p + 26)//30
|
| 89 |
+
return datetime.date(int(y), int(m), int(d))
|
vllm/lib/python3.10/site-packages/dateutil/relativedelta.py
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
import datetime
|
| 3 |
+
import calendar
|
| 4 |
+
|
| 5 |
+
import operator
|
| 6 |
+
from math import copysign
|
| 7 |
+
|
| 8 |
+
from six import integer_types
|
| 9 |
+
from warnings import warn
|
| 10 |
+
|
| 11 |
+
from ._common import weekday
|
| 12 |
+
|
| 13 |
+
MO, TU, WE, TH, FR, SA, SU = weekdays = tuple(weekday(x) for x in range(7))
|
| 14 |
+
|
| 15 |
+
__all__ = ["relativedelta", "MO", "TU", "WE", "TH", "FR", "SA", "SU"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class relativedelta(object):
|
| 19 |
+
"""
|
| 20 |
+
The relativedelta type is designed to be applied to an existing datetime and
|
| 21 |
+
can replace specific components of that datetime, or represents an interval
|
| 22 |
+
of time.
|
| 23 |
+
|
| 24 |
+
It is based on the specification of the excellent work done by M.-A. Lemburg
|
| 25 |
+
in his
|
| 26 |
+
`mx.DateTime <https://www.egenix.com/products/python/mxBase/mxDateTime/>`_ extension.
|
| 27 |
+
However, notice that this type does *NOT* implement the same algorithm as
|
| 28 |
+
his work. Do *NOT* expect it to behave like mx.DateTime's counterpart.
|
| 29 |
+
|
| 30 |
+
There are two different ways to build a relativedelta instance. The
|
| 31 |
+
first one is passing it two date/datetime classes::
|
| 32 |
+
|
| 33 |
+
relativedelta(datetime1, datetime2)
|
| 34 |
+
|
| 35 |
+
The second one is passing it any number of the following keyword arguments::
|
| 36 |
+
|
| 37 |
+
relativedelta(arg1=x,arg2=y,arg3=z...)
|
| 38 |
+
|
| 39 |
+
year, month, day, hour, minute, second, microsecond:
|
| 40 |
+
Absolute information (argument is singular); adding or subtracting a
|
| 41 |
+
relativedelta with absolute information does not perform an arithmetic
|
| 42 |
+
operation, but rather REPLACES the corresponding value in the
|
| 43 |
+
original datetime with the value(s) in relativedelta.
|
| 44 |
+
|
| 45 |
+
years, months, weeks, days, hours, minutes, seconds, microseconds:
|
| 46 |
+
Relative information, may be negative (argument is plural); adding
|
| 47 |
+
or subtracting a relativedelta with relative information performs
|
| 48 |
+
the corresponding arithmetic operation on the original datetime value
|
| 49 |
+
with the information in the relativedelta.
|
| 50 |
+
|
| 51 |
+
weekday:
|
| 52 |
+
One of the weekday instances (MO, TU, etc) available in the
|
| 53 |
+
relativedelta module. These instances may receive a parameter N,
|
| 54 |
+
specifying the Nth weekday, which could be positive or negative
|
| 55 |
+
(like MO(+1) or MO(-2)). Not specifying it is the same as specifying
|
| 56 |
+
+1. You can also use an integer, where 0=MO. This argument is always
|
| 57 |
+
relative e.g. if the calculated date is already Monday, using MO(1)
|
| 58 |
+
or MO(-1) won't change the day. To effectively make it absolute, use
|
| 59 |
+
it in combination with the day argument (e.g. day=1, MO(1) for first
|
| 60 |
+
Monday of the month).
|
| 61 |
+
|
| 62 |
+
leapdays:
|
| 63 |
+
Will add given days to the date found, if year is a leap
|
| 64 |
+
year, and the date found is post 28 of february.
|
| 65 |
+
|
| 66 |
+
yearday, nlyearday:
|
| 67 |
+
Set the yearday or the non-leap year day (jump leap days).
|
| 68 |
+
These are converted to day/month/leapdays information.
|
| 69 |
+
|
| 70 |
+
There are relative and absolute forms of the keyword
|
| 71 |
+
arguments. The plural is relative, and the singular is
|
| 72 |
+
absolute. For each argument in the order below, the absolute form
|
| 73 |
+
is applied first (by setting each attribute to that value) and
|
| 74 |
+
then the relative form (by adding the value to the attribute).
|
| 75 |
+
|
| 76 |
+
The order of attributes considered when this relativedelta is
|
| 77 |
+
added to a datetime is:
|
| 78 |
+
|
| 79 |
+
1. Year
|
| 80 |
+
2. Month
|
| 81 |
+
3. Day
|
| 82 |
+
4. Hours
|
| 83 |
+
5. Minutes
|
| 84 |
+
6. Seconds
|
| 85 |
+
7. Microseconds
|
| 86 |
+
|
| 87 |
+
Finally, weekday is applied, using the rule described above.
|
| 88 |
+
|
| 89 |
+
For example
|
| 90 |
+
|
| 91 |
+
>>> from datetime import datetime
|
| 92 |
+
>>> from dateutil.relativedelta import relativedelta, MO
|
| 93 |
+
>>> dt = datetime(2018, 4, 9, 13, 37, 0)
|
| 94 |
+
>>> delta = relativedelta(hours=25, day=1, weekday=MO(1))
|
| 95 |
+
>>> dt + delta
|
| 96 |
+
datetime.datetime(2018, 4, 2, 14, 37)
|
| 97 |
+
|
| 98 |
+
First, the day is set to 1 (the first of the month), then 25 hours
|
| 99 |
+
are added, to get to the 2nd day and 14th hour, finally the
|
| 100 |
+
weekday is applied, but since the 2nd is already a Monday there is
|
| 101 |
+
no effect.
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
def __init__(self, dt1=None, dt2=None,
|
| 106 |
+
years=0, months=0, days=0, leapdays=0, weeks=0,
|
| 107 |
+
hours=0, minutes=0, seconds=0, microseconds=0,
|
| 108 |
+
year=None, month=None, day=None, weekday=None,
|
| 109 |
+
yearday=None, nlyearday=None,
|
| 110 |
+
hour=None, minute=None, second=None, microsecond=None):
|
| 111 |
+
|
| 112 |
+
if dt1 and dt2:
|
| 113 |
+
# datetime is a subclass of date. So both must be date
|
| 114 |
+
if not (isinstance(dt1, datetime.date) and
|
| 115 |
+
isinstance(dt2, datetime.date)):
|
| 116 |
+
raise TypeError("relativedelta only diffs datetime/date")
|
| 117 |
+
|
| 118 |
+
# We allow two dates, or two datetimes, so we coerce them to be
|
| 119 |
+
# of the same type
|
| 120 |
+
if (isinstance(dt1, datetime.datetime) !=
|
| 121 |
+
isinstance(dt2, datetime.datetime)):
|
| 122 |
+
if not isinstance(dt1, datetime.datetime):
|
| 123 |
+
dt1 = datetime.datetime.fromordinal(dt1.toordinal())
|
| 124 |
+
elif not isinstance(dt2, datetime.datetime):
|
| 125 |
+
dt2 = datetime.datetime.fromordinal(dt2.toordinal())
|
| 126 |
+
|
| 127 |
+
self.years = 0
|
| 128 |
+
self.months = 0
|
| 129 |
+
self.days = 0
|
| 130 |
+
self.leapdays = 0
|
| 131 |
+
self.hours = 0
|
| 132 |
+
self.minutes = 0
|
| 133 |
+
self.seconds = 0
|
| 134 |
+
self.microseconds = 0
|
| 135 |
+
self.year = None
|
| 136 |
+
self.month = None
|
| 137 |
+
self.day = None
|
| 138 |
+
self.weekday = None
|
| 139 |
+
self.hour = None
|
| 140 |
+
self.minute = None
|
| 141 |
+
self.second = None
|
| 142 |
+
self.microsecond = None
|
| 143 |
+
self._has_time = 0
|
| 144 |
+
|
| 145 |
+
# Get year / month delta between the two
|
| 146 |
+
months = (dt1.year - dt2.year) * 12 + (dt1.month - dt2.month)
|
| 147 |
+
self._set_months(months)
|
| 148 |
+
|
| 149 |
+
# Remove the year/month delta so the timedelta is just well-defined
|
| 150 |
+
# time units (seconds, days and microseconds)
|
| 151 |
+
dtm = self.__radd__(dt2)
|
| 152 |
+
|
| 153 |
+
# If we've overshot our target, make an adjustment
|
| 154 |
+
if dt1 < dt2:
|
| 155 |
+
compare = operator.gt
|
| 156 |
+
increment = 1
|
| 157 |
+
else:
|
| 158 |
+
compare = operator.lt
|
| 159 |
+
increment = -1
|
| 160 |
+
|
| 161 |
+
while compare(dt1, dtm):
|
| 162 |
+
months += increment
|
| 163 |
+
self._set_months(months)
|
| 164 |
+
dtm = self.__radd__(dt2)
|
| 165 |
+
|
| 166 |
+
# Get the timedelta between the "months-adjusted" date and dt1
|
| 167 |
+
delta = dt1 - dtm
|
| 168 |
+
self.seconds = delta.seconds + delta.days * 86400
|
| 169 |
+
self.microseconds = delta.microseconds
|
| 170 |
+
else:
|
| 171 |
+
# Check for non-integer values in integer-only quantities
|
| 172 |
+
if any(x is not None and x != int(x) for x in (years, months)):
|
| 173 |
+
raise ValueError("Non-integer years and months are "
|
| 174 |
+
"ambiguous and not currently supported.")
|
| 175 |
+
|
| 176 |
+
# Relative information
|
| 177 |
+
self.years = int(years)
|
| 178 |
+
self.months = int(months)
|
| 179 |
+
self.days = days + weeks * 7
|
| 180 |
+
self.leapdays = leapdays
|
| 181 |
+
self.hours = hours
|
| 182 |
+
self.minutes = minutes
|
| 183 |
+
self.seconds = seconds
|
| 184 |
+
self.microseconds = microseconds
|
| 185 |
+
|
| 186 |
+
# Absolute information
|
| 187 |
+
self.year = year
|
| 188 |
+
self.month = month
|
| 189 |
+
self.day = day
|
| 190 |
+
self.hour = hour
|
| 191 |
+
self.minute = minute
|
| 192 |
+
self.second = second
|
| 193 |
+
self.microsecond = microsecond
|
| 194 |
+
|
| 195 |
+
if any(x is not None and int(x) != x
|
| 196 |
+
for x in (year, month, day, hour,
|
| 197 |
+
minute, second, microsecond)):
|
| 198 |
+
# For now we'll deprecate floats - later it'll be an error.
|
| 199 |
+
warn("Non-integer value passed as absolute information. " +
|
| 200 |
+
"This is not a well-defined condition and will raise " +
|
| 201 |
+
"errors in future versions.", DeprecationWarning)
|
| 202 |
+
|
| 203 |
+
if isinstance(weekday, integer_types):
|
| 204 |
+
self.weekday = weekdays[weekday]
|
| 205 |
+
else:
|
| 206 |
+
self.weekday = weekday
|
| 207 |
+
|
| 208 |
+
yday = 0
|
| 209 |
+
if nlyearday:
|
| 210 |
+
yday = nlyearday
|
| 211 |
+
elif yearday:
|
| 212 |
+
yday = yearday
|
| 213 |
+
if yearday > 59:
|
| 214 |
+
self.leapdays = -1
|
| 215 |
+
if yday:
|
| 216 |
+
ydayidx = [31, 59, 90, 120, 151, 181, 212,
|
| 217 |
+
243, 273, 304, 334, 366]
|
| 218 |
+
for idx, ydays in enumerate(ydayidx):
|
| 219 |
+
if yday <= ydays:
|
| 220 |
+
self.month = idx+1
|
| 221 |
+
if idx == 0:
|
| 222 |
+
self.day = yday
|
| 223 |
+
else:
|
| 224 |
+
self.day = yday-ydayidx[idx-1]
|
| 225 |
+
break
|
| 226 |
+
else:
|
| 227 |
+
raise ValueError("invalid year day (%d)" % yday)
|
| 228 |
+
|
| 229 |
+
self._fix()
|
| 230 |
+
|
| 231 |
+
def _fix(self):
|
| 232 |
+
if abs(self.microseconds) > 999999:
|
| 233 |
+
s = _sign(self.microseconds)
|
| 234 |
+
div, mod = divmod(self.microseconds * s, 1000000)
|
| 235 |
+
self.microseconds = mod * s
|
| 236 |
+
self.seconds += div * s
|
| 237 |
+
if abs(self.seconds) > 59:
|
| 238 |
+
s = _sign(self.seconds)
|
| 239 |
+
div, mod = divmod(self.seconds * s, 60)
|
| 240 |
+
self.seconds = mod * s
|
| 241 |
+
self.minutes += div * s
|
| 242 |
+
if abs(self.minutes) > 59:
|
| 243 |
+
s = _sign(self.minutes)
|
| 244 |
+
div, mod = divmod(self.minutes * s, 60)
|
| 245 |
+
self.minutes = mod * s
|
| 246 |
+
self.hours += div * s
|
| 247 |
+
if abs(self.hours) > 23:
|
| 248 |
+
s = _sign(self.hours)
|
| 249 |
+
div, mod = divmod(self.hours * s, 24)
|
| 250 |
+
self.hours = mod * s
|
| 251 |
+
self.days += div * s
|
| 252 |
+
if abs(self.months) > 11:
|
| 253 |
+
s = _sign(self.months)
|
| 254 |
+
div, mod = divmod(self.months * s, 12)
|
| 255 |
+
self.months = mod * s
|
| 256 |
+
self.years += div * s
|
| 257 |
+
if (self.hours or self.minutes or self.seconds or self.microseconds
|
| 258 |
+
or self.hour is not None or self.minute is not None or
|
| 259 |
+
self.second is not None or self.microsecond is not None):
|
| 260 |
+
self._has_time = 1
|
| 261 |
+
else:
|
| 262 |
+
self._has_time = 0
|
| 263 |
+
|
| 264 |
+
@property
|
| 265 |
+
def weeks(self):
|
| 266 |
+
return int(self.days / 7.0)
|
| 267 |
+
|
| 268 |
+
@weeks.setter
|
| 269 |
+
def weeks(self, value):
|
| 270 |
+
self.days = self.days - (self.weeks * 7) + value * 7
|
| 271 |
+
|
| 272 |
+
def _set_months(self, months):
|
| 273 |
+
self.months = months
|
| 274 |
+
if abs(self.months) > 11:
|
| 275 |
+
s = _sign(self.months)
|
| 276 |
+
div, mod = divmod(self.months * s, 12)
|
| 277 |
+
self.months = mod * s
|
| 278 |
+
self.years = div * s
|
| 279 |
+
else:
|
| 280 |
+
self.years = 0
|
| 281 |
+
|
| 282 |
+
def normalized(self):
|
| 283 |
+
"""
|
| 284 |
+
Return a version of this object represented entirely using integer
|
| 285 |
+
values for the relative attributes.
|
| 286 |
+
|
| 287 |
+
>>> relativedelta(days=1.5, hours=2).normalized()
|
| 288 |
+
relativedelta(days=+1, hours=+14)
|
| 289 |
+
|
| 290 |
+
:return:
|
| 291 |
+
Returns a :class:`dateutil.relativedelta.relativedelta` object.
|
| 292 |
+
"""
|
| 293 |
+
# Cascade remainders down (rounding each to roughly nearest microsecond)
|
| 294 |
+
days = int(self.days)
|
| 295 |
+
|
| 296 |
+
hours_f = round(self.hours + 24 * (self.days - days), 11)
|
| 297 |
+
hours = int(hours_f)
|
| 298 |
+
|
| 299 |
+
minutes_f = round(self.minutes + 60 * (hours_f - hours), 10)
|
| 300 |
+
minutes = int(minutes_f)
|
| 301 |
+
|
| 302 |
+
seconds_f = round(self.seconds + 60 * (minutes_f - minutes), 8)
|
| 303 |
+
seconds = int(seconds_f)
|
| 304 |
+
|
| 305 |
+
microseconds = round(self.microseconds + 1e6 * (seconds_f - seconds))
|
| 306 |
+
|
| 307 |
+
# Constructor carries overflow back up with call to _fix()
|
| 308 |
+
return self.__class__(years=self.years, months=self.months,
|
| 309 |
+
days=days, hours=hours, minutes=minutes,
|
| 310 |
+
seconds=seconds, microseconds=microseconds,
|
| 311 |
+
leapdays=self.leapdays, year=self.year,
|
| 312 |
+
month=self.month, day=self.day,
|
| 313 |
+
weekday=self.weekday, hour=self.hour,
|
| 314 |
+
minute=self.minute, second=self.second,
|
| 315 |
+
microsecond=self.microsecond)
|
| 316 |
+
|
| 317 |
+
def __add__(self, other):
|
| 318 |
+
if isinstance(other, relativedelta):
|
| 319 |
+
return self.__class__(years=other.years + self.years,
|
| 320 |
+
months=other.months + self.months,
|
| 321 |
+
days=other.days + self.days,
|
| 322 |
+
hours=other.hours + self.hours,
|
| 323 |
+
minutes=other.minutes + self.minutes,
|
| 324 |
+
seconds=other.seconds + self.seconds,
|
| 325 |
+
microseconds=(other.microseconds +
|
| 326 |
+
self.microseconds),
|
| 327 |
+
leapdays=other.leapdays or self.leapdays,
|
| 328 |
+
year=(other.year if other.year is not None
|
| 329 |
+
else self.year),
|
| 330 |
+
month=(other.month if other.month is not None
|
| 331 |
+
else self.month),
|
| 332 |
+
day=(other.day if other.day is not None
|
| 333 |
+
else self.day),
|
| 334 |
+
weekday=(other.weekday if other.weekday is not None
|
| 335 |
+
else self.weekday),
|
| 336 |
+
hour=(other.hour if other.hour is not None
|
| 337 |
+
else self.hour),
|
| 338 |
+
minute=(other.minute if other.minute is not None
|
| 339 |
+
else self.minute),
|
| 340 |
+
second=(other.second if other.second is not None
|
| 341 |
+
else self.second),
|
| 342 |
+
microsecond=(other.microsecond if other.microsecond
|
| 343 |
+
is not None else
|
| 344 |
+
self.microsecond))
|
| 345 |
+
if isinstance(other, datetime.timedelta):
|
| 346 |
+
return self.__class__(years=self.years,
|
| 347 |
+
months=self.months,
|
| 348 |
+
days=self.days + other.days,
|
| 349 |
+
hours=self.hours,
|
| 350 |
+
minutes=self.minutes,
|
| 351 |
+
seconds=self.seconds + other.seconds,
|
| 352 |
+
microseconds=self.microseconds + other.microseconds,
|
| 353 |
+
leapdays=self.leapdays,
|
| 354 |
+
year=self.year,
|
| 355 |
+
month=self.month,
|
| 356 |
+
day=self.day,
|
| 357 |
+
weekday=self.weekday,
|
| 358 |
+
hour=self.hour,
|
| 359 |
+
minute=self.minute,
|
| 360 |
+
second=self.second,
|
| 361 |
+
microsecond=self.microsecond)
|
| 362 |
+
if not isinstance(other, datetime.date):
|
| 363 |
+
return NotImplemented
|
| 364 |
+
elif self._has_time and not isinstance(other, datetime.datetime):
|
| 365 |
+
other = datetime.datetime.fromordinal(other.toordinal())
|
| 366 |
+
year = (self.year or other.year)+self.years
|
| 367 |
+
month = self.month or other.month
|
| 368 |
+
if self.months:
|
| 369 |
+
assert 1 <= abs(self.months) <= 12
|
| 370 |
+
month += self.months
|
| 371 |
+
if month > 12:
|
| 372 |
+
year += 1
|
| 373 |
+
month -= 12
|
| 374 |
+
elif month < 1:
|
| 375 |
+
year -= 1
|
| 376 |
+
month += 12
|
| 377 |
+
day = min(calendar.monthrange(year, month)[1],
|
| 378 |
+
self.day or other.day)
|
| 379 |
+
repl = {"year": year, "month": month, "day": day}
|
| 380 |
+
for attr in ["hour", "minute", "second", "microsecond"]:
|
| 381 |
+
value = getattr(self, attr)
|
| 382 |
+
if value is not None:
|
| 383 |
+
repl[attr] = value
|
| 384 |
+
days = self.days
|
| 385 |
+
if self.leapdays and month > 2 and calendar.isleap(year):
|
| 386 |
+
days += self.leapdays
|
| 387 |
+
ret = (other.replace(**repl)
|
| 388 |
+
+ datetime.timedelta(days=days,
|
| 389 |
+
hours=self.hours,
|
| 390 |
+
minutes=self.minutes,
|
| 391 |
+
seconds=self.seconds,
|
| 392 |
+
microseconds=self.microseconds))
|
| 393 |
+
if self.weekday:
|
| 394 |
+
weekday, nth = self.weekday.weekday, self.weekday.n or 1
|
| 395 |
+
jumpdays = (abs(nth) - 1) * 7
|
| 396 |
+
if nth > 0:
|
| 397 |
+
jumpdays += (7 - ret.weekday() + weekday) % 7
|
| 398 |
+
else:
|
| 399 |
+
jumpdays += (ret.weekday() - weekday) % 7
|
| 400 |
+
jumpdays *= -1
|
| 401 |
+
ret += datetime.timedelta(days=jumpdays)
|
| 402 |
+
return ret
|
| 403 |
+
|
| 404 |
+
def __radd__(self, other):
|
| 405 |
+
return self.__add__(other)
|
| 406 |
+
|
| 407 |
+
def __rsub__(self, other):
|
| 408 |
+
return self.__neg__().__radd__(other)
|
| 409 |
+
|
| 410 |
+
def __sub__(self, other):
|
| 411 |
+
if not isinstance(other, relativedelta):
|
| 412 |
+
return NotImplemented # In case the other object defines __rsub__
|
| 413 |
+
return self.__class__(years=self.years - other.years,
|
| 414 |
+
months=self.months - other.months,
|
| 415 |
+
days=self.days - other.days,
|
| 416 |
+
hours=self.hours - other.hours,
|
| 417 |
+
minutes=self.minutes - other.minutes,
|
| 418 |
+
seconds=self.seconds - other.seconds,
|
| 419 |
+
microseconds=self.microseconds - other.microseconds,
|
| 420 |
+
leapdays=self.leapdays or other.leapdays,
|
| 421 |
+
year=(self.year if self.year is not None
|
| 422 |
+
else other.year),
|
| 423 |
+
month=(self.month if self.month is not None else
|
| 424 |
+
other.month),
|
| 425 |
+
day=(self.day if self.day is not None else
|
| 426 |
+
other.day),
|
| 427 |
+
weekday=(self.weekday if self.weekday is not None else
|
| 428 |
+
other.weekday),
|
| 429 |
+
hour=(self.hour if self.hour is not None else
|
| 430 |
+
other.hour),
|
| 431 |
+
minute=(self.minute if self.minute is not None else
|
| 432 |
+
other.minute),
|
| 433 |
+
second=(self.second if self.second is not None else
|
| 434 |
+
other.second),
|
| 435 |
+
microsecond=(self.microsecond if self.microsecond
|
| 436 |
+
is not None else
|
| 437 |
+
other.microsecond))
|
| 438 |
+
|
| 439 |
+
def __abs__(self):
|
| 440 |
+
return self.__class__(years=abs(self.years),
|
| 441 |
+
months=abs(self.months),
|
| 442 |
+
days=abs(self.days),
|
| 443 |
+
hours=abs(self.hours),
|
| 444 |
+
minutes=abs(self.minutes),
|
| 445 |
+
seconds=abs(self.seconds),
|
| 446 |
+
microseconds=abs(self.microseconds),
|
| 447 |
+
leapdays=self.leapdays,
|
| 448 |
+
year=self.year,
|
| 449 |
+
month=self.month,
|
| 450 |
+
day=self.day,
|
| 451 |
+
weekday=self.weekday,
|
| 452 |
+
hour=self.hour,
|
| 453 |
+
minute=self.minute,
|
| 454 |
+
second=self.second,
|
| 455 |
+
microsecond=self.microsecond)
|
| 456 |
+
|
| 457 |
+
def __neg__(self):
|
| 458 |
+
return self.__class__(years=-self.years,
|
| 459 |
+
months=-self.months,
|
| 460 |
+
days=-self.days,
|
| 461 |
+
hours=-self.hours,
|
| 462 |
+
minutes=-self.minutes,
|
| 463 |
+
seconds=-self.seconds,
|
| 464 |
+
microseconds=-self.microseconds,
|
| 465 |
+
leapdays=self.leapdays,
|
| 466 |
+
year=self.year,
|
| 467 |
+
month=self.month,
|
| 468 |
+
day=self.day,
|
| 469 |
+
weekday=self.weekday,
|
| 470 |
+
hour=self.hour,
|
| 471 |
+
minute=self.minute,
|
| 472 |
+
second=self.second,
|
| 473 |
+
microsecond=self.microsecond)
|
| 474 |
+
|
| 475 |
+
def __bool__(self):
|
| 476 |
+
return not (not self.years and
|
| 477 |
+
not self.months and
|
| 478 |
+
not self.days and
|
| 479 |
+
not self.hours and
|
| 480 |
+
not self.minutes and
|
| 481 |
+
not self.seconds and
|
| 482 |
+
not self.microseconds and
|
| 483 |
+
not self.leapdays and
|
| 484 |
+
self.year is None and
|
| 485 |
+
self.month is None and
|
| 486 |
+
self.day is None and
|
| 487 |
+
self.weekday is None and
|
| 488 |
+
self.hour is None and
|
| 489 |
+
self.minute is None and
|
| 490 |
+
self.second is None and
|
| 491 |
+
self.microsecond is None)
|
| 492 |
+
# Compatibility with Python 2.x
|
| 493 |
+
__nonzero__ = __bool__
|
| 494 |
+
|
| 495 |
+
def __mul__(self, other):
|
| 496 |
+
try:
|
| 497 |
+
f = float(other)
|
| 498 |
+
except TypeError:
|
| 499 |
+
return NotImplemented
|
| 500 |
+
|
| 501 |
+
return self.__class__(years=int(self.years * f),
|
| 502 |
+
months=int(self.months * f),
|
| 503 |
+
days=int(self.days * f),
|
| 504 |
+
hours=int(self.hours * f),
|
| 505 |
+
minutes=int(self.minutes * f),
|
| 506 |
+
seconds=int(self.seconds * f),
|
| 507 |
+
microseconds=int(self.microseconds * f),
|
| 508 |
+
leapdays=self.leapdays,
|
| 509 |
+
year=self.year,
|
| 510 |
+
month=self.month,
|
| 511 |
+
day=self.day,
|
| 512 |
+
weekday=self.weekday,
|
| 513 |
+
hour=self.hour,
|
| 514 |
+
minute=self.minute,
|
| 515 |
+
second=self.second,
|
| 516 |
+
microsecond=self.microsecond)
|
| 517 |
+
|
| 518 |
+
__rmul__ = __mul__
|
| 519 |
+
|
| 520 |
+
def __eq__(self, other):
|
| 521 |
+
if not isinstance(other, relativedelta):
|
| 522 |
+
return NotImplemented
|
| 523 |
+
if self.weekday or other.weekday:
|
| 524 |
+
if not self.weekday or not other.weekday:
|
| 525 |
+
return False
|
| 526 |
+
if self.weekday.weekday != other.weekday.weekday:
|
| 527 |
+
return False
|
| 528 |
+
n1, n2 = self.weekday.n, other.weekday.n
|
| 529 |
+
if n1 != n2 and not ((not n1 or n1 == 1) and (not n2 or n2 == 1)):
|
| 530 |
+
return False
|
| 531 |
+
return (self.years == other.years and
|
| 532 |
+
self.months == other.months and
|
| 533 |
+
self.days == other.days and
|
| 534 |
+
self.hours == other.hours and
|
| 535 |
+
self.minutes == other.minutes and
|
| 536 |
+
self.seconds == other.seconds and
|
| 537 |
+
self.microseconds == other.microseconds and
|
| 538 |
+
self.leapdays == other.leapdays and
|
| 539 |
+
self.year == other.year and
|
| 540 |
+
self.month == other.month and
|
| 541 |
+
self.day == other.day and
|
| 542 |
+
self.hour == other.hour and
|
| 543 |
+
self.minute == other.minute and
|
| 544 |
+
self.second == other.second and
|
| 545 |
+
self.microsecond == other.microsecond)
|
| 546 |
+
|
| 547 |
+
def __hash__(self):
|
| 548 |
+
return hash((
|
| 549 |
+
self.weekday,
|
| 550 |
+
self.years,
|
| 551 |
+
self.months,
|
| 552 |
+
self.days,
|
| 553 |
+
self.hours,
|
| 554 |
+
self.minutes,
|
| 555 |
+
self.seconds,
|
| 556 |
+
self.microseconds,
|
| 557 |
+
self.leapdays,
|
| 558 |
+
self.year,
|
| 559 |
+
self.month,
|
| 560 |
+
self.day,
|
| 561 |
+
self.hour,
|
| 562 |
+
self.minute,
|
| 563 |
+
self.second,
|
| 564 |
+
self.microsecond,
|
| 565 |
+
))
|
| 566 |
+
|
| 567 |
+
def __ne__(self, other):
|
| 568 |
+
return not self.__eq__(other)
|
| 569 |
+
|
| 570 |
+
def __div__(self, other):
|
| 571 |
+
try:
|
| 572 |
+
reciprocal = 1 / float(other)
|
| 573 |
+
except TypeError:
|
| 574 |
+
return NotImplemented
|
| 575 |
+
|
| 576 |
+
return self.__mul__(reciprocal)
|
| 577 |
+
|
| 578 |
+
__truediv__ = __div__
|
| 579 |
+
|
| 580 |
+
def __repr__(self):
|
| 581 |
+
l = []
|
| 582 |
+
for attr in ["years", "months", "days", "leapdays",
|
| 583 |
+
"hours", "minutes", "seconds", "microseconds"]:
|
| 584 |
+
value = getattr(self, attr)
|
| 585 |
+
if value:
|
| 586 |
+
l.append("{attr}={value:+g}".format(attr=attr, value=value))
|
| 587 |
+
for attr in ["year", "month", "day", "weekday",
|
| 588 |
+
"hour", "minute", "second", "microsecond"]:
|
| 589 |
+
value = getattr(self, attr)
|
| 590 |
+
if value is not None:
|
| 591 |
+
l.append("{attr}={value}".format(attr=attr, value=repr(value)))
|
| 592 |
+
return "{classname}({attrs})".format(classname=self.__class__.__name__,
|
| 593 |
+
attrs=", ".join(l))
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
def _sign(x):
|
| 597 |
+
return int(copysign(1, x))
|
| 598 |
+
|
| 599 |
+
# vim:ts=4:sw=4:et
|
vllm/lib/python3.10/site-packages/dateutil/rrule.py
ADDED
|
@@ -0,0 +1,1737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
The rrule module offers a small, complete, and very fast, implementation of
|
| 4 |
+
the recurrence rules documented in the
|
| 5 |
+
`iCalendar RFC <https://tools.ietf.org/html/rfc5545>`_,
|
| 6 |
+
including support for caching of results.
|
| 7 |
+
"""
|
| 8 |
+
import calendar
|
| 9 |
+
import datetime
|
| 10 |
+
import heapq
|
| 11 |
+
import itertools
|
| 12 |
+
import re
|
| 13 |
+
import sys
|
| 14 |
+
from functools import wraps
|
| 15 |
+
# For warning about deprecation of until and count
|
| 16 |
+
from warnings import warn
|
| 17 |
+
|
| 18 |
+
from six import advance_iterator, integer_types
|
| 19 |
+
|
| 20 |
+
from six.moves import _thread, range
|
| 21 |
+
|
| 22 |
+
from ._common import weekday as weekdaybase
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
from math import gcd
|
| 26 |
+
except ImportError:
|
| 27 |
+
from fractions import gcd
|
| 28 |
+
|
| 29 |
+
__all__ = ["rrule", "rruleset", "rrulestr",
|
| 30 |
+
"YEARLY", "MONTHLY", "WEEKLY", "DAILY",
|
| 31 |
+
"HOURLY", "MINUTELY", "SECONDLY",
|
| 32 |
+
"MO", "TU", "WE", "TH", "FR", "SA", "SU"]
|
| 33 |
+
|
| 34 |
+
# Every mask is 7 days longer to handle cross-year weekly periods.
|
| 35 |
+
M366MASK = tuple([1]*31+[2]*29+[3]*31+[4]*30+[5]*31+[6]*30 +
|
| 36 |
+
[7]*31+[8]*31+[9]*30+[10]*31+[11]*30+[12]*31+[1]*7)
|
| 37 |
+
M365MASK = list(M366MASK)
|
| 38 |
+
M29, M30, M31 = list(range(1, 30)), list(range(1, 31)), list(range(1, 32))
|
| 39 |
+
MDAY366MASK = tuple(M31+M29+M31+M30+M31+M30+M31+M31+M30+M31+M30+M31+M31[:7])
|
| 40 |
+
MDAY365MASK = list(MDAY366MASK)
|
| 41 |
+
M29, M30, M31 = list(range(-29, 0)), list(range(-30, 0)), list(range(-31, 0))
|
| 42 |
+
NMDAY366MASK = tuple(M31+M29+M31+M30+M31+M30+M31+M31+M30+M31+M30+M31+M31[:7])
|
| 43 |
+
NMDAY365MASK = list(NMDAY366MASK)
|
| 44 |
+
M366RANGE = (0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366)
|
| 45 |
+
M365RANGE = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365)
|
| 46 |
+
WDAYMASK = [0, 1, 2, 3, 4, 5, 6]*55
|
| 47 |
+
del M29, M30, M31, M365MASK[59], MDAY365MASK[59], NMDAY365MASK[31]
|
| 48 |
+
MDAY365MASK = tuple(MDAY365MASK)
|
| 49 |
+
M365MASK = tuple(M365MASK)
|
| 50 |
+
|
| 51 |
+
FREQNAMES = ['YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY', 'HOURLY', 'MINUTELY', 'SECONDLY']
|
| 52 |
+
|
| 53 |
+
(YEARLY,
|
| 54 |
+
MONTHLY,
|
| 55 |
+
WEEKLY,
|
| 56 |
+
DAILY,
|
| 57 |
+
HOURLY,
|
| 58 |
+
MINUTELY,
|
| 59 |
+
SECONDLY) = list(range(7))
|
| 60 |
+
|
| 61 |
+
# Imported on demand.
|
| 62 |
+
easter = None
|
| 63 |
+
parser = None
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class weekday(weekdaybase):
|
| 67 |
+
"""
|
| 68 |
+
This version of weekday does not allow n = 0.
|
| 69 |
+
"""
|
| 70 |
+
def __init__(self, wkday, n=None):
|
| 71 |
+
if n == 0:
|
| 72 |
+
raise ValueError("Can't create weekday with n==0")
|
| 73 |
+
|
| 74 |
+
super(weekday, self).__init__(wkday, n)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
MO, TU, WE, TH, FR, SA, SU = weekdays = tuple(weekday(x) for x in range(7))
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _invalidates_cache(f):
|
| 81 |
+
"""
|
| 82 |
+
Decorator for rruleset methods which may invalidate the
|
| 83 |
+
cached length.
|
| 84 |
+
"""
|
| 85 |
+
@wraps(f)
|
| 86 |
+
def inner_func(self, *args, **kwargs):
|
| 87 |
+
rv = f(self, *args, **kwargs)
|
| 88 |
+
self._invalidate_cache()
|
| 89 |
+
return rv
|
| 90 |
+
|
| 91 |
+
return inner_func
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class rrulebase(object):
|
| 95 |
+
def __init__(self, cache=False):
|
| 96 |
+
if cache:
|
| 97 |
+
self._cache = []
|
| 98 |
+
self._cache_lock = _thread.allocate_lock()
|
| 99 |
+
self._invalidate_cache()
|
| 100 |
+
else:
|
| 101 |
+
self._cache = None
|
| 102 |
+
self._cache_complete = False
|
| 103 |
+
self._len = None
|
| 104 |
+
|
| 105 |
+
def __iter__(self):
|
| 106 |
+
if self._cache_complete:
|
| 107 |
+
return iter(self._cache)
|
| 108 |
+
elif self._cache is None:
|
| 109 |
+
return self._iter()
|
| 110 |
+
else:
|
| 111 |
+
return self._iter_cached()
|
| 112 |
+
|
| 113 |
+
def _invalidate_cache(self):
|
| 114 |
+
if self._cache is not None:
|
| 115 |
+
self._cache = []
|
| 116 |
+
self._cache_complete = False
|
| 117 |
+
self._cache_gen = self._iter()
|
| 118 |
+
|
| 119 |
+
if self._cache_lock.locked():
|
| 120 |
+
self._cache_lock.release()
|
| 121 |
+
|
| 122 |
+
self._len = None
|
| 123 |
+
|
| 124 |
+
def _iter_cached(self):
|
| 125 |
+
i = 0
|
| 126 |
+
gen = self._cache_gen
|
| 127 |
+
cache = self._cache
|
| 128 |
+
acquire = self._cache_lock.acquire
|
| 129 |
+
release = self._cache_lock.release
|
| 130 |
+
while gen:
|
| 131 |
+
if i == len(cache):
|
| 132 |
+
acquire()
|
| 133 |
+
if self._cache_complete:
|
| 134 |
+
break
|
| 135 |
+
try:
|
| 136 |
+
for j in range(10):
|
| 137 |
+
cache.append(advance_iterator(gen))
|
| 138 |
+
except StopIteration:
|
| 139 |
+
self._cache_gen = gen = None
|
| 140 |
+
self._cache_complete = True
|
| 141 |
+
break
|
| 142 |
+
release()
|
| 143 |
+
yield cache[i]
|
| 144 |
+
i += 1
|
| 145 |
+
while i < self._len:
|
| 146 |
+
yield cache[i]
|
| 147 |
+
i += 1
|
| 148 |
+
|
| 149 |
+
def __getitem__(self, item):
|
| 150 |
+
if self._cache_complete:
|
| 151 |
+
return self._cache[item]
|
| 152 |
+
elif isinstance(item, slice):
|
| 153 |
+
if item.step and item.step < 0:
|
| 154 |
+
return list(iter(self))[item]
|
| 155 |
+
else:
|
| 156 |
+
return list(itertools.islice(self,
|
| 157 |
+
item.start or 0,
|
| 158 |
+
item.stop or sys.maxsize,
|
| 159 |
+
item.step or 1))
|
| 160 |
+
elif item >= 0:
|
| 161 |
+
gen = iter(self)
|
| 162 |
+
try:
|
| 163 |
+
for i in range(item+1):
|
| 164 |
+
res = advance_iterator(gen)
|
| 165 |
+
except StopIteration:
|
| 166 |
+
raise IndexError
|
| 167 |
+
return res
|
| 168 |
+
else:
|
| 169 |
+
return list(iter(self))[item]
|
| 170 |
+
|
| 171 |
+
def __contains__(self, item):
|
| 172 |
+
if self._cache_complete:
|
| 173 |
+
return item in self._cache
|
| 174 |
+
else:
|
| 175 |
+
for i in self:
|
| 176 |
+
if i == item:
|
| 177 |
+
return True
|
| 178 |
+
elif i > item:
|
| 179 |
+
return False
|
| 180 |
+
return False
|
| 181 |
+
|
| 182 |
+
# __len__() introduces a large performance penalty.
|
| 183 |
+
def count(self):
|
| 184 |
+
""" Returns the number of recurrences in this set. It will have go
|
| 185 |
+
through the whole recurrence, if this hasn't been done before. """
|
| 186 |
+
if self._len is None:
|
| 187 |
+
for x in self:
|
| 188 |
+
pass
|
| 189 |
+
return self._len
|
| 190 |
+
|
| 191 |
+
def before(self, dt, inc=False):
|
| 192 |
+
""" Returns the last recurrence before the given datetime instance. The
|
| 193 |
+
inc keyword defines what happens if dt is an occurrence. With
|
| 194 |
+
inc=True, if dt itself is an occurrence, it will be returned. """
|
| 195 |
+
if self._cache_complete:
|
| 196 |
+
gen = self._cache
|
| 197 |
+
else:
|
| 198 |
+
gen = self
|
| 199 |
+
last = None
|
| 200 |
+
if inc:
|
| 201 |
+
for i in gen:
|
| 202 |
+
if i > dt:
|
| 203 |
+
break
|
| 204 |
+
last = i
|
| 205 |
+
else:
|
| 206 |
+
for i in gen:
|
| 207 |
+
if i >= dt:
|
| 208 |
+
break
|
| 209 |
+
last = i
|
| 210 |
+
return last
|
| 211 |
+
|
| 212 |
+
def after(self, dt, inc=False):
|
| 213 |
+
""" Returns the first recurrence after the given datetime instance. The
|
| 214 |
+
inc keyword defines what happens if dt is an occurrence. With
|
| 215 |
+
inc=True, if dt itself is an occurrence, it will be returned. """
|
| 216 |
+
if self._cache_complete:
|
| 217 |
+
gen = self._cache
|
| 218 |
+
else:
|
| 219 |
+
gen = self
|
| 220 |
+
if inc:
|
| 221 |
+
for i in gen:
|
| 222 |
+
if i >= dt:
|
| 223 |
+
return i
|
| 224 |
+
else:
|
| 225 |
+
for i in gen:
|
| 226 |
+
if i > dt:
|
| 227 |
+
return i
|
| 228 |
+
return None
|
| 229 |
+
|
| 230 |
+
def xafter(self, dt, count=None, inc=False):
|
| 231 |
+
"""
|
| 232 |
+
Generator which yields up to `count` recurrences after the given
|
| 233 |
+
datetime instance, equivalent to `after`.
|
| 234 |
+
|
| 235 |
+
:param dt:
|
| 236 |
+
The datetime at which to start generating recurrences.
|
| 237 |
+
|
| 238 |
+
:param count:
|
| 239 |
+
The maximum number of recurrences to generate. If `None` (default),
|
| 240 |
+
dates are generated until the recurrence rule is exhausted.
|
| 241 |
+
|
| 242 |
+
:param inc:
|
| 243 |
+
If `dt` is an instance of the rule and `inc` is `True`, it is
|
| 244 |
+
included in the output.
|
| 245 |
+
|
| 246 |
+
:yields: Yields a sequence of `datetime` objects.
|
| 247 |
+
"""
|
| 248 |
+
|
| 249 |
+
if self._cache_complete:
|
| 250 |
+
gen = self._cache
|
| 251 |
+
else:
|
| 252 |
+
gen = self
|
| 253 |
+
|
| 254 |
+
# Select the comparison function
|
| 255 |
+
if inc:
|
| 256 |
+
comp = lambda dc, dtc: dc >= dtc
|
| 257 |
+
else:
|
| 258 |
+
comp = lambda dc, dtc: dc > dtc
|
| 259 |
+
|
| 260 |
+
# Generate dates
|
| 261 |
+
n = 0
|
| 262 |
+
for d in gen:
|
| 263 |
+
if comp(d, dt):
|
| 264 |
+
if count is not None:
|
| 265 |
+
n += 1
|
| 266 |
+
if n > count:
|
| 267 |
+
break
|
| 268 |
+
|
| 269 |
+
yield d
|
| 270 |
+
|
| 271 |
+
def between(self, after, before, inc=False, count=1):
|
| 272 |
+
""" Returns all the occurrences of the rrule between after and before.
|
| 273 |
+
The inc keyword defines what happens if after and/or before are
|
| 274 |
+
themselves occurrences. With inc=True, they will be included in the
|
| 275 |
+
list, if they are found in the recurrence set. """
|
| 276 |
+
if self._cache_complete:
|
| 277 |
+
gen = self._cache
|
| 278 |
+
else:
|
| 279 |
+
gen = self
|
| 280 |
+
started = False
|
| 281 |
+
l = []
|
| 282 |
+
if inc:
|
| 283 |
+
for i in gen:
|
| 284 |
+
if i > before:
|
| 285 |
+
break
|
| 286 |
+
elif not started:
|
| 287 |
+
if i >= after:
|
| 288 |
+
started = True
|
| 289 |
+
l.append(i)
|
| 290 |
+
else:
|
| 291 |
+
l.append(i)
|
| 292 |
+
else:
|
| 293 |
+
for i in gen:
|
| 294 |
+
if i >= before:
|
| 295 |
+
break
|
| 296 |
+
elif not started:
|
| 297 |
+
if i > after:
|
| 298 |
+
started = True
|
| 299 |
+
l.append(i)
|
| 300 |
+
else:
|
| 301 |
+
l.append(i)
|
| 302 |
+
return l
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
class rrule(rrulebase):
|
| 306 |
+
"""
|
| 307 |
+
That's the base of the rrule operation. It accepts all the keywords
|
| 308 |
+
defined in the RFC as its constructor parameters (except byday,
|
| 309 |
+
which was renamed to byweekday) and more. The constructor prototype is::
|
| 310 |
+
|
| 311 |
+
rrule(freq)
|
| 312 |
+
|
| 313 |
+
Where freq must be one of YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
|
| 314 |
+
or SECONDLY.
|
| 315 |
+
|
| 316 |
+
.. note::
|
| 317 |
+
Per RFC section 3.3.10, recurrence instances falling on invalid dates
|
| 318 |
+
and times are ignored rather than coerced:
|
| 319 |
+
|
| 320 |
+
Recurrence rules may generate recurrence instances with an invalid
|
| 321 |
+
date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM
|
| 322 |
+
on a day where the local time is moved forward by an hour at 1:00
|
| 323 |
+
AM). Such recurrence instances MUST be ignored and MUST NOT be
|
| 324 |
+
counted as part of the recurrence set.
|
| 325 |
+
|
| 326 |
+
This can lead to possibly surprising behavior when, for example, the
|
| 327 |
+
start date occurs at the end of the month:
|
| 328 |
+
|
| 329 |
+
>>> from dateutil.rrule import rrule, MONTHLY
|
| 330 |
+
>>> from datetime import datetime
|
| 331 |
+
>>> start_date = datetime(2014, 12, 31)
|
| 332 |
+
>>> list(rrule(freq=MONTHLY, count=4, dtstart=start_date))
|
| 333 |
+
... # doctest: +NORMALIZE_WHITESPACE
|
| 334 |
+
[datetime.datetime(2014, 12, 31, 0, 0),
|
| 335 |
+
datetime.datetime(2015, 1, 31, 0, 0),
|
| 336 |
+
datetime.datetime(2015, 3, 31, 0, 0),
|
| 337 |
+
datetime.datetime(2015, 5, 31, 0, 0)]
|
| 338 |
+
|
| 339 |
+
Additionally, it supports the following keyword arguments:
|
| 340 |
+
|
| 341 |
+
:param dtstart:
|
| 342 |
+
The recurrence start. Besides being the base for the recurrence,
|
| 343 |
+
missing parameters in the final recurrence instances will also be
|
| 344 |
+
extracted from this date. If not given, datetime.now() will be used
|
| 345 |
+
instead.
|
| 346 |
+
:param interval:
|
| 347 |
+
The interval between each freq iteration. For example, when using
|
| 348 |
+
YEARLY, an interval of 2 means once every two years, but with HOURLY,
|
| 349 |
+
it means once every two hours. The default interval is 1.
|
| 350 |
+
:param wkst:
|
| 351 |
+
The week start day. Must be one of the MO, TU, WE constants, or an
|
| 352 |
+
integer, specifying the first day of the week. This will affect
|
| 353 |
+
recurrences based on weekly periods. The default week start is got
|
| 354 |
+
from calendar.firstweekday(), and may be modified by
|
| 355 |
+
calendar.setfirstweekday().
|
| 356 |
+
:param count:
|
| 357 |
+
If given, this determines how many occurrences will be generated.
|
| 358 |
+
|
| 359 |
+
.. note::
|
| 360 |
+
As of version 2.5.0, the use of the keyword ``until`` in conjunction
|
| 361 |
+
with ``count`` is deprecated, to make sure ``dateutil`` is fully
|
| 362 |
+
compliant with `RFC-5545 Sec. 3.3.10 <https://tools.ietf.org/
|
| 363 |
+
html/rfc5545#section-3.3.10>`_. Therefore, ``until`` and ``count``
|
| 364 |
+
**must not** occur in the same call to ``rrule``.
|
| 365 |
+
:param until:
|
| 366 |
+
If given, this must be a datetime instance specifying the upper-bound
|
| 367 |
+
limit of the recurrence. The last recurrence in the rule is the greatest
|
| 368 |
+
datetime that is less than or equal to the value specified in the
|
| 369 |
+
``until`` parameter.
|
| 370 |
+
|
| 371 |
+
.. note::
|
| 372 |
+
As of version 2.5.0, the use of the keyword ``until`` in conjunction
|
| 373 |
+
with ``count`` is deprecated, to make sure ``dateutil`` is fully
|
| 374 |
+
compliant with `RFC-5545 Sec. 3.3.10 <https://tools.ietf.org/
|
| 375 |
+
html/rfc5545#section-3.3.10>`_. Therefore, ``until`` and ``count``
|
| 376 |
+
**must not** occur in the same call to ``rrule``.
|
| 377 |
+
:param bysetpos:
|
| 378 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 379 |
+
positive or negative. Each given integer will specify an occurrence
|
| 380 |
+
number, corresponding to the nth occurrence of the rule inside the
|
| 381 |
+
frequency period. For example, a bysetpos of -1 if combined with a
|
| 382 |
+
MONTHLY frequency, and a byweekday of (MO, TU, WE, TH, FR), will
|
| 383 |
+
result in the last work day of every month.
|
| 384 |
+
:param bymonth:
|
| 385 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 386 |
+
meaning the months to apply the recurrence to.
|
| 387 |
+
:param bymonthday:
|
| 388 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 389 |
+
meaning the month days to apply the recurrence to.
|
| 390 |
+
:param byyearday:
|
| 391 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 392 |
+
meaning the year days to apply the recurrence to.
|
| 393 |
+
:param byeaster:
|
| 394 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 395 |
+
positive or negative. Each integer will define an offset from the
|
| 396 |
+
Easter Sunday. Passing the offset 0 to byeaster will yield the Easter
|
| 397 |
+
Sunday itself. This is an extension to the RFC specification.
|
| 398 |
+
:param byweekno:
|
| 399 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 400 |
+
meaning the week numbers to apply the recurrence to. Week numbers
|
| 401 |
+
have the meaning described in ISO8601, that is, the first week of
|
| 402 |
+
the year is that containing at least four days of the new year.
|
| 403 |
+
:param byweekday:
|
| 404 |
+
If given, it must be either an integer (0 == MO), a sequence of
|
| 405 |
+
integers, one of the weekday constants (MO, TU, etc), or a sequence
|
| 406 |
+
of these constants. When given, these variables will define the
|
| 407 |
+
weekdays where the recurrence will be applied. It's also possible to
|
| 408 |
+
use an argument n for the weekday instances, which will mean the nth
|
| 409 |
+
occurrence of this weekday in the period. For example, with MONTHLY,
|
| 410 |
+
or with YEARLY and BYMONTH, using FR(+1) in byweekday will specify the
|
| 411 |
+
first friday of the month where the recurrence happens. Notice that in
|
| 412 |
+
the RFC documentation, this is specified as BYDAY, but was renamed to
|
| 413 |
+
avoid the ambiguity of that keyword.
|
| 414 |
+
:param byhour:
|
| 415 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 416 |
+
meaning the hours to apply the recurrence to.
|
| 417 |
+
:param byminute:
|
| 418 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 419 |
+
meaning the minutes to apply the recurrence to.
|
| 420 |
+
:param bysecond:
|
| 421 |
+
If given, it must be either an integer, or a sequence of integers,
|
| 422 |
+
meaning the seconds to apply the recurrence to.
|
| 423 |
+
:param cache:
|
| 424 |
+
If given, it must be a boolean value specifying to enable or disable
|
| 425 |
+
caching of results. If you will use the same rrule instance multiple
|
| 426 |
+
times, enabling caching will improve the performance considerably.
|
| 427 |
+
"""
|
| 428 |
+
def __init__(self, freq, dtstart=None,
|
| 429 |
+
interval=1, wkst=None, count=None, until=None, bysetpos=None,
|
| 430 |
+
bymonth=None, bymonthday=None, byyearday=None, byeaster=None,
|
| 431 |
+
byweekno=None, byweekday=None,
|
| 432 |
+
byhour=None, byminute=None, bysecond=None,
|
| 433 |
+
cache=False):
|
| 434 |
+
super(rrule, self).__init__(cache)
|
| 435 |
+
global easter
|
| 436 |
+
if not dtstart:
|
| 437 |
+
if until and until.tzinfo:
|
| 438 |
+
dtstart = datetime.datetime.now(tz=until.tzinfo).replace(microsecond=0)
|
| 439 |
+
else:
|
| 440 |
+
dtstart = datetime.datetime.now().replace(microsecond=0)
|
| 441 |
+
elif not isinstance(dtstart, datetime.datetime):
|
| 442 |
+
dtstart = datetime.datetime.fromordinal(dtstart.toordinal())
|
| 443 |
+
else:
|
| 444 |
+
dtstart = dtstart.replace(microsecond=0)
|
| 445 |
+
self._dtstart = dtstart
|
| 446 |
+
self._tzinfo = dtstart.tzinfo
|
| 447 |
+
self._freq = freq
|
| 448 |
+
self._interval = interval
|
| 449 |
+
self._count = count
|
| 450 |
+
|
| 451 |
+
# Cache the original byxxx rules, if they are provided, as the _byxxx
|
| 452 |
+
# attributes do not necessarily map to the inputs, and this can be
|
| 453 |
+
# a problem in generating the strings. Only store things if they've
|
| 454 |
+
# been supplied (the string retrieval will just use .get())
|
| 455 |
+
self._original_rule = {}
|
| 456 |
+
|
| 457 |
+
if until and not isinstance(until, datetime.datetime):
|
| 458 |
+
until = datetime.datetime.fromordinal(until.toordinal())
|
| 459 |
+
self._until = until
|
| 460 |
+
|
| 461 |
+
if self._dtstart and self._until:
|
| 462 |
+
if (self._dtstart.tzinfo is not None) != (self._until.tzinfo is not None):
|
| 463 |
+
# According to RFC5545 Section 3.3.10:
|
| 464 |
+
# https://tools.ietf.org/html/rfc5545#section-3.3.10
|
| 465 |
+
#
|
| 466 |
+
# > If the "DTSTART" property is specified as a date with UTC
|
| 467 |
+
# > time or a date with local time and time zone reference,
|
| 468 |
+
# > then the UNTIL rule part MUST be specified as a date with
|
| 469 |
+
# > UTC time.
|
| 470 |
+
raise ValueError(
|
| 471 |
+
'RRULE UNTIL values must be specified in UTC when DTSTART '
|
| 472 |
+
'is timezone-aware'
|
| 473 |
+
)
|
| 474 |
+
|
| 475 |
+
if count is not None and until:
|
| 476 |
+
warn("Using both 'count' and 'until' is inconsistent with RFC 5545"
|
| 477 |
+
" and has been deprecated in dateutil. Future versions will "
|
| 478 |
+
"raise an error.", DeprecationWarning)
|
| 479 |
+
|
| 480 |
+
if wkst is None:
|
| 481 |
+
self._wkst = calendar.firstweekday()
|
| 482 |
+
elif isinstance(wkst, integer_types):
|
| 483 |
+
self._wkst = wkst
|
| 484 |
+
else:
|
| 485 |
+
self._wkst = wkst.weekday
|
| 486 |
+
|
| 487 |
+
if bysetpos is None:
|
| 488 |
+
self._bysetpos = None
|
| 489 |
+
elif isinstance(bysetpos, integer_types):
|
| 490 |
+
if bysetpos == 0 or not (-366 <= bysetpos <= 366):
|
| 491 |
+
raise ValueError("bysetpos must be between 1 and 366, "
|
| 492 |
+
"or between -366 and -1")
|
| 493 |
+
self._bysetpos = (bysetpos,)
|
| 494 |
+
else:
|
| 495 |
+
self._bysetpos = tuple(bysetpos)
|
| 496 |
+
for pos in self._bysetpos:
|
| 497 |
+
if pos == 0 or not (-366 <= pos <= 366):
|
| 498 |
+
raise ValueError("bysetpos must be between 1 and 366, "
|
| 499 |
+
"or between -366 and -1")
|
| 500 |
+
|
| 501 |
+
if self._bysetpos:
|
| 502 |
+
self._original_rule['bysetpos'] = self._bysetpos
|
| 503 |
+
|
| 504 |
+
if (byweekno is None and byyearday is None and bymonthday is None and
|
| 505 |
+
byweekday is None and byeaster is None):
|
| 506 |
+
if freq == YEARLY:
|
| 507 |
+
if bymonth is None:
|
| 508 |
+
bymonth = dtstart.month
|
| 509 |
+
self._original_rule['bymonth'] = None
|
| 510 |
+
bymonthday = dtstart.day
|
| 511 |
+
self._original_rule['bymonthday'] = None
|
| 512 |
+
elif freq == MONTHLY:
|
| 513 |
+
bymonthday = dtstart.day
|
| 514 |
+
self._original_rule['bymonthday'] = None
|
| 515 |
+
elif freq == WEEKLY:
|
| 516 |
+
byweekday = dtstart.weekday()
|
| 517 |
+
self._original_rule['byweekday'] = None
|
| 518 |
+
|
| 519 |
+
# bymonth
|
| 520 |
+
if bymonth is None:
|
| 521 |
+
self._bymonth = None
|
| 522 |
+
else:
|
| 523 |
+
if isinstance(bymonth, integer_types):
|
| 524 |
+
bymonth = (bymonth,)
|
| 525 |
+
|
| 526 |
+
self._bymonth = tuple(sorted(set(bymonth)))
|
| 527 |
+
|
| 528 |
+
if 'bymonth' not in self._original_rule:
|
| 529 |
+
self._original_rule['bymonth'] = self._bymonth
|
| 530 |
+
|
| 531 |
+
# byyearday
|
| 532 |
+
if byyearday is None:
|
| 533 |
+
self._byyearday = None
|
| 534 |
+
else:
|
| 535 |
+
if isinstance(byyearday, integer_types):
|
| 536 |
+
byyearday = (byyearday,)
|
| 537 |
+
|
| 538 |
+
self._byyearday = tuple(sorted(set(byyearday)))
|
| 539 |
+
self._original_rule['byyearday'] = self._byyearday
|
| 540 |
+
|
| 541 |
+
# byeaster
|
| 542 |
+
if byeaster is not None:
|
| 543 |
+
if not easter:
|
| 544 |
+
from dateutil import easter
|
| 545 |
+
if isinstance(byeaster, integer_types):
|
| 546 |
+
self._byeaster = (byeaster,)
|
| 547 |
+
else:
|
| 548 |
+
self._byeaster = tuple(sorted(byeaster))
|
| 549 |
+
|
| 550 |
+
self._original_rule['byeaster'] = self._byeaster
|
| 551 |
+
else:
|
| 552 |
+
self._byeaster = None
|
| 553 |
+
|
| 554 |
+
# bymonthday
|
| 555 |
+
if bymonthday is None:
|
| 556 |
+
self._bymonthday = ()
|
| 557 |
+
self._bynmonthday = ()
|
| 558 |
+
else:
|
| 559 |
+
if isinstance(bymonthday, integer_types):
|
| 560 |
+
bymonthday = (bymonthday,)
|
| 561 |
+
|
| 562 |
+
bymonthday = set(bymonthday) # Ensure it's unique
|
| 563 |
+
|
| 564 |
+
self._bymonthday = tuple(sorted(x for x in bymonthday if x > 0))
|
| 565 |
+
self._bynmonthday = tuple(sorted(x for x in bymonthday if x < 0))
|
| 566 |
+
|
| 567 |
+
# Storing positive numbers first, then negative numbers
|
| 568 |
+
if 'bymonthday' not in self._original_rule:
|
| 569 |
+
self._original_rule['bymonthday'] = tuple(
|
| 570 |
+
itertools.chain(self._bymonthday, self._bynmonthday))
|
| 571 |
+
|
| 572 |
+
# byweekno
|
| 573 |
+
if byweekno is None:
|
| 574 |
+
self._byweekno = None
|
| 575 |
+
else:
|
| 576 |
+
if isinstance(byweekno, integer_types):
|
| 577 |
+
byweekno = (byweekno,)
|
| 578 |
+
|
| 579 |
+
self._byweekno = tuple(sorted(set(byweekno)))
|
| 580 |
+
|
| 581 |
+
self._original_rule['byweekno'] = self._byweekno
|
| 582 |
+
|
| 583 |
+
# byweekday / bynweekday
|
| 584 |
+
if byweekday is None:
|
| 585 |
+
self._byweekday = None
|
| 586 |
+
self._bynweekday = None
|
| 587 |
+
else:
|
| 588 |
+
# If it's one of the valid non-sequence types, convert to a
|
| 589 |
+
# single-element sequence before the iterator that builds the
|
| 590 |
+
# byweekday set.
|
| 591 |
+
if isinstance(byweekday, integer_types) or hasattr(byweekday, "n"):
|
| 592 |
+
byweekday = (byweekday,)
|
| 593 |
+
|
| 594 |
+
self._byweekday = set()
|
| 595 |
+
self._bynweekday = set()
|
| 596 |
+
for wday in byweekday:
|
| 597 |
+
if isinstance(wday, integer_types):
|
| 598 |
+
self._byweekday.add(wday)
|
| 599 |
+
elif not wday.n or freq > MONTHLY:
|
| 600 |
+
self._byweekday.add(wday.weekday)
|
| 601 |
+
else:
|
| 602 |
+
self._bynweekday.add((wday.weekday, wday.n))
|
| 603 |
+
|
| 604 |
+
if not self._byweekday:
|
| 605 |
+
self._byweekday = None
|
| 606 |
+
elif not self._bynweekday:
|
| 607 |
+
self._bynweekday = None
|
| 608 |
+
|
| 609 |
+
if self._byweekday is not None:
|
| 610 |
+
self._byweekday = tuple(sorted(self._byweekday))
|
| 611 |
+
orig_byweekday = [weekday(x) for x in self._byweekday]
|
| 612 |
+
else:
|
| 613 |
+
orig_byweekday = ()
|
| 614 |
+
|
| 615 |
+
if self._bynweekday is not None:
|
| 616 |
+
self._bynweekday = tuple(sorted(self._bynweekday))
|
| 617 |
+
orig_bynweekday = [weekday(*x) for x in self._bynweekday]
|
| 618 |
+
else:
|
| 619 |
+
orig_bynweekday = ()
|
| 620 |
+
|
| 621 |
+
if 'byweekday' not in self._original_rule:
|
| 622 |
+
self._original_rule['byweekday'] = tuple(itertools.chain(
|
| 623 |
+
orig_byweekday, orig_bynweekday))
|
| 624 |
+
|
| 625 |
+
# byhour
|
| 626 |
+
if byhour is None:
|
| 627 |
+
if freq < HOURLY:
|
| 628 |
+
self._byhour = {dtstart.hour}
|
| 629 |
+
else:
|
| 630 |
+
self._byhour = None
|
| 631 |
+
else:
|
| 632 |
+
if isinstance(byhour, integer_types):
|
| 633 |
+
byhour = (byhour,)
|
| 634 |
+
|
| 635 |
+
if freq == HOURLY:
|
| 636 |
+
self._byhour = self.__construct_byset(start=dtstart.hour,
|
| 637 |
+
byxxx=byhour,
|
| 638 |
+
base=24)
|
| 639 |
+
else:
|
| 640 |
+
self._byhour = set(byhour)
|
| 641 |
+
|
| 642 |
+
self._byhour = tuple(sorted(self._byhour))
|
| 643 |
+
self._original_rule['byhour'] = self._byhour
|
| 644 |
+
|
| 645 |
+
# byminute
|
| 646 |
+
if byminute is None:
|
| 647 |
+
if freq < MINUTELY:
|
| 648 |
+
self._byminute = {dtstart.minute}
|
| 649 |
+
else:
|
| 650 |
+
self._byminute = None
|
| 651 |
+
else:
|
| 652 |
+
if isinstance(byminute, integer_types):
|
| 653 |
+
byminute = (byminute,)
|
| 654 |
+
|
| 655 |
+
if freq == MINUTELY:
|
| 656 |
+
self._byminute = self.__construct_byset(start=dtstart.minute,
|
| 657 |
+
byxxx=byminute,
|
| 658 |
+
base=60)
|
| 659 |
+
else:
|
| 660 |
+
self._byminute = set(byminute)
|
| 661 |
+
|
| 662 |
+
self._byminute = tuple(sorted(self._byminute))
|
| 663 |
+
self._original_rule['byminute'] = self._byminute
|
| 664 |
+
|
| 665 |
+
# bysecond
|
| 666 |
+
if bysecond is None:
|
| 667 |
+
if freq < SECONDLY:
|
| 668 |
+
self._bysecond = ((dtstart.second,))
|
| 669 |
+
else:
|
| 670 |
+
self._bysecond = None
|
| 671 |
+
else:
|
| 672 |
+
if isinstance(bysecond, integer_types):
|
| 673 |
+
bysecond = (bysecond,)
|
| 674 |
+
|
| 675 |
+
self._bysecond = set(bysecond)
|
| 676 |
+
|
| 677 |
+
if freq == SECONDLY:
|
| 678 |
+
self._bysecond = self.__construct_byset(start=dtstart.second,
|
| 679 |
+
byxxx=bysecond,
|
| 680 |
+
base=60)
|
| 681 |
+
else:
|
| 682 |
+
self._bysecond = set(bysecond)
|
| 683 |
+
|
| 684 |
+
self._bysecond = tuple(sorted(self._bysecond))
|
| 685 |
+
self._original_rule['bysecond'] = self._bysecond
|
| 686 |
+
|
| 687 |
+
if self._freq >= HOURLY:
|
| 688 |
+
self._timeset = None
|
| 689 |
+
else:
|
| 690 |
+
self._timeset = []
|
| 691 |
+
for hour in self._byhour:
|
| 692 |
+
for minute in self._byminute:
|
| 693 |
+
for second in self._bysecond:
|
| 694 |
+
self._timeset.append(
|
| 695 |
+
datetime.time(hour, minute, second,
|
| 696 |
+
tzinfo=self._tzinfo))
|
| 697 |
+
self._timeset.sort()
|
| 698 |
+
self._timeset = tuple(self._timeset)
|
| 699 |
+
|
| 700 |
+
def __str__(self):
|
| 701 |
+
"""
|
| 702 |
+
Output a string that would generate this RRULE if passed to rrulestr.
|
| 703 |
+
This is mostly compatible with RFC5545, except for the
|
| 704 |
+
dateutil-specific extension BYEASTER.
|
| 705 |
+
"""
|
| 706 |
+
|
| 707 |
+
output = []
|
| 708 |
+
h, m, s = [None] * 3
|
| 709 |
+
if self._dtstart:
|
| 710 |
+
output.append(self._dtstart.strftime('DTSTART:%Y%m%dT%H%M%S'))
|
| 711 |
+
h, m, s = self._dtstart.timetuple()[3:6]
|
| 712 |
+
|
| 713 |
+
parts = ['FREQ=' + FREQNAMES[self._freq]]
|
| 714 |
+
if self._interval != 1:
|
| 715 |
+
parts.append('INTERVAL=' + str(self._interval))
|
| 716 |
+
|
| 717 |
+
if self._wkst:
|
| 718 |
+
parts.append('WKST=' + repr(weekday(self._wkst))[0:2])
|
| 719 |
+
|
| 720 |
+
if self._count is not None:
|
| 721 |
+
parts.append('COUNT=' + str(self._count))
|
| 722 |
+
|
| 723 |
+
if self._until:
|
| 724 |
+
parts.append(self._until.strftime('UNTIL=%Y%m%dT%H%M%S'))
|
| 725 |
+
|
| 726 |
+
if self._original_rule.get('byweekday') is not None:
|
| 727 |
+
# The str() method on weekday objects doesn't generate
|
| 728 |
+
# RFC5545-compliant strings, so we should modify that.
|
| 729 |
+
original_rule = dict(self._original_rule)
|
| 730 |
+
wday_strings = []
|
| 731 |
+
for wday in original_rule['byweekday']:
|
| 732 |
+
if wday.n:
|
| 733 |
+
wday_strings.append('{n:+d}{wday}'.format(
|
| 734 |
+
n=wday.n,
|
| 735 |
+
wday=repr(wday)[0:2]))
|
| 736 |
+
else:
|
| 737 |
+
wday_strings.append(repr(wday))
|
| 738 |
+
|
| 739 |
+
original_rule['byweekday'] = wday_strings
|
| 740 |
+
else:
|
| 741 |
+
original_rule = self._original_rule
|
| 742 |
+
|
| 743 |
+
partfmt = '{name}={vals}'
|
| 744 |
+
for name, key in [('BYSETPOS', 'bysetpos'),
|
| 745 |
+
('BYMONTH', 'bymonth'),
|
| 746 |
+
('BYMONTHDAY', 'bymonthday'),
|
| 747 |
+
('BYYEARDAY', 'byyearday'),
|
| 748 |
+
('BYWEEKNO', 'byweekno'),
|
| 749 |
+
('BYDAY', 'byweekday'),
|
| 750 |
+
('BYHOUR', 'byhour'),
|
| 751 |
+
('BYMINUTE', 'byminute'),
|
| 752 |
+
('BYSECOND', 'bysecond'),
|
| 753 |
+
('BYEASTER', 'byeaster')]:
|
| 754 |
+
value = original_rule.get(key)
|
| 755 |
+
if value:
|
| 756 |
+
parts.append(partfmt.format(name=name, vals=(','.join(str(v)
|
| 757 |
+
for v in value))))
|
| 758 |
+
|
| 759 |
+
output.append('RRULE:' + ';'.join(parts))
|
| 760 |
+
return '\n'.join(output)
|
| 761 |
+
|
| 762 |
+
def replace(self, **kwargs):
|
| 763 |
+
"""Return new rrule with same attributes except for those attributes given new
|
| 764 |
+
values by whichever keyword arguments are specified."""
|
| 765 |
+
new_kwargs = {"interval": self._interval,
|
| 766 |
+
"count": self._count,
|
| 767 |
+
"dtstart": self._dtstart,
|
| 768 |
+
"freq": self._freq,
|
| 769 |
+
"until": self._until,
|
| 770 |
+
"wkst": self._wkst,
|
| 771 |
+
"cache": False if self._cache is None else True }
|
| 772 |
+
new_kwargs.update(self._original_rule)
|
| 773 |
+
new_kwargs.update(kwargs)
|
| 774 |
+
return rrule(**new_kwargs)
|
| 775 |
+
|
| 776 |
+
def _iter(self):
|
| 777 |
+
year, month, day, hour, minute, second, weekday, yearday, _ = \
|
| 778 |
+
self._dtstart.timetuple()
|
| 779 |
+
|
| 780 |
+
# Some local variables to speed things up a bit
|
| 781 |
+
freq = self._freq
|
| 782 |
+
interval = self._interval
|
| 783 |
+
wkst = self._wkst
|
| 784 |
+
until = self._until
|
| 785 |
+
bymonth = self._bymonth
|
| 786 |
+
byweekno = self._byweekno
|
| 787 |
+
byyearday = self._byyearday
|
| 788 |
+
byweekday = self._byweekday
|
| 789 |
+
byeaster = self._byeaster
|
| 790 |
+
bymonthday = self._bymonthday
|
| 791 |
+
bynmonthday = self._bynmonthday
|
| 792 |
+
bysetpos = self._bysetpos
|
| 793 |
+
byhour = self._byhour
|
| 794 |
+
byminute = self._byminute
|
| 795 |
+
bysecond = self._bysecond
|
| 796 |
+
|
| 797 |
+
ii = _iterinfo(self)
|
| 798 |
+
ii.rebuild(year, month)
|
| 799 |
+
|
| 800 |
+
getdayset = {YEARLY: ii.ydayset,
|
| 801 |
+
MONTHLY: ii.mdayset,
|
| 802 |
+
WEEKLY: ii.wdayset,
|
| 803 |
+
DAILY: ii.ddayset,
|
| 804 |
+
HOURLY: ii.ddayset,
|
| 805 |
+
MINUTELY: ii.ddayset,
|
| 806 |
+
SECONDLY: ii.ddayset}[freq]
|
| 807 |
+
|
| 808 |
+
if freq < HOURLY:
|
| 809 |
+
timeset = self._timeset
|
| 810 |
+
else:
|
| 811 |
+
gettimeset = {HOURLY: ii.htimeset,
|
| 812 |
+
MINUTELY: ii.mtimeset,
|
| 813 |
+
SECONDLY: ii.stimeset}[freq]
|
| 814 |
+
if ((freq >= HOURLY and
|
| 815 |
+
self._byhour and hour not in self._byhour) or
|
| 816 |
+
(freq >= MINUTELY and
|
| 817 |
+
self._byminute and minute not in self._byminute) or
|
| 818 |
+
(freq >= SECONDLY and
|
| 819 |
+
self._bysecond and second not in self._bysecond)):
|
| 820 |
+
timeset = ()
|
| 821 |
+
else:
|
| 822 |
+
timeset = gettimeset(hour, minute, second)
|
| 823 |
+
|
| 824 |
+
total = 0
|
| 825 |
+
count = self._count
|
| 826 |
+
while True:
|
| 827 |
+
# Get dayset with the right frequency
|
| 828 |
+
dayset, start, end = getdayset(year, month, day)
|
| 829 |
+
|
| 830 |
+
# Do the "hard" work ;-)
|
| 831 |
+
filtered = False
|
| 832 |
+
for i in dayset[start:end]:
|
| 833 |
+
if ((bymonth and ii.mmask[i] not in bymonth) or
|
| 834 |
+
(byweekno and not ii.wnomask[i]) or
|
| 835 |
+
(byweekday and ii.wdaymask[i] not in byweekday) or
|
| 836 |
+
(ii.nwdaymask and not ii.nwdaymask[i]) or
|
| 837 |
+
(byeaster and not ii.eastermask[i]) or
|
| 838 |
+
((bymonthday or bynmonthday) and
|
| 839 |
+
ii.mdaymask[i] not in bymonthday and
|
| 840 |
+
ii.nmdaymask[i] not in bynmonthday) or
|
| 841 |
+
(byyearday and
|
| 842 |
+
((i < ii.yearlen and i+1 not in byyearday and
|
| 843 |
+
-ii.yearlen+i not in byyearday) or
|
| 844 |
+
(i >= ii.yearlen and i+1-ii.yearlen not in byyearday and
|
| 845 |
+
-ii.nextyearlen+i-ii.yearlen not in byyearday)))):
|
| 846 |
+
dayset[i] = None
|
| 847 |
+
filtered = True
|
| 848 |
+
|
| 849 |
+
# Output results
|
| 850 |
+
if bysetpos and timeset:
|
| 851 |
+
poslist = []
|
| 852 |
+
for pos in bysetpos:
|
| 853 |
+
if pos < 0:
|
| 854 |
+
daypos, timepos = divmod(pos, len(timeset))
|
| 855 |
+
else:
|
| 856 |
+
daypos, timepos = divmod(pos-1, len(timeset))
|
| 857 |
+
try:
|
| 858 |
+
i = [x for x in dayset[start:end]
|
| 859 |
+
if x is not None][daypos]
|
| 860 |
+
time = timeset[timepos]
|
| 861 |
+
except IndexError:
|
| 862 |
+
pass
|
| 863 |
+
else:
|
| 864 |
+
date = datetime.date.fromordinal(ii.yearordinal+i)
|
| 865 |
+
res = datetime.datetime.combine(date, time)
|
| 866 |
+
if res not in poslist:
|
| 867 |
+
poslist.append(res)
|
| 868 |
+
poslist.sort()
|
| 869 |
+
for res in poslist:
|
| 870 |
+
if until and res > until:
|
| 871 |
+
self._len = total
|
| 872 |
+
return
|
| 873 |
+
elif res >= self._dtstart:
|
| 874 |
+
if count is not None:
|
| 875 |
+
count -= 1
|
| 876 |
+
if count < 0:
|
| 877 |
+
self._len = total
|
| 878 |
+
return
|
| 879 |
+
total += 1
|
| 880 |
+
yield res
|
| 881 |
+
else:
|
| 882 |
+
for i in dayset[start:end]:
|
| 883 |
+
if i is not None:
|
| 884 |
+
date = datetime.date.fromordinal(ii.yearordinal + i)
|
| 885 |
+
for time in timeset:
|
| 886 |
+
res = datetime.datetime.combine(date, time)
|
| 887 |
+
if until and res > until:
|
| 888 |
+
self._len = total
|
| 889 |
+
return
|
| 890 |
+
elif res >= self._dtstart:
|
| 891 |
+
if count is not None:
|
| 892 |
+
count -= 1
|
| 893 |
+
if count < 0:
|
| 894 |
+
self._len = total
|
| 895 |
+
return
|
| 896 |
+
|
| 897 |
+
total += 1
|
| 898 |
+
yield res
|
| 899 |
+
|
| 900 |
+
# Handle frequency and interval
|
| 901 |
+
fixday = False
|
| 902 |
+
if freq == YEARLY:
|
| 903 |
+
year += interval
|
| 904 |
+
if year > datetime.MAXYEAR:
|
| 905 |
+
self._len = total
|
| 906 |
+
return
|
| 907 |
+
ii.rebuild(year, month)
|
| 908 |
+
elif freq == MONTHLY:
|
| 909 |
+
month += interval
|
| 910 |
+
if month > 12:
|
| 911 |
+
div, mod = divmod(month, 12)
|
| 912 |
+
month = mod
|
| 913 |
+
year += div
|
| 914 |
+
if month == 0:
|
| 915 |
+
month = 12
|
| 916 |
+
year -= 1
|
| 917 |
+
if year > datetime.MAXYEAR:
|
| 918 |
+
self._len = total
|
| 919 |
+
return
|
| 920 |
+
ii.rebuild(year, month)
|
| 921 |
+
elif freq == WEEKLY:
|
| 922 |
+
if wkst > weekday:
|
| 923 |
+
day += -(weekday+1+(6-wkst))+self._interval*7
|
| 924 |
+
else:
|
| 925 |
+
day += -(weekday-wkst)+self._interval*7
|
| 926 |
+
weekday = wkst
|
| 927 |
+
fixday = True
|
| 928 |
+
elif freq == DAILY:
|
| 929 |
+
day += interval
|
| 930 |
+
fixday = True
|
| 931 |
+
elif freq == HOURLY:
|
| 932 |
+
if filtered:
|
| 933 |
+
# Jump to one iteration before next day
|
| 934 |
+
hour += ((23-hour)//interval)*interval
|
| 935 |
+
|
| 936 |
+
if byhour:
|
| 937 |
+
ndays, hour = self.__mod_distance(value=hour,
|
| 938 |
+
byxxx=self._byhour,
|
| 939 |
+
base=24)
|
| 940 |
+
else:
|
| 941 |
+
ndays, hour = divmod(hour+interval, 24)
|
| 942 |
+
|
| 943 |
+
if ndays:
|
| 944 |
+
day += ndays
|
| 945 |
+
fixday = True
|
| 946 |
+
|
| 947 |
+
timeset = gettimeset(hour, minute, second)
|
| 948 |
+
elif freq == MINUTELY:
|
| 949 |
+
if filtered:
|
| 950 |
+
# Jump to one iteration before next day
|
| 951 |
+
minute += ((1439-(hour*60+minute))//interval)*interval
|
| 952 |
+
|
| 953 |
+
valid = False
|
| 954 |
+
rep_rate = (24*60)
|
| 955 |
+
for j in range(rep_rate // gcd(interval, rep_rate)):
|
| 956 |
+
if byminute:
|
| 957 |
+
nhours, minute = \
|
| 958 |
+
self.__mod_distance(value=minute,
|
| 959 |
+
byxxx=self._byminute,
|
| 960 |
+
base=60)
|
| 961 |
+
else:
|
| 962 |
+
nhours, minute = divmod(minute+interval, 60)
|
| 963 |
+
|
| 964 |
+
div, hour = divmod(hour+nhours, 24)
|
| 965 |
+
if div:
|
| 966 |
+
day += div
|
| 967 |
+
fixday = True
|
| 968 |
+
filtered = False
|
| 969 |
+
|
| 970 |
+
if not byhour or hour in byhour:
|
| 971 |
+
valid = True
|
| 972 |
+
break
|
| 973 |
+
|
| 974 |
+
if not valid:
|
| 975 |
+
raise ValueError('Invalid combination of interval and ' +
|
| 976 |
+
'byhour resulting in empty rule.')
|
| 977 |
+
|
| 978 |
+
timeset = gettimeset(hour, minute, second)
|
| 979 |
+
elif freq == SECONDLY:
|
| 980 |
+
if filtered:
|
| 981 |
+
# Jump to one iteration before next day
|
| 982 |
+
second += (((86399 - (hour * 3600 + minute * 60 + second))
|
| 983 |
+
// interval) * interval)
|
| 984 |
+
|
| 985 |
+
rep_rate = (24 * 3600)
|
| 986 |
+
valid = False
|
| 987 |
+
for j in range(0, rep_rate // gcd(interval, rep_rate)):
|
| 988 |
+
if bysecond:
|
| 989 |
+
nminutes, second = \
|
| 990 |
+
self.__mod_distance(value=second,
|
| 991 |
+
byxxx=self._bysecond,
|
| 992 |
+
base=60)
|
| 993 |
+
else:
|
| 994 |
+
nminutes, second = divmod(second+interval, 60)
|
| 995 |
+
|
| 996 |
+
div, minute = divmod(minute+nminutes, 60)
|
| 997 |
+
if div:
|
| 998 |
+
hour += div
|
| 999 |
+
div, hour = divmod(hour, 24)
|
| 1000 |
+
if div:
|
| 1001 |
+
day += div
|
| 1002 |
+
fixday = True
|
| 1003 |
+
|
| 1004 |
+
if ((not byhour or hour in byhour) and
|
| 1005 |
+
(not byminute or minute in byminute) and
|
| 1006 |
+
(not bysecond or second in bysecond)):
|
| 1007 |
+
valid = True
|
| 1008 |
+
break
|
| 1009 |
+
|
| 1010 |
+
if not valid:
|
| 1011 |
+
raise ValueError('Invalid combination of interval, ' +
|
| 1012 |
+
'byhour and byminute resulting in empty' +
|
| 1013 |
+
' rule.')
|
| 1014 |
+
|
| 1015 |
+
timeset = gettimeset(hour, minute, second)
|
| 1016 |
+
|
| 1017 |
+
if fixday and day > 28:
|
| 1018 |
+
daysinmonth = calendar.monthrange(year, month)[1]
|
| 1019 |
+
if day > daysinmonth:
|
| 1020 |
+
while day > daysinmonth:
|
| 1021 |
+
day -= daysinmonth
|
| 1022 |
+
month += 1
|
| 1023 |
+
if month == 13:
|
| 1024 |
+
month = 1
|
| 1025 |
+
year += 1
|
| 1026 |
+
if year > datetime.MAXYEAR:
|
| 1027 |
+
self._len = total
|
| 1028 |
+
return
|
| 1029 |
+
daysinmonth = calendar.monthrange(year, month)[1]
|
| 1030 |
+
ii.rebuild(year, month)
|
| 1031 |
+
|
| 1032 |
+
def __construct_byset(self, start, byxxx, base):
|
| 1033 |
+
"""
|
| 1034 |
+
If a `BYXXX` sequence is passed to the constructor at the same level as
|
| 1035 |
+
`FREQ` (e.g. `FREQ=HOURLY,BYHOUR={2,4,7},INTERVAL=3`), there are some
|
| 1036 |
+
specifications which cannot be reached given some starting conditions.
|
| 1037 |
+
|
| 1038 |
+
This occurs whenever the interval is not coprime with the base of a
|
| 1039 |
+
given unit and the difference between the starting position and the
|
| 1040 |
+
ending position is not coprime with the greatest common denominator
|
| 1041 |
+
between the interval and the base. For example, with a FREQ of hourly
|
| 1042 |
+
starting at 17:00 and an interval of 4, the only valid values for
|
| 1043 |
+
BYHOUR would be {21, 1, 5, 9, 13, 17}, because 4 and 24 are not
|
| 1044 |
+
coprime.
|
| 1045 |
+
|
| 1046 |
+
:param start:
|
| 1047 |
+
Specifies the starting position.
|
| 1048 |
+
:param byxxx:
|
| 1049 |
+
An iterable containing the list of allowed values.
|
| 1050 |
+
:param base:
|
| 1051 |
+
The largest allowable value for the specified frequency (e.g.
|
| 1052 |
+
24 hours, 60 minutes).
|
| 1053 |
+
|
| 1054 |
+
This does not preserve the type of the iterable, returning a set, since
|
| 1055 |
+
the values should be unique and the order is irrelevant, this will
|
| 1056 |
+
speed up later lookups.
|
| 1057 |
+
|
| 1058 |
+
In the event of an empty set, raises a :exception:`ValueError`, as this
|
| 1059 |
+
results in an empty rrule.
|
| 1060 |
+
"""
|
| 1061 |
+
|
| 1062 |
+
cset = set()
|
| 1063 |
+
|
| 1064 |
+
# Support a single byxxx value.
|
| 1065 |
+
if isinstance(byxxx, integer_types):
|
| 1066 |
+
byxxx = (byxxx, )
|
| 1067 |
+
|
| 1068 |
+
for num in byxxx:
|
| 1069 |
+
i_gcd = gcd(self._interval, base)
|
| 1070 |
+
# Use divmod rather than % because we need to wrap negative nums.
|
| 1071 |
+
if i_gcd == 1 or divmod(num - start, i_gcd)[1] == 0:
|
| 1072 |
+
cset.add(num)
|
| 1073 |
+
|
| 1074 |
+
if len(cset) == 0:
|
| 1075 |
+
raise ValueError("Invalid rrule byxxx generates an empty set.")
|
| 1076 |
+
|
| 1077 |
+
return cset
|
| 1078 |
+
|
| 1079 |
+
def __mod_distance(self, value, byxxx, base):
|
| 1080 |
+
"""
|
| 1081 |
+
Calculates the next value in a sequence where the `FREQ` parameter is
|
| 1082 |
+
specified along with a `BYXXX` parameter at the same "level"
|
| 1083 |
+
(e.g. `HOURLY` specified with `BYHOUR`).
|
| 1084 |
+
|
| 1085 |
+
:param value:
|
| 1086 |
+
The old value of the component.
|
| 1087 |
+
:param byxxx:
|
| 1088 |
+
The `BYXXX` set, which should have been generated by
|
| 1089 |
+
`rrule._construct_byset`, or something else which checks that a
|
| 1090 |
+
valid rule is present.
|
| 1091 |
+
:param base:
|
| 1092 |
+
The largest allowable value for the specified frequency (e.g.
|
| 1093 |
+
24 hours, 60 minutes).
|
| 1094 |
+
|
| 1095 |
+
If a valid value is not found after `base` iterations (the maximum
|
| 1096 |
+
number before the sequence would start to repeat), this raises a
|
| 1097 |
+
:exception:`ValueError`, as no valid values were found.
|
| 1098 |
+
|
| 1099 |
+
This returns a tuple of `divmod(n*interval, base)`, where `n` is the
|
| 1100 |
+
smallest number of `interval` repetitions until the next specified
|
| 1101 |
+
value in `byxxx` is found.
|
| 1102 |
+
"""
|
| 1103 |
+
accumulator = 0
|
| 1104 |
+
for ii in range(1, base + 1):
|
| 1105 |
+
# Using divmod() over % to account for negative intervals
|
| 1106 |
+
div, value = divmod(value + self._interval, base)
|
| 1107 |
+
accumulator += div
|
| 1108 |
+
if value in byxxx:
|
| 1109 |
+
return (accumulator, value)
|
| 1110 |
+
|
| 1111 |
+
|
| 1112 |
+
class _iterinfo(object):
|
| 1113 |
+
__slots__ = ["rrule", "lastyear", "lastmonth",
|
| 1114 |
+
"yearlen", "nextyearlen", "yearordinal", "yearweekday",
|
| 1115 |
+
"mmask", "mrange", "mdaymask", "nmdaymask",
|
| 1116 |
+
"wdaymask", "wnomask", "nwdaymask", "eastermask"]
|
| 1117 |
+
|
| 1118 |
+
def __init__(self, rrule):
|
| 1119 |
+
for attr in self.__slots__:
|
| 1120 |
+
setattr(self, attr, None)
|
| 1121 |
+
self.rrule = rrule
|
| 1122 |
+
|
| 1123 |
+
def rebuild(self, year, month):
|
| 1124 |
+
# Every mask is 7 days longer to handle cross-year weekly periods.
|
| 1125 |
+
rr = self.rrule
|
| 1126 |
+
if year != self.lastyear:
|
| 1127 |
+
self.yearlen = 365 + calendar.isleap(year)
|
| 1128 |
+
self.nextyearlen = 365 + calendar.isleap(year + 1)
|
| 1129 |
+
firstyday = datetime.date(year, 1, 1)
|
| 1130 |
+
self.yearordinal = firstyday.toordinal()
|
| 1131 |
+
self.yearweekday = firstyday.weekday()
|
| 1132 |
+
|
| 1133 |
+
wday = datetime.date(year, 1, 1).weekday()
|
| 1134 |
+
if self.yearlen == 365:
|
| 1135 |
+
self.mmask = M365MASK
|
| 1136 |
+
self.mdaymask = MDAY365MASK
|
| 1137 |
+
self.nmdaymask = NMDAY365MASK
|
| 1138 |
+
self.wdaymask = WDAYMASK[wday:]
|
| 1139 |
+
self.mrange = M365RANGE
|
| 1140 |
+
else:
|
| 1141 |
+
self.mmask = M366MASK
|
| 1142 |
+
self.mdaymask = MDAY366MASK
|
| 1143 |
+
self.nmdaymask = NMDAY366MASK
|
| 1144 |
+
self.wdaymask = WDAYMASK[wday:]
|
| 1145 |
+
self.mrange = M366RANGE
|
| 1146 |
+
|
| 1147 |
+
if not rr._byweekno:
|
| 1148 |
+
self.wnomask = None
|
| 1149 |
+
else:
|
| 1150 |
+
self.wnomask = [0]*(self.yearlen+7)
|
| 1151 |
+
# no1wkst = firstwkst = self.wdaymask.index(rr._wkst)
|
| 1152 |
+
no1wkst = firstwkst = (7-self.yearweekday+rr._wkst) % 7
|
| 1153 |
+
if no1wkst >= 4:
|
| 1154 |
+
no1wkst = 0
|
| 1155 |
+
# Number of days in the year, plus the days we got
|
| 1156 |
+
# from last year.
|
| 1157 |
+
wyearlen = self.yearlen+(self.yearweekday-rr._wkst) % 7
|
| 1158 |
+
else:
|
| 1159 |
+
# Number of days in the year, minus the days we
|
| 1160 |
+
# left in last year.
|
| 1161 |
+
wyearlen = self.yearlen-no1wkst
|
| 1162 |
+
div, mod = divmod(wyearlen, 7)
|
| 1163 |
+
numweeks = div+mod//4
|
| 1164 |
+
for n in rr._byweekno:
|
| 1165 |
+
if n < 0:
|
| 1166 |
+
n += numweeks+1
|
| 1167 |
+
if not (0 < n <= numweeks):
|
| 1168 |
+
continue
|
| 1169 |
+
if n > 1:
|
| 1170 |
+
i = no1wkst+(n-1)*7
|
| 1171 |
+
if no1wkst != firstwkst:
|
| 1172 |
+
i -= 7-firstwkst
|
| 1173 |
+
else:
|
| 1174 |
+
i = no1wkst
|
| 1175 |
+
for j in range(7):
|
| 1176 |
+
self.wnomask[i] = 1
|
| 1177 |
+
i += 1
|
| 1178 |
+
if self.wdaymask[i] == rr._wkst:
|
| 1179 |
+
break
|
| 1180 |
+
if 1 in rr._byweekno:
|
| 1181 |
+
# Check week number 1 of next year as well
|
| 1182 |
+
# TODO: Check -numweeks for next year.
|
| 1183 |
+
i = no1wkst+numweeks*7
|
| 1184 |
+
if no1wkst != firstwkst:
|
| 1185 |
+
i -= 7-firstwkst
|
| 1186 |
+
if i < self.yearlen:
|
| 1187 |
+
# If week starts in next year, we
|
| 1188 |
+
# don't care about it.
|
| 1189 |
+
for j in range(7):
|
| 1190 |
+
self.wnomask[i] = 1
|
| 1191 |
+
i += 1
|
| 1192 |
+
if self.wdaymask[i] == rr._wkst:
|
| 1193 |
+
break
|
| 1194 |
+
if no1wkst:
|
| 1195 |
+
# Check last week number of last year as
|
| 1196 |
+
# well. If no1wkst is 0, either the year
|
| 1197 |
+
# started on week start, or week number 1
|
| 1198 |
+
# got days from last year, so there are no
|
| 1199 |
+
# days from last year's last week number in
|
| 1200 |
+
# this year.
|
| 1201 |
+
if -1 not in rr._byweekno:
|
| 1202 |
+
lyearweekday = datetime.date(year-1, 1, 1).weekday()
|
| 1203 |
+
lno1wkst = (7-lyearweekday+rr._wkst) % 7
|
| 1204 |
+
lyearlen = 365+calendar.isleap(year-1)
|
| 1205 |
+
if lno1wkst >= 4:
|
| 1206 |
+
lno1wkst = 0
|
| 1207 |
+
lnumweeks = 52+(lyearlen +
|
| 1208 |
+
(lyearweekday-rr._wkst) % 7) % 7//4
|
| 1209 |
+
else:
|
| 1210 |
+
lnumweeks = 52+(self.yearlen-no1wkst) % 7//4
|
| 1211 |
+
else:
|
| 1212 |
+
lnumweeks = -1
|
| 1213 |
+
if lnumweeks in rr._byweekno:
|
| 1214 |
+
for i in range(no1wkst):
|
| 1215 |
+
self.wnomask[i] = 1
|
| 1216 |
+
|
| 1217 |
+
if (rr._bynweekday and (month != self.lastmonth or
|
| 1218 |
+
year != self.lastyear)):
|
| 1219 |
+
ranges = []
|
| 1220 |
+
if rr._freq == YEARLY:
|
| 1221 |
+
if rr._bymonth:
|
| 1222 |
+
for month in rr._bymonth:
|
| 1223 |
+
ranges.append(self.mrange[month-1:month+1])
|
| 1224 |
+
else:
|
| 1225 |
+
ranges = [(0, self.yearlen)]
|
| 1226 |
+
elif rr._freq == MONTHLY:
|
| 1227 |
+
ranges = [self.mrange[month-1:month+1]]
|
| 1228 |
+
if ranges:
|
| 1229 |
+
# Weekly frequency won't get here, so we may not
|
| 1230 |
+
# care about cross-year weekly periods.
|
| 1231 |
+
self.nwdaymask = [0]*self.yearlen
|
| 1232 |
+
for first, last in ranges:
|
| 1233 |
+
last -= 1
|
| 1234 |
+
for wday, n in rr._bynweekday:
|
| 1235 |
+
if n < 0:
|
| 1236 |
+
i = last+(n+1)*7
|
| 1237 |
+
i -= (self.wdaymask[i]-wday) % 7
|
| 1238 |
+
else:
|
| 1239 |
+
i = first+(n-1)*7
|
| 1240 |
+
i += (7-self.wdaymask[i]+wday) % 7
|
| 1241 |
+
if first <= i <= last:
|
| 1242 |
+
self.nwdaymask[i] = 1
|
| 1243 |
+
|
| 1244 |
+
if rr._byeaster:
|
| 1245 |
+
self.eastermask = [0]*(self.yearlen+7)
|
| 1246 |
+
eyday = easter.easter(year).toordinal()-self.yearordinal
|
| 1247 |
+
for offset in rr._byeaster:
|
| 1248 |
+
self.eastermask[eyday+offset] = 1
|
| 1249 |
+
|
| 1250 |
+
self.lastyear = year
|
| 1251 |
+
self.lastmonth = month
|
| 1252 |
+
|
| 1253 |
+
def ydayset(self, year, month, day):
|
| 1254 |
+
return list(range(self.yearlen)), 0, self.yearlen
|
| 1255 |
+
|
| 1256 |
+
def mdayset(self, year, month, day):
|
| 1257 |
+
dset = [None]*self.yearlen
|
| 1258 |
+
start, end = self.mrange[month-1:month+1]
|
| 1259 |
+
for i in range(start, end):
|
| 1260 |
+
dset[i] = i
|
| 1261 |
+
return dset, start, end
|
| 1262 |
+
|
| 1263 |
+
def wdayset(self, year, month, day):
|
| 1264 |
+
# We need to handle cross-year weeks here.
|
| 1265 |
+
dset = [None]*(self.yearlen+7)
|
| 1266 |
+
i = datetime.date(year, month, day).toordinal()-self.yearordinal
|
| 1267 |
+
start = i
|
| 1268 |
+
for j in range(7):
|
| 1269 |
+
dset[i] = i
|
| 1270 |
+
i += 1
|
| 1271 |
+
# if (not (0 <= i < self.yearlen) or
|
| 1272 |
+
# self.wdaymask[i] == self.rrule._wkst):
|
| 1273 |
+
# This will cross the year boundary, if necessary.
|
| 1274 |
+
if self.wdaymask[i] == self.rrule._wkst:
|
| 1275 |
+
break
|
| 1276 |
+
return dset, start, i
|
| 1277 |
+
|
| 1278 |
+
def ddayset(self, year, month, day):
|
| 1279 |
+
dset = [None] * self.yearlen
|
| 1280 |
+
i = datetime.date(year, month, day).toordinal() - self.yearordinal
|
| 1281 |
+
dset[i] = i
|
| 1282 |
+
return dset, i, i + 1
|
| 1283 |
+
|
| 1284 |
+
def htimeset(self, hour, minute, second):
|
| 1285 |
+
tset = []
|
| 1286 |
+
rr = self.rrule
|
| 1287 |
+
for minute in rr._byminute:
|
| 1288 |
+
for second in rr._bysecond:
|
| 1289 |
+
tset.append(datetime.time(hour, minute, second,
|
| 1290 |
+
tzinfo=rr._tzinfo))
|
| 1291 |
+
tset.sort()
|
| 1292 |
+
return tset
|
| 1293 |
+
|
| 1294 |
+
def mtimeset(self, hour, minute, second):
|
| 1295 |
+
tset = []
|
| 1296 |
+
rr = self.rrule
|
| 1297 |
+
for second in rr._bysecond:
|
| 1298 |
+
tset.append(datetime.time(hour, minute, second, tzinfo=rr._tzinfo))
|
| 1299 |
+
tset.sort()
|
| 1300 |
+
return tset
|
| 1301 |
+
|
| 1302 |
+
def stimeset(self, hour, minute, second):
|
| 1303 |
+
return (datetime.time(hour, minute, second,
|
| 1304 |
+
tzinfo=self.rrule._tzinfo),)
|
| 1305 |
+
|
| 1306 |
+
|
| 1307 |
+
class rruleset(rrulebase):
|
| 1308 |
+
""" The rruleset type allows more complex recurrence setups, mixing
|
| 1309 |
+
multiple rules, dates, exclusion rules, and exclusion dates. The type
|
| 1310 |
+
constructor takes the following keyword arguments:
|
| 1311 |
+
|
| 1312 |
+
:param cache: If True, caching of results will be enabled, improving
|
| 1313 |
+
performance of multiple queries considerably. """
|
| 1314 |
+
|
| 1315 |
+
class _genitem(object):
|
| 1316 |
+
def __init__(self, genlist, gen):
|
| 1317 |
+
try:
|
| 1318 |
+
self.dt = advance_iterator(gen)
|
| 1319 |
+
genlist.append(self)
|
| 1320 |
+
except StopIteration:
|
| 1321 |
+
pass
|
| 1322 |
+
self.genlist = genlist
|
| 1323 |
+
self.gen = gen
|
| 1324 |
+
|
| 1325 |
+
def __next__(self):
|
| 1326 |
+
try:
|
| 1327 |
+
self.dt = advance_iterator(self.gen)
|
| 1328 |
+
except StopIteration:
|
| 1329 |
+
if self.genlist[0] is self:
|
| 1330 |
+
heapq.heappop(self.genlist)
|
| 1331 |
+
else:
|
| 1332 |
+
self.genlist.remove(self)
|
| 1333 |
+
heapq.heapify(self.genlist)
|
| 1334 |
+
|
| 1335 |
+
next = __next__
|
| 1336 |
+
|
| 1337 |
+
def __lt__(self, other):
|
| 1338 |
+
return self.dt < other.dt
|
| 1339 |
+
|
| 1340 |
+
def __gt__(self, other):
|
| 1341 |
+
return self.dt > other.dt
|
| 1342 |
+
|
| 1343 |
+
def __eq__(self, other):
|
| 1344 |
+
return self.dt == other.dt
|
| 1345 |
+
|
| 1346 |
+
def __ne__(self, other):
|
| 1347 |
+
return self.dt != other.dt
|
| 1348 |
+
|
| 1349 |
+
def __init__(self, cache=False):
|
| 1350 |
+
super(rruleset, self).__init__(cache)
|
| 1351 |
+
self._rrule = []
|
| 1352 |
+
self._rdate = []
|
| 1353 |
+
self._exrule = []
|
| 1354 |
+
self._exdate = []
|
| 1355 |
+
|
| 1356 |
+
@_invalidates_cache
|
| 1357 |
+
def rrule(self, rrule):
|
| 1358 |
+
""" Include the given :py:class:`rrule` instance in the recurrence set
|
| 1359 |
+
generation. """
|
| 1360 |
+
self._rrule.append(rrule)
|
| 1361 |
+
|
| 1362 |
+
@_invalidates_cache
|
| 1363 |
+
def rdate(self, rdate):
|
| 1364 |
+
""" Include the given :py:class:`datetime` instance in the recurrence
|
| 1365 |
+
set generation. """
|
| 1366 |
+
self._rdate.append(rdate)
|
| 1367 |
+
|
| 1368 |
+
@_invalidates_cache
|
| 1369 |
+
def exrule(self, exrule):
|
| 1370 |
+
""" Include the given rrule instance in the recurrence set exclusion
|
| 1371 |
+
list. Dates which are part of the given recurrence rules will not
|
| 1372 |
+
be generated, even if some inclusive rrule or rdate matches them.
|
| 1373 |
+
"""
|
| 1374 |
+
self._exrule.append(exrule)
|
| 1375 |
+
|
| 1376 |
+
@_invalidates_cache
|
| 1377 |
+
def exdate(self, exdate):
|
| 1378 |
+
""" Include the given datetime instance in the recurrence set
|
| 1379 |
+
exclusion list. Dates included that way will not be generated,
|
| 1380 |
+
even if some inclusive rrule or rdate matches them. """
|
| 1381 |
+
self._exdate.append(exdate)
|
| 1382 |
+
|
| 1383 |
+
def _iter(self):
|
| 1384 |
+
rlist = []
|
| 1385 |
+
self._rdate.sort()
|
| 1386 |
+
self._genitem(rlist, iter(self._rdate))
|
| 1387 |
+
for gen in [iter(x) for x in self._rrule]:
|
| 1388 |
+
self._genitem(rlist, gen)
|
| 1389 |
+
exlist = []
|
| 1390 |
+
self._exdate.sort()
|
| 1391 |
+
self._genitem(exlist, iter(self._exdate))
|
| 1392 |
+
for gen in [iter(x) for x in self._exrule]:
|
| 1393 |
+
self._genitem(exlist, gen)
|
| 1394 |
+
lastdt = None
|
| 1395 |
+
total = 0
|
| 1396 |
+
heapq.heapify(rlist)
|
| 1397 |
+
heapq.heapify(exlist)
|
| 1398 |
+
while rlist:
|
| 1399 |
+
ritem = rlist[0]
|
| 1400 |
+
if not lastdt or lastdt != ritem.dt:
|
| 1401 |
+
while exlist and exlist[0] < ritem:
|
| 1402 |
+
exitem = exlist[0]
|
| 1403 |
+
advance_iterator(exitem)
|
| 1404 |
+
if exlist and exlist[0] is exitem:
|
| 1405 |
+
heapq.heapreplace(exlist, exitem)
|
| 1406 |
+
if not exlist or ritem != exlist[0]:
|
| 1407 |
+
total += 1
|
| 1408 |
+
yield ritem.dt
|
| 1409 |
+
lastdt = ritem.dt
|
| 1410 |
+
advance_iterator(ritem)
|
| 1411 |
+
if rlist and rlist[0] is ritem:
|
| 1412 |
+
heapq.heapreplace(rlist, ritem)
|
| 1413 |
+
self._len = total
|
| 1414 |
+
|
| 1415 |
+
|
| 1416 |
+
|
| 1417 |
+
|
| 1418 |
+
class _rrulestr(object):
|
| 1419 |
+
""" Parses a string representation of a recurrence rule or set of
|
| 1420 |
+
recurrence rules.
|
| 1421 |
+
|
| 1422 |
+
:param s:
|
| 1423 |
+
Required, a string defining one or more recurrence rules.
|
| 1424 |
+
|
| 1425 |
+
:param dtstart:
|
| 1426 |
+
If given, used as the default recurrence start if not specified in the
|
| 1427 |
+
rule string.
|
| 1428 |
+
|
| 1429 |
+
:param cache:
|
| 1430 |
+
If set ``True`` caching of results will be enabled, improving
|
| 1431 |
+
performance of multiple queries considerably.
|
| 1432 |
+
|
| 1433 |
+
:param unfold:
|
| 1434 |
+
If set ``True`` indicates that a rule string is split over more
|
| 1435 |
+
than one line and should be joined before processing.
|
| 1436 |
+
|
| 1437 |
+
:param forceset:
|
| 1438 |
+
If set ``True`` forces a :class:`dateutil.rrule.rruleset` to
|
| 1439 |
+
be returned.
|
| 1440 |
+
|
| 1441 |
+
:param compatible:
|
| 1442 |
+
If set ``True`` forces ``unfold`` and ``forceset`` to be ``True``.
|
| 1443 |
+
|
| 1444 |
+
:param ignoretz:
|
| 1445 |
+
If set ``True``, time zones in parsed strings are ignored and a naive
|
| 1446 |
+
:class:`datetime.datetime` object is returned.
|
| 1447 |
+
|
| 1448 |
+
:param tzids:
|
| 1449 |
+
If given, a callable or mapping used to retrieve a
|
| 1450 |
+
:class:`datetime.tzinfo` from a string representation.
|
| 1451 |
+
Defaults to :func:`dateutil.tz.gettz`.
|
| 1452 |
+
|
| 1453 |
+
:param tzinfos:
|
| 1454 |
+
Additional time zone names / aliases which may be present in a string
|
| 1455 |
+
representation. See :func:`dateutil.parser.parse` for more
|
| 1456 |
+
information.
|
| 1457 |
+
|
| 1458 |
+
:return:
|
| 1459 |
+
Returns a :class:`dateutil.rrule.rruleset` or
|
| 1460 |
+
:class:`dateutil.rrule.rrule`
|
| 1461 |
+
"""
|
| 1462 |
+
|
| 1463 |
+
_freq_map = {"YEARLY": YEARLY,
|
| 1464 |
+
"MONTHLY": MONTHLY,
|
| 1465 |
+
"WEEKLY": WEEKLY,
|
| 1466 |
+
"DAILY": DAILY,
|
| 1467 |
+
"HOURLY": HOURLY,
|
| 1468 |
+
"MINUTELY": MINUTELY,
|
| 1469 |
+
"SECONDLY": SECONDLY}
|
| 1470 |
+
|
| 1471 |
+
_weekday_map = {"MO": 0, "TU": 1, "WE": 2, "TH": 3,
|
| 1472 |
+
"FR": 4, "SA": 5, "SU": 6}
|
| 1473 |
+
|
| 1474 |
+
def _handle_int(self, rrkwargs, name, value, **kwargs):
|
| 1475 |
+
rrkwargs[name.lower()] = int(value)
|
| 1476 |
+
|
| 1477 |
+
def _handle_int_list(self, rrkwargs, name, value, **kwargs):
|
| 1478 |
+
rrkwargs[name.lower()] = [int(x) for x in value.split(',')]
|
| 1479 |
+
|
| 1480 |
+
_handle_INTERVAL = _handle_int
|
| 1481 |
+
_handle_COUNT = _handle_int
|
| 1482 |
+
_handle_BYSETPOS = _handle_int_list
|
| 1483 |
+
_handle_BYMONTH = _handle_int_list
|
| 1484 |
+
_handle_BYMONTHDAY = _handle_int_list
|
| 1485 |
+
_handle_BYYEARDAY = _handle_int_list
|
| 1486 |
+
_handle_BYEASTER = _handle_int_list
|
| 1487 |
+
_handle_BYWEEKNO = _handle_int_list
|
| 1488 |
+
_handle_BYHOUR = _handle_int_list
|
| 1489 |
+
_handle_BYMINUTE = _handle_int_list
|
| 1490 |
+
_handle_BYSECOND = _handle_int_list
|
| 1491 |
+
|
| 1492 |
+
def _handle_FREQ(self, rrkwargs, name, value, **kwargs):
|
| 1493 |
+
rrkwargs["freq"] = self._freq_map[value]
|
| 1494 |
+
|
| 1495 |
+
def _handle_UNTIL(self, rrkwargs, name, value, **kwargs):
|
| 1496 |
+
global parser
|
| 1497 |
+
if not parser:
|
| 1498 |
+
from dateutil import parser
|
| 1499 |
+
try:
|
| 1500 |
+
rrkwargs["until"] = parser.parse(value,
|
| 1501 |
+
ignoretz=kwargs.get("ignoretz"),
|
| 1502 |
+
tzinfos=kwargs.get("tzinfos"))
|
| 1503 |
+
except ValueError:
|
| 1504 |
+
raise ValueError("invalid until date")
|
| 1505 |
+
|
| 1506 |
+
def _handle_WKST(self, rrkwargs, name, value, **kwargs):
|
| 1507 |
+
rrkwargs["wkst"] = self._weekday_map[value]
|
| 1508 |
+
|
| 1509 |
+
def _handle_BYWEEKDAY(self, rrkwargs, name, value, **kwargs):
|
| 1510 |
+
"""
|
| 1511 |
+
Two ways to specify this: +1MO or MO(+1)
|
| 1512 |
+
"""
|
| 1513 |
+
l = []
|
| 1514 |
+
for wday in value.split(','):
|
| 1515 |
+
if '(' in wday:
|
| 1516 |
+
# If it's of the form TH(+1), etc.
|
| 1517 |
+
splt = wday.split('(')
|
| 1518 |
+
w = splt[0]
|
| 1519 |
+
n = int(splt[1][:-1])
|
| 1520 |
+
elif len(wday):
|
| 1521 |
+
# If it's of the form +1MO
|
| 1522 |
+
for i in range(len(wday)):
|
| 1523 |
+
if wday[i] not in '+-0123456789':
|
| 1524 |
+
break
|
| 1525 |
+
n = wday[:i] or None
|
| 1526 |
+
w = wday[i:]
|
| 1527 |
+
if n:
|
| 1528 |
+
n = int(n)
|
| 1529 |
+
else:
|
| 1530 |
+
raise ValueError("Invalid (empty) BYDAY specification.")
|
| 1531 |
+
|
| 1532 |
+
l.append(weekdays[self._weekday_map[w]](n))
|
| 1533 |
+
rrkwargs["byweekday"] = l
|
| 1534 |
+
|
| 1535 |
+
_handle_BYDAY = _handle_BYWEEKDAY
|
| 1536 |
+
|
| 1537 |
+
def _parse_rfc_rrule(self, line,
|
| 1538 |
+
dtstart=None,
|
| 1539 |
+
cache=False,
|
| 1540 |
+
ignoretz=False,
|
| 1541 |
+
tzinfos=None):
|
| 1542 |
+
if line.find(':') != -1:
|
| 1543 |
+
name, value = line.split(':')
|
| 1544 |
+
if name != "RRULE":
|
| 1545 |
+
raise ValueError("unknown parameter name")
|
| 1546 |
+
else:
|
| 1547 |
+
value = line
|
| 1548 |
+
rrkwargs = {}
|
| 1549 |
+
for pair in value.split(';'):
|
| 1550 |
+
name, value = pair.split('=')
|
| 1551 |
+
name = name.upper()
|
| 1552 |
+
value = value.upper()
|
| 1553 |
+
try:
|
| 1554 |
+
getattr(self, "_handle_"+name)(rrkwargs, name, value,
|
| 1555 |
+
ignoretz=ignoretz,
|
| 1556 |
+
tzinfos=tzinfos)
|
| 1557 |
+
except AttributeError:
|
| 1558 |
+
raise ValueError("unknown parameter '%s'" % name)
|
| 1559 |
+
except (KeyError, ValueError):
|
| 1560 |
+
raise ValueError("invalid '%s': %s" % (name, value))
|
| 1561 |
+
return rrule(dtstart=dtstart, cache=cache, **rrkwargs)
|
| 1562 |
+
|
| 1563 |
+
def _parse_date_value(self, date_value, parms, rule_tzids,
|
| 1564 |
+
ignoretz, tzids, tzinfos):
|
| 1565 |
+
global parser
|
| 1566 |
+
if not parser:
|
| 1567 |
+
from dateutil import parser
|
| 1568 |
+
|
| 1569 |
+
datevals = []
|
| 1570 |
+
value_found = False
|
| 1571 |
+
TZID = None
|
| 1572 |
+
|
| 1573 |
+
for parm in parms:
|
| 1574 |
+
if parm.startswith("TZID="):
|
| 1575 |
+
try:
|
| 1576 |
+
tzkey = rule_tzids[parm.split('TZID=')[-1]]
|
| 1577 |
+
except KeyError:
|
| 1578 |
+
continue
|
| 1579 |
+
if tzids is None:
|
| 1580 |
+
from . import tz
|
| 1581 |
+
tzlookup = tz.gettz
|
| 1582 |
+
elif callable(tzids):
|
| 1583 |
+
tzlookup = tzids
|
| 1584 |
+
else:
|
| 1585 |
+
tzlookup = getattr(tzids, 'get', None)
|
| 1586 |
+
if tzlookup is None:
|
| 1587 |
+
msg = ('tzids must be a callable, mapping, or None, '
|
| 1588 |
+
'not %s' % tzids)
|
| 1589 |
+
raise ValueError(msg)
|
| 1590 |
+
|
| 1591 |
+
TZID = tzlookup(tzkey)
|
| 1592 |
+
continue
|
| 1593 |
+
|
| 1594 |
+
# RFC 5445 3.8.2.4: The VALUE parameter is optional, but may be found
|
| 1595 |
+
# only once.
|
| 1596 |
+
if parm not in {"VALUE=DATE-TIME", "VALUE=DATE"}:
|
| 1597 |
+
raise ValueError("unsupported parm: " + parm)
|
| 1598 |
+
else:
|
| 1599 |
+
if value_found:
|
| 1600 |
+
msg = ("Duplicate value parameter found in: " + parm)
|
| 1601 |
+
raise ValueError(msg)
|
| 1602 |
+
value_found = True
|
| 1603 |
+
|
| 1604 |
+
for datestr in date_value.split(','):
|
| 1605 |
+
date = parser.parse(datestr, ignoretz=ignoretz, tzinfos=tzinfos)
|
| 1606 |
+
if TZID is not None:
|
| 1607 |
+
if date.tzinfo is None:
|
| 1608 |
+
date = date.replace(tzinfo=TZID)
|
| 1609 |
+
else:
|
| 1610 |
+
raise ValueError('DTSTART/EXDATE specifies multiple timezone')
|
| 1611 |
+
datevals.append(date)
|
| 1612 |
+
|
| 1613 |
+
return datevals
|
| 1614 |
+
|
| 1615 |
+
def _parse_rfc(self, s,
|
| 1616 |
+
dtstart=None,
|
| 1617 |
+
cache=False,
|
| 1618 |
+
unfold=False,
|
| 1619 |
+
forceset=False,
|
| 1620 |
+
compatible=False,
|
| 1621 |
+
ignoretz=False,
|
| 1622 |
+
tzids=None,
|
| 1623 |
+
tzinfos=None):
|
| 1624 |
+
global parser
|
| 1625 |
+
if compatible:
|
| 1626 |
+
forceset = True
|
| 1627 |
+
unfold = True
|
| 1628 |
+
|
| 1629 |
+
TZID_NAMES = dict(map(
|
| 1630 |
+
lambda x: (x.upper(), x),
|
| 1631 |
+
re.findall('TZID=(?P<name>[^:]+):', s)
|
| 1632 |
+
))
|
| 1633 |
+
s = s.upper()
|
| 1634 |
+
if not s.strip():
|
| 1635 |
+
raise ValueError("empty string")
|
| 1636 |
+
if unfold:
|
| 1637 |
+
lines = s.splitlines()
|
| 1638 |
+
i = 0
|
| 1639 |
+
while i < len(lines):
|
| 1640 |
+
line = lines[i].rstrip()
|
| 1641 |
+
if not line:
|
| 1642 |
+
del lines[i]
|
| 1643 |
+
elif i > 0 and line[0] == " ":
|
| 1644 |
+
lines[i-1] += line[1:]
|
| 1645 |
+
del lines[i]
|
| 1646 |
+
else:
|
| 1647 |
+
i += 1
|
| 1648 |
+
else:
|
| 1649 |
+
lines = s.split()
|
| 1650 |
+
if (not forceset and len(lines) == 1 and (s.find(':') == -1 or
|
| 1651 |
+
s.startswith('RRULE:'))):
|
| 1652 |
+
return self._parse_rfc_rrule(lines[0], cache=cache,
|
| 1653 |
+
dtstart=dtstart, ignoretz=ignoretz,
|
| 1654 |
+
tzinfos=tzinfos)
|
| 1655 |
+
else:
|
| 1656 |
+
rrulevals = []
|
| 1657 |
+
rdatevals = []
|
| 1658 |
+
exrulevals = []
|
| 1659 |
+
exdatevals = []
|
| 1660 |
+
for line in lines:
|
| 1661 |
+
if not line:
|
| 1662 |
+
continue
|
| 1663 |
+
if line.find(':') == -1:
|
| 1664 |
+
name = "RRULE"
|
| 1665 |
+
value = line
|
| 1666 |
+
else:
|
| 1667 |
+
name, value = line.split(':', 1)
|
| 1668 |
+
parms = name.split(';')
|
| 1669 |
+
if not parms:
|
| 1670 |
+
raise ValueError("empty property name")
|
| 1671 |
+
name = parms[0]
|
| 1672 |
+
parms = parms[1:]
|
| 1673 |
+
if name == "RRULE":
|
| 1674 |
+
for parm in parms:
|
| 1675 |
+
raise ValueError("unsupported RRULE parm: "+parm)
|
| 1676 |
+
rrulevals.append(value)
|
| 1677 |
+
elif name == "RDATE":
|
| 1678 |
+
for parm in parms:
|
| 1679 |
+
if parm != "VALUE=DATE-TIME":
|
| 1680 |
+
raise ValueError("unsupported RDATE parm: "+parm)
|
| 1681 |
+
rdatevals.append(value)
|
| 1682 |
+
elif name == "EXRULE":
|
| 1683 |
+
for parm in parms:
|
| 1684 |
+
raise ValueError("unsupported EXRULE parm: "+parm)
|
| 1685 |
+
exrulevals.append(value)
|
| 1686 |
+
elif name == "EXDATE":
|
| 1687 |
+
exdatevals.extend(
|
| 1688 |
+
self._parse_date_value(value, parms,
|
| 1689 |
+
TZID_NAMES, ignoretz,
|
| 1690 |
+
tzids, tzinfos)
|
| 1691 |
+
)
|
| 1692 |
+
elif name == "DTSTART":
|
| 1693 |
+
dtvals = self._parse_date_value(value, parms, TZID_NAMES,
|
| 1694 |
+
ignoretz, tzids, tzinfos)
|
| 1695 |
+
if len(dtvals) != 1:
|
| 1696 |
+
raise ValueError("Multiple DTSTART values specified:" +
|
| 1697 |
+
value)
|
| 1698 |
+
dtstart = dtvals[0]
|
| 1699 |
+
else:
|
| 1700 |
+
raise ValueError("unsupported property: "+name)
|
| 1701 |
+
if (forceset or len(rrulevals) > 1 or rdatevals
|
| 1702 |
+
or exrulevals or exdatevals):
|
| 1703 |
+
if not parser and (rdatevals or exdatevals):
|
| 1704 |
+
from dateutil import parser
|
| 1705 |
+
rset = rruleset(cache=cache)
|
| 1706 |
+
for value in rrulevals:
|
| 1707 |
+
rset.rrule(self._parse_rfc_rrule(value, dtstart=dtstart,
|
| 1708 |
+
ignoretz=ignoretz,
|
| 1709 |
+
tzinfos=tzinfos))
|
| 1710 |
+
for value in rdatevals:
|
| 1711 |
+
for datestr in value.split(','):
|
| 1712 |
+
rset.rdate(parser.parse(datestr,
|
| 1713 |
+
ignoretz=ignoretz,
|
| 1714 |
+
tzinfos=tzinfos))
|
| 1715 |
+
for value in exrulevals:
|
| 1716 |
+
rset.exrule(self._parse_rfc_rrule(value, dtstart=dtstart,
|
| 1717 |
+
ignoretz=ignoretz,
|
| 1718 |
+
tzinfos=tzinfos))
|
| 1719 |
+
for value in exdatevals:
|
| 1720 |
+
rset.exdate(value)
|
| 1721 |
+
if compatible and dtstart:
|
| 1722 |
+
rset.rdate(dtstart)
|
| 1723 |
+
return rset
|
| 1724 |
+
else:
|
| 1725 |
+
return self._parse_rfc_rrule(rrulevals[0],
|
| 1726 |
+
dtstart=dtstart,
|
| 1727 |
+
cache=cache,
|
| 1728 |
+
ignoretz=ignoretz,
|
| 1729 |
+
tzinfos=tzinfos)
|
| 1730 |
+
|
| 1731 |
+
def __call__(self, s, **kwargs):
|
| 1732 |
+
return self._parse_rfc(s, **kwargs)
|
| 1733 |
+
|
| 1734 |
+
|
| 1735 |
+
rrulestr = _rrulestr()
|
| 1736 |
+
|
| 1737 |
+
# vim:ts=4:sw=4:et
|
vllm/lib/python3.10/site-packages/dateutil/tz/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from .tz import *
|
| 3 |
+
from .tz import __doc__
|
| 4 |
+
|
| 5 |
+
__all__ = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
|
| 6 |
+
"tzstr", "tzical", "tzwin", "tzwinlocal", "gettz",
|
| 7 |
+
"enfold", "datetime_ambiguous", "datetime_exists",
|
| 8 |
+
"resolve_imaginary", "UTC", "DeprecatedTzFormatWarning"]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class DeprecatedTzFormatWarning(Warning):
|
| 12 |
+
"""Warning raised when time zones are parsed from deprecated formats."""
|
vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (651 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/_common.cpython-310.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/_factories.cpython-310.pyc
ADDED
|
Binary file (2.92 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/tz.cpython-310.pyc
ADDED
|
Binary file (44.9 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dateutil/tz/__pycache__/win.cpython-310.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dateutil/tz/_common.py
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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3 |
+
from functools import wraps
|
| 4 |
+
|
| 5 |
+
from datetime import datetime, timedelta, tzinfo
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
ZERO = timedelta(0)
|
| 9 |
+
|
| 10 |
+
__all__ = ['tzname_in_python2', 'enfold']
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def tzname_in_python2(namefunc):
|
| 14 |
+
"""Change unicode output into bytestrings in Python 2
|
| 15 |
+
|
| 16 |
+
tzname() API changed in Python 3. It used to return bytes, but was changed
|
| 17 |
+
to unicode strings
|
| 18 |
+
"""
|
| 19 |
+
if PY2:
|
| 20 |
+
@wraps(namefunc)
|
| 21 |
+
def adjust_encoding(*args, **kwargs):
|
| 22 |
+
name = namefunc(*args, **kwargs)
|
| 23 |
+
if name is not None:
|
| 24 |
+
name = name.encode()
|
| 25 |
+
|
| 26 |
+
return name
|
| 27 |
+
|
| 28 |
+
return adjust_encoding
|
| 29 |
+
else:
|
| 30 |
+
return namefunc
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# The following is adapted from Alexander Belopolsky's tz library
|
| 34 |
+
# https://github.com/abalkin/tz
|
| 35 |
+
if hasattr(datetime, 'fold'):
|
| 36 |
+
# This is the pre-python 3.6 fold situation
|
| 37 |
+
def enfold(dt, fold=1):
|
| 38 |
+
"""
|
| 39 |
+
Provides a unified interface for assigning the ``fold`` attribute to
|
| 40 |
+
datetimes both before and after the implementation of PEP-495.
|
| 41 |
+
|
| 42 |
+
:param fold:
|
| 43 |
+
The value for the ``fold`` attribute in the returned datetime. This
|
| 44 |
+
should be either 0 or 1.
|
| 45 |
+
|
| 46 |
+
:return:
|
| 47 |
+
Returns an object for which ``getattr(dt, 'fold', 0)`` returns
|
| 48 |
+
``fold`` for all versions of Python. In versions prior to
|
| 49 |
+
Python 3.6, this is a ``_DatetimeWithFold`` object, which is a
|
| 50 |
+
subclass of :py:class:`datetime.datetime` with the ``fold``
|
| 51 |
+
attribute added, if ``fold`` is 1.
|
| 52 |
+
|
| 53 |
+
.. versionadded:: 2.6.0
|
| 54 |
+
"""
|
| 55 |
+
return dt.replace(fold=fold)
|
| 56 |
+
|
| 57 |
+
else:
|
| 58 |
+
class _DatetimeWithFold(datetime):
|
| 59 |
+
"""
|
| 60 |
+
This is a class designed to provide a PEP 495-compliant interface for
|
| 61 |
+
Python versions before 3.6. It is used only for dates in a fold, so
|
| 62 |
+
the ``fold`` attribute is fixed at ``1``.
|
| 63 |
+
|
| 64 |
+
.. versionadded:: 2.6.0
|
| 65 |
+
"""
|
| 66 |
+
__slots__ = ()
|
| 67 |
+
|
| 68 |
+
def replace(self, *args, **kwargs):
|
| 69 |
+
"""
|
| 70 |
+
Return a datetime with the same attributes, except for those
|
| 71 |
+
attributes given new values by whichever keyword arguments are
|
| 72 |
+
specified. Note that tzinfo=None can be specified to create a naive
|
| 73 |
+
datetime from an aware datetime with no conversion of date and time
|
| 74 |
+
data.
|
| 75 |
+
|
| 76 |
+
This is reimplemented in ``_DatetimeWithFold`` because pypy3 will
|
| 77 |
+
return a ``datetime.datetime`` even if ``fold`` is unchanged.
|
| 78 |
+
"""
|
| 79 |
+
argnames = (
|
| 80 |
+
'year', 'month', 'day', 'hour', 'minute', 'second',
|
| 81 |
+
'microsecond', 'tzinfo'
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
for arg, argname in zip(args, argnames):
|
| 85 |
+
if argname in kwargs:
|
| 86 |
+
raise TypeError('Duplicate argument: {}'.format(argname))
|
| 87 |
+
|
| 88 |
+
kwargs[argname] = arg
|
| 89 |
+
|
| 90 |
+
for argname in argnames:
|
| 91 |
+
if argname not in kwargs:
|
| 92 |
+
kwargs[argname] = getattr(self, argname)
|
| 93 |
+
|
| 94 |
+
dt_class = self.__class__ if kwargs.get('fold', 1) else datetime
|
| 95 |
+
|
| 96 |
+
return dt_class(**kwargs)
|
| 97 |
+
|
| 98 |
+
@property
|
| 99 |
+
def fold(self):
|
| 100 |
+
return 1
|
| 101 |
+
|
| 102 |
+
def enfold(dt, fold=1):
|
| 103 |
+
"""
|
| 104 |
+
Provides a unified interface for assigning the ``fold`` attribute to
|
| 105 |
+
datetimes both before and after the implementation of PEP-495.
|
| 106 |
+
|
| 107 |
+
:param fold:
|
| 108 |
+
The value for the ``fold`` attribute in the returned datetime. This
|
| 109 |
+
should be either 0 or 1.
|
| 110 |
+
|
| 111 |
+
:return:
|
| 112 |
+
Returns an object for which ``getattr(dt, 'fold', 0)`` returns
|
| 113 |
+
``fold`` for all versions of Python. In versions prior to
|
| 114 |
+
Python 3.6, this is a ``_DatetimeWithFold`` object, which is a
|
| 115 |
+
subclass of :py:class:`datetime.datetime` with the ``fold``
|
| 116 |
+
attribute added, if ``fold`` is 1.
|
| 117 |
+
|
| 118 |
+
.. versionadded:: 2.6.0
|
| 119 |
+
"""
|
| 120 |
+
if getattr(dt, 'fold', 0) == fold:
|
| 121 |
+
return dt
|
| 122 |
+
|
| 123 |
+
args = dt.timetuple()[:6]
|
| 124 |
+
args += (dt.microsecond, dt.tzinfo)
|
| 125 |
+
|
| 126 |
+
if fold:
|
| 127 |
+
return _DatetimeWithFold(*args)
|
| 128 |
+
else:
|
| 129 |
+
return datetime(*args)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def _validate_fromutc_inputs(f):
|
| 133 |
+
"""
|
| 134 |
+
The CPython version of ``fromutc`` checks that the input is a ``datetime``
|
| 135 |
+
object and that ``self`` is attached as its ``tzinfo``.
|
| 136 |
+
"""
|
| 137 |
+
@wraps(f)
|
| 138 |
+
def fromutc(self, dt):
|
| 139 |
+
if not isinstance(dt, datetime):
|
| 140 |
+
raise TypeError("fromutc() requires a datetime argument")
|
| 141 |
+
if dt.tzinfo is not self:
|
| 142 |
+
raise ValueError("dt.tzinfo is not self")
|
| 143 |
+
|
| 144 |
+
return f(self, dt)
|
| 145 |
+
|
| 146 |
+
return fromutc
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class _tzinfo(tzinfo):
|
| 150 |
+
"""
|
| 151 |
+
Base class for all ``dateutil`` ``tzinfo`` objects.
|
| 152 |
+
"""
|
| 153 |
+
|
| 154 |
+
def is_ambiguous(self, dt):
|
| 155 |
+
"""
|
| 156 |
+
Whether or not the "wall time" of a given datetime is ambiguous in this
|
| 157 |
+
zone.
|
| 158 |
+
|
| 159 |
+
:param dt:
|
| 160 |
+
A :py:class:`datetime.datetime`, naive or time zone aware.
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
:return:
|
| 164 |
+
Returns ``True`` if ambiguous, ``False`` otherwise.
|
| 165 |
+
|
| 166 |
+
.. versionadded:: 2.6.0
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
dt = dt.replace(tzinfo=self)
|
| 170 |
+
|
| 171 |
+
wall_0 = enfold(dt, fold=0)
|
| 172 |
+
wall_1 = enfold(dt, fold=1)
|
| 173 |
+
|
| 174 |
+
same_offset = wall_0.utcoffset() == wall_1.utcoffset()
|
| 175 |
+
same_dt = wall_0.replace(tzinfo=None) == wall_1.replace(tzinfo=None)
|
| 176 |
+
|
| 177 |
+
return same_dt and not same_offset
|
| 178 |
+
|
| 179 |
+
def _fold_status(self, dt_utc, dt_wall):
|
| 180 |
+
"""
|
| 181 |
+
Determine the fold status of a "wall" datetime, given a representation
|
| 182 |
+
of the same datetime as a (naive) UTC datetime. This is calculated based
|
| 183 |
+
on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all
|
| 184 |
+
datetimes, and that this offset is the actual number of hours separating
|
| 185 |
+
``dt_utc`` and ``dt_wall``.
|
| 186 |
+
|
| 187 |
+
:param dt_utc:
|
| 188 |
+
Representation of the datetime as UTC
|
| 189 |
+
|
| 190 |
+
:param dt_wall:
|
| 191 |
+
Representation of the datetime as "wall time". This parameter must
|
| 192 |
+
either have a `fold` attribute or have a fold-naive
|
| 193 |
+
:class:`datetime.tzinfo` attached, otherwise the calculation may
|
| 194 |
+
fail.
|
| 195 |
+
"""
|
| 196 |
+
if self.is_ambiguous(dt_wall):
|
| 197 |
+
delta_wall = dt_wall - dt_utc
|
| 198 |
+
_fold = int(delta_wall == (dt_utc.utcoffset() - dt_utc.dst()))
|
| 199 |
+
else:
|
| 200 |
+
_fold = 0
|
| 201 |
+
|
| 202 |
+
return _fold
|
| 203 |
+
|
| 204 |
+
def _fold(self, dt):
|
| 205 |
+
return getattr(dt, 'fold', 0)
|
| 206 |
+
|
| 207 |
+
def _fromutc(self, dt):
|
| 208 |
+
"""
|
| 209 |
+
Given a timezone-aware datetime in a given timezone, calculates a
|
| 210 |
+
timezone-aware datetime in a new timezone.
|
| 211 |
+
|
| 212 |
+
Since this is the one time that we *know* we have an unambiguous
|
| 213 |
+
datetime object, we take this opportunity to determine whether the
|
| 214 |
+
datetime is ambiguous and in a "fold" state (e.g. if it's the first
|
| 215 |
+
occurrence, chronologically, of the ambiguous datetime).
|
| 216 |
+
|
| 217 |
+
:param dt:
|
| 218 |
+
A timezone-aware :class:`datetime.datetime` object.
|
| 219 |
+
"""
|
| 220 |
+
|
| 221 |
+
# Re-implement the algorithm from Python's datetime.py
|
| 222 |
+
dtoff = dt.utcoffset()
|
| 223 |
+
if dtoff is None:
|
| 224 |
+
raise ValueError("fromutc() requires a non-None utcoffset() "
|
| 225 |
+
"result")
|
| 226 |
+
|
| 227 |
+
# The original datetime.py code assumes that `dst()` defaults to
|
| 228 |
+
# zero during ambiguous times. PEP 495 inverts this presumption, so
|
| 229 |
+
# for pre-PEP 495 versions of python, we need to tweak the algorithm.
|
| 230 |
+
dtdst = dt.dst()
|
| 231 |
+
if dtdst is None:
|
| 232 |
+
raise ValueError("fromutc() requires a non-None dst() result")
|
| 233 |
+
delta = dtoff - dtdst
|
| 234 |
+
|
| 235 |
+
dt += delta
|
| 236 |
+
# Set fold=1 so we can default to being in the fold for
|
| 237 |
+
# ambiguous dates.
|
| 238 |
+
dtdst = enfold(dt, fold=1).dst()
|
| 239 |
+
if dtdst is None:
|
| 240 |
+
raise ValueError("fromutc(): dt.dst gave inconsistent "
|
| 241 |
+
"results; cannot convert")
|
| 242 |
+
return dt + dtdst
|
| 243 |
+
|
| 244 |
+
@_validate_fromutc_inputs
|
| 245 |
+
def fromutc(self, dt):
|
| 246 |
+
"""
|
| 247 |
+
Given a timezone-aware datetime in a given timezone, calculates a
|
| 248 |
+
timezone-aware datetime in a new timezone.
|
| 249 |
+
|
| 250 |
+
Since this is the one time that we *know* we have an unambiguous
|
| 251 |
+
datetime object, we take this opportunity to determine whether the
|
| 252 |
+
datetime is ambiguous and in a "fold" state (e.g. if it's the first
|
| 253 |
+
occurrence, chronologically, of the ambiguous datetime).
|
| 254 |
+
|
| 255 |
+
:param dt:
|
| 256 |
+
A timezone-aware :class:`datetime.datetime` object.
|
| 257 |
+
"""
|
| 258 |
+
dt_wall = self._fromutc(dt)
|
| 259 |
+
|
| 260 |
+
# Calculate the fold status given the two datetimes.
|
| 261 |
+
_fold = self._fold_status(dt, dt_wall)
|
| 262 |
+
|
| 263 |
+
# Set the default fold value for ambiguous dates
|
| 264 |
+
return enfold(dt_wall, fold=_fold)
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
class tzrangebase(_tzinfo):
|
| 268 |
+
"""
|
| 269 |
+
This is an abstract base class for time zones represented by an annual
|
| 270 |
+
transition into and out of DST. Child classes should implement the following
|
| 271 |
+
methods:
|
| 272 |
+
|
| 273 |
+
* ``__init__(self, *args, **kwargs)``
|
| 274 |
+
* ``transitions(self, year)`` - this is expected to return a tuple of
|
| 275 |
+
datetimes representing the DST on and off transitions in standard
|
| 276 |
+
time.
|
| 277 |
+
|
| 278 |
+
A fully initialized ``tzrangebase`` subclass should also provide the
|
| 279 |
+
following attributes:
|
| 280 |
+
* ``hasdst``: Boolean whether or not the zone uses DST.
|
| 281 |
+
* ``_dst_offset`` / ``_std_offset``: :class:`datetime.timedelta` objects
|
| 282 |
+
representing the respective UTC offsets.
|
| 283 |
+
* ``_dst_abbr`` / ``_std_abbr``: Strings representing the timezone short
|
| 284 |
+
abbreviations in DST and STD, respectively.
|
| 285 |
+
* ``_hasdst``: Whether or not the zone has DST.
|
| 286 |
+
|
| 287 |
+
.. versionadded:: 2.6.0
|
| 288 |
+
"""
|
| 289 |
+
def __init__(self):
|
| 290 |
+
raise NotImplementedError('tzrangebase is an abstract base class')
|
| 291 |
+
|
| 292 |
+
def utcoffset(self, dt):
|
| 293 |
+
isdst = self._isdst(dt)
|
| 294 |
+
|
| 295 |
+
if isdst is None:
|
| 296 |
+
return None
|
| 297 |
+
elif isdst:
|
| 298 |
+
return self._dst_offset
|
| 299 |
+
else:
|
| 300 |
+
return self._std_offset
|
| 301 |
+
|
| 302 |
+
def dst(self, dt):
|
| 303 |
+
isdst = self._isdst(dt)
|
| 304 |
+
|
| 305 |
+
if isdst is None:
|
| 306 |
+
return None
|
| 307 |
+
elif isdst:
|
| 308 |
+
return self._dst_base_offset
|
| 309 |
+
else:
|
| 310 |
+
return ZERO
|
| 311 |
+
|
| 312 |
+
@tzname_in_python2
|
| 313 |
+
def tzname(self, dt):
|
| 314 |
+
if self._isdst(dt):
|
| 315 |
+
return self._dst_abbr
|
| 316 |
+
else:
|
| 317 |
+
return self._std_abbr
|
| 318 |
+
|
| 319 |
+
def fromutc(self, dt):
|
| 320 |
+
""" Given a datetime in UTC, return local time """
|
| 321 |
+
if not isinstance(dt, datetime):
|
| 322 |
+
raise TypeError("fromutc() requires a datetime argument")
|
| 323 |
+
|
| 324 |
+
if dt.tzinfo is not self:
|
| 325 |
+
raise ValueError("dt.tzinfo is not self")
|
| 326 |
+
|
| 327 |
+
# Get transitions - if there are none, fixed offset
|
| 328 |
+
transitions = self.transitions(dt.year)
|
| 329 |
+
if transitions is None:
|
| 330 |
+
return dt + self.utcoffset(dt)
|
| 331 |
+
|
| 332 |
+
# Get the transition times in UTC
|
| 333 |
+
dston, dstoff = transitions
|
| 334 |
+
|
| 335 |
+
dston -= self._std_offset
|
| 336 |
+
dstoff -= self._std_offset
|
| 337 |
+
|
| 338 |
+
utc_transitions = (dston, dstoff)
|
| 339 |
+
dt_utc = dt.replace(tzinfo=None)
|
| 340 |
+
|
| 341 |
+
isdst = self._naive_isdst(dt_utc, utc_transitions)
|
| 342 |
+
|
| 343 |
+
if isdst:
|
| 344 |
+
dt_wall = dt + self._dst_offset
|
| 345 |
+
else:
|
| 346 |
+
dt_wall = dt + self._std_offset
|
| 347 |
+
|
| 348 |
+
_fold = int(not isdst and self.is_ambiguous(dt_wall))
|
| 349 |
+
|
| 350 |
+
return enfold(dt_wall, fold=_fold)
|
| 351 |
+
|
| 352 |
+
def is_ambiguous(self, dt):
|
| 353 |
+
"""
|
| 354 |
+
Whether or not the "wall time" of a given datetime is ambiguous in this
|
| 355 |
+
zone.
|
| 356 |
+
|
| 357 |
+
:param dt:
|
| 358 |
+
A :py:class:`datetime.datetime`, naive or time zone aware.
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
:return:
|
| 362 |
+
Returns ``True`` if ambiguous, ``False`` otherwise.
|
| 363 |
+
|
| 364 |
+
.. versionadded:: 2.6.0
|
| 365 |
+
"""
|
| 366 |
+
if not self.hasdst:
|
| 367 |
+
return False
|
| 368 |
+
|
| 369 |
+
start, end = self.transitions(dt.year)
|
| 370 |
+
|
| 371 |
+
dt = dt.replace(tzinfo=None)
|
| 372 |
+
return (end <= dt < end + self._dst_base_offset)
|
| 373 |
+
|
| 374 |
+
def _isdst(self, dt):
|
| 375 |
+
if not self.hasdst:
|
| 376 |
+
return False
|
| 377 |
+
elif dt is None:
|
| 378 |
+
return None
|
| 379 |
+
|
| 380 |
+
transitions = self.transitions(dt.year)
|
| 381 |
+
|
| 382 |
+
if transitions is None:
|
| 383 |
+
return False
|
| 384 |
+
|
| 385 |
+
dt = dt.replace(tzinfo=None)
|
| 386 |
+
|
| 387 |
+
isdst = self._naive_isdst(dt, transitions)
|
| 388 |
+
|
| 389 |
+
# Handle ambiguous dates
|
| 390 |
+
if not isdst and self.is_ambiguous(dt):
|
| 391 |
+
return not self._fold(dt)
|
| 392 |
+
else:
|
| 393 |
+
return isdst
|
| 394 |
+
|
| 395 |
+
def _naive_isdst(self, dt, transitions):
|
| 396 |
+
dston, dstoff = transitions
|
| 397 |
+
|
| 398 |
+
dt = dt.replace(tzinfo=None)
|
| 399 |
+
|
| 400 |
+
if dston < dstoff:
|
| 401 |
+
isdst = dston <= dt < dstoff
|
| 402 |
+
else:
|
| 403 |
+
isdst = not dstoff <= dt < dston
|
| 404 |
+
|
| 405 |
+
return isdst
|
| 406 |
+
|
| 407 |
+
@property
|
| 408 |
+
def _dst_base_offset(self):
|
| 409 |
+
return self._dst_offset - self._std_offset
|
| 410 |
+
|
| 411 |
+
__hash__ = None
|
| 412 |
+
|
| 413 |
+
def __ne__(self, other):
|
| 414 |
+
return not (self == other)
|
| 415 |
+
|
| 416 |
+
def __repr__(self):
|
| 417 |
+
return "%s(...)" % self.__class__.__name__
|
| 418 |
+
|
| 419 |
+
__reduce__ = object.__reduce__
|
vllm/lib/python3.10/site-packages/dateutil/tz/_factories.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import timedelta
|
| 2 |
+
import weakref
|
| 3 |
+
from collections import OrderedDict
|
| 4 |
+
|
| 5 |
+
from six.moves import _thread
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class _TzSingleton(type):
|
| 9 |
+
def __init__(cls, *args, **kwargs):
|
| 10 |
+
cls.__instance = None
|
| 11 |
+
super(_TzSingleton, cls).__init__(*args, **kwargs)
|
| 12 |
+
|
| 13 |
+
def __call__(cls):
|
| 14 |
+
if cls.__instance is None:
|
| 15 |
+
cls.__instance = super(_TzSingleton, cls).__call__()
|
| 16 |
+
return cls.__instance
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class _TzFactory(type):
|
| 20 |
+
def instance(cls, *args, **kwargs):
|
| 21 |
+
"""Alternate constructor that returns a fresh instance"""
|
| 22 |
+
return type.__call__(cls, *args, **kwargs)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class _TzOffsetFactory(_TzFactory):
|
| 26 |
+
def __init__(cls, *args, **kwargs):
|
| 27 |
+
cls.__instances = weakref.WeakValueDictionary()
|
| 28 |
+
cls.__strong_cache = OrderedDict()
|
| 29 |
+
cls.__strong_cache_size = 8
|
| 30 |
+
|
| 31 |
+
cls._cache_lock = _thread.allocate_lock()
|
| 32 |
+
|
| 33 |
+
def __call__(cls, name, offset):
|
| 34 |
+
if isinstance(offset, timedelta):
|
| 35 |
+
key = (name, offset.total_seconds())
|
| 36 |
+
else:
|
| 37 |
+
key = (name, offset)
|
| 38 |
+
|
| 39 |
+
instance = cls.__instances.get(key, None)
|
| 40 |
+
if instance is None:
|
| 41 |
+
instance = cls.__instances.setdefault(key,
|
| 42 |
+
cls.instance(name, offset))
|
| 43 |
+
|
| 44 |
+
# This lock may not be necessary in Python 3. See GH issue #901
|
| 45 |
+
with cls._cache_lock:
|
| 46 |
+
cls.__strong_cache[key] = cls.__strong_cache.pop(key, instance)
|
| 47 |
+
|
| 48 |
+
# Remove an item if the strong cache is overpopulated
|
| 49 |
+
if len(cls.__strong_cache) > cls.__strong_cache_size:
|
| 50 |
+
cls.__strong_cache.popitem(last=False)
|
| 51 |
+
|
| 52 |
+
return instance
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class _TzStrFactory(_TzFactory):
|
| 56 |
+
def __init__(cls, *args, **kwargs):
|
| 57 |
+
cls.__instances = weakref.WeakValueDictionary()
|
| 58 |
+
cls.__strong_cache = OrderedDict()
|
| 59 |
+
cls.__strong_cache_size = 8
|
| 60 |
+
|
| 61 |
+
cls.__cache_lock = _thread.allocate_lock()
|
| 62 |
+
|
| 63 |
+
def __call__(cls, s, posix_offset=False):
|
| 64 |
+
key = (s, posix_offset)
|
| 65 |
+
instance = cls.__instances.get(key, None)
|
| 66 |
+
|
| 67 |
+
if instance is None:
|
| 68 |
+
instance = cls.__instances.setdefault(key,
|
| 69 |
+
cls.instance(s, posix_offset))
|
| 70 |
+
|
| 71 |
+
# This lock may not be necessary in Python 3. See GH issue #901
|
| 72 |
+
with cls.__cache_lock:
|
| 73 |
+
cls.__strong_cache[key] = cls.__strong_cache.pop(key, instance)
|
| 74 |
+
|
| 75 |
+
# Remove an item if the strong cache is overpopulated
|
| 76 |
+
if len(cls.__strong_cache) > cls.__strong_cache_size:
|
| 77 |
+
cls.__strong_cache.popitem(last=False)
|
| 78 |
+
|
| 79 |
+
return instance
|
| 80 |
+
|
vllm/lib/python3.10/site-packages/dateutil/tz/tz.py
ADDED
|
@@ -0,0 +1,1849 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
This module offers timezone implementations subclassing the abstract
|
| 4 |
+
:py:class:`datetime.tzinfo` type. There are classes to handle tzfile format
|
| 5 |
+
files (usually are in :file:`/etc/localtime`, :file:`/usr/share/zoneinfo`,
|
| 6 |
+
etc), TZ environment string (in all known formats), given ranges (with help
|
| 7 |
+
from relative deltas), local machine timezone, fixed offset timezone, and UTC
|
| 8 |
+
timezone.
|
| 9 |
+
"""
|
| 10 |
+
import datetime
|
| 11 |
+
import struct
|
| 12 |
+
import time
|
| 13 |
+
import sys
|
| 14 |
+
import os
|
| 15 |
+
import bisect
|
| 16 |
+
import weakref
|
| 17 |
+
from collections import OrderedDict
|
| 18 |
+
|
| 19 |
+
import six
|
| 20 |
+
from six import string_types
|
| 21 |
+
from six.moves import _thread
|
| 22 |
+
from ._common import tzname_in_python2, _tzinfo
|
| 23 |
+
from ._common import tzrangebase, enfold
|
| 24 |
+
from ._common import _validate_fromutc_inputs
|
| 25 |
+
|
| 26 |
+
from ._factories import _TzSingleton, _TzOffsetFactory
|
| 27 |
+
from ._factories import _TzStrFactory
|
| 28 |
+
try:
|
| 29 |
+
from .win import tzwin, tzwinlocal
|
| 30 |
+
except ImportError:
|
| 31 |
+
tzwin = tzwinlocal = None
|
| 32 |
+
|
| 33 |
+
# For warning about rounding tzinfo
|
| 34 |
+
from warnings import warn
|
| 35 |
+
|
| 36 |
+
ZERO = datetime.timedelta(0)
|
| 37 |
+
EPOCH = datetime.datetime(1970, 1, 1, 0, 0)
|
| 38 |
+
EPOCHORDINAL = EPOCH.toordinal()
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@six.add_metaclass(_TzSingleton)
|
| 42 |
+
class tzutc(datetime.tzinfo):
|
| 43 |
+
"""
|
| 44 |
+
This is a tzinfo object that represents the UTC time zone.
|
| 45 |
+
|
| 46 |
+
**Examples:**
|
| 47 |
+
|
| 48 |
+
.. doctest::
|
| 49 |
+
|
| 50 |
+
>>> from datetime import *
|
| 51 |
+
>>> from dateutil.tz import *
|
| 52 |
+
|
| 53 |
+
>>> datetime.now()
|
| 54 |
+
datetime.datetime(2003, 9, 27, 9, 40, 1, 521290)
|
| 55 |
+
|
| 56 |
+
>>> datetime.now(tzutc())
|
| 57 |
+
datetime.datetime(2003, 9, 27, 12, 40, 12, 156379, tzinfo=tzutc())
|
| 58 |
+
|
| 59 |
+
>>> datetime.now(tzutc()).tzname()
|
| 60 |
+
'UTC'
|
| 61 |
+
|
| 62 |
+
.. versionchanged:: 2.7.0
|
| 63 |
+
``tzutc()`` is now a singleton, so the result of ``tzutc()`` will
|
| 64 |
+
always return the same object.
|
| 65 |
+
|
| 66 |
+
.. doctest::
|
| 67 |
+
|
| 68 |
+
>>> from dateutil.tz import tzutc, UTC
|
| 69 |
+
>>> tzutc() is tzutc()
|
| 70 |
+
True
|
| 71 |
+
>>> tzutc() is UTC
|
| 72 |
+
True
|
| 73 |
+
"""
|
| 74 |
+
def utcoffset(self, dt):
|
| 75 |
+
return ZERO
|
| 76 |
+
|
| 77 |
+
def dst(self, dt):
|
| 78 |
+
return ZERO
|
| 79 |
+
|
| 80 |
+
@tzname_in_python2
|
| 81 |
+
def tzname(self, dt):
|
| 82 |
+
return "UTC"
|
| 83 |
+
|
| 84 |
+
def is_ambiguous(self, dt):
|
| 85 |
+
"""
|
| 86 |
+
Whether or not the "wall time" of a given datetime is ambiguous in this
|
| 87 |
+
zone.
|
| 88 |
+
|
| 89 |
+
:param dt:
|
| 90 |
+
A :py:class:`datetime.datetime`, naive or time zone aware.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
:return:
|
| 94 |
+
Returns ``True`` if ambiguous, ``False`` otherwise.
|
| 95 |
+
|
| 96 |
+
.. versionadded:: 2.6.0
|
| 97 |
+
"""
|
| 98 |
+
return False
|
| 99 |
+
|
| 100 |
+
@_validate_fromutc_inputs
|
| 101 |
+
def fromutc(self, dt):
|
| 102 |
+
"""
|
| 103 |
+
Fast track version of fromutc() returns the original ``dt`` object for
|
| 104 |
+
any valid :py:class:`datetime.datetime` object.
|
| 105 |
+
"""
|
| 106 |
+
return dt
|
| 107 |
+
|
| 108 |
+
def __eq__(self, other):
|
| 109 |
+
if not isinstance(other, (tzutc, tzoffset)):
|
| 110 |
+
return NotImplemented
|
| 111 |
+
|
| 112 |
+
return (isinstance(other, tzutc) or
|
| 113 |
+
(isinstance(other, tzoffset) and other._offset == ZERO))
|
| 114 |
+
|
| 115 |
+
__hash__ = None
|
| 116 |
+
|
| 117 |
+
def __ne__(self, other):
|
| 118 |
+
return not (self == other)
|
| 119 |
+
|
| 120 |
+
def __repr__(self):
|
| 121 |
+
return "%s()" % self.__class__.__name__
|
| 122 |
+
|
| 123 |
+
__reduce__ = object.__reduce__
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
#: Convenience constant providing a :class:`tzutc()` instance
|
| 127 |
+
#:
|
| 128 |
+
#: .. versionadded:: 2.7.0
|
| 129 |
+
UTC = tzutc()
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
@six.add_metaclass(_TzOffsetFactory)
|
| 133 |
+
class tzoffset(datetime.tzinfo):
|
| 134 |
+
"""
|
| 135 |
+
A simple class for representing a fixed offset from UTC.
|
| 136 |
+
|
| 137 |
+
:param name:
|
| 138 |
+
The timezone name, to be returned when ``tzname()`` is called.
|
| 139 |
+
:param offset:
|
| 140 |
+
The time zone offset in seconds, or (since version 2.6.0, represented
|
| 141 |
+
as a :py:class:`datetime.timedelta` object).
|
| 142 |
+
"""
|
| 143 |
+
def __init__(self, name, offset):
|
| 144 |
+
self._name = name
|
| 145 |
+
|
| 146 |
+
try:
|
| 147 |
+
# Allow a timedelta
|
| 148 |
+
offset = offset.total_seconds()
|
| 149 |
+
except (TypeError, AttributeError):
|
| 150 |
+
pass
|
| 151 |
+
|
| 152 |
+
self._offset = datetime.timedelta(seconds=_get_supported_offset(offset))
|
| 153 |
+
|
| 154 |
+
def utcoffset(self, dt):
|
| 155 |
+
return self._offset
|
| 156 |
+
|
| 157 |
+
def dst(self, dt):
|
| 158 |
+
return ZERO
|
| 159 |
+
|
| 160 |
+
@tzname_in_python2
|
| 161 |
+
def tzname(self, dt):
|
| 162 |
+
return self._name
|
| 163 |
+
|
| 164 |
+
@_validate_fromutc_inputs
|
| 165 |
+
def fromutc(self, dt):
|
| 166 |
+
return dt + self._offset
|
| 167 |
+
|
| 168 |
+
def is_ambiguous(self, dt):
|
| 169 |
+
"""
|
| 170 |
+
Whether or not the "wall time" of a given datetime is ambiguous in this
|
| 171 |
+
zone.
|
| 172 |
+
|
| 173 |
+
:param dt:
|
| 174 |
+
A :py:class:`datetime.datetime`, naive or time zone aware.
|
| 175 |
+
:return:
|
| 176 |
+
Returns ``True`` if ambiguous, ``False`` otherwise.
|
| 177 |
+
|
| 178 |
+
.. versionadded:: 2.6.0
|
| 179 |
+
"""
|
| 180 |
+
return False
|
| 181 |
+
|
| 182 |
+
def __eq__(self, other):
|
| 183 |
+
if not isinstance(other, tzoffset):
|
| 184 |
+
return NotImplemented
|
| 185 |
+
|
| 186 |
+
return self._offset == other._offset
|
| 187 |
+
|
| 188 |
+
__hash__ = None
|
| 189 |
+
|
| 190 |
+
def __ne__(self, other):
|
| 191 |
+
return not (self == other)
|
| 192 |
+
|
| 193 |
+
def __repr__(self):
|
| 194 |
+
return "%s(%s, %s)" % (self.__class__.__name__,
|
| 195 |
+
repr(self._name),
|
| 196 |
+
int(self._offset.total_seconds()))
|
| 197 |
+
|
| 198 |
+
__reduce__ = object.__reduce__
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class tzlocal(_tzinfo):
|
| 202 |
+
"""
|
| 203 |
+
A :class:`tzinfo` subclass built around the ``time`` timezone functions.
|
| 204 |
+
"""
|
| 205 |
+
def __init__(self):
|
| 206 |
+
super(tzlocal, self).__init__()
|
| 207 |
+
|
| 208 |
+
self._std_offset = datetime.timedelta(seconds=-time.timezone)
|
| 209 |
+
if time.daylight:
|
| 210 |
+
self._dst_offset = datetime.timedelta(seconds=-time.altzone)
|
| 211 |
+
else:
|
| 212 |
+
self._dst_offset = self._std_offset
|
| 213 |
+
|
| 214 |
+
self._dst_saved = self._dst_offset - self._std_offset
|
| 215 |
+
self._hasdst = bool(self._dst_saved)
|
| 216 |
+
self._tznames = tuple(time.tzname)
|
| 217 |
+
|
| 218 |
+
def utcoffset(self, dt):
|
| 219 |
+
if dt is None and self._hasdst:
|
| 220 |
+
return None
|
| 221 |
+
|
| 222 |
+
if self._isdst(dt):
|
| 223 |
+
return self._dst_offset
|
| 224 |
+
else:
|
| 225 |
+
return self._std_offset
|
| 226 |
+
|
| 227 |
+
def dst(self, dt):
|
| 228 |
+
if dt is None and self._hasdst:
|
| 229 |
+
return None
|
| 230 |
+
|
| 231 |
+
if self._isdst(dt):
|
| 232 |
+
return self._dst_offset - self._std_offset
|
| 233 |
+
else:
|
| 234 |
+
return ZERO
|
| 235 |
+
|
| 236 |
+
@tzname_in_python2
|
| 237 |
+
def tzname(self, dt):
|
| 238 |
+
return self._tznames[self._isdst(dt)]
|
| 239 |
+
|
| 240 |
+
def is_ambiguous(self, dt):
|
| 241 |
+
"""
|
| 242 |
+
Whether or not the "wall time" of a given datetime is ambiguous in this
|
| 243 |
+
zone.
|
| 244 |
+
|
| 245 |
+
:param dt:
|
| 246 |
+
A :py:class:`datetime.datetime`, naive or time zone aware.
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
:return:
|
| 250 |
+
Returns ``True`` if ambiguous, ``False`` otherwise.
|
| 251 |
+
|
| 252 |
+
.. versionadded:: 2.6.0
|
| 253 |
+
"""
|
| 254 |
+
naive_dst = self._naive_is_dst(dt)
|
| 255 |
+
return (not naive_dst and
|
| 256 |
+
(naive_dst != self._naive_is_dst(dt - self._dst_saved)))
|
| 257 |
+
|
| 258 |
+
def _naive_is_dst(self, dt):
|
| 259 |
+
timestamp = _datetime_to_timestamp(dt)
|
| 260 |
+
return time.localtime(timestamp + time.timezone).tm_isdst
|
| 261 |
+
|
| 262 |
+
def _isdst(self, dt, fold_naive=True):
|
| 263 |
+
# We can't use mktime here. It is unstable when deciding if
|
| 264 |
+
# the hour near to a change is DST or not.
|
| 265 |
+
#
|
| 266 |
+
# timestamp = time.mktime((dt.year, dt.month, dt.day, dt.hour,
|
| 267 |
+
# dt.minute, dt.second, dt.weekday(), 0, -1))
|
| 268 |
+
# return time.localtime(timestamp).tm_isdst
|
| 269 |
+
#
|
| 270 |
+
# The code above yields the following result:
|
| 271 |
+
#
|
| 272 |
+
# >>> import tz, datetime
|
| 273 |
+
# >>> t = tz.tzlocal()
|
| 274 |
+
# >>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
| 275 |
+
# 'BRDT'
|
| 276 |
+
# >>> datetime.datetime(2003,2,16,0,tzinfo=t).tzname()
|
| 277 |
+
# 'BRST'
|
| 278 |
+
# >>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
| 279 |
+
# 'BRST'
|
| 280 |
+
# >>> datetime.datetime(2003,2,15,22,tzinfo=t).tzname()
|
| 281 |
+
# 'BRDT'
|
| 282 |
+
# >>> datetime.datetime(2003,2,15,23,tzinfo=t).tzname()
|
| 283 |
+
# 'BRDT'
|
| 284 |
+
#
|
| 285 |
+
# Here is a more stable implementation:
|
| 286 |
+
#
|
| 287 |
+
if not self._hasdst:
|
| 288 |
+
return False
|
| 289 |
+
|
| 290 |
+
# Check for ambiguous times:
|
| 291 |
+
dstval = self._naive_is_dst(dt)
|
| 292 |
+
fold = getattr(dt, 'fold', None)
|
| 293 |
+
|
| 294 |
+
if self.is_ambiguous(dt):
|
| 295 |
+
if fold is not None:
|
| 296 |
+
return not self._fold(dt)
|
| 297 |
+
else:
|
| 298 |
+
return True
|
| 299 |
+
|
| 300 |
+
return dstval
|
| 301 |
+
|
| 302 |
+
def __eq__(self, other):
|
| 303 |
+
if isinstance(other, tzlocal):
|
| 304 |
+
return (self._std_offset == other._std_offset and
|
| 305 |
+
self._dst_offset == other._dst_offset)
|
| 306 |
+
elif isinstance(other, tzutc):
|
| 307 |
+
return (not self._hasdst and
|
| 308 |
+
self._tznames[0] in {'UTC', 'GMT'} and
|
| 309 |
+
self._std_offset == ZERO)
|
| 310 |
+
elif isinstance(other, tzoffset):
|
| 311 |
+
return (not self._hasdst and
|
| 312 |
+
self._tznames[0] == other._name and
|
| 313 |
+
self._std_offset == other._offset)
|
| 314 |
+
else:
|
| 315 |
+
return NotImplemented
|
| 316 |
+
|
| 317 |
+
__hash__ = None
|
| 318 |
+
|
| 319 |
+
def __ne__(self, other):
|
| 320 |
+
return not (self == other)
|
| 321 |
+
|
| 322 |
+
def __repr__(self):
|
| 323 |
+
return "%s()" % self.__class__.__name__
|
| 324 |
+
|
| 325 |
+
__reduce__ = object.__reduce__
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
class _ttinfo(object):
|
| 329 |
+
__slots__ = ["offset", "delta", "isdst", "abbr",
|
| 330 |
+
"isstd", "isgmt", "dstoffset"]
|
| 331 |
+
|
| 332 |
+
def __init__(self):
|
| 333 |
+
for attr in self.__slots__:
|
| 334 |
+
setattr(self, attr, None)
|
| 335 |
+
|
| 336 |
+
def __repr__(self):
|
| 337 |
+
l = []
|
| 338 |
+
for attr in self.__slots__:
|
| 339 |
+
value = getattr(self, attr)
|
| 340 |
+
if value is not None:
|
| 341 |
+
l.append("%s=%s" % (attr, repr(value)))
|
| 342 |
+
return "%s(%s)" % (self.__class__.__name__, ", ".join(l))
|
| 343 |
+
|
| 344 |
+
def __eq__(self, other):
|
| 345 |
+
if not isinstance(other, _ttinfo):
|
| 346 |
+
return NotImplemented
|
| 347 |
+
|
| 348 |
+
return (self.offset == other.offset and
|
| 349 |
+
self.delta == other.delta and
|
| 350 |
+
self.isdst == other.isdst and
|
| 351 |
+
self.abbr == other.abbr and
|
| 352 |
+
self.isstd == other.isstd and
|
| 353 |
+
self.isgmt == other.isgmt and
|
| 354 |
+
self.dstoffset == other.dstoffset)
|
| 355 |
+
|
| 356 |
+
__hash__ = None
|
| 357 |
+
|
| 358 |
+
def __ne__(self, other):
|
| 359 |
+
return not (self == other)
|
| 360 |
+
|
| 361 |
+
def __getstate__(self):
|
| 362 |
+
state = {}
|
| 363 |
+
for name in self.__slots__:
|
| 364 |
+
state[name] = getattr(self, name, None)
|
| 365 |
+
return state
|
| 366 |
+
|
| 367 |
+
def __setstate__(self, state):
|
| 368 |
+
for name in self.__slots__:
|
| 369 |
+
if name in state:
|
| 370 |
+
setattr(self, name, state[name])
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
class _tzfile(object):
|
| 374 |
+
"""
|
| 375 |
+
Lightweight class for holding the relevant transition and time zone
|
| 376 |
+
information read from binary tzfiles.
|
| 377 |
+
"""
|
| 378 |
+
attrs = ['trans_list', 'trans_list_utc', 'trans_idx', 'ttinfo_list',
|
| 379 |
+
'ttinfo_std', 'ttinfo_dst', 'ttinfo_before', 'ttinfo_first']
|
| 380 |
+
|
| 381 |
+
def __init__(self, **kwargs):
|
| 382 |
+
for attr in self.attrs:
|
| 383 |
+
setattr(self, attr, kwargs.get(attr, None))
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
class tzfile(_tzinfo):
|
| 387 |
+
"""
|
| 388 |
+
This is a ``tzinfo`` subclass that allows one to use the ``tzfile(5)``
|
| 389 |
+
format timezone files to extract current and historical zone information.
|
| 390 |
+
|
| 391 |
+
:param fileobj:
|
| 392 |
+
This can be an opened file stream or a file name that the time zone
|
| 393 |
+
information can be read from.
|
| 394 |
+
|
| 395 |
+
:param filename:
|
| 396 |
+
This is an optional parameter specifying the source of the time zone
|
| 397 |
+
information in the event that ``fileobj`` is a file object. If omitted
|
| 398 |
+
and ``fileobj`` is a file stream, this parameter will be set either to
|
| 399 |
+
``fileobj``'s ``name`` attribute or to ``repr(fileobj)``.
|
| 400 |
+
|
| 401 |
+
See `Sources for Time Zone and Daylight Saving Time Data
|
| 402 |
+
<https://data.iana.org/time-zones/tz-link.html>`_ for more information.
|
| 403 |
+
Time zone files can be compiled from the `IANA Time Zone database files
|
| 404 |
+
<https://www.iana.org/time-zones>`_ with the `zic time zone compiler
|
| 405 |
+
<https://www.freebsd.org/cgi/man.cgi?query=zic&sektion=8>`_
|
| 406 |
+
|
| 407 |
+
.. note::
|
| 408 |
+
|
| 409 |
+
Only construct a ``tzfile`` directly if you have a specific timezone
|
| 410 |
+
file on disk that you want to read into a Python ``tzinfo`` object.
|
| 411 |
+
If you want to get a ``tzfile`` representing a specific IANA zone,
|
| 412 |
+
(e.g. ``'America/New_York'``), you should call
|
| 413 |
+
:func:`dateutil.tz.gettz` with the zone identifier.
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
**Examples:**
|
| 417 |
+
|
| 418 |
+
Using the US Eastern time zone as an example, we can see that a ``tzfile``
|
| 419 |
+
provides time zone information for the standard Daylight Saving offsets:
|
| 420 |
+
|
| 421 |
+
.. testsetup:: tzfile
|
| 422 |
+
|
| 423 |
+
from dateutil.tz import gettz
|
| 424 |
+
from datetime import datetime
|
| 425 |
+
|
| 426 |
+
.. doctest:: tzfile
|
| 427 |
+
|
| 428 |
+
>>> NYC = gettz('America/New_York')
|
| 429 |
+
>>> NYC
|
| 430 |
+
tzfile('/usr/share/zoneinfo/America/New_York')
|
| 431 |
+
|
| 432 |
+
>>> print(datetime(2016, 1, 3, tzinfo=NYC)) # EST
|
| 433 |
+
2016-01-03 00:00:00-05:00
|
| 434 |
+
|
| 435 |
+
>>> print(datetime(2016, 7, 7, tzinfo=NYC)) # EDT
|
| 436 |
+
2016-07-07 00:00:00-04:00
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
The ``tzfile`` structure contains a fully history of the time zone,
|
| 440 |
+
so historical dates will also have the right offsets. For example, before
|
| 441 |
+
the adoption of the UTC standards, New York used local solar mean time:
|
| 442 |
+
|
| 443 |
+
.. doctest:: tzfile
|
| 444 |
+
|
| 445 |
+
>>> print(datetime(1901, 4, 12, tzinfo=NYC)) # LMT
|
| 446 |
+
1901-04-12 00:00:00-04:56
|
| 447 |
+
|
| 448 |
+
And during World War II, New York was on "Eastern War Time", which was a
|
| 449 |
+
state of permanent daylight saving time:
|
| 450 |
+
|
| 451 |
+
.. doctest:: tzfile
|
| 452 |
+
|
| 453 |
+
>>> print(datetime(1944, 2, 7, tzinfo=NYC)) # EWT
|
| 454 |
+
1944-02-07 00:00:00-04:00
|
| 455 |
+
|
| 456 |
+
"""
|
| 457 |
+
|
| 458 |
+
def __init__(self, fileobj, filename=None):
|
| 459 |
+
super(tzfile, self).__init__()
|
| 460 |
+
|
| 461 |
+
file_opened_here = False
|
| 462 |
+
if isinstance(fileobj, string_types):
|
| 463 |
+
self._filename = fileobj
|
| 464 |
+
fileobj = open(fileobj, 'rb')
|
| 465 |
+
file_opened_here = True
|
| 466 |
+
elif filename is not None:
|
| 467 |
+
self._filename = filename
|
| 468 |
+
elif hasattr(fileobj, "name"):
|
| 469 |
+
self._filename = fileobj.name
|
| 470 |
+
else:
|
| 471 |
+
self._filename = repr(fileobj)
|
| 472 |
+
|
| 473 |
+
if fileobj is not None:
|
| 474 |
+
if not file_opened_here:
|
| 475 |
+
fileobj = _nullcontext(fileobj)
|
| 476 |
+
|
| 477 |
+
with fileobj as file_stream:
|
| 478 |
+
tzobj = self._read_tzfile(file_stream)
|
| 479 |
+
|
| 480 |
+
self._set_tzdata(tzobj)
|
| 481 |
+
|
| 482 |
+
def _set_tzdata(self, tzobj):
|
| 483 |
+
""" Set the time zone data of this object from a _tzfile object """
|
| 484 |
+
# Copy the relevant attributes over as private attributes
|
| 485 |
+
for attr in _tzfile.attrs:
|
| 486 |
+
setattr(self, '_' + attr, getattr(tzobj, attr))
|
| 487 |
+
|
| 488 |
+
def _read_tzfile(self, fileobj):
|
| 489 |
+
out = _tzfile()
|
| 490 |
+
|
| 491 |
+
# From tzfile(5):
|
| 492 |
+
#
|
| 493 |
+
# The time zone information files used by tzset(3)
|
| 494 |
+
# begin with the magic characters "TZif" to identify
|
| 495 |
+
# them as time zone information files, followed by
|
| 496 |
+
# sixteen bytes reserved for future use, followed by
|
| 497 |
+
# six four-byte values of type long, written in a
|
| 498 |
+
# ``standard'' byte order (the high-order byte
|
| 499 |
+
# of the value is written first).
|
| 500 |
+
if fileobj.read(4).decode() != "TZif":
|
| 501 |
+
raise ValueError("magic not found")
|
| 502 |
+
|
| 503 |
+
fileobj.read(16)
|
| 504 |
+
|
| 505 |
+
(
|
| 506 |
+
# The number of UTC/local indicators stored in the file.
|
| 507 |
+
ttisgmtcnt,
|
| 508 |
+
|
| 509 |
+
# The number of standard/wall indicators stored in the file.
|
| 510 |
+
ttisstdcnt,
|
| 511 |
+
|
| 512 |
+
# The number of leap seconds for which data is
|
| 513 |
+
# stored in the file.
|
| 514 |
+
leapcnt,
|
| 515 |
+
|
| 516 |
+
# The number of "transition times" for which data
|
| 517 |
+
# is stored in the file.
|
| 518 |
+
timecnt,
|
| 519 |
+
|
| 520 |
+
# The number of "local time types" for which data
|
| 521 |
+
# is stored in the file (must not be zero).
|
| 522 |
+
typecnt,
|
| 523 |
+
|
| 524 |
+
# The number of characters of "time zone
|
| 525 |
+
# abbreviation strings" stored in the file.
|
| 526 |
+
charcnt,
|
| 527 |
+
|
| 528 |
+
) = struct.unpack(">6l", fileobj.read(24))
|
| 529 |
+
|
| 530 |
+
# The above header is followed by tzh_timecnt four-byte
|
| 531 |
+
# values of type long, sorted in ascending order.
|
| 532 |
+
# These values are written in ``standard'' byte order.
|
| 533 |
+
# Each is used as a transition time (as returned by
|
| 534 |
+
# time(2)) at which the rules for computing local time
|
| 535 |
+
# change.
|
| 536 |
+
|
| 537 |
+
if timecnt:
|
| 538 |
+
out.trans_list_utc = list(struct.unpack(">%dl" % timecnt,
|
| 539 |
+
fileobj.read(timecnt*4)))
|
| 540 |
+
else:
|
| 541 |
+
out.trans_list_utc = []
|
| 542 |
+
|
| 543 |
+
# Next come tzh_timecnt one-byte values of type unsigned
|
| 544 |
+
# char; each one tells which of the different types of
|
| 545 |
+
# ``local time'' types described in the file is associated
|
| 546 |
+
# with the same-indexed transition time. These values
|
| 547 |
+
# serve as indices into an array of ttinfo structures that
|
| 548 |
+
# appears next in the file.
|
| 549 |
+
|
| 550 |
+
if timecnt:
|
| 551 |
+
out.trans_idx = struct.unpack(">%dB" % timecnt,
|
| 552 |
+
fileobj.read(timecnt))
|
| 553 |
+
else:
|
| 554 |
+
out.trans_idx = []
|
| 555 |
+
|
| 556 |
+
# Each ttinfo structure is written as a four-byte value
|
| 557 |
+
# for tt_gmtoff of type long, in a standard byte
|
| 558 |
+
# order, followed by a one-byte value for tt_isdst
|
| 559 |
+
# and a one-byte value for tt_abbrind. In each
|
| 560 |
+
# structure, tt_gmtoff gives the number of
|
| 561 |
+
# seconds to be added to UTC, tt_isdst tells whether
|
| 562 |
+
# tm_isdst should be set by localtime(3), and
|
| 563 |
+
# tt_abbrind serves as an index into the array of
|
| 564 |
+
# time zone abbreviation characters that follow the
|
| 565 |
+
# ttinfo structure(s) in the file.
|
| 566 |
+
|
| 567 |
+
ttinfo = []
|
| 568 |
+
|
| 569 |
+
for i in range(typecnt):
|
| 570 |
+
ttinfo.append(struct.unpack(">lbb", fileobj.read(6)))
|
| 571 |
+
|
| 572 |
+
abbr = fileobj.read(charcnt).decode()
|
| 573 |
+
|
| 574 |
+
# Then there are tzh_leapcnt pairs of four-byte
|
| 575 |
+
# values, written in standard byte order; the
|
| 576 |
+
# first value of each pair gives the time (as
|
| 577 |
+
# returned by time(2)) at which a leap second
|
| 578 |
+
# occurs; the second gives the total number of
|
| 579 |
+
# leap seconds to be applied after the given time.
|
| 580 |
+
# The pairs of values are sorted in ascending order
|
| 581 |
+
# by time.
|
| 582 |
+
|
| 583 |
+
# Not used, for now (but seek for correct file position)
|
| 584 |
+
if leapcnt:
|
| 585 |
+
fileobj.seek(leapcnt * 8, os.SEEK_CUR)
|
| 586 |
+
|
| 587 |
+
# Then there are tzh_ttisstdcnt standard/wall
|
| 588 |
+
# indicators, each stored as a one-byte value;
|
| 589 |
+
# they tell whether the transition times associated
|
| 590 |
+
# with local time types were specified as standard
|
| 591 |
+
# time or wall clock time, and are used when
|
| 592 |
+
# a time zone file is used in handling POSIX-style
|
| 593 |
+
# time zone environment variables.
|
| 594 |
+
|
| 595 |
+
if ttisstdcnt:
|
| 596 |
+
isstd = struct.unpack(">%db" % ttisstdcnt,
|
| 597 |
+
fileobj.read(ttisstdcnt))
|
| 598 |
+
|
| 599 |
+
# Finally, there are tzh_ttisgmtcnt UTC/local
|
| 600 |
+
# indicators, each stored as a one-byte value;
|
| 601 |
+
# they tell whether the transition times associated
|
| 602 |
+
# with local time types were specified as UTC or
|
| 603 |
+
# local time, and are used when a time zone file
|
| 604 |
+
# is used in handling POSIX-style time zone envi-
|
| 605 |
+
# ronment variables.
|
| 606 |
+
|
| 607 |
+
if ttisgmtcnt:
|
| 608 |
+
isgmt = struct.unpack(">%db" % ttisgmtcnt,
|
| 609 |
+
fileobj.read(ttisgmtcnt))
|
| 610 |
+
|
| 611 |
+
# Build ttinfo list
|
| 612 |
+
out.ttinfo_list = []
|
| 613 |
+
for i in range(typecnt):
|
| 614 |
+
gmtoff, isdst, abbrind = ttinfo[i]
|
| 615 |
+
gmtoff = _get_supported_offset(gmtoff)
|
| 616 |
+
tti = _ttinfo()
|
| 617 |
+
tti.offset = gmtoff
|
| 618 |
+
tti.dstoffset = datetime.timedelta(0)
|
| 619 |
+
tti.delta = datetime.timedelta(seconds=gmtoff)
|
| 620 |
+
tti.isdst = isdst
|
| 621 |
+
tti.abbr = abbr[abbrind:abbr.find('\x00', abbrind)]
|
| 622 |
+
tti.isstd = (ttisstdcnt > i and isstd[i] != 0)
|
| 623 |
+
tti.isgmt = (ttisgmtcnt > i and isgmt[i] != 0)
|
| 624 |
+
out.ttinfo_list.append(tti)
|
| 625 |
+
|
| 626 |
+
# Replace ttinfo indexes for ttinfo objects.
|
| 627 |
+
out.trans_idx = [out.ttinfo_list[idx] for idx in out.trans_idx]
|
| 628 |
+
|
| 629 |
+
# Set standard, dst, and before ttinfos. before will be
|
| 630 |
+
# used when a given time is before any transitions,
|
| 631 |
+
# and will be set to the first non-dst ttinfo, or to
|
| 632 |
+
# the first dst, if all of them are dst.
|
| 633 |
+
out.ttinfo_std = None
|
| 634 |
+
out.ttinfo_dst = None
|
| 635 |
+
out.ttinfo_before = None
|
| 636 |
+
if out.ttinfo_list:
|
| 637 |
+
if not out.trans_list_utc:
|
| 638 |
+
out.ttinfo_std = out.ttinfo_first = out.ttinfo_list[0]
|
| 639 |
+
else:
|
| 640 |
+
for i in range(timecnt-1, -1, -1):
|
| 641 |
+
tti = out.trans_idx[i]
|
| 642 |
+
if not out.ttinfo_std and not tti.isdst:
|
| 643 |
+
out.ttinfo_std = tti
|
| 644 |
+
elif not out.ttinfo_dst and tti.isdst:
|
| 645 |
+
out.ttinfo_dst = tti
|
| 646 |
+
|
| 647 |
+
if out.ttinfo_std and out.ttinfo_dst:
|
| 648 |
+
break
|
| 649 |
+
else:
|
| 650 |
+
if out.ttinfo_dst and not out.ttinfo_std:
|
| 651 |
+
out.ttinfo_std = out.ttinfo_dst
|
| 652 |
+
|
| 653 |
+
for tti in out.ttinfo_list:
|
| 654 |
+
if not tti.isdst:
|
| 655 |
+
out.ttinfo_before = tti
|
| 656 |
+
break
|
| 657 |
+
else:
|
| 658 |
+
out.ttinfo_before = out.ttinfo_list[0]
|
| 659 |
+
|
| 660 |
+
# Now fix transition times to become relative to wall time.
|
| 661 |
+
#
|
| 662 |
+
# I'm not sure about this. In my tests, the tz source file
|
| 663 |
+
# is setup to wall time, and in the binary file isstd and
|
| 664 |
+
# isgmt are off, so it should be in wall time. OTOH, it's
|
| 665 |
+
# always in gmt time. Let me know if you have comments
|
| 666 |
+
# about this.
|
| 667 |
+
lastdst = None
|
| 668 |
+
lastoffset = None
|
| 669 |
+
lastdstoffset = None
|
| 670 |
+
lastbaseoffset = None
|
| 671 |
+
out.trans_list = []
|
| 672 |
+
|
| 673 |
+
for i, tti in enumerate(out.trans_idx):
|
| 674 |
+
offset = tti.offset
|
| 675 |
+
dstoffset = 0
|
| 676 |
+
|
| 677 |
+
if lastdst is not None:
|
| 678 |
+
if tti.isdst:
|
| 679 |
+
if not lastdst:
|
| 680 |
+
dstoffset = offset - lastoffset
|
| 681 |
+
|
| 682 |
+
if not dstoffset and lastdstoffset:
|
| 683 |
+
dstoffset = lastdstoffset
|
| 684 |
+
|
| 685 |
+
tti.dstoffset = datetime.timedelta(seconds=dstoffset)
|
| 686 |
+
lastdstoffset = dstoffset
|
| 687 |
+
|
| 688 |
+
# If a time zone changes its base offset during a DST transition,
|
| 689 |
+
# then you need to adjust by the previous base offset to get the
|
| 690 |
+
# transition time in local time. Otherwise you use the current
|
| 691 |
+
# base offset. Ideally, I would have some mathematical proof of
|
| 692 |
+
# why this is true, but I haven't really thought about it enough.
|
| 693 |
+
baseoffset = offset - dstoffset
|
| 694 |
+
adjustment = baseoffset
|
| 695 |
+
if (lastbaseoffset is not None and baseoffset != lastbaseoffset
|
| 696 |
+
and tti.isdst != lastdst):
|
| 697 |
+
# The base DST has changed
|
| 698 |
+
adjustment = lastbaseoffset
|
| 699 |
+
|
| 700 |
+
lastdst = tti.isdst
|
| 701 |
+
lastoffset = offset
|
| 702 |
+
lastbaseoffset = baseoffset
|
| 703 |
+
|
| 704 |
+
out.trans_list.append(out.trans_list_utc[i] + adjustment)
|
| 705 |
+
|
| 706 |
+
out.trans_idx = tuple(out.trans_idx)
|
| 707 |
+
out.trans_list = tuple(out.trans_list)
|
| 708 |
+
out.trans_list_utc = tuple(out.trans_list_utc)
|
| 709 |
+
|
| 710 |
+
return out
|
| 711 |
+
|
| 712 |
+
def _find_last_transition(self, dt, in_utc=False):
|
| 713 |
+
# If there's no list, there are no transitions to find
|
| 714 |
+
if not self._trans_list:
|
| 715 |
+
return None
|
| 716 |
+
|
| 717 |
+
timestamp = _datetime_to_timestamp(dt)
|
| 718 |
+
|
| 719 |
+
# Find where the timestamp fits in the transition list - if the
|
| 720 |
+
# timestamp is a transition time, it's part of the "after" period.
|
| 721 |
+
trans_list = self._trans_list_utc if in_utc else self._trans_list
|
| 722 |
+
idx = bisect.bisect_right(trans_list, timestamp)
|
| 723 |
+
|
| 724 |
+
# We want to know when the previous transition was, so subtract off 1
|
| 725 |
+
return idx - 1
|
| 726 |
+
|
| 727 |
+
def _get_ttinfo(self, idx):
|
| 728 |
+
# For no list or after the last transition, default to _ttinfo_std
|
| 729 |
+
if idx is None or (idx + 1) >= len(self._trans_list):
|
| 730 |
+
return self._ttinfo_std
|
| 731 |
+
|
| 732 |
+
# If there is a list and the time is before it, return _ttinfo_before
|
| 733 |
+
if idx < 0:
|
| 734 |
+
return self._ttinfo_before
|
| 735 |
+
|
| 736 |
+
return self._trans_idx[idx]
|
| 737 |
+
|
| 738 |
+
def _find_ttinfo(self, dt):
|
| 739 |
+
idx = self._resolve_ambiguous_time(dt)
|
| 740 |
+
|
| 741 |
+
return self._get_ttinfo(idx)
|
| 742 |
+
|
| 743 |
+
def fromutc(self, dt):
|
| 744 |
+
"""
|
| 745 |
+
The ``tzfile`` implementation of :py:func:`datetime.tzinfo.fromutc`.
|
| 746 |
+
|
| 747 |
+
:param dt:
|
| 748 |
+
A :py:class:`datetime.datetime` object.
|
| 749 |
+
|
| 750 |
+
:raises TypeError:
|
| 751 |
+
Raised if ``dt`` is not a :py:class:`datetime.datetime` object.
|
| 752 |
+
|
| 753 |
+
:raises ValueError:
|
| 754 |
+
Raised if this is called with a ``dt`` which does not have this
|
| 755 |
+
``tzinfo`` attached.
|
| 756 |
+
|
| 757 |
+
:return:
|
| 758 |
+
Returns a :py:class:`datetime.datetime` object representing the
|
| 759 |
+
wall time in ``self``'s time zone.
|
| 760 |
+
"""
|
| 761 |
+
# These isinstance checks are in datetime.tzinfo, so we'll preserve
|
| 762 |
+
# them, even if we don't care about duck typing.
|
| 763 |
+
if not isinstance(dt, datetime.datetime):
|
| 764 |
+
raise TypeError("fromutc() requires a datetime argument")
|
| 765 |
+
|
| 766 |
+
if dt.tzinfo is not self:
|
| 767 |
+
raise ValueError("dt.tzinfo is not self")
|
| 768 |
+
|
| 769 |
+
# First treat UTC as wall time and get the transition we're in.
|
| 770 |
+
idx = self._find_last_transition(dt, in_utc=True)
|
| 771 |
+
tti = self._get_ttinfo(idx)
|
| 772 |
+
|
| 773 |
+
dt_out = dt + datetime.timedelta(seconds=tti.offset)
|
| 774 |
+
|
| 775 |
+
fold = self.is_ambiguous(dt_out, idx=idx)
|
| 776 |
+
|
| 777 |
+
return enfold(dt_out, fold=int(fold))
|
| 778 |
+
|
| 779 |
+
def is_ambiguous(self, dt, idx=None):
|
| 780 |
+
"""
|
| 781 |
+
Whether or not the "wall time" of a given datetime is ambiguous in this
|
| 782 |
+
zone.
|
| 783 |
+
|
| 784 |
+
:param dt:
|
| 785 |
+
A :py:class:`datetime.datetime`, naive or time zone aware.
|
| 786 |
+
|
| 787 |
+
|
| 788 |
+
:return:
|
| 789 |
+
Returns ``True`` if ambiguous, ``False`` otherwise.
|
| 790 |
+
|
| 791 |
+
.. versionadded:: 2.6.0
|
| 792 |
+
"""
|
| 793 |
+
if idx is None:
|
| 794 |
+
idx = self._find_last_transition(dt)
|
| 795 |
+
|
| 796 |
+
# Calculate the difference in offsets from current to previous
|
| 797 |
+
timestamp = _datetime_to_timestamp(dt)
|
| 798 |
+
tti = self._get_ttinfo(idx)
|
| 799 |
+
|
| 800 |
+
if idx is None or idx <= 0:
|
| 801 |
+
return False
|
| 802 |
+
|
| 803 |
+
od = self._get_ttinfo(idx - 1).offset - tti.offset
|
| 804 |
+
tt = self._trans_list[idx] # Transition time
|
| 805 |
+
|
| 806 |
+
return timestamp < tt + od
|
| 807 |
+
|
| 808 |
+
def _resolve_ambiguous_time(self, dt):
|
| 809 |
+
idx = self._find_last_transition(dt)
|
| 810 |
+
|
| 811 |
+
# If we have no transitions, return the index
|
| 812 |
+
_fold = self._fold(dt)
|
| 813 |
+
if idx is None or idx == 0:
|
| 814 |
+
return idx
|
| 815 |
+
|
| 816 |
+
# If it's ambiguous and we're in a fold, shift to a different index.
|
| 817 |
+
idx_offset = int(not _fold and self.is_ambiguous(dt, idx))
|
| 818 |
+
|
| 819 |
+
return idx - idx_offset
|
| 820 |
+
|
| 821 |
+
def utcoffset(self, dt):
|
| 822 |
+
if dt is None:
|
| 823 |
+
return None
|
| 824 |
+
|
| 825 |
+
if not self._ttinfo_std:
|
| 826 |
+
return ZERO
|
| 827 |
+
|
| 828 |
+
return self._find_ttinfo(dt).delta
|
| 829 |
+
|
| 830 |
+
def dst(self, dt):
|
| 831 |
+
if dt is None:
|
| 832 |
+
return None
|
| 833 |
+
|
| 834 |
+
if not self._ttinfo_dst:
|
| 835 |
+
return ZERO
|
| 836 |
+
|
| 837 |
+
tti = self._find_ttinfo(dt)
|
| 838 |
+
|
| 839 |
+
if not tti.isdst:
|
| 840 |
+
return ZERO
|
| 841 |
+
|
| 842 |
+
# The documentation says that utcoffset()-dst() must
|
| 843 |
+
# be constant for every dt.
|
| 844 |
+
return tti.dstoffset
|
| 845 |
+
|
| 846 |
+
@tzname_in_python2
|
| 847 |
+
def tzname(self, dt):
|
| 848 |
+
if not self._ttinfo_std or dt is None:
|
| 849 |
+
return None
|
| 850 |
+
return self._find_ttinfo(dt).abbr
|
| 851 |
+
|
| 852 |
+
def __eq__(self, other):
|
| 853 |
+
if not isinstance(other, tzfile):
|
| 854 |
+
return NotImplemented
|
| 855 |
+
return (self._trans_list == other._trans_list and
|
| 856 |
+
self._trans_idx == other._trans_idx and
|
| 857 |
+
self._ttinfo_list == other._ttinfo_list)
|
| 858 |
+
|
| 859 |
+
__hash__ = None
|
| 860 |
+
|
| 861 |
+
def __ne__(self, other):
|
| 862 |
+
return not (self == other)
|
| 863 |
+
|
| 864 |
+
def __repr__(self):
|
| 865 |
+
return "%s(%s)" % (self.__class__.__name__, repr(self._filename))
|
| 866 |
+
|
| 867 |
+
def __reduce__(self):
|
| 868 |
+
return self.__reduce_ex__(None)
|
| 869 |
+
|
| 870 |
+
def __reduce_ex__(self, protocol):
|
| 871 |
+
return (self.__class__, (None, self._filename), self.__dict__)
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
class tzrange(tzrangebase):
|
| 875 |
+
"""
|
| 876 |
+
The ``tzrange`` object is a time zone specified by a set of offsets and
|
| 877 |
+
abbreviations, equivalent to the way the ``TZ`` variable can be specified
|
| 878 |
+
in POSIX-like systems, but using Python delta objects to specify DST
|
| 879 |
+
start, end and offsets.
|
| 880 |
+
|
| 881 |
+
:param stdabbr:
|
| 882 |
+
The abbreviation for standard time (e.g. ``'EST'``).
|
| 883 |
+
|
| 884 |
+
:param stdoffset:
|
| 885 |
+
An integer or :class:`datetime.timedelta` object or equivalent
|
| 886 |
+
specifying the base offset from UTC.
|
| 887 |
+
|
| 888 |
+
If unspecified, +00:00 is used.
|
| 889 |
+
|
| 890 |
+
:param dstabbr:
|
| 891 |
+
The abbreviation for DST / "Summer" time (e.g. ``'EDT'``).
|
| 892 |
+
|
| 893 |
+
If specified, with no other DST information, DST is assumed to occur
|
| 894 |
+
and the default behavior or ``dstoffset``, ``start`` and ``end`` is
|
| 895 |
+
used. If unspecified and no other DST information is specified, it
|
| 896 |
+
is assumed that this zone has no DST.
|
| 897 |
+
|
| 898 |
+
If this is unspecified and other DST information is *is* specified,
|
| 899 |
+
DST occurs in the zone but the time zone abbreviation is left
|
| 900 |
+
unchanged.
|
| 901 |
+
|
| 902 |
+
:param dstoffset:
|
| 903 |
+
A an integer or :class:`datetime.timedelta` object or equivalent
|
| 904 |
+
specifying the UTC offset during DST. If unspecified and any other DST
|
| 905 |
+
information is specified, it is assumed to be the STD offset +1 hour.
|
| 906 |
+
|
| 907 |
+
:param start:
|
| 908 |
+
A :class:`relativedelta.relativedelta` object or equivalent specifying
|
| 909 |
+
the time and time of year that daylight savings time starts. To
|
| 910 |
+
specify, for example, that DST starts at 2AM on the 2nd Sunday in
|
| 911 |
+
March, pass:
|
| 912 |
+
|
| 913 |
+
``relativedelta(hours=2, month=3, day=1, weekday=SU(+2))``
|
| 914 |
+
|
| 915 |
+
If unspecified and any other DST information is specified, the default
|
| 916 |
+
value is 2 AM on the first Sunday in April.
|
| 917 |
+
|
| 918 |
+
:param end:
|
| 919 |
+
A :class:`relativedelta.relativedelta` object or equivalent
|
| 920 |
+
representing the time and time of year that daylight savings time
|
| 921 |
+
ends, with the same specification method as in ``start``. One note is
|
| 922 |
+
that this should point to the first time in the *standard* zone, so if
|
| 923 |
+
a transition occurs at 2AM in the DST zone and the clocks are set back
|
| 924 |
+
1 hour to 1AM, set the ``hours`` parameter to +1.
|
| 925 |
+
|
| 926 |
+
|
| 927 |
+
**Examples:**
|
| 928 |
+
|
| 929 |
+
.. testsetup:: tzrange
|
| 930 |
+
|
| 931 |
+
from dateutil.tz import tzrange, tzstr
|
| 932 |
+
|
| 933 |
+
.. doctest:: tzrange
|
| 934 |
+
|
| 935 |
+
>>> tzstr('EST5EDT') == tzrange("EST", -18000, "EDT")
|
| 936 |
+
True
|
| 937 |
+
|
| 938 |
+
>>> from dateutil.relativedelta import *
|
| 939 |
+
>>> range1 = tzrange("EST", -18000, "EDT")
|
| 940 |
+
>>> range2 = tzrange("EST", -18000, "EDT", -14400,
|
| 941 |
+
... relativedelta(hours=+2, month=4, day=1,
|
| 942 |
+
... weekday=SU(+1)),
|
| 943 |
+
... relativedelta(hours=+1, month=10, day=31,
|
| 944 |
+
... weekday=SU(-1)))
|
| 945 |
+
>>> tzstr('EST5EDT') == range1 == range2
|
| 946 |
+
True
|
| 947 |
+
|
| 948 |
+
"""
|
| 949 |
+
def __init__(self, stdabbr, stdoffset=None,
|
| 950 |
+
dstabbr=None, dstoffset=None,
|
| 951 |
+
start=None, end=None):
|
| 952 |
+
|
| 953 |
+
global relativedelta
|
| 954 |
+
from dateutil import relativedelta
|
| 955 |
+
|
| 956 |
+
self._std_abbr = stdabbr
|
| 957 |
+
self._dst_abbr = dstabbr
|
| 958 |
+
|
| 959 |
+
try:
|
| 960 |
+
stdoffset = stdoffset.total_seconds()
|
| 961 |
+
except (TypeError, AttributeError):
|
| 962 |
+
pass
|
| 963 |
+
|
| 964 |
+
try:
|
| 965 |
+
dstoffset = dstoffset.total_seconds()
|
| 966 |
+
except (TypeError, AttributeError):
|
| 967 |
+
pass
|
| 968 |
+
|
| 969 |
+
if stdoffset is not None:
|
| 970 |
+
self._std_offset = datetime.timedelta(seconds=stdoffset)
|
| 971 |
+
else:
|
| 972 |
+
self._std_offset = ZERO
|
| 973 |
+
|
| 974 |
+
if dstoffset is not None:
|
| 975 |
+
self._dst_offset = datetime.timedelta(seconds=dstoffset)
|
| 976 |
+
elif dstabbr and stdoffset is not None:
|
| 977 |
+
self._dst_offset = self._std_offset + datetime.timedelta(hours=+1)
|
| 978 |
+
else:
|
| 979 |
+
self._dst_offset = ZERO
|
| 980 |
+
|
| 981 |
+
if dstabbr and start is None:
|
| 982 |
+
self._start_delta = relativedelta.relativedelta(
|
| 983 |
+
hours=+2, month=4, day=1, weekday=relativedelta.SU(+1))
|
| 984 |
+
else:
|
| 985 |
+
self._start_delta = start
|
| 986 |
+
|
| 987 |
+
if dstabbr and end is None:
|
| 988 |
+
self._end_delta = relativedelta.relativedelta(
|
| 989 |
+
hours=+1, month=10, day=31, weekday=relativedelta.SU(-1))
|
| 990 |
+
else:
|
| 991 |
+
self._end_delta = end
|
| 992 |
+
|
| 993 |
+
self._dst_base_offset_ = self._dst_offset - self._std_offset
|
| 994 |
+
self.hasdst = bool(self._start_delta)
|
| 995 |
+
|
| 996 |
+
def transitions(self, year):
|
| 997 |
+
"""
|
| 998 |
+
For a given year, get the DST on and off transition times, expressed
|
| 999 |
+
always on the standard time side. For zones with no transitions, this
|
| 1000 |
+
function returns ``None``.
|
| 1001 |
+
|
| 1002 |
+
:param year:
|
| 1003 |
+
The year whose transitions you would like to query.
|
| 1004 |
+
|
| 1005 |
+
:return:
|
| 1006 |
+
Returns a :class:`tuple` of :class:`datetime.datetime` objects,
|
| 1007 |
+
``(dston, dstoff)`` for zones with an annual DST transition, or
|
| 1008 |
+
``None`` for fixed offset zones.
|
| 1009 |
+
"""
|
| 1010 |
+
if not self.hasdst:
|
| 1011 |
+
return None
|
| 1012 |
+
|
| 1013 |
+
base_year = datetime.datetime(year, 1, 1)
|
| 1014 |
+
|
| 1015 |
+
start = base_year + self._start_delta
|
| 1016 |
+
end = base_year + self._end_delta
|
| 1017 |
+
|
| 1018 |
+
return (start, end)
|
| 1019 |
+
|
| 1020 |
+
def __eq__(self, other):
|
| 1021 |
+
if not isinstance(other, tzrange):
|
| 1022 |
+
return NotImplemented
|
| 1023 |
+
|
| 1024 |
+
return (self._std_abbr == other._std_abbr and
|
| 1025 |
+
self._dst_abbr == other._dst_abbr and
|
| 1026 |
+
self._std_offset == other._std_offset and
|
| 1027 |
+
self._dst_offset == other._dst_offset and
|
| 1028 |
+
self._start_delta == other._start_delta and
|
| 1029 |
+
self._end_delta == other._end_delta)
|
| 1030 |
+
|
| 1031 |
+
@property
|
| 1032 |
+
def _dst_base_offset(self):
|
| 1033 |
+
return self._dst_base_offset_
|
| 1034 |
+
|
| 1035 |
+
|
| 1036 |
+
@six.add_metaclass(_TzStrFactory)
|
| 1037 |
+
class tzstr(tzrange):
|
| 1038 |
+
"""
|
| 1039 |
+
``tzstr`` objects are time zone objects specified by a time-zone string as
|
| 1040 |
+
it would be passed to a ``TZ`` variable on POSIX-style systems (see
|
| 1041 |
+
the `GNU C Library: TZ Variable`_ for more details).
|
| 1042 |
+
|
| 1043 |
+
There is one notable exception, which is that POSIX-style time zones use an
|
| 1044 |
+
inverted offset format, so normally ``GMT+3`` would be parsed as an offset
|
| 1045 |
+
3 hours *behind* GMT. The ``tzstr`` time zone object will parse this as an
|
| 1046 |
+
offset 3 hours *ahead* of GMT. If you would like to maintain the POSIX
|
| 1047 |
+
behavior, pass a ``True`` value to ``posix_offset``.
|
| 1048 |
+
|
| 1049 |
+
The :class:`tzrange` object provides the same functionality, but is
|
| 1050 |
+
specified using :class:`relativedelta.relativedelta` objects. rather than
|
| 1051 |
+
strings.
|
| 1052 |
+
|
| 1053 |
+
:param s:
|
| 1054 |
+
A time zone string in ``TZ`` variable format. This can be a
|
| 1055 |
+
:class:`bytes` (2.x: :class:`str`), :class:`str` (2.x:
|
| 1056 |
+
:class:`unicode`) or a stream emitting unicode characters
|
| 1057 |
+
(e.g. :class:`StringIO`).
|
| 1058 |
+
|
| 1059 |
+
:param posix_offset:
|
| 1060 |
+
Optional. If set to ``True``, interpret strings such as ``GMT+3`` or
|
| 1061 |
+
``UTC+3`` as being 3 hours *behind* UTC rather than ahead, per the
|
| 1062 |
+
POSIX standard.
|
| 1063 |
+
|
| 1064 |
+
.. caution::
|
| 1065 |
+
|
| 1066 |
+
Prior to version 2.7.0, this function also supported time zones
|
| 1067 |
+
in the format:
|
| 1068 |
+
|
| 1069 |
+
* ``EST5EDT,4,0,6,7200,10,0,26,7200,3600``
|
| 1070 |
+
* ``EST5EDT,4,1,0,7200,10,-1,0,7200,3600``
|
| 1071 |
+
|
| 1072 |
+
This format is non-standard and has been deprecated; this function
|
| 1073 |
+
will raise a :class:`DeprecatedTZFormatWarning` until
|
| 1074 |
+
support is removed in a future version.
|
| 1075 |
+
|
| 1076 |
+
.. _`GNU C Library: TZ Variable`:
|
| 1077 |
+
https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
|
| 1078 |
+
"""
|
| 1079 |
+
def __init__(self, s, posix_offset=False):
|
| 1080 |
+
global parser
|
| 1081 |
+
from dateutil.parser import _parser as parser
|
| 1082 |
+
|
| 1083 |
+
self._s = s
|
| 1084 |
+
|
| 1085 |
+
res = parser._parsetz(s)
|
| 1086 |
+
if res is None or res.any_unused_tokens:
|
| 1087 |
+
raise ValueError("unknown string format")
|
| 1088 |
+
|
| 1089 |
+
# Here we break the compatibility with the TZ variable handling.
|
| 1090 |
+
# GMT-3 actually *means* the timezone -3.
|
| 1091 |
+
if res.stdabbr in ("GMT", "UTC") and not posix_offset:
|
| 1092 |
+
res.stdoffset *= -1
|
| 1093 |
+
|
| 1094 |
+
# We must initialize it first, since _delta() needs
|
| 1095 |
+
# _std_offset and _dst_offset set. Use False in start/end
|
| 1096 |
+
# to avoid building it two times.
|
| 1097 |
+
tzrange.__init__(self, res.stdabbr, res.stdoffset,
|
| 1098 |
+
res.dstabbr, res.dstoffset,
|
| 1099 |
+
start=False, end=False)
|
| 1100 |
+
|
| 1101 |
+
if not res.dstabbr:
|
| 1102 |
+
self._start_delta = None
|
| 1103 |
+
self._end_delta = None
|
| 1104 |
+
else:
|
| 1105 |
+
self._start_delta = self._delta(res.start)
|
| 1106 |
+
if self._start_delta:
|
| 1107 |
+
self._end_delta = self._delta(res.end, isend=1)
|
| 1108 |
+
|
| 1109 |
+
self.hasdst = bool(self._start_delta)
|
| 1110 |
+
|
| 1111 |
+
def _delta(self, x, isend=0):
|
| 1112 |
+
from dateutil import relativedelta
|
| 1113 |
+
kwargs = {}
|
| 1114 |
+
if x.month is not None:
|
| 1115 |
+
kwargs["month"] = x.month
|
| 1116 |
+
if x.weekday is not None:
|
| 1117 |
+
kwargs["weekday"] = relativedelta.weekday(x.weekday, x.week)
|
| 1118 |
+
if x.week > 0:
|
| 1119 |
+
kwargs["day"] = 1
|
| 1120 |
+
else:
|
| 1121 |
+
kwargs["day"] = 31
|
| 1122 |
+
elif x.day:
|
| 1123 |
+
kwargs["day"] = x.day
|
| 1124 |
+
elif x.yday is not None:
|
| 1125 |
+
kwargs["yearday"] = x.yday
|
| 1126 |
+
elif x.jyday is not None:
|
| 1127 |
+
kwargs["nlyearday"] = x.jyday
|
| 1128 |
+
if not kwargs:
|
| 1129 |
+
# Default is to start on first sunday of april, and end
|
| 1130 |
+
# on last sunday of october.
|
| 1131 |
+
if not isend:
|
| 1132 |
+
kwargs["month"] = 4
|
| 1133 |
+
kwargs["day"] = 1
|
| 1134 |
+
kwargs["weekday"] = relativedelta.SU(+1)
|
| 1135 |
+
else:
|
| 1136 |
+
kwargs["month"] = 10
|
| 1137 |
+
kwargs["day"] = 31
|
| 1138 |
+
kwargs["weekday"] = relativedelta.SU(-1)
|
| 1139 |
+
if x.time is not None:
|
| 1140 |
+
kwargs["seconds"] = x.time
|
| 1141 |
+
else:
|
| 1142 |
+
# Default is 2AM.
|
| 1143 |
+
kwargs["seconds"] = 7200
|
| 1144 |
+
if isend:
|
| 1145 |
+
# Convert to standard time, to follow the documented way
|
| 1146 |
+
# of working with the extra hour. See the documentation
|
| 1147 |
+
# of the tzinfo class.
|
| 1148 |
+
delta = self._dst_offset - self._std_offset
|
| 1149 |
+
kwargs["seconds"] -= delta.seconds + delta.days * 86400
|
| 1150 |
+
return relativedelta.relativedelta(**kwargs)
|
| 1151 |
+
|
| 1152 |
+
def __repr__(self):
|
| 1153 |
+
return "%s(%s)" % (self.__class__.__name__, repr(self._s))
|
| 1154 |
+
|
| 1155 |
+
|
| 1156 |
+
class _tzicalvtzcomp(object):
|
| 1157 |
+
def __init__(self, tzoffsetfrom, tzoffsetto, isdst,
|
| 1158 |
+
tzname=None, rrule=None):
|
| 1159 |
+
self.tzoffsetfrom = datetime.timedelta(seconds=tzoffsetfrom)
|
| 1160 |
+
self.tzoffsetto = datetime.timedelta(seconds=tzoffsetto)
|
| 1161 |
+
self.tzoffsetdiff = self.tzoffsetto - self.tzoffsetfrom
|
| 1162 |
+
self.isdst = isdst
|
| 1163 |
+
self.tzname = tzname
|
| 1164 |
+
self.rrule = rrule
|
| 1165 |
+
|
| 1166 |
+
|
| 1167 |
+
class _tzicalvtz(_tzinfo):
|
| 1168 |
+
def __init__(self, tzid, comps=[]):
|
| 1169 |
+
super(_tzicalvtz, self).__init__()
|
| 1170 |
+
|
| 1171 |
+
self._tzid = tzid
|
| 1172 |
+
self._comps = comps
|
| 1173 |
+
self._cachedate = []
|
| 1174 |
+
self._cachecomp = []
|
| 1175 |
+
self._cache_lock = _thread.allocate_lock()
|
| 1176 |
+
|
| 1177 |
+
def _find_comp(self, dt):
|
| 1178 |
+
if len(self._comps) == 1:
|
| 1179 |
+
return self._comps[0]
|
| 1180 |
+
|
| 1181 |
+
dt = dt.replace(tzinfo=None)
|
| 1182 |
+
|
| 1183 |
+
try:
|
| 1184 |
+
with self._cache_lock:
|
| 1185 |
+
return self._cachecomp[self._cachedate.index(
|
| 1186 |
+
(dt, self._fold(dt)))]
|
| 1187 |
+
except ValueError:
|
| 1188 |
+
pass
|
| 1189 |
+
|
| 1190 |
+
lastcompdt = None
|
| 1191 |
+
lastcomp = None
|
| 1192 |
+
|
| 1193 |
+
for comp in self._comps:
|
| 1194 |
+
compdt = self._find_compdt(comp, dt)
|
| 1195 |
+
|
| 1196 |
+
if compdt and (not lastcompdt or lastcompdt < compdt):
|
| 1197 |
+
lastcompdt = compdt
|
| 1198 |
+
lastcomp = comp
|
| 1199 |
+
|
| 1200 |
+
if not lastcomp:
|
| 1201 |
+
# RFC says nothing about what to do when a given
|
| 1202 |
+
# time is before the first onset date. We'll look for the
|
| 1203 |
+
# first standard component, or the first component, if
|
| 1204 |
+
# none is found.
|
| 1205 |
+
for comp in self._comps:
|
| 1206 |
+
if not comp.isdst:
|
| 1207 |
+
lastcomp = comp
|
| 1208 |
+
break
|
| 1209 |
+
else:
|
| 1210 |
+
lastcomp = comp[0]
|
| 1211 |
+
|
| 1212 |
+
with self._cache_lock:
|
| 1213 |
+
self._cachedate.insert(0, (dt, self._fold(dt)))
|
| 1214 |
+
self._cachecomp.insert(0, lastcomp)
|
| 1215 |
+
|
| 1216 |
+
if len(self._cachedate) > 10:
|
| 1217 |
+
self._cachedate.pop()
|
| 1218 |
+
self._cachecomp.pop()
|
| 1219 |
+
|
| 1220 |
+
return lastcomp
|
| 1221 |
+
|
| 1222 |
+
def _find_compdt(self, comp, dt):
|
| 1223 |
+
if comp.tzoffsetdiff < ZERO and self._fold(dt):
|
| 1224 |
+
dt -= comp.tzoffsetdiff
|
| 1225 |
+
|
| 1226 |
+
compdt = comp.rrule.before(dt, inc=True)
|
| 1227 |
+
|
| 1228 |
+
return compdt
|
| 1229 |
+
|
| 1230 |
+
def utcoffset(self, dt):
|
| 1231 |
+
if dt is None:
|
| 1232 |
+
return None
|
| 1233 |
+
|
| 1234 |
+
return self._find_comp(dt).tzoffsetto
|
| 1235 |
+
|
| 1236 |
+
def dst(self, dt):
|
| 1237 |
+
comp = self._find_comp(dt)
|
| 1238 |
+
if comp.isdst:
|
| 1239 |
+
return comp.tzoffsetdiff
|
| 1240 |
+
else:
|
| 1241 |
+
return ZERO
|
| 1242 |
+
|
| 1243 |
+
@tzname_in_python2
|
| 1244 |
+
def tzname(self, dt):
|
| 1245 |
+
return self._find_comp(dt).tzname
|
| 1246 |
+
|
| 1247 |
+
def __repr__(self):
|
| 1248 |
+
return "<tzicalvtz %s>" % repr(self._tzid)
|
| 1249 |
+
|
| 1250 |
+
__reduce__ = object.__reduce__
|
| 1251 |
+
|
| 1252 |
+
|
| 1253 |
+
class tzical(object):
|
| 1254 |
+
"""
|
| 1255 |
+
This object is designed to parse an iCalendar-style ``VTIMEZONE`` structure
|
| 1256 |
+
as set out in `RFC 5545`_ Section 4.6.5 into one or more `tzinfo` objects.
|
| 1257 |
+
|
| 1258 |
+
:param `fileobj`:
|
| 1259 |
+
A file or stream in iCalendar format, which should be UTF-8 encoded
|
| 1260 |
+
with CRLF endings.
|
| 1261 |
+
|
| 1262 |
+
.. _`RFC 5545`: https://tools.ietf.org/html/rfc5545
|
| 1263 |
+
"""
|
| 1264 |
+
def __init__(self, fileobj):
|
| 1265 |
+
global rrule
|
| 1266 |
+
from dateutil import rrule
|
| 1267 |
+
|
| 1268 |
+
if isinstance(fileobj, string_types):
|
| 1269 |
+
self._s = fileobj
|
| 1270 |
+
# ical should be encoded in UTF-8 with CRLF
|
| 1271 |
+
fileobj = open(fileobj, 'r')
|
| 1272 |
+
else:
|
| 1273 |
+
self._s = getattr(fileobj, 'name', repr(fileobj))
|
| 1274 |
+
fileobj = _nullcontext(fileobj)
|
| 1275 |
+
|
| 1276 |
+
self._vtz = {}
|
| 1277 |
+
|
| 1278 |
+
with fileobj as fobj:
|
| 1279 |
+
self._parse_rfc(fobj.read())
|
| 1280 |
+
|
| 1281 |
+
def keys(self):
|
| 1282 |
+
"""
|
| 1283 |
+
Retrieves the available time zones as a list.
|
| 1284 |
+
"""
|
| 1285 |
+
return list(self._vtz.keys())
|
| 1286 |
+
|
| 1287 |
+
def get(self, tzid=None):
|
| 1288 |
+
"""
|
| 1289 |
+
Retrieve a :py:class:`datetime.tzinfo` object by its ``tzid``.
|
| 1290 |
+
|
| 1291 |
+
:param tzid:
|
| 1292 |
+
If there is exactly one time zone available, omitting ``tzid``
|
| 1293 |
+
or passing :py:const:`None` value returns it. Otherwise a valid
|
| 1294 |
+
key (which can be retrieved from :func:`keys`) is required.
|
| 1295 |
+
|
| 1296 |
+
:raises ValueError:
|
| 1297 |
+
Raised if ``tzid`` is not specified but there are either more
|
| 1298 |
+
or fewer than 1 zone defined.
|
| 1299 |
+
|
| 1300 |
+
:returns:
|
| 1301 |
+
Returns either a :py:class:`datetime.tzinfo` object representing
|
| 1302 |
+
the relevant time zone or :py:const:`None` if the ``tzid`` was
|
| 1303 |
+
not found.
|
| 1304 |
+
"""
|
| 1305 |
+
if tzid is None:
|
| 1306 |
+
if len(self._vtz) == 0:
|
| 1307 |
+
raise ValueError("no timezones defined")
|
| 1308 |
+
elif len(self._vtz) > 1:
|
| 1309 |
+
raise ValueError("more than one timezone available")
|
| 1310 |
+
tzid = next(iter(self._vtz))
|
| 1311 |
+
|
| 1312 |
+
return self._vtz.get(tzid)
|
| 1313 |
+
|
| 1314 |
+
def _parse_offset(self, s):
|
| 1315 |
+
s = s.strip()
|
| 1316 |
+
if not s:
|
| 1317 |
+
raise ValueError("empty offset")
|
| 1318 |
+
if s[0] in ('+', '-'):
|
| 1319 |
+
signal = (-1, +1)[s[0] == '+']
|
| 1320 |
+
s = s[1:]
|
| 1321 |
+
else:
|
| 1322 |
+
signal = +1
|
| 1323 |
+
if len(s) == 4:
|
| 1324 |
+
return (int(s[:2]) * 3600 + int(s[2:]) * 60) * signal
|
| 1325 |
+
elif len(s) == 6:
|
| 1326 |
+
return (int(s[:2]) * 3600 + int(s[2:4]) * 60 + int(s[4:])) * signal
|
| 1327 |
+
else:
|
| 1328 |
+
raise ValueError("invalid offset: " + s)
|
| 1329 |
+
|
| 1330 |
+
def _parse_rfc(self, s):
|
| 1331 |
+
lines = s.splitlines()
|
| 1332 |
+
if not lines:
|
| 1333 |
+
raise ValueError("empty string")
|
| 1334 |
+
|
| 1335 |
+
# Unfold
|
| 1336 |
+
i = 0
|
| 1337 |
+
while i < len(lines):
|
| 1338 |
+
line = lines[i].rstrip()
|
| 1339 |
+
if not line:
|
| 1340 |
+
del lines[i]
|
| 1341 |
+
elif i > 0 and line[0] == " ":
|
| 1342 |
+
lines[i-1] += line[1:]
|
| 1343 |
+
del lines[i]
|
| 1344 |
+
else:
|
| 1345 |
+
i += 1
|
| 1346 |
+
|
| 1347 |
+
tzid = None
|
| 1348 |
+
comps = []
|
| 1349 |
+
invtz = False
|
| 1350 |
+
comptype = None
|
| 1351 |
+
for line in lines:
|
| 1352 |
+
if not line:
|
| 1353 |
+
continue
|
| 1354 |
+
name, value = line.split(':', 1)
|
| 1355 |
+
parms = name.split(';')
|
| 1356 |
+
if not parms:
|
| 1357 |
+
raise ValueError("empty property name")
|
| 1358 |
+
name = parms[0].upper()
|
| 1359 |
+
parms = parms[1:]
|
| 1360 |
+
if invtz:
|
| 1361 |
+
if name == "BEGIN":
|
| 1362 |
+
if value in ("STANDARD", "DAYLIGHT"):
|
| 1363 |
+
# Process component
|
| 1364 |
+
pass
|
| 1365 |
+
else:
|
| 1366 |
+
raise ValueError("unknown component: "+value)
|
| 1367 |
+
comptype = value
|
| 1368 |
+
founddtstart = False
|
| 1369 |
+
tzoffsetfrom = None
|
| 1370 |
+
tzoffsetto = None
|
| 1371 |
+
rrulelines = []
|
| 1372 |
+
tzname = None
|
| 1373 |
+
elif name == "END":
|
| 1374 |
+
if value == "VTIMEZONE":
|
| 1375 |
+
if comptype:
|
| 1376 |
+
raise ValueError("component not closed: "+comptype)
|
| 1377 |
+
if not tzid:
|
| 1378 |
+
raise ValueError("mandatory TZID not found")
|
| 1379 |
+
if not comps:
|
| 1380 |
+
raise ValueError(
|
| 1381 |
+
"at least one component is needed")
|
| 1382 |
+
# Process vtimezone
|
| 1383 |
+
self._vtz[tzid] = _tzicalvtz(tzid, comps)
|
| 1384 |
+
invtz = False
|
| 1385 |
+
elif value == comptype:
|
| 1386 |
+
if not founddtstart:
|
| 1387 |
+
raise ValueError("mandatory DTSTART not found")
|
| 1388 |
+
if tzoffsetfrom is None:
|
| 1389 |
+
raise ValueError(
|
| 1390 |
+
"mandatory TZOFFSETFROM not found")
|
| 1391 |
+
if tzoffsetto is None:
|
| 1392 |
+
raise ValueError(
|
| 1393 |
+
"mandatory TZOFFSETFROM not found")
|
| 1394 |
+
# Process component
|
| 1395 |
+
rr = None
|
| 1396 |
+
if rrulelines:
|
| 1397 |
+
rr = rrule.rrulestr("\n".join(rrulelines),
|
| 1398 |
+
compatible=True,
|
| 1399 |
+
ignoretz=True,
|
| 1400 |
+
cache=True)
|
| 1401 |
+
comp = _tzicalvtzcomp(tzoffsetfrom, tzoffsetto,
|
| 1402 |
+
(comptype == "DAYLIGHT"),
|
| 1403 |
+
tzname, rr)
|
| 1404 |
+
comps.append(comp)
|
| 1405 |
+
comptype = None
|
| 1406 |
+
else:
|
| 1407 |
+
raise ValueError("invalid component end: "+value)
|
| 1408 |
+
elif comptype:
|
| 1409 |
+
if name == "DTSTART":
|
| 1410 |
+
# DTSTART in VTIMEZONE takes a subset of valid RRULE
|
| 1411 |
+
# values under RFC 5545.
|
| 1412 |
+
for parm in parms:
|
| 1413 |
+
if parm != 'VALUE=DATE-TIME':
|
| 1414 |
+
msg = ('Unsupported DTSTART param in ' +
|
| 1415 |
+
'VTIMEZONE: ' + parm)
|
| 1416 |
+
raise ValueError(msg)
|
| 1417 |
+
rrulelines.append(line)
|
| 1418 |
+
founddtstart = True
|
| 1419 |
+
elif name in ("RRULE", "RDATE", "EXRULE", "EXDATE"):
|
| 1420 |
+
rrulelines.append(line)
|
| 1421 |
+
elif name == "TZOFFSETFROM":
|
| 1422 |
+
if parms:
|
| 1423 |
+
raise ValueError(
|
| 1424 |
+
"unsupported %s parm: %s " % (name, parms[0]))
|
| 1425 |
+
tzoffsetfrom = self._parse_offset(value)
|
| 1426 |
+
elif name == "TZOFFSETTO":
|
| 1427 |
+
if parms:
|
| 1428 |
+
raise ValueError(
|
| 1429 |
+
"unsupported TZOFFSETTO parm: "+parms[0])
|
| 1430 |
+
tzoffsetto = self._parse_offset(value)
|
| 1431 |
+
elif name == "TZNAME":
|
| 1432 |
+
if parms:
|
| 1433 |
+
raise ValueError(
|
| 1434 |
+
"unsupported TZNAME parm: "+parms[0])
|
| 1435 |
+
tzname = value
|
| 1436 |
+
elif name == "COMMENT":
|
| 1437 |
+
pass
|
| 1438 |
+
else:
|
| 1439 |
+
raise ValueError("unsupported property: "+name)
|
| 1440 |
+
else:
|
| 1441 |
+
if name == "TZID":
|
| 1442 |
+
if parms:
|
| 1443 |
+
raise ValueError(
|
| 1444 |
+
"unsupported TZID parm: "+parms[0])
|
| 1445 |
+
tzid = value
|
| 1446 |
+
elif name in ("TZURL", "LAST-MODIFIED", "COMMENT"):
|
| 1447 |
+
pass
|
| 1448 |
+
else:
|
| 1449 |
+
raise ValueError("unsupported property: "+name)
|
| 1450 |
+
elif name == "BEGIN" and value == "VTIMEZONE":
|
| 1451 |
+
tzid = None
|
| 1452 |
+
comps = []
|
| 1453 |
+
invtz = True
|
| 1454 |
+
|
| 1455 |
+
def __repr__(self):
|
| 1456 |
+
return "%s(%s)" % (self.__class__.__name__, repr(self._s))
|
| 1457 |
+
|
| 1458 |
+
|
| 1459 |
+
if sys.platform != "win32":
|
| 1460 |
+
TZFILES = ["/etc/localtime", "localtime"]
|
| 1461 |
+
TZPATHS = ["/usr/share/zoneinfo",
|
| 1462 |
+
"/usr/lib/zoneinfo",
|
| 1463 |
+
"/usr/share/lib/zoneinfo",
|
| 1464 |
+
"/etc/zoneinfo"]
|
| 1465 |
+
else:
|
| 1466 |
+
TZFILES = []
|
| 1467 |
+
TZPATHS = []
|
| 1468 |
+
|
| 1469 |
+
|
| 1470 |
+
def __get_gettz():
|
| 1471 |
+
tzlocal_classes = (tzlocal,)
|
| 1472 |
+
if tzwinlocal is not None:
|
| 1473 |
+
tzlocal_classes += (tzwinlocal,)
|
| 1474 |
+
|
| 1475 |
+
class GettzFunc(object):
|
| 1476 |
+
"""
|
| 1477 |
+
Retrieve a time zone object from a string representation
|
| 1478 |
+
|
| 1479 |
+
This function is intended to retrieve the :py:class:`tzinfo` subclass
|
| 1480 |
+
that best represents the time zone that would be used if a POSIX
|
| 1481 |
+
`TZ variable`_ were set to the same value.
|
| 1482 |
+
|
| 1483 |
+
If no argument or an empty string is passed to ``gettz``, local time
|
| 1484 |
+
is returned:
|
| 1485 |
+
|
| 1486 |
+
.. code-block:: python3
|
| 1487 |
+
|
| 1488 |
+
>>> gettz()
|
| 1489 |
+
tzfile('/etc/localtime')
|
| 1490 |
+
|
| 1491 |
+
This function is also the preferred way to map IANA tz database keys
|
| 1492 |
+
to :class:`tzfile` objects:
|
| 1493 |
+
|
| 1494 |
+
.. code-block:: python3
|
| 1495 |
+
|
| 1496 |
+
>>> gettz('Pacific/Kiritimati')
|
| 1497 |
+
tzfile('/usr/share/zoneinfo/Pacific/Kiritimati')
|
| 1498 |
+
|
| 1499 |
+
On Windows, the standard is extended to include the Windows-specific
|
| 1500 |
+
zone names provided by the operating system:
|
| 1501 |
+
|
| 1502 |
+
.. code-block:: python3
|
| 1503 |
+
|
| 1504 |
+
>>> gettz('Egypt Standard Time')
|
| 1505 |
+
tzwin('Egypt Standard Time')
|
| 1506 |
+
|
| 1507 |
+
Passing a GNU ``TZ`` style string time zone specification returns a
|
| 1508 |
+
:class:`tzstr` object:
|
| 1509 |
+
|
| 1510 |
+
.. code-block:: python3
|
| 1511 |
+
|
| 1512 |
+
>>> gettz('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3')
|
| 1513 |
+
tzstr('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3')
|
| 1514 |
+
|
| 1515 |
+
:param name:
|
| 1516 |
+
A time zone name (IANA, or, on Windows, Windows keys), location of
|
| 1517 |
+
a ``tzfile(5)`` zoneinfo file or ``TZ`` variable style time zone
|
| 1518 |
+
specifier. An empty string, no argument or ``None`` is interpreted
|
| 1519 |
+
as local time.
|
| 1520 |
+
|
| 1521 |
+
:return:
|
| 1522 |
+
Returns an instance of one of ``dateutil``'s :py:class:`tzinfo`
|
| 1523 |
+
subclasses.
|
| 1524 |
+
|
| 1525 |
+
.. versionchanged:: 2.7.0
|
| 1526 |
+
|
| 1527 |
+
After version 2.7.0, any two calls to ``gettz`` using the same
|
| 1528 |
+
input strings will return the same object:
|
| 1529 |
+
|
| 1530 |
+
.. code-block:: python3
|
| 1531 |
+
|
| 1532 |
+
>>> tz.gettz('America/Chicago') is tz.gettz('America/Chicago')
|
| 1533 |
+
True
|
| 1534 |
+
|
| 1535 |
+
In addition to improving performance, this ensures that
|
| 1536 |
+
`"same zone" semantics`_ are used for datetimes in the same zone.
|
| 1537 |
+
|
| 1538 |
+
|
| 1539 |
+
.. _`TZ variable`:
|
| 1540 |
+
https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
|
| 1541 |
+
|
| 1542 |
+
.. _`"same zone" semantics`:
|
| 1543 |
+
https://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html
|
| 1544 |
+
"""
|
| 1545 |
+
def __init__(self):
|
| 1546 |
+
|
| 1547 |
+
self.__instances = weakref.WeakValueDictionary()
|
| 1548 |
+
self.__strong_cache_size = 8
|
| 1549 |
+
self.__strong_cache = OrderedDict()
|
| 1550 |
+
self._cache_lock = _thread.allocate_lock()
|
| 1551 |
+
|
| 1552 |
+
def __call__(self, name=None):
|
| 1553 |
+
with self._cache_lock:
|
| 1554 |
+
rv = self.__instances.get(name, None)
|
| 1555 |
+
|
| 1556 |
+
if rv is None:
|
| 1557 |
+
rv = self.nocache(name=name)
|
| 1558 |
+
if not (name is None
|
| 1559 |
+
or isinstance(rv, tzlocal_classes)
|
| 1560 |
+
or rv is None):
|
| 1561 |
+
# tzlocal is slightly more complicated than the other
|
| 1562 |
+
# time zone providers because it depends on environment
|
| 1563 |
+
# at construction time, so don't cache that.
|
| 1564 |
+
#
|
| 1565 |
+
# We also cannot store weak references to None, so we
|
| 1566 |
+
# will also not store that.
|
| 1567 |
+
self.__instances[name] = rv
|
| 1568 |
+
else:
|
| 1569 |
+
# No need for strong caching, return immediately
|
| 1570 |
+
return rv
|
| 1571 |
+
|
| 1572 |
+
self.__strong_cache[name] = self.__strong_cache.pop(name, rv)
|
| 1573 |
+
|
| 1574 |
+
if len(self.__strong_cache) > self.__strong_cache_size:
|
| 1575 |
+
self.__strong_cache.popitem(last=False)
|
| 1576 |
+
|
| 1577 |
+
return rv
|
| 1578 |
+
|
| 1579 |
+
def set_cache_size(self, size):
|
| 1580 |
+
with self._cache_lock:
|
| 1581 |
+
self.__strong_cache_size = size
|
| 1582 |
+
while len(self.__strong_cache) > size:
|
| 1583 |
+
self.__strong_cache.popitem(last=False)
|
| 1584 |
+
|
| 1585 |
+
def cache_clear(self):
|
| 1586 |
+
with self._cache_lock:
|
| 1587 |
+
self.__instances = weakref.WeakValueDictionary()
|
| 1588 |
+
self.__strong_cache.clear()
|
| 1589 |
+
|
| 1590 |
+
@staticmethod
|
| 1591 |
+
def nocache(name=None):
|
| 1592 |
+
"""A non-cached version of gettz"""
|
| 1593 |
+
tz = None
|
| 1594 |
+
if not name:
|
| 1595 |
+
try:
|
| 1596 |
+
name = os.environ["TZ"]
|
| 1597 |
+
except KeyError:
|
| 1598 |
+
pass
|
| 1599 |
+
if name is None or name in ("", ":"):
|
| 1600 |
+
for filepath in TZFILES:
|
| 1601 |
+
if not os.path.isabs(filepath):
|
| 1602 |
+
filename = filepath
|
| 1603 |
+
for path in TZPATHS:
|
| 1604 |
+
filepath = os.path.join(path, filename)
|
| 1605 |
+
if os.path.isfile(filepath):
|
| 1606 |
+
break
|
| 1607 |
+
else:
|
| 1608 |
+
continue
|
| 1609 |
+
if os.path.isfile(filepath):
|
| 1610 |
+
try:
|
| 1611 |
+
tz = tzfile(filepath)
|
| 1612 |
+
break
|
| 1613 |
+
except (IOError, OSError, ValueError):
|
| 1614 |
+
pass
|
| 1615 |
+
else:
|
| 1616 |
+
tz = tzlocal()
|
| 1617 |
+
else:
|
| 1618 |
+
try:
|
| 1619 |
+
if name.startswith(":"):
|
| 1620 |
+
name = name[1:]
|
| 1621 |
+
except TypeError as e:
|
| 1622 |
+
if isinstance(name, bytes):
|
| 1623 |
+
new_msg = "gettz argument should be str, not bytes"
|
| 1624 |
+
six.raise_from(TypeError(new_msg), e)
|
| 1625 |
+
else:
|
| 1626 |
+
raise
|
| 1627 |
+
if os.path.isabs(name):
|
| 1628 |
+
if os.path.isfile(name):
|
| 1629 |
+
tz = tzfile(name)
|
| 1630 |
+
else:
|
| 1631 |
+
tz = None
|
| 1632 |
+
else:
|
| 1633 |
+
for path in TZPATHS:
|
| 1634 |
+
filepath = os.path.join(path, name)
|
| 1635 |
+
if not os.path.isfile(filepath):
|
| 1636 |
+
filepath = filepath.replace(' ', '_')
|
| 1637 |
+
if not os.path.isfile(filepath):
|
| 1638 |
+
continue
|
| 1639 |
+
try:
|
| 1640 |
+
tz = tzfile(filepath)
|
| 1641 |
+
break
|
| 1642 |
+
except (IOError, OSError, ValueError):
|
| 1643 |
+
pass
|
| 1644 |
+
else:
|
| 1645 |
+
tz = None
|
| 1646 |
+
if tzwin is not None:
|
| 1647 |
+
try:
|
| 1648 |
+
tz = tzwin(name)
|
| 1649 |
+
except (WindowsError, UnicodeEncodeError):
|
| 1650 |
+
# UnicodeEncodeError is for Python 2.7 compat
|
| 1651 |
+
tz = None
|
| 1652 |
+
|
| 1653 |
+
if not tz:
|
| 1654 |
+
from dateutil.zoneinfo import get_zonefile_instance
|
| 1655 |
+
tz = get_zonefile_instance().get(name)
|
| 1656 |
+
|
| 1657 |
+
if not tz:
|
| 1658 |
+
for c in name:
|
| 1659 |
+
# name is not a tzstr unless it has at least
|
| 1660 |
+
# one offset. For short values of "name", an
|
| 1661 |
+
# explicit for loop seems to be the fastest way
|
| 1662 |
+
# To determine if a string contains a digit
|
| 1663 |
+
if c in "0123456789":
|
| 1664 |
+
try:
|
| 1665 |
+
tz = tzstr(name)
|
| 1666 |
+
except ValueError:
|
| 1667 |
+
pass
|
| 1668 |
+
break
|
| 1669 |
+
else:
|
| 1670 |
+
if name in ("GMT", "UTC"):
|
| 1671 |
+
tz = UTC
|
| 1672 |
+
elif name in time.tzname:
|
| 1673 |
+
tz = tzlocal()
|
| 1674 |
+
return tz
|
| 1675 |
+
|
| 1676 |
+
return GettzFunc()
|
| 1677 |
+
|
| 1678 |
+
|
| 1679 |
+
gettz = __get_gettz()
|
| 1680 |
+
del __get_gettz
|
| 1681 |
+
|
| 1682 |
+
|
| 1683 |
+
def datetime_exists(dt, tz=None):
|
| 1684 |
+
"""
|
| 1685 |
+
Given a datetime and a time zone, determine whether or not a given datetime
|
| 1686 |
+
would fall in a gap.
|
| 1687 |
+
|
| 1688 |
+
:param dt:
|
| 1689 |
+
A :class:`datetime.datetime` (whose time zone will be ignored if ``tz``
|
| 1690 |
+
is provided.)
|
| 1691 |
+
|
| 1692 |
+
:param tz:
|
| 1693 |
+
A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If
|
| 1694 |
+
``None`` or not provided, the datetime's own time zone will be used.
|
| 1695 |
+
|
| 1696 |
+
:return:
|
| 1697 |
+
Returns a boolean value whether or not the "wall time" exists in
|
| 1698 |
+
``tz``.
|
| 1699 |
+
|
| 1700 |
+
.. versionadded:: 2.7.0
|
| 1701 |
+
"""
|
| 1702 |
+
if tz is None:
|
| 1703 |
+
if dt.tzinfo is None:
|
| 1704 |
+
raise ValueError('Datetime is naive and no time zone provided.')
|
| 1705 |
+
tz = dt.tzinfo
|
| 1706 |
+
|
| 1707 |
+
dt = dt.replace(tzinfo=None)
|
| 1708 |
+
|
| 1709 |
+
# This is essentially a test of whether or not the datetime can survive
|
| 1710 |
+
# a round trip to UTC.
|
| 1711 |
+
dt_rt = dt.replace(tzinfo=tz).astimezone(UTC).astimezone(tz)
|
| 1712 |
+
dt_rt = dt_rt.replace(tzinfo=None)
|
| 1713 |
+
|
| 1714 |
+
return dt == dt_rt
|
| 1715 |
+
|
| 1716 |
+
|
| 1717 |
+
def datetime_ambiguous(dt, tz=None):
|
| 1718 |
+
"""
|
| 1719 |
+
Given a datetime and a time zone, determine whether or not a given datetime
|
| 1720 |
+
is ambiguous (i.e if there are two times differentiated only by their DST
|
| 1721 |
+
status).
|
| 1722 |
+
|
| 1723 |
+
:param dt:
|
| 1724 |
+
A :class:`datetime.datetime` (whose time zone will be ignored if ``tz``
|
| 1725 |
+
is provided.)
|
| 1726 |
+
|
| 1727 |
+
:param tz:
|
| 1728 |
+
A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If
|
| 1729 |
+
``None`` or not provided, the datetime's own time zone will be used.
|
| 1730 |
+
|
| 1731 |
+
:return:
|
| 1732 |
+
Returns a boolean value whether or not the "wall time" is ambiguous in
|
| 1733 |
+
``tz``.
|
| 1734 |
+
|
| 1735 |
+
.. versionadded:: 2.6.0
|
| 1736 |
+
"""
|
| 1737 |
+
if tz is None:
|
| 1738 |
+
if dt.tzinfo is None:
|
| 1739 |
+
raise ValueError('Datetime is naive and no time zone provided.')
|
| 1740 |
+
|
| 1741 |
+
tz = dt.tzinfo
|
| 1742 |
+
|
| 1743 |
+
# If a time zone defines its own "is_ambiguous" function, we'll use that.
|
| 1744 |
+
is_ambiguous_fn = getattr(tz, 'is_ambiguous', None)
|
| 1745 |
+
if is_ambiguous_fn is not None:
|
| 1746 |
+
try:
|
| 1747 |
+
return tz.is_ambiguous(dt)
|
| 1748 |
+
except Exception:
|
| 1749 |
+
pass
|
| 1750 |
+
|
| 1751 |
+
# If it doesn't come out and tell us it's ambiguous, we'll just check if
|
| 1752 |
+
# the fold attribute has any effect on this particular date and time.
|
| 1753 |
+
dt = dt.replace(tzinfo=tz)
|
| 1754 |
+
wall_0 = enfold(dt, fold=0)
|
| 1755 |
+
wall_1 = enfold(dt, fold=1)
|
| 1756 |
+
|
| 1757 |
+
same_offset = wall_0.utcoffset() == wall_1.utcoffset()
|
| 1758 |
+
same_dst = wall_0.dst() == wall_1.dst()
|
| 1759 |
+
|
| 1760 |
+
return not (same_offset and same_dst)
|
| 1761 |
+
|
| 1762 |
+
|
| 1763 |
+
def resolve_imaginary(dt):
|
| 1764 |
+
"""
|
| 1765 |
+
Given a datetime that may be imaginary, return an existing datetime.
|
| 1766 |
+
|
| 1767 |
+
This function assumes that an imaginary datetime represents what the
|
| 1768 |
+
wall time would be in a zone had the offset transition not occurred, so
|
| 1769 |
+
it will always fall forward by the transition's change in offset.
|
| 1770 |
+
|
| 1771 |
+
.. doctest::
|
| 1772 |
+
|
| 1773 |
+
>>> from dateutil import tz
|
| 1774 |
+
>>> from datetime import datetime
|
| 1775 |
+
>>> NYC = tz.gettz('America/New_York')
|
| 1776 |
+
>>> print(tz.resolve_imaginary(datetime(2017, 3, 12, 2, 30, tzinfo=NYC)))
|
| 1777 |
+
2017-03-12 03:30:00-04:00
|
| 1778 |
+
|
| 1779 |
+
>>> KIR = tz.gettz('Pacific/Kiritimati')
|
| 1780 |
+
>>> print(tz.resolve_imaginary(datetime(1995, 1, 1, 12, 30, tzinfo=KIR)))
|
| 1781 |
+
1995-01-02 12:30:00+14:00
|
| 1782 |
+
|
| 1783 |
+
As a note, :func:`datetime.astimezone` is guaranteed to produce a valid,
|
| 1784 |
+
existing datetime, so a round-trip to and from UTC is sufficient to get
|
| 1785 |
+
an extant datetime, however, this generally "falls back" to an earlier time
|
| 1786 |
+
rather than falling forward to the STD side (though no guarantees are made
|
| 1787 |
+
about this behavior).
|
| 1788 |
+
|
| 1789 |
+
:param dt:
|
| 1790 |
+
A :class:`datetime.datetime` which may or may not exist.
|
| 1791 |
+
|
| 1792 |
+
:return:
|
| 1793 |
+
Returns an existing :class:`datetime.datetime`. If ``dt`` was not
|
| 1794 |
+
imaginary, the datetime returned is guaranteed to be the same object
|
| 1795 |
+
passed to the function.
|
| 1796 |
+
|
| 1797 |
+
.. versionadded:: 2.7.0
|
| 1798 |
+
"""
|
| 1799 |
+
if dt.tzinfo is not None and not datetime_exists(dt):
|
| 1800 |
+
|
| 1801 |
+
curr_offset = (dt + datetime.timedelta(hours=24)).utcoffset()
|
| 1802 |
+
old_offset = (dt - datetime.timedelta(hours=24)).utcoffset()
|
| 1803 |
+
|
| 1804 |
+
dt += curr_offset - old_offset
|
| 1805 |
+
|
| 1806 |
+
return dt
|
| 1807 |
+
|
| 1808 |
+
|
| 1809 |
+
def _datetime_to_timestamp(dt):
|
| 1810 |
+
"""
|
| 1811 |
+
Convert a :class:`datetime.datetime` object to an epoch timestamp in
|
| 1812 |
+
seconds since January 1, 1970, ignoring the time zone.
|
| 1813 |
+
"""
|
| 1814 |
+
return (dt.replace(tzinfo=None) - EPOCH).total_seconds()
|
| 1815 |
+
|
| 1816 |
+
|
| 1817 |
+
if sys.version_info >= (3, 6):
|
| 1818 |
+
def _get_supported_offset(second_offset):
|
| 1819 |
+
return second_offset
|
| 1820 |
+
else:
|
| 1821 |
+
def _get_supported_offset(second_offset):
|
| 1822 |
+
# For python pre-3.6, round to full-minutes if that's not the case.
|
| 1823 |
+
# Python's datetime doesn't accept sub-minute timezones. Check
|
| 1824 |
+
# http://python.org/sf/1447945 or https://bugs.python.org/issue5288
|
| 1825 |
+
# for some information.
|
| 1826 |
+
old_offset = second_offset
|
| 1827 |
+
calculated_offset = 60 * ((second_offset + 30) // 60)
|
| 1828 |
+
return calculated_offset
|
| 1829 |
+
|
| 1830 |
+
|
| 1831 |
+
try:
|
| 1832 |
+
# Python 3.7 feature
|
| 1833 |
+
from contextlib import nullcontext as _nullcontext
|
| 1834 |
+
except ImportError:
|
| 1835 |
+
class _nullcontext(object):
|
| 1836 |
+
"""
|
| 1837 |
+
Class for wrapping contexts so that they are passed through in a
|
| 1838 |
+
with statement.
|
| 1839 |
+
"""
|
| 1840 |
+
def __init__(self, context):
|
| 1841 |
+
self.context = context
|
| 1842 |
+
|
| 1843 |
+
def __enter__(self):
|
| 1844 |
+
return self.context
|
| 1845 |
+
|
| 1846 |
+
def __exit__(*args, **kwargs):
|
| 1847 |
+
pass
|
| 1848 |
+
|
| 1849 |
+
# vim:ts=4:sw=4:et
|
vllm/lib/python3.10/site-packages/dateutil/tz/win.py
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
This module provides an interface to the native time zone data on Windows,
|
| 4 |
+
including :py:class:`datetime.tzinfo` implementations.
|
| 5 |
+
|
| 6 |
+
Attempting to import this module on a non-Windows platform will raise an
|
| 7 |
+
:py:obj:`ImportError`.
|
| 8 |
+
"""
|
| 9 |
+
# This code was originally contributed by Jeffrey Harris.
|
| 10 |
+
import datetime
|
| 11 |
+
import struct
|
| 12 |
+
|
| 13 |
+
from six.moves import winreg
|
| 14 |
+
from six import text_type
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
import ctypes
|
| 18 |
+
from ctypes import wintypes
|
| 19 |
+
except ValueError:
|
| 20 |
+
# ValueError is raised on non-Windows systems for some horrible reason.
|
| 21 |
+
raise ImportError("Running tzwin on non-Windows system")
|
| 22 |
+
|
| 23 |
+
from ._common import tzrangebase
|
| 24 |
+
|
| 25 |
+
__all__ = ["tzwin", "tzwinlocal", "tzres"]
|
| 26 |
+
|
| 27 |
+
ONEWEEK = datetime.timedelta(7)
|
| 28 |
+
|
| 29 |
+
TZKEYNAMENT = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones"
|
| 30 |
+
TZKEYNAME9X = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones"
|
| 31 |
+
TZLOCALKEYNAME = r"SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _settzkeyname():
|
| 35 |
+
handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
|
| 36 |
+
try:
|
| 37 |
+
winreg.OpenKey(handle, TZKEYNAMENT).Close()
|
| 38 |
+
TZKEYNAME = TZKEYNAMENT
|
| 39 |
+
except WindowsError:
|
| 40 |
+
TZKEYNAME = TZKEYNAME9X
|
| 41 |
+
handle.Close()
|
| 42 |
+
return TZKEYNAME
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
TZKEYNAME = _settzkeyname()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class tzres(object):
|
| 49 |
+
"""
|
| 50 |
+
Class for accessing ``tzres.dll``, which contains timezone name related
|
| 51 |
+
resources.
|
| 52 |
+
|
| 53 |
+
.. versionadded:: 2.5.0
|
| 54 |
+
"""
|
| 55 |
+
p_wchar = ctypes.POINTER(wintypes.WCHAR) # Pointer to a wide char
|
| 56 |
+
|
| 57 |
+
def __init__(self, tzres_loc='tzres.dll'):
|
| 58 |
+
# Load the user32 DLL so we can load strings from tzres
|
| 59 |
+
user32 = ctypes.WinDLL('user32')
|
| 60 |
+
|
| 61 |
+
# Specify the LoadStringW function
|
| 62 |
+
user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
|
| 63 |
+
wintypes.UINT,
|
| 64 |
+
wintypes.LPWSTR,
|
| 65 |
+
ctypes.c_int)
|
| 66 |
+
|
| 67 |
+
self.LoadStringW = user32.LoadStringW
|
| 68 |
+
self._tzres = ctypes.WinDLL(tzres_loc)
|
| 69 |
+
self.tzres_loc = tzres_loc
|
| 70 |
+
|
| 71 |
+
def load_name(self, offset):
|
| 72 |
+
"""
|
| 73 |
+
Load a timezone name from a DLL offset (integer).
|
| 74 |
+
|
| 75 |
+
>>> from dateutil.tzwin import tzres
|
| 76 |
+
>>> tzr = tzres()
|
| 77 |
+
>>> print(tzr.load_name(112))
|
| 78 |
+
'Eastern Standard Time'
|
| 79 |
+
|
| 80 |
+
:param offset:
|
| 81 |
+
A positive integer value referring to a string from the tzres dll.
|
| 82 |
+
|
| 83 |
+
.. note::
|
| 84 |
+
|
| 85 |
+
Offsets found in the registry are generally of the form
|
| 86 |
+
``@tzres.dll,-114``. The offset in this case is 114, not -114.
|
| 87 |
+
|
| 88 |
+
"""
|
| 89 |
+
resource = self.p_wchar()
|
| 90 |
+
lpBuffer = ctypes.cast(ctypes.byref(resource), wintypes.LPWSTR)
|
| 91 |
+
nchar = self.LoadStringW(self._tzres._handle, offset, lpBuffer, 0)
|
| 92 |
+
return resource[:nchar]
|
| 93 |
+
|
| 94 |
+
def name_from_string(self, tzname_str):
|
| 95 |
+
"""
|
| 96 |
+
Parse strings as returned from the Windows registry into the time zone
|
| 97 |
+
name as defined in the registry.
|
| 98 |
+
|
| 99 |
+
>>> from dateutil.tzwin import tzres
|
| 100 |
+
>>> tzr = tzres()
|
| 101 |
+
>>> print(tzr.name_from_string('@tzres.dll,-251'))
|
| 102 |
+
'Dateline Daylight Time'
|
| 103 |
+
>>> print(tzr.name_from_string('Eastern Standard Time'))
|
| 104 |
+
'Eastern Standard Time'
|
| 105 |
+
|
| 106 |
+
:param tzname_str:
|
| 107 |
+
A timezone name string as returned from a Windows registry key.
|
| 108 |
+
|
| 109 |
+
:return:
|
| 110 |
+
Returns the localized timezone string from tzres.dll if the string
|
| 111 |
+
is of the form `@tzres.dll,-offset`, else returns the input string.
|
| 112 |
+
"""
|
| 113 |
+
if not tzname_str.startswith('@'):
|
| 114 |
+
return tzname_str
|
| 115 |
+
|
| 116 |
+
name_splt = tzname_str.split(',-')
|
| 117 |
+
try:
|
| 118 |
+
offset = int(name_splt[1])
|
| 119 |
+
except:
|
| 120 |
+
raise ValueError("Malformed timezone string.")
|
| 121 |
+
|
| 122 |
+
return self.load_name(offset)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class tzwinbase(tzrangebase):
|
| 126 |
+
"""tzinfo class based on win32's timezones available in the registry."""
|
| 127 |
+
def __init__(self):
|
| 128 |
+
raise NotImplementedError('tzwinbase is an abstract base class')
|
| 129 |
+
|
| 130 |
+
def __eq__(self, other):
|
| 131 |
+
# Compare on all relevant dimensions, including name.
|
| 132 |
+
if not isinstance(other, tzwinbase):
|
| 133 |
+
return NotImplemented
|
| 134 |
+
|
| 135 |
+
return (self._std_offset == other._std_offset and
|
| 136 |
+
self._dst_offset == other._dst_offset and
|
| 137 |
+
self._stddayofweek == other._stddayofweek and
|
| 138 |
+
self._dstdayofweek == other._dstdayofweek and
|
| 139 |
+
self._stdweeknumber == other._stdweeknumber and
|
| 140 |
+
self._dstweeknumber == other._dstweeknumber and
|
| 141 |
+
self._stdhour == other._stdhour and
|
| 142 |
+
self._dsthour == other._dsthour and
|
| 143 |
+
self._stdminute == other._stdminute and
|
| 144 |
+
self._dstminute == other._dstminute and
|
| 145 |
+
self._std_abbr == other._std_abbr and
|
| 146 |
+
self._dst_abbr == other._dst_abbr)
|
| 147 |
+
|
| 148 |
+
@staticmethod
|
| 149 |
+
def list():
|
| 150 |
+
"""Return a list of all time zones known to the system."""
|
| 151 |
+
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
|
| 152 |
+
with winreg.OpenKey(handle, TZKEYNAME) as tzkey:
|
| 153 |
+
result = [winreg.EnumKey(tzkey, i)
|
| 154 |
+
for i in range(winreg.QueryInfoKey(tzkey)[0])]
|
| 155 |
+
return result
|
| 156 |
+
|
| 157 |
+
def display(self):
|
| 158 |
+
"""
|
| 159 |
+
Return the display name of the time zone.
|
| 160 |
+
"""
|
| 161 |
+
return self._display
|
| 162 |
+
|
| 163 |
+
def transitions(self, year):
|
| 164 |
+
"""
|
| 165 |
+
For a given year, get the DST on and off transition times, expressed
|
| 166 |
+
always on the standard time side. For zones with no transitions, this
|
| 167 |
+
function returns ``None``.
|
| 168 |
+
|
| 169 |
+
:param year:
|
| 170 |
+
The year whose transitions you would like to query.
|
| 171 |
+
|
| 172 |
+
:return:
|
| 173 |
+
Returns a :class:`tuple` of :class:`datetime.datetime` objects,
|
| 174 |
+
``(dston, dstoff)`` for zones with an annual DST transition, or
|
| 175 |
+
``None`` for fixed offset zones.
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
if not self.hasdst:
|
| 179 |
+
return None
|
| 180 |
+
|
| 181 |
+
dston = picknthweekday(year, self._dstmonth, self._dstdayofweek,
|
| 182 |
+
self._dsthour, self._dstminute,
|
| 183 |
+
self._dstweeknumber)
|
| 184 |
+
|
| 185 |
+
dstoff = picknthweekday(year, self._stdmonth, self._stddayofweek,
|
| 186 |
+
self._stdhour, self._stdminute,
|
| 187 |
+
self._stdweeknumber)
|
| 188 |
+
|
| 189 |
+
# Ambiguous dates default to the STD side
|
| 190 |
+
dstoff -= self._dst_base_offset
|
| 191 |
+
|
| 192 |
+
return dston, dstoff
|
| 193 |
+
|
| 194 |
+
def _get_hasdst(self):
|
| 195 |
+
return self._dstmonth != 0
|
| 196 |
+
|
| 197 |
+
@property
|
| 198 |
+
def _dst_base_offset(self):
|
| 199 |
+
return self._dst_base_offset_
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class tzwin(tzwinbase):
|
| 203 |
+
"""
|
| 204 |
+
Time zone object created from the zone info in the Windows registry
|
| 205 |
+
|
| 206 |
+
These are similar to :py:class:`dateutil.tz.tzrange` objects in that
|
| 207 |
+
the time zone data is provided in the format of a single offset rule
|
| 208 |
+
for either 0 or 2 time zone transitions per year.
|
| 209 |
+
|
| 210 |
+
:param: name
|
| 211 |
+
The name of a Windows time zone key, e.g. "Eastern Standard Time".
|
| 212 |
+
The full list of keys can be retrieved with :func:`tzwin.list`.
|
| 213 |
+
"""
|
| 214 |
+
|
| 215 |
+
def __init__(self, name):
|
| 216 |
+
self._name = name
|
| 217 |
+
|
| 218 |
+
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
|
| 219 |
+
tzkeyname = text_type("{kn}\\{name}").format(kn=TZKEYNAME, name=name)
|
| 220 |
+
with winreg.OpenKey(handle, tzkeyname) as tzkey:
|
| 221 |
+
keydict = valuestodict(tzkey)
|
| 222 |
+
|
| 223 |
+
self._std_abbr = keydict["Std"]
|
| 224 |
+
self._dst_abbr = keydict["Dlt"]
|
| 225 |
+
|
| 226 |
+
self._display = keydict["Display"]
|
| 227 |
+
|
| 228 |
+
# See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
|
| 229 |
+
tup = struct.unpack("=3l16h", keydict["TZI"])
|
| 230 |
+
stdoffset = -tup[0]-tup[1] # Bias + StandardBias * -1
|
| 231 |
+
dstoffset = stdoffset-tup[2] # + DaylightBias * -1
|
| 232 |
+
self._std_offset = datetime.timedelta(minutes=stdoffset)
|
| 233 |
+
self._dst_offset = datetime.timedelta(minutes=dstoffset)
|
| 234 |
+
|
| 235 |
+
# for the meaning see the win32 TIME_ZONE_INFORMATION structure docs
|
| 236 |
+
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx
|
| 237 |
+
(self._stdmonth,
|
| 238 |
+
self._stddayofweek, # Sunday = 0
|
| 239 |
+
self._stdweeknumber, # Last = 5
|
| 240 |
+
self._stdhour,
|
| 241 |
+
self._stdminute) = tup[4:9]
|
| 242 |
+
|
| 243 |
+
(self._dstmonth,
|
| 244 |
+
self._dstdayofweek, # Sunday = 0
|
| 245 |
+
self._dstweeknumber, # Last = 5
|
| 246 |
+
self._dsthour,
|
| 247 |
+
self._dstminute) = tup[12:17]
|
| 248 |
+
|
| 249 |
+
self._dst_base_offset_ = self._dst_offset - self._std_offset
|
| 250 |
+
self.hasdst = self._get_hasdst()
|
| 251 |
+
|
| 252 |
+
def __repr__(self):
|
| 253 |
+
return "tzwin(%s)" % repr(self._name)
|
| 254 |
+
|
| 255 |
+
def __reduce__(self):
|
| 256 |
+
return (self.__class__, (self._name,))
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
class tzwinlocal(tzwinbase):
|
| 260 |
+
"""
|
| 261 |
+
Class representing the local time zone information in the Windows registry
|
| 262 |
+
|
| 263 |
+
While :class:`dateutil.tz.tzlocal` makes system calls (via the :mod:`time`
|
| 264 |
+
module) to retrieve time zone information, ``tzwinlocal`` retrieves the
|
| 265 |
+
rules directly from the Windows registry and creates an object like
|
| 266 |
+
:class:`dateutil.tz.tzwin`.
|
| 267 |
+
|
| 268 |
+
Because Windows does not have an equivalent of :func:`time.tzset`, on
|
| 269 |
+
Windows, :class:`dateutil.tz.tzlocal` instances will always reflect the
|
| 270 |
+
time zone settings *at the time that the process was started*, meaning
|
| 271 |
+
changes to the machine's time zone settings during the run of a program
|
| 272 |
+
on Windows will **not** be reflected by :class:`dateutil.tz.tzlocal`.
|
| 273 |
+
Because ``tzwinlocal`` reads the registry directly, it is unaffected by
|
| 274 |
+
this issue.
|
| 275 |
+
"""
|
| 276 |
+
def __init__(self):
|
| 277 |
+
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:
|
| 278 |
+
with winreg.OpenKey(handle, TZLOCALKEYNAME) as tzlocalkey:
|
| 279 |
+
keydict = valuestodict(tzlocalkey)
|
| 280 |
+
|
| 281 |
+
self._std_abbr = keydict["StandardName"]
|
| 282 |
+
self._dst_abbr = keydict["DaylightName"]
|
| 283 |
+
|
| 284 |
+
try:
|
| 285 |
+
tzkeyname = text_type('{kn}\\{sn}').format(kn=TZKEYNAME,
|
| 286 |
+
sn=self._std_abbr)
|
| 287 |
+
with winreg.OpenKey(handle, tzkeyname) as tzkey:
|
| 288 |
+
_keydict = valuestodict(tzkey)
|
| 289 |
+
self._display = _keydict["Display"]
|
| 290 |
+
except OSError:
|
| 291 |
+
self._display = None
|
| 292 |
+
|
| 293 |
+
stdoffset = -keydict["Bias"]-keydict["StandardBias"]
|
| 294 |
+
dstoffset = stdoffset-keydict["DaylightBias"]
|
| 295 |
+
|
| 296 |
+
self._std_offset = datetime.timedelta(minutes=stdoffset)
|
| 297 |
+
self._dst_offset = datetime.timedelta(minutes=dstoffset)
|
| 298 |
+
|
| 299 |
+
# For reasons unclear, in this particular key, the day of week has been
|
| 300 |
+
# moved to the END of the SYSTEMTIME structure.
|
| 301 |
+
tup = struct.unpack("=8h", keydict["StandardStart"])
|
| 302 |
+
|
| 303 |
+
(self._stdmonth,
|
| 304 |
+
self._stdweeknumber, # Last = 5
|
| 305 |
+
self._stdhour,
|
| 306 |
+
self._stdminute) = tup[1:5]
|
| 307 |
+
|
| 308 |
+
self._stddayofweek = tup[7]
|
| 309 |
+
|
| 310 |
+
tup = struct.unpack("=8h", keydict["DaylightStart"])
|
| 311 |
+
|
| 312 |
+
(self._dstmonth,
|
| 313 |
+
self._dstweeknumber, # Last = 5
|
| 314 |
+
self._dsthour,
|
| 315 |
+
self._dstminute) = tup[1:5]
|
| 316 |
+
|
| 317 |
+
self._dstdayofweek = tup[7]
|
| 318 |
+
|
| 319 |
+
self._dst_base_offset_ = self._dst_offset - self._std_offset
|
| 320 |
+
self.hasdst = self._get_hasdst()
|
| 321 |
+
|
| 322 |
+
def __repr__(self):
|
| 323 |
+
return "tzwinlocal()"
|
| 324 |
+
|
| 325 |
+
def __str__(self):
|
| 326 |
+
# str will return the standard name, not the daylight name.
|
| 327 |
+
return "tzwinlocal(%s)" % repr(self._std_abbr)
|
| 328 |
+
|
| 329 |
+
def __reduce__(self):
|
| 330 |
+
return (self.__class__, ())
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def picknthweekday(year, month, dayofweek, hour, minute, whichweek):
|
| 334 |
+
""" dayofweek == 0 means Sunday, whichweek 5 means last instance """
|
| 335 |
+
first = datetime.datetime(year, month, 1, hour, minute)
|
| 336 |
+
|
| 337 |
+
# This will work if dayofweek is ISO weekday (1-7) or Microsoft-style (0-6),
|
| 338 |
+
# Because 7 % 7 = 0
|
| 339 |
+
weekdayone = first.replace(day=((dayofweek - first.isoweekday()) % 7) + 1)
|
| 340 |
+
wd = weekdayone + ((whichweek - 1) * ONEWEEK)
|
| 341 |
+
if (wd.month != month):
|
| 342 |
+
wd -= ONEWEEK
|
| 343 |
+
|
| 344 |
+
return wd
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def valuestodict(key):
|
| 348 |
+
"""Convert a registry key's values to a dictionary."""
|
| 349 |
+
dout = {}
|
| 350 |
+
size = winreg.QueryInfoKey(key)[1]
|
| 351 |
+
tz_res = None
|
| 352 |
+
|
| 353 |
+
for i in range(size):
|
| 354 |
+
key_name, value, dtype = winreg.EnumValue(key, i)
|
| 355 |
+
if dtype == winreg.REG_DWORD or dtype == winreg.REG_DWORD_LITTLE_ENDIAN:
|
| 356 |
+
# If it's a DWORD (32-bit integer), it's stored as unsigned - convert
|
| 357 |
+
# that to a proper signed integer
|
| 358 |
+
if value & (1 << 31):
|
| 359 |
+
value = value - (1 << 32)
|
| 360 |
+
elif dtype == winreg.REG_SZ:
|
| 361 |
+
# If it's a reference to the tzres DLL, load the actual string
|
| 362 |
+
if value.startswith('@tzres'):
|
| 363 |
+
tz_res = tz_res or tzres()
|
| 364 |
+
value = tz_res.name_from_string(value)
|
| 365 |
+
|
| 366 |
+
value = value.rstrip('\x00') # Remove trailing nulls
|
| 367 |
+
|
| 368 |
+
dout[key_name] = value
|
| 369 |
+
|
| 370 |
+
return dout
|
vllm/lib/python3.10/site-packages/dateutil/tzwin.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tzwin has moved to dateutil.tz.win
|
| 2 |
+
from .tz.win import *
|
vllm/lib/python3.10/site-packages/dateutil/utils.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
This module offers general convenience and utility functions for dealing with
|
| 4 |
+
datetimes.
|
| 5 |
+
|
| 6 |
+
.. versionadded:: 2.7.0
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import unicode_literals
|
| 9 |
+
|
| 10 |
+
from datetime import datetime, time
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def today(tzinfo=None):
|
| 14 |
+
"""
|
| 15 |
+
Returns a :py:class:`datetime` representing the current day at midnight
|
| 16 |
+
|
| 17 |
+
:param tzinfo:
|
| 18 |
+
The time zone to attach (also used to determine the current day).
|
| 19 |
+
|
| 20 |
+
:return:
|
| 21 |
+
A :py:class:`datetime.datetime` object representing the current day
|
| 22 |
+
at midnight.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
dt = datetime.now(tzinfo)
|
| 26 |
+
return datetime.combine(dt.date(), time(0, tzinfo=tzinfo))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def default_tzinfo(dt, tzinfo):
|
| 30 |
+
"""
|
| 31 |
+
Sets the ``tzinfo`` parameter on naive datetimes only
|
| 32 |
+
|
| 33 |
+
This is useful for example when you are provided a datetime that may have
|
| 34 |
+
either an implicit or explicit time zone, such as when parsing a time zone
|
| 35 |
+
string.
|
| 36 |
+
|
| 37 |
+
.. doctest::
|
| 38 |
+
|
| 39 |
+
>>> from dateutil.tz import tzoffset
|
| 40 |
+
>>> from dateutil.parser import parse
|
| 41 |
+
>>> from dateutil.utils import default_tzinfo
|
| 42 |
+
>>> dflt_tz = tzoffset("EST", -18000)
|
| 43 |
+
>>> print(default_tzinfo(parse('2014-01-01 12:30 UTC'), dflt_tz))
|
| 44 |
+
2014-01-01 12:30:00+00:00
|
| 45 |
+
>>> print(default_tzinfo(parse('2014-01-01 12:30'), dflt_tz))
|
| 46 |
+
2014-01-01 12:30:00-05:00
|
| 47 |
+
|
| 48 |
+
:param dt:
|
| 49 |
+
The datetime on which to replace the time zone
|
| 50 |
+
|
| 51 |
+
:param tzinfo:
|
| 52 |
+
The :py:class:`datetime.tzinfo` subclass instance to assign to
|
| 53 |
+
``dt`` if (and only if) it is naive.
|
| 54 |
+
|
| 55 |
+
:return:
|
| 56 |
+
Returns an aware :py:class:`datetime.datetime`.
|
| 57 |
+
"""
|
| 58 |
+
if dt.tzinfo is not None:
|
| 59 |
+
return dt
|
| 60 |
+
else:
|
| 61 |
+
return dt.replace(tzinfo=tzinfo)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def within_delta(dt1, dt2, delta):
|
| 65 |
+
"""
|
| 66 |
+
Useful for comparing two datetimes that may have a negligible difference
|
| 67 |
+
to be considered equal.
|
| 68 |
+
"""
|
| 69 |
+
delta = abs(delta)
|
| 70 |
+
difference = dt1 - dt2
|
| 71 |
+
return -delta <= difference <= delta
|
vllm/lib/python3.10/site-packages/dateutil/zoneinfo/rebuild.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
+
import shutil
|
| 5 |
+
import json
|
| 6 |
+
from subprocess import check_call, check_output
|
| 7 |
+
from tarfile import TarFile
|
| 8 |
+
|
| 9 |
+
from dateutil.zoneinfo import METADATA_FN, ZONEFILENAME
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def rebuild(filename, tag=None, format="gz", zonegroups=[], metadata=None):
|
| 13 |
+
"""Rebuild the internal timezone info in dateutil/zoneinfo/zoneinfo*tar*
|
| 14 |
+
|
| 15 |
+
filename is the timezone tarball from ``ftp.iana.org/tz``.
|
| 16 |
+
|
| 17 |
+
"""
|
| 18 |
+
tmpdir = tempfile.mkdtemp()
|
| 19 |
+
zonedir = os.path.join(tmpdir, "zoneinfo")
|
| 20 |
+
moduledir = os.path.dirname(__file__)
|
| 21 |
+
try:
|
| 22 |
+
with TarFile.open(filename) as tf:
|
| 23 |
+
for name in zonegroups:
|
| 24 |
+
tf.extract(name, tmpdir)
|
| 25 |
+
filepaths = [os.path.join(tmpdir, n) for n in zonegroups]
|
| 26 |
+
|
| 27 |
+
_run_zic(zonedir, filepaths)
|
| 28 |
+
|
| 29 |
+
# write metadata file
|
| 30 |
+
with open(os.path.join(zonedir, METADATA_FN), 'w') as f:
|
| 31 |
+
json.dump(metadata, f, indent=4, sort_keys=True)
|
| 32 |
+
target = os.path.join(moduledir, ZONEFILENAME)
|
| 33 |
+
with TarFile.open(target, "w:%s" % format) as tf:
|
| 34 |
+
for entry in os.listdir(zonedir):
|
| 35 |
+
entrypath = os.path.join(zonedir, entry)
|
| 36 |
+
tf.add(entrypath, entry)
|
| 37 |
+
finally:
|
| 38 |
+
shutil.rmtree(tmpdir)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _run_zic(zonedir, filepaths):
|
| 42 |
+
"""Calls the ``zic`` compiler in a compatible way to get a "fat" binary.
|
| 43 |
+
|
| 44 |
+
Recent versions of ``zic`` default to ``-b slim``, while older versions
|
| 45 |
+
don't even have the ``-b`` option (but default to "fat" binaries). The
|
| 46 |
+
current version of dateutil does not support Version 2+ TZif files, which
|
| 47 |
+
causes problems when used in conjunction with "slim" binaries, so this
|
| 48 |
+
function is used to ensure that we always get a "fat" binary.
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
help_text = check_output(["zic", "--help"])
|
| 53 |
+
except OSError as e:
|
| 54 |
+
_print_on_nosuchfile(e)
|
| 55 |
+
raise
|
| 56 |
+
|
| 57 |
+
if b"-b " in help_text:
|
| 58 |
+
bloat_args = ["-b", "fat"]
|
| 59 |
+
else:
|
| 60 |
+
bloat_args = []
|
| 61 |
+
|
| 62 |
+
check_call(["zic"] + bloat_args + ["-d", zonedir] + filepaths)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _print_on_nosuchfile(e):
|
| 66 |
+
"""Print helpful troubleshooting message
|
| 67 |
+
|
| 68 |
+
e is an exception raised by subprocess.check_call()
|
| 69 |
+
|
| 70 |
+
"""
|
| 71 |
+
if e.errno == 2:
|
| 72 |
+
logging.error(
|
| 73 |
+
"Could not find zic. Perhaps you need to install "
|
| 74 |
+
"libc-bin or some other package that provides it, "
|
| 75 |
+
"or it's not in your PATH?")
|
vllm/lib/python3.10/site-packages/dns/rdtypes/CH/A.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
import struct
|
| 19 |
+
|
| 20 |
+
import dns.immutable
|
| 21 |
+
import dns.rdtypes.mxbase
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@dns.immutable.immutable
|
| 25 |
+
class A(dns.rdata.Rdata):
|
| 26 |
+
"""A record for Chaosnet"""
|
| 27 |
+
|
| 28 |
+
# domain: the domain of the address
|
| 29 |
+
# address: the 16-bit address
|
| 30 |
+
|
| 31 |
+
__slots__ = ["domain", "address"]
|
| 32 |
+
|
| 33 |
+
def __init__(self, rdclass, rdtype, domain, address):
|
| 34 |
+
super().__init__(rdclass, rdtype)
|
| 35 |
+
self.domain = self._as_name(domain)
|
| 36 |
+
self.address = self._as_uint16(address)
|
| 37 |
+
|
| 38 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 39 |
+
domain = self.domain.choose_relativity(origin, relativize)
|
| 40 |
+
return f"{domain} {self.address:o}"
|
| 41 |
+
|
| 42 |
+
@classmethod
|
| 43 |
+
def from_text(
|
| 44 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 45 |
+
):
|
| 46 |
+
domain = tok.get_name(origin, relativize, relativize_to)
|
| 47 |
+
address = tok.get_uint16(base=8)
|
| 48 |
+
return cls(rdclass, rdtype, domain, address)
|
| 49 |
+
|
| 50 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 51 |
+
self.domain.to_wire(file, compress, origin, canonicalize)
|
| 52 |
+
pref = struct.pack("!H", self.address)
|
| 53 |
+
file.write(pref)
|
| 54 |
+
|
| 55 |
+
@classmethod
|
| 56 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 57 |
+
domain = parser.get_name(origin)
|
| 58 |
+
address = parser.get_uint16()
|
| 59 |
+
return cls(rdclass, rdtype, domain, address)
|
vllm/lib/python3.10/site-packages/dns/rdtypes/CH/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
"""Class CH rdata type classes."""
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
"A",
|
| 22 |
+
]
|
vllm/lib/python3.10/site-packages/dns/rdtypes/CH/__pycache__/A.cpython-310.pyc
ADDED
|
Binary file (1.68 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/CH/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (226 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/A.cpython-310.pyc
ADDED
|
Binary file (1.53 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/AAAA.cpython-310.pyc
ADDED
|
Binary file (1.55 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/HTTPS.cpython-310.pyc
ADDED
|
Binary file (462 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/IPSECKEY.cpython-310.pyc
ADDED
|
Binary file (2.46 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/KX.cpython-310.pyc
ADDED
|
Binary file (465 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/NAPTR.cpython-310.pyc
ADDED
|
Binary file (2.92 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/NSAP.cpython-310.pyc
ADDED
|
Binary file (1.79 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/NSAP_PTR.cpython-310.pyc
ADDED
|
Binary file (473 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/PX.cpython-310.pyc
ADDED
|
Binary file (2.21 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/SRV.cpython-310.pyc
ADDED
|
Binary file (2.39 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/dns/rdtypes/IN/__pycache__/SVCB.cpython-310.pyc
ADDED
|
Binary file (459 Bytes). View file
|
|
|