o
    i%                     @   s   d 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	 ddlm
Z
 ddlm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 ZefddZG dd deZe Zdd ZG dd deZdS )a  
    werkzeug.debug.repr
    ~~~~~~~~~~~~~~~~~~~

    This module implements object representations for debugging purposes.
    Unlike the default repr these reprs expose a lot more information and
    produce HTML instead of ASCII.

    Together with the CSS and JavaScript files of the debugger this gives
    a colorful and more compact output.

    :copyright: 2007 Pallets
    :license: BSD-3-Clause
    N)deque)format_exception_only   )integer_types)	iteritems)PY2)string_types)	text_type)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>c                 C   s   t  | S )z9Creates a debug repr of an object as HTML unicode string.)DebugReprGeneratorrepr)obj r   N/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/werkzeug/debug/repr.py
debug_repr2   s   r   c                 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   dump7   s
   
r   c                   @   s"   e Zd ZdZdd ZdddZdS )_HelperzDisplays an HTML version of the normal help, for the interactive
    debugger only because it requires a patched sys.stdout.
    c                 C   s   dS )Nz(Type help(object) for help about object.r   selfr   r   r   __repr__H   s   z_Helper.__repr__Nc                 C   s   |d u rt jdt|   d S dd l}|| t j }t|tr)|	dd}t
|}t|dkrB|d }d|dd  }nd}|d }t jt||d  d S )	Nz<span class=help>%s</span>r   utf-8ignorer   z

Help)titletext)r   r   r   r   pydochelpreset
isinstancebytesdecode_paragraph_resplitlenjoin	HELP_HTML)r   topicr&   r   
paragraphsr$   r%   r   r   r   __call__K   s   



z_Helper.__call__N)__name__
__module____qualname____doc__r    r3   r   r   r   r   r   C   s    r   c                 C   sh   t |tr|D ]}t||u r|   S qnt||u r| S d}|jjdvr+d|jj }d||jj| f S )N )__builtin__
exceptionsz<span class="module">%s.</span>z%s%s(%s))r)   tupletype	__class__r6   r5   )innerr   basemoduler   r   r   _add_subclass_infob   s   
rB   c                   @   s   e Zd Zdd Ze df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 Zd%ddZd&ddZdd Zdd Zdd Zdd Zdd Zd d! Zd'd#d$Zd"S )(r   c                 C   s
   g | _ d S r4   )_stackr   r   r   r   __init__p   s   
zDebugReprGenerator.__init__   c                    s    fdd}|S )Nc                    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">T</span>r9   )rB   	enumerateappendr   r/   )r   r   	recursivebufhave_extended_sectionidxitemr@   leftlimitrightr   r   proxyt   s   



z6DebugReprGenerator._sequence_repr_maker.<locals>.proxyr   )rQ   rS   r@   rR   rT   r   rP   r   _sequence_repr_makers   s   z'DebugReprGenerator._sequence_repr_maker[]()zset([z])zfrozenset([z/<span class="module">collections.</span>deque([c                 C   sb   t |j}tr|dd}nt|dd}|d d dkr)d|dd   }d| S d| }d| S )	Nzstring-escaper"   zunicode-escaper   uurrz0re.compile(<span class="string regex">%s</span>))r   patternr   r+   codecs)r   r   r]   r   r   r   
regex_repr   s   
zDebugReprGenerator.regex_reprF   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v rP|d	 dv rPt||ttfS |S )
Nz<span class="string">r   rG   rH   r9   r   z'"ubr   )	r   r.   extendr
   rJ   r/   rB   r*   r	   )r   r   rR   rL   r\   outr   r   r   string_repr   s    	

$zDebugReprGenerator.string_repr   c           	      C   s   |rt d|tS dg}d}tt|D ])\}\}}|r |d ||d kr-|d d}|d| || |f  q|rD|d	 |d
 t d||tS )Nz{...}{FrF   r   rG   TzT<span class="pair"><span class="key">%s</span>: <span class="value">%s</span></span>rH   }r9   )rB   dictrI   r   rJ   r   r/   )	r   drK   rR   rL   rM   rN   keyvaluer   r   r   	dict_repr   s&   



zDebugReprGenerator.dict_reprc                 C   s$   t |}tr|dd}dt| S )Nr!   replacez<span class="object">%s</span>)r   r   r+   r
   )r   r   r\   r   r   r   object_repr   s   zDebugReprGenerator.object_reprc                 C   s   |t u rdt  S t|tttfrd| S t|tst|tr#| |S t|tr-| 	|S t|t
r8| ||S t|trC| ||S t|trN| ||S t|trY| ||S t|trd| ||S td urst|trs| ||S | |S )Nz<span class="help">%r</span>z<span class="number">%r</span>)helperr)   r   floatcomplexr   r*   rd   	RegexTyper_   list	list_reprr<   
tuple_reprsetset_repr	frozensetfrozenset_reprrh   rl   r   
deque_reprrn   )r   r   rK   r   r   r   dispatch_repr   s*   








z DebugReprGenerator.dispatch_reprc                 C   sV   zd tt d d  }W n ty   d}Y nw tr#|dd}dt|  S )Nr9   r   ?r!   r"   z8<span class="brokenrepr">&lt;broken repr (%s)&gt;</span>)	r/   r   r   exc_info	Exceptionr   r+   r
   strip)r   infor   r   r   fallback_repr   s   z DebugReprGenerator.fallback_reprc                 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)rC   rJ   r{   popr~   r   )r   r   rK   rO   r   r   r   r      s    
zDebugReprGenerator.reprc              	   C   s   d  }}t |tr)d}g }t|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)   rh   r   r   rJ   r   dirgetattrr~   objectr    render_object_dump)r   r   r   itemsr$   rj   rk   r   r   r   r     s*   


zDebugReprGenerator.dump_objectc                    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)r   r   )r   ri   r   r   r   r   r     s   zDebugReprGenerator.dump_localsNc                 C   s\   g }|D ]\}}| dt||f  q|s| d tt||r%d| ndd|d S )Nz&<tr><th>%s<td><pre class=repr>%s</pre>z<tr><td><em>Nothing</em>z<pre class=repr>%s</pre>r9   
)r$   r   r   )rJ   r
   OBJECT_DUMP_HTMLr/   )r   r   r$   r   
html_itemsrj   rk   r   r   r   r     s   
z%DebugReprGenerator.render_object_dump)r`   )re   r4   )r5   r6   r7   rD   r   rU   rs   rt   r<   ru   rv   rw   rx   ry   r   rz   r_   rd   rl   rn   r{   r   r   r   r   r   r   r   r   r   r   o   s*    

r   )r8   r^   rer   collectionsr   	tracebackr   _compatr   r   r   r   r	   utilsr
   r   r   compiler,   r=   rr   r0   r   r   r   r   ro   rB   r   r   r   r   r   <module>   s.   
	