%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�#���ddlZddlmZddlmZmZddlmZmZddl	m
Z
ddlmZGd�d�Z
eej�Gd	�d
��Zy)�N)�implementer)�error�
interfaces)�client�dns)�DNSNameError)�nativeStringc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�"_SRVConnector_ClientFactoryWrapperc� �||_||_y�N)�-_SRVConnector_ClientFactoryWrapper__connector�2_SRVConnector_ClientFactoryWrapper__wrappedFactory)�self�	connector�wrappedFactorys   �:/usr/lib/python3/dist-packages/twisted/names/srvconnect.py�__init__z+_SRVConnector_ClientFactoryWrapper.__init__s��$��� .���c�N�|jj|j�yr
)r�startedConnectingr)rrs  rrz4_SRVConnector_ClientFactoryWrapper.startedConnectings�����/�/��0@�0@�Arc�:�|jj|�yr
)r�connectionFailed�rr�reasons   r�clientConnectionFailedz9_SRVConnector_ClientFactoryWrapper.clientConnectionFaileds�����)�)�&�1rc�:�|jj|�yr
)r�connectionLostrs   r�clientConnectionLostz7_SRVConnector_ClientFactoryWrapper.clientConnectionLosts�����'�'��/rc�.�t|j|�Sr
)�getattrr)r�keys  r�__getattr__z._SRVConnector_ClientFactoryWrapper.__getattr__s���t�,�,�c�2�2rN)�__name__�
__module__�__qualname__rrrrr#�rrrrs��/�B�2�0�3rrc�h�eZdZdZdZdddidfd�Zd�Zd	�Zd
�Zd�Z	d�Z
d
�Zd�Zd�Z
d�Zd�Zd�Zy)�SRVConnectoraD
    A connector that looks up DNS SRV records.

    RFC 2782 details how SRV records should be interpreted and selected
    for subsequent connection attempts. The algorithm for using the records'
    priority and weight is implemented in L{pickServer}.

    @ivar servers: List of candidate server records for future connection
        attempts.
    @type servers: L{list} of L{dns.Record_SRV}

    @ivar orderedServers: List of server records that have already been tried
        in this round of connection attempts.
    @type orderedServers: L{list} of L{dns.Record_SRV}
    r�tcp�
connectTCPr'Nc
���||_||_|�dntj|�|_||_||_||_||_||_	|	|_
d|_d|_d|_
y)a�
        @param domain: The domain to connect to.  If passed as a text
            string, it will be encoded using C{idna} encoding.
        @type domain: L{bytes} or L{str}

        @param defaultPort: Optional default port number to be used when SRV
            lookup fails and the service name is unknown. This should be the
            port number associated with the service name as defined by the IANA
            registry.
        @type defaultPort: L{int}
        N)�reactor�servicer�domainString�domain�factory�protocol�connectFuncName�connectFuncArgs�connectFuncKwArgs�_defaultPortr�servers�orderedServers)
rr-r.r0r1r2r3r4r5�defaultPorts
          rrzSRVConnector.__init__6sn��.������$�n�d�#�2B�2B�6�2J������ ��
�.���.���!2���'���������"��rc
��|jj�|jj|�|j�s|j�%|jt
jd��ytjdt|j��dt|j��dt|j����}|j|j|j�|j!|fd��|j"r|j%|j&�|j%|j
�y|j(�|j+�y|j(j-�y)z"Start connection to remote server.NzDomain is not defined.�_z._�.c�"�|j�Sr
)�_reallyConnect)�xrs  r�<lambda>z&SRVConnector.connect.<locals>.<lambda>qs��t�/B�/B�/D�r)r1�doStartrr7r0rr�DNSLookupErrorr�
lookupServicer	r.r2�addCallbacks�
_cbGotServers�
_ebGotServers�addCallbackr6�
addErrback�_ebServiceUnknownrr>�connect)r�ds  rrJzSRVConnector.connect]s�����������&�&�t�,��|�|��{�{�"��%�%��(�(�)A�B����$�$�!����.� ����/� ����-�	��A�
�N�N�4�-�-�t�/A�/A�B�
�M�M��D�E�� � ����T�3�3�4�
�L�L��.�.�/�
�^�^�
#����!��N�N�"�"�$rc�J�|jt�g|_g|_yr
)�traprr7r8�r�failures  rrFzSRVConnector._ebGotServerszs�����\�"���� ��rc�4�|\}}}t|�dk(r�|djtjk(r�|djrq|djj
tjd�k(rBtjdt|j��dt|j��d���g|_g|_
|D]Q}|jtjk7s|js�-|jj|j��Sy)N�r�.zService z not available for domain r<)�len�typer�SRV�payload�target�NamerrB�reprr.r0r7r8�append)r�result�answers�auth�add�as      rrEzSRVConnector._cbGotServers�s���#����s���L�A����
���3�7�7�*���
�"�"���
�"�"�)�)�S�X�X�d�^�;��&�&�����%�t�D�K�K�'8�:��
�
��� ����	2�A��v�v���� ��	�	�����&�&�q�y�y�1�		2rc���|jtj�tjdd|j
|j�g|_g|_|j�y)a.
        Connect to the default port when the service name is unknown.

        If no SRV records were found, the service name will be passed as the
        port. If resolving the name fails with
        L{error.ServiceNameUnknownError}, a final attempt is done using the
        default port.
        rN)
rMr�ServiceNameUnknownErrorr�
Record_SRVr6r0r7r8rJrNs  rrIzSRVConnector._ebServiceUnknown�sJ��	���U�2�2�3����q�!�T�->�->����L�M��� ������rc�t�|j�J�|j�J�|js-|js!t|j�|jfS|js$|jr|j|_g|_|jsJ�|jjd���|jdj}d}d}g}|jD]9}|j|k(s�||jz
}|j||f�|dz
}�;tjd|�}|D]d\}}||k\s�|j|}|j|=|jj|�t|j�|jfcStd|jj �d���)a;
        Pick the next server.

        This selects the next server from the list of SRV records according
        to their priority and weight values, as set out by the default
        algorithm specified in RFC 2782.

        At the beginning of a round, L{servers} is populated with
        L{orderedServers}, and the latter is made empty. L{servers}
        is the list of candidates, and L{orderedServers} is the list of servers
        that have already been tried.

        First, all records are ordered by priority and weight in ascending
        order. Then for each priority level, a running sum is calculated
        over the sorted list of records for that priority. Then a random value
        between 0 and the final sum is compared to each record in order. The
        first record that is greater than or equal to that random value is
        chosen and removed from the list of candidates for this round.

        @return: A tuple of target hostname and port from the chosen DNS SRV
            record.
        @rtype: L{tuple} of native L{str} and L{int}
        c�2�|j|jfSr
)�priority�weight)�records rr@z)SRVConnector.pickServer.<locals>.<lambda>�s��f�o�o�v�}�}�-M�r)r"rrQzImpossible z pickServer result.)r7r8r	r0r.�sortrerfrZ�random�randint�strrW�port�RuntimeError�	__class__r$)	r�minPriority�index�	weightSum�weightIndexr?�randrf�chosens	         r�
pickServerzSRVConnector.pickServer�s���0�|�|�'�'�'��"�"�.�.�.��|�|�D�$7�$7�����,�d�l�l�:�:��|�|�� 3� 3��.�.�D�L�"$�D���|�|��|������M��N��l�l�1�o�.�.�����	������	�A��z�z�[�(��Q�X�X�%�	��"�"�E�9�#5�6���
��		��~�~�a��+��(�	7�M�E�6���~����e�,���L�L��'��#�#�*�*�6�2��6�=�=�)�6�;�;�6�6�
	7��[����)@�)@�(A�AT�U�V�Vrc��|jrd|_y|j�\|_|_|j�Jd��|j�Jd��t	|j
|j�}||j|jt||j�g|j��i|j��|_y)NrzMust have a host to connect to.zMust have a port to connect to.)�stopAfterDNSru�hostrlr!r-r3rr1r4r5r)r�connectFuncs  rr>zSRVConnector._reallyConnect�s������ !�D���#���0���	�4�9��y�y�$�G�&G�G�$��y�y�$�G�&G�G�$��d�l�l�D�,@�,@�A��$��I�I��I�I�.�t�T�\�\�B�
��
!�
!�	
�
�$�$�
��rc�`�|jr|jj�yd|_y)zStop attempting to connect.rQN)r�stopConnectingrw�rs rr{zSRVConnector.stopConnecting�s!���>�>��N�N�)�)�+� !�D�rc�r�|j�|jj�y|j�y)z%Disconnect whatever our are state is.N)r�
disconnectr{r|s rr~zSRVConnector.disconnect�s(���>�>�%��N�N�%�%�'����!rc�R�|jsJ�|jj�Sr
)r�getDestinationr|s rr�zSRVConnector.getDestinations!���~�~��~��~�~�,�,�.�.rc�p�|jj||�|jj�yr
)r1r�doStop�rrs  rrzSRVConnector.connectionFailed	s&�����+�+�D�&�9������rc�p�|jj||�|jj�yr
)r1rr�r�s  rrzSRVConnector.connectionLost
s&�����)�)�$��7������r)r$r%r&�__doc__rwrrJrFrErIrur>r{r~r�rrr'rrr)r)"s^��� �L��$����%#�N%�:!�2�,�;W�z
�$"�"�/��rr))ri�zope.interfacer�twisted.internetrr�
twisted.namesrr�twisted.names.errorr�twisted.python.compatr	r�
IConnectorr)r'rr�<module>r�sJ���&�.�%�,�.�3�3�$
�Z�
"�
"�#�l�l�$�lr

Zerion Mini Shell 1.0