%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�ft�� �dZddlmZddlZddlmZddlmZmZm	Z	ddl
mZddlm
Z
mZddlmZdd	lmZmZdd
lmZ	ddlmZddlmZmZmZmZmZmZm Z m!Z!m"Z"dd
l#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1ddl4m5Z5m6Z6ddl7m8Z8m9Z9ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAddlBmCZCmDZDmEZEmFZFddlmGZGddlHmIZImJZJddlKmLZLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddlVmWZWddlXmYZYmZZZGd�d �Z[Gd!�d"eE�Z\	d5d#�Z]Gd$�d%eZ�Z^	d6d&�Z_Gd'�d(eY�Z`Gd)�d*eZ�ZaGd+�d,eZ�ZbGd-�d.eZ�Zce	e>�Gd/�d0eC��Zde	e>�Gd1�d2eF��ZeGd3�d4eY�Zfy#e2$rdZ3dxZxZ!xZZ Y��
wxYw)7z%
Tests for L{twisted.protocols.tls}.
�)�annotationsN)�Union)�	Interface�directlyProvides�implementer)�verifyObject)�given�
strategies)�reactor)�Clock�
deferLater)�	iterbytes)�crypto)	�SSL_CB_HANDSHAKE_DONE�
TLS_METHOD�
Connection�Context�Error�TLSv1_1_METHOD�TLSv1_2_METHOD�TLSv1_METHOD�
WantReadError)�TLSMemoryBIOFactory�TLSMemoryBIOProtocol�_AggregateSmallWrites�_ProducerMembrane�_PullToPush)�PrivateCertificate�optionsForClientTLS)�ClientTLSContext�ServerTLSContext�certPath)�!certificatesForAuthorityAndServerz;pyOpenSSL 16.0.0 or newer required for twisted.protocol.tls)�Deferred�
gatherResults)�ConnectionDone�ConnectionLost)�IHandshakeListener�IOpenSSLClientConnectionCreator�IOpenSSLServerConnectionCreator�IProtocolNegotiationFactory�
IPushProducer�
ISSLTransport�
ISystemHandle)�
ClientFactory�Factory�Protocol�
ServerFactory)�TaskStopped)�NonStreamingProducer�StringTransport)�collapsingPumpPolicy�
loopbackAsync)�log)�Failure)�FilePath)�connectedServerAndClient��ConnectionLostNotifyingProtocol)�SynchronousTestCase�TestCasec�6�eZdZdZefd�Zed��Zd�Zd�Z	y)�HandshakeCallbackContextFactorya
    L{HandshakeCallbackContextFactory} is a factory for SSL contexts which
    allows applications to get notification when the SSL handshake completes.

    @ivar _finished: A L{Deferred} which will be called back when the handshake
        is done.
    c�0�t�|_||_y�N)r$�	_finished�_method)�self�methods  �A/usr/lib/python3/dist-packages/twisted/protocols/test/test_tls.py�__init__z(HandshakeCallbackContextFactory.__init__Ts��!�������c�,�|�}||jfS)z�
        Create a new L{HandshakeCallbackContextFactory} and return a two-tuple
        of it and a L{Deferred} which will fire when a connection created with
        it completes a TLS handshake.
        )rD)�cls�contextFactorys  rH�factoryAndDeferredz2HandshakeCallbackContextFactory.factoryAndDeferredXs������~�7�7�7�7rJc�N�|tzr|jjd�yy)a
        This is the "info callback" on the context.  It will be called
        periodically by pyOpenSSL with information about the state of a
        connection.  When it indicates the handshake is complete, it will fire
        C{self._finished}.
        N)rrD�callback)rF�
connection�where�rets    rH�_infoz%HandshakeCallbackContextFactory._infobs$���(�(��N�N�#�#�D�)�)rJc�f�t|j�}|j|j�|S)zp
        Create and return an SSL context configured to use L{self._info} as the
        info callback.
        )rrE�set_info_callbackrT)rF�contexts  rH�
getContextz*HandshakeCallbackContextFactory.getContextls)��
�$�,�,�'���!�!�$�*�*�-��rJN)
�__name__�
__module__�__qualname__�__doc__rrI�classmethodrNrTrX�rJrHrArAKs/���)���8��8�*�rJrAc�(�eZdZdZd�Zd�Zd�Zd�Zy)�AccumulatingProtocola.
    A protocol which collects the bytes it receives and closes its connection
    after receiving a certain minimum of data.

    @ivar howMany: The number of bytes of data to wait for before closing the
        connection.

    @ivar received: A L{list} of L{bytes} of the bytes received so far.
    c��||_yrC)�howMany)rFrbs  rHrIzAccumulatingProtocol.__init__�s	����rJc��g|_yrC)�received�rFs rH�connectionMadez#AccumulatingProtocol.connectionMade�s	����
rJc���|jj|�ttt|j��|j
k\r|jj�yyrC)rd�append�sum�map�lenrb�	transport�loseConnection�rF�datas  rH�dataReceivedz!AccumulatingProtocol.dataReceived�sE���
�
���T�"��s�3��
�
�&�'�4�<�<�7��N�N�)�)�+�8rJc�Z�|jt�stj|�yyrC)�checkr&r8�err�rF�reasons  rH�connectionLostz#AccumulatingProtocol.connectionLost�s���|�|�N�+��G�G�F�O�,rJN)rYrZr[r\rIrfrprvr^rJrHr`r`vs�����,�
rJr`c�f��
�td��
t�}�
fd�|_�r+ttt
�G�fd�d��}|�}n|r
t
|��}n
t�}t�}t||||�}|jd�}	|�
t�}|	j|��
|	fS)a

    Create a protocol hooked up to a TLS transport hooked up to a
    StringTransport.

    @param serverMethod: The TLS method accepted by the server-side and used by the created protocol. Set to to C{None} to use the default method used by your OpenSSL library.
    l�J)�c����SrCr^��clientProtocols�rH�<lambda>z"buildTLSProtocol.<locals>.<lambda>�s���^�rJc���eZdZ�fd�ZeZy)�-buildTLSProtocol.<locals>.HardCodedConnectionc����SrCr^)rF�tlsProtocol�fakeConnections  �rH�clientConnectionForTLSzDbuildTLSProtocol.<locals>.HardCodedConnection.clientConnectionForTLS�s	���%�%rJN)rYrZr[r��serverConnectionForTLS�r�s�rH�HardCodedConnectionr}�s���
&�&<�"rJr��rGN)
r`r/�protocolrr*r)r!r rr�
buildProtocolr5�makeConnection)�serverrlr��serverMethod�
clientFactoryr�rM�clock�wrapperFactory�sslProtocolrzs  `       @rH�buildTLSProtocolr��s����*�,�7�N�!�O�M�3�M���	�4�6U�	V�	<�	<�
W�	<�-�.���-�\�B�N�-�/�N��G�E�(��F�
�M�5��N�!�.�.�t�4�K���#�%�	����y�)��;�&�&rJc�"�eZdZdZd�Zd�Zd�Zy)�TLSMemoryBIOFactoryTestsz<
    Ensure TLSMemoryBIOFactory logging acts correctly.
    c�P�t�}g}|j}tj|�|j	tj
|�t
�}d�|_d�|_t|d|�}|j�|j�|j|g�y)zs
        L{TLSMemoryBIOFactory.doStart} and L{TLSMemoryBIOFactory.doStop} do
        not log any messages.
        c��yrCr^r^rJrHr{z5TLSMemoryBIOFactoryTests.test_quiet.<locals>.<lambda>���rJc��yrCr^r^rJrHr{z5TLSMemoryBIOFactoryTests.test_quiet.<locals>.<lambda>�r�rJFN)r!rhr8�addObserver�
addCleanup�removeObserverr2�doStart�doStopr�assertEqual)rFrM�logs�logger�wrappedFactory�factorys      rH�
test_quietz#TLSMemoryBIOFactoryTests.test_quiet�s���
*�+�����������������*�*�F�3�&���!-��� ,���%�n�e�^�L��������������r�"rJc��t�}t|dt��}|jd|j	��y)z�
        L{TLSMemoryBIOFactory.logPrefix} amends the wrapped factory's log prefix
        with a short string (C{"TLS"}) indicating the wrapping, rather than its
        full class name.
        FzServerFactory (TLS)N)r!rr2r��	logPrefix)rFrMr�s   rH�test_logPrefixz'TLSMemoryBIOFactoryTests.test_logPrefix�s6��*�+��%�n�e�]�_�M�����.��0A�0A�0C�DrJc��Gd�d�}t�}t|d|��}|jd|j��y)z�
        If the wrapped factory does not provide L{ILoggingContext},
        L{TLSMemoryBIOFactory.logPrefix} uses the wrapped factory's class name.
        c��eZdZy)�BTLSMemoryBIOFactoryTests.test_logPrefixFallback.<locals>.NoFactoryN�rYrZr[r^rJrH�	NoFactoryr�����rJr�FzNoFactory (TLS)N)r!rr�r�)rFr�rMr�s    rH�test_logPrefixFallbackz/TLSMemoryBIOFactoryTests.test_logPrefixFallback�s@��	�	�*�+��%�n�e�Y�[�I�����*�G�,=�,=�,?�@rJN)rYrZr[r\r�r�r�r^rJrHr�r��s���#�(E�ArJr�c������	�
��t�\}}t�}tt�G��fd�dt���tt�Gd�dt���	tt
d|��dtj�fd��|�	��
t|j�d
tj�	fd��|�	��t�fd��
fd
�d
|��\}}}|||fS)a
    Construct a client and server L{TLSMemoryBIOProtocol} connected by an IO
    pump.

    @param greetingData: The data which should be written in L{connectionMade}.
    @type greetingData: L{bytes}

    @return: 3-tuple of client, server, L{twisted.test.iosim.IOPump}
    c�:���eZdZdZdZ��fd�Z�fd�Zd�Z�xZS)�*handshakingClientAndServer.<locals>.ClientFNc�^��t�|����|jj��yyrC)�superrfrl�write)rF�	__class__�clientGreetingDatas ��rHrfz9handshakingClientAndServer.<locals>.Client.connectionMades,����G�"�$�!�-����$�$�%7�8�.rJc���d|_|jj�|_�r|jj	�yy�NT)�	handshookrl�getPeerCertificate�peerAfterHandshake�abortConnection)rF�clientAbortAfterHandshakes �rH�handshakeCompletedz=handshakingClientAndServer.<locals>.Client.handshakeCompleteds7���!�D�N�&*�n�n�&G�&G�&I�D�#�(����.�.�0�)rJc��yrCr^rts  rHrvz9handshakingClientAndServer.<locals>.Client.connectionLost���rJ)	rYrZr[r�r�rfr�rv�
__classcell__)r�r�r�s@��rH�Clientr��s����	�!��	9�
	1�	rJr�c��eZdZdZd�Zd�Zy)�*handshakingClientAndServer.<locals>.ServerFc��d|_yr�)�
handshakedres rHr�z=handshakingClientAndServer.<locals>.Server.handshakeCompleteds	��"�D�OrJc��yrCr^rts  rHrvz9handshakingClientAndServer.<locals>.Server.connectionLostr�rJN)rYrZr[r�r�rvr^rJrH�Serverr�s���
�	#�	rJr��example.com��	trustRootTc����d�S�Ni?Br^)r�s�rHr{z,handshakingClientAndServer.<locals>.<lambda>�������rJ)�isClientr�r�Fc����d�Sr�r^)r�s�rHr{z,handshakingClientAndServer.<locals>.<lambda>!r�rJc�&���jd�SrC�r�)�serverFs�rHr{z,handshakingClientAndServer.<locals>.<lambda>%�����%�%�d�+�rJc�&���jd�SrCr�)�clientFs�rHr{z,handshakingClientAndServer.<locals>.<lambda>&r�rJ)�greetr�)r#rrr(r`rrr/�forProtocol�optionsr2r;)r�r��authCert�
serverCertr��clientr��pumpr�r�r�r�s``      @@@@rH�handshakingClientAndServerr��s����=�>��H�j��G�E��#�$��%��%��$�#�$��%��%��"��M�X�>��$�0�0�1G�H��	�G�"������$�0�0�1G�H��	�G�4�+�+���	��F�F�D��6�4��rJc�"�eZdZdZd�Zd�Zd�Zy)�DeterministicTLSMemoryBIOTestsz�
    Test for the implementation of L{ISSLTransport} which runs over another
    transport.

    @note: Prefer to add test cases to this suite, in this style, using
        L{connectedServerAndClient}, rather than returning L{Deferred}s.
    c��t�\}}}|j|jjd�|j|jjd�|j�|j|jjd�|j|jjd�|j
|jjd�y)a
        The completion of the TLS handshake calls C{handshakeCompleted} on
        L{Protocol} objects that provide L{IHandshakeListener}.  At the time
        C{handshakeCompleted} is invoked, the transport's peer certificate will
        have been initialized.
        FTN)r�r��wrappedProtocolr�r��flush�assertIsNotr�)rFr�r�r�s    rH�test_handshakeNotificationz9DeterministicTLSMemoryBIOTests.test_handshakeNotification6s��� :�;���������/�/�9�9�5�A�����/�/�:�:�E�B��
�
������/�/�9�9�4�@�����/�/�:�:�D�A�����/�/�B�B�D�IrJc��tdd�\}}}|j}|j�|j|jg�y)a
        If some data is written to the transport in C{connectionMade}, but
        C{handshakeDone} doesn't like something it sees about the handshake, it
        can use C{abortConnection} to ensure that the application never
        receives that data.
        s
untrustworthyTN)r�r�r�r�rd�rFr�r�r��wrappedServerProtocols     rH�test_handshakeStopWritingz8DeterministicTLSMemoryBIOTests.test_handshakeStopWritingEsD�� :�:J�D�Q����� &� 6� 6���
�
�����.�7�7��<rJc���t�\}}}|j}|j�|j|jg�|jd�|jd�|j|jg�|jd��|j|jg�|jd��|jdj
|j�d�y)	z�
        If a small amount data is written to the TLS transport, it is only
        delivered if time passes, indicating small-write buffering is in
        effect.
        shelsloF)�advanceClockTrJ�helloN)r�r�r�r�rdr��joinr�s     rH�test_smalWriteBufferingz6DeterministicTLSMemoryBIOTests.test_smalWriteBufferingQs��� :�;����� &� 6� 6���
�
�����.�7�7��<����V�����U�����.�7�7��<��
�
��
�&����.�7�7��<��
�
��
�%�������"7�"@�"@�A�8�LrJN)rYrZr[r\r�r�r�r^rJrHr�r�-s���
J�
=�MrJr�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zefd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�TLSMemoryBIOTestsze
    Tests for the implementation of L{ISSLTransport} which runs over another
    L{ITransport}.
    c��tdd�}|jtj|��|jt	j|��y)zj
        L{TLSMemoryBIOProtocol} instances provide L{ISSLTransport} and
        L{ISystemHandle}.
        N)r�
assertTruer-�
providedByr.)rF�protos  rH�test_interfacesz!TLSMemoryBIOTests.test_interfacesjs>��
%�T�4�0�����
�0�0��7�8����
�0�0��7�8rJc�(�Gd�dt�}Gd�d�}t�}t�}t|d|�}|�}t	||�t|t
��}|j|�|j|j|��y)zw
        L{TLSMemoryBIOProtocol} instances provide the interfaces provided by
        the transport they wrap.
        c��eZdZy)�DTLSMemoryBIOTests.test_wrappedProtocolInterfaces.<locals>.ITransportNr�r^rJrH�
ITransportr�yr�rJr�c��eZdZd�Zy)�ETLSMemoryBIOTests.test_wrappedProtocolInterfaces.<locals>.MyTransportc��yrCr^rns  rHr�zKTLSMemoryBIOTests.test_wrappedProtocolInterfaces.<locals>.MyTransport.write}���rJN)rYrZr[r�r^rJrH�MyTransportr�|s��
rJr�TN)
rr/r rrrr1r�r�r�)rFr�r�r�rMr�rlrs        rH�test_wrappedProtocolInterfacesz0TLSMemoryBIOTests.test_wrappedProtocolInterfacesss{��	��	�	�	�&��
�)�+��,�^�T�=�Q���M�	���J�/�*�>�8�:�F���"�"�9�-����
�-�-�k�:�;rJc���t�}t�}t|d|�}t|t	��}t�}|j
|�|j|j�t�y)a/
        L{TLSMemoryBIOProtocol.getHandle} returns the L{OpenSSL.SSL.Connection}
        instance it uses to actually implement TLS.

        This may seem odd.  In fact, it is.  The L{OpenSSL.SSL.Connection} is
        not actually the "system handle" here, nor even an object the reactor
        knows about directly.  However, L{twisted.internet.ssl.Certificate}'s
        C{peerFromTransport} and C{hostFromTransport} methods depend on being
        able to get an L{OpenSSL.SSL.Connection} object in order to work
        properly.  Implementing L{ISystemHandle.getHandle} like this is the
        easiest way for those APIs to be made to work.  If they are changed,
        then it may make sense to get rid of this implementation of
        L{ISystemHandle} and return the underlying socket instead.
        TN)
r/r rrr1r5r��assertIsInstance�	getHandler)rFr�rMr�r�rls      rH�test_getHandlez TLSMemoryBIOTests.test_getHandle�s\�� �/��)�+��,�^�T�7�K��$�^�X�Z�@��#�%�	�
���Y�'����e�o�o�/��<rJc�n��t��t�}�fd�|_t�}t	|d|�}|jd�}t
�}|j|�|j�j�|j�j|�|j�j|�y)z�
        When L{TLSMemoryBIOProtocol} is connected to a transport, it connects
        the protocol it wraps to a transport.
        c����SrCr^rys�rHr{z7TLSMemoryBIOTests.test_makeConnection.<locals>.<lambda>������rJTN)r1r/r�r rr�r5r��assertIsNotNonerlr��assertIs)rFr�rMr�r�rlrzs      @rH�test_makeConnectionz%TLSMemoryBIOTests.test_makeConnection�s����
"���%��
�!7�
��)�+��,�^�T�=�Q��$�2�2�4�8��#�%�	��"�"�9�-����^�5�5�6�����1�1�9�=��
�
�n�.�.��<rJc�4�t�}t|_tj	�\}}t|d|�}|j
d�}t�}t|_t�}t|d|�}|j
d�}t||�}	||||	fS)z@
        Start handshake between TLS client and server.
        TNF)
r/r1r�rArNrr�r2r!r7)
rFr��clientContextFactory�handshakeDeferredr��sslClientProtocol�
serverFactory�serverContextFactory�sslServerProtocol�connectionDeferreds
          rH�handshakeProtocolsz$TLSMemoryBIOTests.handshakeProtocols�s���&��
�!)�
��

,�>�>�@�	
� ��,�-A�4��W��*�8�8��>��%��
�!)�
��/�1��,�-A�5�-�X��*�8�8��>��*�+<�>O�P������	
�	
rJc�0�|j�\}}}}|S)zr
        The TLS handshake is performed when L{TLSMemoryBIOProtocol} is
        connected to a transport.
        )r)rF�	tlsClient�	tlsServerr�_s     rH�test_handshakez TLSMemoryBIOTests.test_handshake�s$��
6:�5L�5L�5N�2�	�9�/��!� rJc���
�t��t�}�fd�|_t�}t	|d|�}|jd�}t��
t
�}�
fd�|_tt�j�}tj|�}|j|�}t	|d|�}|jd�}	t|	|�}
d�}�j|��
j|�t��
|
g�S)z�
        L{TLSMemoryBIOProtocol} reports errors in the handshake process to the
        application-level protocol object using its C{connectionLost} method
        and disconnects the underlying transport.
        c���t��SrCr<��clientConnectionLosts�rHr{z9TLSMemoryBIOTests.test_handshakeFailure.<locals>.<lambda>�����)H� �*
�rJTNc���t��SrCr<)�serverConnectionLosts�rHr{z9TLSMemoryBIOTests.test_handshakeFailure.<locals>.<lambda>�rrJFc�B�|jjt�yrC)�lostConnectionReason�trapr)r�s rH�cbConnectionLostzATLSMemoryBIOTests.test_handshakeFailure.<locals>.cbConnectionLost�s��

�)�)�.�.�u�5rJ)r$r/r�rArr�r2r:r"�
getContentr�loadPEMr�r7�addCallbackr%)rFr�rr�r	r
�certificateData�certificaterrr
rrrs            @@rH�test_handshakeFailurez'TLSMemoryBIOTests.test_handshakeFailure�s��� (�z��%��
�"
�
�� ?�@��,�-A�4��W��*�8�8��>��'�z��%��
�"
�
��#�8�,�7�7�9��(�0�0��A��*�2�2�;�?��,�-A�5�-�X��*�8�8��>��*�+<�>O�P��	6�	�(�(�)9�:��(�(�)9�:��
!�#7�9K�L�
�	
rJc�^��	�t�}t|_tj	�\}}t|d|�}|j
d��	t�}t|_t�}t|d|�}|j
d�}t|�	���	fd�}|j|�|S)z�
        L{TLSMemoryBIOProtocol.getPeerCertificate} returns the
        L{OpenSSL.crypto.X509} instance representing the peer's
        certificate.
        TNFc����j�}�j|tj��j	|jd�d�y)N�sha256s_D6:F2:2C:74:3B:E2:5E:F9:CA:DA:47:08:14:78:20:75:78:95:9E:52:BD:D2:7C:77:DD:D4:EE:DE:33:BF:34:40)r�r�r�X509r��digest)�ignored�certrFr	s  ��rH�cbHandshookz>TLSMemoryBIOTests.test_getPeerCertificate.<locals>.cbHandshook(sD���$�7�7�9�D��!�!�$����4�������H�%�8�	
rJ)r/r1r�rArNrr�r2r!r7r!)
rFr�rrr�r
rrr,r	s
`        @rH�test_getPeerCertificatez)TLSMemoryBIOTests.test_getPeerCertificate
s����&��
�!)�
��

,�>�>�@�	
� ��,�-A�4��W��*�8�8��>��%��
�!)�
��/�1��,�-A�5�-�X��*�8�8��>���'�):�;�
	�	�%�%�k�2� � rJc������
��d�
t��t�}�fd�|_tj	�\}}t|d|�}|j
d�}tt�
���t�}�fd�|_t�}t|d|�}|j
d�}t||�����
fd�}	|j|	��
��fd�}
|j|
�|S)	��
        Bytes written to L{TLSMemoryBIOProtocol} before the handshake is
        complete are received by the protocol on the other side of the
        connection once the handshake succeeds.
        �
some bytesc����SrCr^rys�rHr{z<TLSMemoryBIOTests.test_writeAfterHandshake.<locals>.<lambda>ArrJTNc����SrCr^��serverProtocols�rHr{z<TLSMemoryBIOTests.test_writeAfterHandshake.<locals>.<lambda>LrrJFc�>���jj���SrC�rlr�)r*rzr
ros ���rHr,z?TLSMemoryBIOTests.test_writeAfterHandshake.<locals>.cbHandshookUs����$�$�*�*�4�0�&�%rJc�\���jdj�j���y�NrJ�r�r�rd�r*rorFr4s ���rH�cbDisconnectedzBTLSMemoryBIOTests.test_writeAfterHandshake.<locals>.cbDisconnected_�"������S�X�X�n�&=�&=�>��ErJ)
r1r/r�rArNrr�r`rkr2r!r7r!)rFr�rrr�r	r
rrr,r;rzr
ror4s`          @@@@rH�test_writeAfterHandshakez*TLSMemoryBIOTests.test_writeAfterHandshake7s������!���%��
�!7�
��

,�>�>�@�	
� ��,�-A�4��W��*�8�8��>��-�c�$�i�8��%��
�!7�
��/�1��,�-A�5�-�X��*�8�8��>��*�+<�>O�P��	&�	�%�%�k�2�	F�	�%�%�n�5� � rJc����
�t�}||_tj�\}}t	|d|�}|jd�}t
t����
t�}�
fd�|_t�}	t	|	d|�}|jd�}
t|
|�}���
fd�}|j|�|S)z{
        Run test where client sends data before handshake, given the sending
        protocol and expected bytes.
        TNc����SrCr^r3s�rHr{z<TLSMemoryBIOTests.writeBeforeHandshakeTest.<locals>.<lambda>wrrJFc�\���jdj�j���yr8r9r:s ���rH�cbConnectionDonezDTLSMemoryBIOTests.writeBeforeHandshakeTest.<locals>.cbConnectionDone�r<rJ)r/r�rArNrr�r`rkr2r!r7r!)rF�sendingProtocolror�rrr�r	r
rrr
rAr4s` `          @rH�writeBeforeHandshakeTestz*TLSMemoryBIOTests.writeBeforeHandshakeTestfs����
&��
�!0�
��

,�>�>�@�	
� ��,�-A�4��W��*�8�8��>��-�c�$�i�8��%��
�!7�
��/�1��,�-A�5�-�X��*�8�8��>��*�+<�>O�P��	F�	�&�&�'7�8�!�!rJc�N��d�G�fd�dt�}|j|��S)r/r0c���eZdZ�fd�Zy)�JTLSMemoryBIOTests.test_writeBeforeHandshake.<locals>.SimpleSendingProtocolc�<��|jj��yrCr6rns �rHrfzYTLSMemoryBIOTests.test_writeBeforeHandshake.<locals>.SimpleSendingProtocol.connectionMade�s������$�$�T�*rJN�rYrZr[rf�ros�rH�SimpleSendingProtocolrF�s���
+rJrJ�r1rC�rFrJros  @rH�test_writeBeforeHandshakez+TLSMemoryBIOTests.test_writeBeforeHandshake�s,�����	+�H�	+��,�,�-B�D�I�IrJc�N��d�G�fd�dt�}|j|��S)z�
        Bytes written to L{TLSMemoryBIOProtocol} with C{writeSequence} are
        received by the protocol on the other side of the connection.
        r0c���eZdZ�fd�Zy)�CTLSMemoryBIOTests.test_writeSequence.<locals>.SimpleSendingProtocolc�`��|jjtt����yrC)rl�
writeSequence�listrrns �rHrfzRTLSMemoryBIOTests.test_writeSequence.<locals>.SimpleSendingProtocol.connectionMade�s������,�,�T�)�D�/�-B�CrJNrHrIs�rHrJrP�s	���
DrJrJrKrLs  @rH�test_writeSequencez$TLSMemoryBIOTests.test_writeSequence�s.���
��	D�H�	D��,�,�-B�D�I�IrJc�N��d�G�fd�dt�}|j|��S)z�
        Bytes written to L{TLSMemoryBIOProtocol} after C{loseConnection} is
        called are not transmitted (unless there is a registered producer,
        which will be tested elsewhere).
        r0c���eZdZ�fd�Zy)�NTLSMemoryBIOTests.test_writeAfterLoseConnection.<locals>.SimpleSendingProtocolc����|jj��|jj�|jjd�|jjdg�y)Nr��world)rlr�rmrRrns �rHrfz]TLSMemoryBIOTests.test_writeAfterLoseConnection.<locals>.SimpleSendingProtocol.connectionMade�sK������$�$�T�*����-�-�/����$�$�X�.����,�,�h�Z�8rJNrHrIs�rHrJrW�s���
9rJrJrKrLs  @rH�test_writeAfterLoseConnectionz/TLSMemoryBIOTests.test_writeAfterLoseConnection�s,�����	9�H�	9��,�,�-B�D�I�IrJc������d�g�G��fd�dt�}�fd���j|d�}|j��fd��|j�fd��|S)zV
        Writing C{unicode} to L{TLSMemoryBIOProtocol} throws a C{TypeError}.
        �helloc���eZdZ��fd�Zy)�QTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.SimpleSendingProtocolc���	|jj��|jjd�|jj�y#t$r.�j	d�|jj�YywxYw)N�bytesT)rlr�rm�	TypeErrorrhr�)rF�notBytes�results ��rHrfz`TLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.SimpleSendingProtocol.connectionMade�sg���5��N�N�(�(��2��N�N�(�(��2��N�N�1�1�3�� �5��M�M�$�'��N�N�2�2�4�5�s�AA�4B�
BNrH)rbrcs��rHrJr^�s���
5rJrJc�l���jt�jtt��d�y)N�)r�rk�flushLoggedErrorsr'rares�rH�flush_logged_errorszOTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.flush_logged_errors�s&������S��!7�!7��	�!R�S�UV�WrJr`c�*���j�dg�Sr�)r�)�ignrcrFs ��rHr{zDTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.<lambda>�s���d�.�.�v��v�>�rJc�&��ttd��S�Nr)r
r)rirgs �rHr{zDTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.<lambda>�s���j��!�5H�I�rJ)r1rC�addBoth)rFrJ�drgrbrcs`  @@@rH� test_writeUnicodeRaisesTypeErrorz2TLSMemoryBIOTests.test_writeUnicodeRaisesTypeError�sU�������	5�H�	5�	X�
�)�)�*?��J��	�	�	�>�?�	�	�	�I�J��rJc�����gd��G�fd�dt�}t�}||_t�}t	|d|�}|jd�}t
ttt�����t�}�fd�|_t�}t	|d|�}|jd�}t||t�}	���fd�}
|	j|
�|	S)	z�
        If multiple separate TLS messages are received in a single chunk from
        the underlying transport, all of the application bytes from each
        message are delivered to the application-level protocol.
        )	�a�b�c�d�e�f�g�h�ic���eZdZ�fd�Zy)�DTLSMemoryBIOTests.test_multipleWrites.<locals>.SimpleSendingProtocolc�J���D]}|jj|��yrCr6)rF�bros  �rHrfzSTLSMemoryBIOTests.test_multipleWrites.<locals>.SimpleSendingProtocol.connectionMade�s$����,�A��N�N�(�(��+�,rJNrHrIs�rHrJrz�s���
,rJrJTNc����SrCr^r3s�rHr{z7TLSMemoryBIOTests.test_multipleWrites.<locals>.<lambda>�rrJFc�z���jdj�j�dj���yr8r9r:s ���rHrAz?TLSMemoryBIOTests.test_multipleWrites.<locals>.cbConnectionDone�s*������S�X�X�n�&=�&=�>������OrJ)r1r/r�rArr�r`rirjrkr2r!r7r6r!)
rFrJr�rr�r	r
rrr
rAror4s
`          @@rH�test_multipleWritesz%TLSMemoryBIOTests.test_multipleWrites�s����F��	,�H�	,�
&��
�!6�
��>�@��,�-A�4��W��*�8�8��>��-�c�#�c�4�.�.A�B��%��
�!7�
��/�1��,�-A�5�-�X��*�8�8��>��*��0�2F�
��	P�	�&�&�'7�8�!�!rJc����
��d�d�
G��
fd�dt�}t�}||_t|��}t	|d|�}|jd�}t
t���
z��t�}�fd�|_t|��}t	|d	|�}|jd�}	t|	|�}
��
��fd
�}|
j|�|
S)z�
        If a very long string is passed to L{TLSMemoryBIOProtocol.write}, any
        trailing part of it which cannot be send immediately is buffered and
        sent later.
        r0ic���eZdZ��fd�Zy)�:TLSMemoryBIOTests.hugeWrite.<locals>.SimpleSendingProtocolc�B��|jj��z�yrCr6)rFro�factors ��rHrfzITLSMemoryBIOTests.hugeWrite.<locals>.SimpleSendingProtocol.connectionMade�s������$�$�T�F�]�3rJNrH)ror�s��rHrJr��s���
4rJrJr�TNc����SrCr^r3s�rHr{z-TLSMemoryBIOTests.hugeWrite.<locals>.<lambda>
rrJFc�b���jdj�j���z�yr8r9)r*ror�rFr4s ����rHrAz5TLSMemoryBIOTests.hugeWrite.<locals>.cbConnectionDones&������S�X�X�n�&=�&=�>��v�
�NrJ)r1r/r�rArr�r`rkr2r!r7r!)rFrGrJr�rr�r	r
rrr
rAror�r4s`           @@@rH�	hugeWritezTLSMemoryBIOTests.hugeWrite�s��������	4�H�	4�&��
�!6�
��>�f�M��,�-A�4��W��*�8�8��>��-�c�$�i�&�.@�A��%��
�!7�
��/�v�>��,�-A�5�-�X��*�8�8��>��*�+<�>O�P��	O�	�&�&�'7�8�!�!rJc�"�|j�SrC)r�res rH�test_hugeWritez TLSMemoryBIOTests.test_hugeWrites���~�~��rJc�.�|jt��S)Nr�)r�rres rH�test_hugeWrite_TLSv1_2z(TLSMemoryBIOTests.test_hugeWrite_TLSv1_2s���~�~�^�~�4�4rJc���t��t�}�fd�|_t�}t	|d|�}|jd�}t
�}t||�|jj�d�}�j|��S)z~
        If a L{TLSMemoryBIOProtocol} loses its connection unexpectedly, this is
        reported to the application.
        c���t��SrCr<rs�rHr{z;TLSMemoryBIOTests.test_disorderlyShutdown.<locals>.<lambda>'rrJTNc�L�|jjtt�yrC)rrrr'rys rHr;zATLSMemoryBIOTests.test_disorderlyShutdown.<locals>.cbDisconnected8s���/�/�4�4�U�N�KrJ)r$r/r�rArr�r1r7rlrmr!)rFr�rr�r	r4r;rs       @rH�test_disorderlyShutdownz)TLSMemoryBIOTests.test_disorderlyShutdown s����
 (�z��%��
�"
�
�� ?�@��,�-A�4��W��*�8�8��>��"����n�&7�8�	� � �/�/�1�	L�	�(�(��8�#�#rJc����
����Gd�dt�}t��
t�}|�
���fd�|_tj�\}}t
|d|�}|jd�}t��|���t�}�fd�|_t�}t
|d|�}|jd�}	t|	|�dd	z���
���fd
�}
|j|
���fd�}|j|�|S)z�
        L{TLSMemoryBIOProtocol.loseConnection} sends a TLS close alert and
        shuts down the underlying connection cleanly on both sides, after
        transmitting all buffered data.
        c��eZdZd�Zd�Zy)�NTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.NotifyingProtocolc�>�tj||�g|_yrC)r=rIro)rF�onConnectionLosts  rHrIzWTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.NotifyingProtocol.__init__Fs��/�8�8��?O�P���	rJc�:�|jj|�yrC)rorhrns  rHrpz[TLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.NotifyingProtocol.dataReceivedJs���	�	� � ��&rJN)rYrZr[rIrpr^rJrH�NotifyingProtocolr�Es��
�
'rJr�c����SrCr^rys�rHr{zETLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.<lambda>PrrJTNc����SrCr^r3s�rHr{zETLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.<lambda>\rrJFs	123456890順c����jj���jjd��jj�t��g�S)N�x)rlr�rmr%)r*�chunkOfBytesrrzrr4s �����rH�cbHandshakezHTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.cbHandshakefsS���
�$�$�*�*�<�8��$�$�*�*�4�0��$�$�3�3�5�!�"6�8L�!M�N�NrJc���|\}}|jjt�|jjt��jdj	|j
����j
|jjj��j
|jjj�yr8)
rrr&r�r�ror�rl�q�
disconnect)rcrzr4r�rFs   ��rHrAzMTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.cbConnectionDoneys����/5�,�^�^��/�/�4�4�^�D��/�/�4�4�^�D�
���S�X�X�n�&9�&9�:�L�I�
�O�O�N�4�4�6�6�A�A�B�

�O�O�N�4�4�6�6�A�A�BrJ)r=r$r/r�rArNrr�r2r!r7r!)rFr�r�rrr�r	r
rrr�rAr�rrzrr4s`           @@@@@rH�!test_loseConnectionAfterHandshakez3TLSMemoryBIOTests.test_loseConnectionAfterHandshake>s���	'� ?�	'� (�z��%��
�*�+?�@��!7�
��

,�>�>�@�	
� ��,�-A�4��W��*�8�8��>��'�z��*�+?�@��%��
�!7�
��/�1��,�-A�5�-�X��*�8�8��>���'�):�;�#�f�,��	O�	O�	�%�%�k�2�
	C�"	�%�%�&6�7� � rJc�H�Gd�dt�}tt�dt��}|�}t	||�}t�}|j
|�|jd�|j|j�|j|j�|jttd���|j|jjt��|j!|jj"j$d�y)zz
        The user protocol's connectionLost is only called when transport
        underlying TLS is disconnected.
        c��eZdZdZd�Zy)�TTLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses.<locals>.LostProtocolNc��||_yrC)�disconnectedrts  rHrvzcTLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses.<locals>.LostProtocol.connectionLost�s
��$*��!rJ)rYrZr[r�rvr^rJrH�LostProtocolr��s���L�
+rJr�TN�ono)r�)r1rr r/rr5r��_tlsShutdownFinishedr��
disconnecting�assertIsNoner�rvr9r'rrr��value�args)rFr�r�r�rrls      rH�,test_connectionLostOnlyAfterUnderlyingClosesz>TLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses�s���	+�8�	+�-�-=�-?��}��W���>��*�>�8�D��#�%�	��"�"�9�-�
	�(�(��.����	�/�/�0����(�/�/�0�	�"�"�7�>�%�+@�#A�B�����-�-�3�3�N�C�D�����.�.�4�4�9�9�8�DrJc�l��|j�\}}}}|j|�g�|jf�fd�	}||_|jd�|j	�|j|j�|j�dg�|j	�|j�dg�|S)z�
        If TLSMemoryBIOProtocol.loseConnection is called multiple times, all
        but the first call have no effect.
        c�4���jd�|�S�N��rh��shutdown�callss �rH�_shutdownTLSz@TLSMemoryBIOTests.test_loseConnectionTwice.<locals>._shutdownTLS������L�L��O��:�rJr�r�)r�successResultOfr�r�rmr�r�r�)rFrrr�disconnectDeferredr�r�s      @rH�test_loseConnectionTwicez*TLSMemoryBIOTests.test_loseConnectionTwice�s����
�#�#�%�	
��������.�/���"+�"8�"8�	�".�	�������� � �"����	�/�/�0�������$�	� � �"�������$�"�!rJc�������j�\}�}}g�|jf�fd�	}|�_�jd�|j����fd�}|j	|�|S)zq
        If TLSMemoryBIOProtocol.loseConnection is called after connectionLost,
        it does nothing.
        c�4���jd�|�Sr�r�r�s �rHr�zNTLSMemoryBIOTests.test_loseConnectionAfterConnectionLost.<locals>._shutdownTLS�r�rJr�c�r���j�dg��j��j�dg�yr�)r�rm)rr�rFrs ���rHr�zNTLSMemoryBIOTests.test_loseConnectionAfterConnectionLost.<locals>.disconnected�s5������U�Q�C�(�
�$�$�&����U�Q�C�(rJ)rr�r�rmr!)rFrrr�r�r�r�rs`     @@rH�&test_loseConnectionAfterConnectionLostz8TLSMemoryBIOTests.test_loseConnectionAfterConnectionLost�st���
�#�#�%�	
�����
��"+�"8�"8�	�".�	�������� � �"�	)�	�&�&�|�4�!�!rJc�����	��j�\�	}}}|j}g}g�|j|_�j|_�	fd�}|j|���fd�}|j|�|S)zP
        Unexpected disconnects get converted to ConnectionLost errors.
        c�\���jd��jj�y�Nr�)r�rlrm�rirs �rH�
handshakeDonez;TLSMemoryBIOTests.test_unexpectedEOF.<locals>.handshakeDones!����O�O�H�%����.�.�0rJc�\���j�djt��d�yrk)r�rrr'�rirurFs ��rHr�z:TLSMemoryBIOTests.test_unexpectedEOF.<locals>.disconnected
s"����O�O�F�1�I�O�O�N�;�V�A�Y�GrJ)rr�rhrprvr!)
rFrrr�r4ror�r�rurs
`       @@rH�test_unexpectedEOFz$TLSMemoryBIOTests.test_unexpectedEOF�s����
�#�#�%�	
�����"�2�2������&*�k�k��#�(.�
�
��%�	1�	�%�%�m�4�	H�	�&�&�|�4�!�!rJc������j�\�}}}g��j�j_Gd�d�}|�j��_�fd�}|j|���fd�}|j|�|S)zN
        Errors while writing cause the protocols to be disconnected.
        c��eZdZd�Zd�Zd�Zy)�4TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapperc��||_yrC)�_wrapped)rF�wrappeds  rHrIz=TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapper.__init__s	�� '��
rJc�.�t|j|�SrC)�getattrr�)rF�attrs  rH�__getattr__z@TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapper.__getattr__"s���t�}�}�d�3�3rJc��tdg��)N)zSSL routines�z this message is probably useless)r)rFr�s  rH�sendz9TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapper.send%s���U�V�W�WrJN)rYrZr[rIr�r�r^rJrH�Wrapperr�s��
(�
4�
XrJr�c�(���jd�yr�)r�r�s �rHr�z:TLSMemoryBIOTests.test_errorWriting.<locals>.handshakeDone+s����O�O�H�%rJc�\���j�djt��d�yrk)r�rrrr�s ��rHr�z9TLSMemoryBIOTests.test_errorWriting.<locals>.disconnected1s"����O�O�F�1�I�O�O�E�2�F�1�I�>rJ)rrhr�rv�_tlsConnectionr!)	rFrrr�r�r�r�rurs	`      @@rH�test_errorWritingz#TLSMemoryBIOTests.test_errorWritings����
�#�#�%�	
�������39�=�=�	�!�!�0�	X�	X�$+�9�+C�+C�#D�	� �	&�	�%�%�m�4�	?�	�&�&�|�4�!�!rJc�d�d�}|jtj�tj�Gd�dt�}Gd�dt�}|t
�}||�}t
�\}}t|j�dtj|��}ttd|��d	tj|��}	tt||��t|	|���|t
�}
||�}|j|
|�|j||�y
)z�
        TLSMemoryBIOProtocol doesn't leave circular references that keep
        it in memory after connection is closed.
        c�P��t�fd�tj�D��S)z�
            Return the number of instances of a given type in memory.

            @param type: Type whose instances to find.

            @return: The number of instances found.
            c3�<�K�|]}t|��s�d���y�w)r�N)�
isinstance)�.0�x�types  �rH�	<genexpr>zVTLSMemoryBIOTests.test_noCircularReferences.<locals>.nObjectsOfType.<locals>.<genexpr>Es�����J�Q�j��D�6I�q�J�s��)ri�gc�get_objects)r�s`rH�nObjectsOfTypezCTLSMemoryBIOTests.test_noCircularReferences.<locals>.nObjectsOfType=s����J�"�.�.�"2�J�J�JrJc��eZdZd�Zy)�CTLSMemoryBIOTests.test_noCircularReferences.<locals>.CloserProtocolc�8�|jj�yrC)rlrmrns  rHrpzPTLSMemoryBIOTests.test_noCircularReferences.<locals>.CloserProtocol.dataReceivedKs�����-�-�/rJN)rYrZr[rpr^rJrH�CloserProtocolr�Js��
0rJr�c��eZdZd�Zy)�DTLSMemoryBIOTests.test_noCircularReferences.<locals>.GreeterProtocolc�:�|jjd�yr�r6res rHrfzSTLSMemoryBIOTests.test_noCircularReferences.<locals>.GreeterProtocol.connectionMadeOs�����$�$�X�.rJNrHr^rJrH�GreeterProtocolr�Ns��
/rJr�Fr�r�TN)r�r��enable�disabler1rr#rr�r0r�rr7r�)rFr�r�r��
origTLSProtos�origServerProtosr�r�r
r��newTLSProtos�newServerProtoss            rH�test_noCircularReferencesz+TLSMemoryBIOTests.test_noCircularReferences7s��	K�	
����	�	�"�
�
�
��	0�X�	0�	/�h�	/�'�';�<�
�)�.�9��@�B���*�+���� �%��)<�)<�^�)L�
�
�,��
��B������0�
�
�
	� ���0@�A� ���0A�B�	
�
&�&:�;��(��8������}�5�����*:�;rJN)rYrZr[r\r�r�r�rrrr$r-r=rCrMrTrZrnrrr�r�r�r�r�r�r�r�r�r�r�r^rJrHr�r�ds����
9�<�.=�.=�(
�:	!�.
�`(!�T-!�^"�BJ�J�J�"�2&"�P *�$"�L �5�$�<M!�^E�>"�B!"�F"�@%"�N/<rJr�c��eZdZdZdd�Z	dd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�TLSProducerTestszA
    The TLS transport must support the IConsumer interface.
    c��|j�}|j�|jt|xs|�d�|S)a�
        Drain the bytes currently pending write from a L{StringTransport}, then
        clear it, since those bytes have been consumed.

        @param transport: The L{StringTransport} to get the bytes from.
        @type transport: L{StringTransport}

        @param allowEmpty: Allow the test to pass even if the transport has no
            outgoing bytes in it.
        @type allowEmpty: L{bool}

        @return: the outgoing bytes from the given transport
        @rtype: L{bytes}
        T)r��clearr��bool)rFrl�
allowEmptyr�s    rH�drainzTLSProducerTests.drainns9�����!����������j�1�E�2�D�9��rJNc���Gd�dt�}t||||��\}}|�}|jj|d�|j	|jj
�|||fS)a�
        Create a new client-side protocol that is connected to a remote TLS server.

        @param serverMethod: The TLS method accepted by the server-side. Set to to C{None} to use the default method used by your OpenSSL library.

        @return: A tuple with high level client protocol, the low-level client-side TLS protocol, and a producer that is used to send data to the client.
        c�$�eZdZd�Zd�Zd�Zd�Zy)�GTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransportc�<�tj|�g|_yrC)r5rI�producerHistoryres rHrIzPTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.__init__�s���(�(��.�')��$rJc�d�|jjd�tj|�y)N�pause)r�rhr5�pauseProducingres rHrzVTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.pauseProducing�s$���$�$�+�+�G�4��.�.�t�4rJc�d�|jjd�tj|�y)N�resume)r�rhr5�resumeProducingres rHrzWTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.resumeProducing�s$���$�$�+�+�H�5��/�/��5rJc�d�|jjd�tj|�y)N�stop)r�rhr5�
stopProducingres rHrzUTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.stopProducing�s$���$�$�+�+�F�3��-�-�d�3rJN)rYrZr[rIrrrr^rJrH�HistoryStringTransportr��s��
*�
5�
6�
4rJr	)rlr�r�r�T)r5r�rl�registerProducerr��	streaming)	rFrlr�r�r�r	�applicationProtocolr�producers	         rH�setupStreamingProducerz'TLSProducerTests.setupStreamingProducer�sq��	4�_�	4�",<��)��%�	,
�(��[�*�+���%�%�6�6�x��F�����-�-�7�7�8�"�K��9�9rJc��td�D]g}|j|jd�}|r|j|�|j|jd�}|r|j|�|r�d|r�gn|j	|jj�d�|j	|jj�d�y)zJ
        Transfer bytes back and forth between two TLS protocols.
        �TrJN)�ranger�rlrpr�r�)rFr�serverTLSProtocol�i�
clientData�
serverDatas      rH�flushTwoTLSProtocolsz%TLSProducerTests.flushTwoTLSProtocols�s����q��	�A����K�$9�$9�4�@�J��!�.�.�z�:����$5�$?�$?��F�J���(�(��4��j��	�	
����.�.�4�4�6��<����*�4�4�:�:�<�c�BrJc�0�|j�\}}}|jjj�|j	|j
d�|j	|jdg�|j|jj�y)z�
        When the TLS transport is not blocked on reads, it correctly calls
        pauseProducing on the registered producer.
        �pausedrN)
rrlr
rr��
producerStater�r��	_producer�_producerPaused�rFrrr
s    rH�(test_streamingProducerPausedInNormalModez9TLSProducerTests.test_streamingProducerPausedInNormalMode�sy��
$(�#>�#>�#@� ��;��	���&�&�5�5�7�����/�/��:�����1�1�G�9�=�����-�-�=�=�>rJc��|j�\}}}|jjj�|j	|j
dg�|jjj
�|j	|jd�|j	|j
ddg�|j|jj�y)z�
        When the TLS transport is not blocked on reads, it correctly calls
        resumeProducing on the registered producer.
        r�	producingrN)rrlr
rr�r�rr�assertFalserrrs    rH�)test_streamingProducerResumedInNormalModez:TLSProducerTests.test_streamingProducerResumedInNormalMode�s���
$(�#>�#>�#@� ��;�����&�&�5�5�7�����1�1�G�9�=�	���&�&�6�6�8�����/�/��=�����1�1�G�X�3F�G�����.�.�>�>�?rJc�h�|j�\}}}|jjd�|jjjd�|j
|jd�|j
|jdg�|j|jj�y)z�
        When the TLS transport is blocked on reads, it correctly calls
        pauseProducing on the registered producer.
        r�rrrN)rrlr�r��_clock�advancer�rr�r�rr�rFrzrr
s    rH�4test_streamingProducerPausedInWriteBlockedOnReadModezETLSProducerTests.test_streamingProducerPausedInWriteBlockedOnReadMode�s���
15�0K�0K�0M�-���X�	� � �&�&�x�0����"�"�*�*�1�-�����/�/��:�����1�1�G�9�=�����-�-�=�=�>rJc���|j�\}}}|jjddz�|j|jdg�td��\}}|j
||�|j|jddg�|j|jj�|j|jj�|j|jd�y)	z�
        When the TLS transport is blocked on reads, it correctly calls
        resumeProducing on the registered producer.
        shello worldi�rT�r�rrN)rrlr�r�r�r�rr rrr�r)rFrzrr
r4rs      rH�5test_streamingProducerResumedInWriteBlockedOnReadModezFTLSProducerTests.test_streamingProducerResumedInWriteBlockedOnReadMode�s���
15�0K�0K�0M�-���X�
	� � �&�&�~��'>�?�����1�1�G�9�=�-=�D�,I�)��)��!�!�+�/@�A�����1�1�G�X�3F�G�����.�.�>�>�?�	
����.�.�<�<�=�����/�/��=rJc���|j�\}}}|j}t�}|jt|j
j|d�|j|j|�y)zM
        Registering a streaming producer twice throws an exception.
        TN)rr�object�assertRaises�RuntimeErrorrlr
r)rFrzrr
�originalProducer�	producer2s      rH�test_streamingProducerTwicez,TLSProducerTests.test_streamingProducerTwicesg��15�0K�0K�0M�-���X�&�0�0���H�	�����.�2�2�C�C�Y�PT�	
�	
�
�
�k�+�+�-=�>rJc���|j�\}}}|jj�|j|j�|j|jj
�y)z\
        Unregistering a streaming producer removes it, reverting to initial state.
        N�rrl�unregisterProducerr�rr
r%s    rH� test_streamingProducerUnregisterz1TLSProducerTests.test_streamingProducerUnregistersY��15�0K�0K�0M�-���X�� � �3�3�5����+�/�/�0����+�/�/�8�8�9rJc��|j�\}}}|jj�|jj�|j|j�|j|jj
�y)zd
        Unregistering a streaming producer when no producer is registered is
        safe.
        Nr2r%s    rH�%test_streamingProducerUnregisterTwicez6TLSProducerTests.test_streamingProducerUnregisterTwicesk��
15�0K�0K�0M�-���X�� � �3�3�5�� � �3�3�5����+�/�/�0����+�/�/�8�8�9rJc��|j�\}}}td��\}}|s|j||�n	|jj	d�|jj�|j||�|j
|jj�|j
d|jv�|jj	d�|jjddg�|jjjd�|jj�|j|jj�d	�|j
|jj�|jj	d
�|jjdg�|jjjd�|j||�|j!|jj�|j#d	j%|j&�d�y
)zl
        Common code for tests involving writes by producer after
        loseConnection is called.
        Tr(sx rr�� rYrrJswon'tswon't!s
x hello worldN)rr�rrlr�rmr r�r�rRr�r#r$r3�assertNotEqualr�r�r�r�rd)rF�writeBlockedOnReadrzrr
r4rs       rH�loseConnectionWithProducerz+TLSProducerTests.loseConnectionWithProducer#s���
15�0K�0K�0M�-���X�,<�D�,I�)��)�!��%�%�k�3D�E�
�	� � �&�&�u�-�� � �/�/�1��!�!�+�/@�A�	
����.�.�<�<�=�����8�#;�#;�;�<�	� � �&�&�x�0�� � �.�.��h�/?�@����"�"�*�*�1�-�	� � �3�3�5����K�1�1�7�7�9�3�?�����.�.�<�<�=�	� � �&�&�x�0�� � �.�.�	�{�;����"�"�*�*�1�-�	
�!�!�+�/@�A�����-�-�;�;�<�	
������.�"9�"9�:�<L�MrJc�$�|jd�S)z�
        loseConnection() waits for the producer to unregister itself, then
        does a clean TLS close alert, then closes the underlying connection.
        F�r;res rH�0test_streamingProducerLoseConnectionWithProducerzATLSProducerTests.test_streamingProducerLoseConnectionWithProducerUs��
�.�.�u�5�5rJc�$�|jd�S)z�
        Even when writes are blocked on reading, loseConnection() waits for
        the producer to unregister itself, then does a clean TLS close alert,
        then closes the underlying connection.
        Tr=res rH�4test_streamingProducerLoseConnectionWithProducerWBORzETLSProducerTests.test_streamingProducerLoseConnectionWithProducerWBOR\s���.�.�t�4�4rJc��Gd�dt�}Gd�d�}|�}|j||���\}}}|j|jd�|jjd�|jjjd�|j|jd	�|j|jd
g�|jjj�|j|jd�|j|jd
dg�|jd�|j|jd�|j|jd
dg�y)
z�
        pauseProducing() events can come from both the TLS transport layer and
        the underlying transport. In this case, both decide to pause,
        underlying first.
        c��eZdZdZd�Zy)�bTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.PausingStringTransportFc��|js-|j�!d|_|jj�tj||�yr�)�	_didPauser
rr5r�rns  rHr�zhTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.PausingStringTransport.writens9���~�~�$�-�-�*C�%)�D�N��M�M�0�0�2��%�%�d�D�1rJN)rYrZr[rEr�r^rJrH�PausingStringTransportrCks���I�
2rJrFc�6�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�YTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnectionc��g|_yrC)�lres rHrIzbTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.__init__us	����rJc���|js|dd}t|j�dk(r%|jjd�t��|jj|�t|�S)N���r�r)rJrkrhrrns  rHr�z^TLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.sendxsV���v�v����9�D��t�v�v�;�!�#��F�F�M�M�(�+�'�/�)����
�
�d�#��4�y� rJc��yrCr^res rH�set_connect_statezkTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.set_connect_state�r�rJc��yrCr^res rH�do_handshakezfTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.do_handshake�r�rJc��yrCr^rns  rH�	bio_writezcTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.bio_write�r�rJc��y)N�Xr^�rF�sizes  rH�bio_readzbTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.bio_read�s��rJc��t��rC)rrUs  rH�recvz^TLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.recv�s
��#�o�%rJN)
rYrZr[rIr�rNrPrRrWrYr^rJrH�
TLSConnectionrHts%��
�

!�
�
�
�
�
&rJrZr�rr�rrrrN)
r5rr�rrlr�r�r#r$r�r
rrp)rFrFrZrlrzrr
s       rH�1test_streamingProducerBothTransportsDecideToPausezBTLSProducerTests.test_streamingProducerBothTransportsDecideToPausedsF��	2�_�	2�	&�	&�>+�,�	�04�0K�0K��m�o�1L�1
�-���X�	
����/�/��=�	� � �&�&�x�0����"�"�*�*�1�-�����/�/��:�����1�1�G�9�=�	���&�&�6�6�8�����/�/��=�����1�1�G�X�3F�G�� � ��*�����/�/��=�����1�1�G�X�3F�GrJc��|j�\}}}|jjj�|j	|j
d�y)z�
        If the underlying transport tells its producer to stopProducing(),
        this is passed on to the high-level producer.
        �stoppedN)rrlr
rr�rrs    rH�#test_streamingProducerStopProducingz4TLSProducerTests.test_streamingProducerStopProducing�sG��
$(�#>�#>�#@� ��;�����&�&�4�4�6�����/�/��;rJc�`�����t�\}�t|j��|jj�d��jjj
��j
�t��j�j
���j�j|j��j�jj�����fd�}�jj|�td��\}}�j�|��jS)zM
        Non-streaming producers get wrapped as streaming producers.
        Fc����j�j��j�jj��j	�j
�yrC)r��consumerrlr
r�rD)�ignorer
rF�streamingProducerrs ����rH�donez8TLSProducerTests.test_nonStreamingProducer.<locals>.done�sD������h�/�/�0����k�3�3�<�<�=��O�O�-�7�7�8rJTr()r�r4rlr
r
rr�rr��	_consumerr�rrcr!r)rFrzrdr4rr
rcrs`    @@@rH�test_nonStreamingProducerz*TLSProducerTests.test_nonStreamingProducer�s����'7�&8�#���'��(@�(@�A��	� � �1�1�(�E�B�'�1�1�:�:�D�D��	
���/��=����*�4�4�h�?����*�4�4�n�6N�6N�O�����-�-�7�7�8�	9�	���#�#�D�)�,<�D�,I�)��)��!�!�+�/@�A����rJc�l�t�}t|�}|jtt|��y)zC
        L{_ProducerMembrane} implements L{IPushProducer}.
        N)r5rr�rr,)rFr
�membranes   rH�test_interfacezTLSProducerTests.test_interface�s)��#�$��$�X�.������]�H�=�>rJc�8�t�\}}d�|_Gd�d�}|jtt���|�}|j	|d�|j|jj�|j|j�y)z�
        If a producer is registered after the transport has disconnected, the
        producer is not used, and its stopProducing method is called.
        c�6�|jtt�SrC)rrr'�rus rHr{zFTLSProducerTests.registerProducerAfterConnectionLost.<locals>.<lambda>�s��v�{�{��>�8
�rJc��eZdZdZd�Zd�Zy)�FTLSProducerTests.registerProducerAfterConnectionLost.<locals>.ProducerFc��ddzS)Nr�rr^res rHrzVTLSProducerTests.registerProducerAfterConnectionLost.<locals>.Producer.resumeProducing�s���1�u�rJc��d|_yr�)r]res rHrzTTLSProducerTests.registerProducerAfterConnectionLost.<locals>.Producer.stopProducing�s	��#��rJN)rYrZr[r]rrr^rJrH�Producerrn�s���G�
�
$rJrqFN)
r�rvr9r&r
r�rlr
r�r])rFrrzrrqr
s      rH�#registerProducerAfterConnectionLostz4TLSProducerTests.registerProducerAfterConnectionLost�s���
'7�&8�#���)
��%�	$�	$�	�"�"�7�>�+;�#<�=��:���$�$�X�u�5����+�/�/�8�8�9�����(�(�)rJc�&�|jd�y)z�
        If a streaming producer is registered after the transport has
        disconnected, the producer is not used, and its stopProducing method
        is called.
        TN�rrres rH�)test_streamingProducerAfterConnectionLostz:TLSProducerTests.test_streamingProducerAfterConnectionLost�s��	
�0�0��6rJc�&�|jd�y)z�
        If a non-streaming producer is registered after the transport has
        disconnected, the producer is not used, and its stopProducing method
        is called.
        FNrtres rH�,test_nonStreamingProducerAfterConnectionLostz=TLSProducerTests.test_nonStreamingProducerAfterConnectionLosts��	
�0�0��7rJ)F)NNFN)rYrZr[r\r�rrrr!r&r)r0r4r6r;r>r@r[r^rfrirrrurwr^rJrHr�r�is{����*OS�%:�NC�$?�@� ?�$>�0
?�:�	:�0N�d6�5�FH�P<��@?�*�:7�8rJr�c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�NonStreamingProducerTestszP
    Non-streaming producers can be adapted into being streaming producers.
    c�����t��}t|����j�d��jf�fd�	}|�_|j}���fd�}|j|��j
�|S)zd
        Verify the consumer writes out all its data, but is not called after
        that.
        Tc�4��|��j�yrC��
stopStreaming��origrcs �rH�
unregisterz<NonStreamingProducerTests.streamUntilEnd.<locals>.unregister�����F��+�+�-rJc����j�j�d��j�j��j	�j
�y)Ns
0123456789)r�r�r�r
r�rD)rrarFrcs ���rH�
doneStreamingz?NonStreamingProducerTests.streamUntilEnd.<locals>.doneStreaming%sA������X�^�^�-�}�=����h�/�/�0��O�O�-�7�7�8rJ)r4rr
r3rcr!�startStreaming)rFra�
nsProducerr�rdr�rcs``    @rH�streamUntilEndz(NonStreamingProducerTests.streamUntilEndsz���
*�(�3�
�'�
�H�=���!�!�"3�T�:�%�7�7�	.�'1��#�� � ��	9�	
����'�	�(�(�*��rJc�8�t�}|j|�S)z�
        When converted to a streaming producer, the non-streaming producer
        writes out all its data, but is not called after that.
        �r5r�)rFras  rH�test_writeUntilDonez-NonStreamingProducerTests.test_writeUntilDone2s��
#�$���"�"�8�,�,rJc�.���Gd�dt�}|�}t|�}t||��|j�d��fd�}|jj|�|j}��fd�}|j|��j�|S)z}
        When the streaming producer is paused, the underlying producer stops
        getting resumeProducing calls.
        c��eZdZdZd�Zd�Zy)�DNonStreamingProducerTests.test_pause.<locals>.PausingStringTransportrc�L�tj|�t�|_yrC)r5rIr$rres rHrIzMNonStreamingProducerTests.test_pause.<locals>.PausingStringTransport.__init__Cs���(�(��.�&�j��rJc���|xjdz
c_tj||�|jdk(r:|jj	�|j
}|`|j
d�yy�Nr�r)�writesr5r�r
rrrP)rFrorms   rHr�zJNonStreamingProducerTests.test_pause.<locals>.PausingStringTransport.writeGs[�����q� ���%�%�d�D�1��;�;�!�#��M�M�0�0�2����A����J�J�t�$�	$rJN)rYrZr[r�rIr�r^rJrHrFr�@s���F�
)�
%rJrFTc�(���jd�y)Nz$BUG: The producer should not finish!)�fail)rbrFs �rH�shouldNotBeCalledz?NonStreamingProducerTests.test_pause.<locals>.shouldNotBeCalledVs����I�I�<�=rJc�R���j�jjd�yr�)r��	_coopTask�_pauseCount)rbrFrcs ��rHrz4NonStreamingProducerTests.test_pause.<locals>.paused]s ������.�8�8�D�D�a�HrJ)r5r4rr
rcr!rr�)rFrFrar�r�rdrrcs`      @rH�
test_pausez$NonStreamingProducerTests.test_pause:s����	%�_�	%� *�+��)�(�3�
�'�
�H�=���!�!�"3�T�:�	>�	���%�%�&7�8�����	I�	
���� �	�(�(�*��rJc�P�Gd�dt�}|�}|j|�S)a
        When the streaming producer is paused and then resumed, the underlying
        producer starts getting resumeProducing calls again after the resume.

        The test will never finish (or rather, time out) if the resume
        producing call is not working.
        c��eZdZdZd�Zy)�ENonStreamingProducerTests.test_resume.<locals>.PausingStringTransportrc���|xjdz
c_tj||�|jdk(r5|jj	�|jj�yyr�)r�r5r�r
rrrns  rHr�zKNonStreamingProducerTests.test_resume.<locals>.PausingStringTransport.writessQ�����q� ���%�%�d�D�1��;�;�!�#��M�M�0�0�2��M�M�1�1�3�$rJN�rYrZr[r�r�r^rJrHrFr�ps���F�
4rJrFr�)rFrFras   rH�test_resumez%NonStreamingProducerTests.test_resumegs)��	4�_�	4�*�+���"�"�8�,�,rJc������Gd�dt�}|��t���t�����j�d��j}����fd�}|j|��j
�|S)z�
        When the streaming producer is stopped by the consumer, the underlying
        producer is stopped, and streaming is stopped.
        c��eZdZdZd�Zy)�MNonStreamingProducerTests.test_stopProducing.<locals>.StoppingStringTransportrc��|xjdz
c_tj||�|jdk(r|jj	�yyr�)r�r5r�r
rrns  rHr�zSNonStreamingProducerTests.test_stopProducing.<locals>.StoppingStringTransport.write�sA�����q� ���%�%�d�D�1��;�;�!�#��M�M�/�/�1�$rJNr�r^rJrH�StoppingStringTransportr��s���F�
2rJr�Tc����j�j�d��j�j��j�j�y)Ns012)r�r�r�r]rD)rrar�rFrcs ����rHr�zCNonStreamingProducerTests.test_stopProducing.<locals>.doneStreaming�s?������X�^�^�-�v�6��O�O�J�.�.�/��O�O�-�7�7�8rJ)r5r4rr
rcr!r�)rFr�rdr�rar�rcs`   @@@rH�test_stopProducingz,NonStreamingProducerTests.test_stopProducing}st���	2�o�	2�+�,��)�(�3�
�'�
�H�=���!�!�"3�T�:�� � ��	9�	
����'�	�(�(�*��rJc�������	�Gd�dt�}|��}t|���	�j�	d�g�tj�j
��j
tj�j
��jf�	fd�	}|�_�	j��	jj�}|jd�������	fd�}|j|�|S)z�
        Common implementation for tests where the underlying producer throws
        an exception when its resumeProducing is called.
        c��eZdZd�Zy)�INonStreamingProducerTests.resumeProducingRaises.<locals>.ThrowingProducerc�V�|jdk(rddzStj|�y)Nrer�r)�counterr4rres rHrzYNonStreamingProducerTests.resumeProducingRaises.<locals>.ThrowingProducer.resumeProducing�s%���<�<�1�$��q�5�L�(�8�8��>rJN)rYrZr[rr^rJrH�ThrowingProducerr��s��
?rJr�Tc�4��|��j�yrCr|r~s �rHr�zCNonStreamingProducerTests.resumeProducingRaises.<locals>.unregister�r�rJc�,�|jt�SrC)rr3rls rHr{zANonStreamingProducerTests.resumeProducingRaises.<locals>.<lambda>�s��v�{�{�;�'?�rJc����	j�j�d��	j�}�	jt|�t���t	|���D]>\}\}}}�	j|j
|���	j||d��@�	j�
j�y)Ns01�why)	r�r�rfrk�zipr�rr�assertInrD)ri�errors�f�expected�msg�logMsgra�expectedExceptions�
loggedMsgsrFrcs      �����rHr]z@NonStreamingProducerTests.resumeProducingRaises.<locals>.stopped�s�������X�^�^�-�u�5��+�+�-�F����S��[�#�.@�*A�B�.1��*�J�/�
2�*��?�H�c�F�������� 1�2��
�
�c�6�%�=�1�	
2�
�O�O�-�7�7�8rJ)r4rr
r8r�rhr�r�r3r�r��whenDone�
addErrbackr!)
rFrar�r�r�r�rdr]r�rcs
```     @@rH�resumeProducingRaisesz/NonStreamingProducerTests.resumeProducingRaises�s����	?�3�	?�&�h�/�
�'�
�H�=���!�!�"3�T�:��
����
�)�)�*�����*�*�J�,=�,=�>�%�7�7�	.�'1��#�	�(�(�*� �*�*�3�3�5�����?�@�	9�	9�	
����!��rJc�~���t���j�tdfg�}��fd�}|j|�|S)z�
        If the underlying producer raises an exception when resumeProducing is
        called, the streaming wrapper should log the error, unregister from
        the consumer and stop streaming.
        �!failed, producing will be stoppedc�<���j�j�yrC)r�r
)rbrarFs ��rH�
cleanShutdownzKNonStreamingProducerTests.test_resumeProducingRaises.<locals>.cleanShutdown�s������h�/�/�0rJ)r5r��ZeroDivisionErrorr!)rFrdr�ras`  @rH�test_resumeProducingRaisesz4NonStreamingProducerTests.test_resumeProducingRaises�sF���#�$���)�)��)�+N�O�P�
��	1�	
����'��rJc�j�t�}d�}||_|j|tdftdfg�S)a
        If the underlying producer raises an exception when resumeProducing is
        called, the streaming wrapper should log the error, unregister from
        the consumer and stop streaming even if the unregisterProducer call
        also raise.
        c��t��rC)r-r^rJrH�raiserz^NonStreamingProducerTests.test_resumeProducingRaiseAndUnregisterProducerRaises.<locals>.raiser�s
���.� rJr�zfailed to unregister producer)r5r3r�r�r-)rFrar�s   rH�4test_resumeProducingRaiseAndUnregisterProducerRaiseszNNonStreamingProducerTests.test_resumeProducingRaiseAndUnregisterProducerRaises�sH��#�$��	!�'-��#��)�)��"�$G�H��>�?�
�
�	
rJc���t�}t|�}t||�}|j�|j	�|j	�|j|j�y)z�
        stopStreaming() can be called more than once without blowing
        up. This is useful for error-handling paths.
        N)r5r4rr�r}r�rD�rFrar�rcs    rH�test_stopStreamingTwicez1NonStreamingProducerTests.test_stopStreamingTwice�sZ��
#�$��)�(�3�
�'�
�H�=���(�(�*��'�'�)��'�'�)����)�3�3�4rJc��t�}t|�}t||�}|jt	t
|��y)z=
        L{_PullToPush} implements L{IPushProducer}.
        N)r5r4rr�rr,r�s    rHriz(NonStreamingProducerTests.test_interfaces7��#�$��)�(�3�
�'�
�H�=������]�4E�F�GrJN)rYrZr[r\r�r�r�r�r�r�r�r�r�rir^rJrHryrys>��� �D-�+�Z-�,!�F1�f�$
�*5�HrJryc��eZdZdZd�Zd�Zy)�ClientNegotiationFactoryza
    A L{ClientFactory} that has a set of acceptable protocols for NPN/ALPN
    negotiation.
    c��||_y)z�
        Create a L{ClientNegotiationFactory}.

        @param acceptableProtocols: The protocols the client will accept
            speaking after the TLS handshake is complete.
        @type acceptableProtocols: L{list} of L{bytes}
        N��_acceptableProtocols�rF�acceptableProtocolss  rHrIz!ClientNegotiationFactory.__init__���%8��!rJc��|jS�a
        Returns a list of protocols that can be spoken by the connection
        factory in the form of ALPN tokens, as laid out in the IANA registry
        for ALPN tokens.

        @return: a list of ALPN tokens in order of preference.
        @rtype: L{list} of L{bytes}
        r�res rHr�z,ClientNegotiationFactory.acceptableProtocols"����(�(�(rJN�rYrZr[r\rIr�r^rJrHr�r�����
8�	)rJr�c��eZdZdZd�Zd�Zy)�ServerNegotiationFactoryza
    A L{ServerFactory} that has a set of acceptable protocols for NPN/ALPN
    negotiation.
    c��||_y)z�
        Create a L{ServerNegotiationFactory}.

        @param acceptableProtocols: The protocols the server will accept
            speaking after the TLS handshake is complete.
        @type acceptableProtocols: L{list} of L{bytes}
        Nr�r�s  rHrIz!ServerNegotiationFactory.__init__5r�rJc��|jSr�r�res rHr�z,ServerNegotiationFactory.acceptableProtocols?r�rJNr�r^rJrHr�r�.r�rJr�c���eZdZdZeejejej�ejdd��jd���d���d
d��Zy	)�_AggregateSmallWritesTestsz$Tests for ``_AggregateSmallWrites``.r�r�)�	min_value�	max_valuec��d|dzdzzd|S)Ns0123456789ABCDEFGHIJ�r�r^)�lengths rHr{z#_AggregateSmallWritesTests.<lambda>]s ��$;��"��PQ�?Q�$R���$�rJi�)�max_sizec�X�g}t�}t|j|�}|D]'}|�|jd��|j	|��)|j�|j
dj|�djd�|D���|dd}|D]�}t|�}|r|d�|jd�|r|d��d}	|s�3|jd�}
|
�|j
||	��Y|	t|
�z
}	|	|jkDr|j
||	���|r�Y��y)aY
        A L{_AggregateSmallWrites} correctly aggregates data for the given
        sequence of writes (indicated by bytes) and increments in the clock
        (indicated by C{None}).

        If multiple writes happen in between reactor iterations, they should
        get written in a batch at the start of the next reactor iteration.
        NrrJc3�&K�|]	}|��|���y�wrCr^)r�r�s  rHr�zH_AggregateSmallWritesTests.test_writes_get_aggregated.<locals>.<genexpr>�s����&V��E�DU�u�&V�s��)rrrhr$r�r�r�r�rk�pop�MAX_BUFFER_SIZE)rFr�rcr��	aggregater��small_writes�chunk�combined_length�small_writes_length�next_original_maybe_writes           rH�test_writes_get_aggregatedz5_AggregateSmallWritesTests.test_writes_get_aggregatedSs<��:!�����)�&�-�-��?�	��	'�E��}��
�
�a� �����&�		'�	����	
����H�H�V��c�h�h�&V�&�&V�V�	
��a�y���	�E�!�%�j�O��<��?�#:�� � ��#��<��?�#:�"#���,8�,<�,<�Q�,?�)�,�4��$�$�_�6I�J��'�3�/H�+I�I�'�*�Y�-F�-F�F��(�(��:M�N���
	rJN)r�zlist[Union[bytes, None]]�return�None)rYrZr[r\r	�st�lists�one_of�none�integersrjr�r^rJrHr�r�Ksl��.�������B�I�I�����	�����a�7�;�?�?���
��	
��$2�%�$2rJr�)FNNN)NF)gr\�
__future__rr��typingr�zope.interfacerrr�zope.interface.verifyr�
hypothesisr	r
r��twisted.internetr�twisted.internet.taskrr
�twisted.python.compatr�OpenSSLr�OpenSSL.SSLrrrrrrrrr�twisted.protocols.tlsrrrrr�twisted.internet.sslrr�twisted.test.ssl_helpersr r!r"�twisted.test.test_sslverifyr#�ImportError�skip�twisted.internet.deferr$r%�twisted.internet.errorr&r'�twisted.internet.interfacesr(r)r*r+r,r-r.�twisted.internet.protocolr/r0r1r2r3�twisted.internet.testingr4r5�twisted.protocols.loopbackr6r7�twisted.pythonr8�twisted.python.failurer9�twisted.python.filepathr:�twisted.test.iosimr;�twisted.test.test_tcpr=�twisted.trial.unittestr>r?rAr`r�r�r�r�r�r�ryr�r�r�r^rJrH�<module>rs����#�	��C�C�.�.�$�3�+�N��
�
�
���M�U�U�M�:�A����V�U�-�J�J��*�,�7�A�@�(�(�V�8��8EI�''�T.A�x�.A�d8=�> �B4M�%8�4M�nB<��B<�J_8�x�_8�D
CH��CH�L
�
(�)�)�}�)�*�)�8
�
(�)�)�}�)�*�)�8L�!4�L��A9�G�H�D�BF�F�J�F��F���G�s�*E:�:F
�F


Zerion Mini Shell 1.0