
    mh                         d dl mZ d dlmZ d dlZ	 d Zd ZddZd Zd	 Z	d
 Z
d Zedk    r$	  e
             dS # e$ r  ed           Y dS w xY wdS )    )print_function)OptionParserNc                 Z    d }d }d } ||            ||           z    ||           z   S )Nc                 .    |                      dd          S )Nuid )getChildValue)	components    P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/vobject/ics_diff.pygetUIDzgetSortKey.<locals>.getUID   s    &&ub111    c                 r    |                      dd          }d                    t          |                    S )Nsequencer   z{0:05d})r	   formatint)r
   r   s     r   getSequencezgetSortKey.<locals>.getSequence   s1    **:q99H...r   c                 ^    |                      dd           }|dS |                                S )Nrecurrence_idz
0000-00-00)r	   	isoformat)r
   r   s     r   getRecurrenceIDz#getSortKey.<locals>.getRecurrenceID   s4    !//FF < **,,,r    )r
   r   r   r   s       r   
getSortKeyr      s_    2 2 2/ / /- - - 6){{9555	8R8RRRr   c                 .    t          | t                    S )N)key)sortedr   )
componentss    r   	sortByUIDr   "   s    **----r   Fc                     |                                  D ]}t          ||           |                                 D ]}d|j        v r|j        d= |rt	          | d          r| `dS dS dS )zo
    Recursively walk the component's children, deleting extraneous details like
    X-VOBJ-ORIGINAL-TZID.
    zX-VOBJ-ORIGINAL-TZIDdtstamp_listN)r   deleteExtraneouslinesparamshasattrr   )r
   ignore_dtstampcomplines       r   r    r    &   s    
 $$&& / /~....!! 4 4!T[0023 #')^<< #"""# # # #r   c           
      :   fdd }fd t          t          | dg                     t          t          |dg                               } t          t          | dg                     t          t          |dg                               }||z   S )a
  
    Take two VCALENDAR components, compare VEVENTs and VTODOs in them,
    return a list of object pairs containing just UID and the bits
    that didn't match, using None for objects that weren't present in one
    version or the other.

    When there are multiple ContentLines in one VEVENT, for instance many
    DESCRIPTION lines, such lines original order is assumed to be
    meaningful.  Order is also preserved when comparing (the unlikely case
    of) multiple parameters of the same type in a ContentLine

    c                    g }d}t          |          }| D ]}||k    r|                    |d f            t          |          }||         }t          |          }||k    rW|                    d |f           |dz  }||k    r|                    |d f           n||         }t          |          }||k    W||k     r|                    |d f           ||k    r(|dz  } 
||          }	|	|                    |	           |S )Nr      )lenappendr   )leftList	rightListoutput
rightIndexrightListSizer%   leftKey	rightComprightKeymatchResultprocessComponentPairs             r   processComponentListsz#diff.<locals>.processComponentListsB   sL   
I 	3 	3D]**tTl++++$T**%j1	%i00((MM4"3444!OJ!]22tTl333$-j$9	#-i#8#8 (( X%%MM4,////((!OJ"6"6tY"G"GK".k222r   c                     |d S t           j                            |           }t           j                            |           |_        d|_        |S )NT)vobjectbase	ComponentgetBehaviorbehaviorisNative)namebodycs      r   newComponentzdiff.<locals>.newComponentb   sD    <4&&t,,A 11$77AJAJHr   c                 J   | j                                         }|j                                         }g }i }|D ]}|j                             |g           }t          | j         |         d         t          j        j                  r0 | j         |         |          }t          |          dk    r|||<   }| j         |         |k    r"|                    | j         |         |f           |D ]k}||vret          |j         |         d         t          j        j                  rg |j         |         f||<   I|                    g |j         |         f           lt          |          dk    rt          |          dk    rdS t          | j
                  }	t          | j
                  }
|                     d          }|4||	                    d          _        ||
                    d          _        |                                D ]g\  }}t          | \  }}t          |          dk    rt!          d|          |	j         |<   t          |          dk    rt!          d|          |
j         |<   h|D ].\  }}|p|}|d         j
        }|
||	j         |<   |
||
j         |<   /|	|
fS )zu
        Return None if a match, or a pair of components including UIDs and
        any differing children.

        r   Nr   )contentskeysget
isinstancer8   r9   r:   r*   r+   newFromBehaviorr>   r	   addvalueitemszipfilter)leftCompr2   leftChildKeysrightChildKeysdifferentContentLinesdifferentComponentsr   r-   compDifferenceleftrightr   r>   childPairListleftComponentsrightComponentsleftChildLinerightChildLinenonEmptyr6   s                      r   r5   z"diff.<locals>.processComponentPairk   s    !)..00"+0022 "   
	: 
	:C!*..sB77I(+C03W\5KLL :!6!6x7H7M7@"B "B~&&**/=',"3'944%,,h.?.D.7.9 : : : " 	P 	PC-''i05a8',:PQQ P02I4Fs4K/L',,)00"i6H6M1NOOO$%%**s3F/G/G1/L/L4"8=11D#HM22E ((//C(+%),		%  &':'@'@'B'B I I#m25}2E/~&&***0~*F*FDM$'''!+++1$+H+HEN4(1F : :-~(:N{' ,*7DM$'!-+9EN4(;r   vevent_list
vtodo_list)r   getattr)rS   rT   rA   veventsvtodosr6   r5   s        @@r   diffr`   4   s        @  < < < < <| $#IgdM2.N.N$O$O$-ge]B.O.O$P$PR RG #"9WT<-L-L#M#M#,WUL"-M-M#N#NP PF Vr   c                     t          | |          D ]e\  }}t          d           ||                                 t          d           ||                                 t          d           t           fd S )Nz<<<<<<<<<<<<<<<z===============z>>>>>>>>>>>>>>>)r`   printprettyPrint)leftObjrightObjrS   rT   s       r   
prettyDiffrf      s    GX..  e          r   c                     t                      \  } }|r| j        }|\  }}t          |          5 }t          |          5 }t          |          }t          |          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t	          ||           t	          ||           t          ||           d S d S )N)r$   )
getOptionsignoreopenreadOner    rf   )	optionsargsr$   	ics_file1	ics_file2fgcal1cal2s	            r   mainrt      sA   LLMGT  #	9)__ 	4	?? 	a1::D1::D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	n====n====4 s4   BA*B*A.	.B1A.	2BBBc                  j   d} t          | t          j                  }|                    d           |                    dddddd	
           |                                \  }}t          |          dk     r9t          d           t           t          |                                           dS ||fS )Nz*usage: %prog [options] ics_file1 ics_file2)usageversionz8ics_diff will print a comparison of two iCalendar files z-iz--ignore-dtstampri   
store_trueFz%ignore DTSTAMP lines [default: False])destactiondefaulthelp   zerror: too few arguments given)FF)	r   r8   VERSIONset_description
add_option
parse_argsr*   rb   format_help)rv   parsercmdline_optionsrm   s       r   rh   rh      s     9Ew???F
UVVV
d.Xl#*Q  S S S %//11_d
4yy1}}.///f  ""###|D  r   __main__Aborted)F)
__future__r   optparser   r8   r   r   r    r`   rf   rt   rh   __name__KeyboardInterruptrb   r   r   r   <module>r      s	   % % % % % % ! ! ! ! ! ! 
S S S*. . .# # # #{ { {|	 	 	
 
 
! ! !& z   i s   
; AA