
    i8              	       ~   U d dl Z d dlmZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 dZ	 d dlZej                            dd          Zej        d	         Zn#  d
e
v se
dk    rdZndZY nxY w e j        d          Ze                    d          re                    e j                   ne                    e j                   defdZd ZdeddfdZdZeed<    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*e          Z' G d+ d,e          Z( G d- d.e          Z) G d/ d0e          Z* G d1 d2e          Z+d3edee,         fd4Z-d5ee,         d6ee.         d7ee.         dee,         fd8Z/d9e.d:ed3ee         ddfd;Z0 ed<           Z1e2eef         ed=<   d>D ];Z3 e4            e3d          5                                e3d?d         z   d@z            e1e3<   <dS )A    N)defaultdict)datetimetimezone)parsedate_to_datetime)Optional)__version__FPYTHON_CALDAV_COMMDUMPPYTHON_CALDAV_DEBUGMODEdevz	(unknown)DEVELOPMENT
PRODUCTIONcaldavDEBUGreturnc                 4    | j         d| j        d| j        S )z=Utility for formatting a an error response to an error string z

)statusreasonraw)rs    K/root/projects/butler/venv/lib/python3.11/site-packages/caldav/lib/error.pyerrmsgr       s    HHHahhh66    c                     ddl m d                    fd| D                       }t                              d|            t
          dk    r7t                              d|            dd l}|                                 d S d S )Nr   )	xmlstringz : c                 &    g | ]} |          S  r   ).0xr   s     r   
<listcomp>zweirdness.<locals>.<listcomp>(   s!    777!1777r   z#Deviation from expectations found: 	DEBUG_PDBzDropping into debugger due to )	caldav.lib.debugr   joinlogwarning	debugmodeerrorpdb	set_trace)reasonsr   r(   r   s      @r   	weirdnessr+   %   s    ******ZZ7777w77788FKK>f>>???K		;6;;<<<


	  r   	conditionc                    	 | sJ d S # t           $ rt t          dk    r't                              dt          z  d           Y d S t          dk    r5t                              d           dd l}|                                 Y d S  w xY w)Nr   z&Deviation from expectations found.  %sT)exc_infor!   z:Deviation from expectations found.  Dropping into debuggerr   )AssertionErrorr&   r$   r'   ERR_FRAGMENTr(   r)   )r,   r(   s     r   assert_r1   1   s     	 	 	$$II>MX\I]]]]]]+%%IIRSSSJJJMMOOOOOO	s    9B=BBzPlease consider raising an issue at https://github.com/python-caldav/caldav/issues or reach out to t-caldav@tobixen.no, include this error and the traceback (if any) and tell what server you are usingr0   c                   `    e Zd ZU dZedz  ed<   dZeed<   ddedz  dedz  ddfdZdefdZdS )	DAVErrorNurlz	no reasonr   r   c                 .    |r|| _         |r	|| _        d S d S Nr4   r   )selfr4   r   s      r   __init__zDAVError.__init__G   s.     	DH 	! DKKK	! 	!r   c                 >    | j         j        d| j        d| j        S )Nz at 'z
', reason )	__class____name__r4   r   )r8   s    r   __str__zDAVError.__str__M   s*    N###HHHKK
 	
r   )NN)	r<   
__module____qualname__r4   str__annotations__r   r9   r=   r   r   r   r3   r3   C   s         CtFC! !C$J !sTz !T ! ! ! !
 
 
 
 
 
 
r   r3   c                       e Zd ZdZdS )AuthorizationErrorz
    The client encountered an HTTP 403 error and is passing it on
    to the user. The url property will contain the url in question,
    the reason property will contain the excuse the server sent.
    N)r<   r>   r?   __doc__r   r   r   rC   rC   U   s          	Dr   rC   c                       e Zd ZdS )PropsetErrorNr<   r>   r?   r   r   r   rF   rF   _           Dr   rF   c                       e Zd ZdS )ProppatchErrorNrG   r   r   r   rJ   rJ   c   rH   r   rJ   c                       e Zd ZdS )PropfindErrorNrG   r   r   r   rL   rL   g   rH   r   rL   c                       e Zd ZdS )ReportErrorNrG   r   r   r   rN   rN   k   rH   r   rN   c                       e Zd ZdS )
MkcolErrorNrG   r   r   r   rP   rP   o   rH   r   rP   c                       e Zd ZdS )MkcalendarErrorNrG   r   r   r   rR   rR   s   rH   r   rR   c                       e Zd ZdS )PutErrorNrG   r   r   r   rT   rT   w   rH   r   rT   c                       e Zd ZdS )DeleteErrorNrG   r   r   r   rV   rV   {   rH   r   rV   c                       e Zd ZdS )NotFoundErrorNrG   r   r   r   rX   rX      rH   r   rX   c                       e Zd ZdS )ConsistencyErrorNrG   r   r   r   rZ   rZ      rH   r   rZ   c                       e Zd ZdS )ResponseErrorNrG   r   r   r   r\   r\      rH   r   r\   c                   Z     e Zd ZdZ	 	 	 	 d	dedz  dedz  dedz  dedz  ddf
 fdZ xZS )
RateLimitErrorztRaised when the server responds with 429 Too Many Requests or
    503 Service Unavailable with a Retry-After header.Nr4   r   retry_afterretry_after_secondsr   c                 j    t                                          ||           || _        || _        d S )Nr7   )superr9   r_   r`   )r8   r4   r   r_   r`   r;   s        r   r9   zRateLimitError.__init__   s8     	S000&#6   r   )NNNN)r<   r>   r?   rD   r@   floatr9   __classcell__)r;   s   @r   r^   r^      s        : :
 !"&,0	7 	74Z	7 d
	7 4Z		7
 #T\	7 
	7 	7 	7 	7 	7 	7 	7 	7 	7 	7r   r^   retry_after_headerc                 2   	 t          t          |                     S # t          $ r Y nw xY w	 t          |           }t	          j        t          j                  }t          d||z
  	                                          S # t          t          f$ r Y dS w xY w)u   Parse a Retry-After header value into seconds from now.

    Handles both the integer-seconds form (RFC 7231 §7.1.3) and the HTTP-date
    form.  Returns None if the value cannot be parsed.
    g        N)rc   int
ValueErrorr   r   nowr   utcmaxtotal_seconds	TypeError)re   
retry_dateri   s      r   parse_retry_afterro      s    S+,,---   *+=>>
l8<((3c)88::;;;	"   tts    
++AB BBr`   default_sleep	max_sleepc                     | | n|t          |          nd}||dk    rdS |t          |t          |                    }|dk    rdS |S )a2  Compute the effective sleep duration for rate-limit handling.

    Returns None when there is no usable duration (meaning the caller should
    re-raise the RateLimitError rather than sleeping).

    Args:
        retry_after_seconds: Parsed seconds from server Retry-After header,
            or None if the server did not provide one.
        default_sleep: Fallback duration when retry_after_seconds is None.
            None means no fallback; re-raise.
        max_sleep: Hard cap on sleep duration.  None means no cap; 0 means
            never sleep.
    Nr   )rc   min)r`   rp   rq   	effectives       r   compute_sleep_secondsru      sr    ( * 	&3&?eM"""T 
 INNt	5#3#344	A~~tr   status_coder4   c                 t    | dvrdS | dk    r|dS |rt          |          nd}t          |d| ||          )a  Raise RateLimitError when the response indicates rate limiting.

    Raises for:
    - Any 429 response (regardless of Retry-After presence)
    - 503 responses that include a Retry-After header

    Args:
        status_code: HTTP status code from the response.
        url: Request URL (included in exception for context).
        retry_after_header: Raw Retry-After header value, or None.
    )  i  Nrx   z2Rate limited or service unavailable. Retry after: )r4   r   r_   r`   )ro   r^   )rv   r4   re   retry_secondss       r   raise_if_rate_limitedrz      sp      *$$c08=OY%&8999UYM
XDVXX&)	   r   c                      t           S r6   )r3   r   r   r   <lambda>r|      s    x r   exception_by_method)deleteput
mkcalendarmkcolreportpropsetpropfind	proppatch   Error)6loggingcollectionsr   r   r   email.utilsr   typingr   r   r   debug_dump_communicationosenvirongetr&   	getLoggerr$   
startswithsetLevelr   WARNINGr@   r   r+   objectr1   r0   rA   	Exceptionr3   rC   rF   rJ   rL   rN   rP   rR   rT   rV   rX   rZ   r\   r^   rc   ro   rg   ru   rz   r}   dictmethodlocalsupperr   r   r   <module>r      s    # # # # # # ' ' ' ' ' ' ' ' - - - - - -              !III  "z~~.FNN
45II!{k99!		 	g!!   "LLLL!!!7 7 7 7 7
	 	 	v $     _c  _  _  _
 
 
 
 
y 
 
 
$	 	 	 	 	 	 	 		 	 	 	 	8 	 	 		 	 	 	 	X 	 	 		 	 	 	 	H 	 	 		 	 	 	 	( 	 	 		 	 	 	 	 	 	 		 	 	 	 	h 	 	 		 	 	 	 	x 	 	 		 	 	 	 	( 	 	 		 	 	 	 	H 	 	 		 	 	 	 	x 	 	 		 	 	 	 	H 	 	 	7 7 7 7 7X 7 7 7 # (5/    $!%C= } e_	   @	 ! 
	   : ,7;7G7G+H+H T#x-( H H H	 
U 
UF #)&((6!9??+<+<vabbz+IG+S"T
U 
Us   ,A A)