o
    ¹ip  ã                   @   sÎ   d 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 eƒ ZG dd„ deƒZG dd„ deƒZejZeje_G dd„ deƒZdd„ ZG dd„ dejƒZG dd„ deƒZdS )z’
    werkzeug.debug.console
    ~~~~~~~~~~~~~~~~~~~~~~

    Interactive console support.

    :copyright: 2007 Pallets
    :license: BSD-3-Clause
é    N)ÚCodeTypeé   )ÚLocal)Úescapeé   )Ú
debug_repr)Údump)Úhelperc                   @   sb   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zddd„Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚHTMLStringOz-A StringO version that HTML escapes on write.c                 C   s
   g | _ d S ©N)Ú_buffer©Úself© r   úQ/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/werkzeug/debug/console.pyÚ__init__   ó   
zHTMLStringO.__init__c                 C   s   dS )NFr   r   r   r   r   Úisatty   ó   zHTMLStringO.isattyc                 C   ó   d S r   r   r   r   r   r   Úclose"   r   zHTMLStringO.closec                 C   r   r   r   r   r   r   r   Úflush%   r   zHTMLStringO.flushr   c                 C   r   r   r   )r   ÚnÚmoder   r   r   Úseek(   r   zHTMLStringO.seekc                 C   s(   t | jƒdkr	dS | jd }| jd= |S )Nr   Ú )Úlenr   )r   Úretr   r   r   Úreadline+   s
   
zHTMLStringO.readlinec                 C   s   d  | j¡}| jd d …= |S ©Nr   )Újoinr   )r   Úvalr   r   r   Úreset2   s   zHTMLStringO.resetc                 C   s&   t |tƒr| dd¡}| j |¡ d S )Nzutf-8Úreplace)Ú
isinstanceÚbytesÚdecoder   Úappend©r   Úxr   r   r   Ú_write7   s   
zHTMLStringO._writec                 C   s   |   t|ƒ¡ d S r   )r*   r   r(   r   r   r   Úwrite<   s   zHTMLStringO.writec                 C   s   |   td |¡ƒ¡ d S r   )r*   r   r    r(   r   r   r   Ú
writelines?   s   zHTMLStringO.writelinesN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r"   r*   r+   r,   r   r   r   r   r
      s    
r
   c                   @   sT   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ ZdS )ÚThreadedStreamz@Thread-local wrapper for sys.stdout for the interactive console.c                   C   s    t tjtƒs
tƒ t_tƒ t_d S r   )r$   ÚsysÚstdoutr1   r
   Ú_localÚstreamr   r   r   r   ÚpushF   s   zThreadedStream.pushc                  C   s&   zt j} W |  ¡ S  ty   Y dS w r   )r4   r5   ÚAttributeErrorr"   )r5   r   r   r   ÚfetchL   s   þÿzThreadedStream.fetchc                 C   sP   zt j}W n ty   t| ƒ Y S w | d ur&| t jjd< | t| ƒ¡ d S d S )NÚ_)r4   r5   r7   Ú_displayhookÚ_current_ipyÚlocalsr*   r   )Úobjr5   r   r   r   ÚdisplayhookT   s   
ÿþzThreadedStream.displayhookc                 C   s   t d| ƒ‚)Nzread only attribute %s)r7   )r   ÚnameÚvaluer   r   r   Ú__setattr__`   s   zThreadedStream.__setattr__c                 C   ó
   t tjƒS r   )Údirr2   Ú
__stdout__r   r   r   r   Ú__dir__c   r   zThreadedStream.__dir__c                 C   s@   |dkr	t tjƒS ztj}W n ty   tj}Y nw t||ƒS )NÚ__members__)rC   r2   rD   r4   r5   r7   Úgetattr)r   r?   r5   r   r   r   Ú__getattribute__f   s   


ÿ
zThreadedStream.__getattribute__c                 C   rB   r   )Úreprr2   rD   r   r   r   r   Ú__repr__o   r   zThreadedStream.__repr__N)r-   r.   r/   r0   Ústaticmethodr6   r8   r>   rA   rE   rH   rJ   r   r   r   r   r1   C   s    


	r1   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_ConsoleLoaderc                 C   s
   i | _ d S r   )Ú_storager   r   r   r   r   y   r   z_ConsoleLoader.__init__c                 C   s6   || j t|ƒ< |jD ]}t|tƒr|| j t|ƒ< q
d S r   )rM   ÚidÚ	co_constsr$   r   )r   ÚcodeÚsourceÚvarr   r   r   Úregister|   s   

€þz_ConsoleLoader.registerc                 C   s&   z| j t|ƒ W S  ty   Y d S w r   )rM   rN   ÚKeyError©r   rP   r   r   r   Úget_source_by_codeƒ   s
   ÿz!_ConsoleLoader.get_source_by_codeN)r-   r.   r/   r   rS   rV   r   r   r   r   rL   x   s    rL   c                    s   ˆj ‰ ‡ ‡fdd„}|ˆ_ d S )Nc                    s   ˆ | ||ƒ}ˆj  || ¡ |S r   )ÚloaderrS   )rQ   ÚfilenameÚsymbolrP   ©ÚcompileÚconsoler   r   Úfunc   s   z_wrap_compiler.<locals>.func)r[   )r\   r]   r   rZ   r   Ú_wrap_compilerŠ   s   
r^   c                   @   s>   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zdd
d„Zdd„ Zd	S )Ú_InteractiveConsolec                 C   s\   t |ƒ}| |¡ |}t|d< t|d< tƒ  |d< | _tj | |¡ d| _	g | _
t| ƒ d S )Nr   ÚhelpÚ
__loader__F)ÚdictÚupdater   r	   rL   rW   rP   ÚInteractiveInterpreterr   ÚmoreÚbufferr^   )r   Úglobalsr<   Ú_localsr   r   r   r   –   s   
z_InteractiveConsole.__init__c                 C   s”   |  ¡ d }t ¡  | jrdnd}z+d | j|g ¡}tj | |dd¡r.d| _| j 	|¡ n	d| _| jd d …= W t 
¡ }nt 
¡ }w |t|ƒ | S )	NÚ
z... z>>> r   z
<debugger>ÚsingleTF)Úrstripr1   r6   re   r    rf   rP   rd   Ú	runsourcer'   r8   r   )r   rQ   ÚpromptÚsource_to_evalÚoutputr   r   r   rl   ¢   s   ÿ€z_InteractiveConsole.runsourcec                 C   s0   z	t || jƒ W d S  ty   |  ¡  Y d S w r   )Úexecr<   Ú	ExceptionÚshowtracebackrU   r   r   r   Úruncode´   s
   ÿz_InteractiveConsole.runcodec                 C   s*   ddl m} |dd}tj | ¡ ¡ d S )Nr   ©Úget_current_traceback©Úskip©Útbtoolsru   r2   r3   r*   Úrender_summary)r   ru   Útbr   r   r   rr   º   ó   
z!_InteractiveConsole.showtracebackNc                 C   s*   ddl m} |dd}tj | ¡ ¡ d S )Nr   rt   é   rv   rx   )r   rX   ru   r{   r   r   r   ÚshowsyntaxerrorÀ   r|   z#_InteractiveConsole.showsyntaxerrorc                 C   s   t j |¡ d S r   )r2   r3   r+   )r   Údatar   r   r   r+   Æ   s   z_InteractiveConsole.writer   )	r-   r.   r/   r   rl   rs   rr   r~   r+   r   r   r   r   r_   •   s    
r_   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚConsolezAn interactive console.Nc                 C   s(   |d u ri }|d u ri }t ||ƒ| _d S r   )r_   Ú_ipy)r   rg   r<   r   r   r   r   Í   s
   zConsole.__init__c                 C   s,   | j t_tj}z
| j  |¡W |t_S |t_w r   )r   r4   r;   r2   r3   rl   )r   rP   Úold_sys_stdoutr   r   r   ÚevalÔ   s
   zConsole.eval)NN)r-   r.   r/   r0   r   rƒ   r   r   r   r   r€   Ê   s    
r€   )r0   rP   r2   Útypesr   Úlocalr   Úutilsr   rI   r   r   r	   r4   Úobjectr
   r1   r>   r:   rL   r^   rd   r_   r€   r   r   r   r   Ú<module>   s$   	*15