
u3;c       s     d  Z  / 1 d k Z 2 d k Z 3 d k Z 5 d e i f d     YZ  d f  d     YZ  d f  d     YZ  d   Z d S(	   s  A class supporting chat-style (command/response) protocols.

This class adds support for 'chat' style protocols - where one side
sends a 'command', and the other sends a response (examples would be
the common internet protocols - smtp, nntp, ftp, etc..).

The handle_read() method looks at the input stream for the current
'terminator' (usually '
' for single-line responses, '
.
'
for multi-line output), calling self.found_terminator() on its
receipt.

for example:
Say you build an async nntp client using this class.  At the start
of the connection, you'll have self.terminator set to '
', in
order to process the single-line greeting.  Just before issuing a
'LIST' command you'll set it to '
.
'.  The output of the LIST
command will be accumulated (using your own 'collect_incoming_data'
method) up to the terminator, and then control will be returned to
you - by calling your self.found_terminator() method.
Ns
   async_chatc      s   5 d  Z  7 ; d Z < d Z > e d  Z D d   Z H d   Z P d   Z  d   Z  d   Z	  d   Z
  d	   Z  d
   Z  d   Z  d   Z  d   Z  d   Z  d   Z RS(   s   This is an abstract class.  You must derive from this class, and add
	the two methods collect_incoming_data() and found_terminator()i   c    sD   > ? d |  _ @ d |  _ A t   |  _ B t i i |  |  d  S(   Ns    (	   s   selfs   ac_in_buffers   ac_out_buffers   fifos   producer_fifos   asyncores
   dispatchers   __init__s   conn(   s   selfs   conns   asynchat.pys   __init__> s   c    s   D E F | |  _ d S(   sR   Set the input delimiter.  Can be a fixed string of any length, an integer, or NoneN(   s   terms   selfs
   terminator(   s   selfs   terms   asynchat.pys   set_terminatorD s   c    s   H I |  i Sd  S(   N(   s   selfs
   terminator(   s   selfs   asynchat.pys   get_terminatorH s   c    s  P R y S |  i |  i  } Wn/ T t i j
 o } U |  i   V d  Sn XX |  i | |  _ _ x)_ |  i o` t	 |  i  } a |  i   } b | t j o# d |  i |  i  e d |  _ nf t |  t d  j o h | } i | | j  o6 j |  i |  i  k d |  _ l |  i | |  _ nD n |  i |  i |   o |  i | |  _ p d |  _ q |  i   nz t	 |  } { t i |  i |  } | | d j oS ~ | d j o  |  i |  i |   n  |  i | | |  _  |  i   n  t |  i |  }  | oH  | | j o0  |  i |  i |    |  i | |  _ n  Pn   |  i |  i   d |  _ qj Wd  S(   Ns    i    i   (   s   selfs   recvs   ac_in_buffer_sizes   datas   sockets   errors   whys   handle_errors   ac_in_buffers   lens   lbs   get_terminators
   terminators   Nones   collect_incoming_datas   types   ns   found_terminators   terminator_lens   strings   finds   indexs   find_prefix_at_end(   s   selfs   datas   whys   lbs
   terminators   ns   terminator_lens   indexs   asynchat.pys   handle_readP sL    		
c    s     |  i   d  S(   N(   s   selfs   initiate_send(   s   selfs   asynchat.pys   handle_write s   c    s     |  i   d  S(   N(   s   selfs   close(   s   selfs   asynchat.pys   handle_close s   c    s-     |  i i t |    |  i   d  S(   N(   s   selfs   producer_fifos   pushs   simple_producers   datas   initiate_send(   s   selfs   datas   asynchat.pys   push s   c    s'     |  i i |   |  i   d  S(   N(   s   selfs   producer_fifos   pushs   producers   initiate_send(   s   selfs   producers   asynchat.pys   push_with_producer s   c    s#      t  |  i  |  i j Sd S(   s4   predicate for inclusion in the readable for select()N(   s   lens   selfs   ac_in_buffers   ac_in_buffer_size(   s   selfs   asynchat.pys   readable s   c    s5      |  i d j o |  i i   o |  i Sd S(   s4   predicate for inclusion in the writable for select()s    N(   s   selfs   ac_out_buffers   producer_fifos   is_emptys	   connected(   s   selfs   asynchat.pys   writable s   c    s      |  i i t  d S(   sA   automatically close this channel once the outgoing queue is emptyN(   s   selfs   producer_fifos   pushs   None(   s   selfs   asynchat.pys   close_when_done s   c    s0    t  d  }  x d o	 t |  i  o  |  i i   }  | t j o:  |  i o!  |  i i	    |  i
   n  d  SnE  t  |  | j o.  |  i i	    |  i | |  _  d  Sn  | i   }  | o  |  i | |  _  d  Sn  |  i i	   n  d  Sq Wd  S(   Ns    i   (   s   types   _string_types   lens   selfs   producer_fifos   firsts   ps   Nones   ac_out_buffers   pops   closes   mores   data(   s   selfs   _string_types   ps   datas   asynchat.pys   refill_buffer s(    

c    s     |  i }  t |  i  | j  o  |  i   n  |  i o |  i ow  y>  |  i |  i |   }  | o  |  i | |  _ n Wn/  t	 i
 j
 o }  |  i    d  Sn Xn d  S(   N(   s   selfs   ac_out_buffer_sizes   obss   lens   ac_out_buffers   refill_buffers	   connecteds   sends   num_sents   sockets   errors   whys   handle_error(   s   selfs   obss   num_sents   whys   asynchat.pys   initiate_send s   
c    sG     d |  _  d |  _  x"  |  i o  |  i i   q! Wd  S(   Ns    (   s   selfs   ac_in_buffers   ac_out_buffers   producer_fifos   pop(   s   selfs   asynchat.pys   discard_buffers s
    (   s   __doc__s   ac_in_buffer_sizes   ac_out_buffer_sizes   Nones   __init__s   set_terminators   get_terminators   handle_reads   handle_writes   handle_closes   pushs   push_with_producers   readables   writables   close_when_dones   refill_buffers   initiate_sends   discard_buffers(    s   asynchat.pys
   async_chat5 s"   			B
s   simple_producerc      s      d d  Z   d   Z RS(   Nc    s     | |  _   | |  _ d  S(   N(   s   datas   selfs   buffer_size(   s   selfs   datas   buffer_sizes   asynchat.pys   __init__ s   i   c    sv     t  |  i  |  i j o4  |  i |  i  }  |  i |  i |  _  | Sn   |  i }  d |  _  | Sd  S(   Ns    (   s   lens   selfs   datas   buffer_sizes   result(   s   selfs   results   asynchat.pys   more s   (   s   __init__s   more(    s   asynchat.pys   simple_producer s   s   fifoc      sP     e  d  Z  d   Z  d   Z d   Z d   Z 	d   Z RS(   Nc    s.     | o  g  |  _  n  | |  _  d  S(   N(   s   lists   self(   s   selfs   lists   asynchat.pys   __init__ s   c    s     t  |  i  Sd  S(   N(   s   lens   selfs   list(   s   selfs   asynchat.pys   __len__ s   c    s    |  i g  j Sd  S(   N(   s   selfs   list(   s   selfs   asynchat.pys   is_empty s   c    s   |  i d Sd  S(   Ni    (   s   selfs   list(   s   selfs   asynchat.pys   firsts   c    s   |  i i |  d  S(   N(   s   selfs   lists   appends   data(   s   selfs   datas   asynchat.pys   pushs   c    sO   	
|  i o. |  i d } |  i d =d | f Sn d t f Sd  S(   Ni    i   (   s   selfs   lists   results   None(   s   selfs   results   asynchat.pys   pop	s
   (   s   Nones   __init__s   __len__s   is_emptys   firsts   pushs   pop(    s   asynchat.pys   fifo s   c    sX    !t  |  d } "x1 "| o |  i | |   o #| d 8} q W$| Sd  S(   Ni   (   s   lens   needles   ls   haystacks   endswith(   s   haystacks   needles   ls   asynchat.pys   find_prefix_at_end s
    (	   s   __doc__s   sockets   asyncores   strings
   dispatchers
   async_chats   simple_producers   fifos   find_prefix_at_end(    s   asynchat.pys   ?/ s   *