o
    i                  
   @   s   d dl Z d dlZd dlmZ d dlmZmZmZmZ ej	dk r&d dl
mZ nd dlmZ edZG dd deZed	Zd
edef dedededef fddZG dd deZdZdZG dd deZG dd deZdS )    Ndeepcopy)AnyCallableIteratorTypeVar)      )Protocol_DInc                   @   s,   e Zd ZdZdedeegef fddZdS )	DecoratorzLProtocol to mark a function as returning its child with identical signature.namereturnc                 C   s   d S N )selfr   r   r   C/home/ubuntu/.local/lib/python3.10/site-packages/confection/util.py__call__   s   zDecorator.__call__N)__name__
__module____qualname____doc__strr   r   r   r   r   r   r   r      s     r   PartialTfunc.argskwargsr   c                 O   s$   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_funcr   r   r   r      s   r   c                   @   s(   e Zd ZdZedd Zedd ZdS )	GeneratorzCustom generator type. Used to annotate function arguments that accept
    generators so they can be validated by pydantic (which doesn't support
    iterators/iterables otherwise).
    c                 c   s    | j V  d S r   )validate)clsr   r   r   __get_validators__+   s   zGenerator.__get_validators__c                 C   s    t |dst |dstd|S )N__iter____next__znot a valid iterator)hasattr	TypeError)r"   vr   r   r   r!   /   s   zGenerator.validateN)r   r   r   r   classmethodr#   r!   r   r   r   r   r    %   s    
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                       sR   e Zd ZdZeddeddf fddZdd	 Zdd
dZdd Z	dd Z
  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                   s   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__r   r   r.   G   s   
zSimpleFrozenDict.__init__c                 C   
   t | jr   NotImplementedErrorr,   )r   keyvaluer   r   r   __setitem__U      
zSimpleFrozenDict.__setitem__c                 C   r1   r   r2   )r   r4   defaultr   r   r   popX   r7   zSimpleFrozenDict.popc                 C   r1   r   r2   )r   otherr   r   r   update[   r7   zSimpleFrozenDict.updatec                 C   s   |  tdd |  D S )Nc                 S   s   i | ]\}}||qS r   r   ).0kr(   r   r   r   
<dictcomp>_   s    z1SimpleFrozenDict.__deepcopy__.<locals>.<dictcomp>)r0   r   itemsr   memor   r   r   __deepcopy__^   s   zSimpleFrozenDict.__deepcopy__r   )r   r   r   r   DEFAULT_FROZEN_DICT_ERRORr   r.   r6   r9   r;   rB   __classcell__r   r   r/   r   r*   A   s    
r*   c                       sx   e Zd ZdZeddeddf fddZdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Z  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                   s   || _ 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/   r   r   r.   j   s   	zSimpleFrozenList.__init__c                 O   r1   r   r2   r   r   r   r   r   r   appendv   r7   zSimpleFrozenList.appendc                 O   r1   r   r2   rF   r   r   r   cleary   r7   zSimpleFrozenList.clearc                 O   r1   r   r2   rF   r   r   r   extend|   r7   zSimpleFrozenList.extendc                 O   r1   r   r2   rF   r   r   r   insert   r7   zSimpleFrozenList.insertc                 O   r1   r   r2   rF   r   r   r   r9      r7   zSimpleFrozenList.popc                 O   r1   r   r2   rF   r   r   r   remove   r7   zSimpleFrozenList.removec                 O   r1   r   r2   rF   r   r   r   reverse   r7   zSimpleFrozenList.reversec                 O   r1   r   r2   rF   r   r   r   sort   r7   zSimpleFrozenList.sortc                 C   s   |  dd | D S )Nc                 s   s    | ]}t |V  qd S r   r   )r<   r(   r   r   r   	<genexpr>   s    z0SimpleFrozenList.__deepcopy__.<locals>.<genexpr>r/   r@   r   r   r   rB      s   zSimpleFrozenList.__deepcopy__)r   r   r   r   DEFAULT_FROZEN_LIST_ERRORr   r.   rG   rH   rI   rJ   r9   rK   rL   rM   rB   rD   r   r   r/   r   rE   b   s"    
rE   )r   syscopyr   typingr   r   r   r   version_infotyping_extensionsr
   r   r   r   r   r    rC   rO   dictr*   listrE   r   r   r   r   <module>   s4    



!