B
    `'                 @   s   d Z ddlZddlZddlmZ yddlmZ W n ek
rH   dZY nX ddlm	Z	m
Z
mZmZmZmZ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: (c) 2011 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD.
    N)format_exception_only)deque)PY3binary_type
iteritems_longstring_typestext_	text_type)escapez(?:\r\n|\r|\n){2,}zP<div class="box">
  <h3>%(title)s</h3>
  <pre class="help">%(text)s</pre>
</div>zS<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   a/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pyramid_debugtoolbar/repr.py
debug_repr7   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   dump<   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__M   s    z_Helper.__repr__Nc             C   s   |d kr t jdt|   d S dd l}|| tt j dd}t	|}t
|dkrv|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helpr	   reset_paragraph_resplitlenjoin	HELP_HTML)r   Ztopicr$   r   Z
paragraphsr"   r#   r   r   r   __call__P   s    

z_Helper.__call__)N)__name__
__module____qualname____doc__r    r,   r   r   r   r   r   H   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 )builtins__builtin__
exceptionsz<span class="module">%s.</span>z%s%s(%s))
isinstancetupletype	__class__r.   r-   )innerr   basesbasemoduler   r   r   _add_subclass_infoe   s    


r=   c               @   s   e Zd Zdd Ze 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	rbedd
eZ[dd Zd'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$ Zd*d%d&ZdS )+r   c             C   s
   g | _ d S )N)_stack)r   r   r   r   __init__w   s    zDebugReprGenerator.__init__c                s    fdd}|S )Nc                sr   |rt d  | S g}x2t|D ]&\}}|r>|d || | q(W | t td|| S )Nz...z, r1   )r=   	enumerateappendr   r	   r*   )r   r   	recursivebufidxitem)r;   leftrightr   r   proxy{   s    

z6DebugReprGenerator._sequence_repr_maker.<locals>.proxyr   )rF   rG   r;   rH   r   )r;   rF   rG   r   _sequence_repr_makerz   s    z'DebugReprGenerator._sequence_repr_maker[]()zset([z])zfrozenset([Nz/<span class="module">collections.</span>deque([c             C   sl   t r$tdt|j dd}d| }n<tt|jdd}|d d dkrXd|dd   }nd| }td| S )	Nz'%s'zstring-escaper!   rr   uurz0re.compile(<span class="string regex">%s</span>))r   r	   strpatternr   )r   r   rR   r   r   r   
regex_repr   s    
zDebugReprGenerator.regex_reprF   c             C   s   dg}t |}t|d | }t||d  }t|trZ|d |dd  }|dd  }|dkr||d d d|dd  df n
|| |d ttd||t	t
fS )	Nz<span class="string">rO   r   z''z<span class="extended">z</span>r1   )r   r   r5   r
   rA   extendr=   r	   r*   rQ   unicode)r   r   limitrC   escapedabr   r   r   py2_string_repr   s    

$

z"DebugReprGenerator.py2_string_reprc             C   s   dg}t |}t|d | }t||d  }|dkrZ||d d d|dd  df n
|| |d ttd||tS )Nz<span class="string">z''rU   z<span class="extended">r   z</span>r1   )r   r   rV   rA   r=   r	   r*   r
   )r   r   rX   rC   rY   rZ   r[   r   r   r   py3_text_repr   s    $

z DebugReprGenerator.py3_text_reprc             C   s   dg}t t|dd}t|d | }t||d  }|d |dkrl||d d d|dd  d	f n
|| |d	 ttd
||tS )Nz<span class="string">zutf-8replacer[   z''rU   z<span class="extended">r   z</span>r1   )r   r	   r   rA   rV   r=   r*   r   )r   r   rX   rC   rY   rZ   r[   r   r   r   py3_binary_repr   s    
$

z"DebugReprGenerator.py3_binary_reprc             C   s   |rt td|tS dg}xHtt|D ]8\}\}}|rB|d |d| || |f  q(W |d t td||tS )Nz{...}{z, zT<span class="pair"><span class="key">%s</span>: <span class="value">%s</span></span>}r1   )r=   r	   dictr@   r   rA   r   r*   )r   drB   rC   rD   keyvaluer   r   r   	dict_repr   s    

zDebugReprGenerator.dict_reprc             C   s   t dtt t|dd S )Nz<span class="object">%s</span>zutf-8r^   )r	   r   r   )r   r   r   r   r   object_repr   s    zDebugReprGenerator.object_reprc             C   s"  |t krtdt  S t|ttttfr2td| S tr`t|trJ| 	|S t|t
rt| |S nt|trt| |S t|tr| |S t|tr| ||S t|tr| ||S t|tr| ||S t|tr| ||S t|tr| ||S td k	rt|tr| ||S | |S )Nz<span class="help">%r</span>z<span class="number">%r</span>)helperr	   r5   intr   floatcomplexr   r
   r]   r   r_   
basestringr\   	RegexTyperS   list	list_reprr6   
tuple_reprsetset_repr	frozensetfrozenset_reprrb   rf   r   
deque_reprrg   )r   r   rB   r   r   r   dispatch_repr   s4    











z DebugReprGenerator.dispatch_reprc             C   sT   yd tt d d  }W n tk
r6   d}Y nX tdtt|dd  S )Nr1      ?z8<span class="brokenrepr">&lt;broken repr (%s)&gt;</span>zutf-8r!   )r*   r   r   exc_info	Exceptionr	   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>   rA   rv   rz   r}   pop)r   r   rB   rE   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   rU   )r5   rb   r   r   rA   r   dirgetattrrz   objectr    render_object_dump)r   r   r   itemsr"   rd   re   r   r   r   r     s(    



zDebugReprGenerator.dump_objectc                s"    fdd|  D } |dS )Nc                s   g | ]\}}|  |fqS r   )r   ).0rd   re   )r   r   r   
<listcomp>-  s    z2DebugReprGenerator.dump_locals.<locals>.<listcomp>zLocal variables in frame)r   r   )r   rc   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>r1   
)r"   r   r   )rA   r   OBJECT_DUMP_HTMLr*   )r   r   r"   r   Z
html_itemsrd   re   r   r   r   r   0  s    
z%DebugReprGenerator.render_object_dump)rT   )rT   )rT   )N)r-   r.   r/   r?   r   rI   rn   ro   r6   rp   rq   rr   rs   rt   r   ru   rS   r\   r]   r_   rf   rg   rv   r}   r   r   r   r   r   r   r   r   r   v   s,   




r   ) r0   rer   	tracebackr   collectionsr   ImportErrorZpyramid_debugtoolbar.compatr   r   r   r   r   r	   r
   Zpyramid_debugtoolbar.utilsr   r   r   compiler'   r7   rm   r+   r   r   r   r   rh   r=   r   r   r   r   r   <module>   s(   
$	
