o
    ¯b“¸  ã                   @   sÜ  d Z ddlZ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
mZ ddlZddlZddlZddlZddlZddlZddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddl m!Z!m"Z" G dd„ de!j#ƒZ$G dd„ dej%j&ƒZ'G dd„ dƒZ(G dd„ dƒZ)G dd„ dej*ƒZ+G dd„ de!j#ƒZ,G dd„ dej-ƒZ.G dd„ de.ƒZ/G dd„ dej0ƒZ1G d d!„ d!e!j#ƒZ2eej3ƒG d"d#„ d#ƒƒZ4G d$d%„ d%ƒZ5d&d'„ Z6G d(d)„ d)e!j#ƒZ7G d*d+„ d+e!j#ƒZ8G d,d-„ d-ƒZ9G d.d/„ d/e!j#ƒZ:G d0d1„ d1ƒZ;d2Z<e"j=e<e>d3Z?d4Z@e"j=e@e>d3ZAG d5d6„ d6e;e!j#ƒZBG d7d8„ d8e;e!j#ƒZCG d9d:„ d:e1ƒZDG d;d<„ d<eBƒZEG d=d>„ d>eCƒZFG d?d@„ d@e1ƒZGG dAdB„ dBeBƒZHG dCdD„ dDeCƒZIG dEdF„ dFe!j#ƒZJG dGdH„ dHe!j#ƒZKdS )Iz-
Test cases for L{twisted.mail.pop3} module.
é    N)ÚOrderedDict)Úmd5)ÚBytesIO)Úimplementer)ÚcredÚinternetÚmail)Údefer)Úpop3)Úloopback)Úfailure)ÚLineSendingProtocol)ÚunittestÚutilc                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚUtilityTestszl
    Test the various helper functions and classes used by the POP3 server
    protocol implementation.
    c                 C   s¤   g }t t g d¢¡ƒ}t |j|d¡}t |ƒ}|  |g ¡ t|ƒ |  |g ¡ t|ƒ |  |g ¡ t|ƒ |  |g d¢¡ tdƒD ]}t|ƒ qA|  |g d¢¡ dS )zº
        Test creating a LineBuffer and feeding it some lines.  The lines should
        build up in its internal buffer for a while and then get spat out to
        the writer.
        )Ú012Ú345Ú6Ú7Ú8Ú9é   )r   r   r   é   )r   r   r   r   r   r   r   r   N)	ÚiterÚ	itertoolsÚcycler
   Ú_IteratorBufferÚextendÚassertEqualÚnextÚrange)ÚselfÚoutputÚinputÚcÚiÚn© r'   ú=/usr/lib/python3/dist-packages/twisted/mail/test/test_pop3.pyÚtest_LineBuffering'   s   
zUtilityTests.test_LineBufferingc                 C   s>   g }t g d¢ƒ}t |j|d¡}|D ]}q|  |g d¢¡ dS )z„
        Test that a LineBuffer flushes everything when its iterator is
        exhausted, and itself raises StopIteration.
        )ÚaÚbr$   r   N)r   r
   r   r   r   )r!   r"   r#   r$   r%   r'   r'   r(   Útest_FinishLineBuffering<   s   z%UtilityTests.test_FinishLineBufferingc                 C   s   |   t d¡d¡ dS )zb
        Test that the thing that spits out POP3 'success responses' works
        right.
        s   Great.s   +OK Great.
N)r   r
   ÚsuccessResponse©r!   r'   r'   r(   Útest_SuccessResponseFormatterH   s   z*UtilityTests.test_SuccessResponseFormatterc                 C   sD   t t g ¡ƒd }|  |d¡ t t g d¢¡ƒd }|  |d¡ dS )zX
        Test that the function which formats stat lines does so appropriately.
        éÿÿÿÿs	   +OK 0 0
)é
   é   r   iu'  s   +OK 4 10142
N)Úlistr
   ÚformatStatResponser   )r!   ÚstatLiner'   r'   r(   Útest_StatLineFormatterO   s   z#UtilityTests.test_StatLineFormatterc                 C   sD   t t g ¡ƒ}|  |ddg¡ t t g d¢¡ƒ}|  |g d¢¡ dS )z}
        Test that the function which formats the lines in response to a LIST
        command does so appropriately.
        ó   +OK 0
ó   .
)é   é   é   éd   )s   +OK 4
s   1 1
s   2 2
s   3 3
s   4 100
r8   N)r3   r
   ÚformatListResponser   )r!   Ú	listLinesr'   r'   r(   Útest_ListLineFormatterY   s   þz#UtilityTests.test_ListLineFormatterc                 C   sz   g d¢}t t g |j¡ƒ}|  |ddg¡ t t g d¢|j¡ƒ}|  |g d¢¡ t t g d¢|j¡ƒ}|  |g d¢¡ dS )	zy
        Test that the function which formats lines in response to a UIDL
        command does so appropriately.
        )ÚabcÚdefÚghió   +OK 
r8   )é{   i¯  éO  )rC   ó   1 abc
s   2 def
ó   3 ghi
r8   )r   NrE   )rC   rF   rG   r8   N)r3   r
   ÚformatUIDListResponseÚ__getitem__r   )r!   Úuidsr>   r'   r'   r(   Útest_UIDListLineFormatterg   s   ÿz&UtilityTests.test_UIDListLineFormatterN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r,   r/   r6   r?   rK   r'   r'   r'   r(   r   !   s    
r   c                   @   ó   e Zd ZdZdZdd„ ZdS )ÚMyVirtualPOP3z2
    A virtual-domain-supporting POP3 server.
    ó   <moshez>c                 C   s(   |   |¡\}}| jjd  ||| j|¡S )a7  
        Authenticate against a user against a virtual domain.

        @param user: The username.
        @param digest: The digested password.

        @return: A three-tuple like the one returned by
            L{IRealm.requestAvatar}.  The mailbox will be for the user given
            by C{user}.
        ó   baz.com)ÚlookupDomainÚserviceÚdomainsÚauthenticateUserAPOPÚmagic)r!   ÚuserÚdigestÚdomainr'   r'   r(   rW   €   s   
ÿz"MyVirtualPOP3.authenticateUserAPOPN©rL   rM   rN   rO   rX   rW   r'   r'   r'   r(   rQ   y   ó    rQ   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚDummyDomainz-
    A virtual domain for a POP3 server.
    c                 C   s
   i | _ d S ©N©Úusersr.   r'   r'   r(   Ú__init__–   s   
zDummyDomain.__init__c                 C   s   g | j |< dS )zV
        Create a mailbox for a new user.

        @param name: The username.
        Nr`   )r!   Únamer'   r'   r(   ÚaddUser™   ó   zDummyDomain.addUserc                 C   s   | j |  |¡ dS )zš
        Add a message to the mailbox of the named user.

        @param name: The username.
        @param message: The contents of the message.
        N)ra   Úappend)r!   rc   Úmessager'   r'   r(   Ú
addMessage¡   s   zDummyDomain.addMessagec                 C   s   t jt| j| ƒdd„ fS )ae  
        Succeed with a L{ListMailbox}.

        @param name: The name of the user authenticating.
        @param digest: ignored
        @param magic: ignored
        @param domain: ignored

        @return: A three-tuple like the one returned by
            L{IRealm.requestAvatar}.  The mailbox will be for the user given
            by C{name}.
        c                   S   ó   d S r_   r'   r'   r'   r'   r(   Ú<lambda>·   ó    z2DummyDomain.authenticateUserAPOP.<locals>.<lambda>)r
   ÚIMailboxÚListMailboxra   )r!   rc   rZ   rX   r[   r'   r'   r(   rW   ª   s   z DummyDomain.authenticateUserAPOPN)rL   rM   rN   rO   rb   rd   rh   rW   r'   r'   r'   r(   r^   ‘   s    	r^   c                   @   sB   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )rm   z@
    A simple in-memory list implementation of L{IMailbox}.
    c                 C   s
   || _ dS )z,
        @param list: The messages.
        N©r3   )r!   r3   r'   r'   r(   rb   ¿   ó   
zListMailbox.__init__Nc                 C   s&   |du rdd„ | j D ƒS t| j | ƒS )ú™
        Get some message information.

        @param i: See L{pop3.IMailbox.listMessages}.
        @return: See L{pop3.IMailbox.listMessages}.
        Nc                 S   ó   g | ]}t |ƒ‘qS r'   ©Úlen)Ú.0Úlr'   r'   r(   Ú
<listcomp>Í   ó    z,ListMailbox.listMessages.<locals>.<listcomp>)r3   rs   ©r!   r%   r'   r'   r(   ÚlistMessagesÅ   s   zListMailbox.listMessagesc                 C   ó   t | j| ƒS ©z
        Get the message content.

        @param i: See L{pop3.IMailbox.getMessage}.
        @return: See L{pop3.IMailbox.getMessage}.
        )r   r3   rx   r'   r'   r(   Ú
getMessageÐ   ó   zListMailbox.getMessagec                 C   s   |S )z¡
        Construct a UID by using the given index value.

        @param i: See L{pop3.IMailbox.getUidl}.
        @return: See L{pop3.IMailbox.getUidl}.
        r'   rx   r'   r'   r(   ÚgetUidlÙ   s   zListMailbox.getUidlc                 C   ó   d| j |< dS ©zm
        Wipe the message at the given index.

        @param i: See L{pop3.IMailbox.deleteMessage}.
        ó    Nrn   rx   r'   r'   r(   ÚdeleteMessageâ   re   zListMailbox.deleteMessagec                 C   ó   dS )z=
        No-op.

        @see: L{pop3.IMailbox.sync}
        Nr'   r.   r'   r'   r(   Úsyncê   rk   zListMailbox.syncr_   )
rL   rM   rN   rO   rb   ry   r|   r~   r‚   r„   r'   r'   r'   r(   rm   º   s    
		rm   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚMyPOP3DownloaderzE
    A POP3 client which downloads all messages from the server.
    c                 C   s   t j | |¡ |  dd¡ dS )zK
        Authenticate.

        @param line: The welcome response.
        s   hello@baz.coms   worldN)r
   Ú
POP3ClientÚhandle_WELCOMEÚapop©r!   Úliner'   r'   r(   r‡   ÷   s   zMyPOP3Downloader.handle_WELCOMEc                 C   sB   |  ¡ }|d }|dkrtd|› d|› dƒ‚g | _|  d¡ dS )zc
        Require an I{OK} response to I{APOP}.

        @param line: The I{APOP} response.
        r   ó   +OKz	code is: z , parts is: ú r9   N)ÚsplitÚAssertionErrorÚlinesÚretr)r!   rŠ   ÚpartsÚcoder'   r'   r(   Úhandle_APOP   s   zMyPOP3Downloader.handle_APOPc                 C   s   | j  |¡ dS )zh
        Record one line of message information.

        @param line: A I{RETR} response line.
        N)r   rf   r‰   r'   r'   r(   Úhandle_RETR_continue  ó   z%MyPOP3Downloader.handle_RETR_continuec                 C   s   d  | j¡d | _|  ¡  dS )z:
        Record the received message information.
        ó   
N)Újoinr   rg   Úquitr.   r'   r'   r(   Úhandle_RETR_end  s   z MyPOP3Downloader.handle_RETR_endc                 C   s    |dd… dkrt d| ƒ‚dS )zc
        Require an I{OK} response to I{QUIT}.

        @param line: The I{QUIT} response.
        Nr;   r‹   s   code is )rŽ   r‰   r'   r'   r(   Úhandle_QUIT  s   ÿzMyPOP3Downloader.handle_QUITN)	rL   rM   rN   rO   r‡   r“   r”   r™   rš   r'   r'   r'   r(   r…   ò   s    	r…   c                   @   sR   e Zd ZdZdZdeeƒf Zdd„ Zdd„ Zdd	„ Z	e
jd
dge	_dd„ ZdS )Ú	POP3Testsz!
    Tests for L{pop3.POP3}.
    s-   Subject: urgent

Someone set up us the bomb!
s{   +OK <moshez>
+OK Authentication succeeded
+OK 
1 0
.
+OK %d
Subject: urgent

Someone set up us the bomb!
.
+OK 
c                 C   sN   t j ¡ | _i | j_tƒ | jjd< | jjd  d¡ | jjd  d| j¡ dS )zC
        Set up a POP3 server with virtual domain support.
        rS   s   helloN)	r   ÚprotocolÚFactoryÚfactoryrV   r^   rd   rh   rg   r.   r'   r'   r(   ÚsetUpA  s
   zPOP3Tests.setUpc                    s:   t g d¢ƒ‰ tƒ }ˆj|_‡ ‡fdd„}t |ˆ ¡ |¡S )zL
        Messages can be downloaded over a loopback TCP connection.
        )s   APOP hello@baz.com worldó   UIDLó   RETR 1ó   QUITc                    s"   d  ˆ j¡d }ˆ |ˆj¡ d S )Nó   
)r—   Úresponser   ÚexpectedOutput)Úignoredr"   ©Úclientr!   r'   r(   ÚcheckZ  s   z&POP3Tests.test_messages.<locals>.check)r   rQ   rž   rU   r   ÚloopbackTCPÚaddCallback)r!   Úserverr©   r'   r§   r(   Útest_messagesK  s   ÿzPOP3Tests.test_messagesc                    s:   t ƒ ‰ˆjˆ_tƒ ‰ ‡ ‡‡fdd„}t ˆˆ ¡}| |¡S )zH
        Messages can be downloaded over a loopback connection.
        c                    s(   ˆ  ˆ jˆj¡ ˆ t tdƒ¡¡ d S )NúTest harness disconnect)r   rg   ÚconnectionLostr   ÚFailureÚ	Exception)r¦   ©ÚclientProtocolrœ   r!   r'   r(   r©   h  s   ÿz&POP3Tests.test_loopback.<locals>.check)rQ   rž   rU   r…   r   ÚloopbackAsyncr«   )r!   r©   Údr'   r²   r(   Útest_loopback`  s   
zPOP3Tests.test_loopbackz*twisted.mail.pop3.POP3Client is deprecated)rg   c                 C   sR   t j ¡ }i |_tƒ |jd< tƒ }||_|  tj	|j
dd¡}|  |jd d¡ dS )zP
        Look up a user in a domain which this server does not support.
        s   twistedmatrix.coms   nobody@baz.coms   passwordr   zno such domain baz.comN)r   rœ   r   rV   r^   rQ   rU   ÚassertRaisesr
   Ú	POP3ErrorrW   r   Úargs)r!   rž   r¬   Úexcr'   r'   r(   Útest_incorrectDomainu  s   
ÿzPOP3Tests.test_incorrectDomainN)rL   rM   rN   rO   rg   rs   r¥   rŸ   r­   r¶   r   Úsuppressr»   r'   r'   r'   r(   r›   &  s    ÿô

ÿr›   c                   @   rP   )Ú	DummyPOP3zF
    A simple POP3 server with a hard-coded mailbox for any user.
    rR   c                 C   s   t jttƒdd„ fS )zÎ
        Succeed with a L{DummyMailbox}.

        @param user: ignored
        @param password: ignored

        @return: A three-tuple like the one returned by
            L{IRealm.requestAvatar}.
        c                   S   ri   r_   r'   r'   r'   r'   r(   rj   –  rk   z0DummyPOP3.authenticateUserAPOP.<locals>.<lambda>©r
   rl   ÚDummyMailboxÚ
ValueError)r!   rY   Úpasswordr'   r'   r(   rW   Œ  s   
zDummyPOP3.authenticateUserAPOPNr\   r'   r'   r'   r(   r½   …  r]   r½   c                   @   ó   e Zd ZdZdd„ ZdS )ÚDummyPOP3AuthzL
    Class to test successful authentication in twisted.mail.pop3.POP3.
    c                 C   s6   t j tƒ ¡| _t j ¡ }| ||¡ | j |¡ d S r_   )r   ÚportalÚPortalÚ	TestRealmÚcheckersÚ'InMemoryUsernamePasswordDatabaseDontUserd   ÚregisterChecker)r!   rY   rÁ   Úchr'   r'   r(   rb   ž  s   
zDummyPOP3Auth.__init__N)rL   rM   rN   rO   rb   r'   r'   r'   r(   rÃ   ™  ó    rÃ   c                   @   s@   e Zd ZdZdgZdd„ Zddd„Zdd	„ Zd
d„ Zdd„ Z	dS )r¿   zý
    An in-memory L{pop3.IMailbox} implementation.

    @ivar messages: A sequence of L{bytes} defining the messages in this
        mailbox.

    @ivar exceptionType: The type of exception to raise when an out-of-bounds
        index is addressed.
    s,   From: moshe
To: moshe

How are you, friend?
c                 C   s   t jd d … | _|| _d S r_   )r¿   ÚmessagesÚexceptionType)r!   rÍ   r'   r'   r(   rb   ²  s   
zDummyMailbox.__init__Nc                 C   s<   |du rdd„ | j D ƒS |t| j ƒkr|  ¡ ‚t| j | ƒS )rp   Nc                 S   rq   r'   rr   )rt   Úmr'   r'   r(   rv   ¾  rw   z-DummyMailbox.listMessages.<locals>.<listcomp>)rÌ   rs   rÍ   rx   r'   r'   r(   ry   ¶  s
   zDummyMailbox.listMessagesc                 C   rz   r{   )r   rÌ   rx   r'   r'   r(   r|   Ã  r}   zDummyMailbox.getMessagec                 C   s    |t | jƒkr|  ¡ ‚d|f S )zÇ
        Construct a UID which is simply the string representation of the given
        index.

        @param i: See L{pop3.IMailbox.getUidl}.
        @return: See L{pop3.IMailbox.getUidl}.
        s   %d)rs   rÌ   rÍ   rx   r'   r'   r(   r~   Ì  s   
zDummyMailbox.getUidlc                 C   r   r€   )rÌ   rx   r'   r'   r(   r‚   Ø  re   zDummyMailbox.deleteMessager_   )
rL   rM   rN   rO   rÌ   rb   ry   r|   r~   r‚   r'   r'   r'   r(   r¿   ¥  s    

	r¿   c                   @   sä   e Zd ZdZd5dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
ddg g fdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ ZdS )6ÚAnotherPOP3Testsz(
    Additional L{pop3.POP3} tests.
    Nc                 C   s4   |r|nt ƒ }t|ƒ}t ||¡}| | j|||¡S )aO  
        Assert that when C{lines} are delivered to L{pop3.POP3} it responds
        with C{expectedOutput}.

        @param lines: A sequence of L{bytes} representing lines to deliver to
            the server.

        @param expectedOutput: A sequence of L{bytes} representing the
            expected response from the server.

        @param protocolInstance: Instance of L{twisted.mail.pop3.POP3} or
            L{None}. If L{None}, a new DummyPOP3 will be used.

        @return: A L{Deferred} that fires when the lines have been delivered
            and the output checked.
        )r½   r   r   r´   r«   Ú
_cbRunTest)r!   r   r¥   ÚprotocolInstanceÚdummyr¨   rµ   r'   r'   r(   ÚrunTestæ  s   zAnotherPOP3Tests.runTestc                 C   s2   |   d |¡d |j¡¡ | t tdƒ¡¡ |S )Nr£   r®   )r   r—   r¤   r¯   r   r°   r±   )r!   r¦   r¨   rÒ   r¥   r'   r'   r(   rÐ   ü  s   zAnotherPOP3Tests._cbRunTestc                 C   ó   |   g d¢g d¢¡S )a4  
        Test a lot of different POP3 commands in an extremely pipelined
        scenario.

        This test may cover legitimate behavior, but the intent and
        granularity are not very good.  It would likely be an improvement to
        split it into a number of smaller, more focused tests.
        )s   APOP moshez dummyó   LISTr    r¡   ó   RETR 2s   DELE 1r¡   r¢   )ó   +OK <moshez>ó   +OK Authentication succeededs   +OK 1s   1 44ó   .ó   +OK s   1 0rÙ   s   +OK 44s   From: moshes	   To: mosher   s   How are you, friend?rÙ   s    -ERR Bad message number argumentrÚ   s   -ERR message deletedrÚ   ©rÓ   r.   r'   r'   r(   Útest_buffer  s   	
õzAnotherPOP3Tests.test_bufferc                 C   rÔ   )z)
        Test the no-op command.
        )s   APOP spiv dummys   NOOPr¢   )r×   rØ   rÚ   rÚ   rÛ   r.   r'   r'   r(   Ú	test_noop+  s   þzAnotherPOP3Tests.test_noopc                 C   s>   d}|   ddgdd| dg¡}|  tj¡}|  t|ƒd¡ |S )zi
        Sending a command with invalid UTF-8 characters
        will raise a L{pop3.POP3Error}.
        s&   not authenticated yet: cannot do PASSs   PASSr¢   r×   s(   -ERR bad protocol or server: POP3Error: rÚ   r9   )rÓ   ÚflushLoggedErrorsr
   r¸   r   rs   )r!   Úerrorrµ   Úerrorsr'   r'   r(   Útest_badUTF8CharactersInCommand4  s   ýþz0AnotherPOP3Tests.test_badUTF8CharactersInCommandc                 C   sH   t ƒ }tj ¡ |_ddddœ|j_tddgƒ}t ||¡}| 	| j
|¡S )zš
        L{pop3.POP3} responds to an I{AUTH} command with a list of supported
        authentication types based on its factory's C{challengers}.
        N)s   Auth1s
   secondAuths   authLasts   AUTHr¢   )r½   r   rœ   r   rž   Úchallengersr   r   r´   r«   Ú_cbTestAuthListing)r!   Úpr¨   rµ   r'   r'   r(   Útest_authListingF  s   þÿz!AnotherPOP3Tests.test_authListingc                 C   sJ   |   |jd  d¡¡ |  t|jdd… ƒg d¢¡ |  |jd d¡ d S )Nr9   r‹   r:   r   )s   AUTH1s   AUTHLASTs
   SECONDAUTHrÙ   )Ú
assertTruer¤   Ú
startswithr   Úsorted)r!   r¦   r¨   r'   r'   r(   rã   X  s
   ÿz#AnotherPOP3Tests._cbTestAuthListingc           	      C   s~   |s|}|s|}g d¢}||kr||krg d¢}d  d|g¡d  d|g¡g}||dg 7 }||dg 7 }| j||t||ƒdS )	aÝ  
        Test a login with PASS.

        If L{real_user} matches L{tried_user} and L{real_password} matches
        L{tried_password}, a successful login will be expected.
        Otherwise an unsuccessful login will be expected.

        @type real_user: L{bytes}
        @param real_user: The user to test.

        @type real_password: L{bytes}
        @param real_password: The password of the test user.

        @type tried_user: L{bytes} or L{None}
        @param tried_user: The user to call USER with.
            If None, real_user will be used.

        @type tried_password: L{bytes} or L{None}
        @param tried_password: The password to call PASS with.
            If None, real_password will be used.

        @type after_auth_input: L{list} of l{bytes}
        @param after_auth_input: Extra protocol input after authentication.

        @type after_auth_output: L{list} of l{bytes}
        @param after_auth_output: Extra protocol output after authentication.
        )r×   ó   +OK USER accepted, send PASSs   -ERR Authentication failed)r×   ré   rØ   ó    ó   USERó   PASSr¢   rÚ   )rÑ   )r—   rÓ   rÃ   )	r!   Ú	real_userÚreal_passwordÚ
tried_userÚtried_passwordÚafter_auth_inputÚafter_auth_outputr¤   Ú	fullInputr'   r'   r(   Úrun_PASS_  s"   $þýzAnotherPOP3Tests.run_PASSc                 C   s   |   d d|g¡dgg d¢¡S )z
        Test protocol violation produced by calling PASS before USER.
        @type password: L{bytes}
        @param password: A password to test.
        rê   rì   r¢   )r×   s   -ERR USER required before PASSrÚ   )rÓ   r—   )r!   rÁ   r'   r'   r(   Úrun_PASS_before_USER   s   þz%AnotherPOP3Tests.run_PASS_before_USERc                 C   ó
   |   d¡S )z>
        Test PASS before USER with a wrong password.
        ó   fooz©rõ   r.   r'   r'   r(   Útest_illegal_PASS_before_USER«  ro   z.AnotherPOP3Tests.test_illegal_PASS_before_USERc                 C   rö   )z?
        Test PASS before USER with an empty password.
        r   rø   r.   r'   r'   r(   Útest_empty_PASS_before_USER±  ro   z,AnotherPOP3Tests.test_empty_PASS_before_USERc                 C   rö   )zI
        Test PASS before USER with an password that is a space.
        rê   rø   r.   r'   r'   r(   Útest_one_space_PASS_before_USER·  ro   z0AnotherPOP3Tests.test_one_space_PASS_before_USERc                 C   rö   )zK
        Test PASS before USER with a password containing a space.
        ó	   fooz barzrø   r.   r'   r'   r(   Útest_space_PASS_before_USER½  ro   z,AnotherPOP3Tests.test_space_PASS_before_USERc                 C   rö   )zS
        Test PASS before USER with a password containing multiple spaces.
        ó   fooz barz asdfrø   r.   r'   r'   r(   Ú%test_multiple_spaces_PASS_before_USERÃ  ro   z6AnotherPOP3Tests.test_multiple_spaces_PASS_before_USERc                 C   rö   )zS
        Test PASS before USER with a password containing tabs and spaces.
        ó   fooz barz	crazy@! 	 rø   r.   r'   r'   r(   Ú&test_other_whitespace_PASS_before_USERÉ  ro   z7AnotherPOP3Tests.test_other_whitespace_PASS_before_USERc                 C   ó   |   dd¡S )z1
        Test PASS with a good password.
        ó   testuserr÷   ©rô   r.   r'   r'   r(   Útest_good_PASSÏ  ó   zAnotherPOP3Tests.test_good_PASSc                 C   r  )ú?
        Test PASS with a password containing a space.
        r  rü   r  r.   r'   r'   r(   Útest_space_PASSÕ  r  z AnotherPOP3Tests.test_space_PASSc                 C   r  )r  r  rþ   r  r.   r'   r'   r(   Útest_multiple_spaces_PASSÛ  r  z*AnotherPOP3Tests.test_multiple_spaces_PASSc                 C   r  ©zG
        Test PASS with a password containing tabs and spaces.
        r  r   r  r.   r'   r'   r(   Útest_other_whitespace_PASSá  r  z+AnotherPOP3Tests.test_other_whitespace_PASSc                 C   ó   | j ddddS )z.
        Test PASS with a wrong user.
        r  r÷   s	   wronguser)rï   r  r.   r'   r'   r(   Útest_pass_wrong_userç  ó   z%AnotherPOP3Tests.test_pass_wrong_userc                 C   r  )z2
        Test PASS with a wrong password.
        r  r÷   s   barz©rð   r  r.   r'   r'   r(   Útest_wrong_PASSí  r  z AnotherPOP3Tests.test_wrong_PASSc                 C   r  )r  r  rü   s	   foozbarz r  r  r.   r'   r'   r(   Útest_wrong_space_PASSó  r  z&AnotherPOP3Tests.test_wrong_space_PASSc                 C   r  )r  r  rþ   s   foozbarz   r  r  r.   r'   r'   r(   Útest_wrong_multiple_spaces_PASSù  s   ÿz0AnotherPOP3Tests.test_wrong_multiple_spaces_PASSc                 C   r  r
  r  r.   r'   r'   r(   Ú test_wrong_other_whitespace_PASS  r  z1AnotherPOP3Tests.test_wrong_other_whitespace_PASSc                 C   s4   dg}d  ddg¡g}| jdd||d | jtj¡S )zM
        After logging in, test a dummy command that is not defined.
        s   DUMMY COMMANDrê   s'   -ERR bad protocol or server: POP3Error:s   Unknown protocol command: DUMMYr  ó   testpassword)rñ   rò   )r—   rô   r«   rÞ   r
   r¸   )r!   Úextra_inputÚextra_outputr'   r'   r(   Útest_wrong_command  s   þÿÿ	üûz#AnotherPOP3Tests.test_wrong_commandr_   )rL   rM   rN   rO   rÓ   rÐ   rÜ   rÝ   rá   rå   rã   rô   rõ   rù   rú   rû   rý   rÿ   r  r  r  r	  r  r  r  r  r  r  r  r'   r'   r'   r(   rÏ   á  s>    
*	
ùArÏ   c                   @   sL   e Zd ZdZdd„ Zdd„ ZeddgƒZdd	„ Zd
Z	dd„ Z
d
Zdd„ ZdS )ÚTestServerFactoryz÷
    A L{pop3.IServerFactory} implementation, for use by the test suite, with
    some behavior controlled by the values of (settable) public attributes and
    other behavior based on values hard-coded both here and in some test
    methods.
    c                 C   rƒ   )úW
        Return the hard-coded value.

        @return: L{pop3.IServerFactory}
        zTest Implementation Stringr'   r.   r'   r'   r(   Úcap_IMPLEMENTATION&  ó   z$TestServerFactory.cap_IMPLEMENTATIONc                 C   rƒ   )r  é<   r'   r.   r'   r'   r(   Ú
cap_EXPIRE.  r  zTestServerFactory.cap_EXPIRE)s   SCHEME_1N)s   SCHEME_2Nc                 C   rƒ   )r  éx   r'   r.   r'   r'   r(   Úcap_LOGIN_DELAY8  r  z!TestServerFactory.cap_LOGIN_DELAYTc                 C   ó   | j S ©r  )Úpuer.   r'   r'   r(   ÚperUserExpirationB  ó   z#TestServerFactory.perUserExpirationc                 C   r   r!  )Úpuldr.   r'   r'   r(   ÚperUserLoginDelayL  r$  z#TestServerFactory.perUserLoginDelayN)rL   rM   rN   rO   r  r  r   râ   r  r"  r#  r%  r&  r'   r'   r'   r(   r    s    r  c                   @   s   e Zd ZdZdZdZdS )ÚTestMailboxz×
    An incomplete L{IMailbox} implementation with certain per-user values
    hard-coded and known by tests in this module.


    This is useful for testing the server's per-user capability
    implementation.
    r<   é   N)rL   rM   rN   rO   Ú
loginDelayÚmessageExpirationr'   r'   r'   r(   r'  U  s    	r'  c                 G   s   |D ]}|   ||¡ qdS )aG  
    Assert that the given capability is included in all of the capability
    sets.

    @param testcase: A L{unittest.TestCase} to use to make assertions.

    @param s: The capability for which to check.
    @type s: L{bytes}

    @param caps: The capability sets in which to check.
    @type caps: L{tuple} of iterable
    N)ÚassertIn)ÚtestcaseÚsÚcapsr$   r'   r'   r(   Ú	containedc  s   ÿr/  c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚCapabilityTestsz@
    Tests for L{pop3.POP3}'s per-user capability handling.
    c                 C   s–   t ƒ }t ¡ }tƒ |_tj |¡|_| 	¡  | 
¡  | ¡ | _| ¡  ¡ | _t ƒ }tƒ |_tj |¡|_| 
¡  | ¡  ¡ | _| t tdƒ¡¡ dS )ú>
        Create a POP3 server with some capabilities.
        r®   N)r   r
   ÚPOP3r  rž   r   rœ   ÚFileWrapperÚ	transportÚconnectionMadeÚdo_CAPAÚlistCapabilitiesr.  ÚgetvalueÚ
splitlinesÚpcapsr'  ÚmboxÚlpcapsr¯   r   r°   r±   ©r!   r-  rä   r'   r'   r(   rŸ   y  s   
zCapabilityTests.setUpc                 C   ó   t | d| j| j| jƒ dS )zB
        The server can advertise the I{UIDL} capability.
        r    N©r/  r.  r:  r<  r.   r'   r'   r(   Ú	test_UIDL  ó   zCapabilityTests.test_UIDLc                 C   r>  )zA
        The server can advertise the I{TOP} capability.
        s   TOPNr?  r.   r'   r'   r(   Útest_TOP•  rA  zCapabilityTests.test_TOPc                 C   r>  )zB
        The server can advertise the I{USER} capability.
        rë   Nr?  r.   r'   r'   r(   Ú	test_USER›  rA  zCapabilityTests.test_USERc                 C   s$   t | d| j| jƒ t | d| jƒ dS )zj
        The server can advertise its per-user expiration as well as a global
        expiration.
        s   EXPIRE 60 USERs	   EXPIRE 25Nr?  r.   r'   r'   r(   Útest_EXPIRE¡  ó   zCapabilityTests.test_EXPIREc                 C   r>  )zE
        The server can advertise its implementation string.
        s)   IMPLEMENTATION Test Implementation StringNr?  r.   r'   r'   r(   Útest_IMPLEMENTATION©  s   ûz#CapabilityTests.test_IMPLEMENTATIONc                 C   r>  )zH
        The server can advertise the SASL schemes it supports.
        s   SASL SCHEME_1 SCHEME_2Nr?  r.   r'   r'   r(   Ú	test_SASLµ  rA  zCapabilityTests.test_SASLc                 C   s$   t | d| j| jƒ |  d| j¡ dS )zc
        The can advertise a per-user login delay as well as a global login
        delay.
        s   LOGIN-DELAY 120 USERs   LOGIN-DELAY 100N)r/  r.  r:  r+  r<  r.   r'   r'   r(   Útest_LOGIN_DELAY»  rE  z CapabilityTests.test_LOGIN_DELAYN)rL   rM   rN   rO   rŸ   r@  rB  rC  rD  rF  rG  rH  r'   r'   r'   r(   r0  t  s    r0  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚGlobalCapabilitiesTestsz>
    Tests for L{pop3.POP3}'s global capability handling.
    c                 C   s¦   t ƒ }t ¡ }tƒ |_d |j_|j_tj 	|¡|_
| ¡  | ¡  | ¡ | _| ¡  ¡ | _t ƒ }tƒ |_tj 	|¡|_
| ¡  | ¡  ¡ | _| t tdƒ¡¡ dS )r1  Fr®   N)r   r
   r2  r  rž   r"  r%  r   rœ   r3  r4  r5  r6  r7  r.  r8  r9  r:  r'  r;  r<  r¯   r   r°   r±   r=  r'   r'   r(   rŸ   É  s   
zGlobalCapabilitiesTests.setUpc                 C   r>  )zG
        I{EXPIRE} is in the server's advertised capabilities.
        s	   EXPIRE 60Nr?  r.   r'   r'   r(   rD  à  rA  z#GlobalCapabilitiesTests.test_EXPIREc                 C   r>  )zL
        I{LOGIN-DELAY} is in the server's advertised capabilities.
        s   LOGIN-DELAY 120Nr?  r.   r'   r'   r(   rH  æ  rA  z(GlobalCapabilitiesTests.test_LOGIN_DELAYN)rL   rM   rN   rO   rŸ   rD  rH  r'   r'   r'   r(   rI  Ä  s
    rI  c                   @   rÂ   )rÆ   zI
    An L{IRealm} which knows about a single test account's mailbox.
    c                 G   s    |dkrt jttƒdd„ fS J ‚)aE  
        Retrieve a mailbox for I{testuser} or fail.

        @param avatarId: See L{IRealm.requestAvatar}.
        @param mind: See L{IRealm.requestAvatar}.
        @param interfaces: See L{IRealm.requestAvatar}.

        @raises: L{AssertionError} when requesting an C{avatarId} other than
            I{testuser}.
        r  c                   S   ri   r_   r'   r'   r'   r'   r(   rj   þ  rk   z)TestRealm.requestAvatar.<locals>.<lambda>r¾   )r!   ÚavatarIdÚmindÚ
interfacesr'   r'   r(   ÚrequestAvatarò  s   zTestRealm.requestAvatarN)rL   rM   rN   rO   rM  r'   r'   r'   r(   rÆ   í  rË   rÆ   c                   @   rÂ   )Ú	SASLTestsz7
    Tests for L{pop3.POP3}'s SASL implementation.
    c                 C   s.  t  ¡ }tƒ |_dtjji|j_tj 	t
ƒ ¡|_tj ¡ }| dd¡ |j |¡ tƒ }tj |¡|_| ¡  | d¡ |  | ¡  d¡dk¡ | d¡ | ¡  ¡ d d	d
… }t |¡}tjd|td ¡   d¡}| t !d| ¡¡ |  |j"¡ |  | ¡  ¡ d  d¡dk¡ | #t$ %t&dƒ¡¡ d
S )z
        A CRAM-MD5-based SASL login attempt succeeds if it uses a username and
        a hashed password known to the server's credentials checker.
        s   CRAM-MD5r  r  s   CAPAs   SASL CRAM-MD5r   s   AUTH CRAM-MD5r0   r:   N)Ú	digestmodÚasciis	   testuser r‹   r®   )'r
   r2  r  rž   r   ÚcredentialsÚCramMD5Credentialsrâ   rÄ   rÅ   rÆ   rÇ   rÈ   rd   rÉ   r   r   rœ   r3  r4  r5  ÚlineReceivedræ   r8  Úfindr9  Úbase64Ú	b64decodeÚhmacÚHMACr   Ú	hexdigestÚencodeÚ	b64encoder;  r¯   r   r°   r±   )r!   rä   rÊ   r-  Úchalr¤   r'   r'   r(   Útest_ValidLogin  s*   



ÿ zSASLTests.test_ValidLoginN)rL   rM   rN   rO   r]  r'   r'   r'   r(   rN    rË   rN  c                   @   sœ   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%S )&ÚCommandMixinzI
    Tests for all the commands a POP3 server is allowed to receive.
    s1   From: guy
To: fellow

More message text for you.
c                 C   s\   t  ¡ }|  | j¡|_t|_|| _tƒ }t	j
 |¡|_| ¡  | d¡ | d¡ || _dS )zŽ
        Make a POP3 server protocol instance hooked up to a simple mailbox and
        a transport that buffers output to a BytesIO.
        r   N)r
   r2  ÚmailboxTyperÍ   r;  r3   ÚscheduleÚ
pop3Serverr   r   rœ   r3  r4  r5  ÚseekÚtruncateÚpop3Transport©r!   rä   r-  r'   r'   r(   rŸ   4  s   


zCommandMixin.setUpc                 C   s   | j  t tdƒ¡¡ dS )zo
        Disconnect the server protocol so it can clean up anything it might
        need to clean up.
        r®   N)ra  r¯   r   r°   r±   r.   r'   r'   r(   ÚtearDownE  s   ÿzCommandMixin.tearDownc                 C   s   | j j ¡  dS )zz
        Do some of the things that the reactor would take care of, if the
        reactor were actually running.
        N)ra  r4  Ú_checkProducerr.   r'   r'   r(   Ú_flushN  r•   zCommandMixin._flushc                 C   sh   | j }| j}| d¡ |  ¡  |  | ¡ d¡ | d¡ | d¡ | d¡ |  ¡  |  | ¡ d¡ dS )zé
        Test the two forms of list: with a message index number, which should
        return a short-form response, and without a message index number, which
        should return a long-form response, one line per message.
        s   LIST 1ó
   +OK 1 44
r   rÕ   s   +OK 1
1 44
.
N©ra  rd  rS  rh  r   r8  rb  rc  re  r'   r'   r(   Ú	test_LISTV  s   



zCommandMixin.test_LISTc                 C   sš   | j }| j}| d¡ |  | ¡ d¡ | d¡ | d¡ | d¡ |  | ¡ d¡ | d¡ | d¡ | d¡ |  | ¡ d¡ | d¡ | d¡ dS )	zo
        Test that non-integers and out-of-bound integers produce appropriate
        error responses.
        s   LIST as    -ERR Invalid message-number: a
r   s   LIST 0s    -ERR Invalid message-number: 0
s   LIST 2s    -ERR Invalid message-number: 2
N©ra  rd  rS  r   r8  rb  rc  re  r'   r'   r(   Útest_LISTWithBadArgumenti  ó   







z%CommandMixin.test_LISTWithBadArgumentc                 C   s`   | j }| j}| d¡ |  | ¡ d¡ | d¡ | d¡ | d¡ |  ¡  |  | ¡ d¡ dS )zy
        Test the two forms of the UIDL command.  These are just like the two
        forms of the LIST command.
        s   UIDL 1r7   r   r    s   +OK 
1 0
.
N)ra  rd  rS  r   r8  rb  rc  rh  re  r'   r'   r(   r@  €  s   



zCommandMixin.test_UIDLc                 C   óš   | j }| j}| d¡ |  | ¡ d¡ | d¡ | d¡ | d¡ |  | ¡ d¡ | d¡ | d¡ | d¡ |  | ¡ d¡ | d¡ | d¡ dS )z€
        Test that UIDL with a non-integer or an out-of-bounds integer produces
        the appropriate error response.
        s   UIDL aó"   -ERR Bad message number argument
r   s   UIDL 0s   UIDL 2Nrl  re  r'   r'   r(   Útest_UIDLWithBadArgument‘  rn  z%CommandMixin.test_UIDLWithBadArgumentc                 C   s2   | j }| j}| d¡ |  ¡  |  | ¡ d¡ dS )z¦
        Test the single form of the STAT command, which returns a short-form
        response of the number of messages in the mailbox and their total size.
        s   STATri  N)ra  rd  rS  rh  r   r8  re  r'   r'   r(   Ú	test_STAT¨  s
   
zCommandMixin.test_STATc                 C   sF   | j }| j}| d¡ |  ¡  |  | ¡ d¡ | d¡ | d¡ dS )z-
        Test downloading a message.
        r¡   s;   +OK 44
From: moshe
To: moshe

How are you, friend?
.
r   Nrj  re  r'   r'   r(   Ú	test_RETR´  s   
þ
	zCommandMixin.test_RETRc                 C   ro  )z»
        Test that trying to download a message with a bad argument, either not
        an integer or an out-of-bounds integer, fails with the appropriate
        error response.
        s   RETR arp  r   s   RETR 0rÖ   Nrl  re  r'   r'   r(   Útest_RETRWithBadArgumentÉ  s   







z%CommandMixin.test_RETRWithBadArgumentc                 C   sB   | j }| j}|jj | j¡ | d¡ |  ¡  |  | 	¡ d¡ dS )zQ
        Test downloading the headers and part of the body of a message.
        s   TOP 1 0s9   +OK Top of message follows
From: moshe
To: moshe

.
N)
ra  rd  r;  rÌ   rf   ÚextraMessagerS  rh  r   r8  re  r'   r'   r(   rB  á  s   
þzCommandMixin.test_TOPc                 C   s  | j }| j}|jj | j¡ | d¡ |  | ¡ d¡ | 	d¡ | 
d¡ | d¡ |  | ¡ d¡ | 	d¡ | 
d¡ | d¡ |  | ¡ d¡ | 	d¡ | 
d¡ | d¡ |  | ¡ d¡ | 	d¡ | 
d¡ | d¡ |  | ¡ d¡ | 	d¡ | 
d¡ d	S )
a$  
        Test that trying to download a message with a bad argument, either a
        message number which isn't an integer or is an out-of-bounds integer or
        a number of lines which isn't an integer or is a negative integer,
        fails with the appropriate error response.
        s   TOP 1 as   -ERR Bad line count argument
r   s   TOP 1 -1s   TOP a 1rp  s   TOP 0 1s   TOP 3 1N©ra  rd  r;  rÌ   rf   ru  rS  r   r8  rb  rc  re  r'   r'   r(   Útest_TOPWithBadArgumentô  s.   













z$CommandMixin.test_TOPWithBadArgumentc                 C   sN   | j }| j}|jj | j¡ | d¡ |  | ¡ d¡ | 	d¡ | 
d¡ dS )z“
        Test the exceedingly pointless LAST command, which tells you the
        highest message index which you have already downloaded.
        ó   LASTr7   r   Nrv  re  r'   r'   r(   Ú	test_LAST  s   

zCommandMixin.test_LASTc                 C   st   | j }| j}|jj | j¡ | d¡ |  ¡  | d¡ | 	d¡ | d¡ |  
| ¡ d¡ | d¡ | 	d¡ dS )zM
        Test that issuing a RETR command updates the LAST response.
        rÖ   r   rx  ó   +OK 2
N©ra  rd  r;  rÌ   rf   ru  rS  rh  rb  rc  r   r8  re  r'   r'   r(   Útest_RetrieveUpdatesHighest&  s   




z(CommandMixin.test_RetrieveUpdatesHighestc                 C   s`   | j }| j}|jj | j¡ | d¡ |  ¡  | d¡ | 	d¡ | d¡ |  
| ¡ d¡ dS )zL
        Test that issuing a TOP command updates the LAST response.
        s   TOP 2 10r   rx  rz  Nr{  re  r'   r'   r(   Útest_TopUpdatesHighest7  s   



z#CommandMixin.test_TopUpdatesHighestc                 C   sr   | j }| j}|jj | j¡ | d¡ |  ¡  | d¡ |  ¡  | d¡ | 	d¡ | d¡ |  
| ¡ d¡ dS )z
        Test that downloading a message with a smaller index than the current
        LAST response doesn't change the LAST response.
        rÖ   s   TOP 1 10r   rx  rz  Nr{  re  r'   r'   r(   Útest_HighestOnlyProgressesF  s   




z'CommandMixin.test_HighestOnlyProgressesc                 C   sj   | j }| j}|jj | j¡ | d¡ |  ¡  | d¡ | d¡ | 	d¡ | d¡ |  
| ¡ d¡ dS )zH
        Test that issuing RSET changes the LAST response to 0.
        rÖ   s   RSETr   rx  r7   Nr{  re  r'   r'   r(   Útest_ResetClearsHighestX  s   




z$CommandMixin.test_ResetClearsHighestN)rL   rM   rN   rO   ru  rŸ   rf  rh  rk  rm  r@  rq  rr  rs  rt  rB  rw  ry  r|  r}  r~  r  r'   r'   r'   r(   r^  (  s(    	$r^  z}twisted.mail.pop3.IMailbox.listMessages may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.)rg   Úcategoryzxtwisted.mail.pop3.IMailbox.getUidl may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.c                   @   sX   e Zd ZdZeZeZdd„ Ze	ge_
dd„ Zege_
dd„ Ze	ge_
dd	„ Ze	ge_
d
S )ÚIndexErrorCommandTestsz»
    Run all of the command tests against a mailbox which raises IndexError
    when an out of bounds request is made.  This behavior will be deprecated
    shortly and then removed.
    c                 C   ó
   t  | ¡S )z·
        An attempt to get metadata about a message with a bad argument fails
        with an I{ERR} response even if the mailbox implementation raises
        L{IndexError}.
        )r^  rm  r.   r'   r'   r(   rm  †  ó   
z/IndexErrorCommandTests.test_LISTWithBadArgumentc                 C   r‚  )z·
        An attempt to look up the UID of a message with a bad argument fails
        with an I{ERR} response even if the mailbox implementation raises
        L{IndexError}.
        )r^  rq  r.   r'   r'   r(   rq    rƒ  z/IndexErrorCommandTests.test_UIDLWithBadArgumentc                 C   r‚  )zµ
        An attempt to download some of a message with a bad argument fails with
        an I{ERR} response even if the mailbox implementation raises
        L{IndexError}.
        )r^  rw  r.   r'   r'   r(   rw  š  rƒ  z.IndexErrorCommandTests.test_TOPWithBadArgumentc                 C   r‚  )z­
        An attempt to download a message with a bad argument fails with an
        I{ERR} response even if the mailbox implementation raises
        L{IndexError}.
        )r^  rt  r.   r'   r'   r(   rt  ¤  rƒ  z/IndexErrorCommandTests.test_RETRWithBadArgumentN)rL   rM   rN   rO   Ú
IndexErrorrÍ   r¿   r_  rm  Ú_listMessageSuppressionr¼   rq  Ú_getUidlSuppressionrw  rt  r'   r'   r'   r(   r  |  s    r  c                   @   s   e Zd ZdZeZeZdS )ÚValueErrorCommandTestsa  
    Run all of the command tests against a mailbox which raises ValueError
    when an out of bounds request is made.  This is the correct behavior and
    after support for mailboxes which raise IndexError is removed, this will
    become just C{CommandTestCase}.
    N)rL   rM   rN   rO   rÀ   rÍ   r¿   r_  r'   r'   r'   r(   r‡  ¯  s    r‡  c                   @   s   e Zd ZdZddd„ZdS )ÚSyncDeferredMailboxzo
    Mailbox which has a listMessages implementation which returns a Deferred
    which has already fired.
    Nc                 C   s   t  t | |¡¡S )zÏ
        Synchronously list messages.

        @type n: L{int} or L{None}
        @param n: The 0-based index of the message.

        @return: A L{Deferred} which already has a message list result.
        )r	   Úsucceedr¿   ry   )r!   r&   r'   r'   r(   ry   Á  s   	z SyncDeferredMailbox.listMessagesr_   )rL   rM   rN   rO   ry   r'   r'   r'   r(   rˆ  »  s    rˆ  c                   @   ó   e Zd ZdZeZdS )Ú"IndexErrorSyncDeferredCommandTestsz{
    Run all of the L{IndexErrorCommandTests} tests with a
    synchronous-Deferred returning IMailbox implementation.
    N©rL   rM   rN   rO   rˆ  r_  r'   r'   r'   r(   r‹  Í  ó    r‹  c                   @   rŠ  )Ú"ValueErrorSyncDeferredCommandTestsz{
    Run all of the L{ValueErrorCommandTests} tests with a
    synchronous-Deferred returning IMailbox implementation.
    NrŒ  r'   r'   r'   r(   rŽ  Ö  r  rŽ  c                   @   s"   e Zd ZdZdd„ Zddd„ZdS )ÚAsyncDeferredMailboxzo
    Mailbox which has a listMessages implementation which returns a Deferred
    which has not yet fired.
    c                 O   s"   g | _ tj| g|¢R i |¤Ž d S r_   )Úwaitingr¿   rb   )r!   r*   Úkwr'   r'   r(   rb   å  s   zAsyncDeferredMailbox.__init__Nc                 C   s$   t  ¡ }| j |t | |¡f¡ |S )zÎ
        Record a new unfired L{Deferred} in C{self.waiting} and return it.

        @type n: L{int} or L{None}
        @param n: The 0-based index of the message.

        @return: The L{Deferred}
        )r	   ÚDeferredr  rf   r¿   ry   )r!   r&   rµ   r'   r'   r(   ry   é  s   	z!AsyncDeferredMailbox.listMessagesr_   )rL   rM   rN   rO   rb   ry   r'   r'   r'   r(   r  ß  s    r  c                   @   ó   e Zd ZdZeZdd„ ZdS )Ú#IndexErrorAsyncDeferredCommandTestsú}
    Run all of the L{IndexErrorCommandTests} tests with an
    asynchronous-Deferred returning IMailbox implementation.
    c                 C   ó>   | j jjr| j jj ¡ \}}| |¡ | j jjst | ¡ dS ©zH
        Fire whatever Deferreds we've built up in our mailbox.
        N)ra  r;  r  ÚpopÚcallbackr  rh  ©r!   rµ   r*   r'   r'   r(   rh     ó
   


þz*IndexErrorAsyncDeferredCommandTests._flushN©rL   rM   rN   rO   r  r_  rh  r'   r'   r'   r(   r”  ø  ó    r”  c                   @   r“  )Ú#ValueErrorAsyncDeferredCommandTestsr•  c                 C   r–  r—  )ra  r;  r  r˜  r™  r‡  rh  rš  r'   r'   r(   rh    r›  z*ValueErrorAsyncDeferredCommandTests._flushNrœ  r'   r'   r'   r(   rž  
  r  rž  c                   @   rÂ   )ÚPOP3MiscTestsz}
    Miscellaneous tests more to do with module/package structure than
    anything to do with the Post Office Protocol.
    c                 C   s(   t jj}|jD ]
}|  t||ƒ¡ qdS )z
        This test checks that all names listed in
        twisted.mail.pop3.__all__ are actually present in the module.
        N)Útwistedr   r
   Ú__all__ræ   Úhasattr)r!   ÚmodÚattrr'   r'   r(   Útest_all"  s   
ÿzPOP3MiscTests.test_allN)rL   rM   rN   rO   r¥  r'   r'   r'   r(   rŸ    s    rŸ  c                   @   rÂ   )ÚPOP3ClientDeprecationTestszI
    Tests for the now deprecated L{twisted.mail.pop3client} module.
    c                 C   s\   ddl m} | j| jgd}|  |d d t¡ |  |d d d¡ |  t|ƒd¡ | dS )	zò
        A deprecation warning is emitted when directly importing the now
        deprected pop3client module.

        This test might fail is some other code has already imported it.
        No code should use the deprected module.
        r   )Ú
pop3client)ÚoffendingFunctionsr€  rg   zXtwisted.mail.pop3client was deprecated in Twisted 21.2.0. Use twisted.mail.pop3 instead.r9   N)Útwisted.mailr§  ÚflushWarningsÚtest_deprecationr   ÚDeprecationWarningrs   )r!   r§  ÚwarningsShownr'   r'   r(   r«  1  s   
þz+POP3ClientDeprecationTests.test_deprecationN)rL   rM   rN   rO   r«  r'   r'   r'   r(   r¦  ,  rË   r¦  )LrO   rU  rW  r   Úcollectionsr   Úhashlibr   Úior   Úzope.interfacer   Útwisted.cred.checkersr   Útwisted.cred.credentialsÚtwisted.cred.portalÚtwisted.internet.protocolÚtwisted.mail.pop3Útwisted.mail.protocolsr   r   r   Útwisted.internetr	   r©  r
   Útwisted.protocolsr   Útwisted.pythonr   Útwisted.test.proto_helpersr   Útwisted.trialr   r   ÚTestCaser   Ú	protocolsÚVirtualPOP3rQ   r^   rm   r†   r…   r›   r2  r½   rÃ   ÚMailboxr¿   rÏ   ÚIServerFactoryr  r'  r/  r0  rI  rÆ   rN  r^  Ú_listMessageDeprecationr¼   ÚPendingDeprecationWarningr…  Ú_getUidlDeprecationr†  r  r‡  rˆ  r‹  rŽ  r  r”  rž  rŸ  r¦  r'   r'   r'   r(   Ú<module>   s€   X)84_<  >7P)&  Dÿÿÿÿ3		