ó
[³XMc           @   s‹   d  Z  d d l m Z d d l m Z d d l m Z m Z m Z d e f d „  ƒ  YZ	 d e	 f d „  ƒ  YZ
 d	 e j f d
 „  ƒ  YZ d S(   s+   
Test cases for twisted.protocols.stateful
iÿÿÿÿ(   t   test_protocols(   t   StatefulProtocol(   t   packt   unpackt   calcsizet   MyInt32StringReceiverc           B   s\   e  Z d  Z d Z d Z e e ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(	   s)   
    A stateful Int32StringReceiver.
    iŸ† s   !Ic         C   s   |  j  d f S(   Ni   (   t
   _getHeader(   t   self(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   getInitialState   s    c         C   s   |  j  j ƒ  d  S(   N(   t	   transportt   loseConnection(   R   t   length(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   lengthLimitExceeded   s    c         C   s?   t  d | ƒ \ } | |  j k r2 |  j | ƒ d  S|  j | f S(   Ns   !i(   R   t
   MAX_LENGTHR   t
   _getString(   R   t   msgR   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR      s
    c         C   s   |  j  | ƒ |  j d f S(   Ni   (   t   stringReceivedR   (   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR   $   s    c         C   s
   t  ‚ d S(   s    
        Override this.
        N(   t   NotImplementedError(   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR   (   s    c         C   s*   |  j  j t |  j t | ƒ ƒ | ƒ d S(   sS   
        Send an int32-prefixed string to the other end of the connection.
        N(   R	   t   writeR   t   structFormatt   len(   R   t   data(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt
   sendString.   s    (   t   __name__t
   __module__t   __doc__R   R   R   t   prefixLengthR   R   R   R   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR      s   					t	   TestInt32c           B   s/   e  Z d  „  Z d „  Z d Z d Z d „  Z RS(   c         C   s   g  |  _  d  S(   N(   t   received(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   connectionMade6   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   append(   R   t   s(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR   9   s    i2   i    c         C   s   d |  _  d  S(   Ni   (   t   closed(   R   t   reason(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   connectionLost?   s    (   R   R   R   R   R   R    R"   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR   5   s
   		t   Int32TestCasec           B   s   e  Z e Z d  „  Z RS(   c         C   sr   |  j  ƒ  } d } x2 |  j d D]# } | t d t | ƒ ƒ | 7} q  W| j | ƒ |  j | j |  j d ƒ d  S(   Nt    i   s   !i(   t   getProtocolt   stringsR   R   t   dataReceivedt   assertEqualsR   (   R   t   rt   bigR   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   test_bigReceiveF   s    !(   R   R   R   t   protocolR+   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR#   C   s   N(   R   t   twisted.testR    t   twisted.protocols.statefulR   t   structR   R   R   R   R   R#   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   <module>   s   &