3 6ÈcYÖ.ã@s´ddlmZddlmZddlmZmZmZedƒZddgZdd„Z e edƒrZdd d„Z nGd d „d eƒZ dd d„Z d d„Z Gdd„deƒZGdd„deƒZdd„ZeedeƒZdS)é)ÚPY3)Úwraps)ÚdatetimeÚ timedeltaÚtzinfoÚtzname_in_python2Úenfoldcs‡fdd„}|S)zžChange unicode output into bytestrings in Python 2 tzname() API changed in Python 3. It used to return bytes, but was changed to unicode strings cs$ˆ||Ž}|dk r t r |jƒ}|S)N)rÚencode)ÚargsÚkwargsÚname)Únamefunc©ú/usr/lib/python3.6/_common.pyÚadjust_encodings z*tzname_in_python2..adjust_encodingr)r rr)r rr s ÚfoldécCs |j|d�S)a® 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 )r)Úreplace)Údtrrrrr!sc@s eZdZdZfZedd„ƒZdS)Ú_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 cCsdS)Nrr)Úselfrrrr@sz_DatetimeWithFold.foldN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__Úpropertyrrrrrr6srcCsLt|ddƒ|kr|S|jƒdd…}||j|jf7}|r@t|ŽSt|ŽSdS)a® 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 rrNé)ÚgetattrZ timetupleZ microsecondrrr)rrr rrrrDscstˆƒ‡fdd„ƒ}|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|tƒstdƒ‚|j|k r$tdƒ‚ˆ||ƒS)Nz&fromutc() requires a datetime argumentzdt.tzinfo is not self)Ú isinstancerÚ TypeErrorrÚ ValueError)rr)ÚfrrÚfromutcgs   z)_validate_fromutc_inputs..fromutc)r)r"r#r)r"rÚ_validate_fromutc_inputsbs r$c@s<eZdZdZdd„Zdd„Zdd„Zdd „Zed d „ƒZ d S) Ú_tzinfoz= Base class for all ``dateutil`` ``tzinfo`` objects. cCsV|j|d�}t|dd�}t|dd�}|jƒ|jƒk}|jdd�|jdd�k}|oT| S)a6 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 )rr)rrN)rrÚ utcoffset)rrZwall_0Zwall_1Z same_offsetZsame_dtrrrÚ is_ambiguousxs    z_tzinfo.is_ambiguouscCs4|j|ƒr,||}t||jƒ|jƒ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_utcÚdt_wallZ delta_wallÚ_foldrrrÚ _fold_status‘s  z_tzinfo._fold_statuscCs t|ddƒS)Nrr)r)rrrrrr,ªsz _tzinfo._foldcCsh|jƒ}|dkrtdƒ‚|jƒ}|dkr0tdƒ‚||}||7}t|dd�jƒ}|dkr`tdƒ‚||S)aû 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 occurence, 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() resultr)rz;fromutc(): dt.dst gave inconsistent results; cannot convert)r&r!r)r)rrZdtoffZdtdstZdeltarrrÚ_fromutc­sz_tzinfo._fromutccCs"|j|ƒ}|j||ƒ}t||d�S)aû 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 occurance, chronologically, of the ambiguous datetime). :param dt: A timezone-aware :class:`datetime.datetime` object. )r)r.r-r)rrr+r,rrrr#Òs  z_tzinfo.fromutcN) rrrrr'r-r,r.r$r#rrrrr%ss %r%c@szeZdZdZdd„Zdd„Zdd„Zedd „ƒZd d „Z d d „Z dd„Z dd„Z e dd„ƒZdZdd„Zdd„ZejZdS)Ú 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 tdƒ‚dS)Nz%tzrangebase is an abstract base class)ÚNotImplementedError)rrrrÚ__init__ÿsztzrangebase.__init__cCs*|j|ƒ}|dkrdS|r |jS|jSdS)N)Ú_isdstÚ _dst_offsetÚ _std_offset)rrÚisdstrrrr&s  ztzrangebase.utcoffsetcCs(|j|ƒ}|dkrdS|r |jStSdS)N)r2Ú_dst_base_offsetÚZERO)rrr5rrrr) s  ztzrangebase.dstcCs|j|ƒr|jS|jSdS)N)r2Z _dst_abbrZ _std_abbr)rrrrrÚtznames ztzrangebase.tznamec Cs¼t|tƒstdƒ‚|j|k r$tdƒ‚|j|jƒ}|dkrF||j|ƒS|\}}||j8}||j8}||f}|j dd�}|j ||ƒ}|r’||j }n ||j}t | o¬|j |ƒƒ} t|| d�S)z, Given a datetime in UTC, return local time z&fromutc() requires a datetime argumentzdt.tzinfo is not selfN)r)r)rrr rr!Ú transitionsÚyearr&r4rÚ _naive_isdstr3r(r'r) rrr9ÚdstonÚdstoffZutc_transitionsr*r5r+r,rrrr#s$         ztzrangebase.fromutccCsD|js dS|j|jƒ\}}|jdd�}||ko>||jkSS)a6 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 FN)r)Úhasdstr9r:rr6)rrÚstartÚendrrrr'>s  ztzrangebase.is_ambiguouscCsj|js dS|dkrdS|j|jƒ}|dkr.dS|jdd�}|j||ƒ}| rb|j|ƒrb|j|ƒ S|SdS)NF)r)r>r9r:rr;r'r,)rrr9r5rrrr2Ts    ztzrangebase._isdstcCsT|\}}|jdd�}||kr6||ko.|kn}n||koH|kn }|S)N)r)r)rrr9r<r=r5rrrr;is  ztzrangebase._naive_isdstcCs |j|jS)N)r3r4)rrrrr6usztzrangebase._dst_base_offsetNcCs ||k S)Nr)rÚotherrrrÚ__ne__{sztzrangebase.__ne__cCs d|jjS)Nz%s(...))Ú __class__r)rrrrÚ__repr__~sztzrangebase.__repr__)rrrrr1r&r)rr8r#r'r2r;rr6Ú__hash__rBrDÚobjectÚ __reduce__rrrrr/és  ! r/cCs|j|jdd|jdS)Ni€Qi@B)ZsecondsZdaysZ microseconds)ZtdrrrÚ_total_seconds„srHZ total_secondsN)r)r)ZsixrÚ functoolsrrrrr7Ú__all__rÚhasattrrrr$r%r/rHrrrrrÚs     v