U
    (Q^%                     @   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   9/tmp/pip-install-bd4o36v9/Werkzeug/werkzeug/debug/repr.py
debug_repr2   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   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 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   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    r0   r   r   r   r   r   C   s   r   c                 C   sh   t |tr*|D ]}t||kr|   S qnt||kr:| S d}|jjdkrVd|jj }d||jj| f S )N )__builtin__
exceptionsz<span class="module">%s.</span>z%s%s(%s))r(   tupletype	__class__r2   r1   )innerr   basemoduler   r   r   _add_subclass_infob   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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)_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rV|d d}|| | q*|rv|d | t d|| S )Nz...F, <span class="extended">T</span>r5   )r>   	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   )rM   rO   r<   rN   rP   r   rL   r   _sequence_repr_makers   s    z'DebugReprGenerator._sequence_repr_maker[]()zset([z])zfrozenset([z/<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   uurrz0re.compile(<span class="string regex">%s</span>))r   patternr   r*   codecs)r   r   rY   r   r   r   
regex_repr   s    
zDebugReprGenerator.regex_reprF   c                 C   s   dg}t |}t|| dkrJ|t|d | dt||d  df n|t| |d d|}|d dks|d dkr|d	 dkrt||ttfS |S )
Nz<span class="string">r   rC   rD   r5   r   z'"Zubr   )	r   r-   extendr
   rF   r.   r>   r)   r	   )r   r   rN   rH   rX   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\}\}}|r@|d ||d krZ|d d}|d| || |f  q&|r|d	 |d
 t d||tS )Nz{...}{FrB   r   rC   TzT<span class="pair"><span class="key">%s</span>: <span class="value">%s</span></span>rD   }r5   )r>   dictrE   r   rF   r   r.   )	r   drG   rN   rH   rI   rJ   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   rX   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s<t|trF| |S t|trZ| 	|S t|t
rp| ||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   r)   r_   	RegexTyper[   list	list_reprr8   
tuple_reprsetset_repr	frozensetfrozenset_reprrc   rg   r   
deque_reprri   )r   r   rG   r   r   r   dispatch_repr   s*    







z DebugReprGenerator.dispatch_reprc                 C   sX   zd tt d d  }W n tk
r6   d}Y nX trH|dd}dt|  S )Nr5   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   sv   d}| j D ]}||kr
d} q q
| j | z8z| ||W W &S  tk
r`   |   Y W S X W 5 | j   X d S )NFT)r?   rF   poprv   ry   r|   )r   r   rG   rK   r   r   r   r      s    
zDebugReprGenerator.reprc              	   C   s   d  }}t |trRd}g }t|D ].\}}t |ts<d } qR||| |f q"|d krg }| |}t|D ]8}z||| t||f W qp tk
r   Y qpX qpd}|dt	
|dd  7 }| |||S )NzContents ofzDetails for r   )r(   rc   r   r   rF   r   dirgetattrry   objectr    render_object_dump)r   r   r   itemsr#   re   rf   r   r   r   r     s(    


zDebugReprGenerator.dump_objectc                    s"    fdd|  D } |dS )Nc                    s   g | ]\}}|  |fqS r   )r   ).0re   rf   r   r   r   
<listcomp>  s     z2DebugReprGenerator.dump_locals.<locals>.<listcomp>zLocal variables in frame)r   r   )r   rd   r   r   r   r   r     s    zDebugReprGenerator.dump_localsNc                 C   s\   g }|D ]\}}| dt||f  q|s6| d tt||rJd| 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>r5   
)r#   r   r   )rF   r
   OBJECT_DUMP_HTMLr.   )r   r   r#   r   Z
html_itemsre   rf   r   r   r   r     s    
z%DebugReprGenerator.render_object_dump)r\   )r`   )N)r1   r2   r3   r@   r   rQ   rn   ro   r8   rp   rq   rr   rs   rt   r   ru   r[   r_   rg   ri   rv   r|   r   r   r   r   r   r   r   r   r   o   s,     

r   )r4   rZ   rer   collectionsr   	tracebackr   _compatr   r   r   r   r	   utilsr
   r   r   compiler+   r9   rm   r/   r   r   r   r   rj   r>   r   r   r   r   r   <module>   s,   
	