
    i]4                     l   d Z ddlZddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlZddlmZ dd	lmZmZmZmZmZmZmZmZmZmZ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%Z%n# e&$ r dZ%Y nw xY we%duZ'e're%j(         e%j        d          gZ)d gZ*dgZ+ng Z)g Z*g Z+ G d d          Z, e
e-          j.        Z/e/dz  Z0e/dz  Z1e/dz  Z2e/dz  Z3e/dz  Z4e/dz  Z5 ej6        d          d             Z7 ej6        d          d             Z8 ej6        d          d             Z9 ej6        d          d             Z: ej6        d          d              Z; ej6        d          d!             Z< ej6        e) ed          ej=         ej>        d          ej(        gz   "          d#             Z( ej6        e*d$ d% gz   "          d&             Z?d'Z@d(ZAd)  ejB        e0C                                e1C                                e2C                                          D             ZDd*  ejB        e0C                                e1C                                e2C                                          D             ZEd+  ejB        e0C                                e1C                                e2C                                          D             ZFd,efd-ZG ej6        eD"          d,efd.            ZH ej6        eE"          d,efd/            ZI ej6        eF"          d,efd0            ZJd1 e0C                                D             ZK ej6        eK"          d2             ZLej6        d3             ZMej6        d4             ZNej6        d5             ZOej6        d6             ZPej6        d7             ZQej6        d8             ZRej6        d9             ZSeSZTej6        d:             ZUej6        d;             ZVej6        d<             ZWej6        d=             ZX ej6        d          d,ee ddf         fd>            Z! ej6        e+d?gz   "          d@             ZYej6        d,eZfdA            Z[ej6        d,eZfdB            Z\ej6        d,eZfdC            Z]ej6        d,eZfdD            Z^dE Z_ G dF dGe          Z`dH ZadI Zb edJdKdLdMdNdO          Zcecd                    ej(        P          ZedQZfej6        d,eZfdR            Zg ej6        dST          dU             Zhej6        dV             Zi ej6        e$jj        "          dWejk        d,eZfdX            Zl ej6        e"          dY             Zmej6        dZ             Znej6        d,ejo        fd[            Zpej6        d\             ZqdS )]zTest configuration    N)	Generator)datetimetimezone)PathMock)ZoneInfo)tz)AlarmAvailabilityCalendar	ComponentComponentFactoryEventTimezoneTodoTypesFactoryprop
vUTCOffset)PROPERTY_NAMES)TZPtzp   )timezone_idsUTCc                 P    t          j        |                              |           S N)pytzr   localizedttznames     S/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/tests/conftest.py<lambda>r%   /   s    4=0099"==     r   c                   Z    e Zd ZdZddgZdefdZd Zd Zd Z	d	 Z
d
 Zed             ZdS )
DataSourcezFA collection of parsed ICS elements (e.g calendars, timezones, events).ics.jcaldata_source_folderc                 "    || _         || _        d S r   )_parser_data_source_folder)selfr+   parsers      r$   __init__zDataSource.__init__=   s    #5   r&   c                 N      fd j                                         D             S )z(Return all the files that could be used.c                 ^    g | ])}|j                                         j        v "|j        *S  )suffixlower
extensionsstem).0pr/   s     r$   
<listcomp>z#DataSource.keys.<locals>.<listcomp>C   s>     
 
 
x~~4?22 F222r&   )r.   iterdirr/   s   `r$   keyszDataSource.keysA   s=    
 
 
 
-5577
 
 
 	
r&   c                 F   | j         }d|v r|                    dd          \  }}d|z   g}|D ]'}||z   }| j        |z  }|                                r n(|                                s(t	          | dd                    |           d          |dk    r+|                                }t          j        |          }d}n+|	                                }| 
                    |          }d}t          |t                    s||_        ||_        ||_        || j        |<   |S )z;Parse a file and return the result stored in the attribute..r   z' does not exist with these extensions: z, r*   N)r7   rsplitr.   is_fileAttributeErrorjoin	read_textr   	from_jcal
read_bytesr-   
isinstancelistraw_icsraw_jcalsource_file__dict__)	r/   	attributer7   	extensionrL   source_pathrK   sourcerJ   s	            r$   __getitem__zDataSource.__getitem__I   sY   _
)#,#3#3C#;#; Iy	/*J# 	 	I#i/K2[@K""$$ ""$$ 	 ]]TYYzEZEZ]]]   ",,..H(22FGG!,,..G\\'**FH&$'' 	-$FN&FO!,F#)i r&   c                 f    |                     dd          d         }||                                 v S )zkey in self.keys()r@   r   r   )rA   r>   r/   keys     r$   __contains__zDataSource.__contains__i   s-    jja  #diikk!!r&   c                     | |         S r   r4   rT   s     r$   __getattr__zDataSource.__getattr__n   s    Cyr&   c                 *    t          | j                  S r   )reprrM   r=   s    r$   __repr__zDataSource.__repr__q   s    DM"""r&   c                 @                            j         fd          S )z'Return a list of all components parsed.c                 2                         | d          S )NT)multiple)r-   )datar/   s    r$   r%   z%DataSource.multiple.<locals>.<lambda>x   s    4<<t<3T3T r&   )	__class__r.   r=   s   `r$   r^   zDataSource.multiplet   s-     ~~$&T&T&T&T
 
 	
r&   N)__name__
__module____qualname____doc__r7   r   r1   r>   rR   rV   rX   r[   propertyr^   r4   r&   r$   r(   r(   8   s        PP'"J64 6 6 6 6
 
 
  @" " "
  # # # 
 
 X
 
 
r&   r(   	calendars	timezoneseventsalarmsavailabilitiestodosmodulescopec                 @    t          t          t          j                  S r   )r(   CALENDARS_FOLDERr   	from_icalr   s    r$   rf   rf          &(:;;;r&   c                 @    t          t          t          j                  S r   )r(   TIMEZONES_FOLDERr   rq   r   s    r$   rg   rg      rr   r&   c                 @    t          t          t          j                  S r   )r(   EVENTS_FOLDERr   rq   r   s    r$   rh   rh          mU_555r&   c                 @    t          t          t          j                  S r   )r(   ALARMS_FOLDERr   rq   r   s    r$   ri   ri      rw   r&   c                 @    t          t          t          j                  S r   )r(   AVAILABILITIES_FOLDERr   rq   r   s    r$   rj   rj      s    +\-CDDDr&   c                 @    t          t          t          j                  S r   )r(   TODOS_FOLDERr   rq   r   s    r$   rk   rk      s    lDN333r&   )paramsc                     | j         S r   paramrequestr   s     r$   utcr      s     =r&   c                 R    |                      t          j        |                    S Ntzinfo)replacer
   gettzr!   s     r$   r%   r%      s    2::RXf-=-=:>> r&   c                 H    |                      t          |                    S r   )r   r	   r!   s     r$   r%   r%      s    2::Xf-=-=:>> r&   c                     | j         S r   r   r   s     r$   in_timezoner      s     =r&   fuzz_testcase)zbig_bad_calendar.icszissue_104_broken_calendar.icszsmall_bad_calendar.icsz multiple_calendar_components.icszpr_480_summary_with_colon.icszparsing_error_in_UTC_offset.icszparsing_error.icsc                 f    g | ].}|j         t          vr|j        d v rt          |j         v'|j         /S ))r)   r*   nameBROKEN_SOURCE_FILESr5   FUZZ_TESTCASES_BROKEN_CALENDARSr9   files     r$   r;   r;      sQ        y+++((('ty88 	I 	988r&   c                 j    g | ]0}|j         t          vr |j        d k    rt          |j         v)|j         1S )r)   r   r   s     r$   r;   r;      sP        y+++v'ty88 	I 	988r&   c                 j    g | ]0}|j         t          vr |j        d k    rt          |j         v)|j         1S )r*   r   r   s     r$   r;   r;      sP        y+++w'ty88 	I 	988r&   returnc                     |j         }t          d|           | ||fD ]}||v r
||         c S t          d| d          )Nzexample file:zCould not find file r@   )r   print
ValueError)rf   rg   rh   r   rL   r_   s         r$   get_source_filer      sj    -K	/;'''9f, % %$$$$$ 
:K:::
;
;;r&   c                 &    t          ||||          S )zqAn example file.

    source_file.raw_ics - bytes if .ics file
    source_file.raw_jcal - str if .jcal file

    r   r   rf   rg   rh   r   s        r$   rL   rL      s     9iAAAr&   c                 &    t          ||||          S )z[An example .ica file.

    source_file.raw_ics - bytes
    source_file.raw_jcal - None
    r   r   s        r$   ics_filer           9iAAAr&   c                 &    t          ||||          S )zZAn example .jcal file.

    source_file.raw_ics - None
    source_file.raw_jcal - str
    r   r   s        r$   	jcal_filer      r   r&   c                 >    g | ]}t           t          |          v |S r4   )r   str)r9   rU   s     r$   r;   r;     s3       &#c((22 222r&   c                     | j         S )zClusterfuzz calendars.r   r   s    r$   fuzz_v1_calendar_pathr          =r&   c                      t                      S zReturn a new types factory.)r   r4   r&   r$   types_factoryr     s     >>r&   c                      t                      S r   r   r4   r&   r$   component_factoryr          r&   c              #   Z   K   d| j         d<   dV  | j                             d           dS )zMap x_sometime to timetimez
X-SOMETIMEN)	types_mappop)r   s    r$   
x_sometimer   !  s;       -3ML)	EEE-----r&   c                      t                      S )zReturn a new component factory.r   r4   r&   r$   factoryr   )  r   r&   c               #   B   K   dt           _        d V  dt           _        d S )NTF)r   ignore_exceptionsr4   r&   r$   vUTCOffset_ignore_exceptionsr   /  s%      #'J 	EEE#(J   r&   c                 0    t                      }d|_        |S )zReturn an event component.VEVENTr   r   r   cs     r$   event_componentr   6  s     	AAFHr&   c                     t                      S )Return an empty component.)r   r   s    r$   r   r   >  s     ;;r&   c                 0    t                      }d|_        |S )r   	VCALENDARr   r   s     r$   calendar_componentr   G  s     	AAFHr&   c               #   Z   K   t           j        } dt           _        dV  | t           _        dS )z*Remove validation for new() of components.FN)r   _validate_new)values    r$   dont_validate_newr   O  s/       #E#I	EEE#Ir&   c                     t          d          }d|_        |                    ddd           |                    dd	d           |                    |           |S )
zBReturn an event with some values and add it to calendar_component.zA brief history of time)summaryr   dtend20000102T000000r   )encodedtstart20000101T000000)r   r   addadd_component)r   r   es      r$   filled_event_componentr   X  sg     	3444AAFEE'$QE///EE)&qE111$$Q'''Hr&   c                 ,    t                      }d|d<   |S )NzChair, Table, "Room: 42"	resources)r   r   s     r$   calendar_with_resourcesr   c  s    

A/AkNHr&   c              #   j   K   t          j        |            t           V  t          j                     dS )zThe timezone provider.N)_tzpuseuse_defaulttzp_names    r$   r   r   j  s6       	HX
JJJr&   zoneinfoc                 *    t          | j                  S )zThis is annother timezone provider.

    The purpose here is to cross test: pytz <-> zoneinfo.
    tzp as parameter makes sure we test the cross product.
    )r   r   r   s     r$   	other_tzpr   r  s     w}r&   c                 2    |                                  sJ |S )z+Skip tests that are not running under pytz.)	uses_pytz)r   r   s     r$   	pytz_onlyr   |  s     ==??Or&   c                 2    |                                  sJ |S )z/Skip tests that are not running under zoneinfo.)uses_zoneinfo)r   r   r   s      r$   zoneinfo_onlyr     s!     Or&   c                     | dk    sJ | S )zDo not run tests with pytz.r   r4   r   s    r$   no_pytzr     s     vOr&   c                     | dk    sJ | S )zDo not run tests with zoneinfo.r   r4   r   s    r$   no_zoneinfor     s     z!!!!Or&   c                 &   d| j         v rt          dgz   }d| j         v rdg}d| j         v rt          }d| j         v rd| j         v r
J d            dD ]'}d| | j         v r||v r|                    |           (|                     d|d	           d
S d
S )a  Parametrize without skipping:

    tzp_name will be parametrized according to the use of
    - pytz_only
    - zoneinfo_only
    - no_pytz
    - no_zoneinfo

    See https://docs.pytest.org/en/6.2.x/example/parametrize.html#deferring-the-setup-of-parametrized-resources
    r   r   r   r   z,Use pytz_only or zoneinfo_only but not both!)r   r   no_rl   rm   N)fixturenamesPYTZ_TZPremoveparametrize)metafunc	tzp_namesr   s      r$   pytest_generate_testsr     s     X***
|+	h333#I(/// Ix444x44449 544( 	' 	'DT||x4449J9J  &&&Z(CCCCC +*r&   c                       e Zd ZdZd ZdS )DoctestZoneInfoz+Constent ZoneInfo representation for tests.c                     d| j         dS )NzZoneInfo(key=))rU   r=   s    r$   r[   zDoctestZoneInfo.__repr__  s    ,tx,,,,r&   N)ra   rb   rc   rd   r[   r4   r&   r$   r   r     s)        55- - - - -r&   r   c                  D    d | D             } t          d | D               dS )zdoctest printc                 f    g | ].}t          |t                    r|                    d           n|/S )zUTF-8)rH   bytesdecoder9   args     r$   r;   z!doctest_print.<locals>.<listcomp>  s8    SSSs:c5#9#9BCJJwsSSSr&   c              3      K   | ]M}t          |                                                              d d                              dd          V  NdS )z

N)r   stripr   r   s     r$   	<genexpr>z doctest_print.<locals>.<genexpr>  sR      WW3CHHNN$$VT22::4FFWWWWWWr&   N)r   )argss    r$   doctest_printr    s6    SSdSSSD	WWRVWWWXXXXr&   c                 <    | dk    rt           S t          | g|R i |S )zIReplace the import mechanism to skip the whole doctest if we import pytz.r   )r   
__import__)r   r  kws      r$   doctest_importr	    s.    v~~d(T(((R(((r&   i                 r   z$d755cef5-2311-46ed-a0e1-6733c9e15c63c                      t           S )z!The UID that tests always create.)UID_DEFAULTr4   r&   r$   test_uidr    s
     r&   T)autousec                     t          j        t          d          |                     t           dfd           |                     t          dt          d                      dS )zYCreate a fixed test environment for the functions that are time and randomness dependent.   )versionuuid4c                       S r   r4   )uids   r$   r%   zfixed_env.<locals>.<lambda>  s    s r&   _utc_nowc                      t           S r   )NOW_UTCr4   r&   r$   r%   zfixed_env.<locals>.<lambda>  s    G r&   N)uuidUUIDr  setattrr   staticmethod)monkeypatchr  s    @r$   	fixed_envr!    s_     )K
+
+
+Cg{{{{333	:|OO/L/LMMMMMr&   c                     |                      t          j        dt                     |                     t          dt
                     ddlm} |                     |dt          j        d                     dt          iS )z,Modify the environment to make doctests run.r   r	   r   )ZONEINFOr   r   r   )
setitemsysmodulesr   r  r   icalendar.timezone.zoneinfor#  r	   r  )r   r#  s     r$   env_for_doctestr(    sv     Z:::*o>>>444444%):5)A)ABBB]##r&   r   c                     | j         S )zxReturn a timezone id to be used with pytz or zoneinfo.

    This goes through all the different timezones possible.
    r   r   s    r$   tzidr*    s     =r&   c                     | j         S )z@Names of property types that occur as a property of a component.r   r   s    r$   v_prop_namer,    r   r&   c                 ,    t          t          |           S )z7Property types that occur as a property of a component.)getattrr   )r,  s    r$   v_propr/    s     4%%%r&   c                 6    |                                  d         S )Nr   )examples)r/  s    r$   v_prop_exampler2    s    ??Qr&   c                      t                      S )zA mock.r   r4   r&   r$   mockr4    s     66Mr&   )rrd   	itertoolsr%  r  r   collections.abcr   r   r   pathlibr   unittest.mockr   r	   pytestdateutilr
   	icalendarr   r   r   r   r   r   r   r   r   r   r   icalendar.tests.datar   icalendar.timezoner   r   r    r   r   ImportErrorHAS_PYTZr   PYTZ_UTCPYTZ_IN_TIMEZONEr   r(   __file__parentHERErp   rt   rv   ry   r{   r}   fixturerf   rg   rh   ri   rj   rk   r   r   r   r   r   chainr<   SOURCE_FILES	ICS_FILES
JCAL_FILESr   rL   r   r   FUZZ_V1r   r   r   r   r   r   r   r   compr   r   r   r   r   r   r   r   r   r   r   r   r  r	  NOWr   r  r  r  r!  r(  TZIDSFixtureRequestr*  r,  r/  	VPROPERTYr2  r4  r4   r&   r$   <module>rQ     s
         



   % % % % % % ' ' ' ' ' ' ' '                                                   0 / / / / / " " " " " " * * * * * *      KKKK   DDD t eH
 	>= xHHHHA
 A
 A
 A
 A
 A
 A
 A
H tH~~+% +% xx// g~ h< <  < h< <  < h6 6  6 h6 6  6 hE E  E h4 4  4 xxNN     >>>>     #2   	  ""$4$<$<$>$>@U@U@W@W    	  ""$4$<$<$>$>@U@U@W@W   	 	  ""$4$<$<$>$>@U@U@W@W   
<i < < < < |$$$By B B B %$B y!!!BI B B B "!B z"""BY B B B #"B ''))   w   
   
   
 . . .   
 ) ) )      
 	    $ $ $       hYsD$/      x:,.///  0/      S          S    D D D6- - - - -h - - -Y Y Y) ) ) htQAq"%%
++X\+
*
*4 #    
 N N N $ $ $ |)***&' C    +* ~&&&  '&
 & & &
  dn             s   0A5 5A?>A?