3 ^@,c@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|_tjj|||dSN) ac_in_bufferincomingr producer_fifoasyncore dispatcher__init__)selfZsockZmapr /usr/lib64/python3.6/asynchat.pyr Cszasync_chat.__init__cC tddSNzmust be implemented in subclassZNotImplementedErrorr datar r r collect_incoming_dataQz async_chat.collect_incoming_datacCs|jj|dSN)rappendrr r r _collect_incoming_dataTrz!async_chat._collect_incoming_datacCsdj|j}|jdd=|Sr)Zjoinr)r Zdr r r _get_dataWs  zasync_chat._get_datacCrrrr r r r found_terminator\rzasync_chat.found_terminatorcCsBt|tr|jrt||j}nt|tr8|dkr8td||_dS)Nrz-the number of received bytes must be positive) isinstancestr use_encodingbytesencodingintZ ValueError terminator)r Ztermr r r set_terminator_s zasync_chat.set_terminatorcCs|jSr)r!rr r r get_terminatorjrzasync_chat.get_terminatorcCsy|j|j}Wn:tk r$dStk rJ}z |jdSd}~XnXt|trh|jrhtt|j }|j ||_ xV|j rt |j }|j }|s|j |j d|_ qxt|tr|}||kr|j |j d|_ |j||_n2|j |j d||j |d|_ d|_|jqxt |}|j j|}|dkrp|dkrR|j |j d||j ||d|_ |jqxt|j |}|r||kr|j |j d| |j | d|_ Pqx|j |j d|_ qxWdS)Nrri)Zrecvac_in_buffer_sizeZBlockingIOErrorOSError handle_errorrrrrrrlenr#rr r!rZfindfind_prefix_at_end)r rZwhyZlbr!ZnZterminator_lenZindexr r r handle_readrsR               zasync_chat.handle_readcC |jdSr) initiate_sendrr r r handle_writerzasync_chat.handle_writecCr+r)Zcloserr r r handle_closerzasync_chat.handle_closecCs|t|tttfstdt||j}t||krdx>tdt||D]}|j j ||||qBWn |j j ||j dS)Nz#data argument must be byte-ish (%r)r) rrZ bytearrayZ memoryview TypeErrorZtypeac_out_buffer_sizer(Zrangerrr,)r rZsabsZir r r pushs   zasync_chat.pushcCs|jj||jdSr)rrr,)r Zproducerr r r push_with_producers zasync_chat.push_with_producercCsdSNr$r rr r r readableszasync_chat.readablecCs|jp |j Sr)r connectedrr r r writablezasync_chat.writablecCs|jjddSr)rrrr r r close_when_doner7zasync_chat.close_when_donecCsx|jo|jr|jd}|s<|jd=|dkr<|jdS|j}y|d|}Wn8tk r|j}|r||jj|n|jd=wYnXt|tr|j rt ||j }y|j |}Wnt k r|jdSX|r|t|ks|t|kr||d|jd<n|jd=dSWdS)Nr)rr5r.r0r/moreZ appendleftrrrrrZsendr&r'r()r ZfirstZobsrZnum_sentr r r r,s8  zasync_chat.initiate_sendcCs d|_|jdd=|jjdSr)rrrZclearrr r r discard_bufferss zasync_chat.discard_buffers)NN)__name__ __module__ __qualname__r%r0rrr rrrrr"r#r*r-r.r1r2r4r6r8r,r:r r r r r4s*  H (rc@seZdZdddZddZdS)simple_producercCs||_||_dSr)r buffer_size)r rr@r r r r szsimple_producer.__init__cCsJt|j|jkr6|jd|j}|j|jd|_|S|j}d|_|SdSr)r(rr@)r Zresultr r r r9szsimple_producer.moreN)r?)r;r<r=r r9r r r r r>s r>cCs6t|d}x$|r0|j|d| r0|d8}qW|Sr3)r(Zendswith)ZhaystackZneedleZlr r r r)/s  r))rZ collectionsrr rr>r)r r r r Z0s  \