3
¥Yði%  ã            	   @   s
  d 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jdƒZeeƒZdZdZeed	œd
d„Zefedd	œdd„ZG dd„ dƒZeƒ Zeeejejejejdf f edœdd„Zdeeejeejdeje gef 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.
é    N)Údeque)Úescape)Úformat_exception_onlyz(?:\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Úreturnc             C   s   t ƒ j| ƒS )z1Creates a debug repr of an object as HTML string.)ÚDebugReprGeneratorÚrepr)r   © r	   ú7/tmp/pip-build-8om4l6ph/Werkzeug/werkzeug/debug/repr.pyÚ
debug_repr"   s    r   c             C   s<   t ƒ }| tkr"|jtjdƒjƒ}n
|j| ƒ}tj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               @   s8   e Zd ZdZedœdd„Zd	ejej 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   c             C   s   dS )Nz(Type help(object) for help about object.r	   )Úselfr	   r	   r
   Ú__repr__8   s    z_Helper.__repr__N)Útopicr   c             C   sª   |d kr t jjd| ›d�ƒ d S dd l}|j|ƒ t jjƒ }t|tƒrR|jddƒ}t	j
|ƒ}t|ƒdkr„|d }dj|dd … ƒ}nd}|d }t jjt||d	œ ƒ d S )
Nz<span class=help>z</span>r   zutf-8Úignorer   z

ZHelp)ÚtitleÚtext)r   r   r   ÚpydocÚhelpÚresetÚ
isinstanceÚbytesÚdecodeÚ_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__Ústrr   ÚtÚOptionalÚAnyr*   r	   r	   r	   r
   r   3   s   r   .)Úinnerr   Úbaser   c             C   st   t |tƒr*x.|D ]}t|ƒ|kr| S qW 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>ú(ú))r6   r7   )r"   ÚtupleÚtypeÚ	__class__r,   r+   )r3   r   r4   Úmoduler	   r	   r
   Ú_add_subclass_infoR   s    


r>   é   r   )ÚleftÚrightr4   Úlimitr   c                s$   dt jttdœ‡ ‡‡‡fdd„}|S )Nr   )r   r   Ú	recursiver   c                s˜   |rt ˆ› dˆ› �|ˆ ƒS ˆg}d}xHt|ƒD ]<\}}|rD|jdƒ |ˆkrZ|jdƒ d}|j| j|ƒƒ q.W |r||jdƒ |jˆƒ t dj|ƒ|ˆ ƒS )Nz...Fz, z<span class="extended">Tz</span>r5   )r>   Ú	enumerateÚappendr   r(   )r   r   rC   ÚbufÚhave_extended_sectionÚidxÚitem)r4   r@   rB   rA   r	   r
   Úproxyd   s    



z#_sequence_repr_maker.<locals>.proxy)r0   ÚIterableÚboolr/   )r@   rA   r4   rB   rJ   r	   )r4   r@   rB   rA   r
   Ú_sequence_repr_makera   s     rM   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ejedœdd„Zd)ejeef eedœdd„Zd*ejejedf ejeef ejejeef ef f eeedœdd„Zejejeje ejeje f  edœdd„Zejeedœdd„Z edœdd„Z!e"edœdd „Z#e"edœd!d"„Z$ejeejf ed#œd$d%„Z%d+ej&ej'eef  eeje ed&œd'd(„Z(dS ),r   N)r   c             C   s
   g | _ d S )N)Ú_stack)r   r	   r	   r
   Ú__init__y   s    zDebugReprGenerator.__init__ú[ú]r8   r9   zset([z])zfrozenset([z/<span class="module">collections.</span>deque([)r   r   c             C   s.   t |jƒ}tj|ddƒ}d|› �}d|› d�S )Nzunicode-escaper   Úrz&re.compile(<span class="string regex">z</span>))r   ÚpatternÚcodecsr$   )r   r   rS   r	   r	   r
   Ú
regex_repr„   s    

zDebugReprGenerator.regex_repréF   )r   rB   r   c             C   s¤   dg}t |ƒ}t|ƒ| dkrJ|jt|d |… ƒdt||d … ƒdfƒ n|jt|ƒƒ |jdƒ dj|ƒ}|d dks�|d dkr |d	 dkr t||ttfƒS |S )
Nz<span class="string">é   z<span class="extended">z</span>r5   r   z'"Úbr   )	r   r'   Úextendr   rE   r(   r>   r#   r/   )r   r   rB   rF   rR   Úoutr	   r	   r
   Ústring_reprŠ   s    


$zDebugReprGenerator.string_repré   )ÚdrC   rB   r   c       	      C   s®   |rt d|tƒS dg}d}xht|jƒ ƒD ]X\}\}}|rB|jdƒ ||d kr\|jdƒ d}|jd| j|ƒ› d	| j|ƒ› d
�ƒ q(W |r’|jdƒ |jdƒ t dj|ƒ|tƒS )Nz{...}Ú{Fz, r   z<span class="extended">Tz%<span class="pair"><span class="key">z</span>: <span class="value">z</span></span>z</span>Ú}r5   )r>   ÚdictrD   ÚitemsrE   r   r(   )	r   r]   rC   rB   rF   rG   rH   ÚkeyÚvaluer	   r	   r
   Ú	dict_repr¥   s     

$

zDebugReprGenerator.dict_reprc             C   s   t |ƒ}dt|ƒ› d�S )Nz<span class="object">z</span>)r   r   )r   r   rR   r	   r	   r
   Úobject_repr¾   s    zDebugReprGenerator.object_repr)r   rC   r   c             C   sð   |t krdt ›d�S t|tttfƒr0d|›d�S t|tƒsDt|tƒrN| j|ƒS t|tƒrb| j	|ƒS t|t
ƒrx| j||ƒS t|tƒrŽ| j||ƒS t|tƒr¤| j||ƒS t|tƒrº| j||ƒS t|tƒrÐ| j||ƒS t|tƒræ| j||ƒS | j|ƒS )Nz<span class="help">z</span>z<span class="number">)Úhelperr"   ÚintÚfloatÚcomplexr/   r#   r[   Ú	RegexTyperU   ÚlistÚ	list_reprr:   Ú
tuple_reprÚsetÚset_reprÚ	frozensetÚfrozenset_reprr`   rd   r   Ú
deque_reprre   )r   r   rC   r	   r	   r
   Údispatch_reprÄ   s*    








z DebugReprGenerator.dispatch_reprc             C   sL   ydj ttjƒ d d… Ž ƒ}W n tk
r6   d}Y nX dt|jƒ ƒ› d�S )Nr5   rW   ú?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_reprc             C   sj   d}x| j D ]}||krd}P qW | j j|ƒ z*y| j||ƒS  tk
rT   | jƒ S X W d | j jƒ  X d S )NFT)rN   rE   rs   rv   ry   Úpop)r   r   rC   rI   r	   r	   r
   r   å   s    zDebugReprGenerator.reprc             C   sÞ   d }d }t |tƒrTd}g }x8|jƒ D ],\}}t |tƒs<d }P |j|| j|ƒfƒ q$W |d kr´g }| j|ƒ}xDt|ƒD ]8}y|j|| jt||ƒƒfƒ W qt tk
rª   Y qtX qtW d}|dt	j
|ƒdd… › �7 }| j|||ƒS )NzContents ofzDetails forú r   éÿÿÿÿ)r"   r`   ra   r/   rE   r   ÚdirÚgetattrrv   Úobjectr   Úrender_object_dump)r   r   r   ra   r   rb   rc   r	   r	   r
   r   ô   s*    



zDebugReprGenerator.dump_object)r]   r   c                s"   ‡ fdd„|j ƒ D ƒ}ˆ j|dƒS )Nc                s   g | ]\}}|ˆ j |ƒf‘qS r	   )r   )Ú.0rb   rc   )r   r	   r
   ú
<listcomp>  s    z2DebugReprGenerator.dump_locals.<locals>.<listcomp>zLocal variables in frame)ra   r€   )r   r]   ra   r	   )r   r
   r     s    zDebugReprGenerator.dump_locals)ra   r   r   r   c             C   sj   g }x,|D ]$\}}|j dt|ƒ› d|› d�ƒ q
W |s@|j dƒ tt|ƒd|rR|nd› d�dj|ƒ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   ra   )rE   r   ÚOBJECT_DUMP_HTMLr(   )r   ra   r   r   Z
html_itemsrb   rc   r	   r	   r
   r€     s     
z%DebugReprGenerator.render_object_dump)rV   )r\   )N))r+   r,   r-   rO   rM   rk   rl   r:   rm   rn   ro   rp   rq   r   rr   r0   ÚPatternr/   rU   ÚUnionr#   rg   r[   ÚDictrL   rd   r1   ÚTyper`   ÚCallablere   r2   rs   ry   r   r   r   r   ÚListÚTupler€   r	   r	   r	   r
   r   x   s(   
<"
)r?   )#r.   rT   Úrer   Útypingr0   Úcollectionsr   Úhtmlr   Ú	tracebackr   r   r   Úcompiler%   r;   rj   r)   r„   r/   r   r   r   rf   r†   rˆ   r‹   r>   rg   r‰   rK   rL   rM   r   r	   r	   r	   r
   Ú<module>   s*   
 