
    d.                     b   d dl mZmZmZmZmZmZmZmZm	Z	 d dl m
Z d dl mZ d dlZd Zd Zd Zd Zd	 Zd
 Z G d de          ZdZd Zd Z e            Zd ZeeedeefdZd Z G d de          ZedediZi Z d Z!d Z"d Z#eefdZ$ddeefdZ%ddeefdZ&d Z'i Z(d Z)d  Z*defd!Z+dS )"    )	CheckedPMapCheckedPSetCheckedPVectorCheckedTypeInvariantException_restore_pickleget_typemaybe_parse_user_typemaybe_parse_many_user_types)optional)wrap_invariantNc                     t          t          fd|D             g                     | <   t          |                                           D ](\  }}t	          |t
                    r||          |<   | |= )d S )Nc                     g | ]<}t          |j                            i                                                     =S  )list__dict__getitems).0bnames     \/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/pyrsistent/_field_common.py
<listcomp>zset_fields.<locals>.<listcomp>   s=    PPPQ$qz~~dB77==??@@PPP    )dictsumr   r   
isinstance_PField)dctbasesr   kvs     `  r   
set_fieldsr#      s    SPPPP%PPPRTUUVVCISYY[[!!  1a!! 	CIaLA r   c                 x     t          d  fd|D             D                       }|rt          |dd          d S )Nc              3   $   K   | ]\  }}||V  d S Nr   )r   is_ok
error_codes      r   	<genexpr>z*check_global_invariants.<locals>.<genexpr>   sH       W W'8ujPUW
 W W W W W Wr   c              3   .   K   | ]} |          V  d S r&   r   )r   	invariantsubjects     r   r)   z*check_global_invariants.<locals>.<genexpr>   s-      HH	7++HHHHHHr   r   zGlobal invariant failed)tupler   )r,   
invariantserror_codess   `  r   check_global_invariantsr0      sq     W WHHHHZHHHW W W W WK M b2KLLLM Mr   c                     t          |t                    r| t          u r|                    |          S  | ||          S r&   )r   r   PFIELD_NO_SERIALIZER	serialize)
serializerformatvalues      r   r3   r3   !   sC    %%% '*8L*L*Lv&&&:fe$$$r   c                     |j         rht          fd|j         D                       sJt                    }d                    | j        ||j                  }t	          | ||j         ||          d S d S )Nc              3   R   K   | ]!}t          t          |                    V  "d S r&   )r   r	   )r   tr6   s     r   r)   zcheck_type.<locals>.<genexpr>)   s3      QQj<<QQQQQQr   z'Invalid type for field {0}.{1}, was {2})typeanyr5   __name__
PTypeError)destination_clsfieldr   r6   actual_typemessages      `  r   
check_typerB   (   s    z R#QQQQejQQQQQ R5kk;BB?C[]acncwxx$
KQQQR R R Rr   c                     t          |          t          u rdS t          |          }t          |          dk    rdS t	          t          |d                   |           S )NTr   F)r:   setr-   len
issubclassr	   )type_cls
field_typetypess      r   is_type_clsrJ   /   sW    J3t*E
5zzQuhuQx(((333r   c                 x    |sdS t          | |j                  sdS dt          j        |j                  j        v S )NFignore_extra)rJ   r:   inspect	signaturefactory
parameters)rG   r?   rL   s      r   is_field_ignore_extra_complaintrQ   8   sC     ux,, uW.u}==HHHr   c                   .    e Zd ZdZd Zed             ZdS )r   r:   r+   initial	mandatory_factoryr4   c                 Z    || _         || _        || _        || _        || _        || _        d S r&   rS   )selfr:   r+   rT   rU   rO   r4   s          r   __init__z_PField.__init__G   s0    	""$r   c                     | j         t          u r[t          | j                  dk    rCt	          t          | j                  d                   }t          |t                    r|j        S | j         S )N   r   )	rV   PFIELD_NO_FACTORYrE   r:   r	   r-   rF   r   create)rX   typs     r   rO   z_PField.factoryO   sb     =---#di..A2E2E5++A.//C#{++ "z!}r   N)r<   
__module____qualname__	__slots__rY   propertyrO   r   r   r   r   r   D   sC        WI% % %   X  r   r   r   c                     dS )N)TNr   )_s    r   <lambda>re   Z   s     r   c                     | S r&   r   )xs    r   re   re   [   s    a r   c                     |S r&   r   )rd   r6   s     r   re   re   ]   s     r   Fc                 Z   t          | t          t          t          f          rt          t	          |                     }nt          t          |                     }|t          k    rt          |          rt          |          n|}t          ||||||          }t          |           |S )a  
    Field specification factory for :py:class:`PRecord`.

    :param type: a type or iterable with types that are allowed for this field
    :param invariant: a function specifying an invariant that must hold for the field
    :param initial: value of field if not specified when instantiating the record
    :param mandatory: boolean specifying if the field is mandatory or not
    :param factory: function called when field is set.
    :param serializer: function that returns a serialized version of the field
    )r:   r+   rT   rU   rO   r4   )r   r   rD   r-   r   r
   PFIELD_NO_INVARIANTcallabler   r   _check_field_parameters)	r:   r+   rT   rU   rO   r4   rI   invariant_functionr?   s	            r   r?   r?   `   s    , $sE*++ 1/5566)$//006?CV6V6V[cdm[n[n6V	222t}*<g'ZQ Q QE E"""Lr   c                      j         D ][}t          |t                     sDt          |t                    s/t          d                    t          |                              \ j        t          urot           j                  s[ j         rTt           fd j         D                       s4t          d                    t           j                                      t           j	                  st          d          t           j
                  st          d          t           j                  st          d          d S )Nz Type parameter expected, not {0}c              3   B   K   | ]}t          j        |          V  d S r&   )r   rT   )r   r9   r?   s     r   r)   z*_check_field_parameters.<locals>.<genexpr>   s/      "T"TA:emQ#?#?"T"T"T"T"T"Tr   zInitial has invalid type {0}zInvariant must be callablezFactory must be callablezSerializer must be callable)r:   r   str	TypeErrorr5   rT   PFIELD_NO_INITIALrk   r;   r+   rO   r4   )r?   r9   s   ` r   rl   rl      sG   Z P P!T"" 	P:a+=+= 	P>EEd1ggNNOOO}---'' .J .""T"T"T"T"T"T"TTT . 6==d5=>Q>QRRSSSEO$$ 64555EM"" 42333E$%% 756667 7r   c                   "     e Zd ZdZ fdZ xZS )r=   a  
    Raised when trying to assign a value with a type that doesn't match the declared type.

    Attributes:
    source_class -- The class of the record
    field -- Field name
    expected_types  -- Types allowed for the field
    actual_type -- The non matching type
    c                      t          t          |           j        |i | || _        || _        || _        || _        d S r&   )superr=   rY   source_classr?   expected_typesr@   )rX   rv   r?   rw   r@   argskwargs	__class__s          r   rY   zPTypeError.__init__   sJ    (j$($9&999(
,&r   )r<   r_   r`   __doc__rY   __classcell__)rz   s   @r   r=   r=      sB         ' ' ' ' ' ' ' ' 'r   r=   PVectorPSetc                 @    t           | |f         }t          ||          S )z=Unpickling function for auto-generated PVec/PSet field types.)_seq_field_typesr   )checked_class	item_typedatatype_s       r   _restore_seq_field_pickler      s!    ]I56E5$'''r   c                 @    d                     d | D                       S )z4Convert a tuple of types to a human-readable string. c              3   b   K   | ]*}t          |          j                                        V  +d S r&   )r	   r<   
capitalize)r   r^   s     r   r)   z"_types_to_names.<locals>.<genexpr>   s7      HH38C==)4466HHHHHHr   )join)rI   s    r   _types_to_namesr      s#    77HH%HHHHHHr   c                      t                                f          }||S  G  fdd           }t                    }t          |j                  |z   |_        |t            f<   |S )zFCreate a subclass of the given checked class with the given item type.Nc                   $    e Zd ZZZ fdZdS )%_make_seq_field_type.<locals>.TheTypec                 6    t           t          |           ffS r&   )r   r   )rX   r   r   s    r   
__reduce__z0_make_seq_field_type.<locals>.TheType.__reduce__   s     -"ItDzz:< <r   N)r<   r_   r`   __type____invariant__r   )r   item_invariantr   s   r   TheTyper      s=        &	< 	< 	< 	< 	< 	< 	< 	<r   r   )r   r   SEQ_FIELD_TYPE_SUFFIXESr   _checked_typesr<   )r   r   r   r   r   suffixs   ```   r   _make_seq_field_typer      s      -!;<<E< < < < < < < < <- < < < %]3F&w'=>>GG18]I-.Nr   c           	          t          | ||          |rdfd	}nj        }t          |rt                    n|d| ||                    S )a  
    Create checked field for either ``PSet`` or ``PVector``.

    :param checked_class: ``CheckedPSet`` or ``CheckedPVector``.
    :param item_type: The required type for the items in the set.
    :param optional: If true, ``None`` can be used as a value for
        this field.
    :param initial: Initial value to pass to factory.

    :return: A ``field`` containing a checked class.
    NFc                 <    | d S                      | ||          S )N)_factory_fieldsrL   r]   )argumentr   rL   r   s      r   rO   z _sequence_field.<locals>.factory   s'    t~~h^j~kkkr   T)r:   rO   rU   r+   rT   )NF)r   r]   r?   optional_type)r   r   r   rT   r+   r   rO   r   s          @r   _sequence_fieldr      s     #=)^LLG !	l 	l 	l 	l 	l 	l 	l .EmG,,,g D$ ))+ + + +r   c                 6    t          t          | ||||          S )al  
    Create checked ``PSet`` field.

    :param item_type: The required type for the items in the set.
    :param optional: If true, ``None`` can be used as a value for
        this field.
    :param initial: Initial value to pass to factory if no value is given
        for the field.

    :return: A ``field`` containing a ``CheckedPSet`` of the given type.
    r+   r   )r   r   r   r   rT   r+   r   s        r   
pset_fieldr      s)     ;	8W%.*8: : : :r   c                 6    t          t          | ||||          S )au  
    Create checked ``PVector`` field.

    :param item_type: The required type for the items in the vector.
    :param optional: If true, ``None`` can be used as a value for
        this field.
    :param initial: Initial value to pass to factory if no value is given
        for the field.

    :return: A ``field`` containing a ``CheckedPVector`` of the given type.
    r   )r   r   r   s        r   pvector_fieldr      s)     >9h%.*8: : : :r   c                     dS )N)Tr   r   )items    r   re   re     s    j r   c                 @    t           | |f         }t          ||          S )z8Unpickling function for auto-generated PMap field types.)_pmap_field_typesr   )key_type
value_typer   r   s       r   _restore_pmap_field_pickler     s!    h
23E5$'''r   c                     t                                f          }||S  G  fddt                    }d                    t	          |j                  t	          |j                            |_        |t            f<   |S )zDCreate a subclass of CheckedPMap with the given key and value types.Nc                       e Zd Z ZZd ZdS )%_make_pmap_field_type.<locals>.TheMapc                 H    t           | j        | j        t          |           ffS r&   )r   __key_type____value_type__r   )rX   s    r   r   z0_make_pmap_field_type.<locals>.TheMap.__reduce__(  s'    .&(;T$ZZHJ Jr   N)r<   r_   r`   r   r   r   )r   r   s   r   TheMapr   $  s3        #	J 	J 	J 	J 	Jr   r   z{0}To{1}PMap)r   r   r   r5   r   _checked_key_types_checked_value_typesr<   )r   r   r   r   s   ``  r   _make_pmap_field_typer     s    !!8Z"899EJ J J J J J J J J J J %++1223446 6FO /5h
*+Mr   c                     t          | |          |rfd}nj        }t          d             |rt                    n||          S )ad  
    Create a checked ``PMap`` field.

    :param key: The required type for the keys of the map.
    :param value: The required type for the values of the map.
    :param optional: If true, ``None`` can be used as a value for
        this field.
    :param invariant: Pass-through to ``field``.

    :return: A ``field`` containing a ``CheckedPMap``.
    c                 6    | d S                      |           S r&   r   )r   r   s    r   rO   zpmap_field.<locals>.factoryB  s     t}}X...r   T)rU   rT   r:   rO   r+   )r   r]   r?   r   )r   r   r   r+   rO   r   s        @r   
pmap_fieldr   3  s~     #8Z88F  	/ 	/ 	/ 	/ 	/ 	/ -4/7CmF+++V I7 7 7 7r   ),pyrsistent._checked_typesr   r   r   r   r   r   r	   r
   r   r   r   r   rM   r#   r0   r3   rB   rJ   rQ   objectr   PFIELD_NO_TYPErj   r\   rr   r2   r?   rl   rq   r=   r   r   r   r   r   r   r   r   _validr   r   r   r   r   r   r   <module>r      s  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 @ ? ? ? ? ? 4 4 4 4 4 4   M M M% % %R R R4 4 4I I I    f   * ,, K FHH --  )<FW#4AU! ! ! !H7 7 7(' ' ' ' ' ' ' '& I   ( ( (
I I I  ( 2#6+ + + +> $)",1: : : :& ',R/!4: : : :& 
!	   ( ( (
  * /4?R 7 7 7 7 7 7r   