JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbrў fQc@sdZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZee e eeeefZyeWnek riZYnXddZGdddeZeeefZdd Zd d Z d d Z!ddZ"de#ddZ$de#ddZ%e%Z&de'e#e#ddZ(GdddZ)Gddde)Z*ddZ+e#e'ddZ,ej-d krddl.Z.Gd!d"d"Z/Gd#d$d$e)Z0ndS(%uBasic 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. iN( uEALREADYu EINPROGRESSu EWOULDBLOCKu ECONNRESETuEINVALuENOTCONNu ESHUTDOWNuEISCONNuEBADFu ECONNABORTEDuEPIPEuEAGAINu errorcodec CsOytj|SWn7tttfk rJ|tkr>t|Sd|SYnXdS(NuUnknown error %s(uosustrerroru ValueErroru OverflowErroru NameErroru errorcode(uerr((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu _strerrorDs  u _strerrorcBs|EeZdZdS(uExitNowN(u__name__u __module__u __qualname__(u __locals__((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuExitNowLsuExitNowc Cs;y|jWn&tk r%Yn|jYnXdS(N(uhandle_read_eventu_reraised_exceptionsu handle_error(uobj((u-/opt/alt/python33/lib64/python3.3/asyncore.pyureadQs  ureadc Cs;y|jWn&tk r%Yn|jYnXdS(N(uhandle_write_eventu_reraised_exceptionsu handle_error(uobj((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuwriteYs  uwritec Cs;y|jWn&tk r%Yn|jYnXdS(N(uhandle_expt_eventu_reraised_exceptionsu handle_error(uobj((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu _exceptionas  u _exceptioncCsyz|tj@r|jn|tj@r7|jn|tj@rQ|jn|tjtjBtj B@ry|j nWnwt j k r}z/|j dtkr|jn |j WYdd}~Xn&tk rYn|jYnXdS(Ni(uselectuPOLLINuhandle_read_eventuPOLLOUTuhandle_write_eventuPOLLPRIuhandle_expt_eventuPOLLHUPuPOLLERRuPOLLNVALu handle_closeusocketuerroruargsu _DISCONNECTEDu handle_erroru_reraised_exceptions(uobjuflagsue((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu readwriteis"        u readwritegc Cs|dkrt}n|rg}g}g}xt|jD]v\}}|j}|j}|rz|j|n|r|j r|j|n|s|r@|j|q@q@Wg|ko|ko|knrtj |dSy%t j ||||\}}}Wnt k r/dSYnXx9|D]1}|j |}|dkr^q7nt |q7Wx9|D]1}|j |}|dkrqsnt|qsWx<|D]1}|j |}|dkrqnt|qWndS(N(uNoneu socket_mapulistuitemsureadableuwritableuappendu acceptingutimeusleepuselectuInterruptedErrorugetureaduwriteu _exception( utimeoutumapuruwueufduobjuis_ruis_w((u-/opt/alt/python33/lib64/python3.3/asyncore.pyupoll}sJ     ' %        upollc CsK|dkrt}n|dk r4t|d}ntj}|rGxt|jD]t\}}d}|jr|tjtj BO}n|j r|j r|tj O}n|rY|j ||qYqYWy|j|}Wntk rg}YnXxE|D]:\}}|j|}|dkr3qnt||qWndS(Nii(uNoneu socket_mapuintuselectupollulistuitemsureadableuPOLLINuPOLLPRIuwritableu acceptinguPOLLOUTuregisteruInterruptedErrorugetu readwrite(utimeoutumapupollsterufduobjuflagsur((u-/opt/alt/python33/lib64/python3.3/asyncore.pyupoll2s.        upoll2g>@cCs|dkrt}n|r3ttdr3t}nt}|dkrbxJ|r^|||qHWn0x-|r|dkr||||d}qeWdS(Nupollii(uNoneu socket_mapuhasattruselectupoll2upoll(utimeoutuuse_pollumapucountupoll_fun((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuloops      uloopcBs|EeZdZdBZdBZdBZdBZdBZdAZ e dgZ dAdAddZ ddZeZdAddZdAdd Zejejd d ZdAd d ZddZddZddZddZddZddZddZddZddZd d!Z d"d#Z!d$d%Z"d&d'd(Z#d)d*Z$d+d,Z%d-d.Z&d/d0Z'd1d2Z(d3d4Z)d5d6Z*d7d8Z+d9d:Z,d;d<Z-d=d>Z.d?d@Z/dAS(Cu dispatcheruwarningcCs|dkrt|_n ||_d|_|r|jd|j||d|_y|j|_ Wqt j k r}z:|j dt tfkrd|_n|j|WYdd}~XqXn d|_ dS(NiTF(uNoneu socket_mapu_mapu_filenou setblockingu set_socketuTrueu connectedu getpeernameuaddrusocketuerroruargsuENOTCONNuEINVALuFalseu del_channel(uselfusockumapuerr((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu__init__s         udispatcher.__init__c Cs|jjd|jjg}|jr?|jr?|jdn|jrX|jdn|jdk ry|jd|jWqtk r|jt |jYqXnddj |t |fS(Nu.u listeningu connectedu%s:%du <%s at %#x>u ( u __class__u __module__u__name__u acceptinguaddruappendu connecteduNoneu TypeErrorureprujoinuid(uselfustatus((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu__repr__s  udispatcher.__repr__cCs)|dkr|j}n|||ju:uncaptured python exception, closing channel %s (%s:%s %s)uerror(ucompact_tracebackurepruidulog_infou handle_close(uselfunilutuvutbinfou self_repr((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_errorsudispatcher.handle_errorcCs|jdddS(Nu!unhandled incoming priority eventuwarning(ulog_info(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_exptsudispatcher.handle_exptcCs|jdddS(Nuunhandled read eventuwarning(ulog_info(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_readsudispatcher.handle_readcCs|jdddS(Nuunhandled write eventuwarning(ulog_info(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_writesudispatcher.handle_writecCs|jdddS(Nuunhandled connect eventuwarning(ulog_info(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuhandle_connectsudispatcher.handle_connectcCs,|j}|dk r(|j|ndS(N(uacceptuNoneuhandle_accepted(uselfupair((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_accepts  udispatcher.handle_acceptcCs|j|jdddS(Nuunhandled accepted eventuwarning(ucloseulog_info(uselfusockuaddr((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuhandle_accepteds udispatcher.handle_acceptedcCs|jdd|jdS(Nuunhandled close eventuwarning(ulog_infouclose(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_closesudispatcher.handle_closeNF(0u__name__u __module__u __qualname__uFalseudebugu connectedu acceptingu connectinguclosinguNoneuaddru frozensetuignore_log_typesu__init__u__repr__u__str__u add_channelu del_channelusocketuAF_INETu SOCK_STREAMu create_socketu set_socketuset_reuse_addrureadableuwritableulistenubinduconnectuacceptusendurecvucloseu __getattr__ulogulog_infouhandle_read_eventuhandle_connect_eventuhandle_write_eventuhandle_expt_eventu handle_erroru handle_exptu handle_readu handle_writeuhandle_connectu handle_acceptuhandle_acceptedu handle_close(u __locals__((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu dispatchersN                     u dispatchercBsV|EeZdZd d ddZddZddZddZd d Zd S( udispatcher_with_sendcCs tj|||d|_dS(Ns(u dispatcheru__init__u out_buffer(uselfusockumap((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu__init__sudispatcher_with_send.__init__cCs?d}tj||jdd}|j|d|_dS(Nii(u dispatcherusendu out_buffer(uselfunum_sent((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu initiate_sendsu"dispatcher_with_send.initiate_sendcCs|jdS(N(u initiate_send(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu handle_writesu!dispatcher_with_send.handle_writecCs|j pt|jS(N(u connectedulenu out_buffer(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuwritablesudispatcher_with_send.writablecCsA|jr#|jdt|n|j||_|jdS(Nu sending %s(udebugulog_infourepru out_bufferu initiate_send(uselfudata((u-/opt/alt/python33/lib64/python3.3/asyncore.pyusend s udispatcher_with_send.sendN( u__name__u __module__u __qualname__uNoneu__init__u initiate_sendu handle_writeuwritableusend(u __locals__((u-/opt/alt/python33/lib64/python3.3/asyncore.pyudispatcher_with_sends    udispatcher_with_sendcCstj\}}}g}|s0tdnxD|rv|j|jjj|jjjt|j f|j }q3W~|d\}}}dj dd|D}|||f|||fS(Nutraceback does not existiu cSsg|]}d|qS(u [%s|%s|%s]((u.0ux((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu ;s u%compact_traceback..i( usysuexc_infouAssertionErroruappendutb_frameuf_codeu co_filenameuco_nameustru tb_linenoutb_nextujoin(utuvutbutbinfoufileufunctionulineuinfo((u-/opt/alt/python33/lib64/python3.3/asyncore.pyucompact_traceback*s    ucompact_tracebackcCs|dkrt}nxt|jD]}y|jWq(tk r}z'|jdtkrgn |ssnWYdd}~Xq(tk rYq(|snYq(Xq(W|j dS(Ni( uNoneu socket_mapulistuvaluesucloseuOSErroruargsuEBADFu_reraised_exceptionsuclear(umapu ignore_allux((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu close_all>s    u close_alluposixcBsk|EeZdZddZddZddZd ddZeZeZ d d Z d d Z d S(u file_wrappercCstj||_dS(N(uosudupufd(uselfufd((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu__init__esufile_wrapper.__init__cGstj|j|S(N(uosureadufd(uselfuargs((u-/opt/alt/python33/lib64/python3.3/asyncore.pyurecvhsufile_wrapper.recvcGstj|j|S(N(uosuwriteufd(uselfuargs((u-/opt/alt/python33/lib64/python3.3/asyncore.pyusendksufile_wrapper.sendcCs9|tjkr)|tjkr)| r)dStddS(Niu-Only asyncore specific behaviour implemented.(usocketu SOL_SOCKETuSO_ERRORuNotImplementedError(uselfuleveluoptnameubuflen((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu getsockoptns ufile_wrapper.getsockoptcCstj|jdS(N(uosucloseufd(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyucloseysufile_wrapper.closecCs|jS(N(ufd(uself((u-/opt/alt/python33/lib64/python3.3/asyncore.pyufileno|sufile_wrapper.filenoN( u__name__u __module__u __qualname__u__init__urecvusenduNoneu getsockoptureaduwriteucloseufileno(u __locals__((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu file_wrapper`s    u file_wrappercBs/|EeZdZdddZddZdS(ufile_dispatcherc Cstj|d|d|_y|j}Wntk r@YnX|j|tj|tj d}|t j B}tj|tj |dS(NiT( u dispatcheru__init__uNoneuTrueu connectedufilenouAttributeErroruset_fileufcntluF_GETFLuosu O_NONBLOCKuF_SETFL(uselfufdumapuflags((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu__init__s    ufile_dispatcher.__init__cCs/t||_|jj|_|jdS(N(u file_wrapperusocketufilenou_filenou add_channel(uselfufd((u-/opt/alt/python33/lib64/python3.3/asyncore.pyuset_filesufile_dispatcher.set_fileN(u__name__u __module__u __qualname__uNoneu__init__uset_file(u __locals__((u-/opt/alt/python33/lib64/python3.3/asyncore.pyufile_dispatchers ufile_dispatcher(1u__doc__uselectusocketusysutimeuwarningsuosuerrnouEALREADYu EINPROGRESSu EWOULDBLOCKu ECONNRESETuEINVALuENOTCONNu ESHUTDOWNuEISCONNuEBADFu ECONNABORTEDuEPIPEuEAGAINu errorcodeu frozensetu _DISCONNECTEDu socket_mapu NameErroru _strerroru ExceptionuExitNowuKeyboardInterruptu SystemExitu_reraised_exceptionsureaduwriteu _exceptionu readwriteuNoneupollupoll2upoll3uFalseuloopu dispatcherudispatcher_with_senducompact_tracebacku close_allunameufcntlu file_wrapperufile_dispatcher(((u-/opt/alt/python33/lib64/python3.3/asyncore.pyu/sB      X        *9