
_%                 @   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 j d  Z e e  Z d Z d Z d d   Z e d d  Z Gd d   d e  Z e   Z d d   Z Gd 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    j |   S)z9Creates a debug repr of an object as HTML unicode string.)DebugReprGeneratorrepr)obj r   7/tmp/pip-build-5gj8f0j9/Werkzeug/werkzeug/debug/repr.py
debug_repr2   s    r   c             C   sV   t    } |  t k r3 | 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   dump7   s
    	r   c               @   s1   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 j d t |    d  Sd d  l } | j |  t  j j   } t | t  rs | j	 d d  } t
 j |  } t |  d k r | d } d j | d d    } n d } | d } t  j j t d | d	 | i  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__)__name__
__module____qualname____doc__r   r.   r   r   r   r   r   C   s   r   c             C   s   t  | t  r9 x= | D] } t |  | k r |  Sq Wn t |  | k rO |  Sd } | j j d k rw d | j j } d | | j j |  f S)N __builtin__
exceptionsz<span class="module">%s.</span>z%s%s(%s))r4   r5   )r&   tupletype	__class__r0   r/   )innerr   basemoduler   r   r   _add_subclass_infob   s    r<   c               @   s  e  Z d  Z d d   Z e   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 [ 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 } xb t |  D]T \ } } | rY | j d  |  k rx | j d  d } | j |  j |   q: W| r | j d  | j   t  d j |  |    S)Nz...Fz, z<span class="extended">Tz</span>r3   )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   )rG   rI   r:   rH   rJ   r   )r:   rG   rH   rI   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* | j d d  } n t j | d d  } | d  d  d k rl d | 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   rS   r   r   r   
regex_repr   s    
zDebugReprGenerator.regex_reprF   c             C   s   d g } t  |  } t |  | d k rg | 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">r   z<span class="extended">z</span>r3   r   z'"Zubr   )	r   r+   extendr
   rA   r,   r<   r'   r	   )r   r   rH   rC   rR   outr   r   r   string_repr   s    	0zDebugReprGenerator.string_repr   c       	      C   s   | r t  d | t  Sd g } d } x t t |   D]q \ } \ } } | r] | j d  | | d k r | j d  d } | j d |  j |  |  j |  f  q8 W| r | j d	  | j d
  t  d j |  | 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>}r3   )r<   dictr@   r   rA   r   r,   )	r   drB   rH   rC   rD   rE   keyvaluer   r   r   	dict_repr   s"    	%$zDebugReprGenerator.dict_reprc             C   s2   t  |  } t r$ | j d d  } d t |  S)Nzutf-8replacez<span class="object">%s</span>)r   r   r(   r
   )r   r   rR   r   r   r   object_repr   s    zDebugReprGenerator.object_reprc             C   sN  | t  k r d t  St | t t t f  r4 d | St | t  sR t | t  r_ |  j |  St | t  r{ |  j	 |  St | t
  r |  j | |  St | t  r |  j | |  St | t  r |  j | |  St | t  r |  j | |  St | t  r|  j | |  St d  k	 rAt | t  rA|  j | |  S|  j |  S)Nz<span class="help">%r</span>z<span class="number">%r</span>)helperr&   r   floatcomplexr   r'   rY   	RegexTyperU   list	list_reprr6   
tuple_reprsetset_repr	frozensetfrozenset_reprr]   ra   r   
deque_reprrc   )r   r   rB   r   r   r   dispatch_repr   s*    z DebugReprGenerator.dispatch_reprc             C   sp   y) d j  t t j   d  d     } Wn t k
 rC d } Yn Xt r\ | j d d  } d t | j    S)Nr3   r   ?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   s   d } x$ |  j  D] } | | k r d } Pq W|  j  j |  z7 y |  j | |  SWn t k
 rr |  j   SYn XWd  |  j  j   Xd  S)NFT)r=   rA   rp   rs   rv   pop)r   r   rB   rF   r   r   r   r      s    zDebugReprGenerator.reprc             C   s$  d  } } t  | t  rt d } g  } xL t |  D]> \ } } t  | t  sT d  } P| j | |  j |  f  q2 W| d  k r g  } |  j |  } xR t |  D]D } y) | j | |  j t | |   f  Wq t k
 r Yq Xq Wd } | d t	 j
 |  d d  7} |  j | | |  S)NzContents ofzDetails for r   )r&   r]   r   r   rA   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   | j    D }   j | d  S)Nc                s+   g  |  ]! \ } } |   j  |  f  q Sr   )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_localsNc             C   s   g  } x1 | D]) \ } } | j  d t |  | f  q W| sM | j  d  t d t |  d | ro d | n d d d j |  i S)	Nz&<tr><th>%s<td><pre class=repr>%s</pre>z<tr><td><em>Nothing</em>r!   r   z<pre class=repr>%s</pre>r3   r~   
)rA   r
   OBJECT_DUMP_HTMLr,   )r   r~   r!   r   Z
html_itemsr_   r`   r   r   r   r}     s    z%DebugReprGenerator.render_object_dump)r/   r0   r1   r>   r|   rK   rh   ri   r6   rj   rk   rl   rm   rn   r   ro   rU   rY   ra   rc   rp   rv   r   r   r   r}   r   r   r   r   r   o   s&   r   )r2   rT   rer   collectionsr   	tracebackr   _compatr   r   r   r   r	   utilsr
   r|   r   compiler)   r7   rg   r-   r   r   r   r   rd   r<   r   r   r   r   r   <module>   s,   		