
    ciP                    R   d dl mZ d dlmZ d dlZd dlmZmZmZ d dl	m
Z
 d dlmZ erd dlmZmZ d dlmZ 	 	 	 	 dd	Zd
 Zd Zd Zd Zd Zd Zd Zd Z ed       G d d             Z eeeeeeeeed      Zej9                  d      Zej=                  dd       ZeZ e Z!e!Z"y)    )annotations)TYPE_CHECKINGN)evolvefieldfrozen)HashTrieMap)UndefinedTypeCheck)CallableMapping)Anyc                ,    t        j                  |       S N)r   convert)init_vals    8/tmp/pip-target-z3e9_cxr/lib/python/jsonschema/_types.py_typed_map_converterr      s     x((    c                "    t        |t              S r   )
isinstancelistcheckerinstances     r   is_arrayr          h%%r   c                "    t        |t              S r   )r   boolr   s     r   is_boolr      r   r   c                D    t        |t              ryt        |t              S NF)r   r   intr   s     r   
is_integerr"   "   s    (D!h$$r   c                
    |d u S r    r   s     r   is_nullr%   )   s    tr   c                X    t        |t              ryt        |t        j                        S r    )r   r   numbersNumberr   s     r   	is_numberr)   -   s     (D!h//r   c                "    t        |t              S r   )r   dictr   s     r   	is_objectr,   4   r   r   c                "    t        |t              S r   )r   strr   s     r   	is_stringr/   8   s    h$$r   c                     y)NTr$   r   s     r   is_anyr1   <   s    r   Freprc                  b    e Zd ZU dZ e e       e      Zded<   d Z	ddZ
ddZdddZdd	Zy
)TypeCheckeram  
    A :kw:`type` property checker.

    A `TypeChecker` performs type checking for a `Validator`, converting
    between the defined JSON Schema types and some associated Python types or
    objects.

    Modifying the behavior just mentioned by redefining which Python objects
    are considered to be of which JSON Schema types can be done using
    `TypeChecker.redefine` or `TypeChecker.redefine_many`, and types can be
    removed via `TypeChecker.remove`. Each of these return a new `TypeChecker`.

    Arguments:

        type_checkers:

            The initial mapping of types to their checking functions.

    )default	converter4HashTrieMap[str, Callable[[TypeChecker, Any], bool]]_type_checkersc                    dj                  d t        | j                        D              }d| j                  j                   d| dS )Nz, c              3  2   K   | ]  }t        |        y wr   r2   ).0ks     r   	<genexpr>z'TypeChecker.__repr__.<locals>.<genexpr>[   s     Ga$q'Gs   <z types={z}>)joinsortedr9   	__class____name__)selftypess     r   __repr__zTypeChecker.__repr__Z   sA    		G6$2E2E+FGG4>>**+9UG3??r   c                f    	 | j                   |   } || |      S # t        $ r t        |      dw xY w)ac  
        Check if the instance is of the appropriate type.

        Arguments:

            instance:

                The instance to check

            type:

                The name of the type that is expected.

        Raises:

            `jsonschema.exceptions.UndefinedTypeCheck`:

                if ``type`` is unknown to this object.

        N)r9   KeyErrorr	   )rD   r   typefns       r   is_typezTypeChecker.is_type^   sD    *	5$$T*B $!!  	5$T*4	5s    0c                (    | j                  ||i      S )a  
        Produce a new checker with the given type redefined.

        Arguments:

            type:

                The name of the type to check.

            fn (collections.abc.Callable):

                A callable taking exactly two parameters - the type
                checker calling the function and the instance to check.
                The function should return true if instance is of this
                type and false otherwise.

        )redefine_many)rD   rI   rJ   s      r   redefinezTypeChecker.redefinez   s    $ !!4*--r   c                R    | j                   j                  |      }t        | |      S )z
        Produce a new checker with the given types redefined.

        Arguments:

            definitions (dict):

                A dictionary mapping types to their checking functions.

        type_checkers)r9   updater   )rD   definitionsrQ   s      r   rM   zTypeChecker.redefine_many   s'     ++22;?d-88r   c                    | j                   }|D ]  }	 |j                  |      } t	        | |      S # t        $ r t        |      dw xY w)a*  
        Produce a new checker with the given types forgotten.

        Arguments:

            types:

                the names of the types to remove.

        Raises:

            `jsonschema.exceptions.UndefinedTypeCheck`:

                if any given type is unknown to this object

        NrP   )r9   removerH   r	   r   )rD   rE   rQ   eachs       r   rU   zTypeChecker.remove   s`    " ++ 	9D9 - 4 4T :	9
 d-88  9(.D89s	   3A	N)rI   r.   returnr   )rI   r.   rW   r5   )r$   )rW   r5   )rC   
__module____qualname____doc__r   r   r   r9   __annotations__rF   rK   rN   rM   rU   r$   r   r   r5   r5   @   s@    , 	km/CD   E@"8.(99r   r5   )anyarraybooleanintegerobjectnullnumberstringr\   r_   c                b    t        | |      xs" t        |t              xr |j                         S r   )r"   r   floatr   s     r   <lambda>rf      s/    7H% 	Cx'AH,?,?,A r   )r   z0Mapping[str, Callable[[TypeChecker, Any], bool]]rW   r8   )#
__future__r   typingr   r'   attrsr   r   r   rpdsr   jsonschema.exceptionsr	   collections.abcr
   r   r   r   r   r   r"   r%   r)   r,   r/   r1   r5   draft3_type_checkerrU   draft4_type_checkerrN   draft6_type_checkerdraft7_type_checkerdraft201909_type_checkerdraft202012_type_checkerr$   r   r   <module>rs      s    "    ' '  41)>)9)&&%0&% Ur9 r9 r9j "	  *007 )22  * . 3 r   