U
    /v¶hW$  ã                   @  sê   d Z ddlmZ ddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ eƒ Ze d¡ZeeƒZdZd	Zd
ddœdd„Zefd
ddœdd„ZG dd„ dƒZeƒ Zdd
dddœdd„Zd!ddddddœdd„ZG dd „ d ƒZdS )"zîObject representations for debugging purposes. Unlike the default
repr, these expose more information and produce HTML instead of ASCII.

Together with the CSS and JavaScript of the debugger this gives a
colorful and more compact output.
é    )ÚannotationsN)Údeque)Úformat_exception_only)Úescapez(?:\r\n|\r|\n){2,}zL<div class=box>
  <h3>%(title)s</h3>
  <pre class=help>%(text)s</pre>
</div>zQ<div class=box>
  <h3>%(title)s</h3>
  %(repr)s
  <table>%(items)s</table>
</div>ÚobjectÚstr©ÚobjÚreturnc                 C  s   t ƒ  | ¡S )z1Creates a debug repr of an object as HTML string.)ÚDebugReprGeneratorÚrepr)r	   © r   ú7/tmp/pip-unpacked-wheel-c3xdgso7/werkzeug/debug/repr.pyÚ
debug_repr&   s    r   ÚNonec                 C  s<   t ƒ }| tkr"| t d¡j¡}n
| | ¡}tj |¡ dS )zdPrint the object details to stdout._write (for the interactive
    console of the web debugger.
    é   N)	r   ÚmissingÚdump_localsÚsysÚ	_getframeÚf_localsÚdump_objectÚstdoutÚ_write)r	   ÚgenÚrvr   r   r   Údump+   s
    
r   c                   @  s0   e Zd ZdZddœdd„Zdddd	œd
d„ZdS )Ú_Helperz�Displays an HTML version of the normal help, for the interactive
    debugger only because it requires a patched sys.stdout.
    r   ©r
   c                 C  s   dS )Nz(Type help(object) for help about object.r   ©Úselfr   r   r   Ú__repr__<   s    z_Helper.__repr__Nzt.Any | Noner   )Útopicr
   c                 C  s”   |d kr t j d| ›d�¡ d S dd l}| |¡ t j ¡ }t |¡}t|ƒdkrn|d }d 	|dd … ¡}nd}|d }t j t
||dœ ¡ d S )Nz<span class=help>ú</span>r   r   z

ZHelp)ÚtitleÚtext)r   r   r   ÚpydocÚhelpÚresetÚ_paragraph_reÚsplitÚlenÚjoinÚ	HELP_HTML)r    r"   r&   r   Z
paragraphsr$   r%   r   r   r   Ú__call__?   s    


z_Helper.__call__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r.   r   r   r   r   r   7   s   r   ztype | tuple[type, ...])Úinnerr	   Úbaser
   c                 C  st   t |tƒr*|D ]}t|ƒ|kr|   S qnt|ƒ|kr:| S d}|jjdkrZd|jj› d�}|› t|ƒj› d| › d�S )NÚ )Ú__builtin__Ú
exceptionsz<span class="module">z.</span>ú(ú))Ú
isinstanceÚtupleÚtypeÚ	__class__r0   r/   )r3   r	   r4   ÚclsÚmoduler   r   r   Ú_add_subclass_infoT   s    
r@   é   r<   Úintz>t.Callable[[DebugReprGenerator, t.Iterable[t.Any], bool], str])ÚleftÚrightr4   Úlimitr
   c                   s"   dddddœ‡ ‡‡‡fdd„}|S )Nr   zt.Iterable[t.Any]Úboolr   )r    r	   Ú	recursiver
   c                   s”   |rt ˆ› dˆ› �|ˆ ƒS ˆg}d}t|ƒD ]<\}}|rB| d¡ |ˆkrX| d¡ d}| |  |¡¡ q,|rx| d¡ | ˆ¡ t d |¡|ˆ ƒS )Nz...Fú, ú<span class="extended">Tr#   r5   )r@   Ú	enumerateÚappendr   r,   )r    r	   rG   ÚbufÚhave_extended_sectionÚidxÚitem©r4   rC   rE   rD   r   r   Úproxyd   s    



z#_sequence_repr_maker.<locals>.proxyr   )rC   rD   r4   rE   rQ   r   rP   r   Ú_sequence_repr_makera   s    rR   c                   @  s  e Zd Zddœdd„ZeddeƒZeddeƒZed	d
e	ƒZ
edd
eƒZedd
eƒZdddœdd„Zd5ddddœdd„Zd6dd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'd(„Zd&ddœd)d*„Zd+dd,œd-d.„Zd7d0dd1dd2œd3d4„Zd/S )8r   r   r   c                 C  s
   g | _ d S )N)Ú_stackr   r   r   r   Ú__init__y   s    zDebugReprGenerator.__init__ú[ú]r8   r9   zset([z])zfrozenset([z/<span class="module">collections.</span>deque([zt.Pattern[t.AnyStr]r   r   c                 C  s.   t |jƒ}t |dd¡}d|› �}d|› d�S )Nzunicode-escapeÚignoreÚrz&re.compile(<span class="string regex">z</span>))r   ÚpatternÚcodecsÚdecode)r    r	   rY   r   r   r   Ú
regex_repr„   s    

zDebugReprGenerator.regex_repréF   zstr | bytesrB   )r	   rE   r
   c                 C  s¤   dg}t |ƒ}t|ƒ| dkrJ| t|d |… ƒdt||d … ƒdf¡ n| t|ƒ¡ | d¡ d |¡}|d dks�|d dkr |d	 dkr t||ttfƒS |S )
Nz<span class="string">é   rI   r#   r5   r   z'"Úbr   )	r   r+   Úextendr   rK   r,   r@   Úbytesr   )r    r	   rE   rL   rX   Úoutr   r   r   Ústring_reprŠ   s     üÿ	

$zDebugReprGenerator.string_repré   z7dict[int, None] | dict[str, int] | dict[str | int, int]rF   )ÚdrG   rE   r
   c           	   	   C  sª   |rt d|tƒS dg}d}t| ¡ ƒD ]X\}\}}|r@| d¡ ||d krZ| d¡ d}| d|  |¡› d	|  |¡› d
�¡ q&|rŽ| d¡ | d¡ t d |¡|tƒS )Nz{...}Ú{FrH   r   rI   Tz%<span class="pair"><span class="key">z</span>: <span class="value">z</span></span>r#   Ú}r5   )r@   ÚdictrJ   ÚitemsrK   r   r,   )	r    re   rG   rE   rL   rM   rN   ÚkeyÚvaluer   r   r   Ú	dict_repr¥   s"    

ÿ

zDebugReprGenerator.dict_reprzt.Anyc                 C  s   t |ƒ}dt|ƒ› d�S )Nz<span class="object">r#   )r   r   )r    r	   rX   r   r   r   Úobject_repr¾   s    zDebugReprGenerator.object_repr)r	   rG   r
   c                 C  sð   |t krdt ›d�S t|tttfƒr0d|›d�S t|tƒsDt|tƒrN|  |¡S t|tƒrb|  	|¡S t|t
ƒrx|  ||¡S t|tƒrŽ|  ||¡S t|tƒr¤|  ||¡S t|tƒrº|  ||¡S t|tƒrÐ|  ||¡S t|tƒræ|  ||¡S |  |¡S )Nz<span class="help">r#   z<span class="number">)Úhelperr:   rB   ÚfloatÚcomplexr   ra   rc   Ú	RegexTyper\   ÚlistÚ	list_reprr;   Ú
tuple_reprÚsetÚset_reprÚ	frozensetÚfrozenset_reprrh   rl   r   Ú
deque_reprrm   )r    r	   rG   r   r   r   Údispatch_reprÂ   s*    








z DebugReprGenerator.dispatch_reprc                 C  sL   zd  tt ¡ d d… Ž ¡}W n tk
r6   d}Y nX dt| ¡ ƒ› d�S )Nr5   r^   ú?z*<span class="brokenrepr">&lt;broken repr (z)&gt;</span>)r,   r   r   Úexc_infoÚ	Exceptionr   Ústrip)r    Úinfor   r   r   Úfallback_reprÙ   s    
ÿz DebugReprGenerator.fallback_reprr   c                 C  sv   d}| j D ]}||kr
d} q q
| j  |¡ z8z|  ||¡W W ¢&S  tk
r`   |  ¡  Y W ¢S X W 5 | j  ¡  X d S )NFT)rS   rK   Úpoprz   r}   r€   )r    r	   rG   rO   r   r   r   r   ã   s    
zDebugReprGenerator.reprc              	   C  sØ   d }d }t |tƒrRd}g }| ¡ D ].\}}t |tƒs<d } qR| ||  |¡f¡ q"|d kr®g }|  |¡}t|ƒD ]8}z| ||  t||ƒ¡f¡ W qp tk
r¦   Y qpX qpd}|dt	 
|¡dd… › �7 }|  |||¡S )NzContents ofzDetails forú r   éÿÿÿÿ)r:   rh   ri   r   rK   r   ÚdirÚgetattrr}   r   r!   Úrender_object_dump)r    r	   r   ri   r$   rj   rk   r   r   r   r   ò   s*    


zDebugReprGenerator.dump_objectzdict[str, t.Any])re   r
   c                   s"   ‡ fdd„|  ¡ D ƒ}ˆ  |d¡S )Nc                   s   g | ]\}}|ˆ   |¡f‘qS r   )r   )Ú.0rj   rk   r   r   r   Ú
<listcomp>  s     z2DebugReprGenerator.dump_locals.<locals>.<listcomp>zLocal variables in frame)ri   r†   )r    re   ri   r   r   r   r   
  s    zDebugReprGenerator.dump_localsNzlist[tuple[str, str]]z
str | None)ri   r$   r   r
   c                 C  sf   g }|D ]$\}}|  dt|ƒ› d|› d�¡ q|s<|  d¡ tt|ƒd|rN|nd› d�d |¡dœ S )	Nz<tr><th>z<td><pre class=repr>z</pre>z<tr><td><em>Nothing</em>z<pre class=repr>r5   Ú
)r$   r   ri   )rK   r   ÚOBJECT_DUMP_HTMLr,   )r    ri   r$   r   Z
html_itemsrj   rk   r   r   r   r†     s    
ýz%DebugReprGenerator.render_object_dump)r]   )rd   )N)r/   r0   r1   rT   rR   rr   rs   r;   rt   ru   rv   rw   rx   r   ry   r\   rc   rl   rm   rz   r€   r   r   r   r†   r   r   r   r   r   x   s,     ÿ ü
 ÿr   )rA   )r2   Ú
__future__r   rZ   Úrer   ÚtypingÚtÚcollectionsr   Ú	tracebackr   Z
markupsafer   r   r   Úcompiler)   r<   rq   r-   rŠ   r   r   r   rn   r@   rR   r   r   r   r   r   Ú<module>   s*   
	 ÿ