ó
²“ƒNc           @   sž   d  Z  d d l m 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 e j f d „  ƒ  YZ d S(   s+   
Test cases for twisted.protocols.stateful
iÿÿÿÿ(   t   TestCase(   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   connectionMade7   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   :   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   6   s
   		t   Int32TestCasec           B   s;   e  Z e Z d  d g Z d g Z d d d g Z d „  Z RS(	   t   at   bi   s
      aaaaaat      s   hello theret    c         C   sr   |  j  ƒ  } d } x2 |  j d D]# } | t d t | ƒ ƒ | 7} q  W| j | ƒ |  j | j |  j d ƒ d  S(   NR(   i   s   !i(   t   getProtocolt   stringsR   R   t   dataReceivedt   assertEqualR   (   R   t   rt   bigR    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   test_bigReceiveJ   s    !t   bbbbbbbbbbbbbbbb(   R   R   R   t   protocolR*   t   illegalStringst   partialStringsR/   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyR$   D   s
   	N(   R   t   twisted.trial.unittestR    t   twisted.testR   t   twisted.protocols.statefulR   t   structR   R   R   R   R   t   IntNTestCaseMixinR$   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_stateful.pyt   <module>   s   &