
    Vh                         d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
  G d de      Z G d d	e      Z G d
 de
ej                        Zy)z+
Test cases for twisted.protocols.stateful
    )calcsizepackunpack)StatefulProtocol)
test_basic)TestCasec                   L    e Zd ZdZdZdZ ee      Zd Zd Z	d Z
d Zd Zd	 Zy
)MyInt32StringReceiverz)
    A stateful Int32StringReceiver.
    i z!Ic                     | j                   dfS N   )
_getHeaderselfs    J/home/dcms/DCMS/lib/python3.12/site-packages/twisted/test/test_stateful.pygetInitialStatez%MyInt32StringReceiver.getInitialState   s    !!    c                 8    | j                   j                          y N)	transportloseConnection)r   lengths     r   lengthLimitExceededz)MyInt32StringReceiver.lengthLimitExceeded   s    %%'r   c                 |    t        d|      \  }|| j                  kD  r| j                  |       y | j                  |fS )N!i)r   
MAX_LENGTHr   
_getString)r   msgr   s      r   r   z MyInt32StringReceiver._getHeader   s<    4%	DOO#$$V,&&r   c                 @    | j                  |       | j                  dfS r   )stringReceivedr   r   r   s     r   r   z MyInt32StringReceiver._getString&   s    C !!r   c                     t         )z 
        Override this.
        )NotImplementedErrorr!   s     r   r    z$MyInt32StringReceiver.stringReceived*   s
     "!r   c                 z    | j                   j                  t        | j                  t	        |            |z          y)zS
        Send an int32-prefixed string to the other end of the connection.
        N)r   writer   structFormatlen)r   datas     r   
sendStringz MyInt32StringReceiver.sendString0   s,     	T$"3"3SY?$FGr   N)__name__
__module____qualname____doc__r   r&   r   prefixLengthr   r   r   r   r    r)    r   r   r
   r
      s<     JLL)L"('""Hr   r
   c                   &    e Zd Zd Zd ZdZdZd Zy)	TestInt32c                     g | _         y r   )receivedr   s    r   connectionMadezTestInt32.connectionMade8   s	    r   c                 :    | j                   j                  |       y r   )r3   append)r   ss     r   r    zTestInt32.stringReceived;   s    Qr   2   r   c                     d| _         y )N   )closed)r   reasons     r   connectionLostzTestInt32.connectionLostA   s	    r   N)r*   r+   r,   r4   r    r   r;   r=   r/   r   r   r1   r1   7   s      JFr   r1   c                   ,    e Zd ZeZddgZdgZg dZd Zy)
Int32Tests   as   bbbbbbbbbbbbbbbbs
      aaaaaa)s      s   hello therer   c                     | j                         }d}| j                  dz  D ]  }|t        dt        |            |z   z  } |j	                  |       | j                  |j                  | j                  dz         y )Nr   r   r   )getProtocolstringsr   r'   dataReceivedassertEqualr3   )r   rbigr7   s       r   test_bigReceivezInt32Tests.test_bigReceiveK   sp    ! 	*A4c!f%))C	*	sT\\A%56r   N)	r*   r+   r,   r1   protocolrC   illegalStringspartialStringsrH   r/   r   r   r?   r?   E   s#    HYG/0N;N7r   r?   N)r-   structr   r   r   twisted.protocols.statefulr   twisted.protocols.testr   twisted.trial.unittestr   r
   r1   IntNTestCaseMixinr?   r/   r   r   <module>rQ      sL   
 * ) 7 - +$H, $HN% 7:77 7r   