o
    ŀg                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
Z
ddl
mZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZ z
ddlmZmZ W n eyo   d ZZY nw ddlmZ edZedddddZ e ! Z"e
#eG dd dej$Z%e% Z&e
#eG dd dej$Z'G dd deZ(G dd de)Z*G dd de)Z+G dd deZ,G dd deZ-e
#eG dd de-Z.G dd  d e)Z/G d!d" d"eZ0G d#d$ d$e)Z1ej2d%krd&d'gZ3g d(Z4ng Z3g Z4d)d* Z5e5 Z6[5d:d+d,Z7d:d-d.Z8d/d0 Z9d1d2 Z:ej;d3kr,d4d5 Z<nd6d5 Z<z	dd7l=m>Z? W dS  eyL   G d8d9 d9e)Z?Y dS w );a  
This module offers timezone implementations subclassing the abstract
:py:class:`datetime.tzinfo` type. There are classes to handle tzfile format
files (usually are in :file:`/etc/localtime`, :file:`/usr/share/zoneinfo`,
etc), TZ environment string (in all known formats), given ranges (with help
from relative deltas), local machine timezone, fixed offset timezone, and UTC
timezone.
    N)OrderedDict)string_types)_thread   )tzname_in_python2_tzinfo)tzrangebaseenfold)_validate_fromutc_inputs)_TzSingleton_TzOffsetFactory)_TzStrFactory)tzwin
tzwinlocal)warni  c                   @   sb   e Zd ZdZdd Zdd Zedd Zdd	 Ze	d
d Z
dd ZdZdd Zdd ZejZdS )tzutca  
    This is a tzinfo object that represents the UTC time zone.

    **Examples:**

    .. doctest::

        >>> from datetime import *
        >>> from dateutil.tz import *

        >>> datetime.now()
        datetime.datetime(2003, 9, 27, 9, 40, 1, 521290)

        >>> datetime.now(tzutc())
        datetime.datetime(2003, 9, 27, 12, 40, 12, 156379, tzinfo=tzutc())

        >>> datetime.now(tzutc()).tzname()
        'UTC'

    .. versionchanged:: 2.7.0
        ``tzutc()`` is now a singleton, so the result of ``tzutc()`` will
        always return the same object.

        .. doctest::

            >>> from dateutil.tz import tzutc, UTC
            >>> tzutc() is tzutc()
            True
            >>> tzutc() is UTC
            True
    c                 C      t S NZEROselfdt r   B/var/www/html/myenv/lib/python3.10/site-packages/dateutil/tz/tz.py	utcoffsetJ      ztzutc.utcoffsetc                 C   r   r   r   r   r   r   r   dstM   r   z	tzutc.dstc                 C      dS )NUTCr   r   r   r   r   tznameP   s   ztzutc.tznamec                 C   r   )6  
        Whether or not the "wall time" of a given datetime is ambiguous in this
        zone.

        :param dt:
            A :py:class:`datetime.datetime`, naive or time zone aware.


        :return:
            Returns ``True`` if ambiguous, ``False`` otherwise.

        .. versionadded:: 2.6.0
        Fr   r   r   r   r   is_ambiguousT   s   ztzutc.is_ambiguousc                 C   s   |S )z
        Fast track version of fromutc() returns the original ``dt`` object for
        any valid :py:class:`datetime.datetime` object.
        r   r   r   r   r   fromutcd   s   ztzutc.fromutcc                 C   s0   t |ttfs	tS t |tpt |to|jtkS r   )
isinstancer   tzoffsetNotImplemented_offsetr   r   otherr   r   r   __eq__l   s
   
ztzutc.__eq__Nc                 C   
   | |k S r   r   r(   r   r   r   __ne__u      
ztzutc.__ne__c                 C      d| j j S Nz%s()	__class____name__r   r   r   r   __repr__x      ztzutc.__repr__)r2   
__module____qualname____doc__r   r   r   r    r"   r
   r#   r*   __hash__r,   r4   object
__reduce__r   r   r   r   r   )   s    


r   c                   @   sj   e Zd ZdZdd Zdd Zdd Zedd	 Ze	d
d Z
dd Zdd ZdZdd Zdd ZejZdS )r%   a1  
    A simple class for representing a fixed offset from UTC.

    :param name:
        The timezone name, to be returned when ``tzname()`` is called.
    :param offset:
        The time zone offset in seconds, or (since version 2.6.0, represented
        as a :py:class:`datetime.timedelta` object).
    c              	   C   s@   || _ z| }W n ttfy   Y nw tjt|d| _d S Nseconds)_nametotal_seconds	TypeErrorAttributeErrordatetime	timedelta_get_supported_offsetr'   )r   nameoffsetr   r   r   __init__   s   ztzoffset.__init__c                 C      | j S r   r'   r   r   r   r   r         ztzoffset.utcoffsetc                 C   r   r   r   r   r   r   r   r      r   ztzoffset.dstc                 C   rI   r   )r?   r   r   r   r   r          ztzoffset.tznamec                 C   s
   || j  S r   rJ   r   r   r   r   r#      s   
ztzoffset.fromutcc                 C   r   )a4  
        Whether or not the "wall time" of a given datetime is ambiguous in this
        zone.

        :param dt:
            A :py:class:`datetime.datetime`, naive or time zone aware.
        :return:
            Returns ``True`` if ambiguous, ``False`` otherwise.

        .. versionadded:: 2.6.0
        Fr   r   r   r   r   r"      s   ztzoffset.is_ambiguousc                 C   s   t |tstS | j|jkS r   )r$   r%   r&   r'   r(   r   r   r   r*      s   
ztzoffset.__eq__Nc                 C   r+   r   r   r(   r   r   r   r,      r-   ztzoffset.__ne__c                 C   s"   d| j jt| jt| j f S )Nz
%s(%s, %s))r1   r2   reprr?   intr'   r@   r3   r   r   r   r4      s   ztzoffset.__repr__)r2   r6   r7   r8   rH   r   r   r   r    r
   r#   r"   r*   r9   r,   r4   r:   r;   r   r   r   r   r%      s    	


r%   c                       sx   e Zd ZdZ fddZdd Zdd Zedd	 Zd
d Z	dd Z
dddZdd ZdZdd Zdd ZejZ  ZS )tzlocalzR
    A :class:`tzinfo` subclass built around the ``time`` timezone functions.
    c                    sl   t t|   tjtj d| _tjrtjtj	 d| _
n| j| _
| j
| j | _t| j| _ttj| _d S r<   )superrO   rH   rC   rD   timetimezone_std_offsetdaylightaltzone_dst_offset
_dst_savedbool_hasdsttupler    _tznamesr3   r1   r   r   rH      s   ztzlocal.__init__c                 C   s(   |d u r	| j r	d S | |r| jS | jS r   )rY   _isdstrV   rS   r   r   r   r   r      s
   
ztzlocal.utcoffsetc                 C   s,   |d u r	| j r	d S | |r| j| j S tS r   )rY   r]   rV   rS   r   r   r   r   r   r      s
   
ztzlocal.dstc                 C   s   | j | | S r   )r[   r]   r   r   r   r   r       s   ztzlocal.tznamec                 C   s$   |  |}| o||  || j kS )r!   )_naive_is_dstrW   )r   r   	naive_dstr   r   r   r"      s   
ztzlocal.is_ambiguousc                 C   s   t |}t|tj jS r   )_datetime_to_timestamprQ   	localtimerR   tm_isdst)r   r   	timestampr   r   r   r^     s   ztzlocal._naive_is_dstTc                 C   sF   | j sdS | |}t|dd }| |r!|d ur| | S dS |S )NFfoldT)rY   r^   getattrr"   _fold)r   r   
fold_naivedstvalrd   r   r   r   r]     s   

ztzlocal._isdstc                 C   s~   t |tr| j|jko| j|jkS t |tr&| j o%| jd dv o%| jtkS t |tr=| j o<| jd |j	ko<| j|j
kS tS )Nr   >   GMTr   )r$   rO   rS   rV   r   rY   r[   r   r%   r?   r'   r&   r(   r   r   r   r*   .  s"   




ztzlocal.__eq__Nc                 C   r+   r   r   r(   r   r   r   r,   ?  r-   ztzlocal.__ne__c                 C   r.   r/   r0   r3   r   r   r   r4   B  r5   ztzlocal.__repr__)T)r2   r6   r7   r8   rH   r   r   r   r    r"   r^   r]   r*   r9   r,   r4   r:   r;   __classcell__r   r   r\   r   rO      s    		

(rO   c                   @   sH   e Zd Zg dZdd Zdd Zdd ZdZd	d
 Zdd Z	dd Z
dS )_ttinfo)rG   deltaisdstabbrisstdisgmt	dstoffsetc                 C   s   | j D ]}t| |d  qd S r   	__slots__setattr)r   attrr   r   r   rH   L  s   
z_ttinfo.__init__c                 C   sN   g }| j D ]}t| |}|d ur|d|t|f  qd| jjd|f S )Nz%s=%s%s(%s)z, )rs   re   appendrM   r1   r2   join)r   lru   valuer   r   r   r4   P  s   

z_ttinfo.__repr__c                 C   sb   t |tstS | j|jko0| j|jko0| j|jko0| j|jko0| j|jko0| j|jko0| j	|j	kS r   )
r$   rk   r&   rG   rl   rm   rn   ro   rp   rq   r(   r   r   r   r*   X  s   






z_ttinfo.__eq__Nc                 C   r+   r   r   r(   r   r   r   r,   f  r-   z_ttinfo.__ne__c                 C   s$   i }| j D ]
}t| |d ||< q|S r   )rs   re   r   staterF   r   r   r   __getstate__i  s   
z_ttinfo.__getstate__c                 C   s(   | j D ]}||v rt| |||  qd S r   rr   r{   r   r   r   __setstate__o  s
   
z_ttinfo.__setstate__)r2   r6   r7   rs   rH   r4   r*   r9   r,   r}   r~   r   r   r   r   rk   H  s    rk   c                   @   s    e Zd ZdZg dZdd ZdS )_tzfilezw
    Lightweight class for holding the relevant transition and time zone
    information read from binary tzfiles.
    )
trans_listtrans_list_utc	trans_idxttinfo_list
ttinfo_std
ttinfo_dstttinfo_beforettinfo_firstc                 K   s$   | j D ]}t| |||d  qd S r   )attrsrt   get)r   kwargsru   r   r   r   rH   }  s   
z_tzfile.__init__N)r2   r6   r7   r8   r   rH   r   r   r   r   r   u  s    r   c                       s   e Zd ZdZd& fdd	Zdd Zdd Zd'd
dZdd Zdd Z	dd Z
d&ddZdd Zdd Zdd Zedd Zdd ZdZdd Zd d! Zd"d# Zd$d% Z  ZS )(tzfilea	  
    This is a ``tzinfo`` subclass that allows one to use the ``tzfile(5)``
    format timezone files to extract current and historical zone information.

    :param fileobj:
        This can be an opened file stream or a file name that the time zone
        information can be read from.

    :param filename:
        This is an optional parameter specifying the source of the time zone
        information in the event that ``fileobj`` is a file object. If omitted
        and ``fileobj`` is a file stream, this parameter will be set either to
        ``fileobj``'s ``name`` attribute or to ``repr(fileobj)``.

    See `Sources for Time Zone and Daylight Saving Time Data
    <https://data.iana.org/time-zones/tz-link.html>`_ for more information.
    Time zone files can be compiled from the `IANA Time Zone database files
    <https://www.iana.org/time-zones>`_ with the `zic time zone compiler
    <https://www.freebsd.org/cgi/man.cgi?query=zic&sektion=8>`_

    .. note::

        Only construct a ``tzfile`` directly if you have a specific timezone
        file on disk that you want to read into a Python ``tzinfo`` object.
        If you want to get a ``tzfile`` representing a specific IANA zone,
        (e.g. ``'America/New_York'``), you should call
        :func:`dateutil.tz.gettz` with the zone identifier.


    **Examples:**

    Using the US Eastern time zone as an example, we can see that a ``tzfile``
    provides time zone information for the standard Daylight Saving offsets:

    .. testsetup:: tzfile

        from dateutil.tz import gettz
        from datetime import datetime

    .. doctest:: tzfile

        >>> NYC = gettz('America/New_York')
        >>> NYC
        tzfile('/usr/share/zoneinfo/America/New_York')

        >>> print(datetime(2016, 1, 3, tzinfo=NYC))     # EST
        2016-01-03 00:00:00-05:00

        >>> print(datetime(2016, 7, 7, tzinfo=NYC))     # EDT
        2016-07-07 00:00:00-04:00


    The ``tzfile`` structure contains a fully history of the time zone,
    so historical dates will also have the right offsets. For example, before
    the adoption of the UTC standards, New York used local solar  mean time:

    .. doctest:: tzfile

       >>> print(datetime(1901, 4, 12, tzinfo=NYC))    # LMT
       1901-04-12 00:00:00-04:56

    And during World War II, New York was on "Eastern War Time", which was a
    state of permanent daylight saving time:

    .. doctest:: tzfile

        >>> print(datetime(1944, 2, 7, tzinfo=NYC))    # EWT
        1944-02-07 00:00:00-04:00

    Nc                    s   t t|   d}t|tr|| _t|d}d}n|d ur!|| _nt|dr+|j| _nt	|| _|d urX|s:t
|}|}| |}W d    n1 sLw   Y  | | d S d S )NFrbTrF   )rP   r   rH   r$   r   	_filenameopenhasattrrF   rM   _nullcontext_read_tzfile_set_tzdata)r   fileobjfilenamefile_opened_herefile_streamtzobjr\   r   r   rH     s&   




ztzfile.__init__c                 C   s&   t jD ]}t| d| t|| qdS )z= Set the time zone data of this object from a _tzfile object _N)r   r   rt   re   )r   r   ru   r   r   r   r     s   
ztzfile._set_tzdatac              	      s  t   |d dkrtd|d td|d\}}}}}}|r7ttd| ||d  _ng  _|rItd| || _ng  _g }t	|D ]}	|
td	|d
 qR|| }
|rs||d tj |rtd| ||}|rtd| ||}g  _t	|D ]J}	||	 \}}}t|}t }||_td|_tj|d|_||_|
||
d| |_||	ko||	 dk|_||	ko||	 dk|_ j
| q fdd jD  _d  _d  _d  _ jrY js jd   _ _nTt	|d ddD ])}	 j|	 } js |js | _n js+|jr+| _ jr5 jr5 nq jrC jsC j _ jD ]}|jsQ| _ nqF jd  _d }d }d }d }g  _t  jD ]U\}	}|j}d}|d ur|jr|s|| }|s|r|}tj|d|_|}|| }|}|d ur||kr|j|kr|}|j}|}|} j
 j|	 |  qit! j _t! j _t! j _ S )N   TZifzmagic not found   z>6l   z>%dlz>%dBz>lbb      z>%dbr   r=    c                    s   g | ]} j | qS r   )r   ).0idxoutr   r   
<listcomp>s  s    z'tzfile._read_tzfile.<locals>.<listcomp>r   )"r   readdecode
ValueErrorstructunpacklistr   r   rangerw   seekosSEEK_CURr   rE   rk   rG   rC   rD   rq   rl   rm   findrn   ro   rp   r   r   r   r   r   	enumeraterZ   )r   r   
ttisgmtcnt
ttisstdcntleapcnttimecnttypecntcharcntttinfoirn   ro   rp   gmtoffrm   abbrindttilastdst
lastoffsetlastdstoffsetlastbaseoffsetrG   rq   
baseoffset
adjustmentr   r   r   r     s   

	





	
ztzfile._read_tzfileFc                 C   s6   | j sd S t|}|r| jn| j }t||}|d S )Nr   )_trans_listr`   _trans_list_utcbisectbisect_right)r   r   in_utcrc   r   r   r   r   r   _find_last_transition  s   ztzfile._find_last_transitionc                 C   s8   |d u s|d t | jkr| jS |dk r| jS | j| S )Nr   r   )lenr   _ttinfo_std_ttinfo_before
_trans_idx)r   r   r   r   r   _get_ttinfo  s
   
ztzfile._get_ttinfoc                 C   s   |  |}| |S r   )_resolve_ambiguous_timer   )r   r   r   r   r   r   _find_ttinfo  s   

ztzfile._find_ttinfoc                 C   sn   t |tjs
td|j| urtd| j|dd}| |}|tj|jd }| j	||d}t
|t|dS )a  
        The ``tzfile`` implementation of :py:func:`datetime.tzinfo.fromutc`.

        :param dt:
            A :py:class:`datetime.datetime` object.

        :raises TypeError:
            Raised if ``dt`` is not a :py:class:`datetime.datetime` object.

        :raises ValueError:
            Raised if this is called with a ``dt`` which does not have this
            ``tzinfo`` attached.

        :return:
            Returns a :py:class:`datetime.datetime` object representing the
            wall time in ``self``'s time zone.
        z&fromutc() requires a datetime argumentzdt.tzinfo is not selfT)r   r=   )r   rd   )r$   rC   rA   tzinfor   r   r   rD   rG   r"   r	   rN   )r   r   r   r   dt_outrd   r   r   r   r#     s   

ztzfile.fromutcc                 C   sd   |du r	|  |}t|}| |}|du s|dkrdS | |d j|j }| j| }||| k S )r!   Nr   Fr   )r   r`   r   rG   r   )r   r   r   rc   r   odttr   r   r   r"     s   


ztzfile.is_ambiguousc                 C   sF   |  |}| |}|d u s|dkr|S t| o| ||}|| S )Nr   )r   rf   rN   r"   )r   r   r   rf   
idx_offsetr   r   r   r   (  s   

ztzfile._resolve_ambiguous_timec                 C   s"   |d u rd S | j stS | |jS r   )r   r   r   rl   r   r   r   r   r   5  s
   ztzfile.utcoffsetc                 C   s0   |d u rd S | j stS | |}|jstS |jS r   )_ttinfo_dstr   r   rm   rq   )r   r   r   r   r   r   r   >  s   
z
tzfile.dstc                 C   s   | j r|d u r	d S | |jS r   )r   r   rn   r   r   r   r   r    N  s   ztzfile.tznamec                 C   s2   t |tstS | j|jko| j|jko| j|jkS r   )r$   r   r&   r   r   _ttinfo_listr(   r   r   r   r*   T  s   


ztzfile.__eq__c                 C   r+   r   r   r(   r   r   r   r,   ]  r-   ztzfile.__ne__c                 C      d| j jt| jf S Nrv   )r1   r2   rM   r   r3   r   r   r   r4   `     ztzfile.__repr__c                 C   s
   |  d S r   )__reduce_ex__r3   r   r   r   r;   c  r-   ztzfile.__reduce__c                 C   s   | j d | jf| jfS r   )r1   r   __dict__)r   protocolr   r   r   r   f  s   ztzfile.__reduce_ex__r   F)r2   r6   r7   r8   rH   r   r   r   r   r   r#   r"   r   r   r   r   r    r*   r9   r,   r4   r;   r   rj   r   r   r\   r   r     s,    G 
a
$	
r   c                   @   s<   e Zd ZdZ			dddZdd Zdd Zed	d
 ZdS )tzrangea[  
    The ``tzrange`` object is a time zone specified by a set of offsets and
    abbreviations, equivalent to the way the ``TZ`` variable can be specified
    in POSIX-like systems, but using Python delta objects to specify DST
    start, end and offsets.

    :param stdabbr:
        The abbreviation for standard time (e.g. ``'EST'``).

    :param stdoffset:
        An integer or :class:`datetime.timedelta` object or equivalent
        specifying the base offset from UTC.

        If unspecified, +00:00 is used.

    :param dstabbr:
        The abbreviation for DST / "Summer" time (e.g. ``'EDT'``).

        If specified, with no other DST information, DST is assumed to occur
        and the default behavior or ``dstoffset``, ``start`` and ``end`` is
        used. If unspecified and no other DST information is specified, it
        is assumed that this zone has no DST.

        If this is unspecified and other DST information is *is* specified,
        DST occurs in the zone but the time zone abbreviation is left
        unchanged.

    :param dstoffset:
        A an integer or :class:`datetime.timedelta` object or equivalent
        specifying the UTC offset during DST. If unspecified and any other DST
        information is specified, it is assumed to be the STD offset +1 hour.

    :param start:
        A :class:`relativedelta.relativedelta` object or equivalent specifying
        the time and time of year that daylight savings time starts. To
        specify, for example, that DST starts at 2AM on the 2nd Sunday in
        March, pass:

            ``relativedelta(hours=2, month=3, day=1, weekday=SU(+2))``

        If unspecified and any other DST information is specified, the default
        value is 2 AM on the first Sunday in April.

    :param end:
        A :class:`relativedelta.relativedelta` object or equivalent
        representing the time and time of year that daylight savings time
        ends, with the same specification method as in ``start``. One note is
        that this should point to the first time in the *standard* zone, so if
        a transition occurs at 2AM in the DST zone and the clocks are set back
        1 hour to 1AM, set the ``hours`` parameter to +1.


    **Examples:**

    .. testsetup:: tzrange

        from dateutil.tz import tzrange, tzstr

    .. doctest:: tzrange

        >>> tzstr('EST5EDT') == tzrange("EST", -18000, "EDT")
        True

        >>> from dateutil.relativedelta import *
        >>> range1 = tzrange("EST", -18000, "EDT")
        >>> range2 = tzrange("EST", -18000, "EDT", -14400,
        ...                  relativedelta(hours=+2, month=4, day=1,
        ...                                weekday=SU(+1)),
        ...                  relativedelta(hours=+1, month=10, day=31,
        ...                                weekday=SU(-1)))
        >>> tzstr('EST5EDT') == range1 == range2
        True

    Nc              	   C   s8  ddl ma || _|| _z| }W n ttfy   Y nw z| }W n ttfy/   Y nw |d ur<tj|d| _	nt
| _	|d urKtj|d| _n|r\|d ur\| j	tjdd | _nt
| _|rs|d u rstjdddtdd| _n|| _|r|d u rtjdd	d
tdd| _n|| _| j| j	 | _t| j| _d S )Nr   relativedeltar=   r   hours   r   )r   monthdayweekday
      r   )dateutilr   	_std_abbr	_dst_abbrr@   rA   rB   rC   rD   rS   r   rV   SU_start_delta
_end_delta_dst_base_offset_rX   hasdst)r   stdabbr	stdoffsetdstabbrrq   startendr   r   r   rH     sB   

ztzrange.__init__c                 C   s4   | j sdS t|dd}|| j }|| j }||fS )a  
        For a given year, get the DST on and off transition times, expressed
        always on the standard time side. For zones with no transitions, this
        function returns ``None``.

        :param year:
            The year whose transitions you would like to query.

        :return:
            Returns a :class:`tuple` of :class:`datetime.datetime` objects,
            ``(dston, dstoff)`` for zones with an annual DST transition, or
            ``None`` for fixed offset zones.
        Nr   )r   rC   r   r   )r   year	base_yearr   r   r   r   r   transitions  s   

ztzrange.transitionsc                 C   sV   t |tstS | j|jko*| j|jko*| j|jko*| j|jko*| j|jko*| j|jkS r   )	r$   r   r&   r   r   rS   rV   r   r   r(   r   r   r   r*     s   





ztzrange.__eq__c                 C   rI   r   )r   r3   r   r   r   _dst_base_offset  rL   ztzrange._dst_base_offset)NNNNN)	r2   r6   r7   r8   rH   r   r*   propertyr   r   r   r   r   r   j  s    J
/r   c                   @   s,   e Zd ZdZdddZdddZdd	 Zd
S )tzstra  
    ``tzstr`` objects are time zone objects specified by a time-zone string as
    it would be passed to a ``TZ`` variable on POSIX-style systems (see
    the `GNU C Library: TZ Variable`_ for more details).

    There is one notable exception, which is that POSIX-style time zones use an
    inverted offset format, so normally ``GMT+3`` would be parsed as an offset
    3 hours *behind* GMT. The ``tzstr`` time zone object will parse this as an
    offset 3 hours *ahead* of GMT. If you would like to maintain the POSIX
    behavior, pass a ``True`` value to ``posix_offset``.

    The :class:`tzrange` object provides the same functionality, but is
    specified using :class:`relativedelta.relativedelta` objects. rather than
    strings.

    :param s:
        A time zone string in ``TZ`` variable format. This can be a
        :class:`bytes` (2.x: :class:`str`), :class:`str` (2.x:
        :class:`unicode`) or a stream emitting unicode characters
        (e.g. :class:`StringIO`).

    :param posix_offset:
        Optional. If set to ``True``, interpret strings such as ``GMT+3`` or
        ``UTC+3`` as being 3 hours *behind* UTC rather than ahead, per the
        POSIX standard.

    .. caution::

        Prior to version 2.7.0, this function also supported time zones
        in the format:

            * ``EST5EDT,4,0,6,7200,10,0,26,7200,3600``
            * ``EST5EDT,4,1,0,7200,10,-1,0,7200,3600``

        This format is non-standard and has been deprecated; this function
        will raise a :class:`DeprecatedTZFormatWarning` until
        support is removed in a future version.

    .. _`GNU C Library: TZ Variable`:
        https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
    Fc              	   C   s   ddl ma || _t|}|d u s|jrtd|jdv r'|s'| jd9  _t	j
| |j|j|j|jddd |jsAd | _d | _n| |j| _| jrT| j|jdd	| _t| j| _d S )
Nr   )_parserzunknown string formatri   r   r   F)r   r   r   )isend)dateutil.parserr   parser_s_parsetzany_unused_tokensr   r   r   r   rH   r   rq   r   r   _deltar   r   rX   r   )r   sposix_offsetresr   r   r   rH   7  s$   
ztzstr.__init__r   c                 C   s<  ddl m} i }|jd ur9|j|d< |jd ur0||j|j|d< |jdkr+d|d< n#d|d< n|jr8|j|d< n|jd urD|j|d< n
|jd urN|j|d	< |sq|sbd
|d< d|d< |d|d< nd|d< d|d< |d|d< |j	d ur||j	|d< nd|d< |r| j
| j }|d  |j|jd  8  < |jdi |S )Nr   r   r   r   r   r   r   yearday	nlyeardayr   r   r   r>   i   iQ r   )r   r   r   r   weekr   ydayjydayr   rQ   rV   rS   r>   days)r   xr   r   r   rl   r   r   r   r  W  s>   










ztzstr._deltac                 C   r   r   r1   r2   rM   r  r3   r   r   r   r4     r   ztzstr.__repr__Nr   )r   )r2   r6   r7   r8   rH   r  r4   r   r   r   r   r     s
    
)
 )r   c                   @   s   e Zd Z	dddZdS )_tzicalvtzcompNc                 C   s@   t j|d| _t j|d| _| j| j | _|| _|| _|| _d S r<   )rC   rD   tzoffsetfrom
tzoffsettotzoffsetdiffrm   r    rrule)r   r  r  rm   r    r  r   r   r   rH     s   
z_tzicalvtzcomp.__init__)NN)r2   r6   r7   rH   r   r   r   r   r    s    r  c                       sZ   e Zd Zg f fdd	Zdd Zdd Zdd Zd	d
 Zedd Z	dd Z
ejZ  ZS )
_tzicalvtzc                    s4   t t|   || _|| _g | _g | _t | _	d S r   )
rP   r  rH   _tzid_comps
_cachedate
_cachecompr   allocate_lock_cache_lock)r   tzidcompsr\   r   r   rH     s   z_tzicalvtz.__init__c                 C   sb  t | jdkr| jd S |jd d}z$| j | j| j|| |f W  d    W S 1 s0w   Y  W n	 ty?   Y nw d }d }| jD ]}| 	||}|r[|rW||k r[|}|}qG|so| jD ]	}|j
sj|} nqa|d }| j5 | jd|| |f | jd| t | jdkr| j  | j  W d    |S W d    |S 1 sw   Y  |S )Nr   r   r   r   )r   r  replacer  r  r  indexrf   r   _find_compdtrm   insertpop)r   r   
lastcompdtlastcompcompcompdtr   r   r   
_find_comp  sP   

&




z_tzicalvtz._find_compc                 C   s2   |j tk r| |r||j 8 }|jj|dd}|S )NT)inc)r  r   rf   r  before)r   r'  r   r(  r   r   r   r"    s   
z_tzicalvtz._find_compdtc                 C   s   |d u rd S |  |jS r   )r)  r  r   r   r   r   r     s   z_tzicalvtz.utcoffsetc                 C   s   |  |}|jr|jS tS r   )r)  rm   r  r   )r   r   r'  r   r   r   r     s   
z_tzicalvtz.dstc                 C   s   |  |jS r   )r)  r    r   r   r   r   r      s   z_tzicalvtz.tznamec                 C   s   dt | j S )Nz<tzicalvtz %s>)rM   r  r3   r   r   r   r4     s   z_tzicalvtz.__repr__)r2   r6   r7   rH   r)  r"  r   r   r   r    r4   r:   r;   rj   r   r   r\   r   r    s    	-
r  c                   @   sB   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dS )tzicala[  
    This object is designed to parse an iCalendar-style ``VTIMEZONE`` structure
    as set out in `RFC 5545`_ Section 4.6.5 into one or more `tzinfo` objects.

    :param `fileobj`:
        A file or stream in iCalendar format, which should be UTF-8 encoded
        with CRLF endings.

    .. _`RFC 5545`: https://tools.ietf.org/html/rfc5545
    c                 C   s   ddl ma t|tr|| _t|d}nt|dt|| _t|}i | _	|}| 
|  W d    d S 1 s9w   Y  d S )Nr   )r  rrF   )r   r  r$   r   r  r   re   rM   r   _vtz
_parse_rfcr   )r   r   fobjr   r   r   rH     s   
"ztzical.__init__c                 C   s   t | j S )z?
        Retrieves the available time zones as a list.
        )r   r.  keysr3   r   r   r   r1    s   ztzical.keysNc                 C   sN   |du r!t | jdkrtdt | jdkrtdtt| j}| j|S )a  
        Retrieve a :py:class:`datetime.tzinfo` object by its ``tzid``.

        :param tzid:
            If there is exactly one time zone available, omitting ``tzid``
            or passing :py:const:`None` value returns it. Otherwise a valid
            key (which can be retrieved from :func:`keys`) is required.

        :raises ValueError:
            Raised if ``tzid`` is not specified but there are either more
            or fewer than 1 zone defined.

        :returns:
            Returns either a :py:class:`datetime.tzinfo` object representing
            the relevant time zone or :py:const:`None` if the ``tzid`` was
            not found.
        Nr   zno timezones definedr   z more than one timezone available)r   r.  r   nextiterr   )r   r  r   r   r   r     s   z
tzical.getc                 C   s   |  }|s
td|d dv rd|d dk }|dd  }nd}t|dkr=t|d d d	 t|dd  d
  | S t|dkrat|d d d	 t|dd d
  t|dd   | S td| )Nzempty offsetr   )+-)r   r   r4  r   r   r   i  <   r   zinvalid offset: )stripr   r   rN   )r   r  signalr   r   r   _parse_offset"  s   ,<ztzical._parse_offsetc                 C   sP  |  }|s
tdd}|t|k rD||  }|s||= n |dkr:|d dkr:||d   |dd  7  < ||= n|d7 }|t|k sd }g }d}d }|D ]V}|sTqN|dd\}	}
|	d}|sgtd|d  }	|dd  }|r|	d	kr|
d
v rntd|
 |
}d}d }d }g }d }qN|	dkr|
dkr|rtd| |std|stdt||| j|< d}qN|
|kr|std|d u rtd|d u rtdd }|rtj	d
|dddd}t|||dk||}|| d }qNtd|
 |rv|	dkr|D ]}|dkrd| }t|q|| d}qN|	dv r)|| qN|	dkrA|r;td|	|d f | |
}qN|	dkrW|rQtd|d  | |
}qN|	d krj|rgtd!|d  |
}qN|	d"krpqNtd#|	 |	d$kr|rtd%|d  |
}qN|	d&v rqNtd#|	 |	d	kr|
dkrd }g }d}qNd S )'Nzempty stringr    r   F:;zempty property nameBEGIN)STANDARDDAYLIGHTzunknown component: END	VTIMEZONEzcomponent not closed: zmandatory TZID not foundz at least one component is neededzmandatory DTSTART not foundz mandatory TZOFFSETFROM not found
T)
compatibleignoretzcacher?  zinvalid component end: DTSTARTzVALUE=DATE-TIMEz(Unsupported DTSTART param in VTIMEZONE: )RRULERDATEEXRULEEXDATETZOFFSETFROMzunsupported %s parm: %s 
TZOFFSETTOzunsupported TZOFFSETTO parm: TZNAMEzunsupported TZNAME parm: COMMENTzunsupported property: TZIDzunsupported TZID parm: )TZURLzLAST-MODIFIEDrN  )
splitlinesr   r   rstripsplitupperr  r.  r  rrulestrrx   r  rw   r9  )r   r  linesr   liner  r  invtzcomptyperF   rz   parmsfounddtstartr  r  
rrulelinesr    rrr'  parmmsgr   r   r   r/  2  s   
















ztzical._parse_rfcc                 C   r   r   r  r3   r   r   r   r4     r   ztzical.__repr__r   )
r2   r6   r7   r8   rH   r1  r   r9  r/  r4   r   r   r   r   r,    s    

}r,  win32z/etc/localtimera   )z/usr/share/zoneinfoz/usr/lib/zoneinfoz/usr/share/lib/zoneinfoz/etc/zoneinfoc                     s2   t f td ur tf7  G  fdddt} |  S )Nc                       sD   e Zd ZdZdd Zd fdd	Zdd Zd	d
 ZedddZ	dS )z__get_gettz.<locals>.GettzFunca	  
        Retrieve a time zone object from a string representation

        This function is intended to retrieve the :py:class:`tzinfo` subclass
        that best represents the time zone that would be used if a POSIX
        `TZ variable`_ were set to the same value.

        If no argument or an empty string is passed to ``gettz``, local time
        is returned:

        .. code-block:: python3

            >>> gettz()
            tzfile('/etc/localtime')

        This function is also the preferred way to map IANA tz database keys
        to :class:`tzfile` objects:

        .. code-block:: python3

            >>> gettz('Pacific/Kiritimati')
            tzfile('/usr/share/zoneinfo/Pacific/Kiritimati')

        On Windows, the standard is extended to include the Windows-specific
        zone names provided by the operating system:

        .. code-block:: python3

            >>> gettz('Egypt Standard Time')
            tzwin('Egypt Standard Time')

        Passing a GNU ``TZ`` style string time zone specification returns a
        :class:`tzstr` object:

        .. code-block:: python3

            >>> gettz('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3')
            tzstr('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3')

        :param name:
            A time zone name (IANA, or, on Windows, Windows keys), location of
            a ``tzfile(5)`` zoneinfo file or ``TZ`` variable style time zone
            specifier. An empty string, no argument or ``None`` is interpreted
            as local time.

        :return:
            Returns an instance of one of ``dateutil``'s :py:class:`tzinfo`
            subclasses.

        .. versionchanged:: 2.7.0

            After version 2.7.0, any two calls to ``gettz`` using the same
            input strings will return the same object:

            .. code-block:: python3

                >>> tz.gettz('America/Chicago') is tz.gettz('America/Chicago')
                True

            In addition to improving performance, this ensures that
            `"same zone" semantics`_ are used for datetimes in the same zone.


        .. _`TZ variable`:
            https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

        .. _`"same zone" semantics`:
            https://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html
        c                 S   s&   t  | _d| _t | _t | _d S )Nr   )	weakrefWeakValueDictionary_GettzFunc__instances_GettzFunc__strong_cache_sizer   _GettzFunc__strong_cacher   r  r  r3   r   r   r   rH   	  s   
z'__get_gettz.<locals>.GettzFunc.__init__Nc                    s   | j W | j|d }|d u r1| j|d}|d u s(t| s(|d u s(|| j|< n	|W  d    S | j||| j|< t| j| jkrR| jj	dd W d    |S W d    |S 1 s]w   Y  |S )N)rF   Flast)
r  rc  r   nocacher$   re  r$  r   rd  popitem)r   rF   rvtzlocal_classesr   r   __call__  s*   

z'__get_gettz.<locals>.GettzFunc.__call__c                 S   sl   | j ) || _t| j|kr$| jjdd t| j|ksW d    d S W d    d S 1 s/w   Y  d S )NFrf  )r  rd  r   re  ri  )r   sizer   r   r   set_cache_size+  s   "z-__get_gettz.<locals>.GettzFunc.set_cache_sizec                 S   s@   | j  t | _| j  W d    d S 1 sw   Y  d S r   )r  ra  rb  rc  re  clearr3   r   r   r   cache_clear1  s   
"z*__get_gettz.<locals>.GettzFunc.cache_clearc           	      S   sr  d}| szt jd } W n	 ty   Y nw | du s| dv r_tD ]:}t j|s>|}tD ]}t j||}t j|r< nq+qt j|rYzt	|}W  |S  t
ttfyX   Y qw qt }|S z| drk| dd } W n# ty } zt| trd}tt|| n W Y d}~nd}~ww t j| rt j| rt	| }|S d}|S tD ]0}t j|| }t j|s|dd}t j|sqzt	|}W  |S  t
ttfy   Y qw d}tdurzt| }W n ttfy   d}Y nw |sd	d
lm} | | }|s7| D ]}|dv r#zt| }W  |S  ty"   Y  |S w q| dv r.t}|S | tjv r7t }|S )zA non-cached version of gettzNTZ) r;  r;  r   z'gettz argument should be str, not bytesr:  r   r   )get_zonefile_instance
0123456789r   )r   environKeyErrorTZFILESpathisabsTZPATHSrx   isfiler   IOErrorOSErrorr   rO   
startswithrA   r$   bytessix
raise_fromr   r   WindowsErrorUnicodeEncodeErrordateutil.zoneinfort  r   r   r   rQ   r    )	rF   tzfilepathr   ry  enew_msgrt  cr   r   r   rh  6  s   >:

-+!


z&__get_gettz.<locals>.GettzFunc.nocacher   )
r2   r6   r7   r8   rH   rm  ro  rq  staticmethodrh  r   rk  r   r   	GettzFunc  s    Er  )rO   r   r:   )r  r   rk  r   __get_gettz  s   
 Jr  c                 C   sX   |du r| j du rtd| j }| jdd} | j|dt|}|jdd}| |kS )a  
    Given a datetime and a time zone, determine whether or not a given datetime
    would fall in a gap.

    :param dt:
        A :class:`datetime.datetime` (whose time zone will be ignored if ``tz``
        is provided.)

    :param tz:
        A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If
        ``None`` or not provided, the datetime's own time zone will be used.

    :return:
        Returns a boolean value whether or not the "wall time" exists in
        ``tz``.

    .. versionadded:: 2.7.0
    N,Datetime is naive and no time zone provided.r  )r   r   r   
astimezoner   )r   r  dt_rtr   r   r   datetime_exists  s   
r  c                 C   s   |du r| j du rtd| j }t|dd}|dur*z|| W S  ty)   Y nw | j|d} t| dd}t| dd}| | k}| | k}|oO| S )a\  
    Given a datetime and a time zone, determine whether or not a given datetime
    is ambiguous (i.e if there are two times differentiated only by their DST
    status).

    :param dt:
        A :class:`datetime.datetime` (whose time zone will be ignored if ``tz``
        is provided.)

    :param tz:
        A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If
        ``None`` or not provided, the datetime's own time zone will be used.

    :return:
        Returns a boolean value whether or not the "wall time" is ambiguous in
        ``tz``.

    .. versionadded:: 2.6.0
    Nr  r"   r  r   r   r   )	r   r   re   r"   	Exceptionr   r	   r   r   )r   r  is_ambiguous_fnwall_0wall_1same_offsetsame_dstr   r   r   datetime_ambiguous  s"   

r  c                 C   sJ   | j dur#t| s#| tjdd  }| tjdd  }| || 7 } | S )aZ  
    Given a datetime that may be imaginary, return an existing datetime.

    This function assumes that an imaginary datetime represents what the
    wall time would be in a zone had the offset transition not occurred, so
    it will always fall forward by the transition's change in offset.

    .. doctest::

        >>> from dateutil import tz
        >>> from datetime import datetime
        >>> NYC = tz.gettz('America/New_York')
        >>> print(tz.resolve_imaginary(datetime(2017, 3, 12, 2, 30, tzinfo=NYC)))
        2017-03-12 03:30:00-04:00

        >>> KIR = tz.gettz('Pacific/Kiritimati')
        >>> print(tz.resolve_imaginary(datetime(1995, 1, 1, 12, 30, tzinfo=KIR)))
        1995-01-02 12:30:00+14:00

    As a note, :func:`datetime.astimezone` is guaranteed to produce a valid,
    existing datetime, so a round-trip to and from UTC is sufficient to get
    an extant datetime, however, this generally "falls back" to an earlier time
    rather than falling forward to the STD side (though no guarantees are made
    about this behavior).

    :param dt:
        A :class:`datetime.datetime` which may or may not exist.

    :return:
        Returns an existing :class:`datetime.datetime`. If ``dt`` was not
        imaginary, the datetime returned is guaranteed to be the same object
        passed to the function.

    .. versionadded:: 2.7.0
    Nr   r   )r   r  rC   rD   r   )r   curr_offset
old_offsetr   r   r   resolve_imaginary  s
   $r  c                 C   s   | j ddt  S )z
    Convert a :class:`datetime.datetime` object to an epoch timestamp in
    seconds since January 1, 1970, ignoring the time zone.
    Nr  )r   EPOCHr@   )r   r   r   r   r`     s   r`   )   r   c                 C   s   | S r   r   )second_offsetr   r   r   rE     r   rE   c                 C   s   | }d| d d  }|S )Nr6     r   )r  r  calculated_offsetr   r   r   rE     s   )nullcontextc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r   zj
        Class for wrapping contexts so that they are passed through in a
        with statement.
        c                 C   s
   || _ d S r   context)r   r  r   r   r   rH   0  r-   z_nullcontext.__init__c                 C   rI   r   r  r3   r   r   r   	__enter__3  rK   z_nullcontext.__enter__c                  O   s   d S r   r   )argsr   r   r   r   __exit__6  r   z_nullcontext.__exit__N)r2   r6   r7   r8   rH   r  r  r   r   r   r   r   +  s
    r   r   )@r8   rC   r   rQ   sysr   r   ra  collectionsr   r  r   	six.movesr   _commonr   r   r   r	   r
   
_factoriesr   r   r   winr   r   ImportErrorwarningsr   rD   r   r  	toordinalEPOCHORDINALadd_metaclassr   r   r   r%   rO   r:   rk   r   r   r   r   r  r  r,  platformrx  r{  r  gettzr  r  r  r`   version_inforE   
contextlibr  r   r   r   r   r   <module>   s   
WD-   k #wV O
 R

"..

