B
    bAZ|$                 @   s   d Z ddlZddlZddlZddlmZ yddlmZ W n ek
rP   dZY nX ddl	m
Z
 ddlmZmZmZmZ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: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD.
    N)format_exception_only)deque)escape)	iteritemsPY2	text_typeinteger_typesstring_typesz(?:\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   2lib/python3.7/site-packages/werkzeug/debug/repr.py
debug_repr1   s    r   c             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   dump6   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 kr t jdt|   d S dd l}|| t j }t|trR|	dd}t
|}t|dkr|d }d|dd  }nd}|d }t jt||d  d S )	Nz<span class=help>%s</span>r   zutf-8ignorer   z

ZHelp)titletext)r   r   r   r   pydochelpreset
isinstancebytesdecode_paragraph_resplitlenjoin	HELP_HTML)r   Ztopicr"   r   Z
paragraphsr    r!   r   r   r   __call__K   s    



z_Helper.__call__)N)__name__
__module____qualname____doc__r   r-   r   r   r   r   r   B   s   r   c             C   sh   t |tr*x.|D ]}t||kr| S qW nt||kr:| S d}|jjdkrVd|jj }d||jj| f S )N )Z__builtin__
exceptionsz<span class="module">%s.</span>z%s%s(%s))r%   tupletype	__class__r/   r.   )innerr   basemoduler   r   r   _add_subclass_infoa   s    


r:   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k	rde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 )N)_stack)r   r   r   r   __init__p   s    zDebugReprGenerator.__init__   c                s    fdd}|S )Nc                s   |rt d  | S g}d}xHt|D ]<\}}|rB|d |krX|d d}|| | q,W |rz|d | t d|| S )Nz...Fz, z<span class="extended">Tz</span>r2   )r:   	enumerateappendr   r+   )r   r   	recursivebufhave_extended_sectionidxitem)r8   leftlimitrightr   r   proxyt   s    



z6DebugReprGenerator._sequence_repr_maker.<locals>.proxyr   )rE   rG   r8   rF   rH   r   )r8   rE   rF   rG   r   _sequence_repr_makers   s    z'DebugReprGenerator._sequence_repr_maker[]()zset([z])zfrozenset([Nz/<span class="module">collections.</span>deque([c             C   s\   t |j}tr|dd}nt|dd}|d d dkrLd|dd   }nd| }d| S )	Nzstring-escaper   zunicode-escaper   uZurrz0re.compile(<span class="string regex">%s</span>))r   patternr   r'   codecs)r   r   rP   r   r   r   
regex_repr   s    
zDebugReprGenerator.regex_reprF   c             C   s   dg}t |d | }t ||d  }t|trVtrV|d |dd  }|dd  }|dkr|t|d d dt|dd  df n|t| |d td||t	tfS )	Nz<span class="string">rN   r   z''z<span class="extended">z</span>r2   )
r   r%   r   r   r?   extendr   r:   r+   r&   )r   r   rF   rA   abr   r   r   string_repr   s    
,
zDebugReprGenerator.string_repr   c       	      C   s   |rt d|tS dg}d}xbtt|D ]R\}\}}|rB|d ||d kr\|d d}|d| || |f  q(W |r|d	 |d
 t d||tS )Nz{...}{Fz, r   z<span class="extended">TzT<span class="pair"><span class="key">%s</span>: <span class="value">%s</span></span>z</span>}r2   )r:   dictr>   r   r?   r   r+   )	r   dr@   rF   rA   rB   rC   keyvaluer   r   r   	dict_repr   s     



zDebugReprGenerator.dict_reprc             C   s$   t |}tr|dd}dt| S )Nzutf-8replacez<span class="object">%s</span>)r   r   r'   r   )r   r   rO   r   r   r   object_repr   s    zDebugReprGenerator.object_reprc             C   s   |t krdt  S t|tttfr(d| S t|tr<| |S t|trP| |S t|t	rf| 
||S t|tr|| ||S t|tr| ||S t|tr| ||S t|tr| ||S td k	rt|tr| ||S | |S )Nz<span class="help">%r</span>z<span class="number">%r</span>)helperr%   r   floatcomplexr	   rX   	RegexTyperR   list	list_reprr4   
tuple_reprsetset_repr	frozensetfrozenset_reprr\   r`   r   
deque_reprrb   )r   r   r@   r   r   r   dispatch_repr   s*    








z DebugReprGenerator.dispatch_reprc             C   sX   yd tt d d  }W n tk
r6   d}Y nX trH|dd}dt|  S )Nr2      ?zutf-8r   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   sj   d}x| j D ]}||krd}P qW | j | z*y| ||S  tk
rT   |  S X W d | j   X d S )NFT)r;   r?   ro   rs   rv   pop)r   r   r@   rD   r   r   r   r      s    zDebugReprGenerator.reprc          	   C   s   d  }}t |trTd}g }x8t|D ],\}}t |ts<d }P ||| |f q$W |d krg }| |}xDt|D ]8}y||| t||f W qt tk
r   Y qtX qtW d}|dt	
|dd  7 }| |||S )NzContents ofzDetails for r   rT   )r%   r\   r   r	   r?   r   dirgetattrrs   objectr   render_object_dump)r   r   r   itemsr    r^   r_   r   r   r   r      s(    



zDebugReprGenerator.dump_objectc                s"    fdd|  D } |dS )Nc                s   g | ]\}}|  |fqS r   )r   ).0r^   r_   )r   r   r   
<listcomp>
  s    z2DebugReprGenerator.dump_locals.<locals>.<listcomp>zLocal variables in frame)r}   r|   )r   r]   r}   r   )r   r   r   	  s    zDebugReprGenerator.dump_localsc             C   s`   g }x&|D ]\}}| dt||f  q
W |s:| d tt||rNd| pPd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>r2   
)r    r   r}   )r?   r   OBJECT_DUMP_HTMLr+   )r   r}   r    r   Z
html_itemsr^   r_   r   r   r   r|     s    
z%DebugReprGenerator.render_object_dump)rS   )rY   )N)r.   r/   r0   r<   r{   rI   rg   rh   r4   ri   rj   rk   rl   rm   r   rn   rR   rX   r`   rb   ro   rv   r   r   r   r|   r   r   r   r   r
   n   s(   


r
   )r1   r   rerQ   	tracebackr   collectionsr   ImportErrorZwerkzeug.utilsr   Zwerkzeug._compatr   r   r   r   r	   r{   r   compiler(   r5   rf   r,   r   r   r   r   rc   r:   r
   r   r   r   r   <module>   s*   

