
    fD?                        d dl Z d dlmZ d dlmZ d dlZd dlZd dlZd dlmZmZ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$             Z+d% Z,d& Z-d' Z.d( Zd) Z/d* Z0d+ Z1d, Z2d- Z3d. Z4d/ Z5ej#        $                    d0 e j6        g d1d23                    d4             Z7ej#        $                    d5d6g          d7             Z8dS )8    N)datetime)	timedelta)	ComponentCalendarEvent)prop)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    a/var/www/dev/btcams2024/python_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"{+0	2 	2"3 "3 3 3 3 3 3 3r   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    
,
-/ / / 
M222
$5666 
-
.0 0 0 eZ_---..]++.//-..-..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//s   -//my product//N)r   r   vTextdecodedcs    r   test_get_content_directlyr#   ?   s[    EE(%&&&X;$*%677777799X"4444444r   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&   G   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.   L   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_componentr1   Q   s<    :w///%%''+dddddddr   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r0   filled_event_components    r   test_nested_component_event_icsr6   W   s4    !))++	     r   c           	      j    t                               | j        t          dddd          g           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)selfassertEqualsubcomponentsr   r   r5   s     r   test_nested_componentsrB   `   sQ     	(	*7H46 6 
7 
7 	8    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>l   s    666qAF666r   	VCALENDARVEVENTNwalkrA   s     r   #test_walk_filled_calendar_componentrP   j   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 rE   rF   rH   s     r   rK   z$test_filter_walk.<locals>.<listcomp>r   s    >>>qAF>>>r   rM   c                     g | ]
}|d          S dtstartrE   rH   s     r   rK   z$test_filter_walk.<locals>.<listcomp>s   s    DDDQAiLDDDr   r9   NrN   rA   s     r   test_filter_walkrV   o   sl     ?>.33H==>>>8*LLLLDD"4"9"9("C"CDDDIZH[[[[[[[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   rY      VEVENTr;   r8   r<   r9   r=   r:   ENDr\   ra   rZ   N)r   property_itemsr   r   rA   s     r   test_recursive_property_itemsrd   v   ss     :w///,,..	 :t/?/H/H"I	;	'	/1C	3             r   c                 l    |                      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.F	recursiverX   r   r   rb   N)rc   r   r   rA   s     r   test_flat_property_itemsrh      sS    ,,u,==	 
d&w//	0	B             r   c                 B    |                      d          g dk    sJ dS )zFlat enumeration on the event.Frf   )r[   r]   r^   r_   r`   N)rc   r4   s    r   rh   rh      sO    !0050AA FE FE FE E E E E E E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   r0   r!   s    r   test_indentrm      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
Nrl   calendar_with_resourcess    r   test_INLINE_propertiesrr      sU     #h=W/X&Y&YYYYY"**,,	     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_inlinerp   s    r   test_get_inliner{      sA     #--k!-DD&&&' ' ' ' ' 'r   c                 D    |                      dd          g dk    sJ dS )zThese can also be decodedrt      ru   )s   Chairs   Tables   Room: 42Nry   rp   s    r   test_get_inline_decodedr~      s?    "--k!-DD)))* * * * * *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 ...rt   )AListofzsome, recourcesr}   encodezA,List,of,"some, recources"r   ru   N)
set_inlinerz   rp   s    r   test_set_inliner      su    &&{4Z4Z4Z '   ";/3PPPPP"--k!-DDHnHnHnnnnnnnr   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   ru   )z19970308T160000Z/PT3Hz19970308T200000Z/PT1Hz!19970308T230000Z/19970309T000000Zr}   )rz   r,   r   r   )r"   r   s     r   test_inline_free_busy_inliner      s    :AjM<<
1<--	. 	. 	.. . . . ||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.
    rU   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_utcr0   
splitlines)comptzpliness      r   test_cal_Component_addr      s6    	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..r2r1a((* * + + + 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 )z5Already encoded values should not be re-encoded.
    ATTACHmeyouFr   usN)r   r   vBinary)r   binarys     r   "test_cal_Component_add_no_reencoder      su     	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   r0   r   )r   r   s     r   )test_cal_Component_add_property_parameterr      s^     	HH]I"(6::  < < <LLNN%%''E75@@@@@@r   zcomponent_name, property_name))rM   r<   )rM   r;   )rM   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component_nameproperty_namer   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        dk    sJ dS )r   r   r   :r   N)r   r   r   tzinfor   s        r   test_cal_Component_from_ical_2r     sd     ~-4M]S((M,~==M#M22I]#&-5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   joinr0   r   setr   r   
sorted_strpreserved_strs       r   )test_cal_Component_to_ical_property_orderr     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   r0   r   r   s       r   *test_cal_Component_to_ical_parameter_orderr     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   /  s        	$	&8::# f)))Y'''X&&&&&r   r   rE   )r"   r   s   ` r   repr_exampler   -  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   ;  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   @  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   D  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   rB   rB   H  sj    ''(:;;;	,
84 #$$
 
 
 
 
 
 
r   c                 b    | d         } |d          }|                                 dk    sJ dS )z)Check the events in the component factoryrM   19700101rT   s,   BEGIN:VEVENT
DTSTART:19700101
END:VEVENT
Nr3   )factoryr   r   s      r   test_component_factory_VEVENTr   U  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.rL   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uidrU   i        r   se   BEGIN:VEVENT
SUMMARY:Python meeting about calendaring
DTSTART:20050404T080000
UID:42
END:VEVENT
N)r   r   r   r   r   r@   r0   )r   r   s     r   .test_minimal_calendar_component_with_one_eventr   a  s    
**C 7CMC	N GGE9E)E%L	IIi$1aA66777eQ''))	     r   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 )DESCRIPTIONr3   rI   es     r   rK   zItest_calendar_with_parsing_errors_includes_all_events.<locals>.<listcomp>{  s)    eee!M*2244eeer   rM   s   Perfectly OK events   Wrong eventNparsing_errorrO   )	calendarsevent_descriptionss     r   5test_calendar_with_parsing_errors_includes_all_eventsr   u  sH     fei>U>Z>Z[c>d>deee"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 rE   )errorsr   s     r   rK   zOtest_calendar_with_parsing_errors_has_an_error_in_one_event.<locals>.<listcomp>  s    GGG1ahGGGr   rM   )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  r0   raw_ics)r   vUTCOffset_ignore_exceptionss     r   test_cal_ignore_errors_parsingr    s.    088::i>c>kkkkkkkr   zcalendar, 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 NrE   )r   r   other_calendarr   are_calendars_equalare_calendars_actually_equals         r   test_comparing_calendarsr    s<     $H->1JJ#+~#= ">>>>>>>r   zcalendar, shuffeled_calendar)r  (issue_526_calendar_with_shuffeled_eventsc                 j    | |         j         | |         j         k    rJ | |         | |         k    sJ d S r  )r@   )r   r   shuffeled_calendars      r   Ctest_calendars_with_same_subcomponents_in_different_order_are_equalr    sH     "0I>P4Q4_____X),>"???????r   )9	itertoolsr   r   r  r   r   icalendar.calr   r   r   r   icalendar.propr	   r   r   r   r#   r&   r.   r1   r6   rB   rP   rV   rd   rh   rm   rr   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  productr  r  rE   r   r   <module>r(     s                        				 4 4 4 4 4 4 4 4 4 4       ' ' ' ' ' ') ) )3 3 3  85 5 5> > >
: : :
e e e    R R R
\ \ \	  	  	      E E E    ' ' '* * *o o o	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> > >
  (I I IU U U. . .l l l I       ? ? ? 7:  @ @ @ @ @r   