B cZ1@s@ddlZddlmZGdddejZGdddZddZdS) N)dequec@seZdZdZdZdZdZd'ddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZdS)( async_chatirzlatin-1NcCs(d|_g|_t|_tj|||dS)N) ac_in_bufferincomingr producer_fifoasyncore dispatcher__init__)selfZsockmapr +/opt/alt/python37/lib/python3.7/asynchat.pyr Cszasync_chat.__init__cCs tddS)Nzmust be implemented in subclass)NotImplementedError)r datar r rcollect_incoming_dataQsz async_chat.collect_incoming_datacCs|j|dS)N)rappend)r rr r r_collect_incoming_dataTsz!async_chat._collect_incoming_datacCsd|j}|jdd=|S)Nr)joinr)r dr r r _get_dataWs  zasync_chat._get_datacCs tddS)Nzmust be implemented in subclass)r)r r r rfound_terminator\szasync_chat.found_terminatorcCsBt|tr|jrt||j}nt|tr8|dkr8td||_dS)Nrz-the number of received bytes must be positive) isinstancestr use_encodingbytesencodingint ValueError terminator)r Ztermr r rset_terminator_s zasync_chat.set_terminatorcCs|jS)N)r)r r r rget_terminatorjszasync_chat.get_terminatorc Csy||j}Wn<tk r$dStk rL}z |dSd}~XYnXt|trj|jrjtt|j }|j ||_ xV|j rt |j }| }|s| |j d|_ qzt|tr|}||kr| |j d|_ |j||_n2| |j d||j |d|_ d|_|qzt |}|j |}|dkrr|dkrT| |j d||j ||d|_ |qzt|j |}|r||kr| |j d| |j | d|_ Pqz| |j d|_ qzWdS)Nrr)Zrecvac_in_buffer_sizeBlockingIOErrorOSError handle_errorrrrrrrlenr!rrrrfindfind_prefix_at_end)r rZwhyZlbrnZterminator_lenindexr r r handle_readrsR               zasync_chat.handle_readcCs |dS)N) initiate_send)r r r r handle_writeszasync_chat.handle_writecCs |dS)N)close)r r r r handle_closeszasync_chat.handle_closecCs|t|tttfstdt||j}t||krdx>tdt||D]}|j ||||qBWn |j || dS)Nz#data argument must be byte-ish (%r)r) rr bytearray memoryview TypeErrortypeac_out_buffer_sizer'rangerrr-)r rZsabsir r rpushs   zasync_chat.pushcCs|j||dS)N)rrr-)r Zproducerr r rpush_with_producers zasync_chat.push_with_producercCsdS)Nr )r r r rreadableszasync_chat.readablecCs|jp |j S)N)r connected)r r r rwritableszasync_chat.writablecCs|jddS)N)rr)r r r rclose_when_doneszasync_chat.close_when_donecCsx|jr|jr|jd}|s>|jd=|dkr>|dS|j}y|d|}Wn8tk r|}|r~|j|n|jd=wYnXt|tr|j rt ||j }y| |}Wnt k r|dSX|r|t|ks|t|kr ||d|jd<n|jd=dSWdS)Nr)rr<r0r5r3more appendleftrrrrrsendr%r&r')r firstZobsrZnum_sentr r rr-s8  zasync_chat.initiate_sendcCs d|_|jdd=|jdS)Nr)rrrclear)r r r rdiscard_bufferss zasync_chat.discard_buffers)NN)__name__ __module__ __qualname__r#r5rrr rrrrr r!r,r.r0r8r9r;r=r>r-rDr r r rr4s*  H (rc@seZdZdddZddZdS)simple_producercCs||_||_dS)N)r buffer_size)r rrJr r rr szsimple_producer.__init__cCsJt|j|jkr6|jd|j}|j|jd|_|S|j}d|_|SdS)Nr)r'rrJ)r resultr r rr?szsimple_producer.moreN)rI)rErFrGr r?r r r rrHs rHcCs4t|d}x"|r.||d|s.|d8}qW|S)Nr:)r'endswith)ZhaystackZneedlelr r rr)/s  r))r collectionsrr rrHr)r r r r0s  \