JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbrў fD-c@s}dZddlZddlZddlmZGdddejZGdddZGdd d Zd d Z dS( uA class supporting chat-style (command/response) protocols. This class adds support for 'chat' style protocols - where one side sends a 'command', and the other sends a response (examples would be the common internet protocols - smtp, nntp, ftp, etc..). The handle_read() method looks at the input stream for the current 'terminator' (usually '\r\n' for single-line responses, '\r\n.\r\n' for multi-line output), calling self.found_terminator() on its receipt. for example: Say you build an async nntp client using this class. At the start of the connection, you'll have self.terminator set to '\r\n', in order to process the single-line greeting. Just before issuing a 'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST command will be accumulated (using your own 'collect_incoming_data' method) up to the terminator, and then control will be returned to you - by calling your self.found_terminator() method. iN(udequecBs|EeZdZdZdZdZdZdZd'd'ddZ ddZ d d Z d d Z d dZ ddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'S((u async_chatuThis is an abstract class. You must derive from this class, and add the two methods collect_incoming_data() and found_terminator()iiulatin-1cCs8d|_g|_t|_tjj|||dS(Ns(u ac_in_bufferuincomingudequeu producer_fifouasyncoreu dispatcheru__init__(uselfusockumap((u-/opt/alt/python33/lib64/python3.3/asynchat.pyu__init__Ds   uasync_chat.__init__cCstddS(Numust be implemented in subclass(uNotImplementedError(uselfudata((u-/opt/alt/python33/lib64/python3.3/asynchat.pyucollect_incoming_dataRsu async_chat.collect_incoming_datacCs|jj|dS(N(uincominguappend(uselfudata((u-/opt/alt/python33/lib64/python3.3/asynchat.pyu_collect_incoming_dataUsu!async_chat._collect_incoming_datacCs&dj|j}|jdd=|S(Ns(ujoinuincoming(uselfud((u-/opt/alt/python33/lib64/python3.3/asynchat.pyu _get_dataXsuasync_chat._get_datacCstddS(Numust be implemented in subclass(uNotImplementedError(uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyufound_terminator]suasync_chat.found_terminatorcCs:t|tr-|jr-t||j}n||_dS(uRSet the input delimiter. Can be a fixed string of any length, an integer, or NoneN(u isinstanceustru use_encodingubytesuencodingu terminator(uselfuterm((u-/opt/alt/python33/lib64/python3.3/asynchat.pyuset_terminator`suasync_chat.set_terminatorcCs|jS(N(u terminator(uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyuget_terminatorfsuasync_chat.get_terminatorcCs`y|j|j}Wn6tjk rN}z|jdSWYdd}~XnXt|tr||jr|tt|j }n|j ||_ x|j r[t |j }|j }|s|j |j d|_ qt|trh|}||kr"|j |j d|_ |j||_qX|j |j d||j |d|_ d|_|jqt |}|j j|}|dkr|dkr|j |j d|n|j ||d|_ |jqt|j |}|r?||kr;|j |j d| |j | d|_ nPq|j |j d|_ qWdS(Nsiii(urecvuac_in_buffer_sizeusocketuerroru handle_erroru isinstanceustru use_encodingubytesuencodingu ac_in_bufferulenuget_terminatorucollect_incoming_datauintu terminatorufound_terminatorufindufind_prefix_at_end(uselfudatauwhyulbu terminatorunuterminator_lenuindex((u-/opt/alt/python33/lib64/python3.3/asynchat.pyu handle_readnsN            uasync_chat.handle_readcCs|jdS(N(u initiate_send(uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyu handle_writesuasync_chat.handle_writecCs|jdS(N(uclose(uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyu handle_closesuasync_chat.handle_closecCs}|j}t||kr_xQtdt||D]$}|jj||||q4Wn|jj||jdS(Ni(uac_out_buffer_sizeulenurangeu producer_fifouappendu initiate_send(uselfudatausabsui((u-/opt/alt/python33/lib64/python3.3/asynchat.pyupushs  %uasync_chat.pushcCs|jj||jdS(N(u producer_fifouappendu initiate_send(uselfuproducer((u-/opt/alt/python33/lib64/python3.3/asynchat.pyupush_with_producersuasync_chat.push_with_producercCsdS(u4predicate for inclusion in the readable for select()i((uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyureadablesuasync_chat.readablecCs|jp|j S(u4predicate for inclusion in the writable for select()(u producer_fifou connected(uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyuwritablesuasync_chat.writablecCs|jjddS(uAautomatically close this channel once the outgoing queue is emptyN(u producer_fifouappenduNone(uself((u-/opt/alt/python33/lib64/python3.3/asynchat.pyuclose_when_donesuasync_chat.close_when_donecCssxl|jrn|jrn|jd}|sO|jd=|dkrO|jdSn|j}y|d|}WnDtk r|j}|r|jj|n |jd=wYnXt|t r|j rt ||j }ny|j |}Wn#tjk r|jdSYnX|rj|t|ksC|t|kr]||d|jd/s  (