ó
¡t\c           @   sÖ   d  d l  m Z d  d l m Z d  d l m Z m Z m Z e d ƒ Z d d g Z d „  Z	 e
 e d ƒ r{ d	 d
 „ Z n" d e f d „  ƒ  YZ d	 d „ Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   PY2(   t   wraps(   t   datetimet	   timedeltat   tzinfoi    t   tzname_in_python2t   enfoldc            s-   t  r% t ˆ  ƒ ‡  f d †  ƒ } | Sˆ  Sd S(   sž   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
    c             s.   ˆ  |  | Ž  } | d  k	 r* | j ƒ  } n  | S(   N(   t   Nonet   encode(   t   argst   kwargst   name(   t   namefunc(    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   adjust_encoding   s    N(   R    R   (   R   R   (    (   R   s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR      s    t   foldi   c         C   s   |  j  d | ƒ S(   s®  
        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   (   t   replace(   t   dtR   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR   %   s    t   _DatetimeWithFoldc           B   s,   e  Z d  Z d Z d „  Z e d „  ƒ Z RS(   sö   
        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
        c         O   s²   d } xK t  | | ƒ D]: \ } } | | k rF t d	 j | ƒ ƒ ‚ n  | | | <q Wx0 | D]( } | | k r[ t |  | ƒ | | <q[ q[ W| j d
 d ƒ r¢ |  j n t } | |   S(   sì  
            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.
            t   yeart   montht   dayt   hourt   minutet   secondt   microsecondR   s   Duplicate argument: {}R   i   (   R   R   R   R   R   R   R   R   (   t   zipt	   TypeErrort   formatt   getattrt   gett	   __class__R   (   t   selfR	   R
   t   argnamest   argt   argnamet   dt_class(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR   D   s     !c         C   s   d S(   Ni   (    (   R   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR   b   s    (    (   t   __name__t
   __module__t   __doc__t	   __slots__R   t   propertyR   (    (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR   :   s   	c         C   s`   t  |  d d ƒ | k r |  S|  j ƒ  d  } | |  j |  j f 7} | rR t | Œ  St | Œ  Sd S(   s®  
        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   i    i   N(   R   t	   timetupleR   R   R   R   (   R   R   R	   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR   f   s    
c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   s   
    The CPython version of ``fromutc`` checks that the input is a ``datetime``
    object and that ``self`` is attached as its ``tzinfo``.
    c            sI   t  | t ƒ s t d ƒ ‚ n  | j |  k	 r< t d ƒ ‚ n  ˆ  |  | ƒ S(   Ns&   fromutc() requires a datetime arguments   dt.tzinfo is not self(   t
   isinstanceR   R   R   t
   ValueError(   R   R   (   t   f(    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   fromutc‰   s
    (   R   (   R,   R-   (    (   R,   s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   _validate_fromutc_inputs„   s    	t   _tzinfoc           B   sA   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z RS(   s=   
    Base class for all ``dateutil`` ``tzinfo`` objects.
    c         C   s}   | j  d |  ƒ } t | d d ƒ} t | d d ƒ} | j ƒ  | j ƒ  k } | j  d d ƒ | j  d d ƒ k } | o| | S(   s6  
        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
        R   R   i    i   N(   R   R   t	   utcoffsetR   (   R   R   t   wall_0t   wall_1t   same_offsett   same_dt(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   is_ambiguousš   s    $c         C   sH   |  j  | ƒ r> | | } t | | j ƒ  | j ƒ  k ƒ } n d } | S(   sÀ  
        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.
        i    (   R5   t   intR0   t   dst(   R   t   dt_utct   dt_wallt
   delta_wallt   _fold(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   _fold_status³   s
    
%c         C   s   t  | d d ƒ S(   NR   i    (   R   (   R   R   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR;   Ì   s    c         C   s   | j  ƒ  } | d k r' t d ƒ ‚ n  | j ƒ  } | d k rN t d ƒ ‚ n  | | } | | 7} t | d d ƒj ƒ  } | d k r• t d ƒ ‚ n  | | S(   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
        occurence, chronologically, of the ambiguous datetime).

        :param dt:
            A timezone-aware :class:`datetime.datetime` object.
        s0   fromutc() requires a non-None utcoffset() results*   fromutc() requires a non-None dst() resultR   i   s;   fromutc(): dt.dst gave inconsistent results; cannot convertN(   R0   R   R+   R7   R   (   R   R   t   dtofft   dtdstt   delta(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   _fromutcÏ   s    

c         C   s1   |  j  | ƒ } |  j | | ƒ } t | d | ƒS(   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
        occurance, chronologically, of the ambiguous datetime).

        :param dt:
            A timezone-aware :class:`datetime.datetime` object.
        R   (   R@   R<   R   (   R   R   R9   R;   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR-   ô   s    (	   R$   R%   R&   R5   R<   R;   R@   R.   R-   (    (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR/   •   s   				%t   tzrangebasec           B   sŒ   e  Z d  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z e d	 „  ƒ Z d Z d
 „  Z d „  Z e j Z RS(   s‹  
    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
    c         C   s   t  d ƒ ‚ d  S(   Ns%   tzrangebase is an abstract base class(   t   NotImplementedError(   R   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   __init__!  s    c         C   s7   |  j  | ƒ } | d  k r d  S| r, |  j S|  j Sd  S(   N(   t   _isdstR   t   _dst_offsett   _std_offset(   R   R   t   isdst(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR0   $  s    c         C   s4   |  j  | ƒ } | d  k r d  S| r, |  j St Sd  S(   N(   RD   R   t   _dst_base_offsett   ZERO(   R   R   RG   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR7   .  s    c         C   s!   |  j  | ƒ r |  j S|  j Sd  S(   N(   RD   t	   _dst_abbrt	   _std_abbr(   R   R   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   tzname8  s    c   
      C   s  t  | t ƒ s t d ƒ ‚ n  | j |  k	 r< t d ƒ ‚ n  |  j | j ƒ } | d k rk | |  j | ƒ S| \ } } | |  j	 8} | |  j	 8} | | f } | j
 d d ƒ } |  j | | ƒ } | r× | |  j } n | |  j	 } t | oú |  j | ƒ ƒ }	 t | d |	 ƒS(   s,    Given a datetime in UTC, return local time s&   fromutc() requires a datetime arguments   dt.tzinfo is not selfR   R   N(   R*   R   R   R   R+   t   transitionsR   R   R0   RF   R   t   _naive_isdstRE   R6   R5   R   (
   R   R   RM   t   dstont   dstofft   utc_transitionsR8   RG   R9   R;   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR-   ?  s$    c         C   sV   |  j  s t S|  j | j ƒ \ } } | j d d ƒ } | | k oS | |  j k  SS(   s6  
        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
        R   N(   t   hasdstt   FalseRM   R   R   R   RH   (   R   R   t   startt   end(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyR5   `  s
    	c         C   s   |  j  s t S| d  k r d  S|  j | j ƒ } | d  k r? t S| j d d  ƒ } |  j | | ƒ } | r‡ |  j | ƒ r‡ |  j | ƒ S| Sd  S(   NR   (	   RR   RS   R   RM   R   R   RN   R5   R;   (   R   R   RM   RG   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyRD   v  s    	c         C   sj   | \ } } | j  d d  ƒ } | | k  rI | | k oA | k  n } n | | k o` | k  n } | S(   NR   (   R   R   (   R   R   RM   RO   RP   RG   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyRN   ‹  s    c         C   s   |  j  |  j S(   N(   RE   RF   (   R   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyRH   —  s    c         C   s   |  | k S(   N(    (   R   t   other(    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   __ne__  s    c         C   s   d |  j  j S(   Ns   %s(...)(   R   R$   (   R   (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   __repr__   s    N(   R$   R%   R&   RC   R0   R7   R   RL   R-   R5   RD   RN   R(   RH   R   t   __hash__RW   RX   t   objectt
   __reduce__(    (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyRA     s   		
	
	!					N(   t   sixR    t	   functoolsR   R   R   R   RI   t   __all__R   t   hasattrR   R   R.   R/   RA   (    (    (    s2   lib/python2.7/site-packages/dateutil/tz/_common.pyt   <module>   s   	,	v