
    g*                        d dl Z d dlZd dlmZmZ d dlmZmZ ddlm	Z	m
Z
mZmZ ddlmZmZ ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZ  e       Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*i dedede de"de#de$de$de!d e%d!e&d"e'd#e(d$e*d%e*d&e)d'e)d(e)Z+d) Z,	 	 	 	 d4d*ed+ed,e-d-e.d.e.d/e.d0e.fd1Z/	 	 	 d5d2ee   d+ed-e.d.e.d/e.d0e.fd3Z0y)6    N)MappingSequence)AnyIterable   )INT_MAX_VALUEINT_MIN_VALUELONG_MAX_VALUELONG_MIN_VALUE)ValidationErrorValidationErrorData)extract_record_typeextract_logical_typeschema_nameparse_schema)LOGICAL_WRITERS)UnknownType)SchemaNamedSchemasc                 
    | du S )z#Checks that the data value is None.N datumkwargss     L/var/www/openai/venv/lib/python3.12/site-packages/fastavro/_validation_py.py_validate_nullr      s    D=    c                 "    t        | t              S )z*Check that the data value is bool instance)
isinstanceboolr   s     r   _validate_booleanr!      s    eT""r   c                 "    t        | t              S )z#Check that the data value is stringr   strr   s     r   _validate_stringr%      s    eS!!r   c                 .    t        | t        t        f      S )z.Check that the data value is python bytes type)r   bytes	bytearrayr   s     r   _validate_bytesr)      s    eeY/00r   c                     t        | t        t        j                  f      xr+ t        | cxk  xr	 t
        k  nc xr t        | t               S )z
    Check that the data value is a non floating
    point number with size less that Int32.

    Int32 = -2147483648<=datum<=2147483647

    conditional python types: int, numbers.Integral
    )r   intnumbersIntegralr	   r   r    r   s     r   _validate_intr.   $   sB     	53 0 012 	(U3m3	(5$''r   c                     t        | t        t        j                  f      xr+ t        | cxk  xr	 t
        k  nc xr t        | t               S )z
    Check that the data value is a non floating
    point number with size less that long64.

    Int64 = -9223372036854775808 <= datum <= 9223372036854775807

    conditional python types: int, numbers.Integral
    )r   r+   r,   r-   r   r
   r    r   s     r   _validate_longr0   4   sB     	53 0 012 	(e5~5	(5$''r   c                 r    t        | t        t        t        j                  f      xr t        | t
               S )z
    Check that the data value is a floating
    point number or double precision.

    conditional python types
    (int, float, numbers.Real)
    )r   r+   floatr,   Realr    r   s     r   _validate_floatr4   D   s,     ec5',,78XESWAX=XXr   c                 H    t        | t              xr t        |       |d   k(  S )zb
    Check that the data value is fixed width bytes,
    matching the schema['size'] exactly!
    size)r   r'   lenr   schemar   s      r   _validate_fixedr:   O   s#    
 eU#DE
fVn(DDr   c                     | |d   v S )z:Check that the data value matches one of the enum symbols.symbolsr   r8   s      r   _validate_enumr=   W   s    F9%%%r   c                     t        | t        t        j                  f      xr+ t        | t               xr t	        fd| D              S )z:Check that the data list values all match schema['items'].c           	   3   F   K   | ]  }t        |d            yw)itemsr   r9   named_schemasfieldraise_errorsoptionsN	_validate).0drB   rE   	parent_nsrD   r9   s     r   	<genexpr>z"_validate_array.<locals>.<genexpr>a   s=      

  g+)     !)r   r   arrayr$   allr   r9   rB   rJ   rD   rE   s    `````r   _validate_arrayrP   \   sK     	58U[[12 	
5#&&	
 

 

 

r   c                     t        | t              xr: t        d | D              xr& t        fd| j                         D              S )zY
    Check that the data is a Map(k,v)
    matching values to schema['values'] type.
    c              3   <   K   | ]  }t        |t                y w)Nr#   )rH   ks     r   rK   z _validate_map.<locals>.<genexpr>v   s     2Eq
1c"Es   c           	   3   F   K   | ]  }t        |d            yw)valuesrA   NrF   )rH   vrB   rE   rJ   rD   r9   s     r   rK   z _validate_map.<locals>.<genexpr>w   s>      

 $ h'+)  $rL   )r   r   rN   rU   rO   s    `````r   _validate_maprW   o   sI     	5'" 	
2E22	
 

 \\^

 

r   c                      t        ||      \  }t         t              xr, d v xr  d   k7   xr t         fd|d   D              S )ze
    Check that the data is a Mapping type with all schema defined fields
    validated as True.
    z-typec           
   3      K   | ]G  }t        j                  |d    |j                  dt                    |d    d|d            I yw)namedefaulttype.rA   N)rG   getNoValue)rH   fr   fullnamerB   rE   rD   s     r   rK   z#_validate_record.<locals>.<genexpr>   sf      

 & ii&	155G+DEy+!
!AfI;/)  &s   AAfields)r   r   r   rN   )r   r9   rB   rJ   rD   rE   _ra   s   ` ` `` @r   _validate_recordrd      sc    
 fi0KAx5'" 	
E!@eGn&@A	
 

 H%

 

r   c           	      p   t        | t              rL|j                  d      s;| \  }} |D ]0  }t        |      dk(  r|d   }n|}||k(  st	        | |||||      c S  yg }	|D ]  }
	 t	        | |
||||      }|r y |rt        |	 y# t
        $ r%}|	j                  |j                         Y d}~Od}~ww xY w)z[
    Check that the data is a list type with possible options to
    validate as True.
    disable_tuple_notationrecordrZ   r9   rB   rC   rD   rE   FTN)r   tupler^   r   rG   r   extenderrors)r   r9   rB   rJ   rD   rE   rZ   	candidater   rk   sretes                r   _validate_unionrp      s    
 %4L(MuI"9-9'/'d" $"/#!-#    F	$+)C    v&&	  	$MM!((##	$s   %B	B5B00B5nullbooleanstringr+   longr2   doubler'   fixedenumrM   mapunionerror_unionrg   errorrequestc                    t        |      }d }| t        u r|j                  d      rd}n| t        u rd } t        |      }|r t	        j                  |      }	|	r	 |	| |      } t
        j                  |      }
|
r |
| |||||      }n$||v rt        | ||   ||||      }nt        |      |r|du rt        t        | ||            |S )NstrictF)r9   rB   rJ   rD   rE   rh   )
r   r_   r^   r   r   
VALIDATORSrG   r   r   r   )r   r9   rB   rC   rD   rE   record_typeresultlogical_typeprepare	validators              r   rG   rG      s    %f-KFGKK1GE+F3%)),7Gv.NN;/	+)F M)$[1+)F k**%1%GHHMr   r   r9   rC   rD   r~   rf   returnc           
      F    i }t        ||      }t        | ||||||d      S )a  
    Determine if a python datum is an instance of a schema.

    Parameters
    ----------
    datum
        Data being validated
    schema
        Schema
    field
        Record field being validated
    raise_errors
        If true, errors are raised for invalid data. If false, a simple
        True (valid) or False (invalid) result is returned
    strict
        If true, fields without values will raise errors rather than implicitly
        defaulting to None
    disable_tuple_notation
        If set to True, tuples will not be treated as a special case. Therefore,
        using a tuple to indicate the type of a record will not work


    Example::

        from fastavro.validation import validate
        schema = {...}
        record = {...}
        validate(record, schema)
    r~   rf   )rE   )r   rG   )r   r9   rC   rD   r~   rf   rB   parsed_schemas           r   validater     s;    J #%M 7M!=ST r   recordsc                    i }t        ||      }g }g }| D ]&  }		 |j                  t        |	||d|||d             ( |r
|rt        | t        |      S # t        $ r%}
|j	                  |
j
                         Y d}
~
id}
~
ww xY w)a  
    Validate a list of data!

    Parameters
    ----------
    records
        List of records to validate
    schema
        Schema
    raise_errors
        If true, errors are raised for invalid data. If false, a simple
        True (valid) or False (invalid) result is returned
    strict
        If true, fields without values will raise errors rather than implicitly
        defaulting to None
    disable_tuple_notation
        If set to True, tuples will not be treated as a special case. Therefore,
        using a tuple to indicate the type of a record will not work


    Example::

        from fastavro.validation import validate_many
        schema = {...}
        records = [{...}, {...}, ...]
        validate_many(records, schema)
     r   )rC   rD   rE   N)r   appendrG   r   rj   rk   rN   )r   r9   rD   r~   rf   rB   r   rk   resultsrg   ro   s              r   validate_manyr   <  s    D #%M 7MFG	$NN!!!-"(2H
 " v&&w<	  	$MM!((##	$s   #A	BA>>B)r   TFF)TFF)1rM   r,   collections.abcr   r   typingr   r   constr   r	   r
   r   _validate_commonr   r   r9   r   r   r   r   logical_writersr   _schema_commonr   typesr   r   objectr_   r   r!   r%   r)   r.   r0   r4   r:   r=   rP   rW   rd   rp   r   rG   r$   r    r   r   r   r   r   <module>r      s     -   O O B X X , ' '
(
#
"
1
  YE&
&,.*Z
N   
=	
 N _ o _ _ N _ 
= _ ?   !" #
**` #(... . 	.
 . !. 
.h #(9c]99 9 	9
 !9 
9r   