a
    /§»a³	  ã                   @   sB   d dl Z d dlZeZe j dd¡ZG dd„ dejƒZd	dd„Z	dS )
é    NÚreprÚreprlibc                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚSafeReprz‹ subclass of repr.Repr that limits the resulting size of repr()
        and includes information on exceptions raised during the call.
    c                 C   s   |   tjj| |¡S ©N)Ú_callhelperr   ÚReprr   )ÚselfÚx© r
   úI/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/py/_io/saferepr.pyr      s    zSafeRepr.reprc                 C   sœ   dd„ }||d | j … ƒ}t|ƒ| j kr˜td| j d d ƒ}td| j d | ƒ}||d |… |t|ƒ| d …  ƒ}|d |… d |t|ƒ| d …  }|S )Nc                 S   sL   d| vrt j d¡|  S d| vr0t j d¡|  S t j d¡|  dd¡ S d S )Nú'z'%s'ú"z"%s"z\')ÚpyÚbuiltinZ_totextÚreplace)Úur
   r
   r   r      s
    z#SafeRepr.repr_unicode.<locals>.reprr   é   é   ú...)Ú	maxstringÚlenÚmax)r   r	   Úlevelr   ÚsÚiÚjr
   r
   r   Úrepr_unicode   s    $$zSafeRepr.repr_unicodec                 C   s   |   t|¡S r   )r   Úbuiltin_repr)r   r	   r   r
   r
   r   Úrepr_instance    s    zSafeRepr.repr_instancec                 G   s   z||g|¢R Ž }W nˆ t jjy,   ‚ Y nÐ   t ¡ \}}}t|ddƒ}zt|ƒ}	W n& t jjyp   ‚ Y n   d}	Y n0 d||	|jjt	|ƒf  Y S 0 t
|ƒ| jkrøtd| jd d ƒ}
td| jd |
 ƒ}|d |
… d |t
|ƒ| d …  }|S d S )NÚ__name__Úunknownz/<[%s("%s") raised in repr()] %s object at 0x%x>r   r   r   r   )r   r   Z_sysexÚsysÚexc_infoÚgetattrÚstrÚ	__class__r   Úidr   Úmaxsizer   )r   Úcallr	   Úargsr   ÚclsÚeÚtbZexc_namer"   r   r   r
   r
   r   r   #   s*    
ÿ$zSafeRepr._callhelperN)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r
   r
   r
   r   r      s
   r   éð   c                 C   s"   t ƒ }||_||_d|_| | ¡S )aP   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'   Úmaxotherr   )Úobjr'   Zsreprr
   r
   r   Úsaferepr;   s
    r4   )r0   )
r   r!   r   r   r   Z
_tryimportr   r   r   r4   r
   r
   r
   r   Ú<module>   s
   3