
    VhT                        d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlZ	d dl
mZmZmZmZmZ d dlmZ d dlmZmZmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZ 	 d dl m!Z!m"Z"  G d de      Z$dddddddZ%d-dZ&d Z' G d de      Z( G d d      Z) G d d      Z* G d de      Z+ G d de      Z, G d de      Z- G d  d!e      Z. G d" d#      Z/ G d$ d%ej`                        Z1 ee! d&       e ejd                  ed       d&       G d' d(e                    Z3 G d) d*e/e      Z4 G d+ d,e      Z5y# e#$ r dZ!dZ"Y w xY w).    N)List)skipIf)directlyProvides)defererror
interfacesprotocolreactor)StringTransport)AdvancedPOP3Client InsecureAuthenticationDisallowedServerErrorResponse)pop3testserver)basicloopback)log)TestCase)ClientTLSContextServerTLSContextc                       e Zd Zd Zy)#StringTransportWithConnectionLosingc                 ^    | j                   j                  t        j                                y N)r	   connectionLostr   ConnectionDoneselfs    Q/home/dcms/DCMS/lib/python3.12/site-packages/twisted/mail/test/test_pop3client.pyloseConnectionz2StringTransportWithConnectionLosing.loseConnection!   s    $$U%9%9%;<    N)__name__
__module____qualname__r    r    r   r   r       s    =r    r   s   180s   LOGIN)s   TOPs   LOGIN-DELAYs   UIDL   STLSs   USERs   SASLc                     t               }t        |_        t               }||_        |j                  |       | r|j                  d       ||fS )Ns   +OK Hello!
)
POP3ClientcapCache	_capCacher   r	   makeConnectiondataReceived)greetpts      r   setUpr/   /   sH    A AK+-AAJQ	()a4Kr    c                     | fdS )Nc                      |       S r   r$   )resultfs     r   <lambda>zstrip.<locals>.<lambda>A   s    qs r    r$   )r3   s    r   stripr5   @   s    ""r    c                   Z    e 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y)POP3ClientLoginTestsc                      t        d      \  }}d|_        |j                  dd      }|j                  d        j	                  |t
              j                   fd      S )NFr,   T   username   passwords   -ERR Offline for maintenance
c                 B    j                  | j                  d   d      S )Nr   s   Offline for maintenanceassertEqualargsexcr   s    r   r4   z;POP3ClientLoginTests.testNegativeGreeting.<locals>.<lambda>K   s    ((!6PQ r    )r/   allowInsecureLoginloginr+   assertFailurer   addCallbackr   r-   r.   ds   `   r   testNegativeGreetingz)POP3ClientLoginTests.testNegativeGreetingE   sZ    5!1#GGK-	:;!!!%89EEQ
 	
r    c                     t               \  }}|j                  d      }| j                  |j                         d       |j	                  d       |j                  | j                  d      S )Nr:      USER username
s   +OK send password
s   send password)r/   userr>   valuer+   rE   rF   s       r   
testOkUserzPOP3ClientLoginTests.testOkUserN   sW    w1FF;$89	/0}}T--/?@@r    c                      t               \  }}|j                  d      } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr:   rJ   s   -ERR account suspended
c                 B    j                  | j                  d   d      S )Nr   s   account suspendedr=   r@   s    r   r4   z2POP3ClientLoginTests.testBadUser.<locals>.<lambda>[   s    ((!6JK r    )r/   rK   r>   rL   r+   rD   r   rE   rF   s   `   r   testBadUserz POP3ClientLoginTests.testBadUserU   sd    w1FF;$89	45!!!%89EEK
 	
r    c                     t               \  }}|j                  d      }| j                  |j                         d       |j	                  d       |j                  | j                  d      S )Nr;      PASS password
s   +OK you're in!
s
   you're in!)r/   passwordr>   rL   r+   rE   rF   s       r   
testOkPasszPOP3ClientLoginTests.testOkPass^   sV    w1JJ{#$89	,-}}T--}==r    c                      t               \  }}|j                  d      } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr;   rR   s   -ERR go away
c                 B    j                  | j                  d   d      S )Nr   s   go awayr=   r@   s    r   r4   z2POP3ClientLoginTests.testBadPass.<locals>.<lambda>k   s    ((!jA r    )r/   rS   r>   rL   r+   rD   r   rE   rF   s   `   r   testBadPassz POP3ClientLoginTests.testBadPasse   sd    w1JJ{#$89	*+!!!%89EEA
 	
r    c                 J   t               \  }}d|_        |j                  dd      }| j                  |j	                         d       |j                  d       | j                  |j	                         d       |j                  d       |j                  | j                  d      S )	NTr:   r;   rJ   s   +OK go ahead
   USER username
PASS password
s   +OK password accepted
s   password accepted)r/   rB   rC   r>   rL   r+   rE   rF   s       r   testOkLoginz POP3ClientLoginTests.testOkLoginn   s    w1#GGK-$89	*+$IJ	34}}T--/CDDr    c                 d    t               \  }}d|_        |j                  dd      } j                  |j	                         d       |j                  d        j                  |j	                         d       |j                  d        j                  |t              j                   fd      S )	NTr:   r;   rJ   s   +OK waiting on you
rY      -ERR bogus login
c                 B    j                  | j                  d   d      S Nr   s   bogus loginr=   r@   s    r   r4   z;POP3ClientLoginTests.testBadPasswordLogin.<locals>.<lambda>       ((!nE r    	r/   rB   rC   r>   rL   r+   rD   r   rE   rF   s   `   r   testBadPasswordLoginz)POP3ClientLoginTests.testBadPasswordLoginx   s    w1#GGK-$89	01$IJ	./!!!%89EEE
 	
r    c                     t               \  }}d|_        |j                  dd      } j                  |j	                         d       |j                  d        j                  |t              j                   fd      S )NTr:   r;   rJ   r\   c                 B    j                  | j                  d   d      S r^   r=   r@   s    r   r4   z;POP3ClientLoginTests.testBadUsernameLogin.<locals>.<lambda>   r_   r    r`   rF   s   `   r   testBadUsernameLoginz)POP3ClientLoginTests.testBadUsernameLogin   sn    w1#GGK-$89	./!!!%89EEE
 	
r    c                 |    t        d      \  }}|j                  d       | j                  |j                  d        y )NFr9   s"   +OK lalala this has no challenge
r/   r+   r>   serverChallenger   r-   r.   s      r   testServerGreetingz'POP3ClientLoginTests.testServerGreeting   s3    5!1	>?**D1r    c                 |    t        d      \  }}|j                  d       | j                  |j                  d       y )NFr9   s   +OK <here is the challenge>
s   <here is the challenge>rf   rh   s      r   testServerGreetingWithChallengez4POP3ClientLoginTests.testServerGreetingWithChallenge   s4    5!1	9:**,FGr    c                     t        d      \  }}|j                  d       |j                  dd      }| j                  |j	                         d       |j                  d       |j                  | j                  d      S )	NFr9   s"   +OK <challenge string goes here>
r:   r;   s0   APOP username f34f1e464d0d7927607753129cabe39a
s   +OK Welcome!
s   Welcome!)r/   r+   rC   r>   rL   rE   rF   s       r   testAPOPzPOP3ClientLoginTests.testAPOP   sm    5!1	>?GGK-GGIL	
 	
*+}}T--{;;r    c                     t        d      \  }}|j                  d       |j                  dd      }| j                  |j	                                | j                  |t              S )NFr9      +OK Howdy
r:   r;   )r/   r+   rC   assertFalserL   rD   r   rF   s       r    testInsecureLoginRaisesExceptionz5POP3ClientLoginTests.testInsecureLoginRaisesException   sU    5!1	'(GGK-#!!!%EFFr    c                    t        d      \  }}t        |t        j                         |j	                  d       |j                  dd      }| j                  |j                         d       |j                          |j	                  d       | j                  |j                         d       |j	                  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.
        Fr9   ro   r:   r;   rJ   s   +OK
rR   )	r/   r   r   ISSLTransportr+   rC   r>   rL   clearrF   s       r    testSSLTransportConsideredSecurez5POP3ClientLoginTests.testSSLTransportConsideredSecure   s     5!1J445	'(GGK-$89			z"$89	z"r    N)r!   r"   r#   rH   rM   rP   rT   rW   rZ   ra   rd   ri   rk   rm   rq   ru   r$   r    r   r7   r7   D   sG    
A
>
E


2
H
<Gr    r7   c                       e Zd Zd Zd Zy)ListConsumerc                     i | _         y r   datar   s    r   __init__zListConsumer.__init__   	    	r    c                 d    |\  }}| j                   j                  |g       j                  |       y r   )rz   
setdefaultappend)r   r2   itemrL   s       r   consumezListConsumer.consume   s*    u		T2&--e4r    Nr!   r"   r#   r{   r   r$   r    r   rw   rw      s    5r    rw   c                       e Zd Zd Zd Zy)MessageConsumerc                     g | _         y r   ry   r   s    r   r{   zMessageConsumer.__init__   r|   r    c                 :    | j                   j                  |       y r   )rz   r   r   lines     r   r   zMessageConsumer.consume   s    		r    Nr   r$   r    r   r   r      s    r    r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)POP3ClientListTestsc                     t               \  }}|j                         }| j                  |j                         d       |j	                  d       |j	                  d       |j                  | j                  g d      S )N   LIST
   +OK Here it comes
s   1 3
2 2
3 1
.
)         )r/   listSizer>   rL   r+   rE   rF   s       r   testListSizez POP3ClientListTests.testListSize   s_    w1JJLK0	/0	45}}T--y99r    c           
         t               \  }}t               }|j                  }|j                  |      }| j	                  |j                         d       |j                  d       |j                  d       | j	                  |j                  dgdgdgd       |j                  d       | j	                  |j                  dgdgdgdgdgdgd	       |j                  d
       |j                  | j                  |      S )Nr   r   s   1 3
2 2
3 1
r   r   r   )r   r   r   s   5 3
6 2
7 1
)r   r   r               .
)
r/   rw   r   r   r>   rL   r+   rz   rE   assertIdenticalr   r-   r.   cr3   rG   s         r   testListSizeWithConsumerz,POP3ClientListTests.testListSizeWithConsumer   s    w1NIIJJqMK0	/0	/0aSaSaS!9:	/0aSaSaSaSaSaS!QR	x }}T11155r    c                      t               \  }}|j                         } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   !   -ERR Fatal doom server exploded
c                 B    j                  | j                  d   d      S Nr   s   Fatal doom server explodedr=   r@   s    r   r4   z8POP3ClientListTests.testFailedListSize.<locals>.<lambda>       ((!6ST r    )r/   r   r>   rL   r+   rD   r   rE   rF   s   `   r   testFailedListSizez&POP3ClientListTests.testFailedListSize   s`    w1JJLK0	=>!!!%89EET
 	
r    c                     t               \  }}|j                         }| j                  |j                         d       |j	                  d       |j	                  d       |j                  | j                  g d      S )N   UIDL
r   s   1 abc
2 def
3 ghi
.
)   abcs   defs   ghi)r/   listUIDr>   rL   r+   rE   rF   s       r   testListUIDzPOP3ClientListTests.testListUID   s`    w1IIKK0	/0	:;}}T--/GHHr    c                    t               \  }}t               }|j                  }|j                  |      }| j	                  |j                         d       |j                  d       |j                  d       | j	                  |j                  dgdgdgd       |j                  d       |j                  | j                  |      S )	Nr   r   s   1 xyz
2 abc
5 mno
s   xyzr   s   mno)r   r   r   r   )
r/   rw   r   r   r>   rL   r+   rz   rE   r   r   s         r   testListUIDWithConsumerz+POP3ClientListTests.testListUIDWithConsumer   s    w1NIIIIaLK0	/0	56fX6(x!HI	x }}T11155r    c                      t               \  }}|j                         } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   r   c                 B    j                  | j                  d   d      S r   r=   r@   s    r   r4   z7POP3ClientListTests.testFailedListUID.<locals>.<lambda>  r   r    )r/   r   r>   rL   r+   rD   r   rE   rF   s   `   r   testFailedListUIDz%POP3ClientListTests.testFailedListUID   s`    w1IIKK0	=>!!!%89EET
 	
r    N)	r!   r"   r#   r   r   r   r   r   r   r$   r    r   r   r      s!    :6
I
6
r    r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
POP3ClientMessageTestsc                 B   t               \  }}|j                  d      }| j                  |j                         d       |j	                  d       |j	                  d       |j	                  d       |j	                  d       |j                  | j                  ddg      S )	N      RETR 8
   +OK Message incoming
   La la la here is message text
s"   ..Further message text tra la la
r      La la la here is message texts   .Further message text tra la lar/   retriever>   rL   r+   rE   rF   s       r   testRetrievez#POP3ClientMessageTests.testRetrieve  s    w1JJqMM2	23	;<	>?	x }}-/QR
 	
r    c                 L   t               \  }}t               }|j                  }|j                  d|      }| j	                  |j                         d       |j                  d       |j                  d       |j                  d       |j                  | j                  ||      S )Nr   r   r   r   s   ..Further message text
.
)	r/   r   r   r   r>   rL   r+   rE   _cbTestRetrieveWithConsumerr   s         r   testRetrieveWithConsumerz/POP3ClientMessageTests.testRetrieveWithConsumer  s    w1IIJJq!M2	23	;<	9:}}T==q!DDr    c                 d    | j                  ||       | j                  |j                  ddg       y )Nr   s   .Further message textr   r>   rz   r   r2   r3   r   s       r   r   z2POP3ClientMessageTests._cbTestRetrieveWithConsumer#  s0    VQ'FF57OP	
r    c                 F   t               \  }}|j                  dd      }| j                  |j                         d       |j	                  d       |j	                  d       |j	                  d       |j	                  d       |j                  | j                  d	d
g      S )Nr   r   lines	   TOP 8 2
   +OK 2 lines on the way
   Line the first!  Woop
   Line the last!  Bye
r      Line the first!  Woop   Line the last!  Byer   rF   s       r   testPartialRetrievez*POP3ClientMessageTests.testPartialRetrieve)  s    w1JJqJ"N3	45	34	12	x }}79OP
 	
r    c                 r   t               \  }}t               }|j                  }|j                  d|d      }| j	                  |j                         d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  | j                  ||      S )	Nr   r   r   r   r   r   r   r   )	r/   r   r   r   r>   rL   r+   rE   "_cbTestPartialRetrieveWithConsumerr   s         r   testPartialRetrieveWithConsumerz6POP3ClientMessageTests.testPartialRetrieveWithConsumer5  s    w1IIJJq!1J%N3	45	34	12	x }}TDDaKKr    c                 d    | j                  ||       | j                  |j                  ddg       y )Nr   r   r   r   s       r   r   z9POP3ClientMessageTests._cbTestPartialRetrieveWithConsumerA  s-    VQ'":<R!STr    c                      t               \  }}|j                  d      } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   s   RETR 1
r   c                 B    j                  | j                  d   d      S r   r=   r@   s    r   r4   z;POP3ClientMessageTests.testFailedRetrieve.<locals>.<lambda>K  r   r    )r/   r   r>   rL   r+   rD   r   rE   rF   s   `   r   testFailedRetrievez)POP3ClientMessageTests.testFailedRetrieveE  sb    w1JJqMM2	=>!!!%89EET
 	
r    c           
      X   t               \  }}t        d      D cg c]=  }|j                  |      j                  | j                  d|dz   fz  d|dz   fz  g      ? }}t        dd      D ]  }| j	                  |j                         d|fz         |j                          |j                  d       |j                  d|fz         |j                  d	|fz         | j	                  |j                         d
       |j                  d        t        j                  |d      S c c}w )z
        Issue three retrieve calls immediately without waiting for any to
        succeed and make sure they all do succeed eventually.
        r   s   First line of %d.r   s   Second line of %d.r   s	   RETR %d
r   s   First line of %d.
s   Second line of %d.
r    r   T)fireOnOneErrback)
r/   ranger   rE   r>   rL   rt   r+   r   DeferredList)r   r-   r.   imessagess        r   test_concurrentRetrievesz/POP3ClientMessageTests.test_concurrentRetrievesN  s   
 w1 1X

 	 JJqM%%  %Q02G1q5(2RS
 
 q! 	%AQWWY!(=>GGINN89NN3qd:;NN4t;<QWWY,NN8$	% !!(TBB#
s   AD'N)r!   r"   r#   r   r   r   r   r   r   r   r   r$   r    r   r   r   
  s.    
	E



LU
Cr    r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)POP3ClientMiscTestsc           
         t               \  }}|j                  d      }| j                  |j                         d       |j	                  d       |j	                  d       |j                  | j                  d d d g dddgdgd	      S )
Nr   useCache   CAPA
s   +OK Capabilities on the way
s!   X
Y
Z
A 1 2 3
B 1 2
C 1
.
)   1   2   3r   r   )   X   Y   Z   A   B   Cr/   capabilitiesr>   rL   r+   rE   rF   s       r   testCapabilityz"POP3ClientMiscTests.testCapabilityi  s    w1NNAN&K0	9:	IJ}}(Tlf

 
	
r    c                     t               \  }}|j                  d      }| j                  |j                         d       |j	                  d       |j                  | j                  i       S )Nr   r   r      -ERR This server is lame!
r   rF   s       r   testCapabilityErrorz'POP3ClientMiscTests.testCapabilityError{  sW    w1NNAN&K0	78}}T--r22r    c                     t               \  }}|j                         }| j                  |j                         d       |j	                  d       |j                  | j                  d      S )N   STAT
s   +OK 1 1212
)r   i  )r/   statr>   rL   r+   rE   rF   s       r   testStatzPOP3ClientMiscTests.testStat  sR    w1FFHK0	()}}T--y99r    c                      t               \  }}|j                         } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   r   c                 B    j                  | j                  d   d      S Nr   s   This server is lame!r=   r@   s    r   r4   z3POP3ClientMiscTests.testStatError.<locals>.<lambda>      ((!6MN r    )r/   r   r>   rL   r+   rD   r   rE   rF   s   `   r   testStatErrorz!POP3ClientMiscTests.testStatError  `    w1FFHK0	78!!!%89EEN
 	
r    c                     t               \  }}|j                         }| j                  |j                         d       |j	                  d       |j                  | j                  d      S )N   NOOP
s   +OK No-op to you too!
s   No-op to you too!)r/   noopr>   rL   r+   rE   rF   s       r   testNoopzPOP3ClientMiscTests.testNoop  sS    w1FFHK0	34}}T--/CDDr    c                      t               \  }}|j                         } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   r   c                 B    j                  | j                  d   d      S r   r=   r@   s    r   r4   z3POP3ClientMiscTests.testNoopError.<locals>.<lambda>  r   r    )r/   r   r>   rL   r+   rD   r   rE   rF   s   `   r   testNoopErrorz!POP3ClientMiscTests.testNoopError  r   r    c                     t               \  }}|j                         }| j                  |j                         d       |j	                  d       |j                  | j                  d      S )N   RSET
s   +OK Reset state
s   Reset state)r/   resetr>   rL   r+   rE   rF   s       r   testRsetzPOP3ClientMiscTests.testRset  sR    w1GGIK0	-.}}T--~>>r    c                      t               \  }}|j                         } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   r   c                 B    j                  | j                  d   d      S r   r=   r@   s    r   r4   z3POP3ClientMiscTests.testRsetError.<locals>.<lambda>  r   r    )r/   r   r>   rL   r+   rD   r   rE   rF   s   `   r   testRsetErrorz!POP3ClientMiscTests.testRsetError  s`    w1GGIK0	78!!!%89EEN
 	
r    c                     t               \  }}|j                  d      }| j                  |j                         d       |j	                  d       |j                  | j                  d      S )Nr      DELE 4
s   +OK Hasta la vista
s   Hasta la vista)r/   deleter>   rL   r+   rE   rF   s       r   
testDeletezPOP3ClientMiscTests.testDelete  sU    w1HHQKM2	01}}T--/@AAr    c                      t               \  }}|j                  d      } j                  |j                         d       |j	                  d        j                  |t              j                   fd      S )Nr   r  s   -ERR Winner is not you.
c                 B    j                  | j                  d   d      S )Nr   s   Winner is not you.r=   r@   s    r   r4   z5POP3ClientMiscTests.testDeleteError.<locals>.<lambda>  s    ((!6KL r    )r/   r  r>   rL   r+   rD   r   rE   rF   s   `   r   testDeleteErrorz#POP3ClientMiscTests.testDeleteError  sb    w1HHQKM2	56!!!%89EEL
 	
r    N)r!   r"   r#   r   r   r   r   r   r   r   r  r  r  r$   r    r   r   r   h  s6    
$3:
E
?
B
r    r   c                       e Zd ZddZd Zy)SimpleClientNc                      || _         d| _        y )NT)deferredrB   )r   r  contextFactorys      r   r{   zSimpleClient.__init__  s     "&r    c                 :    | j                   j                  d        y r   )r  callback)r   	challenges     r   serverGreetingzSimpleClient.serverGreeting  s    t$r    r   )r!   r"   r#   r{   r  r$   r    r   r
  r
    s    '%r    r
  c                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)POP3HelperMixinNc                     t        j                         }t        j                  | j                        | _        t        || j                        | _        d| j                  _	        || _
        y )N)r     )r   Deferredr   POP3TestServer	serverCTXserverr
  	clientCTXclienttimeout	connected)r   rG   s     r   r/   zPOP3HelperMixin.setUp  sI    NN$334>>R"1T^^D r    c                     | ` | `| `y r   )r  r  r  r   s    r   tearDownzPOP3HelperMixin.tearDown  s    KKNr    c                 L    | j                   j                  j                          y r   )r  	transportr   )r   ignores     r   _cbStopClientzPOP3HelperMixin._cbStopClient  s    ,,.r    c                     | j                   j                  j                          | j                  j                  j                          |S r   )r  r!  r   r  )r   failures     r   
_ebGeneralzPOP3HelperMixin._ebGeneral  s3    ,,.,,.r    c                 Z    t        j                  | j                  | j                  d      S )NF)noisy)r   loopbackTCPr  r  r   s    r   r   zPOP3HelperMixin.loopback  s    ##DKKEJJr    )
r!   r"   r#   r  r  r/   r  r#  r&  r   r$   r    r   r  r    s&    II
/
Kr    r  c                   6    e Zd Z G d dej                        Zy)TLSServerFactoryc                   2    e Zd ZU dZg Zee   ed<   d Zd Z	y)TLSServerFactory.protocolNoutputc                     g | j                   _        | j                  d d  | _        | j                  j                  d      D ]  }| j	                  |        y )Nr   )factoryinputr.  popsendLiner   s     r   connectionMadez(TLSServerFactory.protocol.connectionMade  sE    !#DLL++a.DK* $d#$r    c                    | j                   j                  j                  |       | j                  j	                  d      D cg c]  }| j                  |       c} |dk(  r&| j                  j                  | j                         y y c c}w )Nr   r%   )	r0  r1  r   r.  r2  r3  r!  startTLScontext)r   r   ls      r   lineReceivedz&TLSServerFactory.protocol.lineReceived  se    LL%%d+'+{{q'9:!T]]1:w''5  ;s   B
)
r!   r"   r#   r7  r.  r   bytes__annotations__r4  r9  r$   r    r   r	   r-    s     U 	$	6r    r	   N)r!   r"   r#   r   LineReceiverr	   r$   r    r   r+  r+    s    65%% 6r    r+  zOpenSSL not presentc                       e Zd ZdZd Zy)POP3TLSTestsz=
    Tests for POP3Client's support for TLS connections.
    c                 n   
 t               dgg ddgddgdggj                  _        t               j                  _        t        j                  dd      } j                  |j                         |j                         j                  }|j                         j                  }t        j                         t        t        j                         t                     fd}|_        t        j"                         }fd|_        t        j$                  |||      
fd	}fd
} fd}
fd}	j&                  j)                  |       j&                  j)                  |       j&                  j)                  |       j&                  j+                  |	       j&                  S )zd
        POP3Client.startTLS starts a TLS session over its existing TCP
        connection.
           +OK)r@  r%      .rA  r   z	127.0.0.1)	interfacec                 T    t         j                  |        j                  d        y r   )r
  r   r  )reasonconnLostDeferredcps    r   r   z2POP3TLSTests.test_startTLS.<locals>.connectionLost  s!    ''F3%%d+r    c                       S r   r$   )rF  s   r   r4   z,POP3TLSTests.test_startTLS.<locals>.<lambda>  s    b r    c                 N    t        j                  d       j                         S )Nz!Connected to server; starting TLS)r   msgr6  ignoredrF  s    r   cbConnectedz/POP3TLSTests.test_startTLS.<locals>.cbConnected!  s    GG78;;= r    c                 N    t        j                  d       j                         S )NzStarted TLS; disconnecting)r   rI  quitrJ  s    r   cbStartedTLSz0POP3TLSTests.test_startTLS.<locals>.cbStartedTLS%  s    GG01779r    c                 l    t        j                  d       j                  j                  g d       y )Nz.Disconnected; asserting correct input received)   CAPAr%   rQ  s   QUIT)r   rI  r>   r1  )ignr   sfs    r   cbDisconnectedz2POP3TLSTests.test_startTLS.<locals>.cbDisconnected)  s%    GGDERXX'KLr    c                 R    t        j                  d       j                          S )NzEAsserted correct input; disconnecting client and shutting down server)r   rI  
disconnect)r2   connrE  s    r   cleanupz+POP3TLSTests.test_startTLS.<locals>.cleanup-  s&    GG2 OO##r    )r+  r	   r.  r   r7  r
   	listenTCP
addCleanupstopListeninggetHosthostportr   r  r
  r   r   ClientFactory
connectTCPr  rE   addBoth)r   r^  HPr   cfrL  rO  rT  rX  rW  rE  rF  rS  s   `         @@@@r   test_startTLSzPOP3TLSTests.test_startTLS  sR   
 H#HTNH
 /0  B+>**+LLNLLN >>+%..*,<,>?	, +##% !!!Q+	!		M	$ 	,
-
/
G${{r    N)r!   r"   r#   __doc__re  r$   r    r   r>  r>    s    9r    r>  c                       e Zd Zd Zy)POP3TimeoutTestsc                      fd} fd fd fd}d j                   _        dt        _        ||g}t	         j
                  j                  t	        t        |              j
                  j                   j                          j
                  j                   j                          j                         S )Nc                      j                   j                  dd      } | j                         | j                         | S )Ntesttwisted)r  rC   rE   
addErrback)rG   loggedInr   timedOuts    r   rC   z+POP3TimeoutTests.testTimeout.<locals>.login?  s6    !!&)4AMM(#LL"Hr    c                 (    j                  d       y )Nz%Successfully logged in!?  Impossible!)fail)r2   r   s    r   rn  z.POP3TimeoutTests.testTimeout.<locals>.loggedInE  s    II=>r    c                 f    | j                  t        j                         j                  d        y r   )trapr   TimeoutErrorr#  )r%  r   s    r   ro  z.POP3TimeoutTests.testTimeout.<locals>.timedOutH  s#    LL++,t$r    c                  8     j                   j                         S r   )r  rN  r   s   r   rN  z*POP3TimeoutTests.testTimeout.<locals>.quitL  s    ;;##%%r    g{Gz?T)r  r  r   TIMEOUT_RESPONSEmapr  rE   r5   r#  rm  r&  r   )r   rC   rN  methodsrn  ro  s   `   @@r   testTimeoutzPOP3TimeoutTests.testTimeout>  s    		?	%	& # +/'$-DNN&&E7(;<""4#5#56!!$//2}}r    N)r!   r"   r#   ry  r$   r    r   rh  rh  =  s    r    rh  c                       e Zd ZdZd Zd Zy)POP3ClientModuleStructureTestszt
    Miscellaneous tests more to do with module/package structure than
    anything to do with the POP3 client.
    c                 l    | j                  t        j                  j                  j                  g        y)z
        twisted.mail._pop3client.__all__ should be empty because all classes
        should be imported through twisted.mail.pop3.
        N)r>   rl  mail_pop3client__all__r   s    r   test_allz'POP3ClientModuleStructureTests.test_allb  s$    
 	11992>r    c                    t        j                  t        j                  d   t         j                        D cg c]  }|d   d   dk(  s|d    }}|D ]  }|dk(  sR| j                  t        t        j                  j                  |      | dt        j                  j                          Z| j                  t        t        j                  j                  d              yc c}w )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.
        ztwisted.mail._pop3clientr   _r'   z not in r   N)
inspect
getmemberssysmodulesisclass
assertTruehasattrrl  r}  pop3)r   r   publicClassespcs       r   test_importz*POP3ClientModuleStructureTests.test_importi  s     ''67
 Q47c>	 aD
 
   	RB%GLL--r2d(7<<#4#4"56
 (9(9;O PQ	R
s   C#N)r!   r"   r#   rf  r  r  r$   r    r   r{  r{  \  s    
?Rr    r{  )T)6r  r  typingr   unittestr   zope.interfacer   twisted.mail._pop3clientrl  twisted.internetr   r   r   r	   r
   twisted.internet.testingr   twisted.mail.pop3r   r'   r   r   twisted.mail.testr   twisted.protocolsr   r   twisted.pythonr   twisted.trial.unittestr   twisted.test.ssl_helpersr   r   ImportErrorr   r(   r/   r5   r7   rw   r   r   r   r   r
  r  ServerFactoryr+  IReactorSSLr>  rh  r{  r$   r    r   <module>r     ss  
  
   +  H H 4 
 - -  +K=/ = "#t8 tn5 5 ;
( ;
|[CX [C|X
( X
v%: %K K86x-- 6$ 34"J""7D113HI>8 > J 5>B >#RX #RC  s   D3 3	D?>D?