3 \_@sHdddddddgZddlZeed r2ejd d gd d lmZd dlmZd dlmZd dlmZd dlm Z d dl m Z d!Z Gddde ZGdddeZe d"de dddZe d#de dddZeed re d$de ddd Ze d%de ddd ZGdddejZGdddeejZGdddZGd ddZdS)& StreamReader StreamWriterStreamReaderProtocolopen_connection start_serverIncompleteReadErrorLimitOverrunErrorNZAF_UNIXopen_unix_connectionstart_unix_server) coroutines)compat)events) protocols) coroutine)loggercs$eZdZfddZddZZS)rcs(tjdt||f||_||_dS)Nz-%d bytes read on a total of %r expected bytes)super__init__lenpartialexpected)selfrr) __class__'/usr/lib64/python3.6/asyncio/streams.pyr szIncompleteReadError.__init__cCst||j|jffS)N)typerr)rrrr __reduce__&szIncompleteReadError.__reduce__)__name__ __module__ __qualname__rr __classcell__rr)rrrs cs$eZdZfddZddZZS)rcstj|||_dS)N)rrconsumed)rmessager#)rrrr0s zLimitOverrunError.__init__cCst||jd|jffS)Nr)rargsr#)rrrrr4szLimitOverrunError.__reduce__)rr r!rrr"rr)rrr*s )looplimitc +sb|dkrtj}t||d}t||d|jfdd||f|EdH\}}t|||}||fS)N)r'r&)r&csS)Nrr)protocolrrQsz!open_connection..)rget_event_looprrZcreate_connectionr) hostportr&r'kwdsreader transport_writerr)r(rr8s   c+s8dkrtjfdd}j|||f|EdHS)Ncstd}t|d}|S)N)r'r&)r&)rr)r.r()client_connected_cbr'r&rrfactoryqs zstart_server..factory)rr*Z create_server)r2r+r,r&r'r-r3r)r2r'r&rrVsc+s`|dkrtj}t||d}t||d|jfdd|f|EdH\}}t|||}||fS)N)r'r&)r&csS)Nrr)r(rrr)sz&open_unix_connection..)rr*rrZcreate_unix_connectionr)pathr&r'r-r.r/r0r1r)r(rr }s  c+s6dkrtjfdd}j||f|EdHS)Ncstd}t|d}|S)N)r'r&)r&)rr)r.r()r2r'r&rrr3s z"start_unix_server..factory)rr*Zcreate_unix_server)r2r4r&r'r-r3r)r2r'r&rr sc@s:eZdZd ddZddZddZdd Zed d ZdS) FlowControlMixinNcCs0|dkrtj|_n||_d|_d|_d|_dS)NF)rr*_loop_paused _drain_waiter_connection_lost)rr&rrrrs  zFlowControlMixin.__init__cCs d|_|jjrtjd|dS)NTz%r pauses writing)r7r6 get_debugrdebug)rrrr pause_writings zFlowControlMixin.pause_writingcCsFd|_|jjrtjd||j}|dk rBd|_|jsB|jddS)NFz%r resumes writing)r7r6r:rr;r8done set_result)rwaiterrrrresume_writings  zFlowControlMixin.resume_writingcCsVd|_|jsdS|j}|dkr"dSd|_|jr4dS|dkrH|jdn |j|dS)NT)r9r7r8r=r> set_exception)rexcr?rrrconnection_losts z FlowControlMixin.connection_lostccs<|jrtd|jsdS|j}|jj}||_|EdHdS)NzConnection lost)r9ConnectionResetErrorr7r8r6 create_future)rr?rrr _drain_helpers zFlowControlMixin._drain_helper)N) rr r!rr<r@rCrrFrrrrr5s   r5csBeZdZd fdd ZddZfddZdd Zd d ZZS) rNcs*tj|d||_d|_||_d|_dS)N)r&F)rr_stream_reader_stream_writer_client_connected_cb _over_ssl)rZ stream_readerr2r&)rrrrs zStreamReaderProtocol.__init__cCsd|jj||jddk |_|jdk r`t|||j|j|_|j|j|j}tj |r`|jj |dS)NZ sslcontext) rG set_transportget_extra_inforJrIrr6rHr Z iscoroutineZ create_task)rr/resrrrconnection_mades    z$StreamReaderProtocol.connection_madecsF|jdk r*|dkr|jjn |jj|tj|d|_d|_dS)N)rGfeed_eofrArrCrH)rrB)rrrrCs    z$StreamReaderProtocol.connection_lostcCs|jj|dS)N)rG feed_data)rdatarrr data_receivedsz"StreamReaderProtocol.data_receivedcCs|jj|jrdSdS)NFT)rGrOrJ)rrrr eof_receiveds z!StreamReaderProtocol.eof_received)NN) rr r!rrNrCrRrSr"rr)rrrs   c@sfeZdZddZddZeddZddZd d Zd d Z d dZ ddZ dddZ e ddZdS)rcCs||_||_||_||_dS)N) _transport _protocol_readerr6)rr/r(r.r&rrrrszStreamWriter.__init__cCs:|jjd|jg}|jdk r,|jd|jddj|S)Nz transport=%rz reader=%rz<%s> )rrrTrVappendjoin)rinforrr__repr__!s zStreamWriter.__repr__cCs|jS)N)rT)rrrrr/'szStreamWriter.transportcCs|jj|dS)N)rTwrite)rrQrrrr\+szStreamWriter.writecCs|jj|dS)N)rT writelines)rrQrrrr].szStreamWriter.writelinescCs |jjS)N)rT write_eof)rrrrr^1szStreamWriter.write_eofcCs |jjS)N)rT can_write_eof)rrrrr_4szStreamWriter.can_write_eofcCs |jjS)N)rTclose)rrrrr`7szStreamWriter.closeNcCs|jj||S)N)rTrL)rnamedefaultrrrrL:szStreamWriter.get_extra_infoccsN|jdk r |jj}|dk r ||jdk r:|jjr:dV|jjEdHdS)N)rV exceptionrTZ is_closingrUrF)rrBrrrdrain=s    zStreamWriter.drain)N)rr r!rr[propertyr/r\r]r^r_r`rLrrdrrrrrs   c@seZdZedfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ eddZeddZed'ddZed)ddZed d!Zejred"d#Zed$d%Zejrd&d#ZdS)*rNcCsZ|dkrtd||_|dkr*tj|_n||_t|_d|_d|_d|_ d|_ d|_ dS)NrzLimit cannot be <= 0F) ValueError_limitrr*r6 bytearray_buffer_eof_waiter _exceptionrTr7)rr'r&rrrrXs zStreamReader.__init__cCsdg}|jr |jdt|j|jr0|jd|jtkrJ|jd|j|jr`|jd|j|jrv|jd|j|jr|jd|j|j r|jdd d j |S) Nrz%d byteseofzl=%dzw=%rze=%rzt=%rZpausedz<%s>rW) rirXrrjrg_DEFAULT_LIMITrkrlrTr7rY)rrZrrrr[ks    zStreamReader.__repr__cCs|jS)N)rl)rrrrrc}szStreamReader.exceptioncCs0||_|j}|dk r,d|_|js,|j|dS)N)rlrk cancelledrA)rrBr?rrrrAs zStreamReader.set_exceptioncCs*|j}|dk r&d|_|js&|jddS)N)rkror>)rr?rrr_wakeup_waiters zStreamReader._wakeup_waitercCs ||_dS)N)rT)rr/rrrrKszStreamReader.set_transportcCs*|jr&t|j|jkr&d|_|jjdS)NF)r7rrirgrTresume_reading)rrrr_maybe_resume_transportsz$StreamReader._maybe_resume_transportcCsd|_|jdS)NT)rjrp)rrrrrOszStreamReader.feed_eofcCs|jo |j S)N)rjri)rrrrat_eofszStreamReader.at_eofc Csv|sdS|jj||j|jdk rr|j rrt|jd|jkrry|jjWntk rjd|_YnXd|_dS)NrT) riextendrprTr7rrgZ pause_readingNotImplementedError)rrQrrrrPs   zStreamReader.feed_datac csV|jdk rtd||jr,d|_|jj|jj|_z|jEdHWdd|_XdS)NzH%s() called while another coroutine is already waiting for incoming dataF)rk RuntimeErrorr7rTrqr6rE)rZ func_namerrr_wait_for_datas   zStreamReader._wait_for_dataccsd}t|}y|j|EdH}Wntk rB}z|jSd}~Xnftk r}zJ|jj||jrv|jd|j|=n |jj|j t |j dWYdd}~XnX|S)N r) r readuntilrrrri startswithr#clearrrrfr%)rsepseplenlineerrrreadlines  zStreamReader.readlinerxccst|}|dkrtd|jdk r(|jd}xt|j}|||kr||jj||}|dkr\P|d|}||jkr|td||jrt|j}|jj t |d|j dEdHq.W||jkrtd||jd||}|jd||=|j t|S)Nrz,Separator should be at least one-byte stringr z2Separator is not found, and chunk exceed the limitryz2Separator is found, but chunk is longer than limit) rrfrlrifindrgrrjbytesr{rrwrr)rZ separatorr}offsetZbuflenZisepchunkrrrrys:         zStreamReader.readuntilr ccs|jdk r|j|dkrdS|dkrZg}x&|j|jEdH}|sBP|j|q*Wdj|S|j rz|j rz|jdEdHt|jd|}|jd|=|j |S)Nrread) rlrrgrXrYrirjrwrrr)rnZblocksblockrQrrrrPs$   zStreamReader.readccs|dkrtd|jdk r |j|dkr,dSxFt|j|krr|jr`t|j}|jjt|||jdEdHq.Wt|j|krt|j}|jjnt|jd|}|jd|=|j |S)Nrz*readexactly size can not be less than zeror readexactly) rfrlrrirjrr{rrwrr)rrZ incompleterQrrrrs&       zStreamReader.readexactlycCs|S)Nr)rrrr __aiter__szStreamReader.__aiter__ccs|jEdH}|dkrt|S)Nr)rStopAsyncIteration)rvalrrr __anext__szStreamReader.__anext__cCs|S)Nr)rrrrrs)rxr)r)rr r!rnrr[rcrArprKrrrOrsrPrrwrryrrr ZPY35rrZPY352rrrrrVs,    [ 2 *  i)NN)NN)N)N)__all__Zsockethasattrrtr r rrrlogrrnEOFErrorr Exceptionrrrr r ZProtocolr5rrrrrrrs@       "  B3G