³ò
˜›\Kc           @   s¤  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z l Z l	 Z	 l
 Z
 l Z l Z l Z l Z l Z y e Wn e j
 o h  Z n Xd e f d „  ƒ  YZ d „  Z d „  Z d „  Z d	 „  Z d
 d d „ Z d
 d d „ Z e Z d e d d d „ Z d d d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z  d d „ Z! e i" d j o9 d d k# Z# d d 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.
iÿÿÿÿN(	   t   EALREADYt   EINPROGRESSt   EWOULDBLOCKt
   ECONNRESETt   ENOTCONNt	   ESHUTDOWNt   EINTRt   EISCONNt	   errorcodet   ExitNowc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.5/asyncore.pyR	   ?   s   c         C   s;   y |  i  ƒ  Wn& t j
 o
 ‚  n |  i ƒ  n Xd  S(   N(   t   handle_read_eventR	   t   handle_error(   t   obj(    (    s   /usr/lib/python2.5/asyncore.pyt   readB   s    c         C   s;   y |  i  ƒ  Wn& t j
 o
 ‚  n |  i ƒ  n Xd  S(   N(   t   handle_write_eventR	   R   (   R   (    (    s   /usr/lib/python2.5/asyncore.pyt   writeJ   s    c         C   s;   y |  i  ƒ  Wn& t j
 o
 ‚  n |  i ƒ  n Xd  S(   N(   t   handle_expt_eventR	   R   (   R   (    (    s   /usr/lib/python2.5/asyncore.pyt
   _exceptionR   s    c         C   sš   ym | t  i t  i B@o |  i ƒ  n | t  i @o |  i ƒ  n | t  i t  i Bt  i B@o |  i	 ƒ  n Wn& t
 j
 o
 ‚  n |  i ƒ  n Xd  S(   N(   t   selectt   POLLINt   POLLPRIR   t   POLLOUTR   t   POLLERRt   POLLHUPt   POLLNVALR   R	   R   (   R   t   flags(    (    s   /usr/lib/python2.5/asyncore.pyt	   readwriteZ   s    g        c   
      C   s  | d  j o
 t } n | oëg  } g  } g  } x | i ƒ  D]s \ } } | i ƒ  } | i ƒ  } | o | i | ƒ n | o | i | ƒ n | p | o | i | ƒ q= q= Wg  | j o | j o
 | j n o t i |  ƒ n] y% t i | | | |  ƒ \ } } } Wn4 t i	 j
 o% }	 |	 d t
 j o ‚  qKd  Sn Xx; | D]3 } | i | ƒ } | d  j o qRn t | ƒ qRWx; | D]3 } | i | ƒ } | d  j o qn t | ƒ qWx? | D]3 } | i | ƒ } | d  j o qÎn t | ƒ qÎWn d  S(   Ni    (   t   Nonet
   socket_mapt   itemst   readablet   writablet   appendt   timet   sleepR   t   errorR   t   getR   R   R   (
   t   timeoutt   mapt   rt   wt   et   fdR   t   is_rt   is_wt   err(    (    s   /usr/lib/python2.5/asyncore.pyt   pollg   sT    
   *%	   c      	   C   s‚  | d  j o
 t } n |  d  j	 o t |  d ƒ }  n t i ƒ  } | o3x™ | i ƒ  D]‹ \ } } d } | i ƒ  o | t i t i BO} n | i	 ƒ  o | t i
 O} n | o/ | t i t i Bt i BO} | i | | ƒ qX qX Wy | i |  ƒ } Wn6 t i j
 o' } | d t j o ‚  n g  } n XxH | D]< \ } } | i | ƒ } | d  j o q:n t | | ƒ q:Wn d  S(   Niè  i    (   R   R   t   intR   R0   R   R    R   R   R!   R   R   R   R   t   registerR%   R   R&   R   (   R'   R(   t   pollsterR,   R   R   R)   R/   (    (    s   /usr/lib/python2.5/asyncore.pyt   poll2’   s8    
  g      >@c         C   s¢   | d  j o
 t } n | o t t d ƒ o
 t } n t } | d  j o  xP | o | |  | ƒ qN Wn4 x0 | o( | d j o | |  | ƒ | d } qn Wd  S(   NR0   i    i   (   R   R   t   hasattrR   R4   R0   (   R'   t   use_pollR(   t   countt   poll_fun(    (    s   /usr/lib/python2.5/asyncore.pyt   loop´   s    

  t
   dispatcherc           B   s=  e  Z e Z e Z e Z e Z d Z d d d  „ Z	 d „  Z
 d d „ Z d d „ Z d „  Z d 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 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% RS(   c         C   s   | d  j o t |  _ n
 | |  _ | oY |  i | | ƒ |  i i d ƒ t |  _ y | i ƒ  |  _	 WqŒ t i
 j
 o qŒ Xn
 d  |  _ d  S(   Ni    (   R   R   t   _mapt
   set_sockett   sockett   setblockingt   Truet	   connectedt   getpeernamet   addrR%   (   t   selft   sockR(   (    (    s   /usr/lib/python2.5/asyncore.pyt   __init__Î   s    			c         C   sÒ   |  i  i d |  i  i g } |  i o |  i o | i d ƒ n |  i o | i d ƒ n |  i d  j	 oH y | i d |  i ƒ Wqµ t j
 o | i t	 |  i ƒ ƒ qµ Xn d d i
 | ƒ t |  ƒ f S(   Nt   .t	   listeningR@   s   %s:%ds   <%s at %#x>t    (   t	   __class__R   R
   t	   acceptingRB   R"   R@   R   t	   TypeErrort   reprt   joint   id(   RC   t   status(    (    s   /usr/lib/python2.5/asyncore.pyt   __repr__ã   s    
c         C   s+   | d  j o |  i } n |  | |  i <d  S(   N(   R   R;   t   _fileno(   RC   R(   (    (    s   /usr/lib/python2.5/asyncore.pyt   add_channelð   s    c         C   sK   |  i  } | d  j o |  i } n | i | ƒ o | | =n d  |  _  d  S(   N(   RQ   R   R;   t   has_key(   RC   R(   R,   (    (    s   /usr/lib/python2.5/asyncore.pyt   del_channelö   s    	c         C   sT   | | f |  _  t i | | ƒ |  _ |  i i d ƒ |  i i ƒ  |  _ |  i ƒ  d  S(   Ni    (   t   family_and_typeR=   R>   t   filenoRQ   RR   (   RC   t   familyt   type(    (    s   /usr/lib/python2.5/asyncore.pyt   create_socketÿ   s
    c         C   s)   | |  _  | i ƒ  |  _ |  i | ƒ d  S(   N(   R=   RV   RQ   RR   (   RC   RD   R(   (    (    s   /usr/lib/python2.5/asyncore.pyR<     s    	c      	   C   sV   y9 |  i  i t  i t  i |  i  i t  i t  i ƒ d Bƒ Wn t  i j
 o n Xd  S(   Ni   (   R=   t
   setsockoptt
   SOL_SOCKETt   SO_REUSEADDRt
   getsockoptR%   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyt   set_reuse_addr  s    	c         C   s   t  S(   N(   R?   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR      s    c         C   s   t  S(   N(   R?   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR!      s    c         C   s@   t  |  _ t i d j o | d j o
 d } n |  i i | ƒ S(   Nt   nti   i   (   R?   RJ   t   ost   nameR=   t   listen(   RC   t   num(    (    s   /usr/lib/python2.5/asyncore.pyRb   '  s    	
c         C   s   | |  _  |  i i | ƒ S(   N(   RB   R=   t   bind(   RC   RB   (    (    s   /usr/lib/python2.5/asyncore.pyRd   -  s    	c         C   s†   t  |  _ |  i i | ƒ } | t t t f j o d  Sn | d t f j o  | |  _ t	 |  _ |  i
 ƒ  n t i | t | f ‚ d  S(   Ni    (   t   FalseR@   R=   t
   connect_exR   R    R   R   RB   R?   t   handle_connectR%   R   (   RC   t   addressR/   (    (    s   /usr/lib/python2.5/asyncore.pyt   connect1  s    			c         C   sZ   y# |  i  i ƒ  \ } } | | f SWn0 t  i j
 o! } | d t j o qV ‚  n Xd  S(   Ni    (   R=   t   acceptR%   R   (   RC   t   connRB   t   why(    (    s   /usr/lib/python2.5/asyncore.pyRj   >  s    c         C   sY   y |  i  i | ƒ } | SWn8 t  i j
 o) } | d t j o d Sn ‚  d Sn Xd  S(   Ni    (   R=   t   sendR%   R   (   RC   t   datat   resultRl   (    (    s   /usr/lib/python2.5/asyncore.pyRm   I  s    c         C   s   y3 |  i  i | ƒ } | p |  i ƒ  d Sn | SWnG t  i j
 o8 } | d t t t g j o |  i ƒ  d Sq} ‚  n Xd  S(   Nt    i    (   R=   t   recvt   handle_closeR%   R   R   R   (   RC   t   buffer_sizeRn   Rl   (    (    s   /usr/lib/python2.5/asyncore.pyRq   T  s    

c         C   s   |  i  ƒ  |  i i ƒ  d  S(   N(   RT   R=   t   close(   RC   (    (    s   /usr/lib/python2.5/asyncore.pyRt   f  s    
c         C   s   t  |  i | ƒ S(   N(   t   getattrR=   (   RC   t   attr(    (    s   /usr/lib/python2.5/asyncore.pyt   __getattr__l  s    c         C   s   t  i i d t | ƒ ƒ d  S(   Ns   log: %s
(   t   syst   stderrR   t   str(   RC   t   message(    (    s   /usr/lib/python2.5/asyncore.pyt   logs  s    t   infoc         C   s+   t  p | d j o d | | f GHn d  S(   NR}   s   %s: %s(   t	   __debug__(   RC   R{   RX   (    (    s   /usr/lib/python2.5/asyncore.pyt   log_infov  s    c         C   sh   |  i  o% |  i p t |  _ n |  i ƒ  n6 |  i p! |  i ƒ  t |  _ |  i ƒ  n |  i ƒ  d  S(   N(   RJ   R@   R?   t   handle_acceptRg   t   handle_read(   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR   z  s    



	c         C   s/   |  i  p |  i ƒ  t |  _  n |  i ƒ  d  S(   N(   R@   Rg   R?   t   handle_write(   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR   ˆ  s    

c         C   s   |  i  ƒ  d  S(   N(   t   handle_expt(   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR     s    c      	   C   sm   t  ƒ  \ } } } } y t |  ƒ } Wn d t |  ƒ } n X|  i d | | | | f d ƒ |  i ƒ  d  S(   Ns)   <__repr__(self) failed for object at %0x>s:   uncaptured python exception, closing channel %s (%s:%s %s)R%   (   t   compact_tracebackRL   RN   R   Rt   (   RC   t   nilt   tt   vt   tbinfot	   self_repr(    (    s   /usr/lib/python2.5/asyncore.pyR   ’  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled exceptiont   warning(   R   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyRƒ   ¦  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled read eventRŠ   (   R   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR   ©  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled write eventRŠ   (   R   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR‚   ¬  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled connect eventRŠ   (   R   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyRg   ¯  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled accept eventRŠ   (   R   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR€   ²  s    c         C   s   |  i  d d ƒ |  i ƒ  d  S(   Ns   unhandled close eventRŠ   (   R   Rt   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyRr   µ  s    N(&   R
   R   Re   t   debugR@   RJ   t   closingR   RB   RE   RP   RR   RT   RY   R<   R^   R    R!   Rb   Rd   Ri   Rj   Rm   Rq   Rt   Rw   R|   R   R   R   R   R   Rƒ   R   R‚   Rg   R€   Rr   (    (    (    s   /usr/lib/python2.5/asyncore.pyR:   Æ   sD   																								t   dispatcher_with_sendc           B   s;   e  Z d d d  „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s    t  i |  | | ƒ d |  _ d  S(   NRp   (   R:   RE   t
   out_buffer(   RC   RD   R(   (    (    s   /usr/lib/python2.5/asyncore.pyRE   À  s    c         C   s3   d } t  i |  |  i d  ƒ } |  i | |  _ d  S(   Ni    i   (   R:   Rm   RŽ   (   RC   t   num_sent(    (    s   /usr/lib/python2.5/asyncore.pyt   initiate_sendÄ  s    c         C   s   |  i  ƒ  d  S(   N(   R   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR‚   É  s    c         C   s   |  i  p t |  i ƒ S(   N(   R@   t   lenRŽ   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyR!   Ì  s    c         C   sC   |  i  o |  i d t | ƒ ƒ n |  i | |  _ |  i ƒ  d  S(   Ns
   sending %s(   R‹   R   RL   RŽ   R   (   RC   Rn   (    (    s   /usr/lib/python2.5/asyncore.pyRm   Ï  s    
N(   R
   R   R   RE   R   R‚   R!   Rm   (    (    (    s   /usr/lib/python2.5/asyncore.pyR   ¾  s
   			c    
      C   sÏ   t  i ƒ  \ }  } } g  } | p t ‚ xF | o> | i | i i i | i i i t | i	 ƒ f ƒ | i
 } q, W~ | d \ } } } d i g  } | D] } | d | q™ ~ ƒ }	 | | | f |  | |	 f S(   NiÿÿÿÿRH   s
   [%s|%s|%s](   Rx   t   exc_infot   AssertionErrorR"   t   tb_framet   f_codet   co_filenamet   co_nameRz   t	   tb_linenot   tb_nextRM   (
   R†   R‡   t   tbRˆ   t   filet   functiont   linet   _[1]t   xR}   (    (    s   /usr/lib/python2.5/asyncore.pyR„   Ù  s     .c         C   sI   |  d  j o
 t }  n x! |  i ƒ  D] } | i i ƒ  q$ W|  i ƒ  d  S(   N(   R   R   t   valuesR=   Rt   t   clear(   R(   RŸ   (    (    s   /usr/lib/python2.5/asyncore.pyt	   close_allì  s    
 t   posixt   file_wrapperc           B   sA   e  Z d  „  Z d „  Z d „  Z e Z e Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R,   (   RC   R,   (    (    s   /usr/lib/python2.5/asyncore.pyRE     s    c         G   s   t  i |  i | Œ S(   N(   R`   R   R,   (   RC   t   args(    (    s   /usr/lib/python2.5/asyncore.pyRq   
  s    c         G   s   t  i |  i | Œ S(   N(   R`   R   R,   (   RC   R¥   (    (    s   /usr/lib/python2.5/asyncore.pyRm     s    c         C   s   t  i |  i ƒ d  S(   N(   R`   Rt   R,   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyRt     s    c         C   s   |  i  S(   N(   R,   (   RC   (    (    s   /usr/lib/python2.5/asyncore.pyRV     s    (	   R
   R   RE   Rq   Rm   R   R   Rt   RV   (    (    (    s   /usr/lib/python2.5/asyncore.pyR¤     s   				t   file_dispatcherc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   sh   t  i |  d  | ƒ t |  _ |  i | ƒ t i | t i d ƒ } | t i	 B} t i | t i
 | ƒ d  S(   Ni    (   R:   RE   R   R?   R@   t   set_filet   fcntlt   F_GETFLR`   t
   O_NONBLOCKt   F_SETFL(   RC   R,   R(   R   (    (    s   /usr/lib/python2.5/asyncore.pyRE     s    	c         C   s&   | |  _  t | ƒ |  _ |  i ƒ  d  S(   N(   RQ   R¤   R=   RR   (   RC   R,   (    (    s   /usr/lib/python2.5/asyncore.pyR§   $  s    	N(   R
   R   R   RE   R§   (    (    (    s   /usr/lib/python2.5/asyncore.pyR¦     s   	(    (    (&   t   __doc__R   R=   Rx   R#   R`   t   errnoR    R   R   R   R   R   R   R   R   R   t	   NameErrort	   ExceptionR	   R   R   R   R   R   R0   R4   t   poll3Re   R9   R:   R   R„   R¢   Ra   R¨   R¤   R¦   (    (    (    s   /usr/lib/python2.5/asyncore.pys   <module>/   s6   @				+ ø	