a &i2@sddlmZddlmZddlmZmZmZedZddgZddZ e edrZdd dZ nGd d d eZ dd dZ d dZ GdddeZGdddeZdS))PY2wraps)datetime timedeltatzinfotzname_in_python2enfoldcs$trtfdd}|SSdS)zChange unicode output into bytestrings in Python 2 tzname() API changed in Python 3. It used to return bytes, but was changed to unicode strings cs"|i|}|dur|}|SN)encode)argskwargsnamenamefunc7/usr/lib/python3.9/site-packages/dateutil/tz/_common.pyadjust_encodingsz*tzname_in_python2..adjust_encodingN)rr)rrrrrr s foldcCs |j|dS) Provides a unified interface for assigning the ``fold`` attribute to datetimes both before and after the implementation of PEP-495. :param fold: The value for the ``fold`` attribute in the returned datetime. This should be either 0 or 1. :return: Returns an object for which ``getattr(dt, 'fold', 0)`` returns ``fold`` for all versions of Python. In versions prior to Python 3.6, this is a ``_DatetimeWithFold`` object, which is a subclass of :py:class:`datetime.datetime` with the ``fold`` attribute added, if ``fold`` is 1. .. versionadded:: 2.6.0 rreplace)dtrrrrr %sc@s(eZdZdZdZddZeddZdS)_DatetimeWithFoldz This is a class designed to provide a PEP 495-compliant interface for Python versions before 3.6. It is used only for dates in a fold, so the ``fold`` attribute is fixed at ``1``. .. versionadded:: 2.6.0 rcOszd}t||D]&\}}||vr,td||||<q|D]}||vr:t||||<q:|ddrh|jnt}|fi|S)a Return a datetime with the same attributes, except for those attributes given new values by whichever keyword arguments are specified. Note that tzinfo=None can be specified to create a naive datetime from an aware datetime with no conversion of date and time data. This is reimplemented in ``_DatetimeWithFold`` because pypy3 will return a ``datetime.datetime`` even if ``fold`` is unchanged. )yearZmonthZdayZhourZminutesecond microsecondrzDuplicate argument: {}rr)zip TypeErrorformatgetattrget __class__r)selfr r ZargnamesargargnameZdt_classrrrrDs  z_DatetimeWithFold.replacecCsdS)Nrrr%rrrrbsz_DatetimeWithFold.foldN)__name__ __module__ __qualname____doc__ __slots__rpropertyrrrrrr:s rcCsLt|dd|kr|S|dd}||j|jf7}|r@t|St|SdS)rrrN)r"Z timetuplerrrr)rrr rrrr fscstfdd}|S)z The CPython version of ``fromutc`` checks that the input is a ``datetime`` object and that ``self`` is attached as its ``tzinfo``. cs.t|tstd|j|ur$td||S)N&fromutc() requires a datetime argumentdt.tzinfo is not self) isinstancerr r ValueErrorr%rfrrfromutcs   z)_validate_fromutc_inputs..fromutcr)r6r7rr5r_validate_fromutc_inputssr8c@s<eZdZdZddZddZddZdd Zed d Z d S) _tzinfoz= Base class for all ``dateutil`` ``tzinfo`` objects. cCsV|j|d}t|dd}t|dd}||k}|jdd|jddk}|oT| S)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 rrrrN)rr utcoffset)r%rZwall_0Zwall_1Z same_offsetZsame_dtrrr is_ambiguouss    z_tzinfo.is_ambiguouscCs4||r,||}t|||k}nd}|S)a Determine the fold status of a "wall" datetime, given a representation of the same datetime as a (naive) UTC datetime. This is calculated based on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all datetimes, and that this offset is the actual number of hours separating ``dt_utc`` and ``dt_wall``. :param dt_utc: Representation of the datetime as UTC :param dt_wall: Representation of the datetime as "wall time". This parameter must either have a `fold` attribute or have a fold-naive :class:`datetime.tzinfo` attached, otherwise the calculation may fail. r)r=intr<dst)r%dt_utcdt_wallZ delta_wall_foldrrr _fold_statuss  z_tzinfo._fold_statuscCs t|ddS)Nrr)r"r4rrrrBsz _tzinfo._foldcCsh|}|durtd|}|dur0td||}||7}t|dd}|dur`td||S) Given a timezone-aware datetime in a given timezone, calculates a timezone-aware datetime in a new timezone. Since this is the one time that we *know* we have an unambiguous datetime object, we take this opportunity to determine whether the datetime is ambiguous and in a "fold" state (e.g. if it's the first occurrence, chronologically, of the ambiguous datetime). :param dt: A timezone-aware :class:`datetime.datetime` object. Nz0fromutc() requires a non-None utcoffset() resultz*fromutc() requires a non-None dst() resultrrz;fromutc(): dt.dst gave inconsistent results; cannot convert)r<r3r?r )r%rZdtoffZdtdstZdeltarrr_fromutcsz_tzinfo._fromutccCs"||}|||}t||dS)rDr)rErCr )r%rrArBrrrr7s  z_tzinfo.fromutcN) r)r*r+r,r=rCrBrEr8r7rrrrr9s%r9c@szeZdZdZddZddZddZedd Zd d Z d d Z ddZ ddZ e ddZdZddZddZejZdS) tzrangebasea This is an abstract base class for time zones represented by an annual transition into and out of DST. Child classes should implement the following methods: * ``__init__(self, *args, **kwargs)`` * ``transitions(self, year)`` - this is expected to return a tuple of datetimes representing the DST on and off transitions in standard time. A fully initialized ``tzrangebase`` subclass should also provide the following attributes: * ``hasdst``: Boolean whether or not the zone uses DST. * ``_dst_offset`` / ``_std_offset``: :class:`datetime.timedelta` objects representing the respective UTC offsets. * ``_dst_abbr`` / ``_std_abbr``: Strings representing the timezone short abbreviations in DST and STD, respectively. * ``_hasdst``: Whether or not the zone has DST. .. versionadded:: 2.6.0 cCs tddS)Nz%tzrangebase is an abstract base class)NotImplementedErrorr(rrr__init__!sztzrangebase.__init__cCs*||}|durdS|r |jS|jSdSr )_isdst _dst_offset _std_offsetr%risdstrrrr<$s  ztzrangebase.utcoffsetcCs(||}|durdS|r |jStSdSr )rI_dst_base_offsetZEROrLrrrr?.s  ztzrangebase.dstcCs||r|jS|jSdSr )rIZ _dst_abbrZ _std_abbrr4rrrtzname8s ztzrangebase.tznamec Cst|tstd|j|ur$td||j}|durF|||S|\}}||j8}||j8}||f}|j dd}| ||}|r||j }n ||j}t | o| |} t|| dS)z, Given a datetime in UTC, return local time r0r1Nr;r)r2rr rr3 transitionsrr<rKr _naive_isdstrJr>r=r ) r%rrQdstondstoffZutc_transitionsr@rMrArBrrrr7?s$         ztzrangebase.fromutccCsD|js dS||j\}}|jdd}||ko>||jkSS)r:FNr;)hasdstrQrrrN)r%rstartendrrrr=`s  ztzrangebase.is_ambiguouscCsh|js dS|durdS||j}|dur.dS|jdd}|||}|s`||r`|| S|SdS)NFr;)rUrQrrrRr=rB)r%rrQrMrrrrIvs    ztzrangebase._isdstcCsT|\}}|jdd}||kr6||ko.|kn}n||koH|kn }|S)Nr;r)r%rrQrSrTrMrrrrRs  ztzrangebase._naive_isdstcCs |j|jSr )rJrKr(rrrrNsztzrangebase._dst_base_offsetNcCs ||k Sr r)r%otherrrr__ne__sztzrangebase.__ne__cCs d|jjS)Nz%s(...))r$r)r(rrr__repr__sztzrangebase.__repr__)r)r*r+r,rHr<r?rrPr7r=rIrRr.rN__hash__rYrZobject __reduce__rrrrrF s    !  rFN)r)r)Zsixr functoolsrrrrrO__all__rhasattrr rr8r9rFrrrrs    , v