o
    >h                     @   s  d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ zddlmZ dd	lmZ W n eyG   d
ZY nw eZddlmZ G dd dejZG dd dZeejG dd deZG dd deeeZe e   d
S )z(
Tests for L{twisted.internet._newtls}.
    )
interfaces)ConnectableProtocolrunProtocolsWithReactor)ReactorBuilder)
TCPCreator)ContextGeneratingMixin
SSLCreatorStartTLSClientCreatorTLSMixin)unittest)_newtls)tlsN)implementerc                   @   s    e Zd ZdZes
dZdd ZdS )BypassTLSTestsz4
    Tests for the L{_newtls._BypassTLS} class.
    z<Couldn't import _newtls, perhaps pyOpenSSL is old or missingc                    sf   t   g G  fddd}t|| }|  |  g t  }|| |  |g dS )z
        C{_BypassTLS.loseConnection} calls C{loseConnection} on the base
        class, while preserving any default argument in the base class'
        C{loseConnection} implementation.
        c                       s   e Zd Z ffdd	ZdS )zDBypassTLSTests.test_loseConnectionPassThrough.<locals>.FakeTransportc                    s     | d S N)append)self	_connDone)result /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/internet/test/test_newtls.pyloseConnection4   s   zSBypassTLSTests.test_loseConnectionPassThrough.<locals>.FakeTransport.loseConnectionN)__name__
__module____qualname__r   r   defaultr   r   r   FakeTransport3   s    r   N)objectr   
_BypassTLSr   assertEqual)r   r   bypass
notDefaultr   r   r   test_loseConnectionPassThrough*   s   
z-BypassTLSTests.test_loseConnectionPassThroughN)r   r   r   __doc__r   skipr#   r   r   r   r   r   "   s
    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	FakeProducerz'
    A producer that does nothing.
    c                 C      d S r   r   r   r   r   r   pauseProducingH      zFakeProducer.pauseProducingc                 C   r'   r   r   r(   r   r   r   resumeProducingK   r*   zFakeProducer.resumeProducingc                 C   r'   r   r   r(   r   r   r   stopProducingN   r*   zFakeProducer.stopProducingN)r   r   r   r$   r)   r+   r,   r   r   r   r   r&   C   s
    r&   c                   @   s    e Zd ZdZdd Zdd ZdS )ProducerProtocolzy
    Register a producer, unregister it, and verify the producer hooks up to
    innards of C{TLSMemoryBIOProtocol}.
    c                 C   s   || _ || _d S r   )producerr   )r   r.   r   r   r   r   __init__Y   s   
zProducerProtocol.__init__c                 C   sf   t | jjtjstd| j| jd | j	| jjj
j
 | j  | j	| jjj
 | j  d S )Nz#TLSMemoryBIOProtocol not hooked up.T)
isinstance	transportprotocolr   BufferingTLSTransportRuntimeErrorregisterProducerr.   r   r   	_producerunregisterProducerr   r(   r   r   r   handshakeCompleted]   s   
z#ProducerProtocol.handshakeCompletedN)r   r   r   r$   r/   r8   r   r   r   r   r-   R   s    r-   c                   @   s@   e Zd ZdZes
dZdd Zdd Zdd Zd	d
 Z	dd Z
dS )ProducerTestsMixinzM
    Test the new TLS code integrates C{TLSMemoryBIOProtocol} correctly.
    z)Could not import twisted.internet._newtlsc                 C   6   g }t  }t| t t||t  | ||dg dS )z
        C{registerProducer} and C{unregisterProducer} on TLS transports
        created as SSL from the get go are passed to the
        C{TLSMemoryBIOProtocol}, not the underlying transport directly.
        N)r&   r   r   r-   r   r    r   r   r.   r   r   r   test_producerSSLFromStartt      z,ProducerTestsMixin.test_producerSSLFromStartc                 C   r:   )z
        C{registerProducer} and C{unregisterProducer} on TLS transports
        created by C{startTLS} are passed to the C{TLSMemoryBIOProtocol}, not
        the underlying transport directly.
        N)r&   r   r   r-   r	   r    r;   r   r   r   test_producerAfterStartTLS   r=   z-ProducerTestsMixin.test_producerAfterStartTLSc                    sp   |    |  g t G fdddt}G  fdddt}t| | | t  | g dS )z
        When a producer is registered, and then startTLS is called,
        the producer is re-registered with the C{TLSMemoryBIOProtocol}.
        c                       s   e Zd Z fddZdS )zMProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.RegisterTLSProtocolc                    s   | j   | j  r!| j jjj | j jj n| j jjjj | j jjj | j   | j   d S r   )	r1   r5   startTLSr   r2   r6   r.   r7   r   r(   r.   r   serverContext	streamingr   r   connectionMade   s   
z\ProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.RegisterTLSProtocol.connectionMadeNr   r   r   rC   r   r@   r   r   RegisterTLSProtocol   s    rE   c                       s   e Zd Z fddZdS )zJProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.StartTLSProtocolc                    s   | j   d S r   )r1   r?   r(   clientContextr   r   rC      s   zYProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.StartTLSProtocol.connectionMadeNrD   r   rF   r   r   StartTLSProtocol   s    rH   N)getClientContextgetServerContextr&   r   r   r   r    )r   rB   rE   rH   r   )rG   r.   r   rA   rB   r   startTLSAfterRegisterProducer   s   z0ProducerTestsMixin.startTLSAfterRegisterProducerc                 C      |  d dS )z
        When a streaming producer is registered, and then startTLS is called,
        the producer is re-registered with the C{TLSMemoryBIOProtocol}.
        TNrK   r(   r   r   r   +test_startTLSAfterRegisterProducerStreaming   s   z>ProducerTestsMixin.test_startTLSAfterRegisterProducerStreamingc                 C   rL   )z
        When a non-streaming producer is registered, and then startTLS is
        called, the producer is re-registered with the
        C{TLSMemoryBIOProtocol}.
        FNrM   r(   r   r   r   .test_startTLSAfterRegisterProducerNonStreaming   s   zAProducerTestsMixin.test_startTLSAfterRegisterProducerNonStreamingN)r   r   r   r$   r   r%   r<   r>   rK   rN   rO   r   r   r   r   r9   l   s    $r9   )!r$   twisted.internetr   &twisted.internet.test.connectionmixinsr   r   #twisted.internet.test.reactormixinsr   twisted.internet.test.test_tcpr   twisted.internet.test.test_tlsr   r   r	   r
   twisted.trialr   r   __newtlstwisted.protocolsr   ImportErrorzope.interfacer   TestCaser   r&   IHandshakeListenerr-   r9   globalsupdatemakeTestCaseClassesr   r   r   r   <module>   s*   !^