U e5d@,@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|||dSN) ac_in_bufferincomingr producer_fifoasyncore dispatcher__init__)selfZsockmapr /usr/lib64/python3.8/asynchat.pyr Cszasync_chat.__init__cCs tddSNzmust be implemented in subclassNotImplementedErrorr datarrrcollect_incoming_dataQsz async_chat.collect_incoming_datacCs|j|dSN)rappendrrrr_collect_incoming_dataTsz!async_chat._collect_incoming_datacCsd|j}|jdd=|Sr)joinr)r drrr _get_dataWs  zasync_chat._get_datacCs tddSrrr rrrfound_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 Ztermrrrset_terminator_s zasync_chat.set_terminatorcCs|jSr)r%rrrrget_terminatorjszasync_chat.get_terminatorc Csz||j}WnDtk r&YdStk rT}z|WYdSd}~XYnXt|trr|jrrtt|j }|j ||_ |j rt |j }| }|s| |j d|_ q~t|tr|}||kr| |j d|_ |j||_n2| |j d||j |d|_ d|_|q~t |}|j |}|dkrv|dkrX| |j d||j ||d|_ |q~t|j |}|r||kr| |j d| |j | d|_ qq~| |j d|_ q~dS)Nrr)Zrecvac_in_buffer_sizeBlockingIOErrorOSError handle_errorrrr r!r"rlenr'rr#r%rfindfind_prefix_at_end)r rZwhyZlbr%nZterminator_lenindexrrr handle_readrsR              zasync_chat.handle_readcCs |dSr) initiate_sendrrrr handle_writeszasync_chat.handle_writecCs |dSr)closerrrr handle_closeszasync_chat.handle_closecCsxt|tttfstdt||j}t||kr`tdt||D]}|j ||||q@n |j || dS)Nz#data argument must be byte-ish (%r)r) rr! bytearray memoryview TypeErrortypeac_out_buffer_sizer-rangerrr3)r rZsabsirrrpushs  zasync_chat.pushcCs|j||dSr)rrr3)r Zproducerrrrpush_with_producers zasync_chat.push_with_producercCsdSNrrrrrreadableszasync_chat.readablecCs|jp |j Sr)r connectedrrrrwritableszasync_chat.writablecCs|jddSr)rrrrrrclose_when_doneszasync_chat.close_when_donecCs|jr|jr|jd}|s:|jd=|dkr:|dS|j}z|d|}Wn:tk r|}|rz|j|n|jd=YqYnXt|tr|j rt ||j }z| |}Wnt k r|YdSX|r|t|ks|t|kr ||d|jd<n|jd=dSdS)Nr)rrCr6r;r9more appendleftrrr r!r"sendr+r,r-)r firstZobsrZnum_sentrrrr3s8   zasync_chat.initiate_sendcCs d|_|jdd=|jdSr)rrrclearrrrrdiscard_bufferss zasync_chat.discard_buffers)NN)__name__ __module__ __qualname__r)r;r r"r rrrrr&r'r2r4r6r>r?rBrDrEr3rKrrrrr4s*  H (rc@seZdZdddZddZdS)simple_producercCs||_||_dSr)r buffer_size)r rrQrrrr szsimple_producer.__init__cCsJt|j|jkr6|jd|j}|j|jd|_|S|j}d|_|SdSr)r-rrQ)r resultrrrrFszsimple_producer.moreN)rP)rLrMrNr rFrrrrrOs rOcCs0t|d}|r,||d|s,|d8}q |Sr@)r-endswith)ZhaystackZneedlelrrrr//s  r/)r collectionsrr rrOr/rrrr0s  \