o
    i*                     @   s  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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'dd  Z(d!d" Z)d#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'd0e(d1e*d2e*d3e)d4e)d5e)Z+d6d7 Z,	8	9	:	:dGd;ed<ed=e-d>e.d?e.d@e.dAe.fdBdCZ/	9	:	:dHdDee d<ed>e.d?e.d@e.dAe.fdEdFZ0dS )I    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                 K   s   | du S )z#Checks that the data value is None.N datumkwargsr   r   ]/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastavro/_validation_py.py_validate_null   s   r   c                 K   
   t | tS )z*Check that the data value is bool instance)
isinstanceboolr   r   r   r   _validate_boolean      
r   c                 K   r   )z#Check that the data value is stringr   strr   r   r   r   _validate_string   r   r"   c                 K   s   t | ttfS )z.Check that the data value is python bytes type)r   bytes	bytearrayr   r   r   r   _validate_bytes   s   r%   c                 K   4   t | ttjfot|   kotkn  o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   r   r   r   _validate_int$   
   

r*   c                 K   r&   )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   r   r   r   _validate_long4   r+   r,   c                 K   s   t | tttjfo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   r   r   r   _validate_floatD   s   r/   c                 K   s   t | to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   r   r   r   _validate_fixedO   s   r4   c                 K   s   | |d v S )z:Check that the data value matches one of the enum symbols.symbolsr   r2   r   r   r   _validate_enumW   s   r6   c                    s:   t | ttjfot | t ot fdd| D S )z:Check that the data list values all match schema['items'].c              	   3   (    | ]}t |d   dV  qdS )itemsr   r3   named_schemasfieldraise_errorsoptionsN	_validate).0dr:   r=   	parent_nsr<   r3   r   r   	<genexpr>a       	
z"_validate_array.<locals>.<genexpr>)r   r   arrayr!   allr   r3   r:   rC   r<   r=   r   rB   r   _validate_array\   s   
	rI   c                    s>   t | totdd | D ot fdd|  D S )zY
    Check that the data is a Map(k,v)
    matching values to schema['values'] type.
    c                 s   s    | ]}t |tV  qd S )Nr    )r@   kr   r   r   rD   v   s    z _validate_map.<locals>.<genexpr>c              	   3   r7   )valuesr9   Nr>   )r@   vrB   r   r   rD   w   rE   )r   r   rG   rK   rH   r   rB   r   _validate_mapo   s   
	rM   c                    sP   t ||\}t to'd v o d k o't fdd|d D S )ze
    Check that the data is a Mapping type with all schema defined fields
    validated as True.
    z-typec              	   3   sJ    | ] }t  |d  |dt|d  d|d   dV  qdS )namedefaulttype.r9   N)r?   getNoValue)r@   fr   fullnamer:   r=   r<   r   r   rD      s    	
z#_validate_record.<locals>.<genexpr>fields)r   r   r   rG   )r   r3   r:   rC   r<   r=   _r   rU   r   _validate_record   s   
	rY   c                 C   s   t | tr2|ds2| \}} |D ]}t|dkr|d }n|}||kr/t| |||||d  S qdS g }	|D ],}
zt| |
||||d}|rIW  dS W q6 tyb } z|	|j W Y d}~q6d}~ww |rit|	 dS )z[
    Check that the data is a list type with possible options to
    validate as True.
    disable_tuple_notationrecordrN   r3   r:   r;   r<   r=   FTN)r   tuplerR   r   r?   r   extenderrors)r   r3   r:   rC   r<   r=   rN   	candidater   r_   sreter   r   r   _validate_union   sL   


rd   nullbooleanstringr'   longr-   doubler#   fixedenumrF   mapunionerror_unionr[   errorrequestc                 C   s   t |}d }| tu r|drd}n?| tu rd } t|}|r*t|}	|	r*|	| |} t|}
|
r<|
| |||||d}n||v rMt| || ||||d}nt||r_|du r_tt	| |||S )NstrictF)r3   r:   rC   r<   r=   r\   )
r   rS   rR   r   r   
VALIDATORSr?   r   r   r   )r   r3   r:   r;   r<   r=   record_typeresultlogical_typeprepare	validatorr   r   r   r?      sD   


	r?    TFr   r3   r;   r<   rq   rZ   returnc              	   C   s(   i }t ||}t| ||||||d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)
    rq   rZ   )r=   )r   r?   )r   r3   r;   r<   rq   rZ   r:   parsed_schemar   r   r   validate  s   %
r|   recordsc                 C   s   i }t ||}g }g }| D ],}	z|t|	||d|||dd W q ty9 }
 z||
j W Y d}
~
qd}
~
ww |rB|rBt| t|S )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)
    rx   rz   )r;   r<   r=   N)r   appendr?   r   r^   r_   rG   )r}   r3   r<   rq   rZ   r:   r{   r_   resultsr[   rc   r   r   r   validate_many<  s2   "
r   )rx   TFF)TFF)1rF   r(   collections.abcr   r   typingr   r   constr   r   r	   r
   _validate_commonr   r   r3   r   r   r   r   logical_writersr   _schema_commonr   typesr   r   objectrS   r   r   r"   r%   r*   r,   r/   r4   r6   rI   rM   rY   rd   rr   r?   r!   r   r|   r   r   r   r   r   <module>   s    -	
0
4