
    3fi=                    v   d dl Z d dlZd dlZd dlmZ d dlmZ d dl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ  ej4                  e      Z edd	      D  cg c]  } e j<                  |     c} Z G d
 de      Z  G d de      Z! G d de      Z" G d de      Z# G d de      Z$ G d de      Z% G d de      Z& G d de      Z' G d de      Z( G d d      Z) G d de      Z* G d  d!e      Z+ G d" d#      Z, G d$ d%e      Z- G d& d'eee      Z. G d( d)ee      Z/ G d* d+e      Z0yc c} w ),    N)ZoneInfo)BeautifulSoup)parse   )Category)
NEXT_LINK_KEYWORDApiComponentAttachableMixinBaseAttachmentBaseAttachmentsCaseEnumHandleRecipientsMixinImportanceLevel
Pagination
TrackerSet)get_windows_tz   c                        e Zd ZdZdZdZdZdZy)EventResponse	organizertentativelyAcceptedaccepteddeclinednotRespondedN)__name__
__module____qualname__	OrganizerTentativelyAcceptedAcceptedDeclinedNotResponded     K/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/calendar.pyr   r      s    I/HH!Lr$   r   c                       e Zd ZdZdZdZy)AttendeeTyperequiredoptionalresourceN)r   r   r   RequiredOptionalResourcer#   r$   r%   r'   r'   &   s    HHHr$   r'   c                       e Zd ZdZdZdZdZy)EventSensitivitynormalpersonalprivateconfidentialN)r   r   r   NormalPersonalPrivateConfidentialr#   r$   r%   r/   r/   ,   s    FHG!Lr$   r/   c                   $    e Zd ZdZdZdZdZdZdZy)EventShowAsfree	tentativebusyoofworkingElsewhereunknownN)	r   r   r   Free	TentativeBusyOofWorkingElsewhereUnknownr#   r$   r%   r9   r9   3   s!    DID
C)Gr$   r9   c                   8    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZy)CalendarColor	lightBlue
lightGreenlightOrange	lightGraylightYellow	lightTeal	lightPink
lightBrownlightRedmaxColorautoN)r   r   r   	LightBlue
LightGreenLightOrange	LightGrayLightYellow	LightTeal	LightPink
LightBrownLightRedMaxColorAutor#   r$   r%   rG   rG   <   s9    IJKIKIIJHHDr$   rG   c                       e Zd ZdZdZdZdZy)	EventTypesingleInstance
occurrence	exceptionseriesMasterN)r   r   r   SingleInstance
Occurrence	ExceptionSeriesMasterr#   r$   r%   r_   r_   J   s    %NJI!Lr$   r_   c                       e Zd ZdZdZdZdZy)OnlineMeetingProviderTyper?   teamsForBusinessskypeForBusinessskypeForConsumerN)r   r   r   rE   TeamsForBusinessSkypeForBusinessSkypeForConsumerr#   r$   r%   ri   ri   Q   s    G)))r$   ri   c                       e Zd ZddiZy)EventAttachmentattach/events/{id}/attachmentsN)r   r   r   
_endpointsr#   r$   r%   rq   rq   X   s    67Jr$   rq   c                       e Zd ZddddZeZy)EventAttachmentsrs   z/events/{id}/attachments/{ida}z,/events/{id}/attachments/createUploadSession)attachments
attachmentcreate_upload_sessionN)r   r   r   rt   rq   _attachment_constructorr#   r$   r%   rv   rv   \   s    16!OJ .r$   rv   c                       e Zd Zd Zy)DailyEventFrequencyc                      || _         || _        y N)recurrence_typeinterval)selfr   r   s      r%   __init__zDailyEventFrequency.__init__g   s    . r$   N)r   r   r   r   r#   r$   r%   r|   r|   f   s    !r$   r|   c                       e Zd Zd$ fd	Zd Zd Zd Zd Zed        Z	e	j                  d        Z	ed	        Zej                  d
        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zed        Zej                  d        Zed        Zej                  d        Zd Zd Zd%dZd Zd  Zdddd!d"Zdddd!d#Z xZS )&EventRecurrenceNc                    t         |   |j                  |j                         || _        |xs i }|j                  | j                  d      i       }|j                  | j                  d      d      | _        |j                  | j                  d      t                     | _	        |j                  | j                  d      d      | _
        |j                  dd      | _        | j                  rd|d   j                         vrd| _
        |j                  | j                  d	      d      | _        |j                  | j                  d
      d      | _        |j                  | j                  d      d      | _        |j                  | j                  d      i       }|j                  | j                  d      d      | _        |j                  | j                  d      d      | _        |j                  | j                  d      d      | _        |j                  | j                  d      t'        | j                  j(                              | _        |rm| j"                  r#t-        | j"                        j/                         nd| _        | j$                  r#t-        | j$                        j/                         nd| _        yy)z A representation of an event recurrence properties

        :param Event event: event object
        :param dict recurrence: recurrence information
        protocolmain_resourcepatternr   N
daysOfWeekfirstDayOfWeektypeweekly
dayOfMonthmonthindexfirstrangenumberOfOccurrences	startDateendDaterecurrenceTimeZone)superr   r   r   _eventget_cc_EventRecurrence__intervalset_EventRecurrence__days_of_week#_EventRecurrence__first_day_of_week!_EventRecurrence__recurrence_typelower_EventRecurrence__day_of_month_EventRecurrence__month_EventRecurrence__index_EventRecurrence__occurrences_EventRecurrence__start_date_EventRecurrence__end_dater   timezone&_EventRecurrence__recurrence_time_zoner   date)r   event
recurrencerecurrence_patternrecurrence_range	__class__s        r%   r   zEventRecurrence.__init__n   sY    	%..',':': 	 	< %2
'^^DHHY,?D,00*1EtL044TXXl5K58U<#5#9#9HH%&$. !3!7!7!E!!1&9??AA+/(044TXXl5K59;)--dhhw.?F)--dhhw.?I &>>$((7*;R@-11HH*+T3,00+1FM*..txx	/BDI&6&:&:HH)*4==112'4# -1->-> !&!!!##'46D  ,0?? $!!% O r$   c           	         | j                   sydj                  | j                   | j                   dk7  rdnd      }| j                  rdj                  t	        | j                              }dj                  | j
                  || j                   | j                   dk7  rdnd      }| j                  r/dj                  | j                   | j                   dk7  rdnd|      }n| j                  rd	j                  | j
                  || j                   | j                   dk7  rdndt        | j                  dz
           }n| j                  rd
j                  | j                  | j                   | j                   dk7  rdnd      }| j                  r;dj                  t        | j                  dz
     | j                  | j                         }d}| j                  rdj                  | j                        }d}| j                  rdj                  | j                        }n9| j                  r-dj                  | j                  | j                  dk7  rdnd      }dj                  ||      }dj                  ||      S )NzNo recurrence enabledzDaily: every {} day{}r   s z or z(Relative Monthly: {} {} every {} month{}zWeekly: every {} week{} on {}z,Relative Yearly: {} {} every {} year{} on {}z,Absolute Monthly: on day {} every {} month{}z)Absolute Yearly: on {} {} every {} year/szStarting on {}zwith no endzending on {}zup to {} occurrence{}z{} {}z{}. {})r   formatr   joinlistr   r   r   MONTH_NAMESr   r   r   r   )r   r   daysr_rangeends_ons        r%   __repr__zEventRecurrence.__repr__   s%   *)00OO??a'CR1 ;;tD$7$789D@GG!+	5G
 ''9@@OO??a/CR $fLLOO??a/CRq 013     &##!+5 
 ||$f[1A%B%)%8%8%)__6 
 &--d.?.?@G#G(//@##188&&--2C< nnWg6Gw00r$   c                 "    | j                         S r~   r   r   s    r%   __str__zEventRecurrence.__str__       }}r$   c                 ,    t        | j                        S r~   )boolr   r   s    r%   __bool__zEventRecurrence.__bool__   s    DOO$$r$   c                 N    | j                   j                  j                  d       y)X Update the track_changes on the event to reflect a needed
        update on this field r   N)r   _track_changesaddr   s    r%   r   zEventRecurrence._track_changes   s     	""&&|4r$   c                     | j                   S )z Repeat interval for the event

        :getter: Get the current interval
        :setter: Update to a new interval
        :type: int
        )r   r   s    r%   r   zEventRecurrence.interval        r$   c                 2    || _         | j                          y r~   )r   r   r   values     r%   r   zEventRecurrence.interval   s    r$   c                     | j                   S )z Days in week to repeat

        :getter: Get the current list of days
        :setter: Set the list of days to repeat
        :type: set(str)
        )r   r   s    r%   days_of_weekzEventRecurrence.days_of_week        """r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   zEventRecurrence.days_of_week       #r$   c                     | j                   S )z Which day to consider start of the week

        :getter: Get the current start of week
        :setter: Set the start day of week
        :type: str
        )r   r   s    r%   first_day_of_weekz!EventRecurrence.first_day_of_week        '''r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   z!EventRecurrence.first_day_of_week  s    #( r$   c                     | j                   S )z Repeat on this day of month

        :getter: Get the repeat day of month
        :setter: Set the repeat day of month
        :type: int
        )r   r   s    r%   day_of_monthzEventRecurrence.day_of_month  r   r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   zEventRecurrence.day_of_month  r   r$   c                     | j                   S )zi Month of the event

        :getter: Get month
        :setter: Update month
        :type: int
        )r   r   s    r%   r   zEventRecurrence.month       ||r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   zEventRecurrence.month$      r$   c                     | j                   S )zY Index

        :getter: Get index
        :setter: Set index
        :type: str
        )r   r   s    r%   r   zEventRecurrence.index)  r   r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   zEventRecurrence.index3  r   r$   c                     | j                   S )z No. of occurrences

        :getter: Get the no. of occurrences
        :setter: Set the no. of occurrences
        :type: int
        )r   r   s    r%   occurrenceszEventRecurrence.occurrences8       !!!r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   zEventRecurrence.occurrencesB  s    "r$   c                     | j                   S )z Timezone to consider for repeating

        :getter: Get the timezone
        :setter: Set the timezone
        :type: str
        )r   r   s    r%   recurrence_time_zonez$EventRecurrence.recurrence_time_zoneG  s     ***r$   c                 2    || _         | j                          y r~   )r   r   r   s     r%   r   z$EventRecurrence.recurrence_time_zoneQ  s    &+#r$   c                     | j                   S )zYType of the recurrence pattern

        :getter: Get the type
        :type: str
        )r   r   s    r%   r   zEventRecurrence.recurrence_typeV  s     %%%r$   c                     | j                   S )z Start date of repetition

        :getter: get the start date
        :setter: set the start date
        :type: date
        )r   r   s    r%   
start_datezEventRecurrence.start_date_          r$   c                     t        |t        j                        st        d      t        |t        j                        r|j                         }|| _        | j                          y )Nz,start_date value must be a valid date object)
isinstancedtr   
ValueErrordatetimer   r   r   s     r%   r   zEventRecurrence.start_datei  sI    %)KLLeR[[)JJLE!r$   c                     | j                   S )zy End date of repetition

        :getter: get the end date
        :setter: set the end date
        :type: date
        )r   r   s    r%   end_datezEventRecurrence.end_dater  r   r$   c                     t        |t        j                        st        d      t        |t        j                        r|j                         }|| _        | j                          y )Nz*end_date value must be a valid date object)r   r   r   r   r   r   r   r   s     r%   r   zEventRecurrence.end_date|  sH    %)IJJeR[[)JJLEr$   c                 P   i }| j                   rot        | j                   t              rTi x}|| j                  d      <   d|| j                  d      <   | j                   || j                  d      <   | j                  rOt        | j                  t
        t        t        f      r)d|| j                  d      <   t        | j                        || j                  d      <   | j                  r4d|| j                  d      <   | j                  || j                  d      <   n^| j                  rwt        | j                  t              r]d	|| j                  d      <   | j                  || j                  d
      <   | j                  r| j                  || j                  d      <   n| j                  r| j                  || j                  d      <   n| j                  rt        | j                  t              rd|| j                  d      <   | j                  || j                  d      <   | j                  rLt        | j                  t              r2d|| j                  d      <   | j                  || j                  d
      <   | j                  ri x}|| j                  d      <   d|| j                  d      <   | j                  j                         || j                  d      <   | j                  || j                  d      <   | j                  rBd|| j                  d      <   | j                  j                         || j                  d      <   |S | j                   Lt        | j                   t              r2d|| j                  d      <   | j                   || j                  d      <   |S )M Returns a dict to communicate with the server

        :rtype: dict
        r   dailyr   r   relativeMonthlyr   r   r   relativeYearlyr   r   absoluteMonthlyr   absoluteYearlyr   noEndr   r   r   numberedr   )r   r   intr   r   r   tupler   r   r   r   r   r   	isoformatr   r   r   )r   datar   r   s       r%   to_api_datazEventRecurrence.to_api_data  s'   
 ??z$//3?=??dhhy&9!:3:txx/07;txx
34""z$2E2E372D(F7H"488F#34=A''>)"488L#9:++;C&txx'786:6N6N '!124\\js&C;K&txx'78<@LL&txx'89||@D*488G+<=||@D*488G+<=$$D4G4G)M7H"488F#34=A=P=P"488L#9:<<Jt||S$A;K&txx'78<@LL&txx'89 9;;tDHHW$5618TXXf-.)-):):)D)D)F %' 372M2M -.0 5> &!12+/??+D+D+F !HHY')  ##/J&&5 6@ &!127;7I7I !HH235 r$   c                     d| _         t               | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        y)z Clears this event recurrence Nr   )
r   r   r   r   r   r   r   r   r   r   r   s    r%   _clear_patternzEventRecurrence._clear_pattern  sJ     !e#' " !r$   c                     |0| j                   +t        j                  j                         | _         n|| _        |r|| _        n	|r|| _        | j                          y)z Set the range of recurrence

        :param date start: Start date of repetition
        :param date end: End date of repetition
        :param int occurrences: no of occurrences
        N)r   r   r   todayr   r   r   r   )r   startendr   s       r%   	set_rangezEventRecurrence.set_range  sO     =  ($&GGMMO!#DODM!,Dr$   c                 V    | j                          || _         | j                  di | y)a   Set to repeat every x no. of days

        :param int interval: no. of days to repeat at
        :keyword date start: Start date of repetition (kwargs)
        :keyword date end: End date of repetition (kwargs)
        :keyword int occurrences: no of occurrences (kwargs)
        Nr#   )r   r   r  )r   r   kwargss      r%   	set_dailyzEventRecurrence.set_daily  s(     	"  r$   c                X     | j                   |fi | t        |      | _        || _        y)a   Set to repeat every week on specified days for every x no. of days

        :param int interval: no. of days to repeat at
        :param str first_day_of_week: starting day for a week
        :param list[str] days_of_week: list of days of the week to repeat
        :keyword date start: Start date of repetition (kwargs)
        :keyword date end: End date of repetition (kwargs)
        :keyword int occurrences: no of occurrences (kwargs)
        N)r  r   r   r   )r   r   r   r   r  s        r%   
set_weeklyzEventRecurrence.set_weekly  s,     	x*6*!,/#4 r$   r   r   r   c                    |s|st        d      |r|rt        d       | j                  |fi | |r|| _        y|rt        |      | _        |r|| _        yyy)a   Set to repeat every month on specified days for every x no. of days

        :param int interval: no. of days to repeat at
        :param int day_of_month: repeat day of a month
        :param list[str] days_of_week: list of days of the week to repeat
        :param index: index
        :keyword date start: Start date of repetition (kwargs)
        :keyword date end: End date of repetition (kwargs)
        :keyword int occurrences: no of occurrences (kwargs)
        z0Must provide day_of_month or days_of_week valuesz(Must provide only one of the two optionsN)r   r  r   r   r   r   )r   r   r   r   r   r  s         r%   set_monthlyzEventRecurrence.set_monthly  sh     LOPPLGHHx*6*".D"%l"3D$  r$   c                @     | j                   |f|||d| || _        y)a   Set to repeat every month on specified days for every x no. of days

        :param int interval: no. of days to repeat at
        :param int month: month to repeat
        :param int day_of_month: repeat day of a month
        :param list[str] days_of_week: list of days of the week to repeat
        :param index: index
        :keyword date start: Start date of repetition (kwargs)
        :keyword date end: End date of repetition (kwargs)
        :keyword int occurrences: no of occurrences (kwargs)
        r
  N)r  r   )r   r   r   r   r   r   r  s          r%   
set_yearlyzEventRecurrence.set_yearly  s4     	 	K&2%	KCI	Kr$   r~   NNN)r   r   r   r   r   r   r   r   propertyr   setterr   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  __classcell__r   s   @r%   r   r   m   s4   /Eb21h%5
   __  # #   ( (   # #     \\    \\  " "   + +    ! & & ! !     __ 8t"&
!5 59t%0 ;? $D r$   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )ResponseStatusz) An event response status (status, time) c                    t         |   |j                  |j                         |xs i j	                  | j                  d      d      | _        | j                  dk(  rdnt        j                  | j                        | _        | j                  r|j	                  | j                  d      d      | _	        | j                  dk(  rd| _	        | j                  r?	 t        | j                        j                  | j                  j                        | _	        yyd| _	        y# t        $ r, t        j                  d| j                          d| _	        Y yw xY w)z An event response status (status, time)

        :param parent: parent of this
        :type parent: Attendees or Event
        :param dict response_status: status info frm cloud
        r   responsenoneNtimez0001-01-01T00:00:00Zz$Couldn't parse event response time: )r   r   r   r   r   r   statusr   
from_valueresponse_timer   
astimezoner   OverflowErrorlogdebug)r   parentresponse_statusr   s      r%   r   zResponseStatus.__init__(  s,    	&//'-';'; 	 	= ',"11HHZ &
 #kkV3d9Q9QRVR]R]9^;;!0!4!4TXXf5Et!LD!!%;; &*"!!.).t/A/A)B)M)MdmmNdNd)eD& " "&D	 % .II DTEWEWDXYZ)-D&.s   =D" "2EEc                 "    | j                   xs dS )NNone)r  r   s    r%   r   zResponseStatus.__repr__G  s    {{$f$r$   c                 "    | j                         S r~   r   r   s    r%   r   zResponseStatus.__str__J  r   r$   )r   r   r   __doc__r   r   r   r  r  s   @r%   r  r  %  s    3&>%r$   r  c                       e Zd ZdZddddddZd Zd Zed        Zej                  d        Zed	        Z
e
j                  d
        Z
d Zed        Zed        Zej                  d        Zy)Attendeez A Event attendee N)nameattendee_typer"  r   c                    d| _         || _        || _        || _        t	        |t
              r|| _        nd| _        t        j                  | _	        |r|| _
        d| _         y)aU   Create a event attendee

        :param str address: email address of the attendee
        :param str name: name of the attendee
        :param AttendeeType attendee_type: requirement of attendee
        :param Response response_status: response status requirement
        :param Event event: event for which to assign the attendee
        TNF)_untrack_address_namer   r   r  _Attendee__response_statusr'   r+   _Attendee__attendee_typer*  )r   addressr)  r*  r"  r   s         r%   r   zAttendee.__init__Q  sZ     
o~6%4D"%)D"+44!.Dr$   c                     | j                   r;dj                  | j                  j                   | j                   | j                        S dj                  | j                  j                   | j                        S )Nz{}: {} ({})z{}: {})r)  r   r*  r1  r   s    r%   r   zAttendee.__repr__h  sZ    99 ''(:(:(?(?(,6 6 ??4#5#5#:#:DLLIIr$   c                 "    | j                         S r~   r   r   s    r%   r   zAttendee.__str__o  r   r$   c                     | j                   S )z Email address

        :getter: Get the email address of attendee
        :setter: Set the email address of attendee
        :type: str
        )r-  r   s    r%   r1  zAttendee.addressr  s     }}r$   c                 @    || _         d| _        | j                          y )Nr   )r-  r.  r   r   s     r%   r1  zAttendee.address|  s    
r$   c                     | j                   S )zv Name

        :getter: Get the name of attendee
        :setter: Set the name of attendee
        :type: str
        )r.  r   s    r%   r)  zAttendee.name       zzr$   c                 2    || _         | j                          y r~   )r.  r   r   s     r%   r)  zAttendee.name  s    
r$   c                 l    | j                   du r&| j                  j                  j                  d       yy)zX Update the track_changes on the event to reflect a
        needed update on this field F	attendeesN)r,  r   r   r   r   s    r%   r   zAttendee._track_changes  s-     ==E!KK&&**;7 "r$   c                     | j                   S )zH Response status of the attendee

        :type: ResponseStatus
        )r/  r   s    r%   r"  zAttendee.response_status       %%%r$   c                     | j                   S )z Requirement of the attendee

        :getter: Get the requirement of attendee
        :setter: Set the requirement of attendee
        :type: AttendeeType
        )r0  r   s    r%   r*  zAttendee.attendee_type  s     ###r$   c                     t        |t              r|| _        nt        j                  |      | _        | j	                          y r~   )r   r'   r0  r  r   r   s     r%   r*  zAttendee.attendee_type  s3    e\*#(D #/#:#:5#AD r$   )r   r   r   r&  r   r   r   r  r1  r  r)  r   r"  r*  r#   r$   r%   r(  r(  N  s    (,D!%T.J   ^^ 
   
[[ 8 & & $ $  r$   r(  c                   f     e Zd ZdZd fd	Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z xZS )	Attendeesz A Collection of Attendees c                     t         |   |j                  |j                         || _        g | _        d| _        |r| j                  |       d| _        y)a   Create a collection of attendees

        :param Event event: event for which to assign the attendees
        :param attendees: list of attendees to add
        :type attendees: str or tuple(str, str) or Attendee or list[str] or
         list[tuple(str,str)] or list[Attendee]
        r   TFN)r   r   r   r   r   _Attendees__attendeesuntrackr   )r   r   r:  r   s      r%   r   zAttendees.__init__  sR     	%..',':': 	 	<HHYr$   c                 ,    t        | j                        S r~   )iterrB  r   s    r%   __iter__zAttendees.__iter__  s    D$$%%r$   c                      | j                   |   S r~   )rB  )r   keys     r%   __getitem__zAttendees.__getitem__  s    $$r$   c                 X    || j                   D ch c]  }|j                   c}v S c c}w r~   )rB  r1  )r   itemattendees      r%   __contains__zAttendees.__contains__  s'    9I9IJX((JJJJs   'c                 ,    t        | j                        S r~   )lenrB  r   s    r%   __len__zAttendees.__len__  s    4##$$r$   c                 "    | j                         S r~   r   r   s    r%   r   zAttendees.__str__  r   r$   c                 J    dj                  t        | j                              S )NzAttendees Count: {})r   rO  rB  r   s    r%   r   zAttendees.__repr__  s    $++C0@0@,ABBr$   c                 2    g | _         | j                          y)z Clear the attendees list N)rB  r   r   s    r%   clearzAttendees.clear  s    r$   c                 l    | j                   du r&| j                  j                  j                  d       yy)r   Fr:  N)rC  r   r   r   r   s    r%   r   zAttendees._track_changes  s-     <<5 KK&&**;7 !r$   c                    |rBt        |t              rA| j                  j                  t	        || j
                               | j                          yt        |t              r,| j                  j                  |       | j                          yt        |t              rJ|\  }}|rB| j                  j                  t	        ||| j
                               | j                          yyt        |t              r|D ]  }| j                  |        yt        |t              r| j                  |v r|j                  | j                        }|D ]  }|j                  | j                  d      i       }|j                  | j                  d      d      }|sH|j                  | j                  d      d      }|j                  | j                  d      d      }| j                  j                  t	        |||| j
                  t        | |j                  | j                  d	      i       
                    yt        d      y)z Add attendees to the parent event

        :param attendees: list of attendees to add
        :type attendees: str or tuple(str, str) or Attendee or list[str] or
         list[tuple(str,str)] or list[Attendee]
        )r1  r   )r1  r)  r   emailAddressr1  Nr)  r   r(   r  r!  r"  )r1  r)  r*  r   r"  z\Attendees must be an address string, an Attendee instance, a (name, address) tuple or a list)r   strrB  appendr(  r   r   r   r   r   dict_cloud_data_keyr   r   r  r   )r   r:  r)  r1  rL  emailr*  s          r%   r   zAttendees.add  s    )S)  ''YdkkBD##%Ix0  ''	2##%Iu- )g$$++ t4;;OQ'')  It, ) 'HHHX&'I "&*&:&:i&G%MM$*>*>?	 ) ?H$LL.)A2FE#ii(;TBG$yy&)94@(0TXXf5E5?)A((//$W43@+/;;%344<LL8<8J8:5<&=	>	??& ! "3 4 4O r$   c                    t        |t        t        f      r,|D ch c]   }t        |t              r|j                  n|" }}n=t        |t
              r|h}n)t        |t              r|j                  h}nt        d      g }| j                  D ]"  }|j                  |vs|j                  |       $ || _        | j                          yc c}w )z Remove the provided attendees from the event

        :param attendees: list of attendees to add
        :type attendees: str or tuple(str, str) or Attendee or list[str] or
         list[tuple(str,str)] or list[Attendee]
        z&Incorrect parameter type for attendeesN)
r   r   r   r(  r1  rY  r   rB  rZ  r   )r   r:  rL  new_attendeess       r%   removezAttendees.remove  s     i$/ &'  %/x$B  P'I ' 	3'"I	8,"**+IEFF(( 	/Hy0$$X.	/ )!'s   %Cc                 b   g }| j                   D ]  }|j                  s| j                  d      | j                  d      |j                  | j                  d      |j                  i| j                  d      | j                  |j                  j
                        i}|j                  |        |S )r   rW  r1  r)  r   )rB  r1  r   r)  r*  r   rZ  )r   r   rL  att_datas       r%   r   zAttendees.to_api_data/  s    
 (( 		&HHH^,+X-=-=((--/ HHV$dhhx/E/E/K/K&L H%		& r$   r~   )r   r   r   r&  r   rF  rI  rM  rP  r   r   rT  r   r   r`  r   r  r  s   @r%   r@  r@    sE    %"&%K%C
804d4r$   r@  c                       e Zd ZdZddddddZddd	 fd

Zd Zd Zd ZdFdZ	e
d        Ze
d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d         Ze
d!        Zej                  d"        Ze
d#        Zej                  d$        Ze
d%        Zej                  d&        Ze
d'        Ze
d(        Ze
d)        Zej                  d*        Ze
d+        Zej                  d,        Ze
d-        Ze
d.        Ze
d/        Ze
d0        Z e j                  d1        Z e
d2        Z!e
d3        Z"e"j                  d4        Z"e
d5        Z#e#j                  d6        Z#e
d7        Z$e$j                  d8        Z$ddddd9d:Z%d; Z&d< Z'dFd=d>d?d@Z(dFd=dAdBZ)dFd=dAdCZ*dD Z+dE Z, xZ-S )GEventz A Calendar event /calendars/{id}z/events/{id}/calendar/events/calendars/{id}/eventsz/events/{id}/instances)calendarr   event_defaultevent_calendarr   Nr!  conc          	         |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       | j                  }t        |      | _
        |j                  dd      | _        |j                  d      }|j                  | j                  i       }|j                   |d	      d      | _        |j                   |d
      d      | _        |j                   |d      |j                  dd      xs d      | _        |j                   |d      i       xs i }|j                   |d      d      | _        |j                   |d      d      | _        t%        | | j                  |j                   |d      g       i      | _        |j                   |d      g       | _        |j                   |d      d      | _        |j                   |d      d      | _        | j                  j.                  }	| j*                  r$t1        | j*                        j3                  |	      nd| _        | j,                  r$t1        | j,                        j3                  |	      nd| _        |j                   |d      d      | _        |j                   |d      i       }
| j7                  |
| j4                        | _        |j                   |d      i       }| j7                  || j4                        | _        |j                   |d      d      | _        t?        | g       | _         | j<                  r|r| jB                  jE                          |j                   |d      g       | _        |j                   |d      d      | _#        tI        jJ                  |j                   |d      d      xs d      | _&        |j                   |d      d      | _'        |j                   |d       d!      | _(        |j                   |d"      i       | _)        |j                   |d#      g       | _*        |j                   |d$      d      | _+        |j                   |d%      d      | _,        tZ        jK                  |j                   |d&      d'            | _.        |j                   |d(      d      | _/        | jV                  sA| j`                  r5| j^                  r"| j^                  j                   |d)      d      nd| _+        | jc                  |j                   |d*      d       |d*      +      | _2        tg        | |j                   |d,      d      -      | _4        |j                   |d.      d!      | _5        |j                   |d/      d0      | _6        |j                   |d1      d!      | _7        tq        | |j                   |d2      i       3      | _9        tt        jK                  |j                   |d4      d            | _;        |j                   |d5      d      | _<        tz        jK                  |j                   |d6      d7            | _>        t~        jK                  |j                   |d8      d9            | _@        d| _A        |j                   |d:      d      | _B        y);a   Create a calendar event representation

        :param parent: parent for this operation
        :type parent: Calendar or Schedule or ApiComponent
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        :param str calendar_id: id of the calender to add this event in
         (kwargs)
        :param bool download_attachments: whether or not to download attachments
         (kwargs)
        :param str subject: subject of the event (kwargs)
        *Need a parent or a connection but not bothr   Nr   r   )casingcalendar_iddownload_attachmentsidtransactionIdsubjectr   bodycontentcontentTypeHTMLr:  )r   r:  
categoriescreatedDateTimelastModifiedDateTimeisAllDayFr  r  hasAttachments)r!  rw   iCalUId
importancer0   isCancelledisOrganizerTlocation	locationsonlineMeetingUrlisOnlineMeetingonlineMeetingProviderrj   onlineMeetingjoinUrlr   fieldr   )r   r   isReminderOnreminderMinutesBeforeStart   responseRequestedresponseStatusrX  sensitivityseriesMasterIdshowAsr<   r   r`   webLink)Cr   rl  popgetattrr   r   r   r   r   r   r   rp  r\  	object_id_Event__transaction_id_Event__subject_Event__body	body_typer@  _Event__attendees_Event__categories_Event__created_Event__modifiedr   r   r  _Event__is_all_day_parse_date_time_time_zone_Event__start_Event__endhas_attachmentsrv   _Event__attachmentsrw   rq  ical_uidr   r  _Event__importanceis_cancelledis_organizer_Event__locationr  online_meeting_url_Event__is_online_meetingri   _Event__online_meeting_provideronline_meetingis_online_meeting_recipient_from_cloud_Event__organizerr   _Event__recurrence_Event__is_reminder_on_Event__remind_before_minutes_Event__response_requestedr  _Event__response_statusr/   _Event__sensitivityseries_master_idr9   _Event__show_asr_   _Event__event_type_Event__no_forwardingweb_link)r   r!  rl  r  r   ccrq  
cloud_dataru  local_tz	start_objend_objr   s               r%   r   zEvent.__init__N  s     cIJJ!'6::S 

?D9 H6<GFOT2$ 	 	(.V__FJJz4J' 	 	) XX(3!::mT:%zz*@AZZ 4 4b9
 $4$7 *r//BD I#9(.

9b(A(GRI r&z2.4" 	 hhr)}b1"]"3"(* %4  *..K""E<G H&NN2l+;R@#+<(=tD$..,B)CTJ==)) t~~.99-1 	   0;;.2 	 'NN2j>5ANN2g;3	66y$BSBST..EB/44Wd>O>OP
  *~~b1A.BEJ-TrJ$8113&NN2l+;R@"r)}d;+66NN2l+X6B(D 'NN2m+<eD 'NN2m+<dC$..J<#;< #-..4F1G"N#->>"5F2G#O )B)M)MNN2568JK*M& )nnR-@$G&&4+A+A&& '+&9&9&=&=bmT&R,0 #  55NN2k?D1K 6 J+$7A~~02<0@$8HI !+r./A4 H'1~~+,b(2$$.NN26I3J37%9!!/t@J467G4H"AN"O .88NN2m,h79 !+r2B/CT J$//
r(|V0TU%006
L\1]^$"r)}d;r$   c                 "    | j                         S r~   r   r   s    r%   r   zEvent.__str__  r   r$   c                 6   | j                   j                         | j                  j                         k(  rfdj                  | j                  | j                   j                         | j                   j                         | j                  j                               S dj                  | j                  | j                   j                         | j                   j                         | j                  j                         | j                  j                               S )Nz$Subject: {} (on: {} from: {} to: {})z+Subject: {} (starts: {} {} and ends: {} {}))r  r   r  r   rt  r  r   s    r%   r   zEvent.__repr__  s    ::??/9@@tzzO`bfblblbqbqbsAER R AGGVZV`V`VeVeVgHL

HY[_[c[c[h[h[jHLY Yr$   c                 4    | j                   |j                   k(  S r~   )r  r   others     r%   __eq__zEvent.__eq__  s    ~~00r$   c                    | j                   }| j                  r<t        | j                  t              r| j                  }n |d      | j                  i}n
 |d      di}i  |d      | j                   |d      | j
                   |d       |d      | j                   |d      | j                  i |d      | j                  | j                         |d	      | j                  | j                         |d
      | j                  j                          |d      | |d      | j                   |d      | j                   |d       || j                  j                          |d      | j"                   |d      | j$                   |d      | j&                   |d       || j(                  j                          |d       || j*                  j                          |d       || j,                         |d       || j.                  j                          |d      d || j0                        dgi}| j2                  r#| j2                  j                         | |d      <   | j4                  r#| j6                  j                         | |d      <   |rDd|v r| j8                  j;                          t=        |j?                               D ]
  }||vs||=  |S )z Returns a dict to communicate with the server

        :param restrict_keys: a set of keys to restrict the returned data to
        :rtype: dict
        displayNamer   rs  rt  ru  rw  rv  r  r  r:  r  ry  r|  r  r  r  r  r  r  r  r  SingleValueExtendedPropertiesz@Boolean {00020329-0000-0000-C000-000000000046} Name DoNotForward)rr  r   r   rw   ) r   r  r   r[  r  r  r  r  _build_date_time_time_zoner  r  r  r   r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  rw   _update_attachments_to_cloudr   keys)r   restrict_keysr  r  r   rH  s         r%   r   zEvent.to_api_data  s    XX??$//40??}-t?=)2.H
!6!6
yM4>>
 vJ=!4>>9t{{,
 wK88F
 uIt66tzzB
 {OT--99;
 zNH
 |d//
 zND--
 |b!2!2!8!89
 ~ 5 5
 +,d.J.J
 "#T%>%>
  }r$"4"4":":;!
" xL"T^^112#
$  !2d&>&>#?%
& &'D,J,J,P,P)Q'
( ./\ 4 452)
8 %)%6%6%B%B%DDL!"&*&8&8&D&D&FDM"#-  ==?DIIK( "m+S	" r$   c                     | j                   S )z= Created time of the event

        :rtype: datetime
        )r  r   s    r%   createdzEvent.created  s     ~~r$   c                     | j                   S )zC Last modified time of the event

        :rtype: datetime
        )r  r   s    r%   modifiedzEvent.modified  s     r$   c                     | j                   S )zq Body of the event

        :getter: Get body text
        :setter: Set body of event
        :type: str
        )r  r   s    r%   ru  z
Event.body#  s     {{r$   c                 f    || _         | j                  j                  | j                  d             y )Nru  )r  r   r   r   r   s     r%   ru  z
Event.body-  s&     01r$   c                     | j                   S )zu Subject of the event

        :getter: Get subject
        :setter: Set subject of event
        :type: str
        )r  r   s    r%   rt  zEvent.subject2       ~~r$   c                 f    || _         | j                  j                  | j                  d             y )Nrt  )r  r   r   r   r   s     r%   rt  zEvent.subject<  s&     34r$   c                     | j                   S )zTransaction Id of the event

        :getter: Get transaction_id
        :setter: Set transaction_id of event - can only be set for event creation
        :type: str
        )r  r   s    r%   transaction_idzEvent.transaction_idA       $$$r$   c                     | j                   r|| j                  k7  rt        d      || _        | j                  j	                  | j                  d             y )Nz1Cannot change transaction_id after event creationrs  )r  r  r   r   r   r   r   s     r%   r  zEvent.transaction_idK  sG    >>et'<'<<PQQ % 9:r$   c                     | j                   S )z~ Start Time of event

        :getter: get the start time
        :setter: set the start time
        :type: datetime
        )r  r   s    r%   r  zEvent.startR  r   r$   c                 f   t        |t        j                        st        d      t        |t        j                        s5t        j                  |j
                  |j                  |j                        }|j                  '|j                  | j                  j                        }n%t        |j                  t              st        d      || _        | j                  s(| j                  t        j                  d      z   | _        | j                   j#                  | j%                  d             y )Nz''start' must be a valid datetime objecttzinfo0TimeZone data must be set using ZoneInfo objects   )minutesr  )r   r   r   r   r   yearr   dayr  replacer   r   r   r  r  	timedeltar   r   r   r   s     r%   r  zEvent.start\  s    %)FGG%-KK

EKKCE<<MM)?)?M@EellH5 !STTxx||bll2&>>DH 12r$   c                     | j                   S )zx End Time of event

        :getter: get the end time
        :setter: set the end time
        :type: datetime
        )r  r   s    r%   r  z	Event.endn  r7  r$   c                    t        |t        j                        st        d      t        |t        j                        s5t        j                  |j
                  |j                  |j                        }|j                  '|j                  | j                  j                        }n%t        |j                  t              st        d      || _        | j                  j                  | j!                  d             y )Nz%'end' must be a valid datetime objectr  r  r  )r   r   r   r   r   r  r   r  r  r  r   r   r   r  r   r   r   r   s     r%   r  z	Event.endx  s    %)DEE%-KK

EKKCE<<MM)?)?M@EellH5 !STT
0r$   c                     | j                   S )z Event Priority

        :getter: get importance of event
        :setter: set the importance of event
        :type: ImportanceLevel
        )r  r   s    r%   r  zEvent.importance  r   r$   c                     t        |t              r|nt        j                  |      | _        | j                  j                  | j                  d             y )Nr  )r   r   r  r  r   r   r   r   s     r%   r  zEvent.importance  sA    &0&HU"1"<"<U"C 	 67r$   c                     | j                   S )z Is the event for whole day

        :getter: get the current status of is_all_day property
        :setter: set if the event is all day or not
        :type: bool
        )r  r   s    r%   
is_all_dayzEvent.is_all_day  r   r$   c                 v   || _         |r| j                  xs t        j                  j	                         }| j
                  xs t        j                  j	                         }|t        j                  d      z   |kD  r|t        j                  d      z   }t        j                  |j                  |j                  |j                        }t        j                  |j                  |j                  |j                        }|| _        || _        | j                  j                  | j                  d             y )N   )hoursr|  )r  r  r   r   r  r  r  r   r  r   r  r  r  r   r   r   )r   r   r  r  s       r%   r  zEvent.is_all_day  s    ! LL3BGGMMOE**/C2..#5 bll44 KK

EKKCE++chh		377;CDJDH 45r$   c                     | j                   S )z Location of event

        :getter: get current location configured for the event
        :setter: set a location for the event
        :type: str
        )r  r   s    r%   r  zEvent.location  r   r$   c                 f    || _         | j                  j                  | j                  d             y )Nr  )r  r   r   r   r   s     r%   r  zEvent.location  s&     45r$   c                     | j                   S )z Status of the Reminder

        :getter: check is reminder enabled or not
        :setter: enable or disable reminder option
        :type: bool
        )r  r   s    r%   is_reminder_onzEvent.is_reminder_on  r  r$   c                     || _         | j                  j                  | j                  d             | j                  j                  | j                  d             y )Nr  r  )r  r   r   r   r   s     r%   r  zEvent.is_reminder_on  sE     % 89)E FGr$   c                     | j                   S )z No. of minutes to remind before the meeting

        :getter: get current minutes
        :setter: set to remind before new x minutes
        :type: int
        )r  r   s    r%   remind_before_minuteszEvent.remind_before_minutes  s     +++r$   c                     d| _         t        |      | _        | j                  j	                  | j                  d             | j                  j	                  | j                  d             y )NTr  r  )r  r   r  r   r   r   r   s     r%   r  zEvent.remind_before_minutes  sQ     $'*5z$ 89)E FGr$   c                     | j                   S )z Is response requested or not

        :getter: Is response requested or not
        :setter: set the event to request response or not
        :type: bool
        )r  r   s    r%   response_requestedzEvent.response_requested  s     (((r$   c                 f    || _         | j                  j                  | j                  d             y )Nr  )r  r   r   r   r   s     r%   r  zEvent.response_requested  s(    $)!)< =>r$   c                     | j                   S )zN Recurrence information of the event

        :rtype: EventRecurrence
        )r  r   s    r%   r   zEvent.recurrence  s        r$   c                     | j                   S )zC Organizer of the meeting event

        :rtype: Recipient
        )r  r   s    r%   r   zEvent.organizer        r$   c                     | j                   S )z Show as "busy" or any other status during the event

        :getter: Current status during the event
        :setter: update show as status
        :type: EventShowAs
        )r  r   s    r%   show_aszEvent.show_as  r  r$   c                     t        |t              r|nt        j                  |      | _        | j                  j                  | j                  d             y )Nr  )r   r9   r  r  r   r   r   r   s     r%   r  zEvent.show_as  s@    #-e[#A%*55e< 	 23r$   c                     | j                   S )z Sensitivity of the Event

        :getter: Get the current sensitivity
        :setter: Set a new sensitivity
        :type: EventSensitivity
        )r  r   s    r%   r  zEvent.sensitivity  r   r$   c                     t        |t              r|nt        j                  |      | _        | j                  j                  | j                  d             y )Nr  )r   r/   r  r  r   r   r   r   s     r%   r  zEvent.sensitivity"  sB    '1%9I'Je#3#>#>u#E 	 78r$   c                     | j                   S )z7 Your response

        :rtype: ResponseStatus
        )r  r   s    r%   r"  zEvent.response_status(  r<  r$   c                     | j                   S )z? List of attachments

        :rtype: EventAttachments
        )r  r   s    r%   rw   zEvent.attachments0  s     !!!r$   c                     | j                   S )z> List of meeting attendees

        :rtype: Attendees
        )r  r   s    r%   r:  zEvent.attendees8  r  r$   c                     | j                   S )z Categories of the event

        :getter: get the list of categories
        :setter: set the list of categories
        :type: list[str]
        )r  r   s    r%   ry  zEvent.categories@  r   r$   c                    t        |t              r`g | _        |D ]S  }t        |t              r&| j                  j	                  |j
                         9| j                  j	                  |       U nGt        |t              r	|g| _        n.t        |t              r|j
                  g| _        nt        d      | j                  j                  | j                  d             y )Nzcategories must be a listry  )r   r   r  r   rZ  r)  rY  r   r   r   r   )r   r   vals      r%   ry  zEvent.categoriesJ  s    eT" "D 2c8,%%,,SXX6%%,,S1	2
 s#!&Dx(!&D899 67r$   c                     | j                   S r~   )r  r   s    r%   
event_typezEvent.event_type[  s       r$   c                     | j                   S )z Status of the online_meeting

        :getter: check is online_meeting enabled or not
        :setter: enable or disable online_meeting option
        :type: bool
        )r  r   s    r%   r  zEvent.is_online_meeting_  r   r$   c                 f    || _         | j                  j                  | j                  d             y )Nr  )r  r   r   r   r   s     r%   r  zEvent.is_online_meetingi  s(    #( ): ;<r$   c                     | j                   S )z online_meeting_provider of event

        :getter: get current online_meeting_provider configured for the event
        :setter: set a online_meeting_provider for the event
        :type: OnlineMeetingProviderType
        )r  r   s    r%   online_meeting_providerzEvent.online_meeting_providern  s     ---r$   c                     t        |t              r|nt        j                  |      | _        | j                  j                  | j                  d             y )Nr  )r   ri   r  r  r   r   r   r   s     r%   r  zEvent.online_meeting_providerx  sD    3=eE^3_%/H/S/STY/Z 	&)@ ABr$   c                     | j                   S r~   )r  r   s    r%   no_forwardingzEvent.no_forwarding~  s    ###r$   c                 H    || _         | j                  j                  d       y )Nr  )r  r   r   r   s     r%   r  zEvent.no_forwarding  s    $ ?@r$   )limitqueryorder_bybatchc                Z     j                   t        j                  k7  rg S  j                   j                  j                  d      j                   j                              }|| j                  j                  kD  r j                  j                  }d|r|n|i}|r||d<   |r5t        |t              r||d<   n|j                  |j                                t        |t        j                        r5t        j                   |j"                  |j$                  |j&                        }|j(                  &|j+                   j                  j,                        }t        |t        j                        r5t        j                   |j"                  |j$                  |j&                        }|j(                  &|j+                   j                  j,                        }|j/                         | j1                  d      <   |j/                         | j1                  d	      <    j2                  j                  ||
      }	|	st5        d      S |	j7                         }
 fd|
j                  dg       D        }|
j                  t8        d      }|r|rt;         | j<                  ||      S |S )a  
        Returns all the occurrences of a seriesMaster event for a specified time range.

        :type start: datetime
        :param start: the start of the time range
        :type end: datetime
        :param end: the end of the time range
        :param int limit: ax no. of events to get. Over 999 uses batch.
        :type query: Query or str
        :param query: optional. extra filters or ordes to apply to this query
        :type order_by: str
        :param order_by: orders the result set based on this condition
        :param int batch: batch size, retrieves items in
             batches allowing to retrieve more items than the limit.
        :return: a list of events
        :rtype: list[Event] or Pagination
        r   rr  N$top$orderby$filterr  startDateTimeendDateTimeparamsr#   c              3   ^   K   | ]$  } j                   dd ij                  |i & yw)r!  Nr#   )r   r\  ).0r   r   s     r%   	<genexpr>z(Event.get_occurrences.<locals>.<genexpr>  s7      6 !$..NN1E1Eu0MN 6s   *-r   r!  r   constructor	next_linkr  )r	  r_   rg   	build_urlrt   r   r   r  r   max_top_valuer   rY  update	as_paramsr   r   r   r  r   r  r  r  r   r   r   rl  rE  jsonr   r   r   )r   r  r  r  r  r  r  urlr  r  r   eventsr$  s   `            r%   get_occurrenceszEvent.get_occurrences  s   $ ??i444InnOO.555HJ =EDMM$?$??MM//E5%e4!)F:%%$)y!eoo/0eRWW%KK

EKKCE<<MM)?)?M@Ec277#++chh		377;C::++T]]%;%;+<C,1OO,=txx()*---/txx&'88<<F<38O}}6#xx46HH.5	YT*...(1@ @ Mr$   c                    | j                   t        d      | j                  | j                  j	                  d      j                  | j                               }| j                  j                  |      }t        |      S )zY Deletes a stored event

        :return: Success / Failure
        :rtype: bool
        z%Attempting to delete an unsaved eventr   r  )	r  RuntimeErrorr%  rt   r   r   rl  deleter   r   r*  r  s      r%   r/  zEvent.delete  se     >>!FGGnnT__009@@DNN@ST88??3'H~r$   c                    | j                   r| j                  sy| j                  | j                  j	                  d      j                  | j                               }| j                  j                  }| j                  | j                        }n| j                  rE| j                  | j                  j	                  d      j                  | j                              }n*| j                  | j                  j	                  d            }| j                  j                  }| j                         } |||      }|sy| j                  j                          | j                   s?|j                         }|j	                  | j                  d	      d
      | _         |j	                  | j                  d      d
      | _        |j	                  | j                  d      d
      | _        | j                  r8t!        | j                        j#                  | j$                  j&                        nd
| _        | j                  r8t!        | j                        j#                  | j$                  j&                        nd
| _        |j	                  | j                  d      d
      | _        yt*        j,                  j/                         j1                  | j$                  j&                        | _        y)z Create a new event or update an existing one by checking what
        values have changed and update them on the server

        :return: Success / Failure
        :rtype: bool
        Tr   r  )r  rj  ri  r   Frr  Nrz  r{  r~  r  )r  r   r%  rt   r   r   rl  patchr   rp  postrT  r)  r   r  r  r   r  r   r   r  r   r   nowr  )r   r*  methodr   r  r   s         r%   savez
Event.save  s-    >>&&..!4!4W!=!D!D!D!WXCXX^^F##$2E2E#FD nnT__%8%89I%J%Q%QUYUeUe%Q%fgnnT__%8%8%IJXX]]F##%D#D)!!#~~MMOE"YYtxx~t<DN"YYtxx0A'BDIDN#ii1G(H$ODO ,0>> #4>>2==&&(?C N ,0?? $DOO4??&&(@D O "IIdhhy&94@DM  !kkoo/77t}}?U?U7VDOr$   TF)send_responsetentativelyc                   | j                   st        d      | j                  | j                  j	                  d      j                  | j                               }|r|dz   n|dz   }i }|r$t        |t              r||| j                  d      <   |du r||| j                  d      <   | j                  j                  ||xs d	
      }t        |      S )z Accept the event

        :param comment: comment to add
        :param send_response: whether or not to send response back
        :param tentatively: whether acceptance is tentative
        :return: Success / Failure
        :rtype: bool
        %Can't accept event that doesn't existr   r  z/tentativelyAcceptz/acceptcommentFsendResponseNr2  r  r.  r%  rt   r   r   r   rY  r   rl  r4  r   )r   r<  r8  r9  r*  r   r  s          r%   accept_eventzEvent.accept_event  s     ~~FGGnnOO(//4>>/BD,7c((S9_z'3/(/D)$%E!-:D.)*88==4<4=8H~r$   )r8  c                   | j                   st        d      | j                  | j                  j	                  d      j                  | j                               }|dz   }i }|r$t        |t              r||| j                  d      <   |du r||| j                  d      <   | j                  j                  ||xs d	      }t        |      S )
z Decline the event

        :param str comment: comment to add
        :param bool send_response: whether or not to send response back
        :return: Success / Failure
        :rtype: bool
        r;  r   r  z/decliner<  Fr=  Nr2  r>  r   r<  r8  r*  r   r  s         r%   decline_eventzEvent.decline_event-  s     ~~FGGnnOO(//4>>/BDJz'3/(/D)$%E!-:D.)*88==4<4=8H~r$   c                   | j                   st        d      | j                  | j                  j	                  d      j                  | j                               }|dz   }i }|r$t        |t              r||| j                  d      <   |du r||| j                  d      <   | j                  j                  ||xs d	      }t        |      S )
z Cancel the event

        :param str comment: comment to add
        :param bool send_response: whether or not to send response back
        :return: Success / Failure
        :rtype: bool
        r;  r   r  z/cancelr<  Fr=  Nr2  r>  rA  s         r%   cancel_eventzEvent.cancel_eventF  s     ~~FGGnnOO(//4>>/BDIoz'3/(/D)$%E!-:D.)*88==4<4=8H~r$   c                     | j                   dk7  r| j                  S 	 t        | j                  d      }|j                  j                  S # t        $ r | j                  cY S w xY w)zq Parse the body html and returns the body text using bs4

        :return: body text
        :rtype: str
        rx  html.parser)r  ru  bstextr.  )r   soups     r%   get_body_textzEvent.get_body_text_  sZ     >>V#99	"dii/D 99>>!  	99	s   A	 	A! A!c                 j    | j                   j                         dk7  ryt        | j                  d      S )zo Returns the beautifulsoup4 of the html body

        :return: Html body
        :rtype: BeautifulSoup
        rx  NrF  )r  upperrG  ru  r   s    r%   get_body_soupzEvent.get_body_soupo  s-     >>!V+dii//r$   r~   ).r   r   r   r&  rt   r   r   r   r  r   r  r  r  ru  r  rt  r  r  r  r  r  r  r  r  r  r   r   r  r  r"  rw   r:  ry  r	  r  r  r  r,  r/  r7  r?  rB  rD  rJ  rM  r  r  s   @r%   rd  rd  C  s;    &+2/J "&4 z<xY18t       
[[2 2   ^^5 5 % % ; ;   \\3 3"   	ZZ1 1 ! ! 8 8
 ! ! 6 6,   __6 6 % % H H
 , , !!H "H ) ) ? ? ! !       ^^4 4
 " " 9 9
 & & " "     ! ! 8 8  ! ! ( ( = = . . ##C $C
 $ $ A A 48tdZ^ HT0d$!&64 2$ 2" 	0r$   rd  c            	            e Zd ZdddddddZeZddd	 fd

Zd Zd Zd Z	e
d        Zd Zd ZddddddddddefdZddZd Z xZS )Calendarre  rg  rf  z/calendars/{id}/calendarViewz/calendar/calendarViewz/calendars/{id}/events/{ide})rh  
get_eventsdefault_eventsevents_viewdefault_events_view	get_eventNrk  c                   |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       |j                  | j                  i       }|j                  | j                  d      d      | _
        |j                  | j                  d      d      | _        | j                  |j                  | j                  d	      i       d	
      | _        |j                  | j                  d      d      }	 t        j                  |      | _        |j                  | j                  d      d      | _        |j                  | j                  d      d      | _        |j                  | j                  d      d      | _        |j                  | j                  d      d      | _        y#  t        j                  d      | _        Y xY w)a   Create a Calendar Representation

        :param parent: parent for this operation
        :type parent: Schedule
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rn  r   Nr   r   r)  r   rr  ownerr  colorrR   canEditFcanSharecanViewPrivateItemshexColor)r   rl  r  r  r   r   r   r   r\  r   r)  rp  r  _Calendar__ownerrG   r  rW  can_edit	can_sharecan_view_private_items	hex_color)r   r!  rl  r  r   r  rW  r   s          r%   r   zCalendar.__init__  s    cIJJ!'6::S 

?D9 H6<GFOT2$ 	 	(.V__FJJz4J' 	 	) ZZ 4 4b9
 NN488F#3R8	%>>$((4.$?11NN488G,b1 2 Btxx0&9	:&11%8DJ #txx	':EB#(<eD&0nnHH*+U'4# $(<dC	:&11&9DJs   :G- -Hc                 "    | j                         S r~   r   r   s    r%   r   zCalendar.__str__  r   r$   c                 N    dj                  | j                  | j                        S )NzCalendar: {} from {})r   r)  rV  r   s    r%   r   zCalendar.__repr__  s    %,,TYY

CCr$   c                 4    | j                   |j                   k(  S r~   )rp  r  s     r%   r  zCalendar.__eq__  s    5#4#444r$   c                     | j                   S )z4 Owner of the calendar

        :rtype: str
        )r\  r   s    r%   rV  zCalendar.owner  s     ||r$   c           	         | j                   sy| j                  | j                  j                  d      j	                  | j                               }| j                  d      | j                  | j                  d      | j                  t        | j                  t              r| j                  j                  n| j                        i}| j                  j                  ||      }t        |      S )z} Updates this calendar. Only name and color can be changed.

        :return: Success / Failure
        :rtype: bool
        Frh  r  r)  rW  r2  )rp  r%  rt   r   r   r   r)  r   rW  rG   r   rl  r3  r   )r   r*  r   r  s       r%   r'  zCalendar.update  s     nnT__00<CCtGWGWCXY HHVdiiHHWtxx+5djj-+P )-

(8(8-1ZZ 9
 88>>#D>1H~r$   c                     | j                   sy| j                  | j                  j                  d      j	                  | j                               }| j
                  j                  |      }|syd| _         y)zX Deletes this calendar

        :return: Success / Failure
        :rtype: bool
        Frh  r  NT)rp  r%  rt   r   r   rl  r/  r0  s      r%   r/  zCalendar.delete  sj     nnOO
+22d6F6F2GI 88??3'r$   FTr  r  r  rq  include_recurringstart_recurringend_recurringr  c                     j                   X|r+ j                   j                  j                  d            }	n j                   j                  j                  d            }	n|rE j                   j                  j                  d      j	                   j                               }	nD j                   j                  j                  d      j	                   j                               }	|| j
                  j                  kD  r j
                  j                  }|rdd|r|n|i}
|rd}d}|nOt        |t              r|}n<t        |t        j                        r|j                         }n|j                  d	      }|nOt        |t              r|}n<t        |t        j                        r|j                         }n|j                  d
      }||t        d      |j                  dd      }|j                  dd      }||
 j                  d      <   ||
 j                  d      <   |r||
d<   |r5t        |t              r||
d<   n|
j!                  |j#                                 j$                  j                  |	|
      }|st'        d      S |j)                         } fd|j                  dg       D        }|j                  t*        d      }|r|rt-         | j.                  ||      S |S )a`   Get events from this Calendar

        :param int limit: max no. of events to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :param download_attachments: downloads event attachments
        :param bool include_recurring: whether to include recurring events or not
        :param start_recurring: a string datetime or a Query object with just a start condition
        :param end_recurring: a string datetime or a Query object with just an end condition
        :return: list of events in this calendar
        :rtype: list[Event] or Pagination
        NrS  rQ  rR  r  rP  Fr  zstart/zend/zqWhen 'include_recurring' is True you must provide a 'start_recurring' and 'end_recurring' with a datetime string.'r   r  r  r  r  r  r#   c              3   `   K   | ]%  } j                   dd j                  |i ' yw))r!  rq  Nr#   )event_constructorr\  )r   r   rq  r   s     r%   r!  z&Calendar.get_events.<locals>.<genexpr>P  sJ      6 	 )$(( J)=J -1,@,@%+HJ 6s   +.r   r"  )rp  r%  rt   r   r   r   r&  r   rY  r   r   r   get_filter_by_attributer   r  r   r'  r(  rl  rE  r)  r   r   rn  )r   r  r  r  r  rq  rh  ri  rj  r*  r  r  r  r  r   r+  r$  s   `    `           r%   rP  zCalendar.get_events  s   ( # nnT__%8%89N%OPnnT__%8%89I%JK nnOO''6==AQAQ=RT nnOO''5<<@P@P<QS =EDMM$?$??MM//E#( 5%e4EC&OS1'OR[[9'113 (??I$M3/#M2;;7#--/ $;;FC}  "c d dMM#r*E++c2&C05F488O,-.1F488M*+!)F:%%$)y!eoo/088<<F<38O}}6  $xx4	6
 HH.5	YT*.*@*@(1@ @ Mr$   c                 >    | j                  | || j                        S )zE Returns a new (unsaved) Event object

        :rtype: Event
        )r!  rt  rp  )rn  rp  r   rt  s     r%   	new_eventzCalendar.new_event]  s+    
 %%T7262B2B & D 	Dr$   c                    |yt        |t              rJ| j                  | j                  j	                  d      j                  | j                  |            }d}d}ni| j                  | j                  j	                  d      j                  | j                              }ddi}|j                  |j                                d	}| j                  j	                  ||
      }|sy|r|j                         }n)|j                         j	                  dg       }|r|d   }ny | j                  dd| i| j                  |iS )z Returns an Event instance by it's id

        :param param: an event_id or a Query instance
        :return: event for the specified info
        :rtype: Event
        NrT  )rr  ideTrP  r  r  r   Fr  r   r   r!  r#   )r   rY  r%  rt   r   r   rp  r'  r(  rl  r)  rn  r\  )r   paramr*  r  by_idr  r   s          r%   rT  zCalendar.get_evente  s9    =eS!..##K0774;K;K<A 8 CDC FE..##L188D<L<L8MOCa[FMM%//+,E88<<F<3MMOEMMO''4Ea%t%% GT G)-)=)=u(EG 	Gr$      r~   )r   r   r   rt   rd  rn  r   r   r   r  r  rV  r'  r/  r   rP  rr  rT  r  r  s   @r%   rO  rO  {  s    %.,573J !%4 2DhD5  .*d4$d(-#'td dLD%Gr$   rO  c            	            e Zd ZdddddZeZeZddd fd
Zd	 Z	d
 Z
ddddddZd ZddZd Z	 ddddddddddZddZddZ xZS )Schedulez
/calendarsre  z	/calendarz/calendar/getSchedule)root_calendarsget_calendardefault_calendarget_availabilityNrk  c                    |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       y)a   Create a wrapper around calendars and events

        :param parent: parent for this operation
        :type parent: Account
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        rn  r   Nr   r   )r   rl  r  r  r   r   r   r   )r   r!  rl  r  r   r   s        r%   r   zSchedule.__init__  s{     cIJJ!'6::S 

?D9 H6<GFOT2$ 	 	(.V__FJJz4J' 	 	)r$   c                 "    | j                         S r~   r   r   s    r%   r   zSchedule.__str__  r   r$   c                 8    dj                  | j                        S )NzSchedule resource: {})r   r   r   s    r%   r   zSchedule.__repr__  s    &--d.@.@AAr$   )r  r  r  c          	         | j                  | j                  j                  d            }i }||| j                  j                  kD  r| j                  j                  }|r|n||d<   |r5t        |t              r||d<   n|j                  |j                                |r||d<   | j                  j                  ||xs d      }|sg S |j                         }|j                  dg       D 	cg c]"  }	 | j                  d
d| i| j                  |	i$ }
}	|j                  t        d      }|r|rt        | |
| j                  ||	      S |
S c c}	w )a   Gets a list of calendars

        To use query an order_by check the OData specification here:
        https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/odata-v4.0-errata03-os.html

        :param int limit: max no. of calendars to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: list of calendars
        :rtype: list[Calendar] or Pagination

        r{  Nr  r  r  r  r   r!  r"  r#   )r%  rt   r   r   r&  r   rY  r'  r(  rl  r)  calendar_constructorr\  r   r   )r   r  r  r  r  r*  r  r  r   x	calendarsr$  s               r%   list_calendarszSchedule.list_calendars  sX   " nnT__001ABC=EDMM$?$??MM//E#(%ev%%$)y!eoo/0!)F:88<<FNd<;I}} 04xx/DF*+ /T.. &d &  !?% & F	 FHH.5	YT	*.*C*C(1@ @ Fs   .'Ec                    |sy| j                  | j                  j                  d            }| j                  j	                  || j                  d      |i      }|sy|j                         } | j                  dd| i| j                  |iS )z Creates a new calendar

        :param str calendar_name: name of the new calendar
        :return: a new Calendar instance
        :rtype: Calendar
        Nr{  r)  r2  r!  r#   )	r%  rt   r   rl  r4  r   r)  r  r\  )r   calendar_namer*  r  r   s        r%   new_calendarzSchedule.new_calendar  s     nnT__001ABC88==DHHV,<m+L=M}} )t(( I I,0,@,@$+GI 	Ir$   c                    |r|rt        d      |s|st        d      |r=| j                  | j                  j                  d      j	                  |            }d}nN| j                  | j                  j                  d            }dj	                  | j                  d      |      d	d
}|r5t        |t              s%|i n|}|j                  |j                                | j                  j                  ||      }|sy|r|j                         }n+|j                         j                  d      }|r|d   nd}|y | j                  dd| i| j                  |iS )aR  Returns a calendar by it's id or name

        :param str calendar_id: the calendar id to be retrieved.
        :param str calendar_name: the calendar name to be retrieved.
        :param query: applies a OData filter to the request
        :type query: Query
        :return: calendar for the given info
        :rtype: Calendar
        zProvide only one of the optionszProvide one of the optionsr|  r  Nr{  z
{} eq '{}'r)  r   )r  r  r  r   r   r!  r#   )r.  r%  rt   r   r   r   r   rY  r'  r(  rl  r)  r  r\  )r   rp  r  r  r*  r  r  r   s           r%   r|  zSchedule.get_calendar  sW    =@AA=;<<..##N3::k:JLCF ..!4!45E!FGC'..txx/?OF eS)%~6eoo/088<<F<3==?D==?&&w/D"47D| )t(( I I,0,@,@$+GI 	Ir$   c                     | j                  | j                  j                  d            }| j                  j                  |      }|sy|j	                         } | j
                  dd| i| j                  |iS )zU Returns the default calendar for the current user

        :rtype: Calendar
        r}  Nr!  r#   )r%  rt   r   rl  r)  r  r\  )r   r*  r  r   s       r%   get_default_calendarzSchedule.get_default_calendar,  sz     nnT__001CDE88<<$}} )t(( I I,0,@,@$+GI 	Ir$   FTrg  c          
      X    | j                  |       }	|	j                  ||||||||      S )ah  Get events from the default Calendar

        :param int limit: max no. of events to get. Over 999 uses batch.
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :param bool download_attachments: downloads event attachments
        :param bool include_recurring: whether to include recurring events or not
        :param start_recurring: a string datetime or a Query object with just a start condition
        :param end_recurring: a string datetime or a Query object with just an end condition
        :return: list of items in this folder
        :rtype: list[Event] or Pagination
        )r!  )r  r  r  r  rq  rh  ri  rj  )r  rP  )
r   r  r  r  r  rq  rh  ri  rj  r}  s
             r%   rP  zSchedule.get_events>  sH    :  44D4A**!5/+' + 	
 		
r$   c                 (    | j                  | |      S )z Returns a new (unsaved) Event object in the default calendar

        :param str subject: subject text for the new event
        :return: new event
        :rtype: Event
        )r!  rt  )rn  rq  s     r%   rr  zSchedule.new_eventh  s     %%T7%CCr$   c                 r   | j                  | j                  j                  d            }| j                  |      | j                  |      ||d}| j                  j                  ||      }|sg S |j                         j                  dg       }ddddd	d
}|D ]  }	|	j                  dd      }
|
D cg c]  }|j                  |d       c}|	d<   |	j                  dg       D ]H  }| j                  |j                  d            |d<   | j                  |j                  d            |d<   J  |S c c}w )a  
        Returns the free/busy availability for a set of users in a given time frame
        :param list schedules: a list of strings (email addresses)
        :param datetime start: the start time frame to look for available space
        :param datetime end: the end time frame to look for available space
        :param int interval: the number of minutes to look for space
        r~  )	startTimeendTimeavailabilityViewInterval	schedulesr2  r   r:   r;   r<   zout of officezworking elsewhere)01234availabilityViewr   unkknownscheduleItemsr  r  )r%  rt   r   r  rl  r4  r)  r  )r   r  r  r  r   r*  r   r  availability_view_codesschedulea_viewcoderK  s                r%   r~  zSchedule.get_availabilityq  sI    nnT__001CDE 88?66s;(0"	
 88==4=0I}}""7B/  $#
  	OH\\"4b9Ffl+m^b,C,G,Gj,Y+mH'( _b9 O $ ? ?@Q RW"==dhhuoNUO	O  ,ns   4D4r~   r  rw  )<   )r   r   r   rt   rO  r  rd  rn  r   r   r   r  r  r|  r  rP  rr  r~  r  r  s   @r%   rz  rz    s    &)'3	J $!%4 ).B.$T .bI,.I`I( (
 "(
TD&r$   rz  )1rh  r   r   loggingzoneinfor   bs4r   rG  dateutil.parserr   categoryr   utilsr   r	   r
   r   r   r   r   r   r   r   utils.windows_tzr   	getLoggerr   r  r   
month_namer   r   r'   r/   r9   rG   r_   ri   rq   rv   r|   r   r  r(  r@  rd  rO  rz  )r  s   0r%   <module>r     sM       $ !    -g!/4Q|<!x""1%<"H "8 "x "( H " "* *8n 8. .! !ul up&\ &Ra aHM Mbu0L/+@ u0pOG|2 OGdJ| Je; =s    D6