mò %U²Ic@s›dZdkZdkZdkZdkZdkZdkZdklZl Z l Z l Z l Z l Z lZlZlZyeWnej o hZnXdeifd„ƒYZd„Zd„Zd„Zd„Zd dd „Zd dd „ZeZd eddd „Zdfd„ƒYZdefd„ƒYZ d„Z!dd„Z"ei#djo6dk$Z$dfd„ƒYZ%defd„ƒYZ&ndS(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. N( sEALREADYs EINPROGRESSs EWOULDBLOCKs ECONNRESETsENOTCONNs ESHUTDOWNsEINTRsEISCONNs errorcodetExitNowcBstZRS(N(t__name__t __module__(((t%/data/zmath/lib/python2.4/asyncore.pyR@scCs;y|iƒWn&tj o ‚n|iƒnXdS(N(tobjthandle_read_eventRt handle_error(R((RtreadCs cCs;y|iƒWn&tj o ‚n|iƒnXdS(N(Rthandle_write_eventRR(R((RtwriteKs cCs;y|iƒWn&tj o ‚n|iƒnXdS(N(Rthandle_expt_eventRR(R((Rt _exceptionSs cCsšym|titiB@o|iƒn|ti@o|iƒn|titi Bti B@o|i ƒnWn&t j o ‚n|i ƒnXdS(N(tflagstselecttPOLLINtPOLLPRIRRtPOLLOUTRtPOLLERRtPOLLHUPtPOLLNVALR RR(RR ((Rt readwrite[sf0.0c Cs |djo t}n|oëg}g}g}x|iƒD]s\}} | i ƒ}| i ƒ}|o|i |ƒn|o|i |ƒn|p|o|i |ƒq=q=Wg|jo|jo |jnoti|ƒn]y%ti||||ƒ\}}}Wn4tij o%}|dtjo‚qKdSnXx;|D]3}|i|ƒ} | djoqRnt| ƒqRWx;|D]3}|i|ƒ} | djoqnt| ƒqWx?|D]3}|i|ƒ} | djoqÎnt| ƒqÎWndS(Ni(tmaptNonet socket_maptrtwtetitemstfdRtreadabletis_rtwritabletis_wtappendttimetsleepttimeoutR terrorterrtEINTRtgetRR R ( R$RRRR R&RRRR((RtpollhsP     *%    cCs‚|djo t}n|dj ot|dƒ}ntiƒ}|o3x™|iƒD]‹\}}d}|i ƒo|ti tiBO}n|iƒo|tiO}n|o/|titiBtiBO}|i||ƒqXqXWy|i|ƒ}Wn6tij o'}|dtjo‚ng}nXxH|D]<\}}|i|ƒ}|djoq:nt||ƒq:WndS(Nièi(RRRR$tintR R)tpollsterRRRR RRRRRRRRtregisterRR%R&R'R(R(R$RRR&R+RRR ((Rtpoll2“s8          f30.0cCs¢|djo t}n|ottdƒo t}nt}|djo xP|o|||ƒqNWn4x0|o(|djo|||ƒ|d}qnWdS(NR)ii( RRRtuse_pollthasattrR R-tpoll_funR)tcountR$(R$R.RR1R0((Rtloopµs     t dispatchercBs=tZeZeZeZeZdZddd„Z d„Z dd„Z dd„Z d„Z dd„Zd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zdd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%RS(NcCs|djo t|_n ||_|oY|i||ƒ|iidƒt |_ y|i ƒ|_ WqŒti j oqŒXn d|_dS(Ni(RRRtselft_maptsockt set_sockettsockett setblockingtTruet connectedt getpeernametaddrR%(R4R6R((Rt__init__Ïs     cCsÒ|iid|iig}|io|io|idƒn|io|idƒn|idj oHy|id|iƒWqµt j o|it |iƒƒqµXnddi |ƒt |ƒfS(Nt.t listeningR;s%s:%ds <%s at %#x>t (R4t __class__RRtstatust acceptingR=R!R;Rt TypeErrortreprtjointid(R4RC((Rt__repr__äs cCs+|djo |i}n|||is:uncaptured python exception, closing channel %s (%s:%s %s)R%( tcompact_tracebacktniltttvttbinfoRFR4t self_reprRHR€Ru(R4R‰R†RˆRŠR‡((RR“scCs|iddƒdS(Nsunhandled exceptiontwarning(R4R€(R4((RR„§scCs|iddƒdS(Nsunhandled read eventR‹(R4R€(R4((RR‚ªscCs|iddƒdS(Nsunhandled write eventR‹(R4R€(R4((RRƒ­scCs|iddƒdS(Nsunhandled connect eventR‹(R4R€(R4((RRe°scCs|iddƒdS(Nsunhandled accept eventR‹(R4R€(R4((RR³scCs|iddƒ|iƒdS(Nsunhandled close eventR‹(R4R€Ru(R4((RRq¶s(&RRR^tdebugR;RDtclosingRR=R>RIRKRMRRR7RWRRR\R]RgRhRkRoRuRxR}R€RRR RR„R‚RƒReRRq(((RR3ÇsD                      tdispatcher_with_sendcBs;tZddd„Zd„Zd„Zd„Zd„ZRS(NcCs ti|||ƒd|_dS(NRn(R3R>R4R6Rt out_buffer(R4R6R((RR>ÁscCs3d}ti||id ƒ}|i||_dS(Nii(tnum_sentR3RkR4R(R4R((Rt initiate_sendÅscCs|iƒdS(N(R4R‘(R4((RRƒÊscCs|i p t|iƒS(N(R4R;tlenR(R4((RRÍscCsC|io|idt|ƒƒn|i||_|iƒdS(Ns sending %s(R4RŒR€RFRlRR‘(R4Rl((RRkÐs (RRRR>R‘RƒRRk(((RRŽ¿s    c CsÁtiƒ\}}} g}xF| o>|i| iii | iii t | i ƒfƒ| i } qW~ |d\}}}dig}|D]}|d|q‹~ƒ}|||f|||fS(NiÿÿÿÿRAs [%s|%s|%s](Rytexc_infoR‡RˆttbR‰R!ttb_frametf_codet co_filenametco_nameR{t tb_linenottb_nexttfiletfunctiontlineRGt_[1]txR~( R‰RœR›R~RžR‡RˆRŸRR”((RR…Ús1.cCsI|djo t}nx!|iƒD]}|iiƒq$W|iƒdS(N(RRRtvaluesRŸR8Rutclear(RRŸ((Rt close_allís    tposixt file_wrappercBsAtZd„Zd„Zd„ZeZeZd„Zd„ZRS(NcCs ||_dS(N(RR4(R4R((RR>scGsti|i|ŒS(N(RYRR4Rtargs(R4R¥((RRo scGsti|i|ŒS(N(RYR R4RR¥(R4R¥((RRkscCsti|iƒdS(N(RYRuR4R(R4((RRuscCs|iS(N(R4R(R4((RRQs( RRR>RoRkRR RuRQ(((RR¤s    tfile_dispatchercBstZdd„Zd„ZRS(NcCshti|d|ƒt|_|i|ƒt i |t i dƒ}|t i B}t i |t i|ƒdS(Ni(R3R>R4RRR:R;tset_fileRtfcntltF_GETFLR RYt O_NONBLOCKtF_SETFL(R4RRR ((RR>s    cCs&||_t|ƒ|_|iƒdS(N(RR4RJR¤R8RK(R4R((RR§%s (RRRR>R§(((RR¦s ('t__doc__t exceptionsR R8RyR"RYterrnoRbRaRcRrRsRtR'RdRfRt NameErrort ExceptionRRR R RRR)R-tpoll3R^R2R3RŽR…R¢RZR¨R¤R¦( R R¤RŽRR…R)RRdRfRrRR-R±RaRcR R¨RsR¢RRyR¦R'R3RtR8R R"R­RbRYR2((Rt?/s8      =     + ø