U
    ¤�©jý  ã                   @  s  U d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ erfddlmZmZ e d	¡Zeed
dƒZded< edkr�dneeƒjZdddœdd„Zdddœdd„Zdddœdd„ZeeƒZded< ddœdd„Zeejƒ ddd œd!d"„ZdddgZdS )#z‡This module identifies timezones.

Normally, timezones have ids.
This is a way to access the ids if you have a
datetime.tzinfo object.
é    )Úannotations)Údefaultdict)ÚPath)ÚTYPE_CHECKINGÚOptional)Útz)Úequivalent_timezone_ids_result)ÚdatetimeÚtzinfoÚUTCÚ	_filenameNzOptional[str]ÚDATEUTIL_UTC_PATHzOptional[tzinfo]z
tuple[str])r
   Úreturnc                 C  sÀ   | dkrdS t | dƒr t| jƒS t | dƒr4t| jƒS t| tjƒrJt| jƒS t| tjƒr`t| j	ƒS t | dƒr¨t
dk	r¨| j}| tt
ƒ¡r tt|ƒ t
¡ƒ}t|ƒS t|ƒS t| tjƒr¼tdƒS dS )ap  Get several timezone ids if we can identify the timezone.

    >>> import zoneinfo
    >>> from icalendar.timezone.tzid import tzids_from_tzinfo
    >>> tzids_from_tzinfo(zoneinfo.ZoneInfo("Arctic/Longyearbyen"))
    ('Arctic/Longyearbyen', 'Atlantic/Jan_Mayen', 'Europe/Berlin', 'Europe/Budapest', 'Europe/Copenhagen', 'Europe/Oslo', 'Europe/Stockholm', 'Europe/Vienna')
    >>> from dateutil.tz import gettz
    >>> tzids_from_tzinfo(gettz("Europe/Berlin"))
    ('Europe/Berlin', 'Arctic/Longyearbyen', 'Atlantic/Jan_Mayen', 'Europe/Budapest', 'Europe/Copenhagen', 'Europe/Oslo', 'Europe/Stockholm', 'Europe/Vienna')

    N© ÚzoneÚkeyr   r   )ÚhasattrÚget_equivalent_tzidsr   r   Ú
isinstancer   Z
_tzicalvtzZ_tzidZtzstrZ_sÚDATEUTIL_ZONEINFO_PATHr   Ú
startswithÚstrr   Úrelative_toZtzutc)r
   ÚpathÚtzidr   r   ú;/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/timezone/tzid.pyÚtzids_from_tzinfo   s(    






r   c                 C  s$   t | ƒ}d|krdS |sdS |d S )z˜Retrieve the timezone id from the tzinfo object.

    Some timezones are equivalent.
    Thus, we might return one ID that is equivelant to others.
    r   Nr   )r   )r
   Ztzidsr   r   r   Útzid_from_tzinfo>   s    r   r	   )Údtr   c                 C  s   t | jƒ}|dkr|  ¡ S |S )z2Retrieve the timezone id from the datetime object.N)r   r
   Útzname)r   r   r   r   r   Útzid_from_dtL   s    
r    zdict[str, set[str]]Ú_EQUIVALENT_IDSztuple | dict | set)Úvaluec                 C  sz   t | tƒr$| D ]}t|  | ¡ qnRt | tƒr<t| d ƒ n:t | tƒr^|  ¡ D ]} t| ƒ qNntd| j	j
› d| ›�ƒ‚dS )zÍThis adds equivalent ids/

    As soon as one timezone implementation used claims their equivalence, 
    they are considered equivalent.
    Have a look at icalendar.timezone.equivalent_timezone_ids.
    é   z!Expected tuple, dict or set, not z: N)r   Úsetr!   ÚupdateÚtupleÚ_add_equivalent_idsÚdictÚvaluesÚ	TypeErrorÚ	__class__Ú__name__)r"   r   r   r   r   r'   V   s    


r'   r   )r   r   c                 C  s&   t  | tƒ ¡}| ftt|| h ƒƒ S )z8This returns the tzids which are equivalent to this one.)r!   Úgetr$   r&   Úsorted)r   Úidsr   r   r   r   j   s    r   ) Ú__doc__Ú
__future__r   Úcollectionsr   Úpathlibr   Útypingr   r   Zdateutil.tzr   Zicalendar.timezoner   r	   r
   ZgettzZDATEUTIL_UTCÚgetattrr   Ú__annotations__Úparentr   r   r   r    r$   r!   r'   Úlookupr   Ú__all__r   r   r   r   Ú<module>   s(   
ÿ#
