%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/mail/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/mail/test/__pycache__/test_mailmail.cpython-312.pyc

�

Ϫ�fi2���dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZdd
lmZddlmZddlmZdd
lmZGd�de�Zy)zi
Tests for L{twisted.mail.scripts.mailmail}, the implementation of the
command line program I{mailmail}.
�N)�StringIO)�skipIf)�version)�Deferred)�
MemoryReactor)�smtp)�mailmail)�parseOptions)�Failure)�platformType)�TestCasec��eZdZdZe�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zeedk(d�d��Zeedk(d�d��Zd�Zd�Zd�Zy)�OptionsTestsz�
    Tests for L{parseOptions} which parses command line arguments and reads
    message text from stdin to produce an L{Options} instance which can be
    used to send a message.
    c���t��_ddlm}m}|�j�}�jtd||���d�_d�_d�_	�fd�}�jtd|�y)zz
        Override some things in mailmail, so that we capture C{stdout},
        and do not call L{reactor.stop}.
        r)�Logger�textFileLogObserver�_log)�observerNc���|�_|�_|�_tj||j
|j|j�j��S)N)�reactor)	�host�options�identr�sendmail�sender�to�body�
memoryReactor)rrr�selfs   ��A/usr/lib/python3/dist-packages/twisted/mail/test/test_mailmail.pyrz$OptionsTests.setUp.<locals>.sendmail3sJ����D�I�"�D�L��D�J��=�=������
�
�����*�*��
�r)
r�out�twisted.loggerrr�patchr	rrr)rrr�logObserverrs`    r �setUpzOptionsTests.setUp#s`���
�:���>�)�$�(�(�3���
�
�8�V�V�[�%A�B���	������
�
	�	
�
�
�8�Z��2r!c��|jtdtd��|jtt
g�}|j
|jd�y)z�
        If no recipients are given in the argument list and there is no
        recipient header in the message text, L{parseOptions} raises
        L{SystemExit} with a string describing the problem.
        �stdinzSubject: foo

Hello, goodbye.
)zNo recipients specified.N)r$�sysr�assertRaises�
SystemExitr
�assertEqual�args�r�excs  r �test_unspecifiedRecipientsz'OptionsTests.test_unspecifiedRecipientsAsC��	
�
�
�3���*S�!T�U����
�L�"�=��������#@�Ar!c�t�|jttdg�}|j|jd�y)z�
        The I{-bp} option for listing queue information is unsupported and
        if it is passed to L{parseOptions}, L{SystemExit} is raised.
        z-bp�zUnsupported option.N�r*r+r
r,r-r.s  r �test_listQueueInformationz&OptionsTests.test_listQueueInformationKs/��
���
�L�5�'�B��������#;�<r!c�t�|jttdg�}|j|jd�y)z�
        The I{-bs} option for using stdin and stdout as the SMTP transport
        is unsupported and if it is passed to L{parseOptions}, L{SystemExit}
        is raised.
        z-bsr2Nr3r.s  r �test_stdioTransportz OptionsTests.test_stdioTransportS�/�����
�L�5�'�B��������#;�<r!c���|jttdg�}|j|jd�|jttdg�}|j|jd�y)z�
        The I{-i} and I{-oi} options for ignoring C{"."} by itself on a line
        are unsupported and if either is passed to L{parseOptions},
        L{SystemExit} is raised.
        z-ir2z-oiNr3r.s  r �test_ignoreFullStopz OptionsTests.test_ignoreFullStop\sZ�����
�L�4�&�A��������#;�<����
�L�5�'�B��������#;�<r!c�t�|jttdg�}|j|jd�y)z�
        The I{-om} option for copying the sender if they appear in an alias
        expansion is unsupported and if it is passed to L{parseOptions},
        L{SystemExit} is raised.
        z-omr2Nr3r.s  r �test_copyAliasedSenderz#OptionsTests.test_copyAliasedSendergr7r!c��t�}|jtd|�|jtt
d�}|j
|jd�|j�}|j
|dt�d��y)z~
        The I{--version} option displays the version and raises
        L{SystemExit} with L{None} as the exit code.
        �stdoutz	--versionNzmailmail version: �
)
rr$r)r*r+r
r,�code�getvaluer)rr"�systemExitCode�datas    r �test_versionzOptionsTests.test_versionpsj��
�j���
�
�3��#�&��*�*�:�|�[�Q������,�,�d�3��|�|�~������!3�G�9�B�?�@r!c��td�}|jtd|�td�}|j	|j
�y)zA
        The I{-odb} flag specifies background delivery.
        r>r(z-odbN)rr$r)r
�
assertTrue�
background�rr(�os   r �test_backgroundDeliveryz$OptionsTests.test_backgroundDelivery}s7�������
�
�3���'��� ��������%r!c��td�}|jtd|�td�}|j	|j
�y)zB
        The I{-odf} flags specifies foreground delivery.
        r>r(z-odfN)rr$r)r
�assertFalserFrGs   r �test_foregroundDeliveryz$OptionsTests.test_foregroundDelivery�s9�������
�
�3���'��� ��������&r!c��td�}|jtd|�td�}|j	t|j�d�y)zd
        The I{-t} flags specifies that recipients should be obtained
        from headers.
        zTo: Curly <invaliduser2@example.com>
Cc: Larry <invaliduser1@example.com>
Bcc: Moe <invaliduser3@example.com>

Oh, a wise guy?
r(�-t�N)rr$r)r
r,�lenrrGs   r �test_recipientsFromHeadersz'OptionsTests.test_recipientsFromHeaders�sG��
�
 �
��	
�
�
�3���'���������Q�T�T��A�&r!c��td�}|jtd|�tgd��}|j	|j
d�y)zw
        When a message has no I{From:} header, a I{From:} value can be
        specified with the I{-F} flag.
        z3To: invaliduser2@example.com
Subject: A wise guy?

r()�-F� Larry <invaliduser1@example.com>rNrTN�rr$r)r
r,rrGs   r �test_setFromzOptionsTests.test_setFrom�s?��
�T�U���
�
�3���'��I�J��������#E�Fr!c��td�}|jtd|�tgd��}|j	|j
d�y)z�
        The I{-F} flag specifies the From: value.  However, I{-F} flag is
        overriden by the value of From: in the e-mail header.
        zLTo: Curly <invaliduser4@example.com>
From: Shemp <invaliduser4@example.com>
r()rSz"Groucho <invaliduser5@example.com>rNzinvaliduser4@example.comNrUrGs   r �!test_overrideFromFlagByFromHeaderz.OptionsTests.test_overrideFromFlagByFromHeader�sE��
�
7�
��	
�
�
�3���'��K�L��������#=�>r!�win32zImailmail.run() does not work on win32 due to lack of support for getuid()c���d}td�}|jtd|�|jtd|�tj�|j|jjtj��|j|jjdg�|j|jj�|jtj�y)z�
        Call L{mailmail.run}, and specify I{-oep} to print errors
        to stderr.  The sender, to, and printErrors options should be
        set and there should be no failure.
        �ztest_mailmail.py�invaliduser2@example.comz-oepr>�argvr(r\N)rr$r)r	�runr,rr�getloginrrE�printErrors�assertIsNone�failed)rr]r(s   r �test_runErrorsToStderrz#OptionsTests.test_runErrorsToStderr�s���H�������
�
�3���%��
�
�3���'�����������,�,�h�.?�.?�.A�B���������+E�*F�G�������0�0�1����(�/�/�*r!c��td�}|jtd|�|j�}t	j
�}t	j�}t|d�5}|jdj||��ddd�|jtd|�d}|jtd|�tj�|j|jj�d	�|j|jj�d
�|j|jj�d�y#1swY��xYw)z�
        Error messages for illegal UID value, illegal GID value, and illegal
        identity entry will be sent to stderr.
        r>r(�wa[useraccess]
allow=invaliduser2,invaliduser1
deny=invaliduser3,invaliduser4,{}
order=allow,deny
[groupaccess]
allow=invalidgid1,invalidgid2
deny=invalidgid1,invalidgid2,{}
order=deny,allow
[identity]
localhost=funny
[addresses]
smarthost=localhost
default_domain=example.com
N�	LOCAL_CFGr[r]z3Illegal UID in \[useraccess\] section: invaliduser1z3Illegal GID in \[groupaccess\] section: invalidgid1z,Illegal entry in \[identity\] section: funny)rr$r)�mktemp�os�getuid�getgid�open�write�formatr	r^�assertRegexr"r@)rr(�filename�myUid�myGid�fr]s       r �test_readInvalidConfigz#OptionsTests.test_readInvalidConfig�s�������
�
�3���'��;�;�=���	�	����	�	���
�(�C�
 �	�A�
�G�G�/�06�v�e�U�/C�
�	�2	
�
�
�8�[�(�3�G���
�
�3���%���������H�H����F�	
�	
����H�H����F�	
�	
����H�H����!Q�	
�M	�	�s�'"E�Ec��ddlm}|j�}t|d�5}|j	|�ddd�||�S#1swY�xYw)a�
        Read a mailmail configuration file.

        The mailmail script checks the twisted.mail.scripts.mailmail.GLOBAL_CFG
        variable and then the twisted.mail.scripts.mailmail.LOCAL_CFG
        variable for the path to its  config file.

        @param config: path to config file
        @type config: L{str}

        @return: A parsed config.
        @rtype: L{twisted.mail.scripts.mailmail.Configuration}
        r)�
loadConfigreN)�twisted.mail.scripts.mailmailrurgrkrl)r�configrurorrs     r �getConfigFromFilezOptionsTests.getConfigFromFilesK��	=��;�;�=��
�(�C�
 �	�A�
�G�G�F�O�	��(�#�#�	�	�s�A�Ac��|jd�}|j|jd�|jd�}|j|jd�|jd�}|j|jd�|j|jd�|jd�}|j	d|j
�|j|j
dd	d
g�|jd�}|j|jdg�|jd
�}|j|jddg�|jd�}|j|jddg�|j|jddg�|jd�}|j|jdg�|jd�}|j|jdg�|jd�}|j|jddg�|j|jddg�y)zj
        L{twisted.mail.scripts.mailmail.loadConfig}
        parses the config file for mailmail.
        z 
[addresses]
smarthost=localhost�	localhostz'
[addresses]
default_domain=example.comzexample.comz;
[addresses]
smarthost=localhost
default_domain=example.comz1
[identity]
host1=invalid
host2=username:password�host1�host2�username�passwordz+
[useraccess]
allow=invalid1,35
order=allow�#z#
[useraccess]
deny=35,36
order=deny�$z/
[useraccess]
allow=35,36
deny=37,38
order=deny�%�&z(
[groupaccess]
allow=gid1,41
order=allow�)z!
[groupaccess]
deny=41
order=denyz6
[groupaccess]
allow=41,42
deny=43,44
order=allow,deny�*�+�,N)
rxr,�	smarthost�domain�assertNotIn�
identities�	allowUIDs�denyUIDs�	allowGIDs�denyGIDs)rrws  r �test_loadConfigzOptionsTests.test_loadConfigs6��
�'�'�
�
��
	
����)�)�;�7��'�'�
�
��
	
������
�6��'�'�
�
��	
����)�)�;�7�������
�6��'�'�
�
��	
����&�"3�"3�4�����*�*�7�3�j�*�5M�N��'�'�
�
��	
����)�)�B�4�0��'�'�
�
��	
������2�r�(�3��'�'�
�
��	
����)�)�B��8�4�������2�r�(�3��'�'�
�
��	
����)�)�B�4�0��'�'�
�
��	
������2�$�/��'�'�
�
��	
����)�)�B��8�4�������2�r�(�3r!c�����fd�}�jtd|�tj�}d|_tt
��}tj||�y)z�
        L{twisted.mail.scripts.mailmail.senderror} sends mail back to the
        sender if an error occurs while sending mail to the recipient.
        c����j|d��j|dg��j|j�d�t�S)Nzpostmaster@�
testsender�
ValueError)rnr,r@r)rr�	recipientrrs    �r rz-OptionsTests.test_senderror.<locals>.sendmail}sC������V�]�3����Y���7����T�]�]�_�l�;��:�r!rr�N)r$rr	�Optionsrrr��	senderror)rr�opts�fails`   r �test_senderrorzOptionsTests.test_senderrorwsK���	�	
�
�
�4��X�.����!��"����z�|�$�����4��&r!N)�__name__�
__module__�__qualname__�__doc__rrr&r0r4r6r9r;rCrIrLrQrVrXrrrcrsrxr�r��r!r rrs����"�O�M�3�<B�=�=�	=�=�A�&�'�'� G�?�����V��+�	�+�$����V��4
�	�4
�l$�0W4�r'r!r)r�rhr)�ior�unittestr�twisted.copyrightr�twisted.internet.deferr�twisted.internet.testingr�twisted.mailr�twisted.mail.scriptsr	rvr
�twisted.python.failurer�twisted.python.runtimer�twisted.trial.unittestr
rr�r!r �<module>r�sA��
�

�
���%�+�2��)�6�*�/�+�m'�8�m'r!

Zerion Mini Shell 1.0