
    i                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	  ed           G d d	                      Z
e G d
 d                      ZdddZd dZd!dZd!dZ	 dd"dZdS )#a  
Base utilities for the operations layer.

This module provides foundational types and utilities used by all
operations modules. The operations layer contains pure functions
(Sans-I/O) that handle business logic without performing any network I/O.

Design principles:
- All functions are pure: same inputs always produce same outputs
- No network I/O - that's the client's responsibility
- Request specs describe WHAT to request, not HOW
- Response processors transform parsed data into domain-friendly formats
    )annotations)	dataclassfield)Any)URLT)frozenc                  ^    e Zd ZU dZded<   dZded<   dZded<   d	Zd
ed<   dZded<   ddZ	dS )	QuerySpeca  
    Base specification for a DAV query.

    This is an immutable description of what to request from the server.
    The client uses this to construct and execute the actual HTTP request.

    Attributes:
        url: The URL to query
        method: HTTP method (PROPFIND, REPORT, etc.)
        depth: DAV depth header (0, 1, or infinity)
        props: Properties to request
        body: Optional pre-built XML body (if complex)
    strurlPROPFINDmethodr   intdepth ztuple[str, ...]propsNzbytes | Nonebodynew_urlreturnc                R    t          || j        | j        | j        | j                  S )z#Return a copy with a different URL.)r   r   r   r   r   )r
   r   r   r   r   )selfr   s     Q/root/projects/butler/venv/lib/python3.11/site-packages/caldav/operations/base.pywith_urlzQuerySpec.with_url-   s0    ;**
 
 
 	
    )r   r   r   r
   )
__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r   r   r
   r
      s           HHHFENNNNED
 
 
 
 
 
r   r
   c                  N    e Zd ZU dZded<    ee          Zded<   dZded	<   d
S )PropertyDataz
    Generic property data extracted from a DAV response.

    Used when we need to pass around arbitrary properties
    without knowing their specific structure.
    r   href)default_factorydict[str, Any]
properties   r   statusN)	r   r   r   r   r   r   dictr%   r'   r   r   r   r!   r!   8   sV           III!&t!<!<!<J<<<<Fr   r!   Nr"   r   base_url
str | Noner   c                `   | s| S d| v rD|                      d          s/|                     dd          } d| v r|                      d          /|r_|                      d          sJ	 t          j        |          }|r"t	          |                    |                     S n# t          $ r Y nw xY w| S )a&  
    Normalize an href to a consistent format.

    Handles relative URLs, double slashes, and other common issues.

    Args:
        href: The href from the server response
        base_url: Optional base URL to resolve relative hrefs against

    Returns:
        Normalized href string
    z//http/)
startswithreplacer   	objectifyr   join	Exception)r"   r)   bases      r   _normalize_hrefr4   F   s       $,,tv66,||D#&& $,,tv66,  // 	=**D ,499T??+++, 	 	 	D	 Ks   %7B 
B+*B+r%   r$   	list[str]c                v    d}|                      |g           }t          |t                    r|S |g S |r|gng S )z
    Extract resource types from properties dict.

    Args:
        properties: Dict of property tag -> value

    Returns:
        List of resource type tags (e.g., ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'])
    z{DAV:}resourcetype)get
isinstancelist)r%   resource_type_keyrts      r   _extract_resource_typer<   f   sR     -	)2	.	.B"d "			 !ttr!r   boolc                ,    t          |           }d}||v S )z
    Check if properties indicate a calendar resource.

    Args:
        properties: Dict of property tag -> value

    Returns:
        True if this is a calendar collection
    z'{urn:ietf:params:xml:ns:caldav}calendarr<   )r%   resource_typescalendar_tags      r   _is_calendar_resourcerB   |   s!     ,J77N<L>))r   c                ,    t          |           }d}||v S )z
    Check if properties indicate a collection resource.

    Args:
        properties: Dict of property tag -> value

    Returns:
        True if this is a collection
    z{DAV:}collectionr?   )r%   r@   collection_tags      r   _is_collection_resourcerE      s!     ,J77N'N^++r   	prop_namedefaultr   c                X    || v r| |         S g d}|D ]}| | }|| v r
| |         c S |S )az  
    Get a property value, handling both namespaced and simple keys.

    Tries the full namespaced key first, then common namespace prefixes.

    Args:
        properties: Dict of property tag -> value
        prop_name: Property name (e.g., 'displayname' or '{DAV:}displayname')
        default: Default value if not found

    Returns:
        Property value or default
    )z{DAV:}z{urn:ietf:params:xml:ns:caldav}z{http://calendarserver.org/ns/}z{http://apple.com/ns/ical/}r   )r%   rF   rG   
namespacesnsfull_keys         r   _get_property_valuerL      st    & J)$$  J  ( (%)%%z!!h'''' " Nr   )N)r"   r   r)   r*   r   r   )r%   r$   r   r5   )r%   r$   r   r=   )r%   r$   rF   r   rG   r   r   r   )r   
__future__r   dataclassesr   r   typingr   caldav.lib.urlr   r
   r!   r4   r<   rB   rE   rL   r   r   r   <module>rQ      sT    # " " " " " ( ( ( ( ( ( ( (             $
 
 
 
 
 
 
 
@ 
 
 
 
 
 
 
 
    @" " " ",* * * *, , , ,$ # # # # # # #r   