HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/conch/__pycache__/manhole.cpython-38.pyc
U


W[8.�@s�dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZddl
mZGdd	�d	�ZGd
d�dej�ZdZd
ZdZdZdZdZGdd�dej�ZGdd�d�Zdd�ZGdd�de�ZdS)aO
Line-input oriented interactive interpreter loop.

Provides classes for handling Python source input and arbitrary output
interactively from a Twisted application.  Also included is syntax coloring
code with support for VT102 terminals, control code handling (^C, ^D, ^Q),
and reasonable handling of Deferreds.

@author: Jp Calderone
�N)�BytesIO)�recvline)�defer)�	_tokenize�_get_async_param)�TokenPrinterc@s8eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dS)
�FileWrapperz�
    Minimal write-file-like object.

    Writes are translated into addOutput calls on an object passed to
    __init__.  Newlines are also converted from network to local style.
    rZnormalcCs
||_dS�N)�o)�selfr
�r�7/usr/lib/python3/dist-packages/twisted/conch/manhole.py�__init__&szFileWrapper.__init__cCsdSr	r�rrrr
�flush*szFileWrapper.flushcCs|j�|�dd��dS)Nz
�
)r
�	addOutput�replace)r�datarrr
�write.szFileWrapper.writecCs|�d�|��dS)N�)r�join)r�linesrrr
�
writelines2szFileWrapper.writelinesN)
�__name__�
__module__�__qualname__�__doc__Z	softspace�staterrrrrrrr
rsrc@sXeZdZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zddd�ZdS)�ManholeInterpreteraf
    Interactive Interpreter with special output and Deferred support.

    Aside from the features provided by L{code.InteractiveInterpreter}, this
    class captures sys.stdout output and redirects it to the appropriate
    location (the Manhole protocol instance).  It also treats Deferreds
    which reach the top-level specially: each is formatted to the user with
    a unique identifier and a new callback and errback added to it, each of
    which will format the unique identifier and the result with which the
    Deferred fires and then pass it on to the next participant in the
    callback chain.
    rN�	<console>cCs,tj�||�i|_||_||_|��dSr	)�code�InteractiveInterpreterr�_pendingDeferreds�handler�filename�resetBuffer)rr$�localsr%rrr
rFs
zManholeInterpreter.__init__cCs
g|_dS)z)
        Reset the input buffer.
        N)�bufferrrrr
r&NszManholeInterpreter.resetBuffercCs@|j�|�d�|j�}|�d�}|�||j�}|s<|��|S)a
        Push a line to the interpreter.

        The line should not have a trailing newline; it may have
        internal newlines.  The line is appended to a buffer and the
        interpreter's runsource() method is called with the
        concatenated contents of the buffer as source.  If this
        indicates that the command was executed or invalid, the buffer
        is reset; otherwise, the command is incomplete, and the buffer
        is left as it was after the line was appended.  The return
        value is 1 if more input is required, 0 if the line was dealt
        with in some way (this is the same as runsource()).

        @param line: line of text
        @type line: L{bytes}
        @return: L{bool} from L{code.InteractiveInterpreter.runsource}
        �
�utf-8)r(�appendr�decodeZ	runsourcer%r&)r�line�source�morerrr
�pushUs
zManholeInterpreter.pushcOsXtj|j}t_z:tjt|j�}t_ztjj|f|�|�W5|t_XW5|t_XdSr	)�sys�displayhook�stdoutrr$r!r"�runcode)r�a�kwZorighookZorigoutrrr
r4pszManholeInterpreter.runcodecCs�||jd<t|tj�r�t|d�r0|�t|��q�t|�|jkr^|�d|jt|�df�q�|j}|j	}||f|t|�<|j	d7_	|j
|j|j||f||fd�|�d|f�n|dk	r�|�t|��dS)N�_�resultz<Deferred #%d>r�)ZcallbackArgsZerrbackArgs)
r'�
isinstancerZDeferred�hasattrr�repr�idr#�numDeferredsZaddCallbacks�_cbDisplayDeferred�_ebDisplayDeferred)r�obj�d�krrr
r2|s"

 �zManholeInterpreter.displayhookcCs$|�d||fd�|jt|�=|S)NzDeferred #%d called back: %rT)rr#r=)rr8rCrArrr
r?�sz%ManholeInterpreter._cbDisplayDeferredcCs(|�d||��fd�|jt|�=|S)NzDeferred #%d failed: %rT)rZgetErrorMessager#r=)rZfailurerCrArrr
r@�sz%ManholeInterpreter._ebDisplayDeferredcKst|f|�}|j�||�dSr	)rr$r)rr�isAsync�kwargsrrr
r�szManholeInterpreter.write)Nr )N)
rrrrr>rr&r0r4r2r?r@rrrrr
r7s

r������c@s`eZdZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zddd�Zdd�Z
dS)�Manholea�
    Mediator between a fancy line source and an interactive interpreter.

    This accepts lines from its transport and passes them on to a
    L{ManholeInterpreter}.  Control commands (^C, ^D, ^\) are also handled
    with something approximating their normal terminal-mode behavior.  It
    can optionally be constructed with a dict which will be used as the
    local namespace for any code executed.
    NcCs"tj�|�|dk	r|��|_dSr	)r�HistoricRecvLiner�copy�	namespace)rrOrrr
r�szManhole.__init__cCsftj�|�t||j�|_|j|jt<|j	|jt
<|j|jt<|j
|jt<|j|jt<|j|jt<dSr	)rrM�connectionMaderrO�interpreter�
handle_INTZkeyHandlers�CTRL_C�
handle_EOF�CTRL_D�	handle_FF�CTRL_LZhandle_HOME�CTRL_AZ
handle_END�CTRL_E�handle_QUIT�CTRL_BACKSLASHrrrr
rP�szManhole.connectionMadecCsTd|_g|_d|_|j��|j��|j�d�|j��|j�|j|j�dS)z~
        Handle ^C as an interrupt keystroke by resetting the current input
        variables to their initial state.
        rsKeyboardInterruptN)	�pn�
lineBuffer�lineBufferIndexrQr&�terminal�nextLiner�psrrrr
rR�s


zManhole.handle_INTcCs |jr|j�d�n|��dS)N�)r]r_rrZrrrr
rT�szManhole.handle_EOFcCs |j��|j��|��dS)zh
        Handle a 'form feed' byte - generally used to request a screen
        refresh/redraw.
        N)r_ZeraseDisplayZ
cursorHomeZ
drawInputLinerrrr
rV�s

zManhole.handle_FFcCs|j��dSr	)r_ZloseConnectionrrrr
rZ�szManhole.handle_QUITcCs |jj}|�d�o|�d�S)Nr)sE)r_Z	lastWrite�endswith)r�wrrr
�
_needsNewline�szManhole._needsNewlinecKs�t|f|�}|r<|j��|j�t|j�t|j|j��|j�|�|r�|�	�r^|j�
�|j�|j|j�|jr�|j}g|_d|_|�|�dS)Nr)
rr_�	eraseLine�cursorBackward�lenr]rar\rrer`r^Z_deliverBuffer)rrrDrEZ	oldBufferrrr
r�s 
�
zManhole.addOutputcCs@|j�|�}t|�|_|��r(|j��|j�|j|j�dSr	)	rQr0�boolr\rer_r`rra)rr-r/rrr
�lineReceived
s


zManhole.lineReceived)N)N)rrrrrOrrPrRrTrVrZrerrjrrrr
rL�s



rLc@sVeZdZdZdddddddd	�Zd
Zdd�Zd
d�Zddd�Zdd�Z	e
ekrRe	ZdS)�VT102Writerz�
    Colorizer for Python tokens.

    A series of tokens are written to instances of this object.  Each is
    colored in a particular way.  The final line of the result of this is
    generally added to the output.
    sssssss)Z
identifier�keywordZ	parameterZvariable�stringZnumber�opscCs
g|_dSr	)�writtenrrrr
r'szVT102Writer.__init__cCs|j�|d�}|S)N�)�typeToColor�get)r�type�rrrr
�color+szVT102Writer.colorNcCsH|rD|dkrD|�|�}|r&|j�|�|j�|�|rD|j�|j�dS)N�
)ruror+�normalColor)r�tokenrs�crrr
r0s
zVT102Writer.writecCsd�|j�}|�d���dS)Nrpr)���)rro�strip�
splitlines)r�srrr
�	__bytes__:szVT102Writer.__bytes__)N)
rrrrrqrwrrurr~�bytes�str�__str__rrrr
rks 	�	

rkc
Csdt|t�s|�d�}t�}t|j�j}t|�}t|j	�D]"}|\}}}}}	||||||	�q8t|�S)z�
    Tokenize and colorize the given Python source.

    Returns a VT102-format colorized version of the last line of C{source}.

    @param source: Python source code
    @type source: L{str} or L{bytes}
    @return: L{bytes} of colorized source
    r*)
r:r�encoderkrrZ
printtokenrr�readline)
r.rd�pr}rxZ	tokenTyperm�start�endr-rrr
�lastColorizedLineDs


r�c@s eZdZdZdd�Zdd�ZdS)�ColoredManholez<
    A REPL which syntax colors input as users type it.
    cCsd�|jj�dd�|j�S)z�
        Return a string containing the currently entered source.

        This is only the code which will be considered for execution
        next.
        r)rp)rrQr(r]rrrr
�	getSourceas
�
�zColoredManhole.getSourcecCs|jdkr|j�|j|�n|g|j|j|jd�<|jd7_|rJdS|dkrb|j�|�dS|��}zt|�}Wn"tj	k
r�|j�|�YnlX|j�
�|j�t|j�t|j
|j�d�|j�|j
|j|�t|j�|j}|�r|j�|�dS)N�insertr9� )�moder]r�r^r_rr�r��tokenize�
TokenErrorrfrgrhrar\)rZchZmoreCharactersComingr.ZcoloredLine�nrrr
�characterReceivedms(

&z ColoredManhole.characterReceivedN)rrrrr�r�rrrr
r�\sr�)rr!r1r��iorZ
twisted.conchrZtwisted.internetrZtwisted.python.compatrrZtwisted.python.htmlizerrrr"rrSrUr[rWrXrYrMrLrkr�r�rrrr
�<module>s$kh1