a
    /§»a·  ã                	   @   sä   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 eedœdd„Z	e
eed	œd
d„Zeeedœdd„ZG dd„ dejƒZeedœdd„Zd eeedœdd„ZG dd„ de jƒZd!ddœeeeee eedœdd„ZdS )"é    N)ÚAny)ÚDict)ÚIO)ÚOptional)ÚobjÚreturnc              	   C   sJ   z
t | ƒW S  ttfy"   ‚ Y n$ tyD   d t| ƒj| ¡ Y S 0 d S )Nz{}("{}"))ÚreprÚKeyboardInterruptÚ
SystemExitÚBaseExceptionÚformatÚtypeÚ__name__)r   © r   úN/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/_pytest/_io/saferepr.pyÚ_try_repr_or_str	   s    
r   )Úexcr   r   c              
   C   sn   zt | ƒ}W nH ttfy$   ‚ Y n2 tyT }  zd t | ƒ¡}W Y d } ~ n
d } ~ 0 0 d |t|ƒjt|ƒ¡S )Nzunpresentable exception ({})z+<[{} raised in repr()] {} object at 0x{:x}>)r   r	   r
   r   r   r   r   Úid)r   r   Úexc_infor   r   r   Ú_format_repr_exception   s    $ÿr   )ÚsÚmaxsizer   c                 C   sX   t | ƒ|krTtd|d d ƒ}td|d | ƒ}| d |… d | t | ƒ| d …  S | S )Nr   é   é   z...)ÚlenÚmax)r   r   ÚiÚjr   r   r   Ú
_ellipsize   s
    $r   c                       sN   e Zd ZdZeddœ‡ fdd„Zeedœ‡ fdd„Zeeed	œd
d„Z	‡  Z
S )ÚSafeReprzurepr.Repr that limits the resulting size of repr() and includes
    information on exceptions raised during the call.N)r   r   c                    s   t ƒ  ¡  || _|| _d S ©N)ÚsuperÚ__init__Ú	maxstringr   )Úselfr   ©Ú	__class__r   r   r"   *   s    
zSafeRepr.__init__)Úxr   c              
      sb   zt ƒ  |¡}W nD ttfy(   ‚ Y n. tyT } zt||ƒ}W Y d }~n
d }~0 0 t|| jƒS r    )r!   r   r	   r
   r   r   r   r   )r$   r'   r   r   r%   r   r   r   /   s     zSafeRepr.repr)r'   Úlevelr   c              
   C   s^   zt |ƒ}W nD ttfy$   ‚ Y n. tyP } zt||ƒ}W Y d }~n
d }~0 0 t|| jƒS r    )r   r	   r
   r   r   r   r   )r$   r'   r(   r   r   r   r   r   Úrepr_instance8   s     zSafeRepr.repr_instance)r   Ú
__module__Ú__qualname__Ú__doc__Úintr"   ÚobjectÚstrr   r)   Ú__classcell__r   r   r%   r   r   &   s   	r   c              
   C   s@   zt  | ¡W S  ty: } zt|| ƒW  Y d}~S d}~0 0 dS )z Return a pretty printed string for the given object.

    Failing __repr__ functions of user instances will be represented
    with a short exception info.
    N)ÚpprintÚpformatÚ	Exceptionr   )r   r   r   r   r   Ú
safeformatB   s    r4   éð   )r   r   r   c                 C   s   t |ƒ | ¡S )aT  Return a size-limited safe repr-string for the given object.

    Failing __repr__ functions of user instances will be represented
    with a short exception info and 'saferepr' generally takes
    care to never raise exceptions itself.

    This function is a wrapper around the Repr/reprlib functionality of the
    standard 2.6 lib.
    )r   r   )r   r   r   r   r   ÚsafereprN   s    
r6   c                       s>   e Zd ZdZeee eeeee	f eddœ‡ fdd„Z
‡  ZS )ÚAlwaysDispatchingPrettyPrinterz;PrettyPrinter that always dispatches (regardless of width).N)r.   ÚstreamÚindentÚ	allowanceÚcontextr(   r   c           	   	      sp   | j  t|ƒjd ¡}t|ƒ}||v s,|d u rFtƒ  ||||||¡ d S d||< || ||||||d ƒ ||= d S )Né   )Ú	_dispatchÚgetr   Ú__repr__r   r!   Ú_format)	r$   r.   r8   r9   r:   r;   r(   ÚpÚobjidr%   r   r   r@   ^   s    
ÿz&AlwaysDispatchingPrettyPrinter._format)r   r*   r+   r,   r.   r   r/   r-   r   r   r@   r0   r   r   r%   r   r7   [   s   
ør7   r<   éP   F)Úcompact)r.   r9   ÚwidthÚdepthrD   r   c                C   s   t ||||d� | ¡S )N)r9   rE   rF   rD   )r7   r2   )r.   r9   rE   rF   rD   r   r   r   Ú_pformat_dispatchw   s
    ÿþrG   )r5   )r<   rC   N)r1   ÚreprlibÚtypingr   r   r   r   r.   r/   r   r   r   r-   r   ÚReprr   r4   r6   ÚPrettyPrinterr7   ÚboolrG   r   r   r   r   Ú<module>   s2   	   üúù