o
    '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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 )*zObject 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   O/var/www/html/olx_land/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 )_HelperzDisplays 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_reprF   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   d7dict[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,    

	
