o
    Ú­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rje	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„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„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.
    ÚreturnÚstrc                 C  s   t | ƒS ©N)r   ©Úself© r   úU/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pydantic/_internal/_repr.pyÚ__repr__   s   zPlainRepr.__repr__N©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   c                   @  s`   e Zd ZdZddd„Zddd„Zd dd„Zd!dd„Zd"dd„Zd#dd„Z	ddd„Z
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   s   € 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   s   2 z0Representation.__repr_args__.<locals>.<listcomp>)r
   r   r   Ú	__slots__Úhasattrr!   Úkeys)r   Ú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__Ú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_strc                 C  s   |  dd„ |  ¡ D ƒ¡S )Nc                 s  s2   � | ]\}}|d u rt |ƒn|› d|›�V  qd S )Nú=)Úreprr'   r   r   r   r%   >   s   €0 z.Representation.__repr_str__.<locals>.<genexpr>)Újoinr0   )r   r7   r   r   r   Ú__repr_str__=   s   zRepresentation.__repr_str__ÚfmtúCallable[[Any], Any]ÚkwargsúGenerator[Any]c                 k  s`   � |   ¡ d V  dV  |  ¡ D ]\}}|dur|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  s2   � |   ¡ 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   rD   Ú
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@   ú, rC   )r2   r;   r   r   r   r   r   X   s   zRepresentation.__repr__N)r   r   r   )r3   r   r   r   )r7   r   r   r   )r<   r=   r>   r   r   r?   )r   r   )r   r   r   r+   r0   r2   r&   r;   rF   rH   rJ   r   r   r   r   r   r       s    






r    Úobjr   r   r   c                 C  sN  t | tjtjfƒr| jS | du rdS t | tƒrt| ƒS t | tƒs%t 	| ¡r)t
| ƒS t | tjtjtfƒs6| j} tt | ¡ƒrNd ttt | ¡ƒ¡}d|› d�S t | tjƒr“t t | ¡¡rhd ttt | ¡ƒ¡}nd ttt | ¡ƒ¡}z
| j› d|› d�W S  ty’   t
| ƒ dd¡ d	d¡ Y S w t | tƒr›| jS t| ƒ dd¡ d	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...rK   zUnion[ú]ú[ztyping.Ú ztyping_extensions.)Ú
isinstanceÚtypesÚFunctionTypeÚBuiltinFunctionTyper   r    r9   r	   r   Úis_typealiastyper   r   Útyping_baseÚWithArgsTypesr5   r1   r   Útyping_extensionsÚ
get_originr:   ÚmapÚdisplay_as_typeÚget_argsÚ
is_literalr   ÚAttributeErrorÚreplace)rL   Úargsr   r   r   rZ   \   s2   
ÿ
rZ   )rL   r   r   r   )r   Ú
__future__r   Ú_annotationsrQ   Úcollections.abcr   r   r   r   Útypingr   r   r	   r
   rW   r   Útyping_inspectionr   Útyping_inspection.introspectionr   rO   r   Útupler   r   Ú__annotations__r   r   r    rZ   r   r   r   r   Ú<module>   s     2	=