HOME


sh-3ll 1.0
DIR:/usr/local/lib/python3.6/site-packages/dateutil/tz/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/dateutil/tz/__pycache__/_common.cpython-36.pyc
3

���h�2�@s�ddlmZddlmZddlmZmZmZed�ZddgZdd�Z	e
ed�rZdd	d�ZnGd
d�de�Zddd�Zd
d�Z
Gdd�de�ZGdd�de�ZdS)�)�PY2)�wraps)�datetime�	timedelta�tzinfo�tzname_in_python2�enfoldcs$trt���fdd��}|S�SdS)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|j�}|S)N)�encode)�args�kwargs�name)�namefunc��>/tmp/pip-build-5_djhm0z/python-dateutil/dateutil/tz/_common.py�adjust_encodings
z*tzname_in_python2.<locals>.adjust_encodingN)rr)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(eZdZdZfZdd�Zedd��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
        cOs~d}x4t||�D]&\}}||kr.td	j|���|||<qWx"|D]}||kr@t||�||<q@W|jd
d�rp|jnt}|f|�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.
            �year�month�day�hour�minute�second�microsecondrzDuplicate argument: {}rr)rrrrrrrr)�zip�	TypeError�format�getattr�get�	__class__r)�selfr
rZargnames�argZargnameZdt_classrrrrDs
z_DatetimeWithFold.replacecCsdS)Nrr)r#rrrrbsz_DatetimeWithFold.foldN)�__name__�
__module__�__qualname__�__doc__�	__slots__r�propertyrrrrrr:srcCsLt|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�)r �	timetuplerrrr)rrr
rrrrfscst���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)�
isinstancerrr�
ValueError)r#r)�frr�fromutc�s


z)_validate_fromutc_inputs.<locals>.fromutc)r)r/r0r)r/r�_validate_fromutc_inputs�s	r1c@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)r#rZwall_0Zwall_1Zsame_offsetZsame_dtrrr�is_ambiguous�s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)r4�intr3�dst)r#�dt_utc�dt_wallZ
delta_wall�_foldrrr�_fold_status�s

z_tzinfo._fold_statuscCst|dd�S)Nrr)r )r#rrrrr9�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
        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() resultr)rz;fromutc(): dt.dst gave inconsistent results; cannot convert)r3r.r6r)r#rZdtoffZdtdst�deltarrr�_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
        occurrence, chronologically, of the ambiguous datetime).

        :param dt:
            A timezone-aware :class:`datetime.datetime` object.
        )r)r<r:r)r#rr8r9rrrr0�s
z_tzinfo.fromutcN)
r%r&r'r(r4r:r9r<r1r0rrrrr2�s%r2c@szeZdZdZdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�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)r#rrr�__init__!sztzrangebase.__init__cCs*|j|�}|dkrdS|r |jS|jSdS)N)�_isdst�_dst_offset�_std_offset)r#r�isdstrrrr3$s
ztzrangebase.utcoffsetcCs(|j|�}|dkrdS|r |jStSdS)N)r@�_dst_base_offset�ZERO)r#rrCrrrr6.s
ztzrangebase.dstcCs|j|�r|jS|jSdS)N)r@Z	_dst_abbrZ	_std_abbr)r#rrrr�tzname8s
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)r-rrrr.�transitionsrr3rBr�_naive_isdstrAr5r4r)
r#rrG�dston�dstoffZutc_transitionsr7rCr8r9rrrr0?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)�hasdstrGrrrD)r#r�start�endrrrr4`s
ztzrangebase.is_ambiguouscCsj|js
dS|dkrdS|j|j�}|dkr.dS|jdd�}|j||�}|rb|j|�rb|j|�S|SdS)NF)r)rKrGrrrHr4r9)r#rrGrCrrrr@vsztzrangebase._isdstcCsT|\}}|jdd�}||kr6||ko.|kn}n||koH|kn}|S)N)r)r)r#rrGrIrJrCrrrrH�sztzrangebase._naive_isdstcCs|j|jS)N)rArB)r#rrrrD�sztzrangebase._dst_base_offsetNcCs
||kS)Nr)r#�otherrrr�__ne__�sztzrangebase.__ne__cCsd|jjS)Nz%s(...))r"r%)r#rrr�__repr__�sztzrangebase.__repr__)r%r&r'r(r?r3r6rrFr0r4r@rHr*rD�__hash__rOrP�object�
__reduce__rrrrr=s

!r=N)r)r)�sixr�	functoolsrrrrrE�__all__r�hasattrrrr1r2r=rrrr�<module>s
,
v