1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
U
«ý°d¿3ã@s|dZddlmZmZmZmZddlZddlmZddlm    Z    ddl
Z
ddl Z ddgZ dd    „Z Gd
d„deƒZeƒZejZdS) z¯
This module offers a parser for ISO-8601 strings
 
It is intended to support all valid date, time and datetime formats per the
ISO-8601 specification.
 
..versionadded:: 2.7.0
é)ÚdatetimeÚ    timedeltaÚtimeÚdateN)Útz©ÚwrapsÚisoparseÚ    isoparsercstˆƒ‡fdd„ƒ}|S)Nc
sztˆd‡fdd„ƒƒ‰tˆtjƒrhzˆ d¡‰Wn6tk
rf}zd}t t|ƒ|¡W5d}~XYnXˆ|ˆf|ž|ŽS)NÚreadcsˆS©N©r ©Ústr_inr úPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\dateutil/parser/isoparser.pyÚ<lambda>óz,_takes_ascii.<locals>.func.<locals>.<lambda>Úasciiz5ISO-8601 strings should contain only ASCII characters)ÚgetattrÚ
isinstanceÚsixÚ    text_typeÚencodeÚUnicodeEncodeErrorÚ
raise_fromÚ
ValueError)ÚselfrÚargsÚkwargsÚeÚmsg©ÚfrrÚfuncs "z_takes_ascii.<locals>.funcr)r"r#r r!rÚ _takes_asciisr$c@sŒeZdZddd„Zedd„ƒZedd„ƒZedd    „ƒZedd d „ƒZd Z    dZ
e   d¡Z dd„Zdd„Zdd„Zdd„Zdd„Zddd„ZdS)r
NcCsD|dk    r:t|ƒdks(t|ƒdks(|dkr0tdƒ‚| d¡}||_dS)zâ
        :param sep:
            A single character that separates date and time portions. If
            ``None``, the parser will accept any single character.
            For strict ISO-8601 adherence, pass ``'T'``.
        Néé€Ú
0123456789z7Separator must be a single, non-numeric ASCII characterr)ÚlenÚordrrÚ_sep)rÚsepr r rÚ__init__+s
 
zisoparser.__init__cCs˜| |¡\}}t|ƒ|kr^|jdks:|||d…|jkrV|| ||dd…¡7}ntdƒ‚t|ƒdkr|ddkrd|d<t|ŽtddSt|ŽS)u+
 
        Parse an ISO-8601 datetime string into a :class:`datetime.datetime`.
 
        An ISO-8601 datetime string consists of a date portion, followed
        optionally by a time portion - the date and time portions are separated
        by a single character separator, which is ``T`` in the official
        standard. Incomplete date formats (such as ``YYYY-MM``) may *not* be
        combined with a time portion.
 
        Supported date formats are:
 
        Common:
 
        - ``YYYY``
        - ``YYYY-MM`` or ``YYYYMM``
        - ``YYYY-MM-DD`` or ``YYYYMMDD``
 
        Uncommon:
 
        - ``YYYY-Www`` or ``YYYYWww`` - ISO week (day defaults to 0)
        - ``YYYY-Www-D`` or ``YYYYWwwD`` - ISO week and day
 
        The ISO week and day numbering follows the same logic as
        :func:`datetime.date.isocalendar`.
 
        Supported time formats are:
 
        - ``hh``
        - ``hh:mm`` or ``hhmm``
        - ``hh:mm:ss`` or ``hhmmss``
        - ``hh:mm:ss.ssssss`` (Up to 6 sub-second digits)
 
        Midnight is a special case for `hh`, as the standard supports both
        00:00 and 24:00 as a representation. The decimal separator can be
        either a dot or a comma.
 
 
        .. caution::
 
            Support for fractional components other than seconds is part of the
            ISO-8601 standard, but is not currently implemented in this parser.
 
        Supported time zone offset formats are:
 
        - `Z` (UTC)
        - `±HH:MM`
        - `±HHMM`
        - `±HH`
 
        Offsets will be represented as :class:`dateutil.tz.tzoffset` objects,
        with the exception of UTC, which will be represented as
        :class:`dateutil.tz.tzutc`. Time zone offsets equivalent to UTC (such
        as `+00:00`) will also be represented as :class:`dateutil.tz.tzutc`.
 
        :param dt_str:
            A string or stream containing only an ISO-8601 datetime string
 
        :return:
            Returns a :class:`datetime.datetime` representing the string.
            Unspecified components default to their lowest value.
 
        .. warning::
 
            As of version 2.7.0, the strictness of the parser should not be
            considered a stable part of the contract. Any valid ISO-8601 string
            that parses correctly with the default settings will continue to
            parse correctly in future versions, but invalid strings that
            currently fail (e.g. ``2017-01-01T00:00+00:00:00``) are not
            guaranteed to continue failing in future versions if they encode
            a valid date.
 
        .. versionadded:: 2.7.0
        Nr%z&String contains unknown ISO componentséér©Údays)Ú_parse_isodater(r*Ú_parse_isotimerrr)rÚdt_strÚ
componentsÚposr r rr    ;sK  zisoparser.isoparsecCs:| |¡\}}|t|ƒkr2tdd | d¡¡ƒ‚t|ŽS)zÞ
        Parse the date portion of an ISO string.
 
        :param datestr:
            The string portion of an ISO string, without a separator
 
        :return:
            Returns a :class:`datetime.date` object
        zString contains unknown ISO zcomponents: {!r}r)r1r(rÚformatÚdecoder)rZdatestrr4r5r r rÚ parse_isodate”s  ÿzisoparser.parse_isodatecCs&| |¡}|ddkrd|d<t|ŽS)zÜ
        Parse the time portion of an ISO string.
 
        :param timestr:
            The time portion of an ISO string, without a separator
 
        :return:
            Returns a :class:`datetime.time` object
        rr.)r2r)rÚtimestrr4r r rÚ parse_isotime¥s
 zisoparser.parse_isotimeTcCs|j||dS)a
        Parse a valid ISO time zone string.
 
        See :func:`isoparser.isoparse` for details on supported formats.
 
        :param tzstr:
            A string representing an ISO time zone offset
 
        :param zero_as_utc:
            Whether to return :class:`dateutil.tz.tzutc` for zero-offset zones
 
        :return:
            Returns :class:`dateutil.tz.tzoffset` for offsets and
            :class:`dateutil.tz.tzutc` for ``Z`` and (if ``zero_as_utc`` is
            specified) offsets equivalent to UTC.
        )Ú zero_as_utc)Ú _parse_tzstr)rÚtzstrr;r r rÚ parse_tzstrµszisoparser.parse_tzstró-ó:s [\.,]([0-9]+)cCs0z | |¡WStk
r*| |¡YSXdSr )Ú_parse_isodate_commonrÚ_parse_isodate_uncommon)rr3r r rr1Îs zisoparser._parse_isodatecCst|ƒ}dddg}|dkr"tdƒ‚t|dd…ƒ|d<d}||krJ||fS|||d…|jk}|rl|d7}||dkr€tdƒ‚t|||d…ƒ|d<|d7}||kr¼|r´||fStdƒ‚|ræ|||d…|jkrÞtdƒ‚|d7}||dkrútd    ƒ‚t|||d…ƒ|d<||dfS)
Nr%éúISO string too shortrézInvalid common monthzInvalid ISO formatzInvalid separator in ISO stringzInvalid common day)r(rÚintÚ    _DATE_SEP)rr3Úlen_strr4r5Úhas_sepr r rrAÔs6
  zisoparser._parse_isodate_commonc
Cstt|ƒdkrtdƒ‚t|dd…ƒ}|dd…|jk}d|}|||d…dkrÜ|d7}t|||d…ƒ}|d7}d}t|ƒ|krÌ|||d…|jk|kr¨tdƒ‚||7}t|||d…ƒ}|d7}| |||¡}n€t|ƒ|d    krôtd
ƒ‚t|||d    …ƒ}|d    7}|dks.|d t |¡krBtd
d  ||¡ƒ‚t|ddƒt    |dd }|j
|j |j g}    |    |fS)NrCrDrér%óWrEz"Inconsistent use of dash separatorr-zInvalid ordinal dayimz {} for year {}r/) r(rrFrGÚ_calculate_weekdateÚcalendarÚisleapr6rrÚyearÚmonthÚday)
rr3rOrIr5ZweeknoZdaynoZ    base_dateZ ordinal_dayr4r r rrBýs8  
ÿz!isoparser._parse_isodate_uncommoncCsd|krdks$ntd |¡ƒ‚d|kr8dksHntd |¡ƒ‚t|ddƒ}|t| ¡ddd    }|dd
|d}|t|d    S) aâ
        Calculate the day of corresponding to the ISO year-week-day calendar.
 
        This function is effectively the inverse of
        :func:`datetime.date.isocalendar`.
 
        :param year:
            The year in the ISO calendar
 
        :param week:
            The week in the ISO calendar - range is [1, 53]
 
        :param day:
            The day in the ISO calendar - range is [1 (MON), 7 (SUN)]
 
        :return:
            Returns a :class:`datetime.date`
        ré6zInvalid week: {}ézInvalid weekday: {}r%rCrEr/é)rr6rrÚ isocalendar)rrOÚweekrQZjan_4Zweek_1Z week_offsetr r rrL)s zisoparser._calculate_weekdatec    Cs´t|ƒ}dddddg}d}d}|dkr.tdƒ‚d}||krl|dkrl|d7}|||d…dkr€| ||d…¡|d<|}ql|dkr¬|||d…|jkr¬d    }|d7}n2|dkrÞ|rÞ|||d…|jkrÖtd
ƒ‚|d7}|d krt|||d…ƒ||<|d7}|d kr2|j ||d…¡}|s,q2| d¡dd …}t|ƒd d t|ƒ||<|t| ¡ƒ7}q2||kr~tdƒ‚|ddkr°tdd„|dd…Dƒƒr°tdƒ‚|S)NréÿÿÿÿrEzISO time too shortFrJr%s-+ZzTz#Inconsistent use of colon separatorr-éé
zUnused components in ISO stringr.css|]}|dkVqdS)rNr )Ú.0Ú    componentr r rÚ    <genexpr>zsz+isoparser._parse_isotime.<locals>.<genexpr>rCz#Hour may only be 24 at 24:00:00.000)    r(rr<Ú    _TIME_SEPrFÚ_FRACTION_REGEXÚmatchÚgroupÚany)    rr9rHr4r5ÚcomprIÚfracZus_strr r rr2JsH
 
 
zisoparser._parse_isotimecCs|dks|dkrtjSt|ƒdkr*tdƒ‚|dd…dkr@d}n|dd…d    krVd}ntd
ƒ‚t|dd …ƒ}t|ƒd kr€d}n&t||d d …|jkršd nd d…ƒ}|rÀ|dkrÀ|dkrÀtjS|d krÐtdƒ‚|dkràtdƒ‚t d||d|d¡SdS)NóZóz>r-rJrXz0Time zone offset must be 1, 3, 5 or 6 charactersrr%r?rWó+zTime zone offset requires signr-rCé;z#Invalid minutes in time zone offsetéz!Invalid hours in time zone offseté<)rÚUTCr(rrFr]Útzoffset)rr=r;ZmultÚhoursÚminutesr r rr<s(  &zisoparser._parse_tzstr)N)T)T)Ú__name__Ú
__module__Ú __qualname__r,r$r    r8r:r>rGr]ÚreÚcompiler^r1rArBrLr2r<r r r rr
*s$
 
X
 
 
),!5)Ú__doc__rrrrrMZdateutilrÚ    functoolsrrqrÚ__all__r$Úobjectr
ZDEFAULT_ISOPARSERr    r r r rÚ<module>s  w