
    i2                       d Z ddlmZ ddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZ erdd	lmZ  ed
dd          Z eddd          Z ed          Zg ZeZeek    r*e                    e           e ed          z  Zeek    *[ddZdgZedk    r#ddlmZ ddlmZ ddlm Z   eee egd           dS dS )a  This module helps identifying the timezone ids and where they differ.

The algorithm: We use the tzname and the utcoffset for each hour from
1970 - 2030.
We make a big map.
If they are equivalent, they are equivalent within the time that is mostly used.

You can regenerate the information from this module.

See also:
- https://stackoverflow.com/questions/79171631/how-do-i-determine-whether-a-zoneinfo-is-an-alias/79171734#79171734

Run this module:

    python -m icalendar.timezone.equivalent_timezone_ids

    )annotations)defaultdict)datetime	timedeltatzinfo)Path)TYPE_CHECKING
NamedTuple)ZoneInfoavailable_timezones)AmbiguousTimeErrorNonExistentTimeError)Callablei     i     hours   create_timezoneslist[Callable[[str], tzinfo]]namestrc                   t                                          d                               d            G d dt                    fd| D             }t          d          t          t
          dfdfd |t          d                    }t          t                    j        d| dz  }|	                    d          5 }|
                    dt          t                    j         d           |
                    d           |
                    d           |
                    d           ddd           n# 1 swxY w Y   |S ) zGenerate a lookup table for timezone information if unknown timezones.

    We cannot create one lookup for all because they seem to be all equivalent
    if we mix timezone implementations.
    	localtimeFactoryc                  $    e Zd ZU ded<   ded<   dS )main.<locals>.TZr   tzr   idN)__name__
__module____qualname____annotations__     e/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/timezone/equivalent_timezone_ids.pyTZr   ;   s"         


r%   r'   c                D    g | ]}D ]}  ||          |          S r$   r$   ).0create_timezonetzidr'   unsorted_tzidss      r&   
<listcomp>zmain.<locals>.<listcomp>?   sV       "   	??4  $''   r%   r   r   Ntzslist[TZ]stepr   startr   endtodoset[str] | Nonereturn5tuple[datetime, dict[timedelta, set[str]]] | set[str]c                D   |d | D             }t          |           dk    rt          d          t          |           dk    r.|                    | d         j                   | d         j        hS |k     rt	          t
                    }	 t          fd| D                        }n# t          t          f$ r d}Y nw xY w|rt          z  ^| D ]5}||j
                                                                   |           6t          |          dk    r|z  i }|                                D ]\  }	}
 |
||z   ||          ||	<   |fS t                      }| D ]6}|                    |j                   |                    |j                   7|S )	zGenerate a lookup tree.Nc                    g | ]	}|j         
S r$   )r   )r)   r   s     r&   r-   z/main.<locals>.generate_tree.<locals>.<listcomp>N   s    (((bBE(((r%   r   ztzs cannot be emptyr   c              3     K   | ]l}|j                                       |j                             t          z
            cxk    o%|j                             t          z             k    nc V  md S )N)r   	utcoffsetDISTANCE_FROM_TIMEZONE_CHANGE)r)   r   r1   s     r&   	<genexpr>z.main.<locals>.generate_tree.<locals>.<genexpr>Y   s       + +  EOOE**uu/L'LMMN N N Nuu/L'LMMN N N N+ + + + + +r%   T)r.   r0   r1   r2   r3   )len
ValueErrorremover   r   listallr   r   r;   r   r:   appenditemssetadd)r.   r0   r1   r2   r3   offsetsaround_tz_changer   lookupoffsettz2resultgenerate_trees     `         r&   rL   zmain.<locals>.generate_treeE   s    <((C(((Ds88q==2333s88q==KKA	"""FI;ckk1<T1B1BG
( (+ + + + + "	+ + + ( ( $   )*<= ( ( (#'   ( 66 ; ;../66r::::7||q  F&}}  !.$edl$" " "v &=  	 	BJJruKKs   B, ,CC!   )r0   equivalent_timezone_ids_z.pywz+'''This file is automatically generated by z'''
zimport datetime

z

lookup = z

__all__ = ['lookup']
)r.   r/   r0   r   r1   r   r2   r   r3   r4   r5   r6   )r   r?   r
   r   STARTENDr   __file__parentopenwriter   )	r   r   r.   rH   filefr'   rL   r,   s	         @@@r&   mainrX   .   s    )**N+&&&)$$$    Z       /  C $!,,, $. . . . . . .` ]3YR%8%8%8999F>> #Gd#G#G#GGD	3 .1	T$x..:MTTT	
 	
 	
 	
%&&&		,---. . . . . . . . . . . . . . . Ms   A0EEErX   __main__)r   )gettz)timezonerK   N)r   r   r   r   )!__doc__
__future__r   collectionsr   r   r   r   pathlibr   typingr	   r
   zoneinfor   r   pytzr   r   collections.abcr   rP   rQ   r;   DTSdtrB   rX   __all__r    dateutil.tzrZ   r[   r$   r%   r&   <module>rh      s   $ # " " " " " # # # # # # 0 0 0 0 0 0 0 0 0 0       , , , , , , , , 2 2 2 2 2 2 2 2 9 9 9 9 9 9 9 9 )((((((q!htQ )	 3 3 3 
CiiJJrNNN ))"


B	 	Cii
 R R R Rj (z!!!!!!!!!!!! 	D	8U#     r%   