%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/conch/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/conch/__pycache__/manhole.cpython-312.pyc

�

Ϫ�fM0��<�dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZddlmZGd�d
�ZGd�dej.�ZdZdZdZdZdZdZGd�de
j>�Z Gd�d�Z!d�Z"Gd�de �Z#y)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)�format_exception)�
TracebackType)�Type)�recvline)�defer)�_get_async_param)�TokenPrinter)�
MonkeyPatcherc�0�eZdZdZdZdZd�Zd�Zd�Zd�Z	y)	�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.
    r�normalc��||_y�N)�o)�selfrs  �7/usr/lib/python3/dist-packages/twisted/conch/manhole.py�__init__zFileWrapper.__init__*s	�����c��yr��rs r�flushzFileWrapper.flush-s��rc�Z�|jj|jdd��y)Nz
�
)r�	addOutput�replace)r�datas  r�writezFileWrapper.write0s����������f�d�3�4rc�D�|jdj|��y)N�)r�join)r�liness  r�
writelineszFileWrapper.writelines3s���
�
�2�7�7�5�>�"rN)
�__name__�
__module__�__qualname__�__doc__�	softspace�staterrrr$rrrr
r
s'����I��E��
�5�#rr
c�f�eZdZdZdZdd�Zd�Zd�Zd�Zde	e
d	e
d
eddfd�Zd
�Z
d�Zd�Zdd�Zy)�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.
    rNc��tjj||�i|_||_||_|j
�t�|_|jjtd|j�|jjtd|j�|jjtdt|j��y)N�displayhook�
excepthook�stdout)�code�InteractiveInterpreterr�_pendingDeferreds�handler�filename�resetBufferr�
monkeyPatcher�addPatch�sysr.r/r
)rr4�localsr5s    rrzManholeInterpreter.__init__Gs����#�#�,�,�T�6�:�!#������ ��
�����*�_������#�#�C���8H�8H�I����#�#�C��t���G����#�#�C��;�t�|�|�3L�Mrc��g|_y)z)
        Reset the input buffer.
        N)�bufferrs rr6zManholeInterpreter.resetBufferSs����rc���|jj|�dj|j�}|jd�}|j	||j
�}|s|j
�|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"�decode�	runsourcer5r6)r�line�source�mores    r�pushzManholeInterpreter.pushYs^��$	
�����4� ����D�K�K�(�����w�'���~�~�f�d�m�m�4��������rc��|j5tjj|g|��i|��ddd�y#1swYyxYwr)r7r1r2�runcode)r�a�kws   rrHzManholeInterpreter.runcodessB��
�
�
�	@��'�'�/�/��?�q�?�B�?�	@�	@�	@�s	�$:�A�excType�excValue�excTraceback�returnc�r�t|||j�}|jdj|��y)zS
        Format exception tracebacks and write them to the output handler.
        r!N)r�tb_nextrr")rrKrLrMr#s     rr/zManholeInterpreter.excepthookws,��!��(�L�4H�4H�I���
�
�2�7�7�5�>�"rc�j�||jd<t|tj�r�t	|d�r|jt
|��yt|�|jvr/|jd|jt|�dfz�y|j}|j}||f|t|�<|xjdz
c_	|j|j|j||f||f��|jd|fz�y|�|jt
|��yy)N�_�resultz<Deferred #%d>r�)�callbackArgs�errbackArgs)
r:�
isinstancer�Deferred�hasattrr�repr�idr3�numDeferreds�addCallbacks�_cbDisplayDeferred�_ebDisplayDeferred)r�obj�d�ks    rr.zManholeInterpreter.displayhook�s������C���c�5�>�>�*��s�H�%��
�
�4��9�%��C��D�2�2�2��
�
�+�t�/E�/E�b��g�/N�q�/Q�.S�S�T��*�*���%�%����X��"�S�'�
��!�!�Q�&�!�� � ��+�+��+�+�"#�S��!"�C��	!���
�
�+�q�d�2�3�
�_��J�J�t�C�y�!�rc�`�|jd||fzd�|jt|�=|S)NzDeferred #%d called back: %rT)rr3r[)rrSrbr`s    rr^z%ManholeInterpreter._cbDisplayDeferred�s1���
�
�1�Q��K�?��F��"�"�2�c�7�+��
rc�|�|jd||j�fzd�|jt|�=|S)NzDeferred #%d failed: %rT)r�getErrorMessager3r[)r�failurerbr`s    rr_z%ManholeInterpreter._ebDisplayDeferred�s;���
�
�,��7�3J�3J�3L�/M�M�t�T��"�"�2�c�7�+��rc�T�t|fi|��}|jj||�yr)r	r4r)rr�isAsync�kwargss    rrzManholeInterpreter.write�s%��"�7�5�f�5�������t�W�-r)Nz	<console>r)r%r&r'r(r\rr6rFrHr�
BaseExceptionrr/r.r^r_rrrrr,r,7sh����L�
N���4@�
#��m�$�
#� �
#�$�	
#�

�
#�"�.�
�
.rr,������c�N�eZdZdZdZdd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zdd
�Zd�Z
y)
�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.
    Nc�r�tjj|�|�|j�|_yyr)r�HistoricRecvLiner�copy�	namespace)rrvs  rrzManhole.__init__�s/���!�!�*�*�4�0�� �&�^�^�-�D�N�!rc���tjj|�t||j�|_|j|jt<|j|jt<|j|jt<|j|jt<|j|jt <|j"|jt$<yr)rrt�connectionMader,rv�interpreter�
handle_INT�keyHandlers�CTRL_C�
handle_EOF�CTRL_D�	handle_FF�CTRL_L�handle_HOME�CTRL_A�
handle_END�CTRL_E�handle_QUIT�CTRL_BACKSLASHrs rrxzManhole.connectionMade�s����!�!�0�0��6�-�d�D�N�N�C���#'�?�?����� �#'�?�?����� �#'�>�>����� �#'�#3�#3����� �#'�?�?����� �+/�+;�+;�����(rc�d�d|_g|_d|_|jj	�|j
j
�|j
jd�|j
j
�|j
j|j|j�y)z~
        Handle ^C as an interrupt keystroke by resetting the current input
        variables to their initial state.
        rsKeyboardInterruptN)	�pn�
lineBuffer�lineBufferIndexryr6�terminal�nextLiner�psrs rrzzManhole.handle_INT�s~��
������ ������$�$�&��
�
��� ��
�
���0�1��
�
��� ��
�
���D�G�G�D�G�G�,�-rc�t�|jr|jjd�y|j�y)N�)r�r�rr�rs rr}zManhole.handle_EOF�s'���?�?��M�M����&����rc��|jj�|jj�|j�y)zh
        Handle a 'form feed' byte - generally used to request a screen
        refresh/redraw.
        N)r��eraseDisplay�
cursorHome�
drawInputLiners rrzManhole.handle_FF�s0��
	
�
�
�"�"�$��
�
� � �"����rc�8�|jj�yr)r��loseConnectionrs rr�zManhole.handle_QUIT�s���
�
�$�$�&rc�z�|jj}|jd�xr|jd�S)Nr>sE)r��	lastWrite�endswith)r�ws  r�
_needsNewlinezManhole._needsNewline�s4���M�M�#�#���:�:�e�$�$�A�Q�Z�Z��-A�)A�Arc�Z�t|fi|��}|rk|jj�|jjt	|j
�t	|j|j�z�|jj|�|r�|j�r|jj�|jj|j|j�|j
r,|j
}g|_d|_|j|�yyy)Nr)
r	r��	eraseLine�cursorBackward�lenr�r�r�rr�r�r��_deliverBuffer)rrrhri�	oldBuffers     rrzManhole.addOutput�s���"�7�5�f�5����M�M�#�#�%��M�M�(�(��T�_�_�)=��D�G�G�D�G�G�DT�@U�)U�V��
�
���D�!���!�!�#��
�
�&�&�(��M�M��������� 0�1���� �O�O�	�"$���'(��$��#�#�I�.��
rc��|jj|�}t|�|_|j	�r|j
j
�|j
j|j|j�yr)	ryrF�boolr�r�r�r�rr�)rrCrEs   r�lineReceivedzManhole.lineReceiveds^�����$�$�T�*���t�*��������M�M�"�"�$��
�
���D�G�G�D�G�G�,�-rr)r%r&r'r(rvrrxrzr}rr�r�rr�rrrrrrr�s<����I�.�
<�
.���'�B�/�*.rrrc�R�eZdZdZdddddddd	�Zd
Zd�Zd�Zdd�Zd�Z	e
ek(re	Zy
y
)�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)�
identifier�keyword�	parameter�variable�string�number�opsc��g|_yr)�writtenrs rrzVT102Writer.__init__$s	����rc�>�|jj|d�}|S)Nr)�typeToColor�get)r�type�rs   r�colorzVT102Writer.color's����� � ��s�+���rNc��|rx|dk7rr|j|�}|r|jj|�|jj|�|r&|jj|j�yyyy)N�
)r�r�r@�normalColor)r�tokenr��cs    rrzVT102Writer.write+sg���U�e�^��
�
�4� �A�����#�#�A�&��L�L����&�����#�#�D�$4�$4�5��$�5rc�|�dj|j�}|jd�j�dS)Nrr>���)r"r��strip�
splitlines)r�ss  r�	__bytes__zVT102Writer.__bytes__4s0���H�H�T�\�\�"���w�w�u�~�(�(�*�2�.�.rr)
r%r&r'r(r�r�rr�rr��bytes�str�__str__rrrr�r�sS���"�� �!�����K��K���6�/�
��|���rr�c�2�t|t�s|jd�}t�}t	|j
�j}t|�}tj|j�D]}|\}}}}}	||||||	��t|�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?)
rWr��encoder�r
r�
printtokenr�tokenize�readline)
rDr��pr�r��	tokenTyper��start�endrCs
          r�lastColorizedLiner�=s����f�e�$����w�'���
�A��Q�W�W��(�(�A����A��"�"�1�:�:�.�/��05�-��F�E�3��	�)�V�U�C��.�/���8�Orc��eZdZdZd�Zd�Zy)�ColoredManholez<
    A REPL which syntax colors input as users type it.
    c��dj|jj�dzdj|j�zS)z�
        Return a string containing the currently entered source.

        This is only the code which will be considered for execution
        next.
        r>r)r"ryr<r�rs r�	getSourcezColoredManhole.getSourceYs6���z�z�$�*�*�1�1�2�U�:�S�X�X�d�o�o�=V�V�Vrc��|jdk(r'|jj|j|�n'|g|j|j|jdz|xjdz
c_|ry|dk(r|jj|�y|j
�}	t|�}|jj�|jjt|j�t|j|j�zdz
�|jj|j|j|z�t|j�|jz
}|r|jj|�yy#tj$r|jj|�YywxYw)N�insertrT� )�moder�r�r�r�rr�r�r�r�r�r�r�r��
TokenError)r�ch�moreCharactersComingrD�coloredLine�ns      r�characterReceivedz ColoredManhole.characterReceivedbsk���9�9�� ��O�O�"�"�4�#7�#7��<�PR�t�D�O�O�D�0�0�4�3G�3G�!�3K�L�����!���
�
��:��M�M����#�����!��	0�+�F�3�K�
�M�M�#�#�%��M�M�(�(��D�O�O�$�s�4�7�7�4�7�7�+;�'<�<�q�@�
�

�M�M��������� 0�;� >�?��D�O�O�$�t�';�';�;�A���
�
�,�,�Q�/����"�"�	$��M�M����#�	$�s�(F�.G�GN)r%r&r'r(r�r�rrrr�r�Ts���W�&0rr�)$r(r1r9r��ior�	tracebackr�typesr�typingr�
twisted.conchr�twisted.internetr�twisted.python.compatr	�twisted.python.htmlizerr
�twisted.python.monkeyrr
r2r,r|r~r�r�r�r�rtrrr�r�r�rrr�<module>r�s���
	��
���&���"�"�2�0�/�#�#�0o.��4�4�o.�d
��	����	��	��	��[.�h�'�'�[.�|+�+�\�.40�W�40r

Zerion Mini Shell 1.0