o
    ßý°jW$  ã                   @  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„Zefd&dd„ZG dd„ dƒZeƒ Zd'dd„Z	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>ÚobjÚobjectÚreturnÚstrc                 C  s   t ƒ  | ¡S )z1Creates a debug repr of an object as HTML string.)ÚDebugReprGeneratorÚrepr)r   © r   ú†/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/werkzeug/debug/repr.pyÚ
debug_repr&   s   r   ÚNonec                 C  s<   t ƒ }| tu 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                   @  s&   e Zd ZdZddd„Z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__NÚtopicút.Any | Noner   c                 C  s”   |d u rt j d| ›d�¡ d S dd l}| |¡ t j ¡ }t |¡}t|ƒdkr7|d }d 	|dd … ¡}nd}|d }t j t
||dœ ¡ d S )Nz<span class=help>ú</span>r   r   z

ÚHelp)ÚtitleÚtext)r   r   r   ÚpydocÚhelpÚresetÚ_paragraph_reÚsplitÚlenÚjoinÚ	HELP_HTML)r   r    r&   r   Ú
paragraphsr$   r%   r   r   r   Ú__call__?   s   


z_Helper.__call__©r   r	   ©N)r    r!   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r/   r   r   r   r   r   7   s    
r   ÚinnerÚbaseútype | tuple[type, ...]c                 C  st   t |tƒr|D ]}t|ƒ|u r|   S qnt|ƒ|u r| S d}|jjdvr-d|jj› d�}|› t|ƒj› d| › d�S )NÚ )Ú__builtin__Ú
exceptionsz<span class="module">z.</span>ú(ú))Ú
isinstanceÚtupleÚtypeÚ	__class__r3   r2   )r6   r   r7   ÚclsÚmoduler   r   r   Ú_add_subclass_infoT   s   
ÿÿrD   é   ÚleftÚrightr@   ÚlimitÚintú>t.Callable[[DebugReprGenerator, t.Iterable[t.Any], bool], str]c                   s   d‡ ‡‡‡fd	d
„}|S )Nr   r
   r   út.Iterable[t.Any]Ú	recursiveÚboolr   r	   c                   s”   |rt ˆ› dˆ› �|ˆ ƒS ˆg}d}t|ƒD ]\}}|r!| d¡ |ˆkr,| d¡ d}| |  |¡¡ q|r<| d¡ | ˆ¡ t d |¡|ˆ ƒS )Nz...Fú, ú<span class="extended">Tr"   r9   )rD   Ú	enumerateÚappendr   r,   )r   r   rL   ÚbufÚhave_extended_sectionÚidxÚitem©r7   rF   rH   rG   r   r   Úproxyd   s   



z#_sequence_repr_maker.<locals>.proxy)r   r
   r   rK   rL   rM   r   r	   r   )rF   rG   r7   rH   rW   r   rV   r   Ú_sequence_repr_makera   s   rX   c                   @  sÀ   e Zd Zd6d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d7dd„Zd8d9dd„Z	d: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	.dAdBd4d5„Zd.S )Cr
   r   r   c                 C  s
   g | _ d S r1   )Ú_stackr   r   r   r   Ú__init__y   s   
zDebugReprGenerator.__init__ú[ú]r<   r=   zset([z])zfrozenset([z/<span class="module">collections.</span>deque([r   út.Pattern[t.AnyStr]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   r`   r   r   r   Ú
regex_repr„   s   

zDebugReprGenerator.regex_repréF   ústr | bytesrH   rI   c                 C  s¤   dg}t |ƒ}t|ƒ| dkr%| t|d |… ƒdt||d … ƒdf¡ n| t|ƒ¡ | d¡ d |¡}|d dv sH|d dkrP|d	 dv rPt||ttfƒS |S )
Nz<span class="string">é   rO   r"   r9   r   z'"Úbr   )	r   r+   Úextendr   rQ   r,   rD   Úbytesr	   )r   r   rH   rR   r_   Úoutr   r   r   Ústring_reprŠ   s    üÿ	

$zDebugReprGenerator.string_repré   Údú7dict[int, None] | dict[str, int] | dict[str | int, int]rL   rM   c           	   	   C  sª   |rt d|tƒS dg}d}t| ¡ ƒD ],\}\}}|r | d¡ ||d kr-| d¡ d}| d|  |¡› d	|  |¡› d
�¡ q|rG| d¡ | d¡ t d |¡|tƒS )Nz{...}Ú{FrN   r   rO   Tz%<span class="pair"><span class="key">z</span>: <span class="value">z</span></span>r"   Ú}r9   )rD   ÚdictrP   ÚitemsrQ   r   r,   )	r   rm   rL   rH   rR   rS   rT   ÚkeyÚvaluer   r   r   Ú	dict_repr¥   s&   

ÿÿ

zDebugReprGenerator.dict_reprút.Anyc                 C  s   t |ƒ}dt|ƒ› d�S )Nz<span class="object">r"   )r   r   )r   r   r_   r   r   r   Úobject_repr¾   s   zDebugReprGenerator.object_reprc                 C  sð   |t u r
dt ›d�S t|tttfƒrd|›d�S t|tƒs"t|tƒr'|  |¡S t|tƒr1|  	|¡S t|t
ƒr<|  ||¡S t|tƒrG|  ||¡S t|tƒrR|  ||¡S t|tƒr]|  ||¡S t|tƒrh|  ||¡S t|tƒrs|  ||¡S |  |¡S )Nz<span class="help">r"   z<span class="number">)Úhelperr>   rI   ÚfloatÚcomplexr	   ri   rk   Ú	RegexTyperc   ÚlistÚ	list_reprr?   Ú
tuple_reprÚsetÚset_reprÚ	frozensetÚfrozenset_reprrq   ru   r   Ú
deque_reprrw   )r   r   rL   r   r   r   Údispatch_reprÂ   s*   









z DebugReprGenerator.dispatch_reprc                 C  sJ   zd  tt ¡ d d… Ž ¡}W n ty   d}Y nw dt| ¡ ƒ› d�S )Nr9   rf   ú?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  s|   d}| j D ]
}||u rd} nq| j  |¡ z!z|  ||¡W W | j  ¡  S  ty7   |  ¡  Y W | j  ¡  S w | j  ¡  w )NFT)rY   rQ   r„   Úpopr‡   rŠ   )r   r   rL   rU   r   r   r   r   ã   s    
þýýzDebugReprGenerator.reprc              	   C  sÔ   d }d }t |tƒr)d}g }| ¡ D ]\}}t |tƒsd } n| ||  |¡f¡ q|d u rUg }|  |¡}t|ƒD ]}z| ||  t||ƒ¡f¡ W q8 tyR   Y q8w d}|dt	 
|¡dd… › �7 }|  |||¡S )NzContents ofzDetails forú r   éÿÿÿÿ)r>   rq   rr   r	   rQ   r   ÚdirÚgetattrr‡   r   r   Úrender_object_dump)r   r   r   rr   r$   rs   rt   r   r   r   r   ò   s,   


ÿzDebugReprGenerator.dump_objectúdict[str, t.Any]c                   s"   ‡ fdd„|  ¡ D ƒ}ˆ  |d¡S )Nc                   s   g | ]\}}|ˆ   |¡f‘qS r   )r   )Ú.0rs   rt   r   r   r   Ú
<listcomp>  s    z2DebugReprGenerator.dump_locals.<locals>.<listcomp>zLocal variables in frame)rr   r�   )r   rm   rr   r   r   r   r   
  s   zDebugReprGenerator.dump_localsNrr   úlist[tuple[str, str]]r$   r   ú
str | Nonec                 C  sf   g }|D ]\}}|  dt|ƒ› d|› d�¡ q|s|  d¡ tt|ƒd|r'|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>r9   Ú
)r$   r   rr   )rQ   r   ÚOBJECT_DUMP_HTMLr,   )r   rr   r$   r   Ú
html_itemsrs   rt   r   r   r   r�     s   
ýz%DebugReprGenerator.render_object_dump)r   r   )r   r]   r   r	   )rd   )r   re   rH   rI   r   r	   )rl   )rm   rn   rL   rM   rH   rI   r   r	   )r   rv   r   r	   )r   rv   rL   rM   r   r	   r0   ©r   r   r   r	   )rm   r‘   r   r	   r1   )rr   r”   r$   r	   r   r•   r   r	   )r2   r3   r4   rZ   rX   r|   r}   r?   r~   r   r€   r�   r‚   r   rƒ   rc   rk   ru   rw   r„   rŠ   r   r   r   r�   r   r   r   r   r
   x   s*    
ÿ
ü






ÿr
   r™   )r   r   r   r   )r6   r	   r   r   r7   r8   r   r	   )rE   )
rF   r	   rG   r	   r7   r@   rH   rI   r   rJ   )r5   Ú
__future__r   ra   Úrer   ÚtypingÚtÚcollectionsr   Ú	tracebackr   Ú
markupsafer   r   r   Úcompiler)   r@   r{   r-   r—   r   r   r   rx   rD   rX   r
   r   r   r   r   Ú<module>   s,    

	
ÿ