HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/conch/insults/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/conch/insults/__pycache__/helper.cpython-312.pyc
�

Ϫ�f�?�	��dZddlZddlZddlmZddlmZddlmZddl	m
Z
mZmZddl
mZddlmZdd	lmZdd
lmZmZdZdZed
�\	ZZZZZZZZ Z!Gd�dejD�Z#e#Z$eedddd�ddd�eejJ�Gd�dejL��Z'Gd�de(�Z)Gd�de'�Z*gd�Z+y)z<
Partial in-memory terminal emulator

@author: Jp Calderone
�N)�implementer)�Version)�insults)�defer�protocol�reactor)�Logger)�_textattributes)�	iterbytes)�
deprecated�deprecatedModuleAttribute��(�	c�t�eZdZdZdZejddddeedfd�Z	e
edddd��d	��Zd
�Z
y)�_FormattingStatez�
    Represents the formatting state/attributes of a single character.

    Character set, intensity, underlinedness, blinkitude, video
    reversal, as well as foreground and background colors made up a
    character's attributes.
    ��charset�bold�	underline�blink�reverseVideo�
foreground�
background�_subtractingFc	�t�||_||_||_||_||_||_||_||_y�Nr)	�selfrrrrrrrrs	         �>/usr/lib/python3/dist-packages/twisted/conch/insults/helper.py�__init__z_FormattingState.__init__3s>�������	�"�����
�(���$���$���(����Twisted�
�rc�L�|j�\}}|j||�S)a<
        Add a character attribute to a copy of this formatting state.

        @param kw: An optional attribute name and value can be provided with
            a keyword argument.

        @return: A formatting state instance with the new attribute.

        @see: L{DefaultFormattingState._withAttribute}.
        )�popitem�_withAttribute)r�kw�k�vs    r�wantOnez_FormattingState.wantOneGs&���z�z�|���1��"�"�1�a�(�(r!c��g}|jr|jd�|jr|jtj�|j
r|jtj�|jr|jtj�|jr|jtj�|jtk7r"|jt|jz�|jtk7r"|jt |jz�|r%ddj#t%t&|��zdzSy)Nrz[�;�m�)r�appendrr�BOLDr�	UNDERLINEr�BLINKr�
REVERSE_VIDEOr�WHITE�
FOREGROUNDr�BLACK�
BACKGROUND�join�map�str)r�attrss  r�toVT102z_FormattingState.toVT102Vs���������L�L��O��9�9��L�L����&��>�>��L�L��*�*�+��:�:��L�L����'�����L�L��.�.�/��?�?�e�#��L�L��d�o�o�5�6��?�?�e�#��L�L��d�o�o�5�6���S�X�X�c�#�u�o�6�6��<�<�r!N)�__name__�
__module__�__qualname__�__doc__�compareAttributesr�G0r5r7r rrr+r=�r!rrrs[���	���
�
�
�������)�(��	�2�q�!�,�-�)�.�)�r!rr"r#r$z=Use twisted.conch.insults.text.assembleFormattedText instead.ztwisted.conch.insults.helper�CharacterAttributec���eZdZdZdD] ZedzZej
d�Zee��"dZ	dZ
dZdZd	Z
e�Ze�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�ZdAd�ZdAd�ZdAd�ZdAd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd �Z(d!�Z)d"�Z*d#�Z+d$�Z,d%�Z-d&�Z.d'�Z/d(�Z0d)�Z1d*�Z2d+�Z3d,�Z4d-�Z5d.�Z6dAd/�Z7dAd0�Z8dAd1�Z9d2�Z:d3�Z;d4�Z<d5�Z=d6�Z>d7�Z?d8�Z@d9�ZAd:�ZBd;�ZCd<�ZDdBd=�ZEd>�ZFd?�ZGy@)C�TerminalBufferz)
    An in-memory terminal emulator.
    )sUP_ARROWs
DOWN_ARROWsRIGHT_ARROWs
LEFT_ARROWsHOMEsINSERTsDELETEsENDsPGUPsPGDNsF1sF2sF3sF4sF5sF6sF7sF8sF9sF10sF11sF12s = object()�ascii�	��P�� c�&�|j||Sr)�lines)r�x�ys   r�getCharacterzTerminalBuffer.getCharacter�s���z�z�!�}�Q��r!c�$�|j�yr)�reset�rs r�connectionMadezTerminalBuffer.connectionMade�s���
�
�r!c�f�t|jdd��D]}|j|��y)z�
        Add the given printable bytes to the terminal.

        Line feeds in L{bytes} will be replaced with carriage return / line
        feed pairs.
        �
s
N)r�replace�insertAtCursor)r�data�bs   r�writezTerminalBuffer.write�s1���4�<�<��w�7�8�	#�A�����"�	#r!c�B�t|jfi|j��Sr)r�
activeCharset�graphicRenditionrUs r�_currentFormattingStatez&TerminalBuffer._currentFormattingState�s���� 2� 2�L�d�6K�6K�L�Lr!c��|dk(rd|_y|dk(r|j�y|tjj	d�v�r|j|j
k\r|j
�||j�f}|jjtjj�rY|g|j|j|j|j|j|jj�n&||j|j|j<|xjdz
c_yy)a�
        Add one byte to the terminal at the cursor and make consequent state
        updates.

        If b is a carriage return, move the cursor to the beginning of the
        current row.

        If b is a line feed, move the cursor to the next row or scroll down if
        the cursor is already in the last row.

        Otherwise, if b is printable, put it at the cursor position (inserting
        or overwriting as dictated by the current mode) and move the cursor.
        �
rrXrHr$N)rP�_scrollDown�string�	printable�encode�width�nextLinera�modes�getr�IRMrOrQ�pop)rr\�chs   rrZzTerminalBuffer.insertAtCursor�s���
��:��D�F�
�%�Z�����
�&�"�"�)�)�'�2�
2��v�v����#��
�
���T�1�1�3�4�B��z�z�~�~�g�m�m�/�/�0�79�d��
�
�4�6�6�"�4�6�6�D�F�F�3��
�
�4�6�6�"�&�&�(�-/��
�
�4�6�6�"�4�6�6�*��F�F�a�K�F�3r!c�r�t|�D�cgc]}|j|j�f�� c}Scc}wr)�range�voidra)rrh�is   r�
_emptyLinezTerminalBuffer._emptyLine�s,��EJ�5�\�R�����D�8�8�:�;�R�R��Rs�#4c��|xjdz
c_|j|jk\rW|xjdzc_|jd=|jj|j	|j
��yy)Nr$r)rQ�heightrOr0rsrhrUs rrdzTerminalBuffer._scrollDown�s[�����!����6�6�T�[�[� ��F�F�a�K�F��
�
�1�
��J�J���d�o�o�d�j�j�9�:�!r!c���|xjdzc_|jdkrJd|_|jd=|jjd|j|j��yy)Nr$r���)rQrO�insertrsrhrUs r�	_scrollUpzTerminalBuffer._scrollUp�sR�����!����6�6�A�:��D�F��
�
�2���J�J���a�������!<�=�r!c�@�td|j|z
�|_y�Nr)�maxrQ�r�ns  r�cursorUpzTerminalBuffer.cursorUp�����Q�����
�#��r!c�Z�t|jdz
|j|z�|_y�Nr$)�minrurQr}s  r�
cursorDownzTerminalBuffer.cursorDown�s ���T�[�[�1�_�d�f�f�q�j�1��r!c�@�td|j|z
�|_yr{)r|rPr}s  r�cursorBackwardzTerminalBuffer.cursorBackward�r�r!c�T�t|j|j|z�|_yr)r�rhrPr}s  r�
cursorForwardzTerminalBuffer.cursorForward�s���T�Z�Z����!��,��r!c� �||_||_yr�rPrQ)r�column�lines   r�cursorPositionzTerminalBuffer.cursorPosition�s�������r!c�p�|jj|_|jj|_yr)�homerPrQrUs r�
cursorHomezTerminalBuffer.cursorHome�s ���������������r!c�$�|j�yr)rdrUs r�indexzTerminalBuffer.index�s�����r!c�$�|j�yr)ryrUs r�reverseIndexzTerminalBuffer.reverseIndex�s�����r!c�2�d|_|j�y)zW
        Update the cursor position attributes and scroll down if appropriate.
        rN)rPrdrUs rrizTerminalBuffer.nextLine�s��������r!c�>�|j|jf|_yr)rPrQ�_savedCursorrUs r�
saveCursorzTerminalBuffer.saveCursors��!�V�V�T�V�V�,��r!c�:�|j\|_|_|`yr)r�rPrQrUs r�
restoreCursorzTerminalBuffer.restoreCursor	s���*�*�������r!c�0�|D]}d|j|<�y)NT)rj�rrjr.s   r�setModeszTerminalBuffer.setModes
s���	!�A� �D�J�J�q�M�	!r!c�L�|D]}	|j|=�y#t$rY�wxYwr)rj�KeyErrorr�s   r�
resetModeszTerminalBuffer.resetModess5���	�A�
��J�J�q�M�	���
��
���
�	#�#c�0�|D]}d|j|<�y)aH
        Enable the given modes.

        Track which modes have been enabled so that the implementations of
        other L{insults.ITerminalTransport} methods can be properly implemented
        to respect these settings.

        @see: L{resetPrivateModes}
        @see: L{insults.ITerminalTransport.setPrivateModes}
        TN)�privateModesr�s   r�setPrivateModeszTerminalBuffer.setPrivateModess#���	(�A�#'�D���a� �	(r!c�L�|D]}	|j|=�y#t$rY�wxYw)z�
        Disable the given modes.

        @see: L{setPrivateModes}
        @see: L{insults.ITerminalTransport.resetPrivateModes}
        N)r�r�r�s   r�resetPrivateModesz TerminalBuffer.resetPrivateModes&s:���	�A�
��%�%�a�(�	���
��
�r�c��d|_y)N�app��
keypadModerUs r�applicationKeypadModez$TerminalBuffer.applicationKeypadMode3�	����r!c��d|_y)N�numr�rUs r�numericKeypadModez TerminalBuffer.numericKeypadMode6r�r!c�"�||j|<yr)�charsets)r�charSet�whichs   r�selectCharacterSetz!TerminalBuffer.selectCharacterSet9s��&��
�
�e�r!c�.�tj|_yr)rrCr_rUs r�shiftInzTerminalBuffer.shiftIn<���$�Z�Z��r!c�.�tj|_yr)r�G1r_rUs r�shiftOutzTerminalBuffer.shiftOut?r�r!c������j�tj�_�j����fd�}|�_y)Nc�(���|��`��_yr�rZr_�r\�f�oldActiveCharsetrs ���rrZz3TerminalBuffer.singleShift2.<locals>.insertAtCursorG����
�a�D��#�!1�D�r!)r_r�G2rZ�rrZr�r�s` @@r�singleShift2zTerminalBuffer.singleShift2B�5����-�-��$�Z�Z�������	2�
-��r!c������j�tj�_�j����fd�}|�_y)Nc�(���|��`��_yrr�r�s ���rrZz3TerminalBuffer.singleShift3.<locals>.insertAtCursorSr�r!)r_r�G3rZr�s` @@r�singleShift3zTerminalBuffer.singleShift3Nr�r!c��|D�]K}|tjk(rddddttd�|_�.|tj
k(rd|jd<�Q|tjk(rd|jd<�t|tjk(rd|jd<��|tjk(rd|jd<��	t|�}t|cxkrttzkrnn|tz
|jd<��t|cxkrttzkrnn|tz
|jd	<��/|jjd
|����Ny#t$r!|jjd
|��Y��ywxYw)NF�rrrrrrTrrrrrrz-Unknown graphic rendition attribute: {attr!r})�attr)r�NORMALr5r7r`r1r2r3r4�intr6�N_COLORSr8�_log�error�
ValueError)r�
attributes�ar*s    r�selectGraphicRenditionz%TerminalBuffer.selectGraphicRenditionZsQ���!	�A��G�N�N�"�!�!&�"�$)�"'�"'�
)��%��g�l�l�"�04��%�%�f�-��g�'�'�'�59��%�%�k�2��g�m�m�#�15��%�%�g�.��g�+�+�+�8<��%�%�n�5���A��A�"�Q�?�*�x�*?�?�>?�*�n��-�-�l�;�#�q�A�J��,A�A�>?�*�n��-�-�l�;��	�	���K�RS�(��?!	��*"���I�I�O�O�G�a�$���s�>E�&E=�<E=c�h�|j|j�|j|j<yr)rsrhrOrQrUs r�	eraseLinezTerminalBuffer.eraseLine~s!��!�_�_�T�Z�Z�8��
�
�4�6�6�r!c��|j|jz
}|j|�|j|j|jdyr)rhrPrsrOrQ)rrhs  r�eraseToLineEndzTerminalBuffer.eraseToLineEnd�s:���
�
�T�V�V�#��'+���u�'=��
�
�4�6�6��4�6�6�8�$r!c��|j|jdz�|j|jd|jdzyr�)rsrPrOrQrUs r�eraseToLineBeginningz#TerminalBuffer.eraseToLineBeginning�s4��+/�?�?�4�6�6�A�:�+F��
�
�4�6�6��<�T�V�V�a�Z�(r!c��t|j�D�cgc]}|j|j���c}|_ycc}wr)rprursrhrO�rrrs  r�eraseDisplayzTerminalBuffer.eraseDisplay�s-��;@����;M�N�a�d�o�o�d�j�j�1�N��
��Ns�"Ac��|j�|j|jz
dz
}t|�D�cgc]}|j	|j
���c}|j|jdzdycc}wr�)r�rurQrprsrhrO)rrurrs   r�eraseToDisplayEndz TerminalBuffer.eraseToDisplayEnd�s\���������t�v�v�%��)��IN�v��#W�A�D�O�O�D�J�J�$?�#W��
�
�4�6�6�A�:�<� ��#Ws�"A:c���|j�t|j�D�cgc]}|j|j���c}|j
d|jycc}wr)r�rprQrsrhrOr�s  r�eraseToDisplayBeginningz&TerminalBuffer.eraseToDisplayBeginning�sE���!�!�#�EJ�4�6�6�]�S������
�
� ;�S��
�
�8�T�V�V���Ss�"A%c��|j|j|j|j|z�=|j|jj|j	t|j|jz
|���yr)rOrQrP�extendrsr�rhr}s  r�deleteCharacterzTerminalBuffer.deleteCharacter�s`���J�J�t�v�v��t�v�v�����
�2�3��
�
�4�6�6��!�!�$�/�/�#�d�j�j�4�6�6�6I�1�2M�"N�Or!c���t|�D�cgc]}|j|j���c}|j|j|j|j|j
d�=ycc}wr)rprsrhrOrQru�rr~rrs   r�
insertLinezTerminalBuffer.insertLine�sO��LQ�RS�H�&U�q�t���t�z�z�'B�&U��
�
�4�6�6�D�F�F�#��J�J�t�{�{�}�%��'Vs�"A.c���|j|j|j|z�=|jjt|�D�cgc]}|j	|j
���c}�ycc}wr)rOrQr�rprsrhr�s   r�
deleteLinezTerminalBuffer.deleteLine�sP���J�J�t�v�v�����
�*�+��
�
����a��I�1�4�?�?�4�:�:�6�I�J��Is�	"A3c�2�|j|jfSrr�rUs r�reportCursorPositionz#TerminalBuffer.reportCursorPosition�s���������r!c�z�tjdd�|_dx|_|_i|_i|_|jtjjtjjg�d|_
tj|_ddddttd�|_tjtj tj"tj tj$tj&tj(tj*i|_|j/�y)Nrr�Fr�)r�Vectorr�rPrQrjr�r��	AUTO_WRAP�CURSOR_MODE�
numericKeypadrCr_r5r7r`�CS_USr�r��CS_ALTERNATEr��CS_ALTERNATE_SPECIALr�r�rUs rrTzTerminalBuffer.reset�s����N�N�1�a�(��	���������
�������
�
!�
!�
+�
+�W�-A�-A�-M�-M�N�	
�#���$�Z�Z������!���
!
���
�J�J��
�
��J�J��
�
��J�J��,�,��J�J��4�4�	
��
�	
���r!c�.�tdt|��y)NzCould not handle)�print�repr)r�bufs  r�unhandledControlSequencez'TerminalBuffer.unhandledControlSequence�s��
� �$�s�)�,r!c�8�g}|jD]y}g}d}|D]K\}}||jur|j|�t|�}�1|j|j��M|jdj|d|���{dj|�S)Nrr!rX)rOrqr0�len�fillr9)rrO�Lr��lengthrnr�s       r�	__bytes__zTerminalBuffer.__bytes__�s��������		1�A��C��F��
*���D��T�Y�Y�&��J�J�r�N� ��X�F��J�J�t�y�y�)�
*�
�L�L����#�g�v�,�/�0�		1��z�z�%� � r!c��td��)Nz%Unimplemented: TerminalBuffer.getHost��NotImplementedErrorrUs r�getHostzTerminalBuffer.getHost����!�"I�J�Jr!c��td��)Nz%Unimplemented: TerminalBuffer.getPeerrrUs r�getPeerzTerminalBuffer.getPeer�rr!c��td��)Nz,Unimplemented: TerminalBuffer.loseConnectionrrUs r�loseConnectionzTerminalBuffer.loseConnection�s��!�"P�Q�Qr!c��td��)Nz+Unimplemented: TerminalBuffer.writeSequencer�rr[s  r�
writeSequencezTerminalBuffer.writeSequence�s��!�"O�P�Pr!c��td��)Nz5Unimplemented: TerminalBuffer.horizontalTabulationSetrrUs r�horizontalTabulationSetz&TerminalBuffer.horizontalTabulationSet�s��!�C�
�	
r!c��td��)Nz-Unimplemented: TerminalBuffer.tabulationClearrrUs r�tabulationClearzTerminalBuffer.tabulationClear����!�"Q�R�Rr!c��td��)Nz0Unimplemented: TerminalBuffer.tabulationClearAllrrUs r�tabulationClearAllz!TerminalBuffer.tabulationClearAll�s��!�"T�U�Ur!c��td��)Nz.Unimplemented: TerminalBuffer.doubleHeightLiner)r�tops  r�doubleHeightLinezTerminalBuffer.doubleHeightLine�s��!�"R�S�Sr!c��td��)Nz-Unimplemented: TerminalBuffer.singleWidthLinerrUs r�singleWidthLinezTerminalBuffer.singleWidthLine�rr!c��td��)Nz-Unimplemented: TerminalBuffer.doubleWidthLinerrUs r�doubleWidthLinezTerminalBuffer.doubleWidthLine�rr!N)r$)T)Hr>r?r@rA�keyID�	execBytes�decode�execStr�exec�TAB�	BACKSPACErhrur��objectrqr	r�rRrVr]rarZrsrdryrr�r�r�r�r�r�r�rir�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rTr�r�rrrrr
rrrrrrDr!rrGrGxs�������0�N�*�	��"�"�7�+���W�
�5�8�C��I��E�
�F��D��8�D��8�D� ��#�M��:S�;�>�$�2�$�-������-��!��(�� � �'�(�(�
-�
-�"�H9�>�G�O�X�
T�P�&�K� ��4-�!�K�K�R�Q�
�S�V�T�S�Sr!rGc��eZdZy)�ExpectationTimeoutN)r>r?r@rDr!rr#r#�s��r!r#c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zde	fd�Z
y)	�ExpectableBufferrc�<�tj|�g|_yr)rGrV�
_expectingrUs rrVzExpectableBuffer.connectionMades���%�%�d�+���r!c�P�tj||�|j�yr)rGr]�_checkExpectedr
s  rr]zExpectableBuffer.writes�����T�4�(����r!c�<�tj|�d|_yr{)rGr��_markrUs rr�zExpectableBuffer.cursorHomes���!�!�$�'���
r!c�V�|jt��|j�yr)�errbackr#r))r�ds  r�_timeoutExpectedz!ExpectableBuffer._timeoutExpecteds��	�	�	�$�&�'����r!c���|j�|jd}|jr�|jd\}}}|r|j�s|jd=�?|j	|�D]i}|r|j�|jd=|xj|j
�z
c_||j
�d}|j|�ny|jr��yyr{)r�r+r'�active�finditer�cancel�end�callback)r�s�expr�timer�deferred�matchs      rr)zExpectableBuffer._checkExpecteds����N�N��T�Z�Z�\�*���o�o�$(�O�O�A�$6�!�D�%���U�\�\�^��O�O�A�&�����q�)�	
����L�L�N��O�O�A�&��
�
�e�i�i�k�)�
��e�i�i�k�m�$���!�!�%�(��	
���o�or!Nc���tj�}d}|r|j||j|�}|jjt
j|�||f�|j�|Sr)	r�Deferred�	callLaterr/r'r0�re�compiler))r�
expression�timeout�	schedulerr.r8s      r�expectzExpectableBuffer.expect"sc���N�N�������'�'���1F�1F��J�E�������
�
�:� 6��q�A�B������r!)r>r?r@r+rVr]r�r/r)rrCrDr!rr%r%�s,��
�E������$*.��r!r%)rErGr%),rAr>re�zope.interfacer�incrementalr�twisted.conch.insultsr�twisted.internetrrr�twisted.loggerr	�twisted.pythonr
�twisted.python.compatr�twisted.python.deprecaterr
r6r8rpr7�RED�GREEN�YELLOW�BLUE�MAGENTA�CYANr5r��_FormattingStateMixinrrE�ITerminalTransport�ProtocolrG�	Exceptionr#r%�__all__rDr!r�<module>rWs���
�
�
�&��)�5�5�!�*�+�J�
�
�
�
�BG��(�?��s�E�6�4��$��x�K��<�<�K�\&����I�r�1�a� �C�"��	�
�W�
'�
'�(�}S�X�&�&�}S�)�}S�@	��	�,�~�,�^G�r!