Current File : //proc/self/root/lib/python3/dist-packages/twisted/mail/test/__pycache__/test_mail.cpython-312.pyc
�

Ϫ�f8c��	�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZmZddlmZddlZddlZddlZddlZddlZddlZddlZddl Zddl!Zddlm"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd	l+m,Z,dd
l-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8dd
l!m9Z9ddl:m;Z;ddl<m=Z=m>Z>m?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHddlImJZJeeHdk7d�Gd�deJ��ZKeeHdk7d�Gd�deJ��ZLeeHdk7d�Gd�deJ��ZMeeHdk7d�Gd�deJ��ZNeeHdk7d�Gd�d eJ��ZOeeHdk7d�Gd!�d"eJ��ZPeeHdk7d�Gd#�d$eJ��ZQeeHdk7d�Gd%�d&e#j�j���ZTGd'�d(�ZUeeHdk7d�Gd)�d*eJeU��ZVeeHdk7d�Gd+�d,eJeU��ZWeeHdk7d�Gd-�d.eJ��ZXeeHdk7d�Gd/�d0eJ��ZYeeHdk7d�Gd1�d2eJ��ZZee#jFj��Gd3�d4��Z\eeHdk7d�Gd5�d6eJ��Z]eeHdk7d�Gd7�d8eJ��Z^Gd9�d:e8j��Z`eeHdk7d�Gd;�d<eJ��ZaeeHdk7d�Gd=�d>eJ��ZbGd?�d@�ZceeHdk7d�GdA�dBeJ��ZdeeHdk7d�GdC�dDeJ��ZeddEl:mfZfmgZgmhZhGdF�dGegj��ZjdH�ZkdI�ZleeHdk7d�GdJ�dKeJ��ZmeeHdk7d�GdL�dMeJ��ZnGdN�dO�ZoeeHdk7d�GdP�dQeJ��ZpGdR�dS�ZqeeHdk7d�GdT�dUeJ��ZrGdV�dW�ZsGdX�dYe#j�j��ZvGdZ�d[e#j�j��ZxGd\�d]�ZyeeHdk7d�Gd^�d_eJ��ZzGd`�da�Z{Gdb�dc�Z|Gdd�de�Z}eeHdk7d�Gdf�dgeJ��Z~y)hz.
Tests for large portions of L{twisted.mail}.
�N)�md5)�skipIf)�	Interface�implementer)�verifyClass)�cred�mail)�address�defer�
interfaces�protocol�reactor�task)�Deferred)�CannotListenError�DNSLookupError�ProcessDone�ProcessTerminated)�LineSendingProtocol�MemoryReactorClock�StringTransport)�pop3�smtp)�_AttemptManager)�dns)�Record_CNAME�	Record_MX�RRHeader)�DNSNameError)�failure�log)�FilePath)�platformType)�TestCase�posixz twisted.mail only works on posixc�\�eZdZeej
dk\d�d��Zd�Zd�Zd�Z	d�Z
y)	�DomainWithDefaultsTests���not ported to Python 3c	�v�td�D�cic]}||dz��
}}tjj|d�}|jt	|�d�|jtt
|��ttd���|jt|j��tt
|���t|j��}|j�|j|td�D�cgc]	}||dzf��c}�t|j��}|j�|j|ttdd���|j�}|j�|j|td�D�cgc]	}||dzf��c}�|j�}|j�|j|ttdd���td�D]Q}|j|||dz�|j|j|�|dz�|j||v��S|d=|d=|d=|jt	|�d�|j|dd�|j|dd�|j|dd�|jddd	d
��|jt	|�d�|j|dd�|j|dd�|j|d
d	�|j!�|jt	|�d�|j|j#dd�d�|j|dd�|j|j%�d�|jt	|�d�|j'�}|j|j(|j(�|j|j*|j*�ycc}wcc}wcc}w)N�
�Default�������*)�a�b�cr5r6r7r�key�value)r8r9)�ranger	�DomainWithDefaultDict�assertEqual�len�list�iter�iterkeys�	iteritems�sort�
itervalues�items�values�get�
assertTrue�update�clear�
setdefault�popitem�copy�domains�default)�self�x�drDrE�dcopys      �=/usr/lib/python3/dist-packages/twisted/mail/test/test_mail.py�testMethodsz#DomainWithDefaultsTests.testMethods?sO�� %�b�	�*�1�Q��B��Y�*��*��I�I�+�+�A�y�9������Q���$�����d�1�g���U�2�Y��8�����a�j�j�l�+�T�$�q�'�]�;��Q�[�[�]�#��
�
�
������e�B�i� @��!�Q��V�� @�A��a�l�l�n�%�����
������e�B��m�!4�5����	��
�
�
������e�B�i� @��!�Q��V�� @�A���������
������e�B��m�!4�5��r��	$�A����Q�q�T�1�r�6�*����Q�U�U�1�X�q�2�v�.��O�O�A��F�#�	$�

�a�D�!�A�$��!������Q���#�����1��y�)�����1��y�)�����1��y�)�	���t�"�3�/�0�����Q���$�����3���&�����3���$�����3���%�	���	�����Q���#�������e�W�5�w�?�����5��7�+��������&6�7�����Q���#������������E�M�M�2�������E�M�M�2��i
+��!A��!As�
P,�P1
�'P6
c���tjjid�}|j|jj||��d|d<|jtddi�||��y)a�
        Assert that the class name of a L{mail.mail.DomainWithDefaultDict}
        instance and the string-formatted underlying domain dictionary both
        appear in the string produced by the given string-returning function.

        @type stringifier: one-argument callable
        @param stringifier: either C{str} or C{repr}, to be used to get a
            string to make assertions against.
        r-r9r8N)r	r;�assertIn�	__class__�__name__�str)rO�stringifier�domains   rS�_stringificationTestz,DomainWithDefaultsTests._stringificationTestws_�����0�0��Y�?���
�
�f�&�&�/�/��V�1D�E���u�
��
�
�c�5�'�*�+�[��-@�A�c�.�|jt�y)z�
        L{DomainWithDefaultDict.__str__} should return a string including
        the class name and the domain mapping held by the instance.
        N)r\rY�rOs rS�test_strz DomainWithDefaultsTests.test_str�s��
	
�!�!�#�&r]c�.�|jt�y)z�
        L{DomainWithDefaultDict.__repr__} should return a string including
        the class name and the domain mapping held by the instance.
        N)r\�reprr_s rS�	test_reprz!DomainWithDefaultsTests.test_repr�s��
	
�!�!�$�'r]c�@�tjjid�}|jd�d}|j|jg�}|jdt
|��|jt|dd�|j||dd�y)	z,
        has_key is now deprecated.
        r-�anythingzotwisted.mail.mail.DomainWithDefaultDict.has_key was deprecated in Twisted 16.3.0. Use the `in` keyword instead.�r�category�messageN)r	r;�has_key�
flushWarnings�test_has_keyDeprecationr<r=�DeprecationWarning)rO�sutrh�warningss    rSrkz/DomainWithDefaultsTests.test_has_keyDeprecation�s����i�i�-�-�b�)�<�����J��
?�	��%�%�t�'C�'C�&D�E������C��M�*����+�X�a�[��-D�E�����(�1�+�i�"8�9r]N)rX�
__module__�__qualname__r�sys�version_inforTr\r`rcrkr3r]rSr'r'=s>���C����$�&>�?�53�@�53�n
B�'�(�:r]r'c�$�eZdZd�Zd�Zd�Zd�Zy)�BounceTestsc�J�tjj�|_y�N)r	�BounceDomainr[r_s rS�setUpzBounceTests.setUp�s���i�i�,�,�.��r]c�n�|jtj|jjd�y)Nzany user)�assertRaisesr�AddressErrorr[�existsr_s rS�
testExistszBounceTests.testExists�s$�����$�+�+�T�[�[�-?�-?��Lr]c�\�|j|jjdd�d�y)Nzrandom q emailerr
F)r<r[�	willRelayr_s rS�	testRelayzBounceTests.testRelay�s%��������.�.�/A�:�N�PU�Vr]c��|jjdd�|jtj|jj
d�y)N�bob�password)r[�addUserrzr�SMTPBadRcptr|r_s rS�testAddUserzBounceTests.testAddUser�s8�������E�:�.����$�*�*�D�K�K�,>�,>��Fr]N)rXrorprxr}r�r�r3r]rSrtrt�s��/�M�W�Gr]rtc��eZdZdZd�Zy)�BounceWithSMTPServerTestsz_
    Tests for L{twisted.mail.mail.BounceDomain} with
    L{twisted.mail.smtp.SMTPServer}.
    c���tjj�}tjj�}|jd|�tjj|�}|j
d�}tjj|dd�}||_t�}|j|�|jd�|jd�|jd�|jd�|j|j�|jd�|j|j!�j#�j%d�dd	�y)
zo
        Incoming emails to a SMTP server with L{twisted.mail.mail.BounceDomain}
        are rejected.
        sfoo.comNsHELO baz.netsMAIL FROM:<a@baz.net>sRCPT TO:<any@foo.com>sQUITs
���s(550 Cannot receive for specified address)r	�MailServicerw�	addDomain�	protocols�SMTPFactory�
buildProtocol�SMTPDomainDelivery�deliveryr�makeConnection�lineReceivedrG�
disconnecting�connectionLostr<r9�strip�split)rO�servicer[�factoryr
�	deliverer�	transports       rS�
test_rejectedz'BounceWithSMTPServerTests.test_rejected�s,��
�)�)�'�'�)�����'�'�)�����*�f�-��.�.�,�,�W�5���(�(��.���N�N�5�5�g�t�T�J�	�%���#�%�	�����	�*�����o�.�����6�7�����6�7�����g�&����	�/�/�0������%�����O�O��#�#�%�+�+�G�4�R�8�7�	
r]N)rXrorp�__doc__r�r3r]rSr�r��s���

r]r�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�FileMessageTestsc�`�|j�|_|j�|_t|jd�|_|j|jj�tjj|j|j|j�|_	y)N�wb)
�mktemp�name�final�open�f�
addCleanup�closer	�FileMessage�fpr_s rSrxzFileMessageTests.setUp�sh���K�K�M��	��[�[�]��
��d�i�i��&�����������%��)�)�'�'�����	�	�4�:�:�F��r]c�h�|jj�j|j�Srv)r��eomReceived�addCallback�_cbFinalNamer_s rS�
testFinalNamezFileMessageTests.testFinalName�s&���w�w�"�"�$�0�0��1B�1B�C�Cr]c��|j||j�|j|jj�|jtjj|j��yrv)
r<r�rGr��closed�assertFalse�os�pathr|r��rO�results  rSr�zFileMessageTests._cbFinalName�sI���������,�������
�
�&����������	�	�2�3r]c�2�d}|j�D]}|jj|��|jj�t	|j
d�5}|j
|j�|�ddd�y#1swYyxYw)N�"first line
second line
third line
�rb)�
splitlinesr�r�r�r�r�r<�read)rO�contents�liner�s    rS�testContentszFileMessageTests.testContents�s|��;���'�'�)�	'�D��G�G� � ��&�	'�������
�$�*�*�d�
#�	1�q����Q�V�V�X�x�0�	1�	1�	1�s�#!B
�
Bc�|�d}|j�D]}|jj|��|jj�|j	t
jj|j��|j	t
jj|j��y)N�first line
second line
)
r�r�r�r�r�r�r�r|r�r��rOr�r�s   rS�testInterruptedz FileMessageTests.testInterrupted�s��/���'�'�)�	'�D��G�G� � ��&�	'������ ����������	�	�2�3����������
�
�3�4r]N)rXrorprxr�r�r�r�r3r]rSr�r��s��G�D�4�
1�5r]r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�MaildirMessageTestszL
    Tests for the file creating by the L{mail.maildir.MaildirMessage}.
    c��|j�|_|j�|_d|_t	|jd�|_|j
|j
j�tjj|j|j
|j|j�|_y)z3
        Create and open a temporary file.
        suser@example.comr�N)r�r�r�r
r�r�r�r�r	�maildir�MaildirMessager�r_s rSrxzMaildirMessageTests.setUpsz���K�K�M��	��[�[�]��
�*����d�i�i��&�����������%��,�,�-�-��L�L�$�&�&�$�)�)�T�Z�Z�
��r]c�L�tj|j�d��dS)zk
        Search for the final file path.

        @rtype: L{str}
        @return: Final file path.
        z	,S=[0-9]*r)�globr�r_s rS�
_finalNamezMaildirMessageTests._finalNames#���y�y�D�J�J�<�y�1�2�1�5�5r]c��|j|jj��}|j||j�dt
jj|����|j|jj�|jt
jj|j��y)z�
        Send the EOM to the message and check that the final file name contains
        the correct file size and the temporary file has been closed and removed.
        z,S=N)�successResultOfr�r�r<r�r�r��getsizerGr�r�r�r|r�)rOr�s  rS�test_finalNamez"MaildirMessageTests.test_finalNames���
�$�$�T�W�W�%8�%8�%:�;������4�:�:�,�c�"�'�'�/�/�%�2H�1I� J�K�������
�
�&����������	�	�2�3r]c�Z�d}|j�D]}|jj|��|j|jj	��}t|d�5}|j
|j�d|j|fz�ddd�y#1swYyxYw)z�
        Send a message contents and the EOM to the message and check that the
        final file contains the correct header and the message contents.
        r�r�sDelivered-To: %s
%sN)	r�r�r�r�r�r�r<r�r
)rOr�r�r�r�s     rS�
test_contentsz!MaildirMessageTests.test_contents%s���
<���'�'�)�	'�D��G�G� � ��&�	'��$�$�T�W�W�%8�%8�%:�;��
�%��
�	�!��������1�T�\�\�8�4L�L�
�	�	�	�s�(0B!�!B*c�L�d}|j�D]}|jj|��|jj�|j	t
jj|j��|jt|j�y)z�
        Check that the interrupted message transfer removes the temporary file
        and a doesn't create a final file.
        r�N)r�r�r�r�r�r�r�r|r�rz�
IndexErrorr�r�s   rS�test_interruptedz$MaildirMessageTests.test_interrupted3sv��
0���'�'�)�	'�D��G�G� � ��&�	'������ ����������	�	�2�3����*�d�o�o�6r]N)	rXrorpr�rxr�r�r�r�r3r]rSr�r��s ���
�6�4��
7r]r�c��eZdZd�Zd�Zd�Zy)�MailServiceTestsc�J�tjj�|_yrv)r	r�r�r_s rSrxzMailServiceTests.setUpBs���y�y�,�,�.��r]c��|jj�}|jt|tj
��|j|j
d�tj�|jj�}|jt|tj
��|j|j
d�tj�|jj�}|jt|tj
��|j|j
d�tj�y)N)�	127.0.0.1�90)r��getPOP3FactoryrG�
isinstancer
�
ServerFactoryr�r�POP3�getSMTPFactoryr�SMTP�getESMTPFactory�ESMTP)rOr�s  rS�
testFactorieszMailServiceTests.testFactoriesEs����L�L�'�'�)�����
�1�h�&<�&<�=�>�������(<�=�t�y�y�I��L�L�'�'�)�����
�1�h�&<�&<�=�>�������(<�=�t�y�y�I��L�L�(�(�*�����
�1�h�&<�&<�=�>�������(<�=�t�z�z�Jr]c�>�t�}t�}||jjd<||jjd<|j|jj	d�|u�|j|jj�|u�y)Nr[�)�objectr��portalsrG�lookupPortal�
defaultPortal)rO�o1�o2s   rS�testPortalszMailServiceTests.testPortalsRsv��
�X��
�X��)+������X�&�#%������R� �������1�1�(�;�r�A�B�������2�2�4��:�;r]N)rXrorprxr�r�r3r]rSr�r�@s��/�K�<r]r�c��eZdZdZd�Zd�Zeejdk\d�d��Z	eejdk\d�d��Z
d�Zd	�Zd
�Z
y)�StringListMailboxTestszc
    Tests for L{StringListMailbox}, an in-memory only implementation of
    L{pop3.IMailbox}.
    c��tjjgd��}|j|j	d�d�|j|j	d�d�|j|j	d�d�y)z�
        L{StringListMailbox.listMessages} returns the length of the message at
        the offset into the mailbox passed to it.
        )�abc�abr5rr)rfr/N�r	r��StringListMailboxr<�listMessages�rO�mailboxs  rS�test_listOneMessagez*StringListMailboxTests.test_listOneMessagecsj��
�,�,�0�0�1C�D������-�-�a�0�!�4�����-�-�a�0�!�4�����-�-�a�0�!�4r]c��tjjgd��}|j|j	�gd��y)z�
        L{StringListMailbox.listMessages} returns a list of the lengths of all
        messages if not passed an index.
        )r5r�r�)rfr)r/Nr�r�s  rS�test_listAllMessagesz+StringListMailboxTests.test_listAllMessagesms2��
�,�,�0�0�1C�D������-�-�/��;r]r(r*c��tjjddg�}|j|j	d�j�d�y)z�
        L{StringListMailbox.getMessage} returns a file-like object from which
        the contents of the message at the given offset into the mailbox can be
        read.
        �fooz
real contentsrfN)r	r�r�r<�
getMessager�r�s  rS�test_getMessagez&StringListMailboxTests.test_getMessageusA���,�,�0�0�%��1I�J������+�+�A�.�3�3�5��Gr]c��tjjddg�}|j|j	d�|j	d��y)z�
        L{StringListMailbox.getUidl} returns a unique identifier for the
        message at the given offset into the mailbox.
        r��barrrfN)r	r�r��assertNotEqual�getUidlr�s  rS�test_getUidlz#StringListMailboxTests.test_getUidls>���,�,�0�0�%���@�����G�O�O�A�.�����0B�Cr]c���tjjdg�}|jd�|j	|jd�d�|j	|j�dg�y)z�
        L{StringListMailbox.deleteMessage} marks a message for deletion causing
        further requests for its length to return 0.
        r�rN)r	r�r��
deleteMessager<r�r�s  rS�test_deleteMessagez)StringListMailboxTests.test_deleteMessage�s^��
�,�,�0�0�%��9�����a� �����-�-�a�0�!�4�����-�-�/�!��5r]c�
�tjjdg�}|jd�|j	�|j|j
d�d�|j|j
�dg�y)z�
        L{StringListMailbox.undeleteMessages} causes any messages marked for
        deletion to be returned to their original state.
        r�rr)N)r	r�r�r�undeleteMessagesr<r�r�s  rS�test_undeleteMessagesz,StringListMailboxTests.test_undeleteMessages�sj��
�,�,�0�0�%��9�����a� �� � �"�����-�-�a�0�!�4�����-�-�/�!��5r]c�*�tjjdg�}|jd�|j	�|j�|j
|jd�d�|j
|j�dg�y)zy
        L{StringListMailbox.sync} causes any messages as marked for deletion to
        be permanently deleted.
        r�rN)r	r�r�r�syncrr<r�r�s  rS�	test_syncz StringListMailboxTests.test_sync�ss��
�,�,�0�0�%��9�����a� ������ � �"�����-�-�a�0�!�4�����-�-�/�!��5r]N)rXrorpr�r�r�rrqrrr�rrrr
r3r]rSr�r�\st���
5�<��C����$�&>�?�H�@�H��C����$�&>�?�D�@�D�6�	6�
6r]r�c�*�eZdZdZdZdZd�Zd�Zd�Zy)�&FailingMaildirMailboxAppendMessageTaskTc�|�|jrtj|||�Sttj
d���NzFaked Permission Problem)�
_openstater�r��OSError�errno�EPERM)rO�fn�attr�modes    rS�osopenz-FailingMaildirMailboxAppendMessageTask.osopen�s.���?�?��7�7�2�t�T�*�*��%�+�+�'A�B�Br]c�z�|jrtj||�Sttj
d��)NzFaked Space problem)�_writestater��writerr�ENOSPC)rO�fh�datas   rS�oswritez.FailingMaildirMailboxAppendMessageTask.oswrite�s.������8�8�B��%�%��%�,�,�(=�>�>r]c�z�|jrtj||�Sttj
d��r)�_renamestater��renamerrr)rO�oldname�newnames   rS�osrenamez/FailingMaildirMailboxAppendMessageTask.osrename�s.������9�9�W�g�.�.��%�+�+�'A�B�Br]N)	rXrorprrrrrr#r3r]rSrr�s$���J��K��L�C�?�Cr]rc��eZdZdZd�Zy)�_AppendTestMixinz�
    Mixin for L{MaildirMailbox.appendMessage} test cases which defines a helper
    for serially appending multiple messages to a mailbox.
    c�����g����fd�}tj|��j�}|j�fd��|S)z�
        Deliver the given messages one at a time.  Delivery is serialized to
        guarantee a predictable order in the mailbox (overlapped message deliver
        makes no guarantees about which message which appear first).
        c3�|�K��D]2}�j|�}|j�j�|���4y�wrv)�
appendMessager��append)�mrQ�mbox�messages�resultss  ���rSr)z0_AppendTestMixin._appendMessages.<locals>.append�s;������
���&�&�q�)���
�
�g�n�n�-���
�s�9<c����Srvr3)�ignoredr-s �rS�<lambda>z2_AppendTestMixin._appendMessages.<locals>.<lambda>�s���g�r])r�	cooperate�whenDoner�)rOr+r,r)rQr-s ``  @rS�_appendMessagesz _AppendTestMixin._appendMessages�s<�����	�
�N�N�6�8�$�-�-�/��	�
�
�-�.��r]N)rXrorpr�r3r3r]rSr%r%�s���
r]r%c�b�eZdZdZd�Zd�Zd
d�Zeejdk\d�d��Z
d	�Zy)�MaildirAppendStringTests�O
    Tests for L{MaildirMailbox.appendMessage} when invoked with a C{str}.
    c��|j�|_tjj	|j�yrv�r�rQr	r��initializeMaildirr_s rSrxzMaildirAppendStringTests.setUp��%�����������&�&�t�v�v�.r]c�P�|jd�}|j|t�S)N�TEST)r(�
assertFailure�	Exception)rOr/r+rQs    rS�_appendz MaildirAppendStringTests._append�s%�����v�&���!�!�!�Y�/�/r]Nc��|�G|jt|jd|jj�||j_|�G|jt|jd|jj�||j_|�H|jt|jd|jj
�||j_yy)a�
        Change the behavior of future C{rename}, C{write}, or C{open} calls made
        by the mailbox C{mbox}.

        @param rename: If not L{None}, a new value for the C{_renamestate}
            attribute of the mailbox's append factory.  The original value will
            be restored at the end of the test.

        @param write: Like C{rename}, but for the C{_writestate} attribute.

        @param open: Like C{rename}, but for the C{_openstate} attribute.
        Nrrr)r��setattr�
AppendFactoryrrr)rOr/r+r rr�s      rS�	_setStatez"MaildirAppendStringTests._setState�s������O�O���"�"���"�"�/�/�	
�/5�D���+����O�O���"�"���"�"�.�.�	
�.3�D���*����O�O���+�+�\�4�;M�;M�;X�;X�
�-1�D���)�	r]r(r*c�J�tjj|j�}t|_|j
|tdd�D�cgc]}d|z��	c}�}|j|jdgdz�|j|j|�|Scc}w)��
        L{MaildirMailbox.appendMessage} returns a L{Deferred} which fires when
        the message has been added to the end of the mailbox.
        rf��XNr,)r	r��MaildirMailboxrQrrBr3r:r�r<�
_cbTestAppend)rOr+�irQs    rS�test_appendz$MaildirAppendStringTests.test_appends����|�|�*�*�4�6�6�2��C���� � ���q�"��'F�A��a��'F�G��	�
�
�d�&�&�����4�	�
�
�d�(�(�$�/����(Gs�B 
c
��|jt|j��d�|jtd�D�cgc]*}t|j	|�j����,c}t
tdd���|jd|d��|jd|�}|j|j|dd��|j|j|�|j|j|dd�	�|j|j|�|j|j|d�
�|Scc}w)��
        Check that the mailbox has the expected number (ten) of messages in it,
        and that each has the expected contents, and that they are in the same
        order as that in which they were appended.
        r,rfrFNF)r T)r r)rr�)r�)
r<r=r�r:r�r�r>rCr?r�)rOr/r+rJrQs     rSrIz&MaildirAppendStringTests._cbTestAppends���	
����T�.�.�0�1�2�6����5:�2�Y�?��S�����#�(�(�*�
+�?��e�A�r�l�AS�	
�	
���t�T�%��0��L�L��t�$��	�
�
�d�n�n�d�4�u�
�E�	�
�
�d�l�l�D�)�	�
�
�d�n�n�d�$�U�
�C�	�
�
�d�l�l�D�)�	�
�
�d�n�n�d��
�6����
@s�/E)NNN)rXrorpr�rxr?rCrrqrrrKrIr3r]rSr5r5�sD���/�0�!1�F�C����$�&>�?��@��r]r5c�T�eZdZdZd�Zeejdk\d�d��Zd�Z	y)�MaildirAppendFileTestsr6c��|j�|_tjj	|j�yrvr8r_s rSrxzMaildirAppendFileTests.setUp8r:r]r(r*c��tjj|j�}g}t	dd�D]h}tj�}|jd|z�|jdd�|j|�|j|j��j|j||�}|j|j|�|S)rErfrFrGr)r	r�rHrQr:�tempfile�
TemporaryFiler�seekr)r�r�r3r�rI)rOr+r,rJ�temprQs      rSrKz"MaildirAppendFileTests.test_append<s����|�|�*�*�4�6�6�2�����q�"��	(�A��)�)�+�D��J�J�s�Q�w���I�I�a��O��O�O�D�!��O�O�D�J�J�'�	(�
� � ��x�0��	�
�
�d�(�(�$�/��r]c
�$�|jt|j��d�|jtd�D�cgc]*}t|j	|�j����,c}t
tdd���ycc}w)rMr,rfrFN)r<r=r�r:r�r�r>)rOr�r+rJs    rSrIz$MaildirAppendFileTests._cbTestAppendOsi��	
����T�.�.�0�1�2�6����5:�2�Y�?��S�����#�(�(�*�
+�?��e�A�r�l�AS�	
��?s�/B
N)
rXrorpr�rxrrqrrrKrIr3r]rSrOrO2s9���/��C����$�&>�?��@��$	
r]rOc�\�eZdZd�Zd�Zd�Zd�Zeejdk\d�d��Z
y)	�MaildirTestsc��|j�|_tjj	|j�yrvr8r_s rSrxzMaildirTests.setUp]r:r]c�B�tj|j�yrv)�shutil�rmtreerQr_s rS�tearDownzMaildirTests.tearDownas���
�
�d�f�f�r]c��|j}tjj|d�}|j	tjj|�xrtjj
|��|j	tjjtjj|d���|j	tjjtjj|d���|j	tjjtjj|d���|j	tjj
tjj|d���|j	tjj
tjj|d���|j	tjj
tjj|d���|j	tjjtjj|d���|j	tjjtjj|d���|j	tjjtjj|d���|j	tjj
tjj|d���|j	tjj
tjj|d���|j	tjj
tjj|d���y)N�.Trash�new�cur�tmp)rQr�r��joinrGr|�isdir)rOrQ�trashs   rS�testInitializerzMaildirTests.testInitializerds*���F�F�������Q��)����������q�)�>�b�g�g�m�m�A�.>�?���������r�w�w�|�|�A�u�'=�>�?���������r�w�w�|�|�A�u�'=�>�?���������r�w�w�|�|�A�u�'=�>�?�������
�
�b�g�g�l�l�1�e�&<�=�>�������
�
�b�g�g�l�l�1�e�&<�=�>�������
�
�b�g�g�l�l�1�e�&<�=�>���������r�w�w�|�|�E�5�'A�B�C���������r�w�w�|�|�E�5�'A�B�C���������r�w�w�|�|�E�5�'A�B�C�������
�
�b�g�g�l�l�5�%�&@�A�B�������
�
�b�g�g�l�l�5�%�&@�A�B�������
�
�b�g�g�l�l�5�%�&@�A�Br]c��tj�}|jd�tjj|�}|j
�}|jd�|j
�}|j||k�y)a
        Each call to L{_MaildirNameGenerator.generate} returns a unique
        string suitable for use as the basename of a new message file.  The
        names are ordered such that those generated earlier sort less than
        those generated later.
        g�������?N)r�Clock�advancer	r��_MaildirNameGenerator�generaterG)rO�clock�	generator�	firstName�
secondNames     rS�test_nameGeneratorzMaildirTests.test_nameGeneratorwsh���
�
���
�
�
�d���L�L�6�6�u�=�	��&�&�(�	�
�
�
�d���'�'�)�
����	�J�.�/r]r(r*c
��tjj}tjj
}dD��cgc] }t
d�D]}|||�����"}}}d}|D]A}t||j|�d�5}|jd|z�ddd�|dz}�Ctjj|j�}	|j|	j�tt
dd���|j|	jd�d�|j|	jd�d	�|j|	jd	�j�d
�|j|	jd�j�d�i}
t
d�D]+}|	j!|�}|j#||
v�d|
|<�-tjj%|d�\}}|	j'd�|j|	jd�d
�|j)tjj+||jdd|���|j#tjj+||j|d���|	j-�|j|	jd�d	�|j#tjj+||jdd|���|j)tjj+||j|d���ycc}}w#1swY���xYw)zb
        Exercise the methods of L{IMailbox} as implemented by
        L{MaildirMailbox}.
        )rar`�rf�wrPNrFr/r1�xxxxxxx�xxr,rr_ra)r�r�rcr	r��_generateMaildirNamer:r�rQrrHr<r�r>r�r�rr�r�rrGr|r)
rO�j�nr6rP�msgsrJr��fObj�mbrQ�u�ps
             rS�test_mailboxzMaildirTests.test_mailbox�s���
�G�G�L�L���L�L�-�-��#1�D�a�5��8�D�a��!�Q�S�	�D�	�D��D�
���	�A��a�����l�C�(�
$�D��
�
�3��7�#�
$��A��A�	�
�\�\�
(�
(����
0��������*�D��q�"��,>�?��������+�Q�/��������+�Q�/�������q�)�.�.�0�'�:�������q�)�.�.�0�'�:����r��	�A��
�
�1�
�A����Q�!�V�$��A�a�D�	�
�w�w�}�}�T�!�W�%���1�
������������+�Q�/���������q�����5�!�'D�E�F����������$�&�&�$�q�'�(:�;�<�
�����������+�Q�/����������$�&�&�(�E�1�(E�F�G���������q�����a��'9�:�;��CE�

$�
$�s�%M0�M6�6N	N)rXrorprxr]rfrprrqrrr~r3r]rSrXrX[s?��/��C�&0�"�C����$�&>�?�(<�@�(<r]rXc��eZdZdZd�Zy)�AbstractMaildirDomainTestszB
    Tests for L{twisted.mail.maildir.AbstractMaildirDomain}.
    c�|�ttjjtjj�y)zW
        L{maildir.AbstractMaildirDomain} implements L{mail.IAliasableDomain}.
        N)rr	�IAliasableDomainr��AbstractMaildirDomainr_s rS�test_interfacez)AbstractMaildirDomainTests.test_interface�s"��	�D�I�I�.�.����0R�0R�Sr]N)rXrorpr�r�r3r]rSr�r��s
���Tr]r�c��eZdZdZd�Zd�Zeejdk\d�d��Z	d�Z
eejdk\d�d��Zeejdk\d�d	��Zeejdk\d�d
��Z
y)�MaildirDirdbmDomainTestsz+
    Tests for L{MaildirDirdbmDomain}.
    c���|j�|_tjj�|_tj
j
|j|j�|_y)zw
        Create a temporary L{MaildirDirdbmDomain} and parent
        L{MailService} before running each test.
        N)r��Pr	r��Sr��MaildirDirdbmDomain�Dr_s rSrxzMaildirDirdbmDomainTests.setUp�sE��
���������&�&�(������1�1�$�&�&�$�&�&�A��r]c�B�tj|j�y)z_
        Remove the temporary C{maildir} directory when the test has
        finished.
        N)r[r\r�r_s rSr]z!MaildirDirdbmDomainTests.tearDown�s��
	�
�
�d�f�f�r]r(r*c	��d}|D]!\}}|jj||��#|D]�\}}|j||jjv�|j	|jj||�|jt
jjt
jj|j|�����y)z�
        L{MaildirDirdbmDomain.addUser} accepts a user and password
        argument. It stores those in a C{dbm} dictionary
        attribute and creates a directory for each user.
        ))�user1�pwd1)�user2�pwd2)�user3�pwd3N)
r�r�rG�dbmr<r�r�r|rcr�)rO�toAddr|r}s    rS�test_addUserz%MaildirDirdbmDomainTests.test_addUser�s���J���	!�D�A�q��F�F�N�N�1�a� �	!��	E�D�A�q��O�O�A������O�,����T�V�V�Z�Z��]�A�.��O�O�B�G�G�N�N�2�7�7�<�<�����+B�C�D�	Er]c�T�|jj�}|jt|�d�|j	t
jjj|d��|j	t
jj|djv�y)z�
        L{MaildirDirdbmDomain.getCredentialsCheckers} initializes and
        returns one L{ICredentialsChecker} checker by default.
        rfrN)r��getCredentialsCheckersr<r=rGr�checkers�ICredentialsChecker�
providedBy�credentials�IUsernamePassword�credentialInterfaces)rO�credss  rS�test_credentialsz)MaildirDirdbmDomainTests.test_credentials�sy��
���-�-�/������U��Q�'�����
�
�9�9�D�D�U�1�X�N�O�������.�.�%��(�2O�2O�O�	
r]c��Gd�dt�}|jjdd�|jt|jj
dd|�|jjddtj�}|jt|�d�|j|dtju�|jtjj|d��|d	�y)
a?
        L{MaildirDirdbmDomain.requestAvatar} raises L{NotImplementedError}
        unless it is supplied with an L{pop3.IMailbox} interface.
        When called with an L{pop3.IMailbox}, it returns a 3-tuple
        containing L{pop3.IMailbox}, an implementation of that interface
        and a NOOP callable.
        c��eZdZy)�?MaildirDirdbmDomainTests.test_requestAvatar.<locals>.ISomethingN)rXrorpr3r]rS�
ISomethingr��s��r]r��userr�Nr)rrfr/)rr�r�rz�NotImplementedError�
requestAvatarr�IMailboxr<r=rGr�)rOr��ts   rS�test_requestAvatarz+MaildirDirdbmDomainTests.test_requestAvatar�s���	��	�	
�����v�z�*��������!5�!5�v�t�Z�	
�
�F�F� � ���t�}�}�=������Q���#�����!���
�
�-�.�����
�
�0�0��1��6�7���!��r]c��|jjdd�|jj�d}tjjdd�}|j
tjj|j|�tjjdd�}|j|j|�d�y)a
        L{DirdbmDatabase.requestAvatarId} raises L{UnauthorizedLogin} if
        supplied with invalid user credentials.
        When called with valid credentials, L{requestAvatarId} returns
        the username associated with the supplied credentials.
        r�r�r�wrong passwordN)r�r�r�rr��UsernamePasswordrz�error�UnauthorizedLogin�requestAvatarIdr<)rO�databaser�s   rS�test_requestAvatarIdz-MaildirDirdbmDomainTests.test_requestAvatarId
s���	
�����v�z�*��6�6�0�0�2�1�5��� � �1�1�&�:J�K�����$�*�*�6�6��8P�8P�RW�X�� � �1�1�&�*�E������1�1�%�8�&�Ar]c�J�|jjdd�|j|jjd�tj
j
|jjd��d|j_|j|jjd�d�d|j_|j|jjd�tj
j
|jjd��y)a]
        L{MaildirDirdbmDomain.userDirectory} is supplied with a user name
        and returns the path to that user's maildir subdirectory.
        Calling L{MaildirDirdbmDomain.userDirectory} with a
        non-existent user returns the 'postmaster' directory if there
        is a postmaster or returns L{None} if there is no postmaster.
        r�r�F�nouserNT�
postmaster)
r�r�r<�
userDirectoryr�r�rc�rootr��assertIdenticalr_s rS�test_userDirectoryz+MaildirDirdbmDomainTests.test_userDirectorys���	
�����v�z�*�����F�F� � ��(�"�'�'�,�,�t�v�v�{�{�F�*K�	
�"��������T�V�V�1�1�(�;�T�B� ���������F�F� � ��*�B�G�G�L�L������l�,S�	
r]N)rXrorpr�rxr]rrqrrr�r�r�r�r�r3r]rSr�r��s����B���C����$�&>�?�
E�@�
E�
��C����$�&>�?��@��0�C����$�&>�?�B�@�B� �C����$�&>�?�
�@�
r]r�c�*�eZdZdZdd�Zd�Zd�Zd�Zy)�StubAliasableDomainz>
    Minimal testable implementation of IAliasableDomain.
    Nc��t���z{
        No test coverage for invocations of this method on domain objects,
        so we just won't implement it.
        �r��rOr��memos   rSr|zStubAliasableDomain.exists;�
��
"�#�#r]c��t��r�r�)rOr�r�s   rSr�zStubAliasableDomain.addUserBr�r]c��gS)a!
        This needs to succeed in order for other tests to complete
        successfully, but we don't actually assert anything about its
        behavior.  Return an empty list.  Sometime later we should return
        something else and assert that a portal got set up properly.
        r3r_s rSr�z*StubAliasableDomain.getCredentialsCheckersIs	���	r]c��||_y)zG
        Just record the value so the test can check it later.
        N)�
aliasGroup)rO�aliasess  rS�
setAliasGroupz!StubAliasableDomain.setAliasGroupRs��"��r]rv)rXrorpr�r|r�r�r�r3r]rSr�r�5s���$�$��"r]r�c��eZdZd�Zd�Zd�Zeejdk\d�d��Z	eejdk\d�d��Z
d�Zd	�Zd
�Z
d�Zy)
�ServiceDomainTestsc��tjj�|_tjj	|jd�|_|j|j
_d|j
_d|j
_|j�|_
tjj|j|j�}|jdd�|jjd|�y)Nr<�hostname�user�password�test.domain)r	r�r�r��DomainDeliveryBaser�r��protocolName�hostr��tmpdirr�r�r�r��rOr[s  rSrxzServiceDomainTests.setUp[s������&�&�(������2�2�4�6�6�4�@����������$����� ������k�k�m������1�1�$�&�&�$�+�+�F�����w��,��������/r]c�B�tj|j�yrv�r[r\r�r_s rSr]zServiceDomainTests.tearDowng����
�
�d�k�k�"r]c��t�}t�}||j_|jj	d|�|j|j|�y)z�
        Test that adding an IAliasableDomain to a mail service properly sets
        up alias group references and such.
        �example.comN)r�r�r�r�r�r�r�)rOr�r[s   rS�testAddAliasableDomainz)ServiceDomainTests.testAddAliasableDomainjsH��
�(��$�&�� ������������/����V�.�.��8r]r(r*c�d�|jjdtjd�dg�}t	j
|�}tjj�}|j|�}|jt|j��d�|jd|�y)N)�
remotehostz123.232.101.234z<someguy@someplace>zuser@host.namerf�Received)r��receivedHeaderr�Address�io�BytesIO�email�parser�Parser�parser<r=rDrV)rO�hdrr��emailParserr*s     rS�testReceivedHeaderz%ServiceDomainTests.testReceivedHeaderus����f�f�#�#�-��L�L�.�/�
��
��
�Z�Z��_���l�l�)�)�+�����b�!������Q�W�W�Y���+��
�
�j�!�$r]c��tjdddd�}tj|jj
|�j
|j�S)Nzuser@test.domain�helo�wherever@whatever)r�Userr�
maybeDeferredr��
validateTor��
_cbValidateTo�rOr�s  rS�testValidateToz!ServiceDomainTests.testValidateTo�sK���y�y�+�V�T�;N�O���"�"�4�6�6�#4�#4�d�;�G�G����
�	
r]c�8�|jt|��yrv)rG�callabler�s  rSr�z ServiceDomainTests._cbValidateTo�s�������(�)r]c���tjdddd�}|jtj|j
j|�tj�S)Nzresu@test.domainr�r��rr�r=rr�r�r�r�r�s  rS�testValidateToBadUsernamez,ServiceDomainTests.testValidateToBadUsername��M���y�y�+�V�T�;N�O���!�!������� 1� 1�4�8�$�:J�:J�
�	
r]c���tjdddd�}|jtj|j
j|�tj�S)Nzuser@domain.testr�r�r�r�s  rS�testValidateToBadDomainz*ServiceDomainTests.testValidateToBadDomain�r�r]c��d}tjd�}|j|jj	||�|u�d}tjd�}|j|jj	||�|u�d}tjd�}|j|jj	||�|u�|jtj|jjd|�y)N)r�r�z<user@hostname>)r��1.2.3.4z<>)rr�rGr��validateFromrz�
SMTPBadSender)rOr��origins   rS�testValidateFromz#ServiceDomainTests.testValidateFrom�s���(�����/�0��������+�+�D�&�9�V�C�D�&�����/�0��������+�+�D�&�9�V�C�D�&�����d�#��������+�+�D�&�9�V�C�D����$�,�,�d�f�f�.A�.A�4��Pr]N)rXrorprxr]r�rrqrrr�r�r�r�r�r�r3r]rSr�r�Ysv��
0�#�	9��C����$�&>�?�
%�@�
%��C����$�&>�?�
�@�
�*�
�
�
Qr]r�c�t�eZdZd�Zd�Zeejdk\d�d��Zd�Z	eejdk\d�d��Z
eejdk\d�d��Zeejdk\d�d	��Zd
�Z
eejdk\d�d��Zeejdk\d�d��Zy
)�VirtualPOP3Testsc��|j�|_tjj�|_tj
j
|j|j�|_|jjdd�|jjd|j�tjj|j�}t|j|jj��|x|jj d<|jj d<tj"j%�|_|j|j&_d|j&_y)Nr�r�r�r�z<unit test magic>)r�r�r	r�r�r�r�r�r�r�r�portal�Portal�map�registerCheckerr�r�r��VirtualPOP3r�r��magic)rOrs  rSrxzVirtualPOP3Tests.setUp�s����k�k�m������&�&�(������1�1�$�&�&�$�+�+�F��������w��,����������/����#�#�D�F�F�+���F�"�"�D�F�F�$A�$A�$C�D�=C�C������r��T�V�V�^�^�M�:����+�+�-����������*����r]c�B�tj|j�yrvr�r_s rSr]zVirtualPOP3Tests.tearDown�r�r]r(r*c���t|jjdz�j�}|jj	d|�j|j�S)Nr�r�)rr�r�	hexdigest�authenticateUserAPOPr��_cbAuthenticateAPOP�rO�resps  rS�testAuthenticateAPOPz%VirtualPOP3Tests.testAuthenticateAPOP�sO���4�6�6�<�<�*�,�-�7�7�9���v�v�*�*�6�4�8�D�D��$�$�
�	
r]c��|jt|�d�|j|dtj�|j	tjj|d��|d�y�Nr)rrfr/�r<r=rr�rGr�r�s  rSrz$VirtualPOP3Tests._cbAuthenticateAPOP��X������V��a�(�������D�M�M�2�����
�
�0�0����;�<���q�	�r]c���t|jjdz�j�}|j	|jjd|�tjj�S)Nr��resu)	rr�rr
r=rrr�r�r
s  rS�!testAuthenticateIncorrectUserAPOPz2VirtualPOP3Tests.testAuthenticateIncorrectUserAPOP�sU���4�6�6�<�<�*�,�-�7�7�9���!�!��F�F�'�'���5�t�z�z�7S�7S�
�	
r]c��td�j�}|j|jj	d|�t
jj�S)Nzwrong digestr�)rr
r=r�rrr�r�r
s  rS�%testAuthenticateIncorrectResponseAPOPz6VirtualPOP3Tests.testAuthenticateIncorrectResponseAPOP�sH���>�"�,�,�.���!�!��F�F�'�'���5�t�z�z�7S�7S�
�	
r]c�l�|jjdd�j|j�S)Nr�r�)r��authenticateUserPASSr��_cbAuthenticatePASSr_s rS�testAuthenticatePASSz%VirtualPOP3Tests.testAuthenticatePASS�s/���v�v�*�*�6�:�>�J�J��$�$�
�	
r]c��|jt|�d�|j|dtj�|j	tjj|d��|d�yrrr�s  rSrz$VirtualPOP3Tests._cbAuthenticatePASS�rr]c��|j|jjdd�tjj
�S)Nrr��r=r�rrr�r�r_s rS�testAuthenticateBadUserPASSz,VirtualPOP3Tests.testAuthenticateBadUserPASS�s6���!�!��F�F�'�'��
�;��J�J�(�(�
�	
r]c��|j|jjdd�tjj
�S)Nr�r�rr_s rS�testAuthenticateBadPasswordPASSz0VirtualPOP3Tests.testAuthenticateBadPasswordPASS�s7���!�!��F�F�'�'��0@�A��J�J�(�(�
�	
r]N)rXrorprxr]rrqrrrrrrrrr r"r3r]rSrr�s��
+�#��C����$�&>�?�
�@�
���C����$�&>�?�
�@�
��C����$�&>�?�
�@�
��C����$�&>�?�
�@�
�
��C����$�&>�?�
�@�
��C����$�&>�?�
�@�
r]rc��eZdZd�Zy)�emptyc��yrvr3r_s rS�__init__zempty.__init__�s��r]N)rXrorpr&r3r]rSr$r$�s��
r]r$c�D�eZdZeej
dk\d�d��Zy)�
RelayTestsr(r*c�p��tjj�}tjj|�}t	j
d�t	jddd�g}t	jddd�t	jddd�g}|D]��t�}d	|_d
|_	t�|_
t�|j_�fd�|jj_|jt|j|�����|D]��t�}d|_t�|_
t�|j_�fd
�|jj_d|_	|j!t"j$|j|���y)Nz/var/run/mail-relay�TCPr�r�z192.168.2.1�>r�i�z	user@hostz	tsoh@resuc����Srvr3��peers�rSr0z'RelayTests.testExists.<locals>.<lambda>����d�r]z
some@placec����Srvr3r-s�rSr0z'RelayTests.testExists.<locals>.<lambda>r/r]z	who@cares)r	r��relay�DomainQueuerr
�UNIXAddress�IPv4Addressr$�orig�destr
r��getPeerrGr�r|rzrr�)rOr�r[�doRelay�	dontRelayr�r.s      @rSr}zRelayTests.testExists�sV����)�)�'�'�)�����(�(��1��
��� 5�6�����{�E�:�
��
����}�b�9�����y�$�7�
�	�
�	;�D��7�D�#�D�I�#�D�I�!�G�D�M�&+�g�D�M�M�#�.:�D�M�M�#�#�+��O�O�H�V�]�]�4�%8�9�:�	;��	E�D��7�D�$�D�I�!�G�D�M�&+�g�D�M�M�#�.:�D�M�M�#�#�+�#�D�I����d�.�.��
�
�t�D�	Er]N)rXrorprrqrrr}r3r]rSr(r(�s*���C����$�&>�?� E�@� Er]r(c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�RelayerTestsc��|j�|_tj|j�g|_td�D]�}tjj|jd|fz�}t|dzd�5}tjd|fzd|fzg|�ddd�t|dzd�}|j|�|jd	d	�|jj|���tjj!�|_|j"j%|j�y#1swY��xYw)
Nr,�body-%d�-Hr��from-%d�to-%d�-Drsr)r�r�r��mkdir�messageFilesr:r�rcr��pickle�dumprrTr)r	r1�RelayerMixin�R�loadMessages)rOrJr�r�s    rSrxzRelayerTests.setUps���k�k�m���
�����������r��	+�A��7�7�<�<����Y�!��-=�>�D��d�T�k�4�(�
C�A����Y�!��-�w�!��~�>��B�
C��T�D�[�#�&�A�
�G�G�D�M�
�F�F�1�a�L����$�$�T�*�	+����(�(�*��������D�-�-�.�
C�
C�s�!E�E	c�B�tj|j�yrvr�r_s rSr]zRelayerTests.tearDown0r�r]c��td�D]O}|j|jj�d|fz�|jj	ddddd��Q|j|jj�d�y)Nr,r?�)r:r<rG�getMailFrom�sentMail�rOrJs  rS�testMailFromzRelayerTests.testMailFrom3sp���r��	9�A����T�V�V�/�/�1�9��t�3C�D��F�F�O�O�C��t�T�4�8�	9�	
������+�+�-�t�4r]c��td�D]P}|j|jj�d|fzg�|jj	ddddd��R|j|jj�d�y)Nr,r@rK)r:r<rG�	getMailTorMrNs  rS�
testMailTozRelayerTests.testMailTo9sr���r��	9�A����T�V�V�-�-�/�'�Q�D�.�1A�B��F�F�O�O�C��t�T�4�8�	9�	
������)�)�+�T�2r]c��td�D]�}tjj|jd|fz�}|j|jj�j�|�|jjddddd���|j|jj�d�y)Nr,r=rK)
r:r�r�rcr�r<rG�getMailDatar�rM)rOrJr�s   rS�testMailDatazRelayerTests.testMailData?s����r��	9�A��7�7�<�<����Y�!��-=�>�D����T�V�V�/�/�1�6�6�8�$�?��F�F�O�O�C��t�T�4�8�	9�	
������+�+�-�t�4r]N)rXrorprxr]rOrRrUr3r]rSr;r;s��/�"#�5�3�5r]r;c�$�eZdZd�Zd�Zd�Zd�Zy)�Managerc�.�g|_g|_g|_yrv)�successr �doner_s rSr&zManager.__init__Hs����������	r]c�>�|jj||f�yrv)rYr)�rOr�rhs   rS�
notifySuccesszManager.notifySuccessM��������W�g�.�/r]c�>�|jj||f�yrv)r r)r\s   rS�
notifyFailurezManager.notifyFailurePr^r]c�:�|jj|�yrv)rZr))rOr�s  rS�
notifyDonezManager.notifyDoneSs���	�	����!r]N)rXrorpr&r]r`rbr3r]rSrWrWGs���
0�0�"r]rWc�$�eZdZd�Zd�Zd�Zd�Zy)�ManagedRelayerTestsc��t�|_ttddd��|_t�|_tjj|j�|_
|jdd|j_|jdd|j_|j|j_y)Nrr.r/)rW�managerr>r:r,r�r�r	�relaymanager�ManagedRelayerMixinr1�namesr_s rSrxzManagedRelayerTests.setUpYs~���y����U�1�b�!�_�-��
��x����&�&�:�:�4�<�<�H��
�"�m�m�A�.��
�
���=�=��+��
�
��!�\�\��
�
�r]c��|jD]!}|jjddddd��#|j|jj
|jD�cgc]}|j|f��c}�ycc}w)NrK)r,r1rMr<rfrYr��rOrJr*s   rS�testSuccessfulSentMailz*ManagedRelayerTests.testSuccessfulSentMailb�i�����	=�A��J�J����T�4��t�<�	=�	
����L�L� � �d�m�m�"L��D�L�L�!�#4�"L�	
��"L��A<
c��|jD]!}|jjddddd��#|j|jj
|jD�cgc]}|j|f��c}�ycc}w)Ni&)r,r1rMr<rfr r�rks   rS�testFailedSentMailz&ManagedRelayerTests.testFailedSentMailjrmrnc���|jjtjt	���|j|jj|jg�yrv)	r1r�r �Failurer>r<rfrZr�r_s rS�testConnectionLostz&ManagedRelayerTests.testConnectionLostrs?���
�
�!�!�'�/�/�)�+�">�?�������*�*�T�\�\�N�;r]N)rXrorprxrlrprsr3r]rSrdrdWs��*�
�
�<r]rdc���eZdZd�Zd�Zeejdk\d�d��Zeejdk\d�d��Z	eejdk\d�d��Z
d�Zy	)
�DirectoryQueueTestsc� �|j�|_tj|j�tj
j
|j�|_d|j_td�D]g}|jj�\}}|5tjd|g|�ddd�|jd|fz�|j��i|jj�y#1swY�KxYw)NF��headersbody: %d)r�r�r�rBr	rg�Queue�queue�noisyr:�createNewMessagerDrEr�r��
readDirectory)rOr*�hdrF�msgFs    rSrxzDirectoryQueueTests.setUpys����k�k�m���
��������&�&�,�,�T�[�[�9��
� ��
�
���r��	�A����4�4�6�J�D�$��
1����X�q�M�4�0�
1����k�Q�D�0�1�����	�	
�
�
� � �"�	
1�
1�s�!D�D
	c�B�tj|j�yrvr�r_s rSr]zDirectoryQueueTests.tearDown�r�r]r(r*c�4�|j|jj��|jt	|jj��d�|jj�}|jj
|d�|jt	|jj��d�|jj|d�|jt	|jj��d�y)Nrwr�)rGrz�
hasWaitingr<r=�
getWaiting�setRelaying�
setWaiting)rO�waitings  rS�testWaitingzDirectoryQueueTests.testWaiting�s�������
�
�-�-�/�0�����T�Z�Z�2�2�4�5�r�:��*�*�'�'�)���
�
���w�q�z�*�����T�Z�Z�2�2�4�5�r�:��
�
���g�a�j�)�����T�Z�Z�2�2�4�5�r�:r]c	��|jj�D]t}|jj|�|jt	|jj��dt	|jj��z
��v|j
|jj��|jj�}|jj|d�|jt	|jj��d�|jt	|jj��d�y)Nrwrrfr�)	rzr�r�r<r=�
getRelayedr�r�r�)rOr*�relayeds   rS�testRelayingz DirectoryQueueTests.testRelaying�s������&�&�(�	�A��J�J�"�"�1�%�����D�J�J�)�)�+�,�b�3�t�z�z�7L�7L�7N�3O�.O�
�	�	
������.�.�0�1��*�*�'�'�)���
�
���g�a�j�)�����T�Z�Z�2�2�4�5�q�9�����T�Z�Z�2�2�4�5�r�:r]c�"�|jj�d}|jj|�|jj|�|j	t|jj��d�|j	t|jj
��d�|j||jj�v�|j||jj
�v�y)Nrr�)rzr�r�rZr<r=r�r�)rO�msgs  rS�testDonezDirectoryQueueTests.testDone�s����j�j�#�#�%�a�(���
�
���s�#��
�
���������T�Z�Z�2�2�4�5�r�:�����T�Z�Z�2�2�4�5�q�9������
�
� 5� 5� 7�7�8������
�
� 5� 5� 7�7�8r]c� �g}|jj�D],}|j|jj|���.|j	�td�D]%}|j
|jd�d|g��'y)Nrwrrx)rzr�r)�getEnveloperBr:r<�pop)rO�	envelopesr�rJs    rS�testEnvelopez DirectoryQueueTests.testEnvelope�s|���	��:�:�(�(�*�	:�C����T�Z�Z�3�3�C�8�9�	:�	�����r��	>�A����Y�]�]�1�-��!�}�=�	>r]N)rXrorprxr]rrqrrr�r�r�r�r3r]rSruruws���#�#��C����$�&>�?�	;�@�	;��C����$�&>�?�;�@�;��C����$�&>�?�	9�@�	9�>r]ru)�client�common�serverc��eZdZd�Zdd�Zy)�
TestAuthorityc�P�tjj|�i|_yrv)r��ResolverBaser&�	addressesr_s rSr&zTestAuthority.__init__�s�����$�$�T�*���r]Nc���||jvr�|tjk(r�g}|j|D]\}tj|tjtjdtj
d|��}|j
|��^tj|ggf�Stjtjtj|���S)N�<r)
r�r�MXr�INrr)r�succeed�failr rr�DomainError)rOr��cls�type�timeoutr-r5r�s        rS�_lookupzTestAuthority._lookup�s����4�>�>�!�d�c�f�f�n��G��^�^�D�)�
$���l�l�4��������S�]�]�1�a�=P�Q�����s�#�
$��=�=�'�2�r�!2�3�3��z�z�'�/�/�#�/�/�$�*?�@�A�Ar]rv)rXrorpr&r�r3r]rSr�r��s
���Br]r�c���t�|_tj|jg�}t	j
|�}	t
jd|d��|_|jj�j}	t
j||d��|_	tjd|fg��|_y#t$r|jj�YnwxYw��)Nrr���	interface)�servers)r��authr��DNSServerFactoryr�DNSDatagramProtocolr�	listenTCP�port�getHost�	listenUDP�udpPortr�
stopListeningr��Resolver�resolver)rOr�r
�
portNumbers    rS�setUpDNSr��s�����D�I��%�%�t�y�y�k�2�G��&�&�w�/�H�
��%�%�a��K�H��	��Y�Y�&�&�(�-�-�
�	�"�,�,��H���D�L�
��O�O�k�:�-F�,G�H�D�M��	!�	&��I�I�#�#�%�	&��s�C�#C+�*C+c�x�g}|jtj|jj��|jtj|j
j��	|jjj�tj|�S#t$rY� wxYwrv)r)rr�r�r�r�r��
_parseCall�cancel�
BaseException�DeferredList)rO�dls  rS�tearDownDNSr��s���	�B��I�I�e�!�!�$�)�)�"9�"9�:�;��I�I�e�!�!�$�,�,�"<�"<�=�>�
��
�
� � �'�'�)����b�!�!���
��
�s�4$B-�-	B9�8B9c��eZdZdZd�Zd�Zd�Zeejdk\d�d��Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zeejdk\d�d��Zd�Zd�Zd�Zd�Zy)�MXTestsz6
    Tests for L{mail.relaymanager.MXCalculator}.
    c��t|�tj�|_tj
j
|j|j�|_yrv)	r�rrhrlr	rg�MXCalculatorr��mxr_s rSrxz
MXTests.setUp�s8������Z�Z�\��
��#�#�0�0�����
�
�K��r]c��t|�Srv)r�r_s rSr]zMXTests.tearDown�s
���4� � r]c��|jtjj|j�j
t�y)zQ
        L{MXCalculator}'s default clock is C{twisted.internet.reactor}.
        N)r�r	rgr�r�rlrr_s rS�test_defaultClockzMXTests.test_defaultClock�s2��	
������*�*�4�=�=�9�?�?��	
r]r(r*c��dg|jjd<|jjd�j	|j
�S)N�the.email.test.domainr�)r�r�r��getMXr��_cbSimpleSuccessr_s rS�testSimpleSuccesszMXTests.testSimpleSuccesss=��.E�-F��	�	���M�*��w�w�}�}�]�+�7�7��8M�8M�N�Nr]c��|j|jd�|jt|j�d�y)Nrr�)r<�
preferencerYr��rOr�s  rSr�zMXTests._cbSimpleSuccesss/���������*�����R�W�W��'>�?r]c��d|j_|j|jjd�t�S)NFr�)r��fallbackToDomainr=r��IOErrorr_s rS�testSimpleFailurezMXTests.testSimpleFailures.��#(���� ��!�!�$�'�'�-�-�
�">��H�Hr]c�`�|j|jjd�t�S�Nr�)r=r�r�rr_s rS�testSimpleFailureWithFallbackz%MXTests.testSimpleFailureWithFallbacks"���!�!�$�'�'�-�-�
�">��O�Or]c������G��fd�d�}|��j_�jj��}��fd�}|j|�|S)aZ
        Issue an MX request for the given domain and arrange for it to be
        responded to with the given records.  Verify that the resulting mail
        exchange is the indicated host.

        @type domain: C{str}
        @type records: C{list} of L{RRHeader}
        @type correctMailExchange: C{str}
        @rtype: L{Deferred}
        c���eZdZ��fd�Zy)�,MXTests._exchangeTest.<locals>.DummyResolverc�z��|�k(rtj�ggf�Stjt���Srv)rr�r�r)rOr�r[�recordss  ��rS�lookupMailExchangez?MXTests._exchangeTest.<locals>.DummyResolver.lookupMailExchanges4����6�>� �=�=�'�2�r�):�;�;��z�z�,�v�"6�7�7r]N�rXrorpr�)r[r�s��rS�
DummyResolverr�s���
8r]r�c�P���jt|j���yrv�r<rYr�)�record�correctMailExchangerOs ��rS�gotMailExchangez.MXTests._exchangeTest.<locals>.gotMailExchange's������S����-�/B�Cr])r�r�r�r�)rOr[r�r�r�rQr�s````   rS�
_exchangeTestzMXTests._exchangeTestsH���	8�	8�)�?������G�G�M�M�&�!��	D�	
�
�
�o�&��r]c
��d}d}d}t|tjtd|���t|tjtd|���t|tjtd|���g}|j|||�S)zh
        The MX record with the lowest preference is returned by
        L{MXCalculator.getMX}.
        r��good.example.com�bad.example.comrf�r�r��payloadrr/)rr�TYPEr��rOr[�good�badr�s     rS�test_mailExchangePreferencez#MXTests.test_mailExchangePreference-sx��
��!����
�&�y�~�~�y��C�?P�Q��&�y�~�~�y��D�?Q�R��&�y�~�~�y��C�?P�Q�
��
�!�!�&�'�4�8�8r]c	��d}d}d}t|tjtd|���t|tjtd|���g}|jj	|�|j|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        which is not also marked as bad.
        r�r�r�rr�rf�rrr�r��markBadr�r�s     rS�test_badExchangeExcludedz MXTests.test_badExchangeExcluded=sq��
��!����
�&�y�~�~�y��C�?P�Q��&�y�~�~�y��D�?Q�R�
��	
��������!�!�&�'�4�8�8r]c	�8�d}d}d}t|tjtd|���t|tjtd|���g}|jj	|�|jj	|�|j|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if all the MX records in the response have been marked bad.
        r�r�zworse.example.comrr�rfr�)rOr[r��worser�s     rS�test_fallbackForAllBadExchangesz'MXTests.test_fallbackForAllBadExchangesMs���
����#��
�&�y�~�~�y��C�?P�Q��&�y�~�~�y��E�?R�S�
��	
���������������!�!�&�'�3�7�7r]c	�`�d}d}d}t|tjtd|���t|tjtd|���g}|jj	|�|j
j
|jj�|j|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if it was last marked bad longer than L{MXCalculator.timeOutBadMX}
        seconds ago.
        r�r�r�rr�rf)	rrr�r�r�rlri�timeOutBadMXr��rOr[r��
previouslyBadr�s     rS�test_badExchangeExpireszMXTests.test_badExchangeExpires^s�����!��)�
�
��)�.�.�)�A�}�:U�
�
�&�y�~�~�y��D�?Q�R�	
��	
�����
�&��
�
���4�7�7�/�/�0��!�!�&�'�=�A�Ar]c	��d}d}d}t|tjtd|���t|tjtd|���g}|jj	|�|jj|�|jj|jj�|j|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if it was marked good after it was marked bad.
        r�r�r�rr�rf)
rrr�r�r��markGoodrlrir�r�r�s     rS�test_goodExchangeUsedzMXTests.test_goodExchangeUsedrs���
��!��)�
�
��)�.�.�)�A�}�:U�
�
�&�y�~�~�y��D�?Q�R�	
��	
�����
�&�������'��
�
���4�7�7�/�/�0��!�!�&�'�=�A�Ar]c�����d�d�G��fd�d�}|�|j_|jj��}|j|jt����|S)z�
        If an MX lookup succeeds but the result set is empty,
        L{MXCalculator.getMX} should try to look up an I{A} record for the
        requested name and call back its returned Deferred with that
        address.
        r�zexample.orgc�:��eZdZdZW�gggfiZW�W�iZd�Zd�Zy)�9MXTests.test_successWithoutResults.<locals>.DummyResolverah
            Fake resolver which will respond to an MX lookup with an empty
            result set.

            @ivar mx: A dictionary mapping hostnames to three-tuples of
                results to be returned from I{MX} lookups.

            @ivar a: A dictionary mapping hostnames to addresses to be
                returned from I{A} lookups.
            c�F�tj|j|�Srv)rr�r�r�s  rSr�zLMXTests.test_successWithoutResults.<locals>.DummyResolver.lookupMailExchange�s���}�}�T�W�W�V�_�5�5r]c�F�tj|j|�Srv)rr�r5r�s  rS�
getHostByNamezGMXTests.test_successWithoutResults.<locals>.DummyResolver.getHostByName�s���}�}�T�V�V�F�^�4�4r]N)rXrorpr�r�r5r�r)r[�ips��rSr�r�s-���	
��2�r�2�,�'�B����A�
6�
5r]r��r��r�r�r�r�r<r)rOr�rQr[rs   @@rS�test_successWithoutResultsz"MXTests.test_successWithoutResults�sY�������	5�	5�*)�?������G�G�M�M�&�!��	�
�
�d�&�&�	�r�(:�;��r]c���Gd�d�}|�|j_|jjd�}|j|jtd���|S)a'
        Test that if the MX record lookup fails, fallback is enabled, and an A
        record is available for the name, then the Deferred returned by
        L{MXCalculator.getMX} ultimately fires with a Record_MX instance which
        gives the address in the A record for the name.
        c��eZdZdZd�Zd�Zy)�AMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolverzw
            Fake resolver which will fail an MX lookup but then succeed a
            getHostByName call.
            c�<�tjt��Srv)rr�rr�s  rSr�zTMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolver.lookupMailExchange�s���z�z�,�.�1�1r]c�,�tjd�S)Nr�)rr�r�s  rSrzOMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolver.getHostByName�s���}�}�Y�/�/r]N)rXrorpr�r�rr3r]rSr�r
�s��
�

2�
0r]r�r[r�rr)rOr�rQs   rS�"test_failureWithSuccessfulFallbackz*MXTests.test_failureWithSuccessfulFallback�sL��
	0�
	0�)�?������G�G�M�M�(�#��	�
�
�d�&�&�	�y�(A�B��r]c������d�d�d�G���fd�d�}|�|j_|jj��}|j|jt����|S)z�
        If an MX lookup returns a single CNAME record as a result, MXCalculator
        will perform an MX lookup for the canonical name indicated and return
        the MX record which results.
        �alias.example.com�canonical.example.com�mail.example.comc� ��eZdZdZ���fd�Zy)�;MXTests.test_cnameWithoutGlueRecords.<locals>.DummyResolverz�
            Fake resolver which will return a CNAME for an MX lookup of a name
            which is an alias and an MX for an MX lookup of the canonical name.
            c
�F��|�k(r<tjt|tjt����gggf�S|�k(r=tjt|t
jtd����gggf�Stjt|��S)Nr�r)rr�rrr�rr�r)rOr[�alias�	canonical�exchanges  ���rSr�zNMXTests.test_cnameWithoutGlueRecords.<locals>.DummyResolver.lookupMailExchange�s�����U�?� �=�=�!)�)/�)5�):�):�,8��,C�!"����
����y�(� �=�=�!)�)/�)2���,5�a��,B�!"����
���!�:�:�l�6�&:�;�;r]N)rXrorpr�r�)rrrs���rSr�r�s
���
�

<r]r�rr)rOr�rQrrrs   @@@rS�test_cnameWithoutGlueRecordsz$MXTests.test_cnameWithoutGlueRecords�s_���$��+�	�%��$	<�$	<�L)�?������G�G�M�M�%� ��	�
�
�d�&�&�	�x�(@�A��r]c����Gd�d�}d�|��j_�jjd��}�j|tj
jj���fd�}|j|�|S)z�
        If L{MXCalculator.getMX} encounters a CNAME chain which is longer than
        the length specified, the returned L{Deferred} should errback with
        L{CanonicalNameChainTooLong}.
        c��eZdZdZdZd�Zy)�.MXTests.test_cnameChain.<locals>.DummyResolverz
            Fake resolver which generates a CNAME chain of infinite length in
            response to MX lookups.
            rc	���|xjdz
c_d|jfz}tjt|tj
t	|���gggf�S)Nrf�x-%d.example.comr�)�chainCounterrr�rrr�)rOr[r�s   rSr�zAMXTests.test_cnameChain.<locals>.DummyResolver.lookupMailExchangesg���!�!�Q�&�!�)�T�->�->�,@�@���}�}�%�%+�%1�%6�%6�(4�T�(:�����
��r]N)rXrorpr�rr�r3r]rSr�r�s��
�
�L�
r]r�r)rc�����j|jdtd�dzfz���j�jjj
�dz�y)Nrrrf)r<�argsrr�r�r)r��
cnameLimitrOs ��rS�cbChainTooLongz/MXTests.test_cnameChain.<locals>.cbChainTooLongsV�������
�
�1�
�|�,>�*�q�.�AR�,R�S�
�
���T�W�W�-�-�:�:�J��N�Kr])	r�r�r�r=�twistedr	rg�CanonicalNameChainTooLongr�)rOr�rQr"r!s`   @rS�test_cnameChainzMXTests.test_cnameChain�sp���	�	�2�
�(�?������G�G�M�M�,�j�9�����1�g�l�l�7�7�Q�Q�R�	L�	
�
�
�n�%��r]c�������g�d�d�d�G����fd�d�}|�|j_|jj��}|j|jt����|S)z�
        If an MX lookup returns a CNAME and the MX record for the CNAME, the
        L{Deferred} returned by L{MXCalculator.getMX} should be called back
        with the name from the MX record without further lookups being
        attempted.
        rrrc���eZdZ����fd�Zy)�8MXTests.test_cnameWithGlueRecords.<locals>.DummyResolverc
����|�k7s�rgggfStjt�tjt����t�t
jt�����gggf�S)Nr�r)rr�rrr�r)rOr[rrr�lookedUps  ����rSr�zKMXTests.test_cnameWithGlueRecords.<locals>.DummyResolver.lookupMailExchange3sw����U�?�h���B�<�'��}�}�%�%*�%1�%6�%6�(4�Y�(?��
%�%.�%.�^�^�(1�x�(@��
�����r]Nr�)rrrr*s����rSr�r(2s
���
�
r]r�rr)rOr�rQrrrr*s   @@@@rS�test_cnameWithGlueRecordsz!MXTests.test_cnameWithGlueRecords&sc�����#��+�	�%��	�	�2)�?������G�G�M�M�%� ��	�
�
�d�&�&�	�x�(@�A��r]c����d�d�G��fd�d�}|�|j_|jj��}|j|tj
jj�|S)z�
        If an MX lookup returns two CNAME records which point to each other,
        the loop should be detected and the L{Deferred} returned by
        L{MXCalculator.getMX} should be errbacked with L{CanonicalNameLoop}.
        zcname1.example.comzcname2.example.comc���eZdZ��fd�Zy)�<MXTests.test_cnameLoopWithGlueRecords.<locals>.DummyResolverc
����tjt�tjt����t�tjt����gggf�S)Nr�)rr�rrr�)rOr[�
firstAlias�secondAliass  ��rSr�zOMXTests.test_cnameLoopWithGlueRecords.<locals>.DummyResolver.lookupMailExchangeZsb����}�}�%�%/�%1�%6�%6�(4�[�(A��
%�%0�%1�%6�%6�(4�Z�(@��
�����r]Nr�)r0r1s��rSr�r.Ys���
r]r�)r�r�r�r=r#r	rg�CanonicalNameLoop)rOr�rQr0r1s   @@rS�test_cnameLoopWithGlueRecordsz%MXTests.test_cnameLoopWithGlueRecordsPs`���*�
�*��	�	�*)�?������G�G�M�M�*�%�����1�g�l�l�7�7�I�I�J��r]c��gd�|jjd<|jjd�j	|j
�S)N)zmx1.test.domainzmx2.test.domainzmx3.test.domainr�)r�r�r�r�r��_cbManyRecordsSuccessfulLookupr_s rS�testManyRecordszMXTests.testManyRecordsssC��.
��	�	���M�*�
�w�w�}�}�]�+�7�7��/�/�
�	
r]c�:�|jt|j�jdd�ddv�|jjt|j��|jj
d�j|j|�S)N�.rfr)�mx1�mx2�mx3r�)	rGrYr�r�r�r�r�r��_cbManyRecordsDifferentResultr�s  rSr5z&MXTests._cbManyRecordsSuccessfulLookup~sq������B�G�G��*�*�3��2�1�5�9N�N�O�������B�G�G��%��w�w�}�}�]�+�7�7��.�.��
�	
r]c�:�|jt|j�t|j��|jj	t|j��|jjd�j
|j||�Sr�)r�rYr�r�r�r�r��_cbManyRecordsLastResult)rO�nextMXr�s   rSr<z%MXTests._cbManyRecordsDifferentResult�si�����C����L�#�f�k�k�*:�;�������F�K�K�(�)��w�w�}�}�]�+�7�7��)�)�2�v�
�	
r]c��|jt|j�t|j��|jt|j�t|j��|jj	t|j��|jjt|j��|jj
d�j|j|�Sr�)	r�rYr�r�r�r�r�r��"_cbManyRecordsRepeatSpecificResult)rO�lastMXr�r?s    rSr>z MXTests._cbManyRecordsLastResult�s������C����L�#�f�k�k�*:�;����C����,�c�&�+�+�.>�?�������F�K�K�(�)�������V�[�[�)�*��w�w�}�}�]�+�7�7��3�3�V�
�	
r]c�t�|jt|j�t|j��yrvr�)rO�againMXr?s   rSrAz*MXTests._cbManyRecordsRepeatSpecificResult�s$������W�\�\�*�C����,<�=r]N)rXrorpr�rxr]r�rrqrrr�r�r�r�r�r�r�r�r�r�rr
rr%r+r3r6r5r<r>rAr3r]rSr�r��s����L�
!�
��C����$�&>�?�O�@�O�@�I�P��69� 9� 8�"B�(B�("�H�23�j,�\(�T!�F�C����$�&>�?�
�@�
�
�
�	
�>r]r�c��eZdZejed��dZd�Zd�Ze	e
jdk\d�d��Ze	e
jdk\d�d��Z
y)	�LiveFireExerciseTestsNz1UDP support is required to determining MX recordsc�,�t|�gd�|_y)N)�	domainDir�insertionDomain�insertionQueue�destinationDomain�destinationQueue)r��tmpdirsr_s rSrxzLiveFireExerciseTests.setUp�s�����
��r]c��|jD]7}tjj|�s�#t	j
|��9t
|�Srv)rMr�r�r|r[r\r�)rOrQs  rSr]zLiveFireExerciseTests.tearDown�s>�����	!�A��w�w�~�~�a� ��
�
�a� �	!��4� � r]r(r*c������tjj�}|jjtj
j
��tjj|d���jdd�|jd��|jd|jd<t|jdj�j��|jtjj!|��|j#�}t%j&d|d���_t+gd	���t-��t/j0�}�fd
�|_�fd�|_t%j4d�j(j7�j8|���fd�}�j;|��S)
NrHr�r�r�r�rr�r�)�
HELO mesonzMAIL FROM: <user@hostname>zRCPT TO: <user@test.domain>�DATA�This is the messager8�QUITc����Srvr3�r�s�rSr0z9LiveFireExerciseTests.testLocalDelivery.<locals>.<lambda>�����V�r]c�&���jd�Srv��callback�r rZs �rSr0z9LiveFireExerciseTests.testLocalDelivery.<locals>.<lambda>�����t�}�}�T�/B�r]c����jddtj�d}|jd�j	�}�j|j
d�d��jj�S�Nr�rfrrR���)	r�rr�r�r�r��find�
smtpServerr�)�ignr+r�r[rOs   ��rS�finishedz9LiveFireExerciseTests.testLocalDelivery.<locals>.finished�sd����'�'���d�m�m�D�Q�G�D��/�/�!�$�)�)�+�C�������)>� ?��D��?�?�0�0�2�2r])r	r��
smtpPortalrrr��AllowAnonymousAccessr�r�r�r�r�rr��setQueuer1r2r�rr�r`rrr
�
ClientFactory�clientConnectionLost�
connectTCPr�r�r�)rOr�r�rbr�r[rZs`   @@@rS�testLocalDeliveryz'LiveFireExerciseTests.testLocalDelivery�sX����)�)�'�'�)�����*�*�4�=�=�+M�+M�+O�P����1�1�'�;�G�����v�z�*����-��0�%�o�o�m�<�������G�O�O�B��/�/��1N�1N�1P�Q�������0�0��9�:��"�"�$��!�+�+�A�q�K�H���$�
�

���z���"�"�$��#��
�!B������;����(?�(?�(A�(F�(F��J�	3�	
����"��r]c�������	�tjj�}|jjtj
j
��tjj|d��|jd��tjd�|jtjjd��|jj!tj"j%|��tjj'|j(��	�	xj*dz
c_tjj-�	d��tjj/�j0��	_dg�j4j6d<|j9�}t;j<d|d�	��_tjj�}|jjtj
j
��tjj|d
���jAdd�|jd��tjd
�|jtjjd
��tjj-�	d���jC�|j9�}t;j<d|d�	��_"�jDjG�jH�	_%tMgd���tO��tQjR�}�fd�|_(�fd�|_*t;jVd�j>jG�jH|����	�fd�}�jY|��S)NrIzinsertion.domainrJ)ztest.identity.hostnamerfr�zdestination.domainrr�rKr�r�rL)rPzMAIL FROM: <user@wherever>z"RCPT TO: <user@destination.domain>rQrRr8rSc����Srvr3rUs�rSr0z9LiveFireExerciseTests.testRelayDelivery.<locals>.<lambda>rVr]c�&���jd�SrvrXrZs �rSr0z9LiveFireExerciseTests.testRelayDelivery.<locals>.<lambda>r[r]c�X���j�}���fd�}|j|�|S)Nc�V���jddtj�d}|jd�j	�}�j|j
d�d��jj��jj��j�yr])r�rr�r�r�r�r_�	insServerr��
destServer�stopService)rar+r�r[�helperrOs   ���rS�	deliveredzLLiveFireExerciseTests.testRelayDelivery.<locals>.finished.<locals>.delivereds}����+�+�F�D�$�-�-�H��K���o�o�a�(�-�-�/���#�#�C�H�H�-B�$C�R�H����,�,�.����-�-�/��"�"�$r])�
checkStater�)rar�rsr[rrrfrOs   ����rSrbz9LiveFireExerciseTests.testRelayDelivery.<locals>.finisheds-����)�)�+�H�
%�
� � ��+��Or])-r	r�rcrrr�rdr�r�r�r�rBrergryrM�setDefaultDomainr1r2�SmartHostSMTPRelayingManagerrz�fArgs�RelayStateHelperr�r��mxcalcr�r�r�rr�ror��startServicerpr�r��PORTrrr
rfrgrhr�)
rO�insServr��destServrbr�r[rZrrrfs
`    @@@@@rS�testRelayDeliveryz'LiveFireExerciseTests.testRelayDelivery�s�����)�)�'�'�)�����*�*�4�=�=�+M�+M�+O�P����1�1�'�;L�M�����,�f�5�
���!�"�����*�*�0�0�1A�B�C����(�(����)@�)@��)I�J��#�#�@�@����O���
�
�4�4�
��"�"�3�3�G�Q�?���*�*�7�7��
�
�F���5@�M��	�	���0�1��"�"�$�� �*�*�1�a�;�G����9�9�(�(�*�����+�+�D�M�M�,N�,N�,P�Q����1�1�(�<O�P�����v�z�*����/��8�
���#�$����$�+�+�1�1�2D�E�F��"�"�3�3�G�Q�?�������#�#�%��!�+�+�A�q�K�H������.�.�0�5�5���$�
�

���z���"�"�$��#��
�!B������;����(>�(>�(@�(E�(E�q�I�	�"	
����"��r])rXrorpr�IReactorUDPr�skiprxr]rrqrrrir~r3r]rSrFrF�sy���z���g�t�,�4�B��
�!��C����$�&>�?�)�@�)�V�C����$�&>�?�K�@�Kr]rFc�$�eZdZd�Zd�Zd�Zd�Zy)�LineBufferMessagec�.�g|_d|_d|_y)NF)�lines�eom�lostr_s rSr&zLineBufferMessage.__init__-s����
������	r]c�:�|jj|�yrv)r�r))rOr�s  rSr�zLineBufferMessage.lineReceived2s���
�
���$�r]c�:�d|_tjd�S)NTz
<Whatever>)r�rr�r_s rSr�zLineBufferMessage.eomReceived5s������}�}�\�*�*r]c��d|_y)NT)r�r_s rSr�z LineBufferMessage.connectionLost9s	����	r]N)rXrorpr&r�r�r�r3r]rSr�r�,s���
 �+�r]r�c��eZdZgd�Zd�Zeejdk\d�d��Zd�Z	d�Z
eejdk\d�d��Zd	�Zy
)�
AliasTests�z
First linez	Next liner�zAfter a blank linez	Last linec��i}gd�}|D]$}tjj||dd��&|j|dddg�|j|ddg�|j|dd	g�|j|d
gd��y)N)zuser:  another@host
znextuser:  |/bin/program
zuser:  me@again
z"moreusers: :/etc/include/filename
z3multiuser: first@host, second@host,last@anotherhostr$r�zanother@hostzme@again�nextuserz
|/bin/program�	moreusersz:/etc/include/filename�	multiuser)z
first@hostzsecond@hostzlast@anotherhost)r	r�handler<)rOr�r��ls    rS�
testHandlezAliasTests.testHandleAs�����
���	;�A��J�J���f�a��T�:�	;�	
������.�*�)E�F�����
�+�o�->�?������,�/G�.H�I�����;��!R�	
r]r(r*c�8�dt�i}tjj|t	j
t
jd�j����}|jt|�d�|d}t|�}dD]#}|j|j|�d��%|jt|�d�|d	}t|�}d
D]#}|j|j|�d��%|jt|�d�|d}t|�}|j|jd�d�d
D]'}|j|j|�dd|z��)|jt|�d�y)Nr�a�                    # Here's a comment
                       # woop another one
                    testuser:                   address1,address2, address3,
                        continuation@address, |/bin/process/this

                    usertwo:thisaddress,thataddress, lastaddress
                    lastuser:       :/includable, /filename, |/program, address
                    )r�r)�testuser)�address1�address2�address3zcontinuation@addressz/bin/process/thisr^rr�usertwo)�thisaddress�thataddress�lastaddress�lastuserz/includable)z	/filename�programr
z%s not found)r�r	r�
loadAliasFiler�r��textwrap�dedent�encoder<r=rYr�r_)rOrMr��group�sr5s      rS�testFileLoaderzAliasTests.testFileLoaderUsw���v�x�.�����)�)���z�z�����
��&�(��*�
��"	
����V��a�(��z�"����J��
�	/�A�
������q�	�2�.�	/�	
����U��Q�'��y�!����J��>�	/�A�������q�	�2�.�	/�����U��Q�'��z�"����J��������
�.��3�4�	C�A�������q�	�2�~��/A�B�	C�����U��Q�'r]c��t�t�t�f}tjj|�}|jD]}|j|��|j
�j|j|�Srv)	r�r	r�MultiWrapperr�r�r�r��_cbMultiWrapper)rOryr��Ls    rS�testMultiWrapperzAliasTests.testMultiWrapper�sn�� �"�$5�$7�9J�9L�L���j�j�%�%�d�+�����	 �A����Q��	 ���� �,�,�T�-A�-A�4�H�Hr]c���|D]^}|j|j�|j|j�|j	|j
|j
��`yrv)rGr�r�r�r<r�)rOr/ryr*s    rSr�zAliasTests._cbMultiWrapper�sK���	2�A��O�O�A�E�E�"����Q�V�V�$����T�Z�Z����1�	2r]c��|j�}tjj|dd�}|j	�}|j
D]}|j
|��|j�j|j|�Srv)
r�r	r�	FileAlias�createMessageReceiverr�r�r�r��_cbTestFileAlias)rO�tmpfiler5r*r�s     rS�
testFileAliaszAliasTests.testFileAlias�sq���+�+�-���J�J� � ��$��5��
�#�#�%�����	�A�
�N�N�1��	��}�}��*�*�4�+@�+@�'�J�Jr]c���t|�5}|j�}ddd�|jD�cgc]}|dd��	c}|j�y#1swY�7xYwcc}w)Nr^�r��	readlinesr<r�)rOr/r�r�r�r�s      rSr�zAliasTests._cbTestFileAlias�sR��
�'�]�	"�a��K�K�M�E�	"����%�0�Q�!�C�R�&�0�$�*�*�=�	"�	"��0s�A�A�AN)
rXrorpr�r�rrqrrr�r�r�r�r�r3r]rSr�r�=so��N�E�
�(�C����$�&>�?�,(�@�,(�\I�2��C����$�&>�?�K�@�K�>r]r�c��eZdZdZd�Zdd�Zy)�DummyDomainz/
    Test domain for L{AddressAliasTests}.
    c��||_yrv)r
)rOr
s  rSr&zDummyDomain.__init__�s	����r]Nc�T���|rtjjd����fd�S)a

        @returns: When a C{memo} is passed in this will raise a
            L{smtp.SMTPBadRcpt} exception, otherwise a boolean
            indicating if the C{user} and string version of
            L{self.address} are equal or not.
        @rtype: C{bool}
        �hamc�4���t�j�k(Srv)rYr
r�s��rSr0z$DummyDomain.exists.<locals>.<lambda>�s���t�s�4�<�<�0�0�r])r	rr�r�s`` rSr|zDummyDomain.exists�s#�����)�)�'�'��.�.�0�0r]rv)rXrorpr�r&r|r3r]rSr�r��s����1r]r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�AddressAliasTestsz7
    Tests for L{twisted.mail.alias.AddressAlias}.
    c��tjjd�|_|jjt|j�i}tjj|j||j�|_y)z+
        Setup an L{AddressAlias}.
        zfoo@barN)r	rr�r
r[r�r�AddressAlias)rOrMs  rSrxzAddressAliasTests.setUp�sY���y�y�(�(��3����<�<�&�&��D�L�L�(A�B���Z�Z�,�,�T�\�\�7�D�L�L�Q��
r]c�V�|j|jj��y)z�
        L{createMessageReceiever} calls C{exists()} on the domain object
        which key matches the C{alias} passed to L{AddressAlias}.
        N)rGrr�r_s rS�test_createMessageReceiverz,AddressAliasTests.test_createMessageReceiver�s��
	
����
�
�8�8�:�;r]c�N�|jt|j�d�y)zP
        The string presentation of L{AddressAlias} includes the alias.
        z<Address foo@bar>N)r<rYrr_s rSr`zAddressAliasTests.test_str�s��	
����T�Z�Z��*=�>r]c�r�|j|jj|jdi�d�y)z�
        L{resolve} will look for additional aliases when an C{aliasmap}
        dictionary is passed, and returns L{None} if none were found.
        r�N)r<r�resolver
r_s rS�test_resolvezAddressAliasTests.test_resolve�s,��
	
������+�+�T�\�\�5�,A�B�D�Ir]c�Z�|j|jji�d�y)z�
        L{resolve} returns L{None} when the alias could not be found in the
        C{aliasmap} and no L{mail.smtp.User} with this alias exists either.
        N)r<rr�r_s rS�test_resolveWithoutAliasmapz-AddressAliasTests.test_resolveWithoutAliasmap�s#��
	
������+�+�B�/��6r]N)	rXrorpr�rxr�r`r�r�r3r]rSr�r��s"���R�<�?�J�7r]r�c��eZdZdgZy)�DummyProcess�onEndN)rXrorp�	__slots__r3r]rSr�r��s	���	�Ir]r�c��eZdZdZd�Zy)�MockProcessAliaszD
    An alias processor that doesn't actually launch processes.
    c��y)z(
        Don't spawn a process.
        Nr3)rO�protor�r�s    rS�spawnProcesszMockProcessAlias.spawnProcess���r]N)rXrorpr�r�r3r]rSr�r��s���r]r�c��eZdZdZeZy)�MockAliasGroupz3
    An alias group using C{MockProcessAlias}.
    N)rXrorpr�r��processAliasFactoryr3r]rSr�r��s���+�r]r�c�"�eZdZdZd�Zd�Zd�Zy)�StubProcessz�
    Fake implementation of L{IProcessTransport}.

    @ivar signals: A list of all the signals which have been sent to this fake
        process.
    c��g|_yrv)�signalsr_s rSr&zStubProcess.__init__s	����r]c��y)z8
        No-op implementation of disconnection.
        Nr3r_s rS�loseConnectionzStubProcess.loseConnectionr�r]c�:�|jj|�y)zL
        Record a signal sent to this process for later inspection.
        N)r�r))rO�signals  rS�
signalProcesszStubProcess.signalProcess	s��	
�����F�#r]N)rXrorpr�r&r�r�r3r]rSr�r��s�����
$r]r�c� �eZdZdZej
ed��dZgd�Zd�Z	d�Z
d�Zd�Ze
ejd	k\d
�d��Zd�Zd
�Zd�Zd�Zd�Ze
ejd	k\d
�d��Ze
ejd	k\d
�d��Zy)�ProcessAliasTestsz%
    Tests for alias resolution.
    NzIReactorProcess not supportedr�c���|dzdz}|jtj|��|jtj|�|�|jtj|��|S)a
        Construct a status from the given exit code.

        @type code: L{int} between 0 and 255 inclusive.
        @param code: The exit status which the code will represent.

        @rtype: L{int}
        @return: A status integer for the given exit code.
        �r)rGr��	WIFEXITEDr<�WEXITSTATUSr��WIFSIGNALED)rO�code�statuss   rS�
exitStatuszProcessAliasTests.exitStatuss]���!�)�q���	
������V�,�-��������/��6��������/�0��
r]c���|}|jtj|��|jtj|�|�|jtj|��|S)a
        Construct a status from the given signal.

        @type signal: L{int} between 0 and 255 inclusive.
        @param signal: The signal number which the status will represent.

        @rtype: L{int}
        @return: A status integer for the given signal.
        )rGr�r�r<�WTERMSIGr�r�)rOr�r�s   rS�signalStatuszProcessAliasTests.signalStatus0sU����	
������v�.�/�������V�,�f�5�������f�-�.��
r]c�D�tj|_dt_y)zB
        Replace L{smtp.DNSNAME} with a well-known value.
        r�N)r�DNSNAMEr_s rSrxzProcessAliasTests.setUpHs���|�|�����r]c�.�|jt_y)z@
        Restore the original value of L{smtp.DNSNAME}.
        N)r�rr_s rSr]zProcessAliasTests.tearDownOs���|�|��r]r(r*c���t�j��}|jd�tj|j
d�tjj|j
dd�}|j�}�jD]}|j|���fd�}|j�j|�S)z�
        Standard call to C{mail.alias.ProcessAlias}: check that the specified
        script is called, and that the input is correctly transferred to it.
        zX#!/bin/sh
rm -f process.alias.out
while read i; do
    echo $i >> process.alias.out
donei�Nc����td�5}|j�}ddd��jD�cgc]}|dd��	c}�j�y#1swY�7xYwcc}w)Nzprocess.alias.outr^r�)r/r�r�r�rOs    �rS�_cbProcessAliasz<ProcessAliasTests.test_processAlias.<locals>._cbProcessAliasksU����)�*�
&�a����
��
&����e�4��a���f�4�d�j�j�A�
&�
&��4s�A�A �A)r"r��
setContentr��chmodr�r	r�ProcessAliasr�r�r�r�r�)rO�shr5r*r�r�s`     rS�test_processAliasz#ProcessAliasTests.test_processAliasUs�����d�k�k�m�
$��
�
�
�
�	
�	������%� ��J�J�#�#�B�G�G�T�4�8��
�#�#�%�����	�A�
�N�N�1��	�	B�
�}�}��*�*�?�;�;r]c������tj�}t��tjj���j
��tjj�d|�}|j�}|j|j����fd�}�j|tjj�|j|�|S)a
        If the alias child process does not exit within a particular period of
        time, the L{Deferred} returned by L{MessageWrapper.eomReceived} should
        fail with L{ProcessAliasTimeout} and send the I{KILL} signal to the
        child process..
        Nc����j�jdg��jt�j	t
j���y)N�KILL)r<r��processEndedrr�r��SIGKILL)r/r�rOr�s ���rS�timedOutz<ProcessAliasTests.test_processAliasTimeout.<locals>.timedOut�s@������Y�.�.���9�
���0��1B�1B�6�>�>�1R�S�Tr])rrhr�r	r�ProcessAliasProtocolr��MessageWrapperr�ri�completionTimeoutr=�ProcessAliasTimeoutr�)rOr�receiverrQr�r�r�s`    @@rS�test_processAliasTimeoutz*ProcessAliasTests.test_processAliasTimeoutrs�����*�*�,���M�	��
�
�/�/�1��
���Y�'��:�:�,�,�U�D�'�B��� � �"�������2�2�3�	U�	
���1�d�j�j�<�<�=�	�
�
�h���r]c�\�t�}tjj�}|j|�tjj|dd�}|jtjtd���|j|j�t�S)z�
        If the process associated with an L{mail.alias.MessageWrapper} exits
        before I{eomReceived} is called, the L{Deferred} returned by
        I{eomReceived} should fail.
        Nr)r�r	rr�r�r�r�r rrrr=r�)rOr�r
r�s    rS�test_earlyProcessTerminationz.ProcessAliasTests.test_earlyProcessTermination�s~�� �M�	��:�:�2�2�4������	�*��:�:�,�,�X�t�T�B������g�o�o�k�!�n�=�>��!�!�(�"6�"6�"8�+�F�Fr]c�\�t�}tjj�}|j|�tjj|dd�}|jtjt|���|j|j�t�S)z�
        Verify that if the process associated with an
        L{mail.alias.MessageWrapper} exits with the given status, the
        L{Deferred} returned by I{eomReceived} fails with L{ProcessTerminated}.
        N)r�r	rr�r�r�r�r rrrr=r�)rOr�r�r
r�s     rS�_terminationTestz"ProcessAliasTests._terminationTest�s��� �M�	��:�:�2�2�4������	�*��:�:�,�,�X�t�T�B������g�o�o�.?��.G�H�I��!�!�(�"6�"6�"8�:K�L�Lr]c�B�|j|jd��S)z�
        If the process associated with an L{mail.alias.MessageWrapper} exits
        with a non-zero exit code, the L{Deferred} returned by I{eomReceived}
        should fail.
        rf)rr�r_s rS�test_errorProcessTerminationz.ProcessAliasTests.test_errorProcessTermination�s���$�$�T�_�_�Q�%7�8�8r]c�^�|j|jtj��S)z�
        If the process associated with an L{mail.alias.MessageWrapper} exits
        because it received a signal, the L{Deferred} returned by
        I{eomReceived} should fail.
        )rr�r��SIGHUPr_s rS�test_signalProcessTerminationz/ProcessAliasTests.test_signalProcessTermination�s$���$�$�T�%6�%6�v�}�}�%E�F�Fr]c	�r�i}dt|gd��i}tgd�|d�}tddg|d�}tjj	d|d�}|j|||d	��|j
|�}tt|j�}|j�tttjj	d
dd�tjjt�d�tjjd
�g�}|j�|j||�|j
|�}	tt|	j�}
|
j�tttjj	ddd�tjj	ddd�g�}|j�|j|
|�|j
|�}tt|j�}|j�tttjj	d
dd�tjjt�d�tjjd
�g�}|j�|j||�y)a�
        Check that the C{resolve} method of alias processors produce the correct
        set of objects:
            - direct alias with L{mail.alias.AddressAlias} if a simple input is passed
            - aliases in a file with L{mail.alias.FileWrapper} if an input in the format
              '/file' is given
            - aliases resulting of a process call wrapped by L{mail.alias.MessageWrapper}
              if the format is '|process'
        r�)r�r�r�)r��|echo�/file�alias1r�r��alias2�alias3�r
rrr�N�echor)�
TestDomainr�r	rr�rHr�rrY�objsrBr�r��FileWrapperr<)
rOr�r[�A1�A2�A3�res1�r1�expected�res2�r2�res3�r3s
             rS�test_aliasResolutionz&ProcessAliasTests.test_aliasResolution�s�����j��*E�F�G��
�7���
J��
�W�g�.���
A��
�Z�Z�
$�
$�X�v�x�
@��������
�	
��z�z�'�"��
��d�i�i�
 ��
���	����
�
�'�'���t�<��
�
�)�)�,�.�&�A��
�
�&�&�w�/�
�
��	�
�
������X�&��z�z�'�"��
��d�i�i�
 ��
���	����
�
�'�'���t�<��
�
�'�'���t�<�
�
��	�
�
������X�&��z�z�'�"��
��d�i�i�
 ��
���	����
�
�'�'���t�<��
�
�)�)�,�.�&�A��
�
�&�&�w�/�
�
��	�
�
������X�&r]c�<�i}dt|g�i}tjjd|d�}tjjd|d�}tjjd|d�}|j	|||d��|j|dj
|�d�|j|dj
|�d�|j|dj
|�d�tddg|d�}||d<|j
|�}tt|j�}|j�tttjjt�d	�g�}	|	j�|j||	�y)
zN
        Check that a cycle in alias resolution is correctly handled.
        r�rr
rrNr�alias4r)rr	rr�rHr<r�r�rrYrrBr�r�)
rOr�r[rrr�A4�res�rrs
          rS�test_cyclicAliasz"ProcessAliasTests.test_cyclicAlias�sT��
���j��"�-�.��
�Z�Z�
$�
$�X�v�x�
@��
�Z�Z�
$�
$�X�v�x�
@��
�Z�Z�
$�
$�X�v�x�
@�����"��b�A�B������*�2�2�7�;�T�B������*�2�2�7�;�T�B������*�2�2�7�;�T�B�
�W�h�/���
B�������j�j��!����S�X�X���	�����s�T�Z�Z�6�6�|�~�v�N�O�P���
�
������H�%r])rXrorpr�r�IReactorProcessrr�r�r�r�rxr]rrqrrr�rrrrr	rr%r3r]rSr�r�s����"�z�!�!�'�4�0�8�.��N�E��*�0�$��C����$�&>�?�<�@�<�8�4G�M�9�G��C����$�&>�?�>'�@�>'�@�C����$�&>�?�&�@�&r]r�c��eZdZd�Zdd�Zy)rc� �||_||_yrv)r��users)rOr�r)s   rSr&zTestDomain.__init__	s�������
r]Nc�,����jj��|jvr�fd�S	|j�}|j	|j|���r�fd�Stj���#t$rtj���wxYw)Nc�F��tjj�dd�Srv)r	rr�)r�s�rSr0z#TestDomain.exists.<locals>.<lambda>	s���4�:�:�2�2�4��t�D�r]c����Srvr3)r�s�rSr0z#TestDomain.exists.<locals>.<lambda>"	s���w�r])r6�localr)r�r�rr�r�)rOr�r�r5r�s `  @rSr|zTestDomain.exists	s�����y�y�����4�:�:��D�D�	)����T�"�A��i�i����d�3�G��&�&��"�"�4�(�(��
�	)��"�"�4�(�(�	)�s�A4�4Brv)rXrorpr&r|r3r]rSrr	s���)r]rc�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�
DummyQueuez�
    A fake relay queue to use for testing.

    This queue doesn't keep track of which messages are waiting to be relayed
    or are in the process of being relayed.

    @ivar directory: See L{__init__}.
    c��||_y)z�
        @type directory: L{bytes}
        @param directory: The pathname of the directory holding messages in the
            queue.
        N)�	directory)rOr1s  rSr&zDummyQueue.__init__0	s��#��r]c���tjj|�}tj|j	|�dz�tj|j	|�dz�y)z�
        Remove a message from the queue.

        @type message: L{bytes}
        @param message: The base filename of a message.
        rAr>N)r�r��basename�remove�getPath�rOrhs  rSrZzDummyQueue.done8	sL���'�'�"�"�7�+��
�	�	�$�,�,�w�'�$�.�/�
�	�	�$�,�,�w�'�$�.�/r]c�p�ttjj|j|dz�d�S)z�
        Get the envelope file for a message in the queue.

        @type message: L{bytes}
        @param message: The base filename of a message.

        @rtype: L{file}
        @return: The envelope file for the message.
        r>r�)r�r�r�rcr1r6s  rS�getEnvelopeFilezDummyQueue.getEnvelopeFileC	s(���B�G�G�L�L�����4��@�$�G�Gr]c�V�tjj|j|�S)z�
        Return the full base pathname of a message in the queue.

        @type message: L{bytes}
        @param message: The base filename of a message.

        @rtype: L{bytes}
        @return: The full base pathname of the message.
        )r�r�rcr1r6s  rSr5zDummyQueue.getPathO	s���w�w�|�|�D�N�N�G�4�4r]c���tj��dt|���}ttjj|j|dz�d�}tjj|j|dz�}tjj|j|dz�}t|d�}|tjj|||�fS)z�
        Create a new message in the queue.

        @rtype: 2-L{tuple} of (E{1}) L{file}, (E{2}) L{FileMessage}
        @return: The envelope file and a message receiver for a new message in
            the queue.
        �_r>r�z-CrA)	�time�idr�r�r�rcr1r	r�)rO�fname�
headerFile�tempFilename�
finalFilename�messageFiles      rSr|zDummyQueue.createNewMessage[	s����9�9�;�-�q��D��
�+���"�'�'�,�,�t�~�~�u�t�|�D�d�K�
��w�w�|�|�D�N�N�E�D�L�A�������T�^�^�U�T�\�B�
��<��.���4�9�9�0�0���}�
�
�	
r]c��y)z�
        Ignore the request to mark a message as waiting to be relayed.

        @type message: L{bytes}
        @param message: The base filename of a message.
        Nr3r6s  rSr�zDummyQueue.setWaitingm	s��	
r]N)
rXrorpr�r&rZr8r5r|r�r3r]rSr/r/&	s&���#�	0�
H�
5�
�$
r]r/c��eZdZdZd�Zy)�!DummySmartHostSMTPRelayingManagera4
    A fake smart host to use for testing.

    @type managed: L{dict} of L{bytes} -> L{list} of
        L{list} of L{bytes}
    @ivar managed: A mapping of a string identifying a managed relayer to
        filenames of messages the managed relayer is responsible for.

    @ivar queue: See L{__init__}.
    c� �i|_||_y)z�
        Initialize the minimum necessary members of a smart host.

        @type queue: L{DummyQueue}
        @param queue: A queue that can be used for testing purposes.
        N)�managedrz)rOrzs  rSr&z*DummySmartHostSMTPRelayingManager.__init__�	s�������
r]N)rXrorpr�r&r3r]rSrErEw	s��	�r]rEc���eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
eej dk\d
�d��Zeej dk\d
�d��Zd�Zd�Zd�Zd�Zy)�_AttemptManagerTestsa
    Test the behavior of L{_AttemptManager}.

    @type tmpdir: L{bytes}
    @ivar tmpdir: The path to a temporary directory holding the message files.

    @type reactor: L{MemoryReactorClock}
    @ivar reactor: The reactor used for test purposes.

    @type eventLog: L{None} or L{dict} of L{bytes} -> L{object}
    @ivar eventLog: Information about the last informational log message
        generated or none if no log message has been generated.

    @type noisyAttemptMgr: L{_AttemptManager}
    @ivar noisyAttemptMgr: An attempt manager which generates informational
        log messages.

    @type quietAttemptMgr: L{_AttemptManager}
    @ivar quietAttemptMgr: An attempt manager which does not generate
        informational log messages.

    @type noisyMessage: L{bytes}
    @ivar noisyMessage: The full base pathname of the message to be used with
        the noisy attempt manager.

    @type quietMessage: L{bytes}
    @ivar quietMessage: The full base pathname of the message to be used with
        the quiet.
    c��|j�|_tj|j�t	�|_d|_tj|j�ttt|j��d|j
�|_
ttt|j��d|j
�|_d}d}tjj!|j|�|_tjj!|j|�|_t'|j"dzd�j)�t'|j$dzd�j)�|g|jj*j,d<|g|jj*j,d	<t'|j"d
zd�5}t/j0dd
g|�ddd�t'|j$d
zd�5}t/j0ddg|�ddd�y#1swY�DxYw#1swYyxYw)a
        Set up a temporary directory for the queue, attempt managers with the
        noisy flag on and off, message files for use with each attempt manager,
        and a reactor.  Also, register to be notified when log messages are
        generated.
        NTF�noisyMessage�quietMessagerArs�noisyRelayer�quietRelayerr>r�zfrom-noisy@domainzto-noisy@domainzfrom-quiet@domainzto-quiet@domain)r�r�r�rBrr�eventLogr!�addObserver�_logObserverrrEr/�noisyAttemptMgr�quietAttemptMgrr�rcrKrLr�r�rfrGrDrE)rO�
noisyBaseName�
quietBaseName�envelopes    rSrxz_AttemptManagerTests.setUp�	s����k�k�m���
�������)�+�����
�����)�)�*�.�-�j����.E�F���L�L� 
���
 /�-�j����.E�F���L�L� 
���'�
�&�
��G�G�L�L����m�D����G�G�L�L����m�D����T�
�
��
%�s�+�1�1�3��T�
�
��
%�s�+�1�1�3�@M�����$�$�,�,�^�<�@M�����$�$�,�,�^�<�
�$�#�#�d�*�D�
1�	L�X��K�K�,�.?�@�(�K�	L��$�#�#�d�*�D�
1�	L�X��K�K�,�.?�@�(�K�	L�	L�	L�	L��	L�	L�s�+I�%I�I�Ic��tj|j�tj|j
�y)zO
        Unregister for log events and remove the temporary directory.
        N)r!�removeObserverrQr[r\r�r_s rSr]z_AttemptManagerTests.tearDown�	s(��	���4�,�,�-��
�
�d�k�k�"r]c��||_y)z�
        A log observer.

        @type eventDict: L{dict} of L{bytes} -> L{object}
        @param eventDict: Information about the last informational log message
            generated.
        N)rO)rO�	eventDicts  rSrQz!_AttemptManagerTests._logObserver�	s��"��
r]c��ttt|j���}|j	|j
�y)z�
        When an attempt manager is created without the noisy parameter, the
        noisy instance variable should default to true.
        N)rrEr/r�rGr{�rO�ams  rS�test_initNoisyDefaultz*_AttemptManagerTests.test_initNoisyDefault�	s-��
�>�z�$�+�+�?V�W�
X��������!r]c�N�|j|jj�y)z�
        When an attempt manager is created with the noisy parameter set to
        true, the noisy instance variable should be set to true.
        N)rGrRr{r_s rS�test_initNoisyz#_AttemptManagerTests.test_initNoisy�	s��
	
����,�,�2�2�3r]c�N�|j|jj�y)z�
        When an attempt manager is created with the noisy parameter set to
        false, the noisy instance variable should be set to false.
        N)r�rSr{r_s rS�test_initQuietz#_AttemptManagerTests.test_initQuiet�	s��
	
����-�-�3�3�4r]c��ttt|j���}|j	|j
t
�y)z�
        When an attempt manager is created without the reactor parameter, the
        reactor instance variable should default to the global reactor.
        N)rrEr/r�r<rr\s  rS�test_initReactorDefaultz,_AttemptManagerTests.test_initReactorDefault
s1��
�>�z�$�+�+�?V�W�
X��������W�-r]c�d�|j|jj|j�y)z�
        When an attempt manager is created with a reactor provided, the
        reactor instance variable should default to that reactor.
        N)r<rRrr_s rS�test_initReactorz%_AttemptManagerTests.test_initReactor

s$��
	
����-�-�5�5�t�|�|�Dr]c��|jjd|j�|j|j�y)zw
        For an attempt manager with the noisy flag set, notifySuccess should
        result in a log message.
        rMN)rRr]rKrGrOr_s rS�test_notifySuccessNoisyz,_AttemptManagerTests.test_notifySuccessNoisy
s0��
	
���*�*�>�4�;L�;L�M�����
�
�&r]c��|jjd|j�|j|j�y)z|
        For an attempt manager with the noisy flag not set, notifySuccess
        should result in no log message.
        rNN)rSr]rLr�rOr_s rS�test_notifySuccessQuietz,_AttemptManagerTests.test_notifySuccessQuiet
s2��
	
���*�*�>�4�;L�;L�M�������'r]r(r*c��|jjd|j�|j|j�y)zw
        For an attempt manager with the noisy flag set, notifyFailure should
        result in a log message.
        rMN)rRr`rKrGrOr_s rS�test_notifyFailureNoisyz,_AttemptManagerTests.test_notifyFailureNoisy!
s0��	
���*�*�>�4�;L�;L�M�����
�
�&r]c��|jjd|j�|j|j�y)z|
        For an attempt manager with the noisy flag not set, notifyFailure
        should result in no log message.
        rNN)rSr`rLr�rOr_s rS�test_notifyFailureQuietz,_AttemptManagerTests.test_notifyFailureQuiet*
s2��	
���*�*�>�4�;L�;L�M�������'r]c�p�|jjd�|j|j�y)zt
        For an attempt manager with the noisy flag set, notifyDone should
        result in a log message.
        rMN)rRrbrGrOr_s rS�test_notifyDoneNoisyz)_AttemptManagerTests.test_notifyDoneNoisy3
s(��
	
���'�'��7�����
�
�&r]c�p�|jjd�|j|j�y)zy
        For an attempt manager with the noisy flag not set, notifyDone
        should result in no log message.
        rNN)rSrbr�rOr_s rS�test_notifyDoneQuietz)_AttemptManagerTests.test_notifyDoneQuiet;
s*��
	
���'�'��7�������'r]c��|jjd�|j|j�|jjd�y)z|
        For an attempt manager with the noisy flag set, notifyNoConnection
        should result in a log message.
        rMr�N)rR�notifyNoConnectionrGrOrrir_s rS�test_notifyNoConnectionNoisyz1_AttemptManagerTests.test_notifyNoConnectionNoisyC
s:��
	
���/�/��?�����
�
�&������R� r]c��|jjd�|j|j�|jjd�y)z�
        For an attempt manager with the noisy flag not set, notifyNoConnection
        should result in no log message.
        rNr�N)rSrtr�rOrrir_s rS�test_notifyNoConnectionQuietz1_AttemptManagerTests.test_notifyNoConnectionQuietL
s<��
	
���/�/��?�������'������R� r]N)rXrorpr�rxr]rQr^r`rbrdrfrhrjrrqrrrlrnrprrrurwr3r]rSrIrI�	s����<+L�Z#�"�"�4�5�.�E�'�(��C����$�&>�?�'�@�'��C����$�&>�?�(�@�(�'�(�!�!r]rI)r��
email.messager��email.parserrr�r�r�rDr[r�rqrRr�r<�hashlibr�unittestr�zope.interfacerr�zope.interface.verifyr�twisted.cred.checkersr#�twisted.cred.credentials�twisted.cred.portal�twisted.mail.alias�twisted.mail.mail�twisted.mail.maildir�twisted.mail.protocols�twisted.mail.relay�twisted.mail.relaymanagerrr	�twisted.internetr
rrr
rr�twisted.internet.deferr�twisted.internet.errorrrrr�twisted.internet.testingrrr�twisted.mailrrr�
twisted.namesr�twisted.names.dnsrrr�twisted.names.errorr�twisted.pythonr r!�twisted.python.filepathr"�twisted.python.runtimer#�twisted.trial.unittestr$r'rtr�r�r�r�r�r�� _MaildirMailboxAppendMessageTaskrr%r5rOrXr�r�r�r�r�rr�r$r(r;rWrdrur�r�r�r�r�r�r�r�rFr�r�r�r�r�rr�r��
AliasGroupr�r�r�rr/rErIr3r]rS�<module>r�s��������	�	�
�
�
�
������1�-��������� ��P�P�+�����
$�5��?�?�,�'�,�/�+�����!C�D�e:�h�e:�E�e:�P����!C�D�G�(�G�E�G�����!C�D�#
��#
�E�#
�L����!C�D�5�x�5�E�5�B����!C�D�=7�(�=7�E�=7�@����!C�D�<�x�<�E�<�6����!C�D�J6�X�J6�E�J6�Z����!C�D�C��L�L�1�1�C�E�C�4��2����!C�D�P�x�)9�P�E�P�f����!C�D�%
�X�'7�%
�E�%
�P����!C�D�U<�8�U<�E�U<�p����!C�D�	T��	T�E�	T�����!C�D�p
�x�p
�E�p
�f
�T�Y�Y�
'�
'�(� "� "�)� "�F����!C�D�KQ��KQ�E�KQ�\����!C�D�F
�x�F
�E�F
�R
�D�I�I�
�
����!C�D�"E��"E�E�"E�J����!C�D�&5�8�&5�E�&5�R
"�
"� ����!C�D�<�(�<�E�<�>����!C�D�A>�(�A>�E�A>�H1�0�B�F�'�'�B�I�&"�����!C�D�l>�h�l>�E�l>�^
����!C�D�L�H�L�E�L�^��"����!C�D�a>��a>�E�a>�H1�1�,����!C�D�&7��&7�E�&7�R���t�z�z�.�.��+�T�Z�Z�*�*�+�$�$�.����!C�D�~&��~&�E�~&�B)�)�(N
�N
�b��.����!C�D�D!�8�D!�E�D!r]
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!