PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  lY.@sqdZddlZddlmZGdddejZGdddZGdd d Zd d ZdS) aA 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. N)dequec@seZdZdZdZdZdZdZddddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS)( async_chatzThis is an abstract class. You must derive from this class, and add the two methods collect_incoming_data() and found_terminator()irzlatin-1NcCs8d|_g|_t|_tjj|||dS)N) ac_in_bufferincomingr producer_fifoasyncore dispatcher__init__)selfsockmapr'/opt/python35/lib/python3.5/asynchat.pyr Cs   zasync_chat.__init__cCstddS)Nzmust be implemented in subclass)NotImplementedError)r datarrrcollect_incoming_dataQsz async_chat.collect_incoming_datacCs|jj|dS)N)rappend)r rrrr_collect_incoming_dataTsz!async_chat._collect_incoming_datacCs&dj|j}|jdd=|S)Nr)joinr)r drrr _get_dataWszasync_chat._get_datacCstddS)Nzmust be implemented in subclass)r)r rrrfound_terminator\szasync_chat.found_terminatorcCsat|tr-|jr-t||j}n't|trT|dkrTtd||_dS)zdSet the input delimiter. Can be a fixed string of any length, an integer, or None. rz-the number of received bytes must be positiveN) isinstancestr use_encodingbytesencodingint ValueError terminator)r Ztermrrrset_terminator_s  zasync_chat.set_terminatorcCs|jS)N)r )r rrrget_terminatorjszasync_chat.get_terminatorcCsiy|j|j}WnHtk r.dSYn3tk r`}z|jdSWYdd}~XnXt|tr|jrtt|j }|j ||_ x|j rdt |j }|j }|s|j |j d|_ qt|trw|}||kr1|j |j d|_ |j||_qa|j |j d||j |d|_ d|_|jqt |}|j j|}|dkr|dkr|j |j d||j ||d|_ |jqt|j |}|rH||krD|j |j d| |j | d|_ Pq|j |j d|_ qWdS)Nrr)recvac_in_buffer_sizeBlockingIOErrorOSError handle_errorrrrrrrlenr"rrr rfindfind_prefix_at_end)r rwhyZlbr nZterminator_lenindexrrr handle_readrsR             zasync_chat.handle_readcCs|jdS)N) initiate_send)r rrr handle_writeszasync_chat.handle_writecCs|jdS)N)close)r rrr handle_closeszasync_chat.handle_closecCst|tttfs-tdt||j}t||krxQtdt||D]$}|j j ||||qaWn|j j ||j dS)Nz#data argument must be byte-ish (%r)r) rr bytearray memoryview TypeErrortypeac_out_buffer_sizer*rangerrr1)r rZsabsirrrpushs %zasync_chat.pushcCs|jj||jdS)N)rrr1)r Zproducerrrrpush_with_producerszasync_chat.push_with_producercCsdS)z4predicate for inclusion in the readable for select()r#r)r rrrreadableszasync_chat.readablecCs|jp|j S)z4predicate for inclusion in the writable for select())r connected)r rrrwritableszasync_chat.writablecCs|jjddS)zAautomatically close this channel once the outgoing queue is emptyN)rr)r rrrclose_when_doneszasync_chat.close_when_donecCsgx`|jrb|jrb|jd}|sL|jd=|dkrL|jdS|j}y|d|}WnDtk r|j}|r|jj|n |jd=wYnXt|tr|j rt ||j }y|j |}Wn t k r|jdSYnX|r^|t|ks:|t|krT||d|jdr@rAr1rGrrrrr4s,       H       (rc@s+eZdZdddZddZdS)simple_producericCs||_||_dS)N)r buffer_size)r rrMrrrr s zsimple_producer.__init__cCset|j|jkrK|jd|j}|j|jd|_|S|j}d|_|SdS)Nr)r*rrM)r resultrrrrBs  zsimple_producer.moreN)rHrIrJr rBrrrrrLs rLc@s[eZdZdddZddZddZdd Zd d Zd d ZdS)fifoNcCsJddl}|jdtdd|s7t|_nt||_dS)Nrz(fifo class will be removed in Python 3.6 stacklevel)warningswarnDeprecationWarningrlist)r rUrRrrrr !s    z fifo.__init__cCs t|jS)N)r*rU)r rrr__len__*sz fifo.__len__cCs|j S)N)rU)r rrris_empty-sz fifo.is_emptycCs |jdS)Nr)rU)r rrrrE0sz fifo.firstcCs|jj|dS)N)rUr)r rrrrr<3sz fifo.pushcCs$|jrd|jjfSdSdS)Nr#r)rN)rUpopleft)r rrrpop6s zfifo.pop) rHrIrJr rVrWrEr<rYrrrrrO s     rOcCsEt|d}x.|r@|j|d| r@|d8}qW|S)Nr#)r*endswith)ZhaystackZneedlelrrrr,Ls#r,) rKr collectionsrr rrLrOr,rrrr/s  ,