o
    i;                     @  s*  U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
l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 m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1 dZ2edYddZ3da4dZddZ5e#de.Z6d[d"d#Z7d\d&d'Z8e,e&hB Z9dZd(d)Z:d]d,d-Z;d^d/d0Z<d_d2d3Z=i d4d5id4d6id4d7ifZ>d8e?d9< dZd:d;Z@d`d=d>ZAdad@dAZBdbdCdDZCdZdEdFZDdZdGdHZEdcdIdJZFdZdKdLZGdZdMdNZHdddPdQZIdedRdSZJdfdWdXZKdS )gaP  The JSON Schema generator for Logfire.

There are custom keywords in the generated JSON Schema. They are prefixed with `x-` to avoid
conflicts with the official keywords. The custom keywords are:

- `x-python-datatype`: The Python data type of the value. It is used to generate the Python type hints.
- `x-columns`: The column names of the data frame. It is used to generate the Python type.
- `x-indices`: The index names of the data frame. It is used to generate the Python type.
- `x-column-count`: The number of columns in the data frame. It is used to generate the Python type.
- `x-row-count`: The number of rows in the data frame. It is used to generate the Python type.
- `x-shape`: The shape of the numpy array. It is used to generate the Python type.
- `x-dtype`: The data type of the numpy array. It is used to generate the Python type.
    )annotationsN)deque)IterableMappingSequence)suppress)Decimal)Enum)	lru_cache)IPv4AddressIPv4InterfaceIPv4NetworkIPv6AddressIPv6InterfaceIPv6Network)	PosixPath)GeneratorType)AnyCallableNewTypecast   )ATTRIBUTES_SCRUBBED_KEY)is_attrsis_sqlalchemyto_json_value)STACK_INFO_KEYS)JsonDict	dump_jsonlog_internal_error	safe_repr)create_json_schema!attributes_json_schema_propertiesattributes_json_schemaJsonSchemaPropertiesreturn?dict[type[Any], JsonDict | Callable[[Any, set[int]], JsonDict]]c                  C  s6  i t ttttttddddtjddddtjddddtj	ddddtj
dd	d
tttdddtdddtdddtdddtdddtdddtjdddtjdddtddd
tddddtti} tt/ dd l}| |j ddd
|j!ddd
|j"ddd
|j#ddd
|j$t%|j&t'i W d    n1 sw   Y  tt dd l(}| |j)ddd
i W d    n1 sw   Y  tt dd l*}| |j+t,i W d    n1 sw   Y  tt dd l-}| |j.t/i W d    | S 1 sw   Y  | S )Nstringdecimalr   )typeformatx-python-datatypez	date-timedatetimedatetime	timedeltar)   r+   ipv4)r)   r*   ipv6ipv4interfaceipv6interfaceipv4networkipv6networkregexuuidarrayrangepathr   r   	NameEmail	SecretStrSecretBytesAnyUrlUrl)0bytes_bytes_schema	bytearray_bytearray_schemar	   _enum_schemar   r,   r-   r.   r/   r   _generator_schemar   r   r   r   r   r   rePatternr8   UUIDr:   r   	Exception_exception_schema
contextlibr   ModuleNotFoundErrorpydanticupdater<   r=   r>   r?   	BaseModel_pydantic_model_schema	RootModel_pydantic_root_model_schemapydantic_corer@   numpyndarray_numpy_schemapandas	DataFrame_pandas_schema)lookuprN   rT   rU   rX    r\   c/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/_internal/json_schema.pytype_to_schema)   s   	








r^   objr   seenset[int]r   c              	   C  s  | du rddiS z| j }|tttthv ri W S t| |v r i W S | }|t|  |tt	t
tthv r:t| |W S t| trEt| |W S t| |}|rO|W S t| r_t| ts_t| |W S t|rit| |W S tpmt a|jdd D ]"}zt| }W n	 ty   Y quw t|r|| |  W S |  W S t| tttfri W S t| trd|jddW S W n ty   t   Y nw dd	d
S )zCreate a JSON Schema from the given object.

    Args:
        obj: The object to create the JSON Schema from.
        seen: A set of object IDs that have already been processed.

    Returns:
        The JSON Schema.
    Nr)   nullr9   r   r)   titler+   objectunknownr0   )!	__class__strintboolfloatidcopyaddlisttupleset	frozensetr   _array_schema
isinstancer   _mapping_schema_sqlalchemy_schemadataclassesis_dataclassr)   _dataclass_schemar   _attrs_schema_type_to_schemar^   __mro__KeyErrorcallabler   __name__rJ   r   )r_   r`   obj_type	sa_schemabaseschemar\   r\   r]   r!   c   sL   



"


r!   r$   
propertiesri   c                 C  s   t d| dS )Nrf   )r)   r   )r   )r   r\   r\   r]   r#      s   r#   
attributesdict[str, Any]c                 C  s   t dd |  D S )Nc                 S  s&   i | ]\}}|t vr|t|t qS r\   )EXCLUDE_KEYSr!   rr   ).0keyvaluer\   r\   r]   
<dictcomp>   s   & z5attributes_json_schema_properties.<locals>.<dictcomp>)r$   items)r   r\   r\   r]   r"      s   r"   c                 C  s   t | ddd t| D |S )N	dataclassc                 s  s    | ]	}|j r|jV  qd S N)reprname)r   fieldr\   r\   r]   	<genexpr>   s    z$_dataclass_schema.<locals>.<genexpr>)_custom_object_schemarx   fields)r_   r`   r\   r\   r]   rz      s   rz   rA   _seenc                 C  &   ddd}| j jdkr| j j|d< |S )Nr'   rA   r0   re   rh   r   r_   r   r   r\   r\   r]   rB      s   
rB   rC   c                 C  r   )Nr'   rC   r0   re   r   r   r\   r\   r]   rD      s   
rD   r	   c                 C  sh   dd | j D }tdd |D }tdd |D r&dddd	d
|  }nd}|| j jdt||dS )Nc                 S  s   g | ]}|j qS r\   )r   )r   er\   r\   r]   
<listcomp>   s    z _enum_schema.<locals>.<listcomp>c                 s  s    | ]}t |jV  qd S r   )r)   r   )r   r   r\   r\   r]   r      s    z_enum_schema.<locals>.<genexpr>c                 s  s    | ]}|d v V  qdS )>   rj   ri   rk   rl   Nr\   )r   tr\   r\   r]   r      s    r'   integerbooleannumber)ri   rj   rk   rl   rf   r	   )r)   re   r+   enum)rh   rr   allpopr   r   )r_   r`   enum_values
enum_typestype_r\   r\   r]   rE      s   rE   r)   rf   r9   rb   ztuple[JsonDict, ...]PLAIN_SCHEMASc                 C  sV   t tttf | } dditdd |  D |}| jjdkr)d|d< | jj|d< |S )	Nr)   rf   c                 S  s(   i | ]\}}t |tr|nt||qS r\   )ru   ri   r    )r   kvr\   r\   r]   r      s   ( z#_mapping_schema.<locals>.<dictcomp>dictr   r+   re   )r   r   r   _propertiesr   rh   r   )r_   r`   r   r\   r\   r]   rv      s   rv   Dlist[Any] | tuple[Any, ...] | deque[Any] | set[Any] | frozenset[Any]c           	      C  s   ddi}t | tkr| jj|d< t| ttfr)zt| } W n ty(   | Y S w g }t	| dkr3|S d }d}d}| D ]}t
||}|| |d urQ||krQd}|tvrWd}|}q;|rh|rd||d< |S ||d< |S )	Nr)   r9   r+   r   TFr   prefixItems)r)   rp   rh   r   ru   rr   rs   sorted	TypeErrorlenr!   appendr   )	r_   r`   r   prefix_itemsprevious_schemause_items_keyfound_non_empty_schemaitemitem_schemar\   r\   r]   rt      s:   

rt   GeneratorType[Any, Any, Any]c                 C  s   dd| j jdS )Nr9   	generator)r)   r+   re   r   r_   r   r\   r\   r]   rF        rF   rJ   c                 C  s   d| j jddS )Nrf   rJ   rd   r   r   r\   r\   r]   rK     r   rK   c                 C  s   dd l }t| |jsJ | j}t|td rddiS i }ttttf}t||r[d }t|tr3d}d}nt|tr;d}nt|trEd}d}nd	}d
}||d}|j	|vrY|j	j
|d< |S t| j|S )Nr   r)   rb   r'   ri   r   r   rj   r   rl   r0   re   )rN   ru   rR   rootr)   ri   rk   rj   rl   rh   r   r!   )r_   r`   rN   r   r   primitive_typesdatatyper   r\   r\   r]   rS     s0   





rS   c                 C  sd   dd l }t| |jsJ zt| j}| jpi }W n ty&   | j}i }Y nw t| dg |||S )Nr   PydanticModel)	rN   ru   rP   r)   model_fieldsmodel_extraAttributeError
__fields__r   )r_   r`   rN   r   extrar\   r\   r]   rQ   E  s   
rQ   c                 C  s   dd l }t| |jsJ | j\}}|d}t||d }t| jd | t| j| d   }|d}t||d }	t| jd |	 t| j|	 d   }
dd|||
|dS )Nr   zdisplay.max_columns   zdisplay.max_rowsr9   rY   )r)   r+   z	x-columnszx-column-countz	x-indiceszx-row-count)	rX   ru   rY   shape
get_optionminrp   columnsindex)r_   r   rX   	row_countcolumn_countmax_columns
col_middler   max_rows
row_middleindicesr\   r\   r]   rZ   T  s    

&
&rZ   c                 C  s4   dd l }t| |jsJ ddt| j|t| jdS )Nr   r9   rV   )r)   r+   zx-shapezx-dtype)rU   ru   rV   r   r   ri   dtype)r_   r`   rU   r\   r\   r]   rW   m  s   
rW   c                 C  s.   dd l }t|j| } t| ddd | jD |S )Nr   attrsc                 s  s    | ]}|j V  qd S r   )r   r   r   r\   r\   r]   r   ~  s    z _attrs_schema.<locals>.<genexpr>)r   r   AttrsInstancer   __attrs_attrs__)r_   r`   r   r\   r\   r]   r{   z  s   r{   JsonDict | Nonec                   sj   t | sd S ddlm}m} z||  W n |jy   Y d S w  fdd|| j D }t| d||S )Nr   )excinspectc                   s   g | ]	}| j vr|qS r\   )unloadedr   stater\   r]   r     s    z&_sqlalchemy_schema.<locals>.<listcomp>
sqlalchemy)r   r   r   r   NoInspectionAvailabler   keysr   )r_   r`   r   
sa_inspectr   r\   r   r]   rw     s   rw   c                 C  s@   i }|   D ]\}}t|| }tvr|||< q|rd|iS i S )Nr   )r   r!   r   )r   r`   schema_propertiesr   r   value_schemar\   r\   r]   r     s   r   datatype_namer   Iterable[str]c              	   C  s^   i }|D ]}t t t| |||< W d    n1 sw   Y  qd| jj|dt||S )Nrf   rd   )r   rJ   getattrrh   r   r   )r_   r   r   r`   r   r   r\   r\   r]   r     s   
r   )r%   r&   )r_   r   r`   ra   r%   r   )r   r$   r%   ri   )r   r   r%   r$   )r_   rA   r   ra   r%   r   )r_   rC   r   ra   r%   r   )r_   r	   r`   ra   r%   r   )r_   r   r`   ra   r%   r   )r_   r   r   ra   r%   r   )r_   rJ   r   ra   r%   r   )r_   r   r   ra   r%   r   )r_   r   r`   ra   r%   r   )r   r   r`   ra   r%   r   )
r_   r   r   ri   r   r   r`   ra   r%   r   )L__doc__
__future__r   rL   rx   r,   rG   r8   collectionsr   collections.abcr   r   r   r   r(   r   r   r	   	functoolsr
   	ipaddressr   r   r   r   r   r   pathlibr   typesr   typingr   r   r   r   	constantsr   json_encoderr   r   r   
stack_infor   utilsr   r   r   r    __all__r^   r|   r!   r$   r#   r"   r   rz   rB   rD   rE   r   __annotations__rv   rt   rF   rK   rS   rQ   rZ   rW   r{   rw   r   r   r\   r\   r\   r]   <module>   s^     6

<








 


'


&




