
M9c       s    d  Z  / 1 d k Z 2 d k Z 3 d k Z 4 d k Z 5 d k Z 7 d k Z 8 e i d j o: 9 d Z : d Z	 ; d Z
 < d Z = d Z > d Z n/ @ d	 k l
 Z
 l	 Z	 l Z l Z l Z l Z B y C e Wn D e j
 o E h  Z n XG d
 e i f d     YZ J d Z L d e d  Z t d e d  Z  d d e d  Z  d f  d     YZ d e f d     YZ d   Z e d  Z d k Z e i d j oK d k Z d k Z d f  d     YZ d e f d     YZ n d S(   s  Basic infrastructure for asynchronous socket service clients and servers.

There are only two ways to have a program on a single processor do "more
than one thing at a time".  Multi-threaded programming is the simplest and 
most popular way to do it, but there is another very different technique,
that lets you have nearly all the advantages of multi-threading, without
actually using multiple threads. it's really only practical if your program
is largely I/O bound. If your program is CPU bound, then pre-emptive
scheduled threads are probably what you really need. Network servers are
rarely CPU-bound, however. 

If your operating system supports the select() system call in its I/O 
library (and nearly all do), then you can use it to juggle multiple
communication channels at once; doing other work while your I/O is taking
place in the "background."  Although this strategy can seem strange and
complex, especially at first, it is in many ways easier to understand and
control than multi-threaded programming. The module documented here solves
many of the difficult problems for you, making the task of building
sophisticated high-performance network servers and clients a snap. 
Ns   nti3'  i4'  i5'  iF'  iI'  iJ'  (   s   EALREADYs   EINPROGRESSs   EWOULDBLOCKs
   ECONNRESETs   ENOTCONNs	   ESHUTDOWNs   ExitNowc      s   G H RS(   N(    (    s%   /mit/python/lib/python2.0/asyncore.pys   ExitNowG s   i    c    s#  L M N | t j o O t } n P | oQ g  } g  } g  } R xg | i   d R rT \ } } S | i	   o T | i
 |  n U | i   o V | i
 |  n qT WW t i | | | |   \ } } } Y t o Z | G| G| GHn \ x | d \ r } ] y] ^ | | } _ y ` | i   Wn5 a t j
 o b t  n c d | i   n XWn e t j
 o
 f n Xq Wh x | d h r } i y] j | | } k y l | i   Wn5 m t j
 o n t  n o p | i   n XWn q t j
 o
 r n XqWn d  S(   Ni    (   s   maps   Nones
   socket_maps   rs   ws   es   itemss   fds   objs   readables   appends   writables   selects   timeouts   DEBUGs   handle_read_events   ExitNows   handle_errors   KeyErrors   handle_write_event(   s   timeouts   maps   rs   ws   es   fds   objs%   /mit/python/lib/python2.0/asyncore.pys   pollL sL   
 $
 	 	f0.0c    s  t u d  k  } v | t j o w t } n y t |  d  }  z | o{ g  } | x | i   d | r} \ } } } d } ~ | i   o  | i } n  | i   o  | | i B} n  | o  | i | | f  n qd W | i  | |   }  x | d  r \ } }  y  | | }  yH  | | i @o  | i   n  | | i @o  | i   n Wn5  t j
 o  t  n   | i   n XWn  t j
 o
  n Xq	Wn d  S(   Ni  i    (   s   polls   maps   Nones
   socket_maps   ints   timeouts   ls   itemss   fds   objs   flagss   readables   POLLINs   writables   POLLOUTs   appends   rs   handle_read_events   handle_write_events   ExitNows   handle_errors   KeyError(   s   timeouts   maps   polls   ls   fds   objs   flagss   rs%   /mit/python/lib/python2.0/asyncore.pys   poll2t s>   
	 	
 c    si     | o  t } n'  t }  | t j o  t } n  x  | o  | |  |  qF Wd  S(   N(   s   use_polls   poll2s   poll_funs   polls   maps   Nones
   socket_maps   timeout(   s   timeouts   use_polls   maps   poll_funs%   /mit/python/lib/python2.0/asyncore.pys   loop s   
	 
f30.0s
   dispatcherc      s    d Z   d Z  d Z  d Z  e Z  e e d  Z  d   Z  e d  Z  e d  Z	  d   Z
  e d  Z  d   Z  d	   Z  e i d
 j o  d   Z n  d   Z  d   Z d   Z 	d   Z d   Z d   Z *d   Z <d   Z Bd   Z Id   Z Ld d  Z Pd   Z ^d   Z ed   Z hd   Z |d   Z d   Z  d   Z! d   Z" d    Z# d!   Z$ RS("   Ni    c    sG     | o6  |  i | |   |  i i d   d |  _ n d  S(   Ni    i   (   s   socks   selfs
   set_sockets   maps   sockets   setblockings	   connected(   s   selfs   socks   maps%   /mit/python/lib/python2.0/asyncore.pys   __init__ s   
c    s
    y  g  }  |  i o |  i o  | i d  n"  |  i o  | i d  n  |  i o  | i d |  i  n  d |  i i t i	 | d  t
 |   f SWnP   y  t |  i  } Wn   d } n X d t
 |   | f Sn Xd  S(   Ns	   listenings	   connecteds   %s:%ds   <%s %s at %x>s    s   no self.addr!s3   <__repr__ (self) failed for object at %x (addr=%s)>(   s   statuss   selfs	   acceptings   addrs   appends	   connecteds	   __class__s   __name__s   strings   joins   ids   reprs   ar(   s   selfs   statuss   ars%   /mit/python/lib/python2.0/asyncore.pys   __repr__ s   	0c    s4     | t j o  t } n  |  | |  i <d  S(   N(   s   maps   Nones
   socket_maps   selfs   _fileno(   s   selfs   maps%   /mit/python/lib/python2.0/asyncore.pys   add_channel s   c    sQ     |  i }  | t j o  t } n  | i |  o  | | =n d  S(   N(   s   selfs   _filenos   fds   maps   Nones
   socket_maps   has_key(   s   selfs   maps   fds%   /mit/python/lib/python2.0/asyncore.pys   del_channel s
   c    sf     | | f |  _  t i | |  |  _  |  i i d   |  i i   |  _  |  i   d  S(   Ni    (	   s   familys   types   selfs   family_and_types   sockets   setblockings   filenos   _filenos   add_channel(   s   selfs   familys   types%   /mit/python/lib/python2.0/asyncore.pys   create_socket s
   c    s9     | |  i d < | i   |  _  |  i |  d  S(   Ns   socket(   s   socks   selfs   __dict__s   filenos   _filenos   add_channels   map(   s   selfs   socks   maps%   /mit/python/lib/python2.0/asyncore.pys
   set_socket s   c    sY     y?  |  i i t i t i  |  i i t i t i  d B Wn   n Xd  S(   Ni   (   s   selfs   sockets
   setsockopts
   SOL_SOCKETs   SO_REUSEADDRs
   getsockopt(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   set_reuse_addr s
   'c    s     d Sd  S(   Ni   (    (   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   readable s   s   macc    s     |  i Sd  S(   N(   s   selfs	   accepting(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   writable s   c    s     d Sd  S(   Ni   (    (   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   writable s   c    sS     d |  _ t i d j o
 | d j o d } n |  i i |  Sd  S(   Ni   s   nti   (   s   selfs	   acceptings   oss   names   nums   sockets   listen(   s   selfs   nums%   /mit/python/lib/python2.0/asyncore.pys   listen s    c    s&   | |  _  |  i i |  Sd  S(   N(   s   addrs   selfs   sockets   bind(   s   selfs   addrs%   /mit/python/lib/python2.0/asyncore.pys   binds   c    s   	
d |  _ y |  i i |  WnR t i j
 o@ } | d t t t	 f j o d  Sn t i |  n Xd |  _ |  i
   d  S(   Ni    i   (   s   selfs	   connecteds   sockets   connects   addresss   errors   whys   EINPROGRESSs   EALREADYs   EWOULDBLOCKs   handle_connect(   s   selfs   addresss   whys%   /mit/python/lib/python2.0/asyncore.pys   connect	s   c    s{   y) |  i i   \ } } | | f SWnE t i j
 o3 } | d t j o n t i |  n Xd  S(   Ni    (   s   selfs   sockets   accepts   conns   addrs   errors   whys   EWOULDBLOCK(   s   selfs   conns   addrs   whys%   /mit/python/lib/python2.0/asyncore.pys   accepts   c    s}    y  !|  i i |  } "| SWnP #t i j
 o> } $| d t j o %d Sn 't i |  (d Sn Xd  S(   Ni    (   s   selfs   sockets   sends   datas   results   errors   whys   EWOULDBLOCK(   s   selfs   datas   results   whys%   /mit/python/lib/python2.0/asyncore.pys   sends   c    s   *+yC ,|  i i |  } -| o 0|  i   1d Sn 3| SWn_ 4t i j
 oM } 6| d t t	 t
 g j o 7|  i   8d Sn :t i |  n Xd  S(   Ns    i    (   s   selfs   sockets   recvs   buffer_sizes   datas   handle_closes   errors   whys
   ECONNRESETs   ENOTCONNs	   ESHUTDOWN(   s   selfs   buffer_sizes   datas   whys%   /mit/python/lib/python2.0/asyncore.pys   recv*s   c    s$   <=|  i   >|  i i   d  S(   N(   s   selfs   del_channels   sockets   close(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   close<s   c    s   BCt  |  i |  Sd  S(   N(   s   getattrs   selfs   sockets   attr(   s   selfs   attrs%   /mit/python/lib/python2.0/asyncore.pys   __getattr__Bs   c    s$   IJt  i i d t |   d  S(   Ns   log: %s
(   s   syss   stderrs   writes   strs   message(   s   selfs   messages%   /mit/python/lib/python2.0/asyncore.pys   logIs   c    s4   LMt  p
 | d j o Nd | | f GHn d  S(   Ns   infos   %s: %s(   s	   __debug__s   types   message(   s   selfs   messages   types%   /mit/python/lib/python2.0/asyncore.pys   log_infoLs   s   infoc    s   PQ|  i o/ T|  i o Ud |  _ n V|  i   nF W|  i o* X|  i   Yd |  _ Z|  i   n \|  i   d  S(   Ni   (   s   selfs	   acceptings	   connecteds   handle_accepts   handle_connects   handle_read(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_read_eventPs   c    s?   ^`|  i o a|  i   bd |  _ n c|  i   d  S(   Ni   (   s   selfs	   connecteds   handle_connects   handle_write(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_write_event^s   c    s   ef|  i   d  S(   N(   s   selfs   handle_expt(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_expt_eventes   c    s   hit    \ \ } } } } } } ly mt |   } Wn nod t
 |   } n Xq|  i d | | | | f xd  z|  i   d  S(   Ns*   <__repr__ (self) failed for object at %0x>s:   uncaptured python exception, closing channel %s (%s:%s %s)s   error(   s   compact_tracebacks   files   funs   lines   ts   vs   tbinfos   reprs   selfs	   self_reprs   ids   log_infos   close(   s   selfs   files   funs   lines   ts   vs   tbinfos	   self_reprs%   /mit/python/lib/python2.0/asyncore.pys   handle_errorhs   !
c    s   |}|  i d d  d  S(   Ns   unhandled exceptions   warning(   s   selfs   log_info(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_expt|s   c    s   |  i d d  d  S(   Ns   unhandled read events   warning(   s   selfs   log_info(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_reads   c    s   |  i d d  d  S(   Ns   unhandled write events   warning(   s   selfs   log_info(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_writes   c    s   |  i d d  d  S(   Ns   unhandled connect events   warning(   s   selfs   log_info(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_connects   c    s   |  i d d  d  S(   Ns   unhandled accept events   warning(   s   selfs   log_info(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_accepts   c    s'   |  i d d  |  i   d  S(   Ns   unhandled close events   warning(   s   selfs   log_infos   close(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_closes   (%   s   debugs	   connecteds	   acceptings   closings   Nones   addrs   __init__s   __repr__s   add_channels   del_channels   create_sockets
   set_sockets   set_reuse_addrs   readables   oss   names   writables   listens   binds   connects   accepts   sends   recvs   closes   __getattr__s   logs   log_infos   handle_read_events   handle_write_events   handle_expt_events   handle_errors   handle_expts   handle_reads   handle_writes   handle_connects   handle_accepts   handle_close(    s%   /mit/python/lib/python2.0/asyncore.pys
   dispatcher sH   					
s   dispatcher_with_sendc      sD   e  d  Z d   Z d   Z d   Z d   Z RS(   Nc    s&   t  i |  |  d |  _ d  S(   Ns    (   s
   dispatchers   __init__s   selfs   socks
   out_buffer(   s   selfs   socks%   /mit/python/lib/python2.0/asyncore.pys   __init__s   c    s?   d } t i |  |  i d   } |  i | |  _ d  S(   Ni    i   (   s   num_sents
   dispatchers   sends   selfs
   out_buffer(   s   selfs   num_sents%   /mit/python/lib/python2.0/asyncore.pys   initiate_sends   	c    s   |  i   d  S(   N(   s   selfs   initiate_send(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   handle_writes   c    s"   |  i p t |  i  Sd  S(   N(   s   selfs	   connecteds   lens
   out_buffer(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   writables   c    sR   |  i o |  i d t |   n |  i | |  _ |  i   d  S(   Ns
   sending %s(   s   selfs   debugs   log_infos   reprs   datas
   out_buffers   initiate_send(   s   selfs   datas%   /mit/python/lib/python2.0/asyncore.pys   sends   (   s   Nones   __init__s   initiate_sends   handle_writes   writables   send(    s%   /mit/python/lib/python2.0/asyncore.pys   dispatcher_with_sends
   c     s   t  i   \ }  } } g  } xb d oW | i | i i i	 | i i i
 t | i  f  | i } | o Pn q* W~ | d \ } } } d t i t d   |  d  d } | | | f |  | | f Sd  S(   Ni   s   [c    s   t  i |  d  S(   Ns   |(   s   strings   joins   x(   s   xs%   /mit/python/lib/python2.0/asyncore.pys   <lambda>s    s   ] [s   ](   s   syss   exc_infos   ts   vs   tbs   tbinfos   appends   tb_frames   f_codes   co_filenames   co_names   strs	   tb_linenos   tb_nexts   files   functions   lines   strings   joins   maps   info(   s   ts   vs   tbs   tbinfos   files   functions   lines   infos%   /mit/python/lib/python2.0/asyncore.pys   compact_tracebacks   	 
4	c    s`   |  t j o t }  n x) |  i   d r } | i i   q2 W|  i   d  S(   Ni    (   s   maps   Nones
   socket_maps   valuess   xs   sockets   closes   clear(   s   maps   xs%   /mit/python/lib/python2.0/asyncore.pys	   close_alls    	s   posixs   file_wrapperc      sS   d   Z  d   Z d   Z e Z e Z d   Z d   Z RS(   Nc    s   | |  _  d  S(   N(   s   fds   self(   s   selfs   fds%   /mit/python/lib/python2.0/asyncore.pys   __init__s   c    s$   t  t i |  i f |  Sd  S(   N(   s   applys   oss   reads   selfs   fds   args(   s   selfs   argss%   /mit/python/lib/python2.0/asyncore.pys   recvs   c    s$   t  t i |  i f |  Sd  S(   N(   s   applys   oss   writes   selfs   fds   args(   s   selfs   argss%   /mit/python/lib/python2.0/asyncore.pys   sends   c    s   t  i |  i  Sd  S(   N(   s   oss   closes   selfs   fd(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   closes   c    s   |  i Sd  S(   N(   s   selfs   fd(   s   selfs%   /mit/python/lib/python2.0/asyncore.pys   filenos   (   s   __init__s   recvs   sends   reads   writes   closes   fileno(    s%   /mit/python/lib/python2.0/asyncore.pys   file_wrappers   		s   file_dispatcherc      s   d   Z   d   Z RS(   Nc    sw   t  i |   d |  _ t i | t i d  } | t i	 B} t i | t i
 |  |  i |  d  S(   Ni   i    (   s
   dispatchers   __init__s   selfs	   connecteds   fcntls   fds   FCNTLs   F_GETFLs   flagss
   O_NONBLOCKs   F_SETFLs   set_file(   s   selfs   fds   flagss%   /mit/python/lib/python2.0/asyncore.pys   __init__s   c    s2    | |  _ t |  |  _ |  i   d  S(   N(   s   fds   selfs   _filenos   file_wrappers   sockets   add_channel(   s   selfs   fds%   /mit/python/lib/python2.0/asyncore.pys   set_file s   (   s   __init__s   set_file(    s%   /mit/python/lib/python2.0/asyncore.pys   file_dispatchers   	(    s   __doc__s
   exceptionss   selects   sockets   strings   syss   oss   names   EWOULDBLOCKs   EINPROGRESSs   EALREADYs
   ECONNRESETs   ENOTCONNs	   ESHUTDOWNs   errnos
   socket_maps	   NameErrors	   Exceptions   ExitNows   DEBUGs   Nones   polls   poll2s   loops
   dispatchers   dispatcher_with_sends   compact_tracebacks	   close_alls   fcntls   FCNTLs   file_wrappers   file_dispatcher(    s%   /mit/python/lib/python2.0/asyncore.pys   ?/ sB   					.	( 