
    i_                    8   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
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 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlm Z  e	r.ddl!m"Z"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+m,Z, ddl-m.Z.  G d de          Z/dgZ0dS )z :rfc:`5545` iCalendar component.    )annotationsN)	timedelta)Path)TYPE_CHECKINGLiteraloverload)
CONCEPTS_TYPE_SETTERLINKS_TYPE_SETTERRELATED_TO_TYPE_SETTERcategories_propertyimages_propertymulti_language_text_propertysingle_string_propertysource_propertyuid_propertyurl_property)	Component)get_example)Timezone)IncompleteComponent)__version__)IterableSequence)datedatetime)Availability)Event)FreeBusy)Journal)Todoc                      e Zd ZdZdZdZdZdZdZe	ddded            Z
ee		 dfdgd                        Zee	dhd                        Ze		 dfdid            Zedjd            Zedkd            Zedld            Zedmd            Zednd!            Zdod#Zdod$Zedpd&            Zej        ej        fdqd*Z ed+d,d-          Z ed.d/d0          Z ed1d2d3          ZeZ e!Z" ed4d5          Z# ed6d7          Z$ ed8d9d:;          Z% ed<d=          Z&e'Z(e)Z*edrd?            Z+e+j,        dsdA            Z+e+j-        dB             Z+e.Z/e		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dtdu fdb            Z0dc Z1 xZ2S )vCalendara  
        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.

    Examples:
        Create a new Calendar:

            >>> from icalendar import Calendar
            >>> calendar = Calendar.new(name="My Calendar")
            >>> print(calendar.calendar_name)
            My Calendar

    	VCALENDAR)VERSIONPRODIDCALSCALEMETHODDESCRIPTIONX-WR-CALDESCNAMEX-WR-CALNAME)r%   r$   )r%   r$   r&   r'   COLOR)
CATEGORIESr(   r*   examplenamestrreturnc                H    |                      t          d|                    S )z0Return the calendar example with the given name.	calendars)	from_icalr   )clsr/   s     Q/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/cal/calendar.pyr.   zCalendar.exampleT   s      }}[d;;<<<    Fstbytes | str | PathmultipleLiteral[False]c                    d S N r5   r8   r:   s      r6   r4   zCalendar.from_icalY   s	     3r7   Literal[True]list[Calendar]c                    d S r=   r>   r?   s      r6   r4   zCalendar.from_ical_   s	     r7   boolCalendar | list[Calendar]c                   t          |t                    r|                                }njt          |t                    rUd|vrQd|vrMt          |          }	 |                                }n# t
          $ r d}Y nw xY w|r|                                }t          j        |d          }d}|D ]5}|j        D ]+}|j	        dk    r|st          j        ||          c c S )d},6|r|S t          |          dk    r#t          |                     d|                    t          |          dk     r#t          |                     d	|                    |d
         S )a  Parse iCalendar data into Calendar instances.

        Wraps :meth:`Component.from_ical()
        <icalendar.cal.component.Component.from_ical>` with timezone
        forward-reference resolution and VTIMEZONE caching.

        Parameters:
            st: iCalendar data as bytes or string, or a path to an iCalendar file as
                :class:`pathlib.Path` or string.
            multiple: If ``True``, returns list. If ``False``, returns single calendar.

        Returns:
            Calendar or list of Calendars
        
FT)r:   	VTIMEZONE   z3Found multiple components where only one is allowedz1Found no components where exactly one is requiredr   )
isinstancer   
read_bytesr0   is_fileOSErrorr   r4   subcomponentsr/   len
ValueError_format_error)	r5   r8   r:   pathrL   compsall_timezones_so_farcomp	components	            r6   r4   zCalendar.from_icale   s   ( b$ 		'BBC   	'T^^B88D ,,..        '__&&#B666# 	1 	1D!/ 1 1	>[00/ A  )22x@@@@@@@A ,1((!1&  	Lu::>>!!I2   
 u::>>!!G   
 Qxs   A- -A<;A<list[Event]c                ,    |                      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 <icalendar.cal.component.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
        VEVENTwalkselfs    r6   eventszCalendar.events   s      yy"""r7   
list[Todo]c                ,    |                      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 <icalendar.cal.component.Component.add_component>`.
        VTODOrZ   r\   s    r6   todoszCalendar.todos   s     yy!!!r7   list[Journal]c                ,    |                      d          S )zAll journal components in the calendar.

        This is a shortcut to get all journals.
        Modifications do not change the calendar.
        Use :py:meth:`Component.add_component <icalendar.cal.component.Component.add_component>`.
        VJOURNALrZ   r\   s    r6   journalszCalendar.journals   s     yy$$$r7   list[Availability]c                ,    |                      d          S )a	  All :class:`Availability` components in the calendar.

        This is a shortcut to get all availabilities.
        Modifications do not change the calendar.
        Use :py:meth:`Component.add_component <icalendar.cal.component.Component.add_component>`.
        VAVAILABILITYrZ   r\   s    r6   availabilitieszCalendar.availabilities   s     yy)))r7   list[FreeBusy]c                ,    |                      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 <icalendar.cal.component.Component.add_component>`.
        	VFREEBUSYrZ   r\   s    r6   freebusyzCalendar.freebusy   s     yy%%%r7   set[str]c                    t                      }|                     d          D ]B\  }}t          |d          r-|                    |j                            d                     C|dhz
  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.
        F)sortedparamsTZIDN)setproperty_itemshasattraddrr   get)r]   result_namevalues       r6   get_used_tzidszCalendar.get_used_tzids   sr      //u/== 	5 	5LE5uh'' 5

5<++F33444r7   c                ~    |                                  dhz
  }| j        D ]}|                    |j                   |S )a)  The set of missing timezone component tzids.

        To create a :rfc:`5545` compatible calendar,
        all of these timezones should be added.

        UTC is excluded: per :rfc:`5545#section-3.2.19`, UTC datetimes use
        the ``Z`` suffix and never require a VTIMEZONE component.
        UTC)r|   	timezonesdiscardtz_name)r]   tzidstimezones      r6   get_missing_tzidszCalendar.get_missing_tzids   sL     ##%%/ 	, 	,H MM(*++++r7   list[Timezone]c                ,    |                      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.
        rH   rZ   r\   s    r6   r   zCalendar.timezones  s     yy%%%r7   
first_dater   	last_datec                    |                                  }|sdS t          | j                  }|D ]K}	 t          j        |||          }n# t
          $ r Y 'w xY w| j                            ||           |dz  }LdS )a  Add all missing VTIMEZONE components.

        This adds all the timezone components that are required.
        VTIMEZONE components are inserted at the beginning of the calendar
        to ensure they appear before other components that reference them.

        .. 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()
        N)r   r   rI   )r   rO   r   r   	from_tzidrP   rN   insert)r]   r   r   missing_tzidsexisting_timezone_counttzidr   s          r6   add_missing_timezoneszCalendar.add_missing_timezones  s    B ..00 	F"%dn"5"5! 	) 	)D#-Z9      %%&=xHHH#q(##	) 	)s   A


AAr*   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
            X-WR-CALNAME: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
            X-WR-CALDESC: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-COLORr%   a  PRODID specifies the identifier for the product that created the iCalendar object.

Conformance:
    The property MUST be specified once in an iCalendar object.

Description:
    The vendor of the implementation SHOULD assure that
    this is a globally unique identifier; using some technique such as
    an FPI value, as defined in [ISO.9070.1991].

    This property SHOULD NOT be used to alter the interpretation of an
    iCalendar object beyond the semantics specified in this memo.  For
    example, it is not to be used to further the understanding of non-
    standard properties.

Example:
    The following is an example of this property. It does not
    imply that English is the default language.

    .. code-block:: text

        -//ABC Corporation//NONSGML My Product//EN
r$   aD  VERSION of the calendar specification.

The default is ``"2.0"`` for :rfc:`5545`.

Purpose:
    This property specifies the identifier corresponding to the
    highest version number or the minimum and maximum range of the
    iCalendar specification that is required in order to interpret the
    iCalendar object.


      r&   a  CALSCALE defines the calendar scale used for the calendar information specified in the iCalendar object.

Compatibility:
    :rfc:`7529` makes the case that GREGORIAN stays the default and other calendar scales
    are implemented on the RRULE.

Conformance:
    This property can be specified once in an iCalendar
    object.  The default value is "GREGORIAN".

Description:
    This memo is based on the Gregorian calendar scale.
    The Gregorian calendar scale is assumed if this property is not
    specified in the iCalendar object.  It is expected that other
    calendar scales will be defined in other specifications or by
    future versions of this memo.
        	GREGORIAN)defaultr'   ag  METHOD defines the iCalendar object method associated with the calendar object.

Description:
    When used in a MIME message entity, the value of this
    property MUST be the same as the Content-Type "method" parameter
    value.  If either the "METHOD" property or the Content-Type
    "method" parameter is specified, then the other MUST also be
    specified.

    No methods are defined by this specification.  This is the subject
    of other specifications, such as the iCalendar Transport-
    independent Interoperability Protocol (iTIP) defined by :rfc:`5546`.

    If this property is not present in the iCalendar object, then a
    scheduling transaction MUST NOT be assumed.  In such cases, the
    iCalendar object is merely being used to transport a snapshot of
    some calendar information; without the intention of conveying a
    scheduling semantic.
timedelta | Nonec                B    |                      d          }|r|j        ndS )a  REFRESH-INTERVAL specifies a suggested minimum interval for
        polling for changes of the calendar data from the original source
        of that data.

        Conformance:
            This property can be specified once in an iCalendar
            object, consisting of a positive duration of time.

        Description:
            This property specifies a positive duration that gives
            a suggested minimum polling interval for checking for updates to
            the calendar data.  The value of this property SHOULD be used by
            calendar user agents to limit the polling interval for calendar
            data updates to the minimum interval specified.

        Raises:
            ValueError: When setting a negative duration.
        REFRESH-INTERVALN)rx   dt)r]   refresh_intervals     r6   r   zCalendar.refresh_interval  s+    (  88$677&6@""D@r7   r{   c                    t          |t                    s|t          d          |'|                                dk    rt	          d          || `|                     d|           dS | `dS )zSet the REFRESH-INTERVAL.NzKREFRESH-INTERVAL must be either a positive timedelta, or None to delete it.r   z.REFRESH-INTERVAL must be a positive timedelta.r   )rJ   r   	TypeErrortotal_secondsrP   r   rw   )r]   r{   s     r6   r   zCalendar.refresh_interval+  s     %++ 	0A)   !4!4!6!6!!;!;MNNN%HH'/////%%%r7   c                0    |                      d           dS )zDelete REFRESH-INTERVAL.r   N)popr\   s    r6   r   zCalendar.refresh_interval;  s     	#$$$$$r7   Nr>   2.0calscale
str | None
categoriesSequence[str]colorconceptsr	   descriptionlanguagelast_modifieddate | datetime | Nonelinksr
   methodorganizationprodidr   refidslist[str] | str | None
related_tor   sourcerN   Iterable[Component] | Noneuidstr | uuid.UUID | Noneurlversionc                  t                                          |||||          }|*|r(|
pd}|r|                                nd}d| d| d| }n|dt           d}||_        ||_        |
|_        ||_        ||_        |	|_	        ||_
        ||_        ||nt          j                    |_        ||_        ||_        ||_        |t%          |          |_        |S )	a  Create a new Calendar with all required properties.

        This creates a new Calendar in accordance with :rfc:`5545` and :rfc:`7986`.

        Parameters:
            calscale: The :attr:`calscale` of the calendar.
            categories: The :attr:`categories` of the calendar.
            color: The :attr:`color` of the calendar.
            concepts: The :attr:`~icalendar.Component.concepts` of the calendar.
            description: The :attr:`description` of the calendar.
            language: The language for the calendar. Used to generate localized `prodid`.
            last_modified: The :attr:`~icalendar.Component.last_modified` of the calendar.
            links: The :attr:`~icalendar.Component.links` of the calendar.
            method: The :attr:`method` of the calendar.
            name: The :attr:`calendar_name` of the calendar.
            organization: The organization name. Used to generate `prodid` if not provided.
            prodid: The :attr:`prodid` of the component. If None and organization is provided,
                generates a `prodid` in format "-//organization//name//language".
            refresh_interval: The :attr:`refresh_interval` of the calendar.
            refids: :attr:`~icalendar.Component.refids` of the calendar.
            related_to: :attr:`~icalendar.Component.related_to` of the calendar.
            source: The :attr:`source` of the calendar.
            subcomponents: The subcomponents of the calendar.
            uid: The :attr:`uid` of the calendar.
                If None, this is set to a new :func:`uuid.uuid4`.
            url: The :attr:`url` of the calendar.
            version: The :attr:`version` of the calendar.

        Returns:
            :class:`Calendar`

        Raises:
            ~error.InvalidCalendar: If the content is not valid according to :rfc:`5545`.

        .. warning:: As time progresses, we will be stricter with the validation.
        )r   r   r   r   r   Nr"   ENz-//z//z-//collective//icalendar//z//EN)supernewupperr   r   r   calendar_namer   r   r   r   r   uuiduuid4r   r   r   r   listrN   )r5   r   r   r   r   r   r   r   r   r   r/   r   r   r   r   r   r   rN   r   r   r   calendarapp_namelang	__class__s                           r6   r   zCalendar.newB  s   z #WW[['! ) 
 
 >l>)zH'/98>>###TD=<==8==t==FF^C+CCCF "!%* $(!oss4:<<$4! $%)-%8%8H"r7   c                    |                      d          st          d          |                      d          st          d          | j        st          d          dS )a!  Validate that the calendar has required properties and components.

        This method can be called explicitly to validate a calendar before output.

        Raises:
            ~error.IncompleteComponent: If the calendar lacks required properties or
                components.
        r%   zCalendar must have a PRODIDr$   zCalendar must have a VERSIONz@Calendar must contain at least one component (event, todo, etc.)N)rx   r   rN   r\   s    r6   validatezCalendar.validate  sv     xx!! 	E%&CDDDxx	"" 	F%&DEEE! 	%R  	 	r7   )r.   )r/   r0   r1   r"   )F)r8   r9   r:   r;   r1   r"   )r8   r9   r:   r@   r1   rA   )r8   r9   r:   rC   r1   rD   )r1   rW   )r1   r_   )r1   rc   )r1   rg   )r1   rk   )r1   ro   )r1   r   )r   r   r   r   )r1   r   )r{   r   )Nr>   NNNNNNNNNNNNNNNNNr   )(r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r
   r   r   r/   r   r   r   r   r   r   r   r   r   r   r   r   r   rN   r   r   r   r   r   r   r0   )3__name__
__module____qualname____doc__r/   canonical_orderrequired
singletonsr:   classmethodr.   r   r4   propertyr^   rb   rf   rj   rn   r|   r   r   r   DEFAULT_FIRST_DATEDEFAULT_LAST_DATEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   setterdeleterr   imagesr   r   __classcell__)r   s   @r6   r"   r"   '   s          D	OHJH = = = = [= @E    [ X    [ X  B B B B [BH # # # X#" " " " X" % % % X% * * * X* & & & X&   &     & & & X&  $6"4/) /) /) /) /)b 10#	' 'MR /.	" "KH #"!	D 	!I% %EL %J
C##	 F4 %$	
 G  &%	" '  H* $#	 F, CFA A A XA, & & & & % % % F  $$& )-"&#04#'!#'!-1)--1!48&*-[ [ [ [ [ [ [[z      r7   r"   )1r   
__future__r   r   r   r   pathlibr   typingr   r   r   icalendar.attrr	   r
   r   r   r   r   r   r   r   r   icalendar.cal.componentr   icalendar.cal.examplesr   icalendar.cal.timezoner   icalendar.errorr   icalendar.versionr   collections.abcr   r   r   icalendar.cal.availabilityr   icalendar.cal.eventr   icalendar.cal.free_busyr   icalendar.cal.journalr   icalendar.cal.todor    r"   __all__r>   r7   r6   <module>r      s   & & " " " " " "              3 3 3 3 3 3 3 3 3 3                        . - - - - - . . . . . . + + + + + + / / / / / / ) ) ) ) ) ) (22222222''''''''777777))))))000000------''''''I
 I
 I
 I
 I
y I
 I
 I
X ,r7   