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rd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 )#zThis 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rt
dk	r| j}|tt
rtt|t
}t|S t|S t| tjrt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 )zRetrieve 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 )zThis 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(   
#
