Ñò
#8Zc           @   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 l Z l Z y e Wn e j
 o h  Z n Xd „  Z d e f d „  ƒ  YZ e e e f Z d „  Z d „  Z d	 „  Z d
 „  Z d e d „ Z d e d „ Z  e  Z! d e" e e d „ Z# d f  d „  ƒ  YZ$ d e$ f d „  ƒ  YZ% d „  Z& e e" d „ Z' e i( d j o9 d 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.
iÿÿÿÿN(   t   EALREADYt   EINPROGRESSt   EWOULDBLOCKt
   ECONNRESETt   ENOTCONNt	   ESHUTDOWNt   EINTRt   EISCONNt   EBADFt   ECONNABORTEDt	   errorcodec         C   sO   y t  i |  ƒ SWn7 t t t f j
 o" |  t j o	 t |  Sd |  SXd  S(   Ns   Unknown error %s(   t   ost   strerrort
   ValueErrort   OverflowErrort	   NameErrorR
   (   t   err(    (    s   /usr/lib/python2.6/asyncore.pyt	   _strerror?   s    	t   ExitNowc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.6/asyncore.pyR   G   s   c         C   s;   y |  i  ƒ  Wn& t j
 o
 ‚  n |  i ƒ  n Xd  S(   N(   t   handle_read_eventt   _reraised_exceptionst   handle_error(   t   obj(    (    s   /usr/lib/python2.6/asyncore.pyt   readL   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.6/asyncore.pyt   writeT   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.6/asyncore.pyt
   _exception\   s    c         C   s  y‚ | t  i @o |  i ƒ  n | t  i @o |  i ƒ  n | t  i @o |  i ƒ  n | t  i t  i Bt  i	 B@o |  i
 ƒ  n Wnx t i j
 oD } | i d t t t t t f j o |  i ƒ  qý |  i
 ƒ  n' t j
 o
 ‚  n |  i ƒ  n Xd  S(   Ni    (   t   selectt   POLLINR   t   POLLOUTR   t   POLLPRIR   t   POLLHUPt   POLLERRt   POLLNVALt   handle_closet   sockett   errort   argsR   R   R   R   R	   R   R   (   R   t   flagst   e(    (    s   /usr/lib/python2.6/asyncore.pyt	   readwrited   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 |  ƒ d  Sy% t i | | | |  ƒ \ } } } Wn7 t i	 j
 o( }	 |	 i
 d t j o ‚  qOd  Sn Xx; | D]3 } | i | ƒ } | d  j o qVn t | ƒ qV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   R'   R(   R   t   getR   R   R   (
   t   timeoutt   mapt   rt   wR*   t   fdR   t   is_rt   is_wR   (    (    s   /usr/lib/python2.6/asyncore.pyt   polly   sV    
   *%	   c      	   C   s…  | d  j o
 t } n |  d  j	 o t |  d ƒ }  n t i ƒ  } | o6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 |  ƒ } Wn9 t i j
 o* } | i 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   R<   R.   R/   R   R!   R0   R    R#   R"   R$   t   registerR'   R(   R   R4   R+   (   R5   R6   t   pollsterR9   R   R)   R7   R   (    (    s   /usr/lib/python2.6/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(   NR<   i    i   (   R,   R-   t   hasattrR   R@   R<   (   R5   t   use_pollR6   t   countt   poll_fun(    (    s   /usr/lib/python2.6/asyncore.pyt   loopÇ   s    

  t
   dispatcherc           B   sU  e  Z e Z e Z e Z e Z d  Z e	 d  g ƒ 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' d „  Z( RS(!   t   warningc         C   sÉ   | d  j o t |  _ n
 | |  _ d  |  _ | o‰ | i d ƒ |  i | | ƒ t |  _ y | i ƒ  |  _	 WqÅ t
 i j
 o: } | i d t j o t |  _ q¸ |  i | ƒ ‚  qÅ Xn
 d  |  _
 d  S(   Ni    (   R,   R-   t   _mapt   _filenot   setblockingt
   set_sockett   Truet	   connectedt   getpeernamet   addrR&   R'   R(   R   t   Falset   del_channel(   t   selft   sockR6   R   (    (    s   /usr/lib/python2.6/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	   listeningRM   s   %s:%ds   <%s at %#x>t    (   t	   __class__R   R   t	   acceptingRO   R1   RM   R,   t	   TypeErrort   reprt   joint   id(   RR   t   status(    (    s   /usr/lib/python2.6/asyncore.pyt   __repr__  s    
c         C   s+   | d  j o |  i } n |  | |  i <d  S(   N(   R,   RH   RI   (   RR   R6   (    (    s   /usr/lib/python2.6/asyncore.pyt   add_channel  s    c         C   sH   |  i  } | d  j o |  i } n | | j o | | =n d  |  _  d  S(   N(   RI   R,   RH   (   RR   R6   R9   (    (    s   /usr/lib/python2.6/asyncore.pyRQ     s    	c         C   s?   | | f |  _  t i | | ƒ } | i d ƒ |  i | ƒ d  S(   Ni    (   t   family_and_typeR&   RJ   RK   (   RR   t   familyt   typeRS   (    (    s   /usr/lib/python2.6/asyncore.pyt   create_socket  s    c         C   s)   | |  _  | i ƒ  |  _ |  i | ƒ d  S(   N(   R&   t   filenoRI   R`   (   RR   RS   R6   (    (    s   /usr/lib/python2.6/asyncore.pyRK   $  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'   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyt   set_reuse_addr*  s    	c         C   s   t  S(   N(   RL   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR/   ;  s    c         C   s   t  S(   N(   RL   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR0   >  s    c         C   s@   t  |  _ t i d j o | d j o
 d } n |  i i | ƒ S(   Nt   nti   (   RL   RY   R   t   nameR&   t   listen(   RR   t   num(    (    s   /usr/lib/python2.6/asyncore.pyRm   E  s    	
c         C   s   | |  _  |  i i | ƒ S(   N(   RO   R&   t   bind(   RR   RO   (    (    s   /usr/lib/python2.6/asyncore.pyRo   K  s    	c         C   sz   t  |  _ |  i i | ƒ } | t t t f j o d  S| d t f j o | |  _ |  i	 ƒ  n t i
 | t | ƒ ‚ d  S(   Ni    (   RP   RM   R&   t
   connect_exR   R    R   R   RO   t   handle_connect_eventR'   R
   (   RR   t   addressR   (    (    s   /usr/lib/python2.6/asyncore.pyt   connectO  s    		c         C   s]   y# |  i  i ƒ  \ } } | | f SWn3 t  i j
 o$ } | i d t j o qY ‚  n Xd  S(   Ni    (   R&   t   acceptR'   R(   R   (   RR   t   connRO   t   why(    (    s   /usr/lib/python2.6/asyncore.pyRt   [  s    c         C   s„   y |  i  i | ƒ } | SWnc t  i j
 oT } | i d t j o d S| i d t t t t f j o |  i	 ƒ  d S‚  n Xd  S(   Ni    (
   R&   t   sendR'   R(   R   R   R   R   R	   R%   (   RR   t   datat   resultRv   (    (    s   /usr/lib/python2.6/asyncore.pyRw   f  s     
c         C   s   y0 |  i  i | ƒ } | p |  i ƒ  d S| SWnJ t  i j
 o; } | i d t t t t g j o |  i ƒ  d S‚  n Xd  S(   Nt    i    (	   R&   t   recvR%   R'   R(   R   R   R   R	   (   RR   t   buffer_sizeRx   Rv   (    (    s   /usr/lib/python2.6/asyncore.pyR{   s  s    
 
c         C   sm   t  |  _ t  |  _ |  i ƒ  y |  i i ƒ  Wn9 t i j
 o* } | i d t t	 f j o ‚  qi n Xd  S(   Ni    (
   RP   RM   RY   RQ   R&   t   closeR'   R(   R   R   (   RR   Rv   (    (    s   /usr/lib/python2.6/asyncore.pyR}   …  s    		
c         C   sJ   y t  |  i | ƒ SWn/ t j
 o# t d |  i i | f ƒ ‚ n Xd  S(   Ns!   %s instance has no attribute '%s'(   t   getattrR&   t   AttributeErrorRX   R   (   RR   t   attr(    (    s   /usr/lib/python2.6/asyncore.pyt   __getattr__‘  s
    c         C   s   t  i i d t | ƒ ƒ d  S(   Ns   log: %s
(   t   syst   stderrR   t   str(   RR   t   message(    (    s   /usr/lib/python2.6/asyncore.pyt   logœ  s    t   infoc         C   s'   | |  i  j o d | | f GHn d  S(   Ns   %s: %s(   t   ignore_log_types(   RR   R…   Rc   (    (    s   /usr/lib/python2.6/asyncore.pyt   log_infoŸ  s    c         C   sH   |  i  o |  i ƒ  n- |  i p |  i ƒ  |  i ƒ  n |  i ƒ  d  S(   N(   RY   t   handle_acceptRM   Rq   t   handle_read(   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR   £  s    


c         C   s   |  i  ƒ  t |  _ d  S(   N(   t   handle_connectRL   RM   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyRq   ®  s    
c         C   sy   |  i  o d  S|  i pR |  i i t i t i ƒ } | d j o t i | t | ƒ ƒ ‚ n |  i ƒ  n |  i	 ƒ  d  S(   Ni    (
   RY   RM   R&   Ri   Rg   t   SO_ERRORR'   R   Rq   t   handle_write(   RR   R   (    (    s   /usr/lib/python2.6/asyncore.pyR   ²  s    

c         C   sD   |  i  i t  i t  i ƒ } | d j o |  i ƒ  n |  i ƒ  d  S(   Ni    (   R&   Ri   Rg   R   R%   t   handle_expt(   RR   R   (    (    s   /usr/lib/python2.6/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_tracebackR[   R]   R‰   R%   (   RR   t   nilt   tt   vt   tbinfot	   self_repr(    (    s   /usr/lib/python2.6/asyncore.pyR   Ð  s    c         C   s   |  i  d d ƒ d  S(   Ns!   unhandled incoming priority eventRG   (   R‰   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR   ä  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled read eventRG   (   R‰   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR‹   ç  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled write eventRG   (   R‰   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyRŽ   ê  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled connect eventRG   (   R‰   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyRŒ   í  s    c         C   s   |  i  d d ƒ d  S(   Ns   unhandled accept eventRG   (   R‰   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyRŠ   ð  s    c         C   s   |  i  d d ƒ |  i ƒ  d  S(   Ns   unhandled close eventRG   (   R‰   R}   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR%   ó  s    N()   R   R   RP   t   debugRM   RY   t   closingR,   RO   t	   frozensetRˆ   RT   R_   R`   RQ   Rd   RK   Rj   R/   R0   Rm   Ro   Rs   Rt   Rw   R{   R}   R   R†   R‰   R   Rq   R   R   R   R   R‹   RŽ   RŒ   RŠ   R%   (    (    (    s   /usr/lib/python2.6/asyncore.pyRF   Ù   sH    																									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(   NRz   (   RF   RT   t
   out_buffer(   RR   RS   R6   (    (    s   /usr/lib/python2.6/asyncore.pyRT   þ  s    c         C   s3   d } t  i |  |  i d  ƒ } |  i | |  _ d  S(   Ni    i   (   RF   Rw   Rš   (   RR   t   num_sent(    (    s   /usr/lib/python2.6/asyncore.pyt   initiate_send  s    c         C   s   |  i  ƒ  d  S(   N(   Rœ   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyRŽ     s    c         C   s   |  i  p t |  i ƒ S(   N(   RM   t   lenRš   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR0   
  s    c         C   sC   |  i  o |  i d t | ƒ ƒ n |  i | |  _ |  i ƒ  d  S(   Ns
   sending %s(   R–   R‰   R[   Rš   Rœ   (   RR   Rx   (    (    s   /usr/lib/python2.6/asyncore.pyRw     s    
N(   R   R   R,   RT   Rœ   RŽ   R0   Rw   (    (    (    s   /usr/lib/python2.6/asyncore.pyR™   ü  s
   			c    
      C   sØ   t  i ƒ  \ }  } } g  } | p t d ƒ ‚ n xF | o> | i | i i i | i i i t | i	 ƒ f ƒ | i
 } q5 W~ | d \ } } } d i g  } | D] } | d | q¢ ~ ƒ }	 | | | f |  | |	 f S(   Ns   traceback does not existiÿÿÿÿRW   s
   [%s|%s|%s](   R‚   t   exc_infot   AssertionErrorR1   t   tb_framet   f_codet   co_filenamet   co_nameR„   t	   tb_linenot   tb_nextR\   (
   R’   R“   t   tbR”   t   filet   functiont   linet   _[1]t   xR‡   (    (    s   /usr/lib/python2.6/asyncore.pyR     s     .c         C   s±   |  d  j o
 t }  n x‰ |  i ƒ  D]{ } y | i ƒ  Wq$ t j
 o/ } | i d t j o qŸ | p ‚  qŸ q$ t j
 o
 ‚  q$ | p ‚  qŸ q$ Xq$ W|  i ƒ  d  S(   Ni    (	   R,   R-   t   valuesR}   t   OSErrorR(   R   R   t   clear(   R6   t
   ignore_allR«   (    (    s   /usr/lib/python2.6/asyncore.pyt	   close_all+  s"    
 t   posixt   file_wrapperc           B   sM   e  Z d  „  Z d „  Z d „  Z d d „ Z e Z e Z d „  Z	 d „  Z
 RS(   c         C   s   t  i | ƒ |  _ d  S(   N(   R   t   dupR9   (   RR   R9   (    (    s   /usr/lib/python2.6/asyncore.pyRT   R  s    c         G   s   t  i |  i | Œ S(   N(   R   R   R9   (   RR   R(   (    (    s   /usr/lib/python2.6/asyncore.pyR{   U  s    c         G   s   t  i |  i | Œ S(   N(   R   R   R9   (   RR   R(   (    (    s   /usr/lib/python2.6/asyncore.pyRw   X  s    c         C   s=   | t  i j o | t  i j o | o d St d ƒ ‚ d  S(   Ni    s-   Only asyncore specific behaviour implemented.(   R&   Rg   R   t   NotImplementedError(   RR   t   levelt   optnamet   buflen(    (    s   /usr/lib/python2.6/asyncore.pyRi   [  s
    c         C   s   t  i |  i ƒ d  S(   N(   R   R}   R9   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyR}   f  s    c         C   s   |  i  S(   N(   R9   (   RR   (    (    s   /usr/lib/python2.6/asyncore.pyRe   i  s    N(   R   R   RT   R{   Rw   R,   Ri   R   R   R}   Re   (    (    (    s   /usr/lib/python2.6/asyncore.pyR²   M  s   				t   file_dispatcherc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   sŽ   t  i |  d  | ƒ t |  _ y | i ƒ  } Wn t j
 o n X|  i | ƒ t i | t i	 d ƒ } | t
 i B} t i | t i | ƒ d  S(   Ni    (   RF   RT   R,   RL   RM   Re   R   t   set_filet   fcntlt   F_GETFLR   t
   O_NONBLOCKt   F_SETFL(   RR   R9   R6   R)   (    (    s   /usr/lib/python2.6/asyncore.pyRT   n  s    	c         C   s/   t  | ƒ |  _ |  i i ƒ  |  _ |  i ƒ  d  S(   N(   R²   R&   Re   RI   R`   (   RR   R9   (    (    s   /usr/lib/python2.6/asyncore.pyR¹   {  s    N(   R   R   R,   RT   R¹   (    (    (    s   /usr/lib/python2.6/asyncore.pyR¸   l  s   (,   t   __doc__R   R&   R‚   R2   R   t   errnoR    R   R   R   R   R   R   R   R   R	   R
   R-   R   R   t	   ExceptionR   t   KeyboardInterruptt
   SystemExitR   R   R   R   R+   R,   R<   R@   t   poll3RP   RE   RF   R™   R   R°   Rl   Rº   R²   R¸   (    (    (    s   /usr/lib/python2.6/asyncore.pyt   <module>/   s<   L					, ÿ $	