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: //usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/test_manhole.cpython-38.pyc
U

��W[�4�@sdZddlZddlmZddlmZmZddlmZddl	m
Z
mZmZm
Z
mZddlmZddlmZd	d
�Ze�ZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�d�ZGdd�de
eje�ZGdd�deeje�ZGdd�deeje�ZGdd�dej�ZdS)z%
Tests for L{twisted.conch.manhole}.
�N)�unittest)�error�defer)�StringTransport)�_TelnetMixin�	_SSHMixin�_StdioMixin�stdio�ssh)�manhole)�insultscCs.zddWnt��ddYSXdS)z�
    Return the string used by Python as the name for code objects which are
    compiled from interactive input or at the top-level of modules.
    �r����N)�	traceback�
extract_stack�rr�A/usr/lib/python3/dist-packages/twisted/conch/test/test_manhole.py�determineDefaultFunctionNamesrc@seZdZdZdd�ZdS)�ManholeInterpreterTestsz2
    Tests for L{manhole.ManholeInterpreter}.
    cCs2t�d�}|j�ddg�|��|�|j�dS)zR
        L{ManholeInterpreter.resetBuffer} should empty the input buffer.
        N�1�2)rZManholeInterpreter�buffer�extendZresetBuffer�assertFalse)�self�interpreterrrr�test_resetBuffer*s
z(ManholeInterpreterTests.test_resetBufferN)�__name__�
__module__�__qualname__�__doc__rrrrrr&src@seZdZdZdd�ZdS)�ManholeProtocolTestsz'
    Tests for L{manhole.Manhole}.
    cCsPt�}t�tj�}|�|�|j}|j}|j�	ddg�|�
�|�|j�dS)zn
        L{manhole.Manhole.handle_INT} should cause the interpreter input buffer
        to be reset.
        rrN)rrZServerProtocolrZManholeZmakeConnectionZterminalProtocolrrrZ
handle_INTr)rZ	transportZterminalZprotocolrrrr�%test_interruptResetsInterpreterBuffer9s
z:ManholeProtocolTests.test_interruptResetsInterpreterBufferN)rrr r!r#rrrrr"5sr"c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�WriterTestscCst�d�dS)z&
        Colorize an integer.
        rN�r�lastColorizedLine�rrrr�test_IntegerJszWriterTests.test_IntegercCst�d�dS)z7
        Colorize an integer in double quotes.
        z"1"Nr%r'rrr�test_DoubleQuoteStringQsz"WriterTests.test_DoubleQuoteStringcCst�d�dS)z7
        Colorize an integer in single quotes.
        z'1'Nr%r'rrr�test_SingleQuoteStringXsz"WriterTests.test_SingleQuoteStringcCst�d�dS)z7
        Colorize an integer in triple quotes.
        z'''1'''Nr%r'rrr�test_TripleSingleQuotedString_sz)WriterTests.test_TripleSingleQuotedStringcCst�d�dS)zB
        Colorize an integer in triple and double quotes.
        z"""1"""Nr%r'rrr�test_TripleDoubleQuotedStringfsz)WriterTests.test_TripleDoubleQuotedStringcCst�d�dS)z1
        Colorize a function definition.
        z
def foo():Nr%r'rrr�test_FunctionDefinitionmsz#WriterTests.test_FunctionDefinitioncCst�d�dS)z.
        Colorize a class definition.
        z
class foo:Nr%r'rrr�test_ClassDefinitiontsz WriterTests.test_ClassDefinitioncCst�d�}|�t|t��dS)z,
        Colorize a Unicode string.
        �иN�rr&Z
assertTrue�
isinstance�bytes�r�resrrr�test_unicode{s
zWriterTests.test_unicodecCst�d�}|�t|t��dS)z/
        Colorize a UTF-8 byte string.
        �иNr0r3rrr�
test_bytes�s
zWriterTests.test_bytescCs|�t�d�t�d��dS)zT
        The output of UTF-8 bytestrings and Unicode strings are identical.
        r6r/N)�assertEqualrr&r'rrr�test_identicalOutput�s�z WriterTests.test_identicalOutputN)
rrr r(r)r*r+r,r-r.r5r7r9rrrrr$Isr$c@s�eZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zejdd��Zejdd��Zdd�Zdd�Zejdd��ZdS)�ManholeLoopbackMixincCs
t�|�S)N)rZwaitForDeferred�r�drrr�wfd�szManholeLoopbackMixin.wfdcs,�j�d�}��d��fdd�}|�|�S)z-
        Evaluate simple expression.
        �dones
1 + 1
donecs��dddg�dS)N�	>>> 1 + 1�2�>>> done��
_assertBuffer��ignr'rr�finished�s��z<ManholeLoopbackMixin.test_SimpleExpression.<locals>.finished��recvlineClient�expect�
_testwrite�addCallback�rZdonerFrr'r�test_SimpleExpression�s�z*ManholeLoopbackMixin.test_SimpleExpressioncs,�j�d�}��d��fdd�}|�|�S)z>
        Evaluate line continuation in triple quotes.
        r>s'''
'''
donecs��ddddg�dS)Ns>>> '''s... '''s'\n'rArBrDr'rrrF�s��zGManholeLoopbackMixin.test_TripleQuoteLineContinuation.<locals>.finishedrGrLrr'r� test_TripleQuoteLineContinuation�s�z5ManholeLoopbackMixin.test_TripleQuoteLineContinuationcs,�j�d�}��d��fdd�}|�|�S)z/
        Evaluate function definition.
        r>s'def foo(bar):
	print(bar)

foo(42)
donecs��ddddddg�dS)Ns>>> def foo(bar):s...     print(bar)�... s>>> foo(42)s42rArBrDr'rrrF�s��z>ManholeLoopbackMixin.test_FunctionDefinition.<locals>.finishedrGrLrr'rr-�s�	z,ManholeLoopbackMixin.test_FunctionDefinitioncs,�j�d�}��d��fdd�}|�|�S)z,
        Evaluate class definition.
        r>sEclass Foo:
	def bar(self):
		print('Hello, world!')

Foo().bar()
donec	s��dddddddg�dS)Ns>>> class Foo:s...     def bar(self):s"...         print('Hello, world!')rOs>>> Foo().bar()s
Hello, world!rArBrDr'rrrF�s��z;ManholeLoopbackMixin.test_ClassDefinition.<locals>.finishedrGrLrr'rr.�s�
z)ManholeLoopbackMixin.test_ClassDefinitioncs,�j�d�}��d��fdd�}|�|�S)z0
        Evaluate raising an exception.
        r>s#raise Exception('foo bar baz')
donecs"��dddt�d�ddg�dS)Ns">>> raise Exception('foo bar baz')s"Traceback (most recent call last):s  File "<console>", line 1, in zutf-8sException: foo bar bazrA)rC�defaultFunctionName�encoderDr'rrrF�s���z5ManholeLoopbackMixin.test_Exception.<locals>.finishedrGrLrr'r�test_Exception�s�	z#ManholeLoopbackMixin.test_Exceptioncs6�j�d�}��dtjd��fdd�}|�|�S)z4
        Evaluate interrupting with CTRL-C.
        r>�cancelled linecs��dddg�dS)N�>>> cancelled line�KeyboardInterruptrArBrDr'rrrFs��z4ManholeLoopbackMixin.test_ControlC.<locals>.finished)rHrIrJr�CTRL_CrKrLrr'r�
test_ControlC
s��z"ManholeLoopbackMixin.test_ControlCcsF�j�d�}��d��fdd�}|�|��fdd�}|�|�|S)z�
        Sending ^C to Manhole while in a state where more input is required to
        complete a statement should discard the entire ongoing statement and
        reset the input prompt to the non-continuation prompt.
        sthingss(
thingscs*��ddg��j�d�}��tj�|S)N�>>> (�
... things�>>> )rCrHrIrJrrV)�ignoredZinterruptedr'rr�gotContinuation's��zNManholeLoopbackMixin.test_interruptDuringContinuation.<locals>.gotContinuationcs��ddddg�dS)NrXrYrUrZrB)r[r'rr�gotInterruption0s��zNManholeLoopbackMixin.test_interruptDuringContinuation.<locals>.gotInterruptionrG)rZ
continuingr\r]rr'r� test_interruptDuringContinuations


z5ManholeLoopbackMixin.test_interruptDuringContinuationcs>��d��j�d�}�fdd�}�fdd�}|�|��|�S)z2
        Evaluate cancelling with CTRL-\.
        rScs.��dg���tj��jj}��|tj�S)NrT)	rCrJrZCTRL_BACKSLASHrH�onDisconnection�
assertFailurer�ConnectionDone)rEr<r'rr�gotPartialLineAs�zBManholeLoopbackMixin.test_ControlBackslash.<locals>.gotPartialLinecs��dg�dS)N�rBrDr'rr�gotClearedLineIs�zBManholeLoopbackMixin.test_ControlBackslash.<locals>.gotClearedLine�rJrHrIrK)rZpartialLinerbrdrr'r�test_ControlBackslash:s

�z*ManholeLoopbackMixin.test_ControlBackslashccs�|�d�|j�d�V|�dg�|�tjd�|j�d�V|�dg�|�d�|j�d�V|�tj�|jj}|�|tj	�VdS)	z~
        A CTRL+D in the middle of a line doesn't close a connection,
        but at the beginning of a line it does.
        s1 + 1�\+ 1r?� + 1�
>>> 1 + 1 + 1�
s3
>>> N)
rJrHrIrCrZCTRL_Dr_r`rrar;rrr�
test_controlDQs

z"ManholeLoopbackMixin.test_controlDccsT|�d�|j�d�V|�ddg�|�tjd�|j�d�V|�dg�dS)	a
        CTRL+L is generally used as a redraw-screen command in terminal
        applications.  Manhole doesn't currently respect this usage of it,
        but it should at least do something reasonable in response to this
        event (rather than, say, eating your face).
        s
1 + 1rgrZr?rhs1 \+ 1 \+ 1riN)rJrHrIrCrZCTRL_Lr'rrr�
test_ControlLgs

z"ManholeLoopbackMixin.test_ControlLcs,��d��j�d�}�fdd�}|�|�S)zl
        CTRL-A can be used as HOME - returning cursor to beginning of
        current line buffer.
        srint "hello"p�
print "hello"cs��dg�dS�Ns>>> print "hello"rB��ignorer'rr�cb�sz.ManholeLoopbackMixin.test_controlA.<locals>.cbre�rr<rqrr'r�
test_controlAzs
z"ManholeLoopbackMixin.test_controlAcs,��d��j�d�}�fdd�}|�|�S)zc
        CTRL-E can be used as END - setting cursor to end of current
        line buffer.
        srint "hellop"rmcs��dg�dSrnrBror'rrrq�sz.ManholeLoopbackMixin.test_controlE.<locals>.cbrerrrr'r�
test_controlE�s
z"ManholeLoopbackMixin.test_controlEc	csZ|�d�|j�d�V|�d�|j�d�V|j�d�V|�ddddd	d
dg�dS)z�
        When a deferred is returned to the manhole REPL, it is displayed with
        a sequence number, and when the deferred fires, the result is printed.
        sCfrom twisted.internet import defer, reactor
d = defer.Deferred()
d
s
<Deferred #0>s.c = reactor.callLater(0.1, d.callback, 'Hi!')
rZs#Deferred #0 called back: 'Hi!'
>>> s/>>> from twisted.internet import defer, reactors>>> d = defer.Deferred()s>>> ds1>>> c = reactor.callLater(0.1, d.callback, 'Hi!')sDeferred #0 called back: 'Hi!'N)rJrHrIrCr'rrr�
test_deferred�s*�����z"ManholeLoopbackMixin.test_deferredN)rrr rZColoredManhole�serverProtocolr=rMrNr-r.rRrWr^rfrZinlineCallbacksrkrlrsrtrurrrrr:�s$

r:c@seZdZdZdS)�ManholeLoopbackTelnetTestsz,
    Test manhole loopback over Telnet.
    N)rrr r!rrrrrw�srwc@seZdZdZedkrdZdS)�ManholeLoopbackSSHTestsz)
    Test manhole loopback over SSH.
    Nz!cryptography requirements missing)rrr r!r
�skiprrrrrx�srxc@s$eZdZdZedkrdZnejZdS)�ManholeLoopbackStdioTestsz1
    Test manhole loopback over standard IO.
    N�Terminal requirements missing)rrr r!r	ryZConsoleManholervrrrrrz�srzc@s$eZdZdZedkrdZdd�ZdS)�ManholeMainTestsz=
    Test the I{main} method from the I{manhole} module.
    Nr{cCs*|jttjdgd�}|�d|jd�dS)z�
        Will raise an exception when called with an argument which is a
        dotted patch which can not be imported..
        z
no-such-class)�argvzEmpty module namerN)ZassertRaises�
ValueErrorr	�mainr8�args)rZ	exceptionrrr�test_mainClassNotFound�s�z'ManholeMainTests.test_mainClassNotFound)rrr r!r	ryr�rrrrr|�sr|)r!rZ
twisted.trialrZtwisted.internetrrZtwisted.test.proto_helpersrZ twisted.conch.test.test_recvlinerrrr	r
Z
twisted.conchrZtwisted.conch.insultsrrrPZTestCaserr"r$r:rwrxrzr|rrrr�<module>s2K�	�
�