a
    “˜ëj4  ã                   @  s  U d Z ddlmZ ddlZddlmZmZmZm	Z	 ddl
mZmZmZm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 erÔe	eedB ef  Zded< e	eee B eeef B eeeef B  Zded< G dd„ deƒZG dd„ dƒZdddœdd„ZdS )z:Tools to provide pretty/human-readable display of objects.é    )ÚannotationsN)ÚCallableÚ
CollectionÚ	GeneratorÚIterable)ÚTYPE_CHECKINGÚAnyÚ
ForwardRefÚcast)Ú	TypeAlias)Útyping_objects)Úis_union_originé   )Ú_typing_extrar   ÚReprArgsÚRichReprResultc                   @  s   e Zd ZdZddœdd„ZdS )Ú	PlainReprz¸String class where repr doesn't include quotes. Useful with Representation when you want to return a string
    representation of something that is valid (or pseudo-valid) python.
    Ústr©Úreturnc                 C  s   t | ƒS ©N)r   ©Úself© r   úW/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pydantic/_internal/_repr.pyÚ__repr__   s    zPlainRepr.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   @  sˆ   e Zd ZdZddœdd„Zddœdd„Zd	dd
œdd„Zdddœdd„Zdd	ddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„ZdS )ÚRepresentationr   r   r   c                   sL   t tt ˆ jƒ}|s(tˆ dƒr(ˆ j ¡ }‡ fdd„|D ƒ}‡ fdd„|D ƒS )a-  Returns the attributes to show in __str__, __repr__, and __pretty__ this is generally overridden.

        Can either return:
        * name - value pairs, e.g.: `[('foo_name', 'foo'), ('bar_name', ['b', 'a', 'r'])]`
        * or, just values, e.g.: `[(None, 'foo'), (None, ['b', 'a', 'r'])]`
        Ú__dict__c                 3  s   | ]}|t ˆ |ƒfV  qd S r   )Úgetattr)Ú.0Úsr   r   r   Ú	<genexpr>1   ó    z/Representation.__repr_args__.<locals>.<genexpr>c                   s2   g | ]*\}}|d ur||ˆ ur"|nˆ   |¡f‘qS r   )Ú__repr_recursion__©r#   ÚaÚvr   r   r   Ú
<listcomp>2   r&   z0Representation.__repr_args__.<locals>.<listcomp>)r
   r   r   Ú	__slots__Úhasattrr!   Úkeys)r   Zattrs_namesÚattrsr   r   r   Ú__repr_args__'   s
    
zRepresentation.__repr_args__r   c                 C  s   | j jS )z/Name of the instance's class, used in __repr__.)Ú	__class__r   r   r   r   r   Ú__repr_name__4   s    zRepresentation.__repr_name__r   )Úobjectr   c                 C  s   dt |ƒj› dt|ƒ› d�S )z8Returns the string representation of a recursive object.z<Recursion on z	 with id=ú>)Útyper   Úid)r   r3   r   r   r   r'   8   s    z!Representation.__repr_recursion__)Újoin_strr   c                 C  s   |  dd„ |  ¡ D ƒ¡S )Nc                 s  s0   | ](\}}|d u rt |ƒn|› d|›�V  qd S )Nú=)Úreprr(   r   r   r   r%   >   r&   z.Representation.__repr_str__.<locals>.<genexpr>)Újoinr0   )r   r7   r   r   r   Ú__repr_str__=   s    zRepresentation.__repr_str__zCallable[[Any], Any]zGenerator[Any])ÚfmtÚkwargsr   c                 k  s^   |   ¡ d V  dV  |  ¡ D ]0\}}|dur6|d V  ||ƒV  dV  dV  qdV  dV  dS )	zRUsed by devtools (https://python-devtools.helpmanual.io/) to pretty print objects.ú(r   Nr8   ú,r   éÿÿÿÿú))r2   r0   )r   r<   r=   ÚnameÚvaluer   r   r   Ú
__pretty__@   s    

zRepresentation.__pretty__r   c                 c  s0   |   ¡ D ]"\}}|du r |V  q||fV  qdS )zYUsed by Rich (https://rich.readthedocs.io/en/stable/pretty.html) to pretty print objects.N)r0   )r   rB   Z
field_reprr   r   r   Ú__rich_repr__M   s    zRepresentation.__rich_repr__c                 C  s
   |   d¡S )Nú )r;   r   r   r   r   Ú__str__U   s    zRepresentation.__str__c                 C  s   |   ¡ › d|  d¡› d�S )Nr>   ú, rA   )r2   r;   r   r   r   r   r   X   s    zRepresentation.__repr__N)r   r   r   r,   r0   r2   r'   r;   rD   rE   rG   r   r   r   r   r   r       s   r    r   r   )Úobjr   c                 C  sZ  t | tjtjfƒr| jS | du r$dS t | tƒr6t| ƒS t | tƒsJt 	| ¡rRt
| ƒS t | tjtjtfƒsl| j} tt | ¡ƒrœd ttt | ¡ƒ¡}d|› d�S t | tjƒ�r,t t | ¡¡rÒd ttt | ¡ƒ¡}nd ttt | ¡ƒ¡}z| j› d|› d�W S  t�y(   t
| ƒ dd¡ d	d¡ Y S 0 n*t | tƒ�r>| jS t| ƒ dd¡ d	d¡S d
S )zœPretty representation of a type, should be as close as possible to the original type definition string.

    Takes some logic from `typing._type_repr`.
    .z...rH   zUnion[ú]ú[ztyping.Ú ztyping_extensions.N)Ú
isinstanceÚtypesÚFunctionTypeÚBuiltinFunctionTyper   r    r9   r	   r   Zis_typealiastyper   r   Ztyping_baseZWithArgsTypesr5   r1   r   Útyping_extensionsÚ
get_originr:   ÚmapÚdisplay_as_typeÚget_argsZ
is_literalr   ÚAttributeErrorÚreplace)rI   Úargsr   r   r   rT   \   s0    
 rT   )r   Ú
__future__r   Z_annotationsrN   Úcollections.abcr   r   r   r   Útypingr   r   r	   r
   rQ   r   Ztyping_inspectionr   Ztyping_inspection.introspectionr   rL   r   Útupler   r   Ú__annotations__r   r   r    rT   r   r   r   r   Ú<module>   s   2	=