U
    j)                    @  s  d 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	 ddl
mZmZmZmZmZmZ ddlZddl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#m$Z$ dd
l%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9m:Z: er:ddl;m<Z< ddddddZ=G dd de!Z>e!ddddZ?g Z@G dd de!ZAe1fddddddddd ZBed!d"ZCed#d$ZDdd%d&d'd(ZEdd%d)d*d+ZFdd,d-d.ZGd/ZHG d0d1 d1eAZIG d2d3 d3eAZJG d4d5 d5eAZKG d6d7 d7eAZLG d8d9 d9eAZMG d:d; d;eAZNG d<d= d=eAZOG d>d? d?eAZPG d@dA dAeAZQe. ZRe> ZSdBd?dAddd1d7dCd5d9d=d;d3dDdgZTdS )EzCalendar is a dictionary like Python object that can render itself as VCAL
files according to RFC 5545.

These are the defined components.
    )annotationsN)defaultdict)datedatetime	timedeltatzinfo)TYPE_CHECKINGList
NamedTupleOptionalTupleUnion)categories_propertycolor_propertyexdates_propertymulti_language_text_propertyrdates_propertyrrules_propertysequence_propertysingle_int_propertysingle_string_propertysingle_utc_propertyuid_property)CaselessDict)IncompleteComponentInvalidCalendar)ContentlineContentlines
Parametersq_joinq_split)DEFAULT_ENCODING)TypesFactorytzid_from_tzinfo	vDDDLists	vDDDTypes	vDurationvText
vUTCOffset)TZPtzp)is_dateto_datetimeAlarmsstrbytes)component_directoryexample_namereturnc                 C  s   t jt}t j|d| }|ds.|d }t j||}t j|sntd| d|  ddt | t	|d}|
 W  5 Q R  S Q R X dS )	z5Return an example and raise an error if it is absent.testsz.icszExample z for z not found. You can use one of , rbN)ospathdirname__file__joinendswithisfile
ValueErrorlistdiropenread)r1   r2   hereZexamplesZexample_filef rD   1/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/cal.pyget_example2   s    
 rF   c                      s    e Zd ZdZ fddZ  ZS )ComponentFactoryz~All components defined in RFC 5545 are registered in this factory class.
    To get a component you can use it like this.
    c                   sZ   t  j|| t| d< t| d< t| d< t| d< t| d< t| d< t| d< t	| d< t
| d	< d
S )#Set keys to upper for initial dict.VEVENTVTODOVJOURNAL	VFREEBUSY	VTIMEZONESTANDARDDAYLIGHTVALARM	VCALENDARN)super__init__EventTodoJournalFreeBusyTimezoneTimezoneStandardTimezoneDaylightAlarmCalendarselfargskwargs	__class__rD   rE   rS   J   s    zComponentFactory.__init__)__name__
__module____qualname____doc__rS   __classcell__rD   rD   ra   rE   rG   E   s   rG      )
CATEGORIES	RESOURCESFREEBUSYc                      s>  e Zd ZdZdZdZdZdZdZdZ	dZ
 fddZdd ZeZd	d
 Zed=ddZd>ddZdd ZefddZd?ddZd@ddZd dddZdd Zddd fdd d!d"ZdAd$d d%d&ZedBd'd(ZedCd*d+ZdDd,d-ZdEd.d/ZdFd0d1Z d2d3 Z! fd4d5Z"e#d6d7Z$e#d8d9Z%d:d d;d<Z&  Z'S )G	ComponentzComponent is the base object for calendar, Event and the other
    components defined in RFC 5545. Normally you will not use this class
    directly, but rather one of the subclasses.
    NrD   Fc                   s   t  j|| g | _g | _dS )rH   N)rR   rS   subcomponentserrorsr]   ra   rD   rE   rS   x   s    zComponent.__init__c                 C  s   dS )zAReturns True, CaselessDict would return False if it had no items.TrD   r^   rD   rD   rE   __bool__   s    zComponent.__bool__c                 C  s   t |  | j sdS dS )zDReturns True if Component has no items or subcomponents, else False.TF)listvaluesrm   ro   rD   rD   rE   is_empty   s    zComponent.is_emptyrh   c                 C  s~   |s|S t |tjr|}nt| }||}|rzt|dsBt |_| D ].\}}|dkrn||jkrx|j|= qJ||j|< qJ|S )a  Encode values to icalendar property values.

        :param name: Name of the property.
        :type name: string

        :param value: Value of the property. Either of a basic Python type of
                      any of the icalendar's own property types.
        :type value: Python native type or icalendar property type.

        :param parameters: Property parameter dictionary for the value. Only
                           available, if encode is set to True.
        :type parameters: Dictionary

        :param encode: True, if the value should be encoded to one of
                       icalendar's own property types (Fallback is "vText")
                       or False, if not.
        :type encode: Boolean

        :returns: icalendar property value
        paramsN)
isinstancetypes_factoryZ	all_typesfor_propertyhasattrr   rt   items)namevalue
parametersencodeobjklasskeyitemrD   rD   rE   _encode   s    



zComponent._encodec                   s   t |tr  dkr t|} rTt |trT dkrT fdd|D }n| }kr }t |trt |tr|| }q|| |}n||g}|< dS )a  Add a property.

        :param name: Name of the property.
        :type name: string

        :param value: Value of the property. Either of a basic Python type of
                      any of the icalendar's own property types.
        :type value: Python native type or icalendar property type.

        :param parameters: Property parameter dictionary for the value. Only
                           available, if encode is set to True.
        :type parameters: Dictionary

        :param encode: True, if the value should be encoded to one of
                       icalendar's own property types (Fallback is "vText")
                       or False, if not.
        :type encode: Boolean

        :returns: None
        )Zdtstampcreatedzlast-modified)ZrdateZexdate
categoriesc                   s   g | ]} | qS rD   r   .0vr}   rz   r|   r^   rD   rE   
<listcomp>   s     z!Component.add.<locals>.<listcomp>N)ru   r   lowerr*   Zlocalize_utcrq   r   append)r^   rz   r{   r|   r}   ZoldvalrD   r   rE   add   s&    





zComponent.addc                 C  s2   t |tr|S t||}t |tr.|t}|S )z&Internal for decoding property values.)ru   r$   rv   	from_icalr'   r}   r!   )r^   rz   r{   decodedrD   rD   rE   _decode   s    


zComponent._decodec                   sT    kr:  }t |tr. fdd|D S  |S |tkrLt n|S dS )z"Returns decoded value of property.c                   s   g | ]}  |qS rD   r   r   rz   r^   rD   rE   r     s     z%Component.decoded.<locals>.<listcomp>N)ru   rq   r   _markerKeyError)r^   rz   defaultr{   rD   r   rE   r   	  s    

zComponent.decodedc                   s2   dd t   D }|r. fdd|D S |S )z*Returns a list of values (split on comma).c                 S  s   g | ]}| d qS )z" )stripr   rD   rD   rE   r     s     z(Component.get_inline.<locals>.<listcomp>c                   s   g | ]}  |qS rD   r   r   valr   rD   rE   r   !  s     )r    )r^   rz   decodevalsrD   r   rE   
get_inline  s    zComponent.get_inlinec                   s0   |r fdd|D }t d t| < dS )z^Converts a list of values into comma separated string and sets value
        to that.
        c                   s   g | ]}j  |d dqS )rh   r}   r   )r   r{   r   rD   rE   r   )  s     z(Component.set_inline.<locals>.<listcomp>inlineN)rv   r   )r^   rz   rr   r}   rD   r   rE   
set_inline$  s    zComponent.set_inline	componentc                 C  s   | j | dS )z%Add a subcomponent to this component.N)rm   r   )r^   r   rD   rD   rE   add_component/  s    zComponent.add_componentc                 C  sH   g }|dks| j |kr(|| r(||  | jD ]}||||7 }q.|S )zWalk to given component.N)rz   r   rm   _walk)r^   rz   selectresultsubcomponentrD   rD   rE   r   3  s    

zComponent._walkc                 C  s   dS )NTrD   )crD   rD   rE   <lambda><      zComponent.<lambda>zlist[Component]r3   c                 C  s   |dk	r|  }| ||S )a  Recursively traverses component and subcomponents. Returns sequence
        of same. If name is passed, only components with name will be returned.

        :param name: The name of the component or None such as ``VEVENT``.
        :param select: A function that takes the component as first argument
          and returns True/False.
        :returns: A list of components that match.
        :rtype: list[Component]
        N)upperr   )r^   rz   r   rD   rD   rE   walk<  s    
zComponent.walkTzlist[tuple[str, object]]c           
      C  s   t d }d|| j fg}|r*|  }n|  }|D ]>}| | }t|trf|D ]}|||f qPq6|||f q6|r| jD ]}	||	j	|d7 }q|d|| j f |S )z`Returns properties in this component and subcomponents as:
        [(name, value), ...]
        textBEGINsortedEND)
rv   rz   to_icalZsorted_keyskeysru   rq   r   rm   property_items)
r^   	recursiver   r'   Z
propertiesZproperty_namesrz   rr   r{   r   rD   rD   rE   r   M  s     


zComponent.property_itemsc                   s  g }g }t |D ]T}|sqz| \}}W nZ tk
r } z<|rN|d nd}	|	r\|	js^ |	jdt|f W Y qW 5 d}~X Y nX | }
|
dkr| }t	
|t}| }	t|	dds||	_||	 q|
dkr2|std| }	|s||	 n|d |	 |dkrhd	|	krht|	 qt| |rJ|d nd}	|	sv|
d
krf qjntd| dd}z|dkr|d}d	kr fdd|D }n fdd|D }n<||krd	kr  |d	 g}n  |g}W nB tk
rD } z"|	js  |	j|
t|f W 5 d}~X Y qX |D ]}|_|	j||dd qJq|rt|S t|dkrt| d|t|dk rt| d||d S )z2Populates the component recursively from a string.Nr   rz    r   z.END encountered without an accompanying BEGIN!rM   TZIDz	X-COMMENTz
Property "z#" does not have a parent component.)DTSTARTDTENDRECURRENCE-IDDUERDATEEXDATErk   ,c                   s    g | ]}   |d  qS r   r   r   factoryrt   rD   rE   r     s   z'Component.from_ical.<locals>.<listcomp>c                   s   g | ]}   |qS rD   r   r   )r   rD   rE   r     s    r   r   rh   3Found multiple components where only one is allowed1Found no components where exactly one is required)r   r   partsr>   ignore_exceptionsrn   r   r/   r   component_factorygetrl   getattrrz   popr   r*   Zcache_timezone_componentrv   rw   splitrt   r   len_format_error)clsstmultiplestackcompslinerz   r   er   unameZc_nameZc_classZdatetime_namesZparsed_componentsZparsed_componentrD   r   rE   r   g  s    








&  zComponent.from_ical[...]c                 C  sb   d}t | t | t | |krP|t |  t | }|  d|d |  d| S |  d| S d S )Na   z:  )r   )Zerror_descriptionZ	bad_inputZelipsisZmax_error_lengthZtruncate_torD   rD   rE   r     s
    zComponent._format_errorc                 C  s    t |dt }tj||||dS )z!Returns property as content line.rt   r   )r   r   r   Z
from_parts)r^   rz   r{   r   rt   rD   rD   rE   content_line  s    zComponent.content_linec                 C  sD   t  }| j|dD ]"\}}| j|||d}|| q|d |S )z<Converts the Component and subcomponents into content lines.r   r   )r   r   r   r   )r^   r   Zcontentlinesrz   r{   ZclrD   rD   rE   content_lines  s    
zComponent.content_linesc                 C  s   | j |d}| S )z}
        :param sorted: Whether parameters and properties should be
                       lexicographically sorted.
        r   )r   r   )r^   r   r   rD   rD   rE   r     s    zComponent.to_icalc                 C  sF   d dd | jD }| jp$t| j dt|  |r<d| nd dS )z>String representation of class with all of it's subcomponents.r5   c                 s  s   | ]}t |V  qd S N)r/   )r   itrD   rD   rE   	<genexpr>  s     z%Component.__repr__.<locals>.<genexpr>(r   ))r;   rm   rz   typerc   dict)r^   subsrD   rD   rE   __repr__  s    zComponent.__repr__c                   sL   t | jt |jkrdS t |}|s,dS | jD ]}||jkr2 dS q2dS )NFT)r   rm   rR   __eq__)r^   otherZproperties_equalr   ra   rD   rE   r      s    

zComponent.__eq__DTSTAMPa@  RFC 5545:

        Conformance:  This property MUST be included in the "VEVENT",
        "VTODO", "VJOURNAL", or "VFREEBUSY" calendar components.

        Description: In the case of an iCalendar object that specifies a
        "METHOD" property, this property specifies the date and time that
        the instance of the iCalendar object was created.  In the case of
        an iCalendar object that doesn't specify a "METHOD" property, this
        property specifies the date and time that the information
        associated with the calendar component was last revised in the
        calendar store.

        The value MUST be specified in the UTC time format.

        In the case of an iCalendar object that doesn't specify a "METHOD"
        property, this property is equivalent to the "LAST-MODIFIED"
        property.
    LAST-MODIFIEDa  RFC 5545:

        Purpose:  This property specifies the date and time that the
        information associated with the calendar component was last
        revised in the calendar store.

        Note: This is analogous to the modification date and time for a
        file in the file system.

        Conformance:  This property can be specified in the "VEVENT",
        "VTODO", "VJOURNAL", or "VTIMEZONE" calendar components.
    boolc                 C  s   t dd |  D S )zXWhether this component has attributes that indicate that Mozilla Thunderbird created it.c                 s  s   | ]}| d V  qdS )zX-MOZ-N)
startswith)r   attrrD   rD   rE   r   ;  s     z+Component.is_thunderbird.<locals>.<genexpr>)anyr   ro   rD   rD   rE   is_thunderbird9  s    zComponent.is_thunderbird)Nrh   )Nrh   )rh   )rh   )TT)F)r   )T)T)T)(rc   rd   re   rf   rz   required
singletonsr   	exclusive	inclusiver   rS   rp   __nonzero__rs   staticmethodr   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   ZLAST_MODIFIEDr   rg   rD   rD   ra   rE   rl   e   sR   (
7

	r	

	
	rl   Optional[str]ztuple[type]r   )prop
value_attr
value_typetype_defdocvPropc           	   	     s   ddfdd}ddd fdd}t |  |jd	< |jd
< ddfdd d d| dddd D  d}t|| |S )aw  Create a single property getter and setter.

    :param prop: The name of the property.
    :param value_attr: The name of the attribute to get the value from.
    :param value_type: The type of the value.
    :param type_def: The type of the property.
    :param doc: The docstring of the property.
    :param vProp: The type of the property from :mod:`icalendar.prop`.
    rl   ro   c                   s   t  }|  |}||krd S t|tr8td  dd krD|n
t||}t|st  dddd D  d| d|S )	Nz	Multiple z	 defined.z must be either a  or c                 s  s   | ]}|j V  qd S r   rc   r   trD   rD   rE   r   ^  s     z8create_single_property.<locals>.p_get.<locals>.<genexpr>, not .)objectr   ru   rq   r   r   r;   )r^   r   r   r{   )r   r   r   rD   rE   p_getT  s    

$z%create_single_property.<locals>.p_getNoner^   r3   c                   s   |d kr |  d S t |sJtdddd D  dt|j d|| < | jkr| jD ]}|krf| |d  qfd S )NzUse r   c                 s  s   | ]}|j V  qd S r   r   r   rD   rD   rE   r   h  s     z8create_single_property.<locals>.p_set.<locals>.<genexpr>r   r   )ru   	TypeErrorr;   r   rc   r   r   )r^   r{   Z
other_prop)p_delr   r   r   rD   rE   p_setb  s    
&

z%create_single_property.<locals>.p_setr{   r3   c                   s   |    d S r   r   ro   )r   rD   rE   r  t  s    z%create_single_property.<locals>.p_delzThe z property.

    z

    Accepted values: r5   c                 s  s   | ]}|j V  qd S r   r   r   rD   rD   rE   r   {  s     z)create_single_property.<locals>.<genexpr>z.
    If the attribute has invalid values, we raise InvalidCalendar.
    If the value is absent, we return None.
    You can also delete the value with del or by setting it to None.
    )r   __annotations__r;   property)	r   r   r   r   r   r   r  r  Zp_docrD   )r  r   r   r   r   rE   create_single_propertyB  s    	r  zX-MOZ-SNOOZE-TIMEz1Thunderbird: Alarms before this time are snoozed.zX-MOZ-LASTACKz6Thunderbird: Alarms before this time are acknowledged.zOptional[timedelta]r  c                 C  s^   t  }| d|}t|tr"|jS t|tr2|jS ||k	rZt|tsZtdt	|j
 ddS )zGetter for property DURATION.durationz"DURATION must be a timedelta, not r   N)r  r   ru   r%   dtr&   tdr   r   r   rc   )r^   r   r  rD   rD   rE   _get_duration  s    

r  r^   r{   c                 C  s\   |dkr|  dd dS t|ts8tdt|j dt|| d< |  d |  d dS )zSetter for property DURATION.Nr  zUse timedelta, not r   r   r   )r   ru   r   r  r   rc   r&   r  rD   rD   rE   _set_duration  s    

r  ro   c                 C  s   |  d dS )zDelete property DURATION.DURATIONNr  ro   rD   rD   rE   _del_duration  s    r  a  The DURATION property.

The "DTSTART" property for a "{component}" specifies the inclusive start of the event.
The "DURATION" property in conjunction with the DTSTART property
for a "{component}" calendar component specifies the non-inclusive end
of the event.

If you would like to calculate the duration of a {component}, do not use this.
Instead use the duration property (lower case).
c                   @  s  e Zd ZdZdZdZdZdZdZdZ	dZ
ed	d
ddZed)dd dddZeddeefedZeddeefedZdd ZeeeeejddZedd
ddZedd
ddZejd d!d"dZedd
d#d$Zejd%d&d'd$ZeZ e!Z"e#Z$e%Z&e'Z(e)Z*e+Z,e-Z.e/Z0d(S )*rT   a  
    A "VEVENT" calendar component is a grouping of component
    properties that represents a scheduled amount of time on a
    calendar. For example, it can be an activity, such as a one-hour
    long department meeting from 8:00 AM to 9:00 AM, tomorrow.
    rI   )SUMMARYr   r   r  r   UIDr   SEQUENCERRULEr   r   r  r   )CLASSCREATEDCOLORDESCRIPTIONr   GEOr   LOCATION	ORGANIZERPRIORITYr   r  STATUSr  ZTRANSPURLr   r   r  r  )r   r  ATTACHATTENDEEri   COMMENTCONTACTr   RSTATUSRELATEDrj   r   r  Tr.   r   c                 C  s   ddl m} || S )aQ  Compute the alarm times for this component.

        >>> from icalendar import Event
        >>> event = Event.example("rfc_9074_example_1")
        >>> len(event.alarms.times)
        1
        >>> alarm_time = event.alarms.times[0]
        >>> alarm_time.trigger  # The time when the alarm pops up
        datetime.datetime(2021, 3, 2, 10, 15, tzinfo=ZoneInfo(key='America/New_York'))
        >>> alarm_time.is_active()  # This alarm has not been acknowledged
        True

        Note that this only uses DTSTART and DTEND, but ignores
        RDATE, EXDATE, and RRULE properties.
        r   r-   icalendar.alarmsr.   r^   r.   rD   rD   rE   alarms  s    zEvent.alarmsrfc_9074_example_3r/   rz   r3   c                 C  s   |  td|S )0Return the calendar example with the given name.eventsr   rF   r   rz   rD   rD   rE   example  s    zEvent.exampler   r  zQThe "DTSTART" property for a "VEVENT" specifies the inclusive start of the event.r   zdThe "DTEND" property for a "VEVENT" calendar component specifies the non-inclusive end of the event.c                 C  s   | j }| j}| j}|dk	r*|dk	r*tdt|trXt|tsX|dk	rX|jdkrXtd|dk	r|dk	rt|t|krtd|||fS )=Verify the calendar validity and return the right attributes.Nz<Only one of DTEND and DURATION may be in a VEVENT, not both.r   :When DTSTART is a date, DURATION must be of days or weeks.zDDTSTART and DTEND must be of the same type, either date or datetime.)	r   r   r  r   ru   r   r   secondsr+   r^   startendr  rD   rD   rE   _get_start_end_duration%  s.     zEvent._get_start_end_durationr   r   c                 C  s   | j | j S )zThe duration of the VEVENT.

        This duration is calculated from the start and end of the event.
        You cannot set the duration as it is unclear what happens to start and end.
        r:  r9  ro   rD   rD   rE   r  D  s    zEvent.durationdate | datetimec                 C  s    |   d }|dkrtd|S )a  The start of the component.

        Invalid values raise an InvalidCalendar.
        If there is no start, we also raise an IncompleteComponent error.

        You can get the start, end and duration of an event as follows:

        >>> from datetime import datetime
        >>> from icalendar import Event
        >>> event = Event()
        >>> event.start = datetime(2021, 1, 1, 12)
        >>> event.end = datetime(2021, 1, 1, 12, 30) # 30 minutes
        >>> event.duration  # 1800 seconds == 30 minutes
        datetime.timedelta(seconds=1800)
        >>> print(event.to_ical())
        BEGIN:VEVENT
        DTSTART:20210101T120000
        DTEND:20210101T123000
        END:VEVENT
        r   NNo DTSTART given.r;  r   r^   r9  rD   rD   rE   r9  M  s    zEvent.startOptional[date | datetime]r9  c                 C  s
   || _ dS zSet the start.Nr   r@  rD   rD   rE   r9  h  s    c                 C  sl   |   \}}}|dkrH|dkrH|dkr.tdt|rD|tdd S |S |dk	rh|dk	r`|| S td|S )The end of the component.

        Invalid values raise an InvalidCalendar error.
        If there is no end, we also raise an IncompleteComponent error.
        Nz#No DTEND or DURATION+DTSTART given.rh   daysr;  r   r+   r   r8  rD   rD   rE   r:  m  s    z	Event.enddate | datetime | Noner:  c                 C  s
   || _ dS zSet the end.N)r   r^   r:  rD   rD   rE   r:    s    N)r.  )1rc   rd   re   rf   rz   canonical_orderr   r   r   r   r   r
  r-  r   r4  r  r   r   r   r   r;  r  r  r  _doc_durationformatr  r  r9  setterr:  _X_MOZ_SNOOZE_TIMEX_MOZ_SNOOZE_TIME_X_MOZ_LASTACKX_MOZ_LASTACKr   colorr   sequencer   r   r   rdatesr   exdatesr   rrulesr   uidrD   rD   rD   rE   rT     sh   
rT   c                   @  s   e Zd ZdZdZdZdZdZdZe	dde
efed	Ze	d
de
efedZeeeeejddZdd ZeddddZejddddZeddddZejddddZeddddZeZeZedddd ZeZ e!Z"e#Z$e%Z&e'Z(e)Z*e+Z,d!S )"rU   a-  
    A "VTODO" calendar component is a grouping of component
    properties that represents an action item or assignment. For
    example, it can be used to represent an item of work assigned to
    an individual, such as "Prepare for the upcoming conference
    seminar on Internet Calendaring".
    rJ   r  )r  r  Z	COMPLETEDr  r  r   r   r  r   r  r  zPERCENT-COMPLETEr   r   r  r!  r  r  r"  r   r  )r   r  r#  r   r  zOThe "DTSTART" property for a "VTODO" specifies the inclusive start of the Todo.r   z`The "DUE" property for a "VTODO" calendar component specifies the non-inclusive end of the Todo.r   c                 C  s   | j }| j}| j}|dk	r*|dk	r*tdt|trXt|tsX|dk	rX|jdkrXtd|dk	r|dk	rt|t|krtd|||fS )r5  Nz9Only one of DUE and DURATION may be in a VTODO, not both.r   r6  zBDTSTART and DUE must be of the same type, either date or datetime.)	r   r   r  r   ru   r   r   r7  r+   r8  rD   rD   rE   r;    s.     zTodo._get_start_end_durationr=  r   c                 C  s    |   d }|dkrtd|S )a  The start of the VTODO.

        Invalid values raise an InvalidCalendar.
        If there is no start, we also raise an IncompleteComponent error.

        You can get the start, end and duration of a Todo as follows:

        >>> from datetime import datetime
        >>> from icalendar import Todo
        >>> todo = Todo()
        >>> todo.start = datetime(2021, 1, 1, 12)
        >>> todo.end = datetime(2021, 1, 1, 12, 30) # 30 minutes
        >>> todo.duration  # 1800 seconds == 30 minutes
        datetime.timedelta(seconds=1800)
        >>> print(todo.to_ical())
        BEGIN:VTODO
        DTSTART:20210101T120000
        DUE:20210101T123000
        END:VTODO
        r   Nr>  r?  r@  rD   rD   rE   r9    s    z
Todo.startrA  rB  c                 C  s
   || _ dS rC  rD  r@  rD   rD   rE   r9    s    c                 C  sl   |   \}}}|dkrH|dkrH|dkr.tdt|rD|tdd S |S |dk	rh|dk	r`|| S td|S )rE  Nz!No DUE or DURATION+DTSTART given.rh   rF  rH  r8  rD   rD   rE   r:    s    zTodo.endrI  rJ  c                 C  s
   || _ dS rK  )r   rL  rD   rD   rE   r:  )  s    r   c                 C  s   | j | j S )zThe duration of the VTODO.

        This duration is calculated from the start and end of the Todo.
        You cannot set the duration as it is unclear what happens to start and end.
        r<  ro   rD   rD   rE   r  .  s    zTodo.durationr.   c                 C  s   ddl m} || S )a  Compute the alarm times for this component.

        >>> from datetime import datetime
        >>> from icalendar import Todo
        >>> todo = Todo()  # empty without alarms
        >>> todo.start = datetime(2024, 10, 26, 10, 21)
        >>> len(todo.alarms.times)
        0

        Note that this only uses DTSTART and DUE, but ignores
        RDATE, EXDATE, and RRULE properties.
        r   r-   r*  r,  rD   rD   rE   r-  :  s    zTodo.alarmsN)-rc   rd   re   rf   rz   r   r   r   r   r  r   r   r   r   r
  r  r  r  rN  rO  r  r;  r9  rP  r:  r  rQ  rR  rS  rT  r-  r   rU  r   rV  r   r   r   rW  r   rX  r   rY  r   rZ  rD   rD   rD   rE   rU     s`   
rU   c                   @  s   e Zd ZdZdZdZdZdZedde	e
fe
dZed	d
ddZejdddddZeZedd
ddZeZeZeZeZeZeZeZdS )rV   a  A descriptive text at a certain time or associated with a component.

    A "VJOURNAL" calendar component is a grouping of
    component properties that represent one or more descriptive text
    notes associated with a particular calendar date.  The "DTSTART"
    property is used to specify the calendar date with which the
    journal entry is associated.  Generally, it will have a DATE value
    data type, but it can also be used to specify a DATE-TIME value
    data type.  Examples of a journal entry include a daily record of
    a legislative body or a journal entry of individual telephone
    contacts for the day or an ordered list of accomplishments for the
    day.
    rK   r  )r  r  r  r   r   r   r  r   r  r!  r  r  r"  )r$  r%  ri   r&  r'  r   r)  r   r  r(  r  r   r  zjThe "DTSTART" property for a "VJOURNAL" that specifies the exact date at which the journal entry was made.r   r   c                 C  s   | j }|dkrtd|S )zThe start of the Journal.

        The "DTSTART"
        property is used to specify the calendar date with which the
        journal entry is associated.
        Nr>  )r   r   r@  rD   rD   rE   r9    s    zJournal.startzdatetime | dater  )r{   r3   c                 C  s
   || _ dS )zSet the start of the journal.NrD  r  rD   rD   rE   r9    s    r   c                 C  s   t dS )z*The journal has no duration: timedelta(0).r   r   ro   rD   rD   rE   r    s    zJournal.durationN)rc   rd   re   rf   rz   r   r   r   r  r   r   r   r
  r9  rP  r:  r  r   rU  r   rV  r   r   r   rW  r   rX  r   rY  r   rZ  rD   rD   rD   rE   rV   U  s4   rV   c                   @  s$   e Zd ZdZdZdZdZdZeZ	dS )rW   a  
    A "VFREEBUSY" calendar component is a grouping of component
    properties that represents either a request for free or busy time
    information, a reply to a request for free or busy time
    information, or a published set of busy time information.
    rL   r  )r'  r   r   r   r  r  r"  )r%  r&  rk   r(  N)
rc   rd   re   rf   rz   r   r   r   r   rZ  rD   rD   rD   rE   rW     s   	rW   c                   @  sh  e Zd ZU dZded< dZdZdZdZe	dddZ
e	d	ddZed;dddddZedddddZedd ZedfdddddZeddddZddd d!Zd"d# d$D ed%d&edd&ed'd(ed)d(edd(ed'd*ed)d*edd*g Zed+e
efd,d-d.d.d d/d0d1Zeee
efddd.d.d d2d3d4Zed5dd6d7Zed8dd9d:Zd+S )<rX   z
    A "VTIMEZONE" calendar component is a grouping of component
    properties that defines a time zone. It is used to describe the
    way in which a time zone changes its offset from UTC over time.
    z)list[TimezoneStandard | TimezoneDaylight]rm   rM   r   )r   r   ZTZURLi  rh   i  pacific_fijir/   r\   r/  c                 C  s   |  td|S )z0Return the timezone example with the given name.	timezonesr2  r3  rD   rD   rE   r4    s    zTimezone.examplez#TimezoneDaylight | TimezoneStandard)r   tznamec                   sH  | j  | j| j}tjd d d }tj|dt jd d d }t j|d d| krtj	d }|j
|d}| d  d}tjj||d}t|| d  d	d
 |D }	nFd| krt| d ts| d g}
n| d }
|gdd
 |
D  }	n|g}	 fdd
t|	D }| jdkr0d}n| jdkr@d}||fS )zextract offsets and transition times from a VTIMEZONE component
        :param component: a STANDARD or DAYLIGHT component
        :param tzname: the name of the zone
           <   )rG  r7  r  z(offsetfrom)r   utf-8)dtstartc                 S  s   g | ]}|j d dqS )Nra  )replace)r   r  rD   rD   rE   r     s     z-Timezone._extract_offsets.<locals>.<listcomp>r   c                 S  s   g | ]}|j D ]
}|jqqS rD   )Zdtsr  )r   treeZleafrD   rD   rE   r     s       c                   s   g | ]}| fqS rD   rD   )r   	transtimeZ
offsetfromZoffsettor^  rD   rE   r     s    rN   r   rO   rh   )TZOFFSETFROM
TZOFFSETTOr   intr7  r   rG  dateutiltztzoffsetrd  r   r   rrulerrulestrr*   Zfix_rrule_untilru   rq   setrz   )r   r^  rc  Z
offsetto_sZoffsetfrom_sZtziZrrstartro  rn  Z
transtimesrW  transitionsZis_dstrD   rg  rE   _extract_offsets  s8    zTimezone._extract_offsetsc                 C  s    | |kr| d7 } q | |  | S )zW
        :param tzname: Candidate tzname
        :param tznames: Other tznames
        Z_1)r   )r^  tznamesrD   rD   rE   _make_unique_tzname!  s    

zTimezone._make_unique_tznameTr)   r   )r*   lookup_tzidc                 C  s&   |r| | j}|dk	r|S || S )a  convert this VTIMEZONE component to a timezone object

        :param tzp: timezone provider to use
        :param lookup_tzid: whether to use the TZID property to look up existing
                            timezone definitions with tzp.
                            If it is False, a new timezone will be created.
                            If it is True, the existing timezone will be used
                            if it exists, otherwise a new timezone will be created.
        N)timezonetz_nameZcreate_timezone)r^   r*   ru  rl  rD   rD   rE   to_tz-  s
    
zTimezone.to_tzr   c                 C  s8   zt | d W S  tk
r2   | d dd Y S X dS )zReturn the name of the timezone component.

        Please note that the names of the timezone are different from this name
        and may change with winter/summer time.
        r   asciird  N)r/   UnicodeEncodeErrorr}   ro   rD   rD   rE   rw  =  s    zTimezone.tz_namez=Tuple[List[datetime], List[Tuple[timedelta, timedelta, str]]]c              	   C  s   | j }g }i }t }|  D ]}t|tkr0qt|d jrNt|d j|_t	|d jt
sftdzt|d }W n tk
r   |d dd}| ||}Y n` tk
r   | d|d  d d|d   d |d	    }| ||}Y nX | ||\||< }|| q|  d
d |D }g }	t|D ]\}
\}}}}d}|| srtdd}nt|
d ddD ].}||| d  s||| d  } qq|st|
t|D ].}||| d  s||| d  } qq|dk	st|	|||f qH||	fS )zReturn a tuple of (transition_times, transition_info)

        - transition_times = [datetime, ...]
        - transition_info = [(TZOFFSETTO, dts_offset, tzname)]

        r   zEVTIMEZONEs sub-components' DTSTART must be of type datetime, not dateTZNAMEry  rd  _rb  rh  ri  c                 S  s   g | ]\}}}}|| qS rD   rD   )r   rf  osfromr|  rD   rD   rE   r   r  s   
 z,Timezone.get_transitions.<locals>.<listcomp>Fr   r7  rh   r         )rw  rp  r   r   rX   r+   r  r,   r   ru   r   AssertionErrorr/   rz  r}   rt  r   r   r   rr  extendsort	enumerater   ranger   r   )r^   zonerq  dstrs  r   r^  Zcomponent_transitionsZtransition_timesZtransition_infonumrf  r}  Zostorz   Z
dst_offsetindexrD   rD   rE   get_transitionsI  sn    	  


zTimezone.get_transitionsc                 C  s   g | ]}t |d qS )rF  r[  )r   rG  rD   rD   rE   r     s    zTimezone.<listcomp>)@                r  rh   r  )hours   )minutes   r~  Nr   r   r   )rv  tzid
first_date	last_dater3   c              	   C  sV  |dkr(t |}|dkr(td| dt|ddd }t|j|j|j}t|j|j|j}t|dr|||}||}n|j	|d}|j	|d}t
t}|}	d}
|	|k r~|
}|	}| }
| jD ]Z}|}||| }z"| |
kr|}||| }qW n tk
r   Y  q Y nX |}q|	 t k}|	 }|dkrHt|
}||
||f}|| |	j	dd ||| jd	  }	q|  }|d
| |dd| d| d | D ]\\}}
}}}t|}|| | |krt|j|j|j}|r t nt }|dkr|
}||_|
|_|d| ||_|rD|d| || q|S )a  Return a VTIMEZONE component from a timezone object.

        This works with pytz and zoneinfo and any other timezone.
        The offsets are calculated from the tzinfo object.

        Parameters:

        :param tzinfo: the timezone object
        :param tzid: the tzid for this timezone. If None, it will be extracted from the tzinfo.
        :param first_date: a datetime that is earlier than anything that happens in the calendar
        :param last_date: a datetime that is later than anything that happens in the calendar
        :raises ValueError: If we have no tzid and cannot extract one.

        .. note::
            This can take some time. Please cache the results.
        NzCannot get TZID from z . Please set the tzid parameter.	normalizec                 S  s   | S r   rD   )r  rD   rD   rE   r     r   z&Timezone.from_tzinfo.<locals>.<lambda>localizera  r   r   r&  zThis timezone only works from z to r   r{  r   )r#   r>   r   r   yearmonthdayrx   r  rd  r   rq   	utcoffset_from_tzinfo_skip_searchOverflowErrorr  r   r^  r/   r   r   ry   minremover   rY   rZ   rh  ri  r   r   )r   rv  r  r  r  r  Zfirst_datetimeZlast_datetimeoffsetsr9  Z	offset_toZoffset_fromr:  Z
add_offsetZlast_endZis_standardrz   r   rl  r^  ZstartsZfirst_startr   rD   rD   rE   from_tzinfo  st    







zTimezone.from_tzinfo)r  r*   r  r  r3   c                 C  s2   | |}|dkr"td| d| ||||S )a  Create a VTIMEZONE from a tzid like ``"Europe/Berlin"``.

        :param tzid: the id of the timezone
        :param tzp: the timezone provider
        :param first_date: a datetime that is earlier than anything that happens in the calendar
        :param last_date: a datetime that is later than anything that happens in the calendar
        :raises ValueError: If the tzid is unknown.

        >>> from icalendar import Timezone
        >>> tz = Timezone.from_tzid("Europe/Berlin")
        >>> print(tz.to_ical()[:36])
        BEGIN:VTIMEZONE
        TZID:Europe/Berlin

        .. note::
            This can take some time. Please cache the results.
        NzUnkown timezone r   )rv  r>   r  )r   r  r*   r  r  rl  rD   rD   rE   	from_tzid  s    
zTimezone.from_tzidzlist[TimezoneStandard]c                 C  s
   |  dS )z%The STANDARD subcomponents as a list.rN   r   ro   rD   rD   rE   standard  s    zTimezone.standardzlist[TimezoneDaylight]c                 C  s
   |  dS )z_The DAYLIGHT subcomponents as a list.

        These are for the daylight saving time.
        rO   r  ro   rD   rD   rE   daylight"  s    zTimezone.daylight)r\  )rc   rd   re   rf   r	  rz   rM  r   r   r   _DEFAULT_FIRST_DATE_DEFAULT_LAST_DATEr   r4  r   rr  rt  r*   rx  r
  rw  r  r   r  r  r  r  r  rD   rD   rD   rE   rX     sZ   
5
J\rX   c                   @  sf   e Zd ZdZdZdZdZdZedde	fe	dZ
edd	efed
eZedd	efedeZeZeZeZdS )rY   z
    The "STANDARD" sub-component of "VTIMEZONE" defines the standard
    time offset from UTC for a time zone. It represents a time zone's
    standard time, typically used during winter months in locations
    that observe Daylight Saving Time.
    rN   )r   ri  rh  )r&  r   r{  r  r   r   r  zThe mandatory "DTSTART" property gives the effective onset date
        and local time for the time zone sub-component definition.
        "DTSTART" in this usage MUST be specified as a date with a local
        time value.ri  r  zThe mandatory "TZOFFSETTO" property gives the UTC offset for the
        time zone sub-component (Standard Time or Daylight Saving Time)
        when this observance is in use.
        rh  a  The mandatory "TZOFFSETFROM" property gives the UTC offset that is
        in use when the onset of this time zone observance begins.
        "TZOFFSETFROM" is combined with "DTSTART" to define the effective
        onset for the time zone sub-component definition.  For example,
        the following represents the time at which the observance of
        Standard Time took effect in Fall 1967 for New York City:

            DTSTART:19671029T020000
            TZOFFSETFROM:-0400
        N)rc   rd   re   rf   rz   r   r   r   r  r   r   r   r(   ri  rh  r   rW  r   rX  r   rY  rD   rD   rD   rE   rY   +  s>   

rY   c                   @  sD   e Zd ZdZdZejZejZejZej	Z	ej
Z
ejZeZeZeZdS )rZ   a	  
    The "DAYLIGHT" sub-component of "VTIMEZONE" defines the daylight
    saving time offset from UTC for a time zone. It represents a time
    zone's daylight saving time, typically used during summer months
    in locations that observe Daylight Saving Time.
    rO   N)rc   rd   re   rf   rz   rY   r   r   r   r   ri  rh  r   rW  r   rX  r   rY  rD   rD   rD   rE   rZ   g  s   rZ   c                   @  s   e Zd ZdZdZdZdZdZdZe	ddd	Z
eeeed
ZeddZeddeefeeeef  dZeddddZejddddZG dd deZedd ZedejdZdS )r[   z
    A "VALARM" calendar component is a grouping of component
    properties that defines an alarm or reminder for an event or a
    to-do. For example, it may be used to define a reminder for a
    pending event or an overdue to-do.
    rP   )ACTIONTRIGGER)
r$  r  r  r  r  r  REPEATr  Z	PROXIMITYACKNOWLEDGED))r  r  )r  r%  )r%  r$  z
RELATED-TOr  r   a!  The REPEAT property of an alarm component.

        The alarm can be defined such that it triggers repeatedly.  A
        definition of an alarm with a repeating trigger MUST include both
        the "DURATION" and "REPEAT" properties.  The "DURATION" property
        specifies the delay period, after which the alarm will repeat.
        The "REPEAT" property specifies the number of additional
        repetitions that the alarm will be triggered.  This repetition
        count is in addition to the initial triggering of the alarm.
        aB  The DURATION property of an alarm component.

    The alarm can be defined such that it triggers repeatedly.  A
    definition of an alarm with a repeating trigger MUST include both
    the "DURATION" and "REPEAT" properties.  The "DURATION" property
    specifies the delay period, after which the alarm will repeat.
    r  a  This is defined in RFC 9074:

    Purpose: This property specifies the UTC date and time at which the
    corresponding alarm was last sent or acknowledged.

    This property is used to specify when an alarm was last sent or acknowledged.
    This allows clients to determine when a pending alarm has been acknowledged
    by a calendar user so that any alerts can be dismissed across multiple devices.
    It also allows clients to track repeating alarms or alarms on recurring events or
    to-dos to ensure that the right number of missed alarms can be tracked.

    Clients SHOULD set this property to the current date-time value in UTC
    when a calendar user acknowledges a pending alarm. Certain kinds of alarms,
    such as email-based alerts, might not provide feedback as to when the calendar user
    sees them. For those kinds of alarms, the client SHOULD set this property
    when the alarm is triggered and the action is successfully carried out.

    When an alarm is triggered on a client, clients can check to see if an "ACKNOWLEDGED"
    property is present. If it is, and the value of that property is greater than or
    equal to the computed trigger time for the alarm, then the client SHOULD NOT trigger
    the alarm. Similarly, if an alarm has been triggered and
    an "alert" has been presented to a calendar user, clients can monitor
    the iCalendar data to determine whether an "ACKNOWLEDGED" property is added or
    changed in the alarm component. If the value of any "ACKNOWLEDGED" property
    in the alarm changes and is greater than or equal to the trigger time of the alarm,
    then clients SHOULD dismiss or cancel any "alert" presented to the calendar user.
    r  r  a2  Purpose:  This property specifies when an alarm will trigger.

    Value Type:  The default value type is DURATION.  The value type can
    be set to a DATE-TIME value type, in which case the value MUST
    specify a UTC-formatted DATE-TIME value.

    Either a positive or negative duration may be specified for the
    "TRIGGER" property.  An alarm with a positive duration is
    triggered after the associated start or end of the event or to-do.
    An alarm with a negative duration is triggered before the
    associated start or end of the event or to-do.r/   r   c                 C  s$   |  d}|dkrdS |j ddS )a  The RELATED parameter of the TRIGGER property.

        Values are either "START" (default) or "END".

        A value of START will set the alarm to trigger off the
        start of the associated event or to-do.  A value of END will set
        the alarm to trigger off the end of the associated event or to-do.

        In this example, we create an alarm that triggers two hours after the
        end of its parent component:

        >>> from icalendar import Alarm
        >>> from datetime import timedelta
        >>> alarm = Alarm()
        >>> alarm.TRIGGER = timedelta(hours=2)
        >>> alarm.TRIGGER_RELATED = "END"
        r  NSTARTr)  )r   rt   )r^   triggerrD   rD   rE   TRIGGER_RELATED  s    
zAlarm.TRIGGER_RELATED)r{   c                 C  s(   |  d}|dkrtd||jd< dS )zSet "START" or "END".r  Nz<You must set a TRIGGER before setting the RELATED parameter.r)  )r   r>   rt   )r^   r{   r  rD   rD   rE   r    s    
c                   @  s*   e Zd ZU dZded< ded< ded< dS )zAlarm.TriggerszThe computed times of alarm triggers.

        start - triggers relative to the start of the Event or Todo (timedelta)

        end - triggers relative to the end of the Event or Todo (timedelta)

        absolute - triggers at a datetime in UTC
        ztuple[timedelta]r9  r:  ztuple[datetime]absoluteN)rc   rd   re   rf   r	  rD   rD   rD   rE   Triggers  s   
	r  c                 C  s   g }g }g }| j }|dk	rt|tr4|| |}n(| jdkrN|| |}n|| |}| j}|dk	rt| jD ]}||d |  qt| jt	|t	|t	|dS )a  The computed triggers of an Alarm.

        This takes the TRIGGER, DURATION and REPEAT properties into account.

        Here, we create an alarm that triggers 3 times before the start of the
        parent component:

        >>> from icalendar import Alarm
        >>> from datetime import timedelta
        >>> alarm = Alarm()
        >>> alarm.TRIGGER = timedelta(hours=-4)  # trigger 4 hours before START
        >>> alarm.DURATION = timedelta(hours=1)  # after 1 hour trigger again
        >>> alarm.REPEAT = 2  # trigger 2 more times
        >>> alarm.triggers.start == (timedelta(hours=-4),  timedelta(hours=-3),  timedelta(hours=-2))
        True
        >>> alarm.triggers.end
        ()
        >>> alarm.triggers.absolute
        ()
        Nr  r   )r9  r:  r  )
r  ru   r   r   r  r  r  r  r  tuple)r^   r9  r:  r  r  r   r  r|  rD   rD   rE   triggers  s,    




  zAlarm.triggersr  z
X-ALARMUIDN) rc   rd   re   rf   rz   r   r   r   r   r   r  r
  r  r  r  r  r   r  r  r   r   r   r   r  r  rP  r
   r  r  r   r   rZ  rD   rD   rD   rE   r[   |  sP   
 	
+r[   c                   @  s   e Zd ZdZdZdZdZdZdZe	d/dd d	d
dZ
e	d0ddZeddddZeddddZeddddZddddZddddZedddd Zejejfd!d!d"d#d$Zed%d&d'Zed(d)d*Zed+d,d-ZeZeZd.S )1r\   z
    The "VCALENDAR" object is a collection of calendar information.
    This information can include a variety of components, such as
    "VEVENT", "VTODO", "VJOURNAL", "VFREEBUSY", "VTIMEZONE", or any
    other type of calendar component.
    rQ   )VERSIONPRODIDCALSCALEMETHODr  X-WR-CALDESCNAMEX-WR-CALNAME)r  r  )r  r  r  r  r  )ri   r  r  r4  r/   r/  c                 C  s   |  td|S )r0  Z	calendarsr2  r3  rD   rD   rE   r4  u  s    zCalendar.exampleFc                 C  s   t j|dd}d}|D ]:}|jD ].}|jdkrJ|r4qNt ||    S q d}q q|rZ|S t|dkrvt| d|t|dk rt| d||d S )	NT)r   rM   Frh   r   r   r   )rl   r   rm   rz   r   r>   r   )r   r   r   r   Zall_timezones_so_farcompr   rD   rD   rE   r   z  s,    

	  zCalendar.from_icalzlist[Event]r   c                 C  s
   |  dS )a  All event components in the calendar.

        This is a shortcut to get all events.
        Modifications do not change the calendar.
        Use :py:meth:`Component.add_component`.

        >>> from icalendar import Calendar
        >>> calendar = Calendar.example()
        >>> event = calendar.events[0]
        >>> event.start
        datetime.date(2022, 1, 1)
        >>> print(event["SUMMARY"])
        New Year's Day
        rI   r  ro   rD   rD   rE   r1    s    zCalendar.eventsz
list[Todo]c                 C  s
   |  dS )zAll todo components in the calendar.

        This is a shortcut to get all todos.
        Modifications do not change the calendar.
        Use :py:meth:`Component.add_component`.
        rJ   r  ro   rD   rD   rE   todos  s    zCalendar.todoszlist[FreeBusy]c                 C  s
   |  dS )zAll FreeBusy components in the calendar.

        This is a shortcut to get all FreeBusy.
        Modifications do not change the calendar.
        Use :py:meth:`Component.add_component`.
        rL   r  ro   rD   rD   rE   freebusy  s    zCalendar.freebusyzset[str]c                 C  sB   t  }| jddD ]$\}}t|dr||jd q|dh S )a  The set of TZIDs in use.

        This goes through the whole calendar to find all occurrences of
        timezone information like the TZID parameter in all attributes.

        >>> from icalendar import Calendar
        >>> calendar = Calendar.example("timezone_rdate")
        >>> calendar.get_used_tzids()
        {'posix/Europe/Vaduz'}

        Even if you use UTC, this will not show up.
        Fr   rt   r   N)rp  r   rx   r   rt   r   )r^   r   rz   r{   rD   rD   rE   get_used_tzids  s
    
zCalendar.get_used_tzidsc                 C  s$   |   }| jD ]}||j q|S )zThe set of missing timezone component tzids.

        To create a :rfc:`5545` compatible calendar,
        all of these timezones should be added.
        )r  r]  r  rw  )r^   Ztzidsrv  rD   rD   rE   get_missing_tzids  s    
zCalendar.get_missing_tzidszlist[Timezone]c                 C  s
   |  dS )a>  Return the timezones components in this calendar.

        >>> from icalendar import Calendar
        >>> calendar = Calendar.example("pacific_fiji")
        >>> [timezone.tz_name for timezone in calendar.timezones]
        ['custom_Pacific/Fiji']

        .. note::

            This is a read-only property.
        rM   r  ro   rD   rD   rE   r]    s    zCalendar.timezonesr   r  r  c              	   C  sJ   |   D ]<}ztj|||d}W n tk
r8   Y qY nX | | qdS )a  Add all missing VTIMEZONE components.

        This adds all the timezone components that are required.

        .. note::

            Timezones that are not known will not be added.

        :param first_date: earlier than anything that happens in the calendar
        :param last_date: later than anything happening in the calendar

        >>> from icalendar import Calendar, Event
        >>> from datetime import datetime
        >>> from zoneinfo import ZoneInfo
        >>> calendar = Calendar()
        >>> event = Event()
        >>> calendar.add_component(event)
        >>> event.start = datetime(1990, 10, 11, 12, tzinfo=ZoneInfo("Europe/Berlin"))
        >>> calendar.timezones
        []
        >>> calendar.add_missing_timezones()
        >>> calendar.timezones[0].tz_name
        'Europe/Berlin'
        >>> calendar.get_missing_tzids()  # check that all are added
        set()
        r  N)r  rX   r  r>   r   )r^   r  r  r  rv  rD   rD   rE   add_missing_timezones  s      

zCalendar.add_missing_timezonesr  r  a  This property specifies the name of the calendar.

    This implements :rfc:`7986` ``NAME`` and ``X-WR-CALNAME``.

    Property Parameters:
        IANA, non-standard, alternate text
        representation, and language property parameters can be specified
        on this property.

    Conformance:
        This property can be specified multiple times in an
        iCalendar object.  However, each property MUST represent the name
        of the calendar in a different language.

    Description:
        This property is used to specify a name of the
        iCalendar object that can be used by calendar user agents when
        presenting the calendar data to a user.  Whilst a calendar only
        has a single name, multiple language variants can be specified by
        including this property multiple times with different "LANGUAGE"
        parameter values on each.

    Example:
        Below, we set the name of the calendar.

        .. code-block:: pycon

            >>> from icalendar import Calendar
            >>> calendar = Calendar()
            >>> calendar.calendar_name = "My Calendar"
            >>> print(calendar.to_ical())
            BEGIN:VCALENDAR
            NAME:My Calendar
            END:VCALENDAR
    r  r  a  This property specifies the description of the calendar.

    This implements :rfc:`7986` ``DESCRIPTION`` and ``X-WR-CALDESC``.

    Conformance:
        This property can be specified multiple times in an
        iCalendar object.  However, each property MUST represent the
        description of the calendar in a different language.

    Description:
        This property is used to specify a lengthy textual
        description of the iCalendar object that can be used by calendar
        user agents when describing the nature of the calendar data to a
        user.  Whilst a calendar only has a single description, multiple
        language variants can be specified by including this property
        multiple times with different "LANGUAGE" parameter values on each.

    Example:
        Below, we add a description to a calendar.

        .. code-block:: pycon

            >>> from icalendar import Calendar
            >>> calendar = Calendar()
            >>> calendar.description = "This is a calendar"
            >>> print(calendar.to_ical())
            BEGIN:VCALENDAR
            DESCRIPTION:This is a calendar
            END:VCALENDAR
    r  a  This property specifies a color used for displaying the calendar.

    This implements :rfc:`7986` ``COLOR`` and ``X-APPLE-CALENDAR-COLOR``.
    Please note that since :rfc:`7986`, subcomponents can have their own color.

    Property Parameters:
        IANA and non-standard property parameters can
        be specified on this property.

    Conformance:
        This property can be specified once in an iCalendar
        object or in ``VEVENT``, ``VTODO``, or ``VJOURNAL`` calendar components.

    Description:
        This property specifies a color that clients MAY use
        when presenting the relevant data to a user.  Typically, this
        would appear as the "background" color of events or tasks.  The
        value is a case-insensitive color name taken from the CSS3 set of
        names, defined in Section 4.3 of `W3C.REC-css3-color-20110607 <https://www.w3.org/TR/css-color-3/>`_.

    Example:
        ``"turquoise"``, ``"#ffffff"``

        .. code-block:: pycon

            >>> from icalendar import Calendar
            >>> calendar = Calendar()
            >>> calendar.color = "black"
            >>> print(calendar.to_ical())
            BEGIN:VCALENDAR
            COLOR:black
            END:VCALENDAR

    zX-APPLE-CALENDAR-COLORN)r4  )F) rc   rd   re   rf   rz   rM  r   r   r   r   r4  r   r
  r1  r  r  r  r  r]  rX   r  r  r  r   Zcalendar_namedescriptionr   rU  r   r   r   rZ  rD   rD   rD   rE   r\   Q  sP   
		( & !"&r\   INLINEr   r   )Urf   
__future__r   r7   collectionsr   r   r   r   r   typingr   r	   r
   r   r   r   Zdateutil.rrulerk  Zdateutil.tzZicalendar.attrr   r   r   r   r   r   r   r   r   r   r   Zicalendar.caselessdictr   Zicalendar.errorr   r   Zicalendar.parserr   r   r   r   r    Zicalendar.parser_toolsr!   Zicalendar.propr"   r#   r$   r%   r&   r'   r(   Zicalendar.timezoner)   r*   Zicalendar.toolsr+   r,   r+  r.   rF   rG   r  r   rl   r  rQ  rS  r  r  r  rN  rT   rU   rV   rW   rX   rY   rZ   r[   r\   rv   r   __all__rD   rD   rD   rE   <module>   s    4$	   fA   [ E\   \< V  7