;ò
ëŒü?c           @   sd   d  Z  d k Z d k Z 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 '\r\n' for single-line responses, '\r\n.\r\n'
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 '\r\n', in
order to process the single-line greeting.  Just before issuing a
'LIST' command you'll set it to '\r\n.\r\n'.  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           B   s­   t  Z d  Z d Z d Z e d „ Z d „  Z d „  Z d „  Z	 d „  Z
 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         C   s5   d |  _ d |  _ t ƒ  |  _ t i i |  | ƒ d  S(   Ns    (	   s   selfs   ac_in_buffers   ac_out_buffers   fifos   producer_fifos   asyncores
   dispatchers   __init__s   conn(   s   selfs   conn(    (    s%   /mit/python/lib/python2.3/asynchat.pys   __init__=   s    		c         C   s   t  d ‚ d  S(   Ns   must be implemented in subclass(   s   NotImplementedError(   s   selfs   data(    (    s%   /mit/python/lib/python2.3/asynchat.pys   collect_incoming_dataC   s    c         C   s   t  d ‚ d  S(   Ns   must be implemented in subclass(   s   NotImplementedError(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   found_terminatorF   s    c         C   s   | |  _ 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   term(    (    s%   /mit/python/lib/python2.3/asynchat.pys   set_terminatorI   s     c         C   s   |  i Sd  S(   N(   s   selfs
   terminator(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   get_terminatorM   s    c         C   s"  y |  i |  i ƒ } Wn& t i j
 o } |  i ƒ  d  Sn X|  i | |  _ xÌ|  i oÁt	 |  i ƒ } |  i ƒ  } | t j p
 | d j o |  i |  i ƒ d |  _ qR t | t ƒ o{ | } | | j  o- |  i |  i ƒ d |  _ |  i | |  _ q|  i |  i |  ƒ |  i | |  _ d |  _ |  i ƒ  qR t	 | ƒ } |  i i | ƒ } | d j oG | d j o |  i |  i |  ƒ n |  i | | |  _ |  i ƒ  qR t |  i | ƒ } | o< | | j o* |  i |  i |  ƒ |  i | |  _ n PqR |  i |  i ƒ d |  _ qR 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
   isinstances   ints   ns   found_terminators   terminator_lens   finds   indexs   find_prefix_at_end(   s   selfs   indexs   lbs   ns   terminator_lens
   terminators   datas   why(    (    s%   /mit/python/lib/python2.3/asynchat.pys   handle_readU   sL    
	 
			c         C   s   |  i ƒ  d  S(   N(   s   selfs   initiate_send(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   handle_write—   s    c         C   s   |  i ƒ  d  S(   N(   s   selfs   close(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   handle_closeš   s    c         C   s$   |  i i t | ƒ ƒ |  i ƒ  d  S(   N(   s   selfs   producer_fifos   pushs   simple_producers   datas   initiate_send(   s   selfs   data(    (    s%   /mit/python/lib/python2.3/asynchat.pys   push   s    c         C   s   |  i i | ƒ |  i ƒ  d  S(   N(   s   selfs   producer_fifos   pushs   producers   initiate_send(   s   selfs   producer(    (    s%   /mit/python/lib/python2.3/asynchat.pys   push_with_producer¡   s    c         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   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   readable¥   s     c         C   s,   |  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   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   writable©   s     c         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   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   close_when_done³   s     c         C   sâ   xÛ n oÓ t  |  i ƒ o» |  i i ƒ  } | t j o. |  i o |  i i ƒ  |  i ƒ  n d  Sn6 t	 | t
 ƒ o% |  i i ƒ  |  i | |  _ d  Sn | i ƒ  } | o |  i | |  _ d  SqÙ |  i i ƒ  q d  Sq
 Wd  S(   Ni   (   s   lens   selfs   producer_fifos   firsts   ps   Nones   ac_out_buffers   pops   closes
   isinstances   strs   mores   data(   s   selfs   ps   data(    (    s%   /mit/python/lib/python2.3/asynchat.pys   refill_buffer¹   s&     c         C   s§   |  i } t |  i ƒ | j  o |  i ƒ  n |  i o |  i ob y5 |  i |  i |  ƒ } | o |  i | |  _ n Wq£ t	 i
 j
 o } |  i ƒ  d  Sq£ 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   whys   num_sent(    (    s%   /mit/python/lib/python2.3/asynchat.pys   initiate_sendÑ   s    	
c         C   s5   d |  _ d |  _ x |  i o |  i i ƒ  q Wd  S(   Ns    (   s   selfs   ac_in_buffers   ac_out_buffers   producer_fifos   pop(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   discard_buffersâ   s
    		 
(   s   __name__s
   __module__s   __doc__s   ac_in_buffer_sizes   ac_out_buffer_sizes   Nones   __init__s   collect_incoming_datas   found_terminators   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%   /mit/python/lib/python2.3/asynchat.pys
   async_chat4   s&    					B						
			s   simple_producerc           B   s   t  Z d d „ Z d „  Z RS(   Ni   c         C   s   | |  _  | |  _ d  S(   N(   s   datas   selfs   buffer_size(   s   selfs   datas   buffer_size(    (    s%   /mit/python/lib/python2.3/asynchat.pys   __init__ì   s    	c         C   s^   t  |  i ƒ |  i j o+ |  i |  i  } |  i |  i |  _ | Sn |  i } d |  _ | Sd  S(   Ns    (   s   lens   selfs   datas   buffer_sizes   result(   s   selfs   result(    (    s%   /mit/python/lib/python2.3/asynchat.pys   moreð   s    		(   s   __name__s
   __module__s   __init__s   more(    (    (    s%   /mit/python/lib/python2.3/asynchat.pys   simple_producerê   s   s   fifoc           B   sA   t  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   Nc         C   s"   | o g  |  _  n
 | |  _  d  S(   N(   s   lists   self(   s   selfs   list(    (    s%   /mit/python/lib/python2.3/asynchat.pys   __init__û   s    c         C   s   t  |  i ƒ Sd  S(   N(   s   lens   selfs   list(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   __len__  s    c         C   s   |  i g  j Sd  S(   N(   s   selfs   list(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   is_empty  s    c         C   s   |  i d Sd  S(   Ni    (   s   selfs   list(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   first  s    c         C   s   |  i i | ƒ d  S(   N(   s   selfs   lists   appends   data(   s   selfs   data(    (    s%   /mit/python/lib/python2.3/asynchat.pys   push
  s    c         C   s2   |  i o d |  i i d ƒ f Sn d t f Sd  S(   Ni   i    (   s   selfs   lists   pops   None(   s   self(    (    s%   /mit/python/lib/python2.3/asynchat.pys   pop  s    
(	   s   __name__s
   __module__s   Nones   __init__s   __len__s   is_emptys   firsts   pushs   pop(    (    (    s%   /mit/python/lib/python2.3/asynchat.pys   fifoú   s   				c         C   sF   t  | ƒ d } x+ | o |  i | |  ƒ o | d 8} q W| Sd  S(   Ni   (   s   lens   needles   ls   haystacks   endswith(   s   haystacks   needles   l(    (    s%   /mit/python/lib/python2.3/asynchat.pys   find_prefix_at_end"  s
     (   s   __doc__s   sockets   asyncores
   dispatchers
   async_chats   simple_producers   fifos   find_prefix_at_end(   s   asyncores   sockets   find_prefix_at_ends   simple_producers   fifos
   async_chat(    (    s%   /mit/python/lib/python2.3/asynchat.pys   ?/   s   		¶(