
    F2jx                        d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	Z	erddl
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dS )a  
Data state management for CalendarObjectResource.

This module implements the Strategy/State pattern for managing different
representations of calendar data (raw string, icalendar object, vobject object).

See https://github.com/python-caldav/caldav/issues/613 for design discussion.

TODO: verify that we have sufficient test coverage - both through unit tests
and integration tests
    )annotationsN)ABCabstractmethod)TYPE_CHECKINGc                  r    e Zd ZdZedd            Zedd            Zedd            Zdd
ZddZ	ddZ
dS )	DataStatezAbstract base class for calendar data states.

    Each concrete state represents a different "source of truth" for the
    calendar data. The state provides access to all representations, but
    only one is authoritative at any time.
    returnstrc                    dS )zGet raw iCalendar string representation.

        This may involve serialization if the current state holds a
        parsed object.
        N selfs    X/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/caldav/datastate.pyget_datazDataState.get_data!   	     	    icalendar.Calendarc                    dS )zGet a fresh copy of the icalendar object.

        This is safe for read-only access - modifications won't affect
        the stored data.
        Nr   r   s    r   get_icalendar_copyzDataState.get_icalendar_copy*   r   r   vobject.base.Componentc                    dS )zGet a fresh copy of the vobject object.

        This is safe for read-only access - modifications won't affect
        the stored data.
        Nr   r   s    r   get_vobject_copyzDataState.get_vobject_copy3   r   r   
str | Nonec                    |                                  }|j        D ]&}|j        dv rd|v rt          |d                   c S 'dS )zExtract UID without full parsing if possible.

        Default implementation parses the data, but subclasses can optimize.
        VEVENTVTODOVJOURNALFREEBUSYUIDN)r   subcomponentsnamer
   r   calcomps      r   get_uidzDataState.get_uid<   s\    
 %%''% 	( 	(DyGGGEUYMM4;'''''tr   c                f    |                                  }|j        D ]}|j        dv r	|j        c S dS )zGet the component type (VEVENT, VTODO, VJOURNAL, FREEBUSY) without full parsing.

        Default implementation parses the data, but subclasses can optimize.
        r   N)r   r!   r"   r#   s      r   get_component_typezDataState.get_component_typeG   sN    
 %%''% 	! 	!DyGGGy    Htr   boolc                    dS )z!Check if this state has any data.Tr   r   s    r   has_datazDataState.has_dataR   s    tr   Nr	   r
   r	   r   r	   r   r	   r   r	   r)   )__name__
__module____qualname____doc__r   r   r   r   r&   r(   r+   r   r   r   r   r      s             ^    ^    ^	 	 	 		 	 	 	     r   r   c                  B    e Zd ZdZddZddZddZdd
ZddZddZ	dS )NoDataStatezNull Object pattern - no data loaded yet.

    This state is used when a CalendarObjectResource is created without
    any initial data. It provides empty/default values for all accessors.
    r	   r
   c                    dS )N r   r   s    r   r   zNoDataState.get_data^   s    rr   r   c                (    t          j                    S N)	icalendarCalendarr   s    r   r   zNoDataState.get_icalendar_copya   s    !###r   r   c                (    dd l } |j                    S Nr   )vobject	iCalendarr   r?   s     r   r   zNoDataState.get_vobject_copyd   s     w """r   r   c                    d S r:   r   r   s    r   r&   zNoDataState.get_uidi       tr   c                    d S r:   r   r   s    r   r(   zNoDataState.get_component_typel   rC   r   r)   c                    dS )NFr   r   s    r   r+   zNoDataState.has_datao   s    ur   Nr,   r-   r.   r/   r0   )
r1   r2   r3   r4   r   r   r   r&   r(   r+   r   r   r   r6   r6   W   s            $ $ $ $# # # #
           r   r6   c                  L     e Zd ZdZddZddZddZdd
Zd fdZddZ	 xZ
S )RawDataStatezState when raw string data is the source of truth.

    This is the most common initial state when data is loaded from
    a CalDAV server.
    datar
   c                    || _         d S r:   _data)r   rH   s     r   __init__zRawDataState.__init__z   s    


r   r	   c                    | j         S r:   rJ   r   s    r   r   zRawDataState.get_data}   s
    zr   r   c                J    t           j                            | j                  S r:   )r;   r<   	from_icalrK   r   s    r   r   zRawDataState.get_icalendar_copy   s    !++DJ777r   r   c                4    dd l } |j        | j                  S r>   )r?   readOnerK   rA   s     r   r   zRawDataState.get_vobject_copy   s    wtz***r   r   c                    t          j        d| j        t           j                  }|r'|                    d                                          S t                                                      S )Nz
^UID:(.+)$   )researchrK   	MULTILINEgroupstripsuperr&   )r   match	__class__s     r   r&   zRawDataState.get_uid   sR    	-R\BB 	*;;q>>'')))ww   r   c                ^    d| j         v rdS d| j         v rdS d| j         v rdS d| j         v rdS d S )	NzBEGIN:VEVENTr   zBEGIN:VTODOr   zBEGIN:VJOURNALr   zBEGIN:FREEBUSY	VFREEBUSYrJ   r   s    r   r(   zRawDataState.get_component_type   sO    TZ''8dj((7++:++;tr   )rH   r
   r,   r-   r.   r/   )r1   r2   r3   r4   rL   r   r   r   r&   r(   __classcell__)r[   s   @r   rG   rG   s   s               8 8 8 8+ + + +
! ! ! ! ! !
 
 
 
 
 
 
 
r   rG   c                  J    e Zd ZdZddZddZddZdd	ZddZddZ	ddZ
dS )IcalendarStatezState when icalendar object is the source of truth.

    This state is entered when:
    - User calls edit_icalendar_instance()
    - User sets icalendar_instance property
    - User modifies the icalendar object
    calendarr   c                    || _         d S r:   	_calendar)r   ra   s     r   rL   zIcalendarState.__init__   s    !r   r	   r
   c                Z    | j                                                             d          S )Nzutf-8)rd   to_icaldecoder   s    r   r   zIcalendarState.get_data   s$    ~%%''..w777r   c                d    t           j                            |                                           S r:   r;   r<   rO   r   r   s    r   r   z!IcalendarState.get_icalendar_copy   s!    !++DMMOO<<<r   c                    | j         S )z|Returns THE icalendar object (not a copy).

        This is the authoritative object - modifications will be saved.
        rc   r   s    r   get_authoritative_icalendarz*IcalendarState.get_authoritative_icalendar   s    
 ~r   r   c                N    dd l } |j        |                                           S r>   r?   rQ   r   rA   s     r   r   zIcalendarState.get_vobject_copy   %    wt}}///r   r   c                l    | j         j        D ]&}|j        dv rd|v rt          |d                   c S 'd S )Nr   r   r   r]   r    )rd   r!   r"   r
   r   r%   s     r   r&   zIcalendarState.get_uid   sK    N0 	( 	(DyHHHUVZ]]4;'''''tr   c                H    | j         j        D ]}|j        dv r	|j        c S d S )Nrp   )rd   r!   r"   rq   s     r   r(   z!IcalendarState.get_component_type   s=    N0 	! 	!DyHHHy    Itr   N)ra   r   r,   r-   r.   r/   )r1   r2   r3   r4   rL   r   r   rk   r   r&   r(   r   r   r   r`   r`      s         " " " "8 8 8 8= = = =   0 0 0 0
        r   r`   c                  J    e Zd ZdZddZddZdd	Zdd
ZddZddZ	ddZ
dS )VobjectStatezState when vobject object is the source of truth.

    This state is entered when:
    - User calls edit_vobject_instance()
    - User sets vobject_instance property
    - User modifies the vobject object
    vobjr   c                    || _         d S r:   _vobject)r   ru   s     r   rL   zVobjectState.__init__   s    r   r	   r
   c                4    | j                                         S r:   )rx   	serializer   s    r   r   zVobjectState.get_data   s    }&&(((r   r   c                d    t           j                            |                                           S r:   ri   r   s    r   r   zVobjectState.get_icalendar_copy   s!    !++DMMOO<<<r   c                N    dd l } |j        |                                           S r>   rm   rA   s     r   r   zVobjectState.get_vobject_copy   rn   r   c                    | j         S )zzReturns THE vobject object (not a copy).

        This is the authoritative object - modifications will be saved.
        rw   r   s    r   get_authoritative_vobjectz&VobjectState.get_authoritative_vobject   s    
 }r   r   c                   	 t          | j        d          r#t          | j        j        j        j                  S t          | j        d          r#t          | j        j        j        j                  S t          | j        d          r#t          | j        j        j        j                  S t          | j        d          r#t          | j        j        j        j                  S n# t          $ r Y nw xY wd S )Nveventvtodovjournal	vfreebusy)
hasattrrx   r
   r   uidvaluer   r   r   AttributeErrorr   s    r   r&   zVobjectState.get_uid   s    
	t}h// >4=/39:::00 >4=.28999
33 >4=15;<<<44 >4=26<===> 	 	 	D	ts"   7C# 7C# 27C# *7C# #
C0/C0c                    t          | j        d          rdS t          | j        d          rdS t          | j        d          rdS t          | j        d          rdS d S )	Nr   r   r   r   r   r   r   r]   )r   rx   r   s    r   r(   zVobjectState.get_component_type   sk    4=(++ 	8T]G,, 	7T]J// 	:T]K00 	;tr   N)ru   r   r,   r-   r.   r/   )r1   r2   r3   r4   rL   r   r   r   r~   r&   r(   r   r   r   rt   rt      s            ) ) ) )= = = =0 0 0 0
      	 	 	 	 	 	r   rt   )r4   
__future__r   rT   abcr   r   typingr   r;   r?   r   r6   rG   r`   rt   r   r   r   <module>r      sR  
 
 # " " " " " 				 # # # # # # # #                 NNN; ; ; ; ; ; ; ;|    )   8' ' ' ' '9 ' ' 'T) ) ) ) )Y ) ) )X6 6 6 6 69 6 6 6 6 6r   