
    iy!                        d Z ddlZddlmZ ddlZddlZddlmZmZ ddl	Z	ddl
Z
ddlmZ ddlZdZd Z G d d	          Zd
 Zej        de	j        de
j        fd            Z G d de          Z	 	 d!de
j        dee	j                 dede
j        fdZ ej                     ej        d ej        d          d           ej        d ej        d          d           ej                     ej                     ej        ddd          dededefd                                                                        Z g d Z!dS )"z7Bring calendars using X-WR-TIMEZONE into RFC 5545 form.    N)BytesIO)	vDDDTypes	vDDDLists)OptionalzX-WR-TIMEZONEc                     t          |           t          |          k    o&t          d t          | |          D                       S )z6Return wether all contents of two lists are identical.c              3   $   K   | ]\  }}||u V  d S N ).0e1e2s      H/root/projects/butler/venv/lib/python3.11/site-packages/x_wr_timezone.py	<genexpr>zlist_is.<locals>.<genexpr>   s*      %I%I62rbBh%I%I%I%I%I%I    )lenallzip)l1l2s     r   list_isr      s=    r77c"ggI#%I%ISR[[%I%I%I"I"IIr   c                   b    e Zd ZdZg dZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZdS )CalendarWalkerzsI walk along the components and values of an icalendar object.

    The idea is the same as a visitor pattern.
    )DTSTARTDTENDRDATEzRECURRENCE-IDEXDATEc                 >   |                                 D ](\  }}||         |ur|                     |||          c S )t          |j                  t          |          k    sJ t	          ||j                  D ]"\  }}||ur|                     |||          c S #|S )z~Check if an icalendar Component has changed and copy it if it has.

        atributes and subcomponents are put into the copy.)itemscopy_componentr   subcomponentsr   )self	component
attributesr    keyvaluenew_subcomponentold_subcomponents           r   copy_if_changedzCalendarWalker.copy_if_changed(   s     %**,, 	Q 	QJC~U****9j-PPPPP +9*++s=/A/AAAAA25mYE\2]2] 	Q 	Q..'777**9j-PPPPP 8r   c                     |                                 }|                                D ]
\  }}|||<   t          |j                  dk    sJ |D ]}|                    |           |S )zACreate a copy of the component with attributes and subcomponents.r   )copyr   r   r    add_component)r!   r"   r#   r    r$   r%   subcomponents          r   r   zCalendarWalker.copy_component5   s    NN$$	$**,, 	# 	#JC"IcNN9*++q0000) 	3 	3L$$\2222r   c                     g }|j         D ]K}t          |t          j        j                  r|                     |          }|                    |           L|                     |i |          S )zCWalk along the calendar and return the changed or identical object.)r    
isinstance	icalendarcalEvent
walk_eventappendr(   )r!   calendarr    r,   s       r   walkzCalendarWalker.walk?   sp    $2 	/ 	/L,	(;<< =#|<<  ....##Hb-@@@r   c                     i }| j         D ]1}|                    |          }||                     |          ||<   2|                     |||j                  S )z@Walk along the event and return the changed or identical object.)VALUE_ATTRIBUTESget
walk_valuer(   r    )r!   eventr#   namer%   s        r   r2   zCalendarWalker.walk_eventH   s`    
) 	: 	:DIIdOOE #'??5#9#9
4 ##E:u7JKKKr   c                     |S )z.Default method for walking along a value type.r
   )r!   r%   s     r   walk_value_defaultz!CalendarWalker.walk_value_defaultQ   s    r   c                 r    dt          |          j        z   }t          | || j                  } ||          S )zWalk along a value type.walk_value_)type__name__getattrr=   )r!   r%   r;   r5   s       r   r9   zCalendarWalker.walk_valueU   s7    tE{{33tT4#:;;tE{{r   c                 n    t          t          | j        |                    }t          ||          r|S |S )zWalk through a list of values.)listmapr9   r   )r!   lvs      r   walk_value_listzCalendarWalker.walk_value_list[   s5    T_a(())1a== 	Hr   c                      d |j         D             } fd|D             }t          ||          r|S t          |          S )Nc                     g | ]	}|j         
S r
   )dt)r   ddds     r   
<listcomp>z7CalendarWalker.walk_value_vDDDLists.<locals>.<listcomp>c   s    '''#sv'''r   c                 :    g | ]}                     |          S r
   )r9   )r   rK   r!   s     r   rM   z7CalendarWalker.walk_value_vDDDLists.<locals>.<listcomp>d   s%    55524??2&&555r   )dtsr   r   )r!   rF   rO   new_dtss   `   r   walk_value_vDDDListsz#CalendarWalker.walk_value_vDDDListsb   sV    '''''55555557C   	H!!!r   c                 j    |                      |j                  }||j        u r|S t          |          S )z"Walk along an icalendar value type)r9   rK   r   )r!   r%   rK   s      r   walk_value_vDDDTypesz#CalendarWalker.walk_value_vDDDTypesi   s1    __UX&&>>L}}r   c                     |S )&Walk along a datetime.datetime object.r
   r!   rK   s     r   walk_value_datetimez"CalendarWalker.walk_value_datetimep   s    	r   c                     |                                 dS |                                                                 dk    S )z0Return whether the time zone is a UTC time zone.NFUTC)tznameupperrV   s     r   is_UTCzCalendarWalker.is_UTCt   s4    99;;5yy{{  ""e++r   c                 .    |                                 d u S r	   )rZ   rV   s     r   is_FloatingzCalendarWalker.is_Floatingz   s    yy{{d""r   N)rA   
__module____qualname____doc__r7   r(   r   r5   r2   r=   r9   rH   rQ   rS   rW   r\   r^   r
   r   r   r   r       s         
 POO    A A AL L L      " " "    , , ,# # # # #r   r   c                 "    t          | d          S )zWhether the time zone requires localize() and normalize().

    pytz requires these funtions to be used in order to correctly use the
    time zones after operations.
    localize)hasattrtzinfos    r   is_pytzrg   ~   s     6J'''r   timezonereturnc                 @    t           j                            |           S )zZReturn a timezone component for the tzid and cache it.
    
    The result is cached.
    )r/   Timezonefrom_tzinfo)rh   s    r   get_timezone_componentrm      s     ))(333r   c                       e Zd ZdZd Zd ZdS )UTCChangingWalkerz/Changes the UTC time zone into a new time zone.c                     || _         dS )z-Initialize the walker with the new time zone.N)new_timezone)r!   rh   s     r   __init__zUTCChangingWalker.__init__   s    $r   c                     |                      |          r|                    | j                  S |                     |          rIt	          | j                  r| j                            |          S |                    | j                  S |S )rU   re   )r\   
astimezonerq   r^   rg   rc   replacerV   s     r   rW   z%UTCChangingWalker.walk_value_datetime   s    ;;r?? 	8==!2333b!! 	8t()) 6(11"555::T%6:777	r   N)rA   r_   r`   ra   rr   rW   r
   r   r   ro   ro      s8        99% % %    r   ro   Fr4   add_timezone_componentc                    ||                      t          d          }|;t          |t          j                  s!t          j        t          |                    }| }~ |xt          |          }|	                    |          }|rR|
                                }|j        dd         |_        |}|j                            dt          |                     |S )a  Make a calendar that might use X-WR-TIMEZONE compatible with RFC 5545.

    Arguments:
    
        calendar: is an icalendar.Calendar object. It does not need to have
            the X-WR-TIMEZONE property but if it has, calendar  will be converted
            to conform to RFC 5545.
            
        timezone: an optional timezone argument if you want to override the
            existence of the actual X-WR-TIMEZONE property of the calendar.
            This can be a string like "Europe/Berlin" or "UTC" or a
            pytz.timezone or any other timezone accepted by the datetime module.
        
        add_timezone_component: whether to add a VTIMEZONE component to the result.
    Nr   )r8   X_WR_TIMEZONEr.   datetimerf   zoneinfoZoneInfostrro   r5   r*   r    insertrm   )r4   rh   rv   resultwalkernew_cals         r   to_standardr      s    ( <<t44Jx$I$I$S]]33"*F"8,,V$$! 	MkkmmG$*$8$;G!F ''+A(+K+KLLLMr   in_filerb-)r@   defaultout_filewbz--add-timezone/--no-timezoneTz(Add a VTIMEZONE component to the result.)r   helpadd_timezonec                     t           j                            |                                           }t	          ||          }|                    |                                           dS )a  x-wr-timezone converts ICSfiles with X-WR-TIMEZONE to use RFC 5545 instead.

    Convert input:

        cat in.ics | x-wr-timezone > out.ics
        wget -O- https://example.org/in.ics | x-wr-timezone > out.ics
        curl https://example.org/in.ics | x-wr-timezone > out.ics

    Convert files:

        x-wr-timezone in.ics out.ics

    By default, x-wr-timezone will add a VTIMEZONE component to the result.
    Use --no-vtimezone to remove it. (Added in v2.0.0)

    Get help:

        x-wr-timezone --help

    For bug reports, code and questions, visit the projet page:

        https://github.com/niccokunzmann/x-wr-timezone

    License: LPGLv3+
    )rv   r   )r/   Calendar	from_icalreadr   writeto_ical)r   r   r   r4   r   s        r   mainr      sV    @ !++GLLNN;;H(<HHHGNN7??$$%%%1r   )r   r   ro   r   rx   r   rm   )NF)"ra   	functoolsior   sysrz   icalendar.propr   r   ry   r/   typingr   clickrx   r   r   rg   cacherf   rk   rm   ro   r   boolr   commandargumentFileversion_optionhelp_optionoptionr   __all__r
   r   r   <module>r      s   > =           



  / / / / / / / /            J J J
[# [# [# [# [# [# [# [#|( ( ( 4HO 4	8J 4 4 4 4       ( ,0$)" "%"(/*"  $" 
		" " " "H 	

4 0 0#>>>
D!1!13???,dAklll 7 $    ml   @? ?> @  r   