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/mail/test/__pycache__/test_pop3client.cpython-38.pyc
U


W[�U�@s,ddlZddlZddlmZddlmZmZmZmZm	Z	ddl
mZddl
m
Z
ddl
mZddlmZddlmZmZdd	lmZdd
lmZddlmZddlmZzdd
lmZmZWnek
r�dZZYnXGdd�de�Z ddddddd�Z!d2dd�Z"dd�Z#Gdd�dej$�Z%Gdd�d�Z&Gdd�d�Z'Gdd�dej$�Z(Gd d!�d!ej$�Z)Gd"d#�d#ej$�Z*Gd$d%�d%e�Z+Gd&d'�d'�Z,Gd(d)�d)ej-�Z.Gd*d+�d+ej$�Z/Gd,d-�d-e,ej$�Z0edk�r�e/fD]Z1d.e1_2�q�n&e	�3ed�dk�re/fD]Z1d/e1_2�qddl4Z5Gd0d1�d1ej$�Z6dS)3�N)�directlyProvides)�reactor�defer�error�protocol�
interfaces)�AdvancedPOP3Client)� InsecureAuthenticationDisallowed)�ServerErrorResponse)�pop3testserver)�basic�loopback)�log)�
intToBytes)�StringTransport)�unittest)�ClientTLSContext�ServerTLSContextc@seZdZdd�ZdS)�#StringTransportWithConnectionLosingcCs|j�t���dS�N)r�connectionLostrZConnectionDone��self�r�C/usr/lib/python3/dist-packages/twisted/mail/test/test_pop3client.py�loseConnectionsz2StringTransportWithConnectionLosing.loseConnectionN)�__name__�
__module__�__qualname__rrrrrrsrs180sLOGIN)sTOPsLOGIN-DELAYsUIDL�STLSsUSERsSASLTcCs8t�}t|_t�}||_|�|�|r0|�d�||fS)Ns+OK Hello!
)�
POP3Client�capCacheZ	_capCacherrZmakeConnection�dataReceived)�greet�p�trrr�setUp$s

r&cCs|fdd�S)NcSs|�Srr)�result�frrr�<lambda>7�zstrip.<locals>.<lambda>r)r(rrr�strip6sr+c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�POP3ClientLoginTestscsDtdd�\}}d|_|�dd�}|�d���|t���fdd��S)	NF�r#T�username�passwords-ERR Offline for maintenance
cs��|jdd�S)NrsOffline for maintenance��assertEqual�args��excrrrr)Cs�z;POP3ClientLoginTests.testNegativeGreeting.<locals>.<lambda>)r&�allowInsecureLogin�loginr"�
assertFailurer
�addCallback�rr$r%�drrr�testNegativeGreeting<s
�
�z)POP3ClientLoginTests.testNegativeGreetingcCs<t�\}}|�d�}|�|��d�|�d�|�|jd�S)Nr.�USER username
s+OK send password
s
send password)r&�userr1�valuer"r8r9rrr�
testOkUserGs



zPOP3ClientLoginTests.testOkUsercsHt�\}}|�d�}��|��d�|�d���|t���fdd��S)Nr.r<s-ERR account suspended
cs��|jdd�S)Nrsaccount suspendedr0r3rrrr)Vr*z2POP3ClientLoginTests.testBadUser.<locals>.<lambda>)r&r=r1r>r"r7r
r8r9rrr�testBadUserOs


�
�z POP3ClientLoginTests.testBadUsercCs<t�\}}|�d�}|�|��d�|�d�|�|jd�S)Nr/�PASS password
s+OK you're in!
s
you're in!)r&�passwordr1r>r"r8r9rrr�
testOkPassYs



zPOP3ClientLoginTests.testOkPasscsHt�\}}|�d�}��|��d�|�d���|t���fdd��S)Nr/rAs-ERR go away
cs��|jdd�S)Nrsgo awayr0r3rrrr)hr*z2POP3ClientLoginTests.testBadPass.<locals>.<lambda>)r&rBr1r>r"r7r
r8r9rrr�testBadPassas


�
�z POP3ClientLoginTests.testBadPasscCs^t�\}}d|_|�dd�}|�|��d�|�d�|�|��d�|�d�|�|jd�S)	NTr.r/r<s+OK go ahead
�USER username
PASS password
s+OK password accepted
spassword accepted)r&r5r6r1r>r"r8r9rrr�testOkLoginks


z POP3ClientLoginTests.testOkLogincsjt�\}}d|_|�dd�}��|��d�|�d���|��d�|�d���|t���fdd	��S)
NTr.r/r<s+OK waiting on you
rE�-ERR bogus login
cs��|jdd�S�Nrsbogus loginr0r3rrrr)�r*z;POP3ClientLoginTests.testBadPasswordLogin.<locals>.<lambda>�	r&r5r6r1r>r"r7r
r8r9rrr�testBadPasswordLoginvs


�
�z)POP3ClientLoginTests.testBadPasswordLogincsPt�\}}d|_|�dd�}��|��d�|�d���|t���fdd��S)NTr.r/r<rGcs��|jdd�SrHr0r3rrrr)�r*z;POP3ClientLoginTests.testBadUsernameLogin.<locals>.<lambda>rIr9rrr�testBadUsernameLogin�s

�
�z)POP3ClientLoginTests.testBadUsernameLogincCs*tdd�\}}|�d�|�|jd�dS)NFr-s"+OK lalala this has no challenge
�r&r"r1ZserverChallenge�rr$r%rrr�testServerGreeting�s
z'POP3ClientLoginTests.testServerGreetingcCs*tdd�\}}|�d�|�|jd�dS)NFr-s+OK <here is the challenge>
s<here is the challenge>rLrMrrr�testServerGreetingWithChallenge�s
z4POP3ClientLoginTests.testServerGreetingWithChallengecCsLtdd�\}}|�d�|�dd�}|�|��d�|�d�|�|jd�S)	NFr-s"+OK <challenge string goes here>
r.r/s0APOP username f34f1e464d0d7927607753129cabe39a
s+OK Welcome!
sWelcome!)r&r"r6r1r>r8r9rrr�testAPOP�s

�
zPOP3ClientLoginTests.testAPOPcCs>tdd�\}}|�d�|�dd�}|�|���|�|t�S)NFr-�+OK Howdy
r.r/)r&r"r6ZassertFalser>r7r	r9rrr� testInsecureLoginRaisesException�s
�z5POP3ClientLoginTests.testInsecureLoginRaisesExceptioncCsptdd�\}}t|tj�|�d�|�dd�}|�|��d�|��|�d�|�|��d�|�d�|S)	z�
        If a server doesn't offer APOP but the transport is secured using
        SSL or TLS, a plaintext login should be allowed, not rejected with
        an InsecureAuthenticationDisallowed exception.
        Fr-rQr.r/r<s+OK
rA)	r&rrZ
ISSLTransportr"r6r1r>�clearr9rrr� testSSLTransportConsideredSecure�s


z5POP3ClientLoginTests.testSSLTransportConsideredSecureN)rrrr;r?r@rCrDrFrJrKrNrOrPrRrTrrrrr,;s



	r,c@seZdZdd�Zdd�ZdS)�ListConsumercCs
i|_dSr��datarrrr�__init__�szListConsumer.__init__cCs |\}}|j�|g��|�dSr)rW�
setdefault�append)rr'�itemr>rrr�consume�szListConsumer.consumeN�rrrrXr\rrrrrU�srUc@seZdZdd�Zdd�ZdS)�MessageConsumercCs
g|_dSrrVrrrrrX�szMessageConsumer.__init__cCs|j�|�dSr)rWrZ�r�linerrrr\�szMessageConsumer.consumeNr]rrrrr^�sr^c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�POP3ClientListTestscCsJt�\}}|��}|�|��d�|�d�|�d�|�|jdddg�S)N�LIST
�+OK Here it comes
s1 3
2 2
3 1
.
���)r&�listSizer1r>r"r8r9rrr�testListSize�s


z POP3ClientListTests.testListSizec
Cs�t�\}}t�}|j}|�|�}|�|��d�|�d�|�d�|�|jdgdgdgd��|�d�|�|jdgdgdgdgdgdgd	��|�d
�|�|j	|�S)Nrbrcs1 3
2 2
3 1
rdrerf)rrfres5 3
6 2
7 1
)rrfre����.
)
r&rUr\rgr1r>r"rWr8�assertIdentical�rr$r%�cr(r:rrr�testListSizeWithConsumer�s




�
z,POP3ClientListTests.testListSizeWithConsumercsFt�\}}|��}��|��d�|�d���|t���fdd��S)Nrb�!-ERR Fatal doom server exploded
cs��|jdd�S�NrsFatal doom server explodedr0r3rrrr)�s�z8POP3ClientListTests.testFailedListSize.<locals>.<lambda>)r&rgr1r>r"r7r
r8r9rrr�testFailedListSize�s

�
�z&POP3ClientListTests.testFailedListSizecCsJt�\}}|��}|�|��d�|�d�|�d�|�|jdddg�S)N�UIDL
rcs1 abc
2 def
3 ghi
.
�abcsdefsghi)r&�listUIDr1r>r"r8r9rrr�testListUID�s


zPOP3ClientListTests.testListUIDcCsxt�\}}t�}|j}|�|�}|�|��d�|�d�|�d�|�|jdgdgdgd��|�d�|�|j	|�S)	Nrtrcs1 xyz
2 abc
5 mno
sxyzrusmno)rrfrirl)
r&rUr\rvr1r>r"rWr8rmrnrrr�testListUIDWithConsumers




z+POP3ClientListTests.testListUIDWithConsumercsFt�\}}|��}��|��d�|�d���|t���fdd��S)Nrtrqcs��|jdd�Srrr0r3rrrr)s�z7POP3ClientListTests.testFailedListUID.<locals>.<lambda>)r&rvr1r>r"r7r
r8r9rrr�testFailedListUIDs

�
�z%POP3ClientListTests.testFailedListUIDN)	rrrrhrprsrwrxryrrrrra�s		
rac@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�POP3ClientMessageTestscCs^t�\}}|�d�}|�|��d�|�d�|�d�|�d�|�d�|�|jddg�S)	N��RETR 8
�+OK Message incoming
�La la la here is message text
s"..Further message text tra la la
rl�La la la here is message texts.Further message text tra la la�r&�retriever1r>r"r8r9rrr�testRetrieves





��z#POP3ClientMessageTests.testRetrievecCs`t�\}}t�}|j}|�d|�}|�|��d�|�d�|�d�|�d�|�|j||�S)Nr{r|r}r~s..Further message text
.
)	r&r^r\r�r1r>r"r8�_cbTestRetrieveWithConsumerrnrrr�testRetrieveWithConsumer+s



z/POP3ClientMessageTests.testRetrieveWithConsumercCs"|�||�|�|jddg�dS)Nrs.Further message text�rmr1rW�rr'r(rorrrr�7s
�z2POP3ClientMessageTests._cbTestRetrieveWithConsumercCsbt�\}}|jddd�}|�|��d�|�d�|�d�|�d�|�d�|�|jd	d
g�S)Nr{re��lines�	TOP 8 2
�+OK 2 lines on the way
�Line the first!  Woop
�Line the last!  Bye
rl�Line the first!  Woop�Line the last!  Byer�r9rrr�testPartialRetrieve=s




��z*POP3ClientMessageTests.testPartialRetrievecCsnt�\}}t�}|j}|jd|dd�}|�|��d�|�d�|�d�|�d�|�d�|�|j||�S)	Nr{rer�r�r�r�r�rl)	r&r^r\r�r1r>r"r8�"_cbTestPartialRetrieveWithConsumerrnrrr�testPartialRetrieveWithConsumerKs




z6POP3ClientMessageTests.testPartialRetrieveWithConsumercCs"|�||�|�|jddg�dS)Nr�r�r�r�rrrr�Xs
�z9POP3ClientMessageTests._cbTestPartialRetrieveWithConsumercsHt�\}}|�d�}��|��d�|�d���|t���fdd��S)NrsRETR 1
rqcs��|jdd�Srrr0r3rrrr)es�z;POP3ClientMessageTests.testFailedRetrieve.<locals>.<lambda>)r&r�r1r>r"r7r
r8r9rrr�testFailedRetrieve^s


�
�z)POP3ClientMessageTests.testFailedRetrievecs�t�\�}��fdd�td�D�}tdd�D]x}��|��dt|�d�|����d���d	t|�d
���dt|�d
���|��d���d
�q,tj|d
d�S)z�
        Issue three retrieve calls immediately without waiting for any to
        succeed and make sure they all do succeed eventually.
        c
sDg|]<}��|���jdt|d�ddt|d�dg��qS)�First line of rf�.�Second line of )r�r8r1r)�.0�i�r$rrr�
<listcomp>os�
��zCPOP3ClientMessageTests.test_concurrentRetrieves.<locals>.<listcomp>rdrfrisRETR s
r�r�rlr�r*T)ZfireOnOneErrback)	r&�ranger1r>rrSr"rZDeferredList)rr%Zmessagesr�rr�r�test_concurrentRetrievesis
�
z/POP3ClientMessageTests.test_concurrentRetrievesN)rrrr�r�r�r�r�r�r�r�rrrrrzs
rzc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�POP3ClientMiscTestsc
Csbt�\}}|jdd�}|�|��d�|�d�|�d�|�|jddddddgddgdgd	��S)
Nr�ZuseCache�CAPA
s+OK Capabilities on the way
s!X
Y
Z
A 1 2 3
B 1 2
C 1
.
�1�2�3)�X�Y�Z�A�B�C�r&Zcapabilitiesr1r>r"r8r9rrr�testCapability�s


��z"POP3ClientMiscTests.testCapabilitycCs>t�\}}|jdd�}|�|��d�|�d�|�|ji�S)Nrr�r��-ERR This server is lame!
r�r9rrr�testCapabilityError�s


z'POP3ClientMiscTests.testCapabilityErrorcCs:t�\}}|��}|�|��d�|�d�|�|jd�S)N�STAT
s+OK 1 1212
)rfi�)r&�statr1r>r"r8r9rrr�testStat�s


zPOP3ClientMiscTests.testStatcsFt�\}}|��}��|��d�|�d���|t���fdd��S)Nr�r�cs��|jdd�S�NrsThis server is lame!r0r3rrrr)�r*z3POP3ClientMiscTests.testStatError.<locals>.<lambda>)r&r�r1r>r"r7r
r8r9rrr�
testStatError�s

�
�z!POP3ClientMiscTests.testStatErrorcCs:t�\}}|��}|�|��d�|�d�|�|jd�S)N�NOOP
s+OK No-op to you too!
sNo-op to you too!)r&�noopr1r>r"r8r9rrr�testNoop�s


zPOP3ClientMiscTests.testNoopcsFt�\}}|��}��|��d�|�d���|t���fdd��S)Nr�r�cs��|jdd�Sr�r0r3rrrr)�r*z3POP3ClientMiscTests.testNoopError.<locals>.<lambda>)r&r�r1r>r"r7r
r8r9rrr�
testNoopError�s

�
�z!POP3ClientMiscTests.testNoopErrorcCs:t�\}}|��}|�|��d�|�d�|�|jd�S)N�RSET
s+OK Reset state
sReset state)r&�resetr1r>r"r8r9rrr�testRset�s


zPOP3ClientMiscTests.testRsetcsFt�\}}|��}��|��d�|�d���|t���fdd��S)Nr�r�cs��|jdd�Sr�r0r3rrrr)�r*z3POP3ClientMiscTests.testRsetError.<locals>.<lambda>)r&r�r1r>r"r7r
r8r9rrr�
testRsetError�s

�
�z!POP3ClientMiscTests.testRsetErrorcCs<t�\}}|�d�}|�|��d�|�d�|�|jd�S)Nrd�DELE 4
s+OK Hasta la vista
sHasta la vista)r&�deleter1r>r"r8r9rrr�
testDelete�s



zPOP3ClientMiscTests.testDeletecsHt�\}}|�d�}��|��d�|�d���|t���fdd��S)Nrdr�s-ERR Winner is not you.
cs��|jdd�S)NrsWinner is not you.r0r3rrrr)�r*z5POP3ClientMiscTests.testDeleteError.<locals>.<lambda>)r&r�r1r>r"r7r
r8r9rrr�testDeleteError�s


�
�z#POP3ClientMiscTests.testDeleteErrorN)
rrrr�r�r�r�r�r�r�r�r�r�rrrrr��s


r�c@seZdZddd�Zdd�ZdS)�SimpleClientNcCs||_d|_dS)NT)�deferredr5)rr��contextFactoryrrrrX�szSimpleClient.__init__cCs|j�d�dSr)r��callback)rZ	challengerrr�serverGreeting�szSimpleClient.serverGreeting)N)rrrrXr�rrrrr��s
r�c@s<eZdZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dS)�POP3HelperMixinNcCs:t��}tj|jd�|_t||jd�|_d|j_	||_
dS)N)r��)r�DeferredrZPOP3TestServer�	serverCTX�serverr��	clientCTX�client�timeout�	connected)rr:rrrr&�s�zPOP3HelperMixin.setUpcCs|`|`|`dSr)r�r�r�rrrr�tearDown�szPOP3HelperMixin.tearDowncCs|jj��dSr)r��	transportr)r�ignorerrr�
_cbStopClientszPOP3HelperMixin._cbStopClientcCs|jj��|jj��|Sr)r�r�rr�)r�failurerrr�
_ebGeneralszPOP3HelperMixin._ebGeneralcCstj|j|jdd�S)NF)Znoisy)r
ZloopbackTCPr�r�rrrrr
szPOP3HelperMixin.loopback)
rrrr�r�r&r�r�r�r
rrrrr��s	r�c@seZdZGdd�dej�ZdS)�TLSServerFactoryc@s$eZdZdZgZdd�Zdd�ZdS)zTLSServerFactory.protocolNcCs8g|j_|jdd�|_|j�d�D]}|�|�q$dS)Nr)�factory�input�output�pop�sendLiner_rrr�connectionMadesz(TLSServerFactory.protocol.connectionMadecsB�jj�|��fdd��j�d�D�|dkr>�j��j�dS)Ncsg|]}��|��qSr)r�)r��lrrrr�sz:TLSServerFactory.protocol.lineReceived.<locals>.<listcomp>rr)r�r�rZr�r�r��startTLS�contextr_rrr�lineReceivedsz&TLSServerFactory.protocol.lineReceived)rrrr�r�r�r�rrrrrsrN)rrrrZLineReceiverrrrrrr�sr�c@seZdZdZdd�ZdS)�POP3TLSTestsz=
    Tests for POP3Client's support for TLS connections.
    c
st��dgdddgdgddgdgg�j_t��j_tjd�dd�}��|j�|�	�j
}|�	�j}t�
��tt�
�t�����fdd�}|�_t��}�fd	d
�|_t�|||���fdd�}�fd
d�}��fdd�}��fdd�}	�j�|��j�|��j�|��j�|	��jS)zd
        POP3Client.startTLS starts a TLS session over its existing TCP
        connection.
        s+OKrr�rz	127.0.0.1)Z	interfacecst��|���d�dSr)r�rr�)�reason)�connLostDeferred�cprrr>sz2POP3TLSTests.test_startTLS.<locals>.connectionLostcs�Srrr�r�rrr)Cr*z,POP3TLSTests.test_startTLS.<locals>.<lambda>cst�d����S)Nz!Connected to server; starting TLS)r�msgr��Zignoredr�rr�cbConnectedGs
z/POP3TLSTests.test_startTLS.<locals>.cbConnectedcst�d����S)NzStarted TLS; disconnecting)rr��quitr�r�rr�cbStartedTLSKs
z0POP3TLSTests.test_startTLS.<locals>.cbStartedTLScs$t�d����jddddg�dS)Nz.Disconnected; asserting correct input receivedsCAPArsQUIT)rr�r1r�)Zign)r�sfrr�cbDisconnectedOs


�z2POP3TLSTests.test_startTLS.<locals>.cbDisconnectedcst�d�����S)NzEAsserted correct input; disconnecting client and shutting down server)rr�Z
disconnect�r')�connr�rr�cleanupUs
z+POP3TLSTests.test_startTLS.<locals>.cleanup)r�rr�rr�rZ	listenTCPZ
addCleanupZ
stopListeningZgetHostZhost�portrr�r�rrZ
ClientFactoryZ
connectTCPr�r8ZaddBoth)
rr��H�PrZcfr�r�r�r�r)r�r�r�rr�r�
test_startTLS)s8�


zPOP3TLSTests.test_startTLSN)rrr�__doc__r�rrrrr�$sr�c@seZdZdd�ZdS)�POP3TimeoutTestscs����fdd�}�fdd���fdd���fdd�}d	�j_d
t_||g}t�jjtt|���j��j��j�	�j
����S)Ncs&�j�dd�}|���|���|S)NZtest�twisted)r�r6r8�
addErrback)r:��loggedInr�timedOutrrr6fs

z+POP3TimeoutTests.testTimeout.<locals>.logincs��d�dS)Nz%Successfully logged in!?  Impossible!)Zfailr�rrrr�lsz.POP3TimeoutTests.testTimeout.<locals>.loggedIncs|�tj���d�dSr)Ztrapr�TimeoutErrorr�)r�rrrr�psz.POP3TimeoutTests.testTimeout.<locals>.timedOutcs
�j��Sr)r�r�rrrrr�tsz*POP3TimeoutTests.testTimeout.<locals>.quitg{�G�z�?T)r�r�rZTIMEOUT_RESPONSE�mapr�r8r+r�r�r�r
)rr6r��methodsrr�r�testTimeouteszPOP3TimeoutTests.testTimeoutN)rrrr�rrrrr�dsr�zOpenSSL not presentzReactor doesn't support SSLc@s eZdZdZdd�Zdd�ZdS)�POP3ClientModuleStructureTestszt
    Miscellaneous tests more to do with module/package structure than
    anything to do with the POP3 client.
    cCs|�tjjjg�dS)z�
        twisted.mail.pop3client.__all__ should be empty because all classes
        should be imported through twisted.mail.pop3.
        N)r1r��mailZ
pop3client�__all__rrrr�test_all�sz'POP3ClientModuleStructureTests.test_allcCs^dd�t�tjdtj�D�}|D]6}|dksD|�ttjj	|��q"|�ttjj	d��q"dS)a
        Every public class in twisted.mail.pop3client should be available as a
        member of twisted.mail.pop3 with the exception of
        twisted.mail.pop3client.POP3Client which should be available as
        twisted.mail.pop3.AdvancedClient.
        cSs$g|]}|dddks|d�qS)r�_r)r�rorrrr��s�z>POP3ClientModuleStructureTests.test_import.<locals>.<listcomp>ztwisted.mail.pop3clientr rN)
�inspectZ
getmembers�sys�modulesZisclassZ
assertTrue�hasattrr�r�Zpop3)rZ
publicClassesZpcrrr�test_import�s
��z*POP3ClientModuleStructureTests.test_importN)rrrr�r�rrrrrr��sr�)T)7rr�Zzope.interfacerZtwisted.internetrrrrrZtwisted.mail.pop3rr r	r
Ztwisted.mail.testrZtwisted.protocolsrr
Ztwisted.pythonrZtwisted.python.compatrZtwisted.test.proto_helpersrZ
twisted.trialrZtwisted.test.ssl_helpersrr�ImportErrorrr!r&r+ZTestCaser,rUr^rarzr�r�r�Z
ServerFactoryr�r�r�Zcase�skipZIReactorSSLZtwisted.mail.pop3clientr�r�rrrr�<module>sX�

Gh`"@!