
    i'                        d Z ddlmZ ddlmZ ddlmZ ddlmZmZ ddl	m
Z
 	 	 d(d	ee         dz  d
edefdZ	 d)deeef         dz  defdZ	 	 	 	 	 	 	 	 	 d*dedz  dedz  dededz  dededed	ee
         dz  dee
         dz  deeedz  f         fdZ	 d+dee         dedefdZ	 	 	 d,dedz  d	ee         dz  dedefdZ	 	 	 	 d-d edz  d!edz  d"edz  d#ee         dz  def
d$Zd)d%ed&edz  de
dz  fd'ZdS ).z
Pure functions for building CalDAV XML request bodies.

All functions in this module are pure - they take data in and return XML out,
with no side effects or I/O.
    )datetime)Any)etree)cdavdav)BaseElementNFpropsallpropreturnc                    |r(t          j                    t          j                    z   }n| rXg }| D ](}t          |          }||                    |           )t          j                    t          j                    |z   z   }n't          j                    t          j                    z   }t          j        |                                dd          S )a  
    Build PROPFIND request body XML.

    Args:
        props: List of property names to retrieve. If None and allprop=False,
               returns minimal propfind.
        allprop: If True, request all properties.

    Returns:
        UTF-8 encoded XML bytes
    Nutf-8Tencodingxml_declaration)	r   PropfindAllprop_prop_name_to_elementappendPropr   tostring
xmlelement)r	   r
   propfindprop_elements	prop_nameprop_elements         W/root/projects/butler/venv/lib/python3.11/site-packages/caldav/protocol/xml_builders.py_build_propfind_bodyr      s      
/<>>CKMM1	 / 	3 	3I0;;L'$$\222<>>SXZZ-%?@<>>CHJJ.>(--//'SWXXXX    	set_propsc                 f   t          j                    }| rtg }|                                 D ],\  }}t          ||          }||                    |           -|r/t          j                    t          j                    |z   z   }||z  }t          j        |	                                dd          S )z
    Build PROPPATCH request body for setting properties.

    Args:
        set_props: Properties to set (name -> value)

    Returns:
        UTF-8 encoded XML bytes
    Nr   Tr   )
r   PropertyUpdateitemsr   r   Setr   r   r   r   )r   propertyupdateset_elementsnamevaluer   set_elements          r   _build_proppatch_bodyr)   /   s     '))N *$??,, 	2 	2KD%0u==L'##L111 	*'))sxzzL'@AKk)N>.3355Y]^^^^r   startendexpandcomp_filtereventtodojournalfiltersc	                    t          j                    }	|r7| r|sddlm}
 |
                    d          |	t          j        | |          z  }	|	g}|r|                    |           t          j                    |z   }t          j	        d          }|}|s|rd}n	|rd}n|rd}g }|r|                    |           | s|r(|
                    t          j        | |                     |r!t          j	        |          }|r||z  }||z  }n|r||z  }t          j                    |z   }t          j                    ||gz   }t          j        |                                dd	
          |fS )a  
    Build calendar-query REPORT request body.

    This is the core CalDAV search operation for retrieving calendar objects
    matching specified criteria.

    Args:
        start: Start of time range filter
        end: End of time range filter
        expand: Whether to expand recurring events
        comp_filter: Component type filter name (VEVENT, VTODO, VJOURNAL)
        event: Include VEVENT components (sets comp_filter if not specified)
        todo: Include VTODO components (sets comp_filter if not specified)
        journal: Include VJOURNAL components (sets comp_filter if not specified)
        props: Additional CalDAV properties to include
        filters: Additional filters to apply

    Returns:
        Tuple of (UTF-8 encoded XML bytes, component type name or None)
    r   )errorz!can't expand without a date range	VCALENDARVEVENTVTODOVJOURNALr   Tr   )r   CalendarData
caldav.libr3   ReportErrorExpandextendr   r   
CompFilterr   	TimeRangeFilterCalendarQueryr   r   r   )r*   r+   r,   r-   r.   r/   r0   r	   r1   datar3   
props_listprop	vcalendar	comp_typefilter_listcomp_filter_elemfilter_elemroots                      r   _build_calendar_query_bodyrJ   J   s   @ D ( 	IC 	I((((((##$GHHHE3''' &*FJ !%   8::
"D ,,I I # 	# II 	#II 	#"I &(K $7###  7 74>%55666  !?955 	,+%%			 ![ 	 +--)+K4"55D 	t((7DQQQ r   Threfsinclude_datac                 X   g }|r<t          j                    t          j                    z   }|                    |           | D ])}|                    t          j        |                     *t          j                    |z   }t          j        |	                                dd          S )a2  
    Build calendar-multiget REPORT request body.

    Used to retrieve multiple calendar objects by their URLs in a single request.

    Args:
        hrefs: List of calendar object URLs to retrieve
        include_data: Include calendar-data in response

    Returns:
        UTF-8 encoded XML bytes
    r   Tr   )
r   r   r   r8   r   HrefCalendarMultiGetr   r   r   )rK   rL   elementsrC   hrefmultigets         r   _build_calendar_multiget_bodyrS      s      #%H xzzD-/// ( (''''$&&1H>(--//'SWXXXXr   1
sync_token
sync_levelc                 |   g }t          j        | pd          }|                    |           t          j        |          }|                    |           |rYg }|D ](}t	          |          }||                    |           )|r)|                    t          j                    |z              nM|                    t          j                    t          j                    t          j                    gz              t          j	                    |z   }	t          j        |	                                dd          S )a|  
    Build sync-collection REPORT request body.

    Used for efficient synchronization - only returns changed items since
    the given sync token.

    Args:
        sync_token: Previous sync token (empty string for initial sync)
        props: Property names to include in response
        sync_level: Sync level (usually "1")

    Returns:
        UTF-8 encoded XML bytes
     Nr   Tr   )r   	SyncTokenr   	SyncLevelr   r   GetEtagr   r8   SyncCollectionr   r   r   )
rU   r	   rV   rP   
token_elem
level_elemr   r   r   sync_collections
             r   _build_sync_collection_bodyr`      s+   & #%H z/R00JOOJ z**JOOJ  
K 	3 	3I0;;L'$$\222 	8OOCHJJ6777 	

ckmmT5F5H5H%IIJJJ(**X5O>/4466Z^____r   displaynamedescriptiontimezonesupported_componentsc                 N   t          j                    }| r|t          j        |           z  }|r|t          j        |          z  }|r|t          j        |          z  }|r4t          j                    }|D ]}|t          j        |          z  }||z  }|t          j                    t          j	                    t          j
                    gz   z  }t          j                    |z   }t          j                    |z   }t          j        |                                dd          S )a7  
    Build MKCALENDAR request body.

    Args:
        displayname: Calendar display name
        description: Calendar description
        timezone: VTIMEZONE component data
        supported_components: List of supported component types (VEVENT, VTODO, etc.)

    Returns:
        UTF-8 encoded XML bytes
    r   Tr   )r   r   DisplayNamer   CalendarDescriptionCalendarTimeZoneSupportedCalendarComponentSetCompResourceType
CollectionCalendarr#   
Mkcalendarr   r   r   )	ra   rb   rc   rd   rC   sccscompset_elem
mkcalendars	            r   _build_mkcalendar_bodyrs      s   $ 8::D -,,, 6(555 0%h/// 133( 	$ 	$DDIdOO#DD 	C#."2"2DMOO!DDDDwyy4H""X-J>*//11GUYZZZZr   r&   r'   c           
      $   t           j        t           j        t           j        t           j        t           j        t           j        t           j        d}t          j	        t          j
        t          j        t          j        t          j        t          j        t          j        t          j        t          j        d	}|                     d          r d| v r|                     dd          d         } |                                                     dd          }||v r:||         }|&	  ||          S # t,          $ r  |            cY S w xY w |            S ||v r:||         }|&	  ||          S # t,          $ r  |            cY S w xY w |            S dS )	z
    Convert property name string to element object.

    Args:
        name: Property name (case-insensitive)
        value: Optional value for valued elements

    Returns:
        BaseElement instance or None if unknown property
    )ra   resourcetypegetetagzcurrent-user-principalownerz
sync-tokenzsupported-report-set)	zcalendar-datazcalendar-home-setzcalendar-user-address-setzcalendar-user-typezcalendar-descriptionzcalendar-timezonez supported-calendar-component-setzschedule-inbox-urlzschedule-outbox-url{}   _-N)r   rf   rk   r[   CurrentUserPrincipalOwnerrY   SupportedReportSetr   r8   CalendarHomeSetCalendarUserAddressSetCalendarUserTyperg   rh   ri   ScheduleInboxURLScheduleOutboxURL
startswithsplitlowerreplace	TypeError)r&   r'   	dav_propscaldav_props
name_lowerclss         r   r   r     s    (;"%":m # 6! !I *!1%)%@"3 $ 8!2,0,N"3#5
$ 
$L s %tzz#q!!!$%%c3//J Y
#s5zz!   suusuu \!!:&s5zz!   suusuu4s$   #
D. .EE!
E, ,FF)NF)N)	NNFNFFFNN)T)NNrT   )NNNN)__doc__r   typingr   lxmlr   caldav.elementsr   r   caldav.elements.baser   liststrboolbytesr   dictr)   tuplerJ   rS   r`   rs   r    r   r   <module>r      s-                      % % % % % % % % , , , , , , #Y Y9tYY Y Y Y Y> (,_ _CH~$_
_ _ _ _8 ""&*(,T Td?T	DT T t	T
 T T T t#T +%T 5#*T T T Tr Y Y9YY Y Y Y Y> "",` ,`d
,`9t,` ,` 	,` ,` ,` ,`` #"-1	)[ )[t)[t)[ Dj)[ s)d*	)[
 )[ )[ )[ )[^= = =C$J =+PTBT = = = = = =r   