U
    Òøïc’  ã                   @   s@   d Z ddlmZmZ ddlmZ dadd„ Zdd„ Zd	d
„ Z	dS )zv
This module contains helper functions to ease the transition from ``pytz`` to
another :pep:`495`-compatible library.
é   )Ú_commonÚ_compat)Ú_PytzShimTimezoneNc                 C   s$   t  ¡ sdS tdkrtƒ  t| tƒS )a!  Check if a time zone is a ``pytz`` time zone.

    This will only import ``pytz`` if it has already been imported, and does
    not rely on the existence of the ``localize`` or ``normalize`` methods
    (since the shim classes also have these methods, but are not ``pytz``
    zones).
    FN)r   Zpytz_importedÚ_PYTZ_BASE_CLASSESÚ_populate_pytz_base_classesÚ
isinstance)Útz© r	   úA/tmp/pip-unpacked-wheel-pe1vybbg/pytz_deprecation_shim/helpers.pyÚis_pytz_zone   s
    r   c                 C   sb   t | tƒr| jS t| ƒr^| jdkrB|  d¡}| ¡ d }t |¡S | jdkrRtj	S t 
| j¡S | S )a  Convert a ``pytz`` or shim timezone into its modern equivalent.

    The shim classes are thin wrappers around :mod:`zoneinfo` or
    :mod:`dateutil.tz` implementations of the :class:`datetime.tzinfo` base
    class. This function removes the shim and returns the underlying "upgraded"
    time zone.

    When passed a ``pytz`` zone (not a shim), this returns the non-``pytz``
    equivalent. This may fail if ``pytz`` is using a data source incompatible
    with the upgraded provider's data source, or if the ``pytz`` zone was built
    from a file rather than an IANA key.

    When passed an object that is not a shim or a ``pytz`` zone, this returns
    the original object.

    :param tz:
        A :class:`datetime.tzinfo` object.

    :raises KeyError:
        If a ``pytz`` zone is passed to the function with no equivalent in the
        :pep:`495`-compatible library's version of the Olson database.

    :return:
        A :pep:`495`-compatible equivalent of any ``pytz`` or shim
        class, or the original object.
    Né<   ÚUTC)r   r   Z_zoner   ÚzoneÚ	utcoffsetÚtotal_secondsr   Zget_fixed_offset_zoner   Zget_timezone)r   ÚoffsetZoffset_minutesr	   r	   r
   Úupgrade_tzinfo!   s    




r   c                  C   sB   dd l } ddlm} || jf}t| j|ƒs:|t| jƒf }|ad S )Né    )Ú
BaseTzInfo)ÚpytzZpytz.tzinfor   Z_FixedOffsetr   r   Útyper   )r   r   Zbase_classesr	   r	   r
   r   O   s    
r   )
Ú__doc__Ú r   r   Ú_implr   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   .