
    #Zj              
       n   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dS )!    Ndeepcopy)AnyCallableProtocolTypeVar   )VARIABLE_RE)ConfigValidationError_DInc                   4    e Zd ZdZdedeegef         fdZdS )	DecoratorzLProtocol to mark a function as returning its child with identical signature.namereturnc                     d S N )selfr   s     [/Users/jameslopez/projects/MentorCore/.venv/lib/python3.11/site-packages/confection/util.py__call__zDecorator.__call__   s          N)__name__
__module____qualname____doc__strr   r   r   r   r   r   r   r      s7        VV@S@Xtfdl%;@@@@@@r   r   PartialTfunc.argskwargsr   c                 H    t          j        | g|R 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#      s4     $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                H     t                      j        |i | || _        dS )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   r   c                *    t          | j                  r   r.   )r   otherr    s      r   updatezSimpleFrozenDict.updateG   r3   r   c                 ~    |                      t          d |                                 D                                 S )Nc                     i | ]\  }}||	S r   r   ).0kvs      r   
<dictcomp>z1SimpleFrozenDict.__deepcopy__.<locals>.<dictcomp>K   s    'F'F'FA1'F'F'Fr   )r,   r   itemsr   memos     r   __deepcopy__zSimpleFrozenDict.__deepcopy__J   s3    ~~h'F'F'F'F'FGGHHHr   r   )r   )r   r   r   r   DEFAULT_FROZEN_DICT_ERRORr   r+   r2   r6   r9   rC   __classcell__r,   s   @r   r&   r&   -   s          /   
 
     . . .. . . .. . . .I I I I I I 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                B    || _          t                      j        |  dS )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.   rK   s      r   clearzSimpleFrozenList.cleare   r3   r   c                 *    t          | j                  r   r.   rK   s      r   extendzSimpleFrozenList.extendh   r3   r   c                 *    t          | j                  r   r.   rK   s      r   insertzSimpleFrozenList.insertk   r3   r   c                 *    t          | j                  r   r.   rK   s      r   r6   zSimpleFrozenList.popn   r3   r   c                 *    t          | j                  r   r.   rK   s      r   removezSimpleFrozenList.removeq   r3   r   c                 *    t          | j                  r   r.   rK   s      r   reversezSimpleFrozenList.reverset   r3   r   c                 *    t          | j                  r   r.   rK   s      r   sortzSimpleFrozenList.sortw   r3   r   c                 @    |                      d | D                       S )Nc              3   4   K   | ]}t          |          V  d S r   r   )r<   r>   s     r   	<genexpr>z0SimpleFrozenList.__deepcopy__.<locals>.<genexpr>{   s(      88ahqkk888888r   rF   rA   s     r   rC   zSimpleFrozenList.__deepcopy__z   s#    ~~884888888r   )r   r   r   r   DEFAULT_FROZEN_LIST_ERRORr   r+   rL   rN   rP   rR   r6   rU   rW   rY   rC   rE   rF   s   @r   rH   rH   N   s          /
  
  
  
  
	
  
  
  
  
  
 . . .. . .. . .. . .. . .. . .. . .. . .9 9 9 9 9 9 9r   rH   c                     t          | d          sdS d |                                 D             }t          |          rdS dS )NkeysFc                 f    g | ].}t          |t                    |                    d           ,|/S )@)
isinstancer   
startswith)r<   r=   s     r   
<listcomp>zis_promise.<locals>.<listcomp>   s8    QQQQ
1c(:(:Qq||C?P?PQqQQQr   T)hasattrr_   len)objid_keyss     r   
is_promiseri   ~   sL    3 uQQ#((**QQQG
7|| t5r   TF)TrueFalseNoner1   c                     	 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_jsonrr      sX    z%      $$$#E****s     === datac                 $   t          | t                    rt          j        |           r| S 	 t	          j        |           } n:# t          $ r-}dt          |            d| d}t          ||          |d}~ww xY wt          j
        dd|           S )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$$)rb   r   r
   searchrn   dumpsrp   typer   resub)r1   rt   eerr_msgs       r   try_dump_jsonr      s     % +"4U";"; 	F
5!! F F F#tE{{ # #a # # # 	 $4g>>>AEF 6+tU+++s   A 
A9(A44A9)rs   )r"   rn   r{   copyr   typingr   r   r   r   
_constantsr
   _errorsr   r   r   r   r#   rD   r]   dictr&   listrH   boolri   rq   r   rr   r   r   r   r   <module>r      s        				       3 3 3 3 3 3 3 3 3 3 3 3 # # # # # # * * * * * *wvA A A A A A A A 7:
3=
!*-9<c8m   = - I I I I It I I IB-9 -9 -9 -9 -9t -9 -9 -9`t     !5$??      , , ,DdOc$9 ,3 , , , , , ,r   