U
    EZh`                     @  s   U d Z ddlmZ ddlZddlZddlmZ ddlZddlm	Z	 ej
r`dZded	< d
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)Any   )_typing_extraz'typing.Iterable[tuple[str | None, Any]]ztyping_extensions.TypeAliasReprArgszJtyping.Iterable[Any | tuple[Any] | tuple[str, Any] | tuple[str, Any, Any]]RichReprResultc                   @  s   e Zd ZdZddddZdS )	PlainReprzString 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   _/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/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                   sB    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>0   s     z/Representation.__repr_args__.<locals>.<genexpr>c                   s2   g | ]*\}}|d k	r|| k	r"|n  |fqS r   )__repr_recursion__r   avr   r   r   
<listcomp>1   s      z0Representation.__repr_args__.<locals>.<listcomp>)	__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__3   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   r(   r   r   r   r   7   s    z!Representation.__repr_recursion__)join_strr   c                 C  s   | dd |  D S )Nc                 s  s0   | ](\}}|d krt |n| d|V  qd S )N=)reprr   r   r   r   r   =   s     z.Representation.__repr_str__.<locals>.<genexpr>)joinr%   )r   r,   r   r   r   __repr_str__<   s    zRepresentation.__repr_str__ztyping.Callable[[Any], Any]z!typing.Generator[Any, None, None])fmtkwargsr   c                 k  s^   |   d V  dV  |  D ]0\}}|dk	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   Nr-   ,r   ))r'   r%   )r   r1   r2   namevaluer   r   r   
__pretty__?   s    

zRepresentation.__pretty__r   c                 c  s0   |   D ]"\}}|dkr |V  q||fV  qdS )zYUsed by Rich (https://rich.readthedocs.io/en/stable/pretty.html) to pretty print objects.N)r%   )r   r7   Z
field_reprr   r   r   __rich_repr__L   s    zRepresentation.__rich_repr__c                 C  s
   |  dS )N )r0   r   r   r   r   __str__T   s    zRepresentation.__str__c                 C  s   |    d| d dS )Nr3   , r6   )r'   r0   r   r   r   r   r   W   s    zRepresentation.__repr__N)r   r   r   r!   r%   r'   r   r0   r9   r:   r<   r   r   r   r   r   r      s   r   r   r	   )objr   c                 C  sZ  t | tjtjfr| jS | dkr$dS t | tr6t| S t | tjsLt	
| rTt| S t | t	jt	jtfsn| j} t	t| rdttt| }d| dS t | t	jr,t	| rdttt| }ndttt| }z| j d| dW S  tk
r(   t| ddd	d Y S X n*t | tr>| jS t| ddd	dS d
S )zPretty representation of a type, should be as close as possible to the original type definition string.

    Takes some logic from `typing._type_repr`.
    .z...r=   zUnion[][ztyping. ztyping_extensions.N)
isinstancetypesFunctionTypeBuiltinFunctionTyper   r   r.   typing
ForwardRefr   Zis_type_alias_typer	   Ztyping_baseZWithArgsTypesr*   r&   Zorigin_is_uniontyping_extensions
get_originr/   mapdisplay_as_typeget_argsZ
is_literalr   AttributeErrorreplace)r>   argsr   r   r   rK   [   s0    

 rK   )r   
__future__r   Z_annotationsrC   rF   r   rH   rA   r   TYPE_CHECKINGr   __annotations__r   r	   r   r   rK   r   r   r   r   <module>   s   
	>