
    iB                        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mZ d dl	m
Z
 d dlmZ d dlmZ d dlm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 Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'ej(        )                    d g d!          Z*e*d"             Z+e*d#             Z,d$ Z-d% Z.ej/        d&             Z0d' Z1d( Z2d) Z3d* Z4d+ Z5d, Z6d- Z7d. Z8d/ Z9d0 Z:d1 Z;d2 Z<ej(        )                    d3 e j=        g d4d56                    d7             Z>ej(        )                    d8d9g          d:             Z?dS );    N)datetime	timedelta)prop)Calendar)	Component)Event)Journal)tzid_from_dtc                 :    | sJ |                                  sJ dS )zCA component is like a dictionary with extra methods and attributes.N)is_emptycalendar_components    X/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/tests/test_unit_cal.pytest_cal_Componentr      s,    &&(((((((    c                     d| d<   |                                  rJ | t          ddi          k    sJ ddg| d<   | t          ddgdd          k    sJ dS )	z|Every key defines a property.A property can consist of either a
    single item. This can be set with a single value...
    z-//max m//icalendar.mxm.dk/prodidPRODIDMax M	RasmussenATTENDEE)r   r   N)r   r   r   s    r    test_nonempty_calendar_componentr      s     $Ax !**,,,,,85R*S!T!TTTTT '.{%;z"{+7TUU" "      r   c                    |                      dddg           |                      dd           |                      dd           |                      dddg           | t          dt          j        d          t          j        d          t          j        d          t          j        d          t          j        d          t          j        d          gi          k    sJ d	S )
zadd multiple values to a property.

    If you use the add method you don't have to considder if a value is
    a list or not.
    attendeeztest@test.comztest2@test.comzmaxm@mxm.dkztest@example.dkztest3@test.comztest4@test.comr   N)addr   r   vCalAddress)event_components    r   test_add_multiple_valuesr   %   s     
_6F$GHHH 
M222
$5666 
%57G$HIIIe 11 !122 // !233 !122 !122		
       r   c                     |                      dd           | d         t          j        d          k    sJ |                     d          dk    sJ dS )z(You can get the values back directly ...r   z-//my product//N)r   r   vTextdecodedcs    r   test_get_content_directlyr$   C   s[    EE(%&&&X;$*%677777799X"3333333r   c                 >    |                      dd          dk    sJ dS )z/With default values for non existing propertiesversionz
No VersionN)r!   r"   s    r   test_get_default_valuer'   K   s'    99Y--======r   c           	          |                      dt          ddd          t          ddd          g           t          |                     d          t          j                  sJ d S )Nrdatei           )r   r   
isinstancer!   r   	vDDDListsr"   s    r   test_default_list_exampler/   P   s]    EE'HT1b))8D!R+@+@ABBBaii(($.9999999r   c                 f    |                      dd           |                                 dk    sJ dS )z7The component can render itself in the RFC 5545 format.r   r   s0   BEGIN:VCALENDAR
ATTENDEE:Max M
END:VCALENDAR
N)r   to_icalr   s    r   test_render_componentr2   U   sN    :w///""$$D	E 	E 	E 	E 	E 	Er   c                 :    |                                  dk    sJ dS )z-Check the ical string of the event component.sk   BEGIN:VEVENT
DTEND:20000102T000000
DTSTART:20000101T000000
SUMMARY:A brief history of time
END:VEVENT
Nr1   filled_event_components    r   test_nested_component_event_icsr7   ^   s4    !))++	     r   c                 D    | j         t          dddd          gk    sJ dS )zXComponents can be nested, so You can add a subcomponent. Eg a calendar
    holds events.20000102T00000020000101T000000A brief history of time)DTENDDTSTARTSUMMARYN)subcomponentsr   r   r6   s     r   test_nested_componentsrA   g   sM     +*,4 	
 	
0      r   c                 R    d |                                  D             ddgk    sJ dS )z9We can walk over nested componentes with the walk method.c                     g | ]	}|j         
S  name.0is     r   
<listcomp>z7test_walk_filled_calendar_component.<locals>.<listcomp>w   s    666qAF666r   	VCALENDARVEVENTNwalkr@   s     r   #test_walk_filled_calendar_componentrO   u   s9    66.3355666;:QQQQQQQr   c                     d |                      d          D             dgk    sJ d |                      d          D             dgk    sJ dS )zYWe can also just walk over specific component types, by filtering
    them on their name.c                     g | ]	}|j         
S rD   rE   rG   s     r   rJ   z$test_filter_walk.<locals>.<listcomp>}   s    >>>qAF>>>r   rL   c                     g | ]
}|d          S dtstartrD   rG   s     r   rJ   z$test_filter_walk.<locals>.<listcomp>~   s    DDDQAiLDDDr   r:   NrM   r@   s     r   test_filter_walkrU   z   s{     ?>.33H==>>>8*LLLLDD"4"9"9("C"CDDDI      r   c           	          |                      dd           |                                 ddt          j        d          fddddd	d
gk    sJ dS )zOWe can enumerate property items recursively with the property_items
    method.r   r   BEGIN	   VCALENDARr   rX      VEVENTr<   r9   r=   r:   r>   r;   ENDr[   r`   rY   Nr   property_itemsr   r   r@   s     r   test_recursive_property_itemsrd      st     :w///,,..	T%g../$&.	3 	 	 	 	 	 	r   c                     |                      dd           |                     d          ddt          j        d          fdgk    sJ dS )	z>We can also enumerate property items just under the component.r   r   F	recursiverW   r   ra   Nrb   r@   s     r   test_flat_property_itemsrh      si    :w///,,u,==	T%g../B      r   c                 B    |                      d          g dk    sJ dS )zFlat enumeration on the event.Frf   )rZ   r\   r]   r^   r_   N)rc   r5   s    r   test_flat_property_items_2rj      sF    !0050AA F F F      r   c                  `    t                      } d| d<   |                                 dk    sJ dS )zGText fields which span multiple mulitple lines require proper indentingzParagraph one

Paragraph twodescriptionsL   BEGIN:VCALENDAR
DESCRIPTION:Paragraph one\n\nParagraph two
END:VCALENDAR
Nr   r1   r"   s    r   test_indentrn      sC    

A7Am99;;	!     r   c                 h    | t          ddi          k    sJ |                                 dk    sJ dS )z{INLINE properties have their values on one property line. Note the
    double quoting of the value with a colon in it.
    	RESOURCESzChair, Table, "Room: 42"sF   BEGIN:VCALENDAR
RESOURCES:Chair\, Table\, "Room: 42"
END:VCALENDAR
Nrm   calendar_with_resourcess    r   test_INLINE_propertiesrs      sd     #h	01' '     #**,,	     r   c                 D    |                      dd          g dk    sJ dS )zXThe inline values must be handled by the get_inline() and
    set_inline() methods.
    	resourcesr   decode)ChairTablezRoom: 42N
get_inlinerq   s    r   test_get_inliner|      sJ     #--k!-DD I I I      r   c                 D    |                      dd          g dk    sJ dS )zThese can also be decodedru      rv   )s   Chairs   Tables   Room: 42Nrz   rq   s    r   test_get_inline_decodedr      sH    "--k!-DD I I I      r   c                     |                      dg dd           | d         dk    sJ |                     dd          g dk    sJ dS )	zYou can set them directly ...ru   )AListofzsome, recourcesr~   encodezA,List,of,"some, recources"r   rv   N)
set_inliner{   rq   s    r   test_set_inliner      s    &&;;;A '    #;/3PPPPP"--k!-DD I I I      r   c                    d| d<   |                      dd          g dk    sJ |                      dd          }t          |d         d         t                    sJ t          |d         d         t                    sJ d S )NzM19970308T160000Z/PT3H,19970308T200000Z/PT1H,19970308T230000Z/19970309T000000Zfreebusyr   rv   )z19970308T160000Z/PT3Hz19970308T200000Z/PT1Hz!19970308T230000Z/19970309T000000Zr~   )r{   r-   r   r   )r#   r   s     r   test_inline_free_busy_inliner      s    W jM <<
1<-- 2 2 2     ||Jq|11Hhqk!nh/////hqk!ni0000000r   c                 8   |                      d|                    t          dddddd          d                     |                      dt          dddddd                     |                      d|                    t          dddd	dd          d                     |                      d
|                    t          dddddd                               |                                                                 }d|v sJ d|v sJ d|v sJ d|v sJ dS )zTest the for timezone correctness: dtstart should preserve it's
    timezone, created, dtstamp and last-modified must be in UTC.
    rT   i  
   r   zEurope/Viennacreated   dtstamp   zlast-modified   s*   DTSTART;TZID=Europe/Vienna:20101010T100000s   CREATED:20101010T120000Zs   DTSTAMP:20101010T120000Zs   LAST-MODIFIED:20101010T160000ZN)r   localizer   localize_utcr1   
splitlines)comptzpliness      r   test_cal_Component_addr      s)    	HHYXdBB1%E%EWWXXXHHYr2r1a88999HHYXdBB1%E%EWWXXXHH_c..xb"b!Q/O/OPPQQQLLNN%%''E8EAAAA&%////&%////,555555r   c                     |                      dd           |                      ddd           t          j        d          }|                      d|           | d         dd|gk    sJ dS )z0Already encoded values should not be re-encoded.ATTACHmeyouFr   usN)r   r   vBinary)r   binarys     r   "test_cal_Component_add_no_reencoder      ss    HHXtHHXuUH+++\$FHHXv>dE62222222r   c                     |                      ddddd           |                                                                 }d|v sJ dS )	zTest the for timezone correctness: dtstart should preserve it's
    timezone, crated, dtstamp and last-modified must be in UTC.
    zX-TEST-PROPztryout.val1val2)prop1prop2)
parameterss)   X-TEST-PROP;PROP1=val1;PROP2=val2:tryout.N)r   r1   r   )r   r   s     r   )test_cal_Component_add_property_parameterr   
  sT     	HH]IFV2T2THUUULLNN%%''E75@@@@@@r   )component_nameproperty_name))rL   r=   )rL   r<   )rL   zRECURRENCE-ID)VTODODUEc                     d| z   dz   }||dz   z  }|d| z   z  }t          j        |          }t          ||         j                  dk    sJ dS )BCheck for proper handling of TZID parameter of datetime propertiesBEGIN:
z;TZID=America/Denver:20120404T073000
END:zAmerica/DenverN)r   	from_icalr
   dtr   r   r   component_str	components        r   test_cal_Component_from_icalr     sk     ~-4M]%<<<M,~==M#M22I	-03448HHHHHHHr   c                     d| z   dz   }||dz   z  }|d| z   z  }t          j        |          }||         j        j        J dS )r   r   r   :r   N)r   r   r   tzinfor   s        r   test_cal_Component_from_ical_2r   (  s_     ~-4M]S((M,~==M#M22I]#&-55555r   c                  \   g d} t          j        d                    |                     }|                                                                }|| k    sJ t          |          t          |           k    sJ |                    d                                          }|| k    sJ d S )N)   BEGIN:VEVENTs   DTSTART:19970714T170000Zs   DTEND:19970715T035959Zs   SUMMARY:Bastille Day Party
   END:VEVENT   
Fsorted)r   r   joinr1   r   setr   r   
sorted_strpreserved_strs       r   )test_cal_Component_to_ical_property_orderr   2  s      M #GLL$?$?@@I""$$//11J&&&&z??c-000000%%U%33>>@@MM))))))r   c                  t   g d} t          j        d                    |                     }|                                                                }|d         | d         k    sJ |d         dk    sJ |d         | d         k    sJ |                    d                                          }|| k    sJ d S )	N)r   s(   X-FOOBAR;C=one;A=two;B=three:helloworld.r   r   r   r~   s(   X-FOOBAR;A=two;B=three;C=one:helloworld.   Fr   )r   r   r   r1   r   r   s       r   *test_cal_Component_to_ical_parameter_orderr   D  s      M
 #GLL$?$?@@I""$$//11Ja=M!,,,,,a=GGGGGa=M!,,,,,%%U%33>>@@MM))))))r   c                 &      G  fdd          }|S )Nc                       e Zd Z Zded<    e            Zded<    e            Zded<    ed          Z	e	
                    e           e	
                    e           dS )!repr_example.<locals>.ReprExamplevalue1key1VALUE1)r   N)__name__
__module____qualname__r   r   calendarr   eventr   nestedadd_componentr"   s   r   ReprExampler   W  s        	$	&8::# f)))Y'''X&&&&&r   r   rD   )r#   r   s   ` r   repr_exampler   U  s=    	' 	' 	' 	' 	' 	' 	' 	' 	' 	' r   c                 X    t          j        dt          | j                            sJ dS )z"Test correct class representation.z#Component\({u?'KEY1': u?'value1'}\)N)rematchstrr   r   s    r   test_repr_componentr   e  s,    8:C@V<W<WXXXXXXXr   c                 X    t          j        dt          | j                            sJ d S )Nz#VCALENDAR\({u?'KEY1': u?'value1'}\))r   r   r   r   r   s    r   test_repr_calendarr   j  s,    8:C@U<V<VWWWWWWWr   c                 X    t          j        dt          | j                            sJ d S )Nz VEVENT\({u?'KEY1': u?'value1'}\))r   r   r   r   r   s    r   test_repr_eventr   n  s,    87\=O9P9PQQQQQQQr   c                     | j                             | j                   t          | j                   t          j        dt          | j                            sJ dS )z#Representation of nested ComponentszComponent\({u?'KEY1': u?'VALUE1'}, Component\({u?'KEY1': u?'value1'}\), VCALENDAR\({u?'KEY1': u?'value1'}, VEVENT\({u?'KEY1': u?'value1'}\)\)\)N)r   r   r   printr   r   r   r   r   s    r   test_nested_components_2r   r  sj    ''(:;;;	,
8	0 	L        r   c                 b    | d         } |d          }|                                 dk    sJ dS )z)Check the events in the component factoryrL   19700101rS   s,   BEGIN:VEVENT
DTSTART:19700101
END:VEVENT
Nr4   )factoryr   r   s      r   test_component_factory_VEVENTr     s>    !IIj)))E==??SSSSSSSr   c                 Z    |                      d          t          j        j        k    sJ dS )z#Check the VCALENDAR in the factory.rK   N)get	icalendarcalr   )r   s    r    test_component_factory_VCALENDARr     s*    ;;{##y}'=======r   c                  *   t                      } d| d<   d| d<   t                      }d|d<   d|d<   |                    d	t          d
ddddd                     |                     |           | j        d                                         dk    sJ dS )z7Setting up a minimal calendar component looks like thisz -//My calendar product//mxm.dk//r   z2.0r&   z Python meeting about calendaringsummary42uidrT   i        r   se   BEGIN:VEVENT
SUMMARY:Python meeting about calendaring
DTSTART:20050404T080000
UID:42
END:VEVENT
N)r   r   r   r   r   r?   r1   )r   r   s     r   .test_minimal_calendar_component_with_one_eventr     s    
**C 7CMC	N GGE9E)E%L	IIi$1aA66777eQ''))	     r   c                 ~    | j         j        }t          |          dk    sJ t          d |D                       sJ dS )z2Calendar.journals returns all VJOURNAL components.r   c              3   @   K   | ]}t          |t                    V  d S N)r-   r	   )rH   js     r   	<genexpr>z2test_calendar_journals_property.<locals>.<genexpr>  s,      88!z!W%%888888r   N)rfc_7986_imagejournalslenall)	calendarsr   s     r   test_calendar_journals_propertyr     sM    '0Hx==A88x8888888888r   c                 b    d | j                             d          D             }|ddgk    sJ dS )Parsing a complete calendar from a string will silently ignore wrong
    events but adding the error information to the component's 'errors'
    attribute. The error in the following is the third EXDATE: it has an
    empty DATE.
    c                 B    g | ]}|d                                           S )DESCRIPTIONr4   rH   es     r   rJ   zItest_calendar_with_parsing_errors_includes_all_events.<locals>.<listcomp>  s6       '(-  ""  r   rL   s   Perfectly OK events   Wrong eventNparsing_errorrN   )r   event_descriptionss     r   5test_calendar_with_parsing_errors_includes_all_eventsr
    sQ     ,5,C,H,H,R,R   "7!HHHHHHHr   c                 d    d | j                             d          D             }|g dggk    sJ dS )r  c                     g | ]	}|j         
S rD   )errorsr  s     r   rJ   zOtest_calendar_with_parsing_errors_has_an_error_in_one_event.<locals>.<listcomp>  s    GGG1ahGGGr   rL   )EXDATEz)Expected datetime, date, or time. Got: ''Nr  )r   r  s     r   ;test_calendar_with_parsing_errors_has_an_error_in_one_eventr    sI     HG	 7 < <X F FGGGFbRSTTTTTTTr   c                 x    t          j        t                    5  | j         ddd           dS # 1 swxY w Y   dS )z1If components are damaged, we raise an exception.N)pytestraises
ValueErrorparsing_error_in_UTC_offset)r   s    r   test_cal_strict_parsingr    s    	z	"	" . .--. . . . . . . . . . . . . . . . . .s   /33c                 X    | j                                         | j         j        k    sJ dS )zMIf we diable the errors, we should be able to put the calendar back together.N)r  r1   raw_ics)r   vUTCOffset_ignore_exceptionss     r   test_cal_ignore_errors_parsingr    s=     	-557708	9 	9 	9 	9 	9 	9r   )r   other_calendar)%issue_156_RDATE_with_PERIOD_TZID_khal'issue_156_RDATE_with_PERIOD_TZID_khal_2)issue_178_custom_component_contains_other'issue_178_custom_component_inside_otherissue_526_calendar_with_events(issue_526_calendar_with_different_events$issue_526_calendar_with_event_subsetr   )repeatc                 F    | |         | |         k    }||k    }||k    sJ d S r   rD   )r   r   r  r   are_calendars_equalare_calendars_actually_equals         r   test_comparing_calendarsr&    s<      $H->1JJ#+~#= ">>>>>>>r   )r   shuffeled_calendar)r  (issue_526_calendar_with_shuffeled_eventsc                 j    | |         j         | |         j         k    sJ | |         | |         k    sJ d S r   )r?   )r   r   r'  s      r   Ctest_calendars_with_same_subcomponents_in_different_order_are_equalr*    sH     	()Y7I-J-XXXXXX),>"???????r   )@	itertoolsr   r   r   r  r   r   icalendar.cal.calendarr   icalendar.cal.componentr   icalendar.cal.eventr   icalendar.cal.journalr	   icalendar.timezoner
   r   r   r   r$   r'   r/   r2   r7   rA   rO   rU   rd   rh   rj   rn   rs   r|   r   r   r   r   r   r   markparametrize	comp_propr   r   r   r   fixturer   r   r   r   r   r   r   r   r   r
  r  r  r  productr&  r*  rD   r   r   <module>r6     s!       				 ( ( ( ( ( ( ( (            + + + + + + - - - - - - % % % % % % ) ) ) ) ) ) + + + + + +) ) )    <4 4 4> > >
: : :
      R R R
           
 
 
      1 1 16 6 6 3 3 3A A A K##'   	 I I I 6 6 6* * *$* * *"   Y Y Y
X X XR R R
 
 
T T T> > >
  *9 9 9	I 	I 	IU U U. . .   "I	
 	
 	
    ? ? ? &	
 @ @ @ @ @r   