
    i              
       <   d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	 ddl
mZ ddlmZ  e	d      Z G d d	e      Z e	d
      Zdedef   dedededef   fdZdZdZ G d de      Z G d de      ZdefdZddddZdedefdZddedeeef   ez  defdZy)     Ndeepcopy)AnyCallableProtocolTypeVar   )VARIABLE_RE)ConfigValidationError_DInc                   ,    e Zd ZdZdedeegef   fdZy)	DecoratorzLProtocol to mark a function as returning its child with identical signature.namereturnc                      y N )selfr   s     `/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/confection/util.py__call__zDecorator.__call__   s        N)__name__
__module____qualname____doc__strr   r   r   r   r   r   r   r      s    V@S@Xtfdl%;@r   r   PartialTfunc.argskwargsr   c                 Z    t        j                  | g|i |}| j                  |_        |S )znWrapper around functools.partial that retains docstrings and can include
    other workarounds if needed.
    )	functoolspartialr   )r   r   r    partial_funcs       r   r#   r#      s0     $$T;D;F;L<<Lr   zsCan't write to frozen dictionary. This is likely an internal error. Are you writing to a default function argument?zkCan't write to frozen list. Maybe you're trying to modify a computed property or default function argument?c                   N     e Zd ZdZeddeddf fdZd ZddZdd	Z	d
 Z
 xZS )SimpleFrozenDictzSimplified implementation of a frozen dict, mainly used as default
    function or method argument (for arguments that should default to empty
    dictionary). Will raise an error if the user attempts to add to dict.
    errorr(   r   Nc                2    t        |   |i | || _        y)zInitialize the frozen dict. Can be initialized with pre-defined
        values.

        error (str): The error message when user tries to assign to dict.
        N)super__init__r(   )r   r(   r   r    	__class__s       r   r+   zSimpleFrozenDict.__init__3   s     	$)&)
r   c                 ,    t        | j                        r   NotImplementedErrorr(   )r   keyvalues      r   __setitem__zSimpleFrozenDict.__setitem__A       !$**--r   c                 ,    t        | j                        r   r.   )r   r0   defaults      r   popzSimpleFrozenDict.popD   r3   r   c                ,    t        | j                        r   r.   )r   otherr    s      r   updatezSimpleFrozenDict.updateG   r3   r   c           
          | j                  t        | j                         D ci c]  \  }}||
 c}}            S c c}}w r   )r,   r   items)r   memokvs       r   __deepcopy__zSimpleFrozenDict.__deepcopy__J   s2    ~~h'FA1'FGHH'Fs   =r   )r   )r   r   r   r   DEFAULT_FROZEN_DICT_ERRORr   r+   r2   r6   r9   r?   __classcell__r,   s   @r   r&   r&   -   s;     / 
 
...Ir   r&   c                   h     e Zd ZdZeddeddf fdZd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Z xZS )SimpleFrozenListaj  Wrapper class around a list that lets us raise custom errors if certain
    attributes/methods are accessed. Mostly used for properties that return an
    immutable list (and that we don't want to convert to a tuple to not break
    too much backwards compatibility). If a user accidentally calls
    frozen_list.append(), we can raise a more helpful error.
    r'   r(   r   Nc                ,    || _         t        |   |  y)zpInitialize the frozen list.

        error (str): The error message when user tries to mutate the list.
        N)r(   r*   r+   )r   r(   r   r,   s      r   r+   zSimpleFrozenList.__init__V   s     
$r   c                 ,    t        | j                        r   r.   r   r   r    s      r   appendzSimpleFrozenList.appendb   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   clearzSimpleFrozenList.cleare   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   extendzSimpleFrozenList.extendh   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   insertzSimpleFrozenList.insertk   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   r6   zSimpleFrozenList.popn   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   removezSimpleFrozenList.removeq   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   reversezSimpleFrozenList.reverset   r3   r   c                 ,    t        | j                        r   r.   rG   s      r   sortzSimpleFrozenList.sortw   r3   r   c                 2    | j                  d | D              S )Nc              3   2   K   | ]  }t        |        y wr   r   ).0r>   s     r   	<genexpr>z0SimpleFrozenList.__deepcopy__.<locals>.<genexpr>{   s     8ahqk8s   rB   )r   r<   s     r   r?   zSimpleFrozenList.__deepcopy__z   s    ~~84888r   )r   r   r   r   DEFAULT_FROZEN_LIST_ERRORr   r+   rH   rJ   rL   rN   r6   rQ   rS   rU   r?   rA   rB   s   @r   rD   rD   N   sS     /
  
  
	
 ........9r   rD   c                     t        | d      sy| j                         D cg c]'  }t        |t              s|j	                  d      s&|) }}t        |      ryyc c}w )NkeysF@T)hasattrr\   
isinstancer   
startswithlen)objr=   id_keyss      r   
is_promiserd   ~   sO    3((*QQ
1c(:q||C?PqQGQ
7| Rs   AAATF)TrueFalseNoner1   c                 v    	 t        j                  |       S # t        $ r | t        v rt        |    cY S | cY S w xY w)zLoad a JSON string if possible, otherwise default to original value.

    Also handles Python-style literals ``True``, ``False``, and ``None``
    which are not valid JSON but are commonly used in config files.
    )jsonloads	Exception_PYTHON_LITERALS)r1   s    r   try_load_jsonrm      s>    zz%   $$#E**s    888datac                    t        | t              rt        j                  |       r| S 	 t	        j
                  |       } t        j                  dd|       S # t        $ r%}dt        |        d| d}t        ||      |d}~ww xY w)zGDump a config value as JSON and output user-friendly error if it fails.z(Couldn't serialize config value of type z: z. Make sure all values in your config are JSON-serializable. If you want to include Python objects, use a registered function that returns the object instead.)configdescNz\$(?!\{)z$$)r_   r   r
   searchri   dumpsrk   typer   resub)r1   rn   eerr_msgs       r   try_dump_jsonry      s     %+"4"4U";	F

5! 66+tU++  F6tE{m2aS I" # 	 $4g>AEFs   A 	B A>>B) )r"   ri   ru   copyr   typingr   r   r   r   
_constantsr
   _errorsr   r   r   r   r#   r@   rZ   dictr&   listrD   boolrd   rl   r   rm   ry   r   r   r   <module>r      s      	  3 3 # *vA A :
3=
!*-9<c8m= - It IB-9t -9`t  !5$?   , ,DdOc$9 ,3 ,r   