
    g6                    
   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
 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 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.m/Z/m0Z0 dZ1ed,d       Z2da3d-dZ4 e!de-      Z5d.dZ6d/dZ7e+e%hz  Z8d-dZ9d0dZ:d1dZ;d2dZ<i ddiddifZ=de>d <   d-d!Z?	 	 	 	 	 	 d3d"Z@d4d#ZAd5d$ZBd-d%ZCd6d&ZDd-d'ZEd-d(ZFd7d)ZGd8d*ZHd9d+ZIy):aP  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)suppress)Decimal)Enum)	lru_cache)IPv4AddressIPv4InterfaceIPv4NetworkIPv6AddressIPv6InterfaceIPv6Network)	PosixPath)GeneratorType)AnyCallableIterableMappingNewTypeSequence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JsonSchemaPropertiesc                 ,   i t         t        t        t        t        t
        t        dddt        j                  dddt        j                  dddt        j                  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t0        ddddt2        t4        i} t7        j8                  t:              5  dd l}| j?                  |j@                  ddd|jB                  ddd|jD                  ddd|jF                  ddd|jH                  tJ        i       d d d        t7        j8                  t:              5  dd l&}| j?                  |jN                  dddi       d d d        t7        j8                  t:              5  dd l(}| j?                  |jR                  tT        i       d d d        t7        j8                  t:              5  dd l+}| j?                  |jX                  tZ        i       d d d        | S # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   | S xY w)Nstringdecimal)typeformatz	date-timedatetime	timedeltar)   x-python-datatypeipv4ipv6ipv4interfaceipv6interfaceipv4networkipv6networkregexuuidarrayrangepathr   )r)   r*   r/   r   	NameEmail	SecretStrSecretBytesAnyUrlUrl).bytes_bytes_schema	bytearray_bytearray_schemar   _enum_schemar   datetimer+   r,   r-   r   _generator_schemar	   r   r
   r   r   r   rePatternr7   UUIDr9   r   	Exception_exception_schema
contextlibr   ModuleNotFoundErrorpydanticupdater;   r<   r=   r>   	BaseModel_pydantic_model_schemapydantic_corer?   numpyndarray_numpy_schemapandas	DataFrame_pandas_schema)lookuprN   rR   rS   rV   s        R/var/www/openai/venv/lib/python3.12/site-packages/logfire/_internal/json_schema.pytype_to_schemar[   (   s   O}O$O 	lO 	(i8	O
 	HDO 	F;O 	F;O 	XKPO 	(O 	h&9O 	h&9O 	ODO 	ODO 	h-@O 	h-@O  	

X9!O" 			H7#O$ 	g>H[Y$)OF, 
		0	1""XK$X""XK$X$$xm&\(!R""$:	
 
2 
		0	1}((8RW*XYZ 
2
 
		0	1u}}m45 
2
 
		0	1v''89 
2 M7 
2	1 
2	1
 
2	1
 
2 Ms1   %A"I%(%I1.&I=5&J	%I.1I:=J	Jc                l   | i S 	 | j                   }|t        t        t        t        hv ri S t        |       |v ri S |j                         }|j                  t        |              |t        t        t        t        t        hv rt        | |      S t        | t              rt!        | |      S t#        | |      }|r|S t%        j&                  |       rt        | t(              st+        | |      S t-        |      rt/        | |      S t0        xs
 t3               a|j4                  dd D ]%  }	 t0        |   }t7        |      r || |      c S |c S  t        | t        t        t        f      ri S t        | t:              rd|j<                  ddS 	 dddS # t8        $ r Y vw xY w# t>        $ r tA                Y )w xY w)	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.
    Nr8   r   r)   titler/   objectunknownr.   )!	__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__callableKeyErrorr   __name__rJ   r    )objseenobj_type	sa_schemabaseschemas         rZ   r"   r"   a   s    {	)==S$..Ic7d?Iyy{CeS)U;; d++W%"3--&sD1	%%c*:c43H$S$//h d++ *=^-=$$Sb)DI(. -5V,<vc4(H&H * cCe,-IX&#h.?.?V`aa '
 9==    sp   %F F AF F *F :0F +F $F '	F0F F 
F (F 	FF FF F32F3r%   c                    t        d| d      S )Nr`   )r)   
properties)r   )r   s    rZ   r$   r$      s    hjABB    c                    t        | j                         D ci c]#  \  }}|t        vs|t        |t	                     % c}}      S c c}}w N)r%   itemsEXCLUDE_KEYSr"   rl   )
attributeskeyvalues      rZ   r#   r#      sK    AKAQAQASoAS:3WZbnWn .	.ASo os
   A	
A	
c                R    t        | dd t        j                  |       D        |      S )N	dataclassc              3  N   K   | ]  }|j                   s|j                    y wr   )reprname).0fields     rZ   	<genexpr>z$_dataclass_schema.<locals>.<genexpr>   s     Y3J%ejj5::3Js   %%)_custom_object_schemarr   fields)r{   r|   s     rZ   rt   rt      s,     ![Y;3E3Ec3JY[_ r   c                t    ddd}| j                   j                  dk7  r| j                   j                  |d<   |S )Nr'   r@   r.   r_   rb   rz   r{   _seenr   s      rZ   rA   rA      s6     (wGF
}}(--00wMr   c                t    ddd}| j                   j                  dk7  r| j                   j                  |d<   |S )Nr'   rB   r.   r_   r   r   s      rZ   rC   rC      s6     ({KF
}},--00wMr   c                   | j                   D cg c]  }|j                   }}t        d |D              }t        d |D              rddddd|j	                            }nd}|| j                   j
                  d	t        ||      d
S c c}w )Nc              3  F   K   | ]  }t        |      j                    y wr   )r)   rz   )r   r   s     rZ   r   z_enum_schema.<locals>.<genexpr>   s     C{eT%[)){s   !c              3  $   K   | ]  }|d v  
 yw)>   rd   rc   re   rf   N )r   ts     rZ   r   z_enum_schema.<locals>.<genexpr>   s     
DA1//s   r'   integerbooleannumber)rc   rd   re   rf   r`   r   )r)   r_   r/   enum)rb   r   rl   allpoprz   r   )r{   r|   eenum_values
enum_typestype_s         rZ   rD   rD      s    $'MM2Mq177MK2C{CCJ

D
DD IPXYZdZhZhZjk ''#k40	  3s   Br)   r`   r8   ztuple[JsonDict, ...]PLAIN_SCHEMASc                T   t        t        t        t        f   |       } ddit        | j	                         D ci c]#  \  }}t        |t              r|n
t        |      |% c}}|      }| j                  j                  dk7  rd|d<   | j                  j                  |d<   |S c c}}w )Nr)   r`   dictr   r/   r_   )
r   r   r   _propertiesr   ro   rc   r!   rb   rz   )r{   r|   kvr   s        rZ   rp   rp      s    
wsCx #
&C
RUR[R[R]^R]$!QZ3/Yq\AER]^`d
eF }}'&/"#--00wM _s   (B$c                   ddi}t        |       t        k7  r| j                  j                  |d<   t	        | t
        t        f      r	 t        |       } g }t        |       dk(  r|S d }d}d}| D ]4  }t        ||      }|j                  |       |||k7  rd}|t        vrd}|}6 |r|r||d<   |S ||d<   |S # t        $ r |cY S w xY w)	Nr)   r8   r/   r   TFr   prefixItems)r)   rj   rb   rz   ro   rl   rm   sorted	TypeErrorlenr"   appendr   )	r{   r|   r   prefix_itemsprevious_schemause_items_keyfound_non_empty_schemaitemitem_schemas	            rZ   rn   rn      s     %g.FCyD&)mm&<&<"##Y'(	+C !L
3x1}-1OM"(t4K(&;/+I!Mm+%)"%  -F7O M %1F=!M5  	M	s   B5 5CCc                6    dd| j                   j                  dS )Nr8   	generator)r)   r/   r_   r   r{   r   s     rZ   rF   rF     s    +H^H^__r   c                6    d| j                   j                  ddS )Nr`   rJ   r^   r   r   s     rZ   rK   rK     s    s}}'='=T_``r   c                    dd l }t        | |j                        sJ 	 t        |       j                  }| j
                  xs i }t        | dg |||      S # t        $ r | j                  }i }Y +w xY w)Nr   PydanticModel)	rN   ro   rP   r)   model_fieldsmodel_extraAttributeError
__fields__r   )r{   r|   rN   r   extras        rZ   rQ   rQ     sz    c8--...c''%2
 !o7H7H%7H$OO	  s   %A A/.A/c                   dd l }t        | |j                        sJ | j                  \  }}|j	                  d      }t        ||      dz  }t        | j                  d |       t        | j                  | d        z   }|j	                  d      }t        ||      dz  }	t        | j                  d |	       t        | j                  |	 d        z   }
dd|||
|dS )Nr   zdisplay.max_columns   zdisplay.max_rowsr8   rW   )r)   r/   z	x-columnszx-column-countz	x-indiceszx-row-count)	rV   ro   rW   shape
get_optionminrj   columnsindex)r{   r   rV   	row_countcolumn_countmax_columns
col_middler   max_rows
row_middleindicess              rZ   rX   rX   *  s    c6++,,,!iiI|##$9:K[,/14J3;;{
+,tCKK4M/NNG  !34HXy)Q.J399[j)*T#))ZKL2I-JJG (&  r   c                    dd l }t        | |j                        sJ ddt        | j                  |      t        | j                        dS )Nr   r8   rT   )r)   r/   zx-shapezx-dtype)rS   ro   rT   r   r   rc   dtype)r{   r|   rS   s      rZ   rU   rU   C  sD    c5==))) & D1syy>	 r   c                t    dd l }t        |j                  |       } t        | dd | j                  D        |      S )Nr   attrsc              3  4   K   | ]  }|j                     y wr   )r   )r   r   s     rZ   r   z _attrs_schema.<locals>.<genexpr>T  s     /XDWSDWs   )r   r   AttrsInstancer   __attrs_attrs__)r{   r|   r   s      rZ   ru   ru   P  s5    
u""C
(C g/XCDWDW/XZ^__r   c                   t        |       sy ddlm}m} 	  ||       } ||       j
                  j                         D cg c]  }||j                  vs| }}t        | d||      S # |j                  $ r Y y w xY wc c}w )Nr   )excinspect
sqlalchemy)	r   r   r   r   NoInspectionAvailabler   keysunloadedr   )r{   r|   r   
sa_inspectstater   r   s          rZ   rq   rq   W  s    53 &c?00557U7C3enn;TC7DU lD$?? $$ Us   A(  A=A=(A:9A:c                z    i }| j                         D ]  \  }}t        ||      x}t        vs|||<   ! |rd|iS i S )Nr   )r   r"   r   )r   r|   schema_propertiesr   r   value_schemas         rZ   r   r   e  sT    "$ &&(
U.ud;;LMQ%1c" ) /00	r   c                    i }|D ])  }t        t              5  t        | |      ||<   d d d        + d| j                  j                  |dt        ||      S # 1 sw Y   [xY w)Nr`   r^   )r   rJ   getattrrb   rz   r   )r{   datatype_namer   r|   r   r   s         rZ   r   r   q  sj    !#Ji %c3/JsO !   ''* j$
'	  ! s   AA 	)returnz?dict[type[Any], JsonDict | Callable[[Any, set[int]], JsonDict]])r{   r   r|   set[int]r   r   )r   r%   r   rc   )r   dict[str, Any]r   r%   )r{   r@   r   r   r   r   )r{   rB   r   r   r   r   )r{   r   r|   r   r   r   )r{   zDlist[Any] | tuple[Any, ...] | deque[Any] | set[Any] | frozenset[Any]r|   r   r   r   )r{   zGeneratorType[Any, Any, Any]r   r   r   r   )r{   rJ   r   r   r   r   )r{   r   r   r   r   r   )r{   r   r|   r   r   zJsonDict | None)r   r   r|   r   r   r   )
r{   r   r   rc   r   zIterable[str]r|   r   r   r   )J__doc__
__future__r   rL   rr   rE   rG   r7   collectionsr   r   r(   r   r   r   	functoolsr   	ipaddressr	   r
   r   r   r   r   pathlibr   typesr   typingr   r   r   r   r   r   r   	constantsr   json_encoderr   r   r   
stack_infor   utilsr   r   r    r!   __all__r[   rv   r"   r%   r$   r#   r   rt   rA   rC   rD   r   __annotations__rp   rn   rF   rK   rQ   rX   rU   ru   rq   r   r   r   r   rZ   <module>r      s-   #    	       f f   L L L . @ @ ' E E
u 2 2j 8>v 5x@ 
C
 "9!::$ (*FH+=?P&Q# Q	$	M$U]$$N`aP2
`@	
r   