U iÛf hã@s&dZddlZddlZddlZddlZeedƒr6ed7ZddlmZddlmZddlm Z dd lm Z dd lm Z dd l m Z dd lmZd Zddedœdd„Zd dedœdd„Zeedƒràd!dedœdd„Zd"dedœdd„ZGdd„de jƒZGdd„dee jƒZGdd„dƒZGdd„dƒZdS)#)Ú StreamReaderÚ StreamWriterÚStreamReaderProtocolÚopen_connectionÚ start_serveréNZAF_UNIX)Úopen_unix_connectionÚstart_unix_serveré)Ú coroutines)Úevents)Ú exceptions)Úformat_helpers)Ú protocols)Úlogger)Úsleepi)ÚloopÚlimitc ‹st|dkrt ¡}ntjdtddt||d}t||d‰|j‡fdd„||f|ŽIdH\}}t|ˆ||ƒ}||fS)Nú[The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.é©Ú stacklevel©rr©rcsˆS©N©r©Úprotocolrú4/opt/alt/python38/lib64/python3.8/asyncio/streams.pyÚ5óz!open_connection..) r Úget_event_loopÚwarningsÚwarnÚDeprecationWarningrrZcreate_connectionr) ÚhostÚportrrÚkwdsÚreaderÚ transportÚ_Úwriterrrrrs" þ   ÿÿrc‹sJˆdkrt ¡‰ntjdtdd‡‡‡fdd„}ˆj|||f|ŽIdHS)Nrrrcstˆˆd}t|ˆˆd}|S©Nrr©rr©r'r©Úclient_connected_cbrrrrÚfactoryXs  ÿzstart_server..factory)r r r!r"r#Z create_server)r/r$r%rrr&r0rr.rr:s þrc‹sr|dkrt ¡}ntjdtddt||d}t||d‰|j‡fdd„|f|ŽIdH\}}t|ˆ||ƒ}||fS)NrrrrrcsˆSrrrrrrrprz&open_unix_connection..) r r r!r"r#rrZcreate_unix_connectionr)Úpathrrr&r'r(r)r*rrrrds  þ   ÿÿrc‹sHˆdkrt ¡‰ntjdtdd‡‡‡fdd„}ˆj||f|ŽIdHS)Nrrrcstˆˆd}t|ˆˆd}|Sr+r,r-r.rrr0~s  ÿz"start_unix_server..factory)r r r!r"r#Zcreate_unix_server)r/r1rrr&r0rr.rrts þrc@s>eZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „ZdS)ÚFlowControlMixinNcCs0|dkrt ¡|_n||_d|_d|_d|_dS©NF)r r Ú_loopÚ_pausedÚ _drain_waiterÚ_connection_lost)ÚselfrrrrÚ__init__‘s  zFlowControlMixin.__init__cCs d|_|j ¡rt d|¡dS)NTz%r pauses writing)r5r4Ú get_debugrÚdebug©r8rrrÚ pause_writingšs zFlowControlMixin.pause_writingcCsFd|_|j ¡rt d|¡|j}|dk rBd|_| ¡sB| d¡dS)NFz%r resumes writing)r5r4r:rr;r6ÚdoneÚ set_result©r8ÚwaiterrrrÚresume_writing s  zFlowControlMixin.resume_writingcCsVd|_|jsdS|j}|dkr"dSd|_| ¡r4dS|dkrH| d¡n | |¡dS©NT)r7r5r6r>r?Ú set_exception©r8ÚexcrArrrÚconnection_lost¬s z FlowControlMixin.connection_lostcÃs<|jrtdƒ‚|jsdS|j}|j ¡}||_|IdHdS)NzConnection lost)r7ÚConnectionResetErrorr5r6r4Ú create_futurer@rrrÚ _drain_helper¼s zFlowControlMixin._drain_helpercCst‚dSr)ÚNotImplementedError©r8ÚstreamrrrÚ_get_close_waiterÇsz"FlowControlMixin._get_close_waiter)N) Ú__name__Ú __module__Ú __qualname__r9r=rBrGrJrNrrrrr2‡s    r2csbeZdZdZd‡fdd„ Zedd„ƒZdd„Z‡fdd „Zd d „Z d d „Z dd„Z dd„Z ‡Z S)rNcsntƒj|d|dk r,t |¡|_|j|_nd|_|dk r@||_d|_d|_d|_ ||_ d|_ |j   ¡|_dS)NrF)Úsuperr9ÚweakrefÚrefÚ_stream_reader_wrÚ_source_tracebackÚ_strong_readerÚ_reject_connectionÚ_stream_writerÚ _transportÚ_client_connected_cbÚ _over_sslr4rIÚ_closed)r8Z stream_readerr/r©Ú __class__rrr9Ös  zStreamReaderProtocol.__init__cCs|jdkrdS| ¡Sr)rUr<rrrÚ_stream_readerés z#StreamReaderProtocol._stream_readercCs®|jr6ddi}|jr|j|d<|j |¡| ¡dS||_|j}|dk rT| |¡| d¡dk |_ |j dk rªt ||||jƒ|_ |  ||j ¡}t  |¡r¤|j |¡d|_dS)NÚmessagezpAn open stream was garbage collected prior to establishing network connection; call "stream.close()" explicitly.Zsource_tracebackZ sslcontext)rXrVr4Zcall_exception_handlerÚabortrZr`Ú set_transportÚget_extra_infor\r[rrYr Z iscoroutineZ create_taskrW)r8r(Úcontextr'ÚresrrrÚconnection_madeïs2ÿ    þÿ  z$StreamReaderProtocol.connection_madecsx|j}|dk r*|dkr | ¡n | |¡|j ¡sV|dkrJ|j d¡n |j |¡tƒ |¡d|_d|_ d|_ dSr) r`Úfeed_eofrDr]r>r?rRrGrUrYrZ)r8rFr'r^rrrG s     z$StreamReaderProtocol.connection_lostcCs|j}|dk r| |¡dSr)r`Ú feed_data)r8Údatar'rrrÚ data_receivedsz"StreamReaderProtocol.data_receivedcCs$|j}|dk r| ¡|jr dSdS)NFT)r`rhr\)r8r'rrrÚ eof_received s z!StreamReaderProtocol.eof_receivedcCs|jSr)r]rLrrrrN+sz&StreamReaderProtocol._get_close_waitercCs"|j}| ¡r| ¡s| ¡dSr)r]r>Ú cancelledÚ exception)r8ÚclosedrrrÚ__del__.szStreamReaderProtocol.__del__)NN)rOrPrQrVr9Úpropertyr`rgrGrkrlrNrpÚ __classcell__rrr^rrËs    rc@sreZdZdd„Zdd„Zedd„ƒZdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z ddd„Zdd„ZdS)rcCs4||_||_||_||_|j ¡|_|j d¡dSr)rZÚ _protocolÚ_readerr4rIZ _complete_futr?)r8r(rr'rrrrr9@s  zStreamWriter.__init__cCs@|jjd|j›g}|jdk r0| d|j›¡d d |¡¡S)Nú transport=zreader=ú<{}>ú )r_rOrZrtÚappendÚformatÚjoin©r8ÚinforrrÚ__repr__Js zStreamWriter.__repr__cCs|jSr©rZr<rrrr(PszStreamWriter.transportcCs|j |¡dSr)rZÚwrite©r8rjrrrrTszStreamWriter.writecCs|j |¡dSr)rZÚ writelinesr€rrrrWszStreamWriter.writelinescCs |j ¡Sr)rZÚ write_eofr<rrrr‚ZszStreamWriter.write_eofcCs |j ¡Sr)rZÚ can_write_eofr<rrrrƒ]szStreamWriter.can_write_eofcCs |j ¡Sr)rZÚcloser<rrrr„`szStreamWriter.closecCs |j ¡Sr)rZÚ is_closingr<rrrr…cszStreamWriter.is_closingcÃs|j |¡IdHdSr)rsrNr<rrrÚ wait_closedfszStreamWriter.wait_closedNcCs|j ||¡Sr)rZrd)r8ÚnameÚdefaultrrrrdiszStreamWriter.get_extra_infocÃsL|jdk r |j ¡}|dk r |‚|j ¡r8tdƒIdH|j ¡IdHdS)Nr)rtrnrZr…rrsrJ)r8rFrrrÚdrainls   zStreamWriter.drain)N)rOrPrQr9r}rqr(rrr‚rƒr„r…r†rdr‰rrrrr6s    rc@s¢eZdZdZedfdd„Zdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd&dd„Zd'dd„Zd d!„Zd"d#„Zd$d%„ZdS)(rNcCsv|dkrtdƒ‚||_|dkr*t ¡|_n||_tƒ|_d|_d|_d|_ d|_ d|_ |j  ¡rrt  t d¡¡|_dS)NrzLimit cannot be <= 0Fr )Ú ValueErrorÚ_limitr r r4Ú bytearrayÚ_bufferÚ_eofÚ_waiterÚ _exceptionrZr5r:r Ú extract_stackÚsysÚ _getframerV)r8rrrrrr9Šs   ÿzStreamReader.__init__cCs¶dg}|jr"| t|jƒ›d¡|jr2| d¡|jtkrN| d|j›¡|jrf| d|j›¡|jr~| d|j›¡|jr–| d|j›¡|j r¦| d¡d   d   |¡¡S) Nrz bytesÚeofzlimit=zwaiter=z exception=ruZpausedrvrw) rrxÚlenrŽr‹Ú_DEFAULT_LIMITrrrZr5ryrzr{rrrr} s    zStreamReader.__repr__cCs|jSr)rr<rrrrn²szStreamReader.exceptioncCs0||_|j}|dk r,d|_| ¡s,| |¡dSr)rrrmrDrErrrrDµs zStreamReader.set_exceptioncCs*|j}|dk r&d|_| ¡s&| d¡dSr)rrmr?r@rrrÚ_wakeup_waiter¾s zStreamReader._wakeup_waitercCs ||_dSrr~)r8r(rrrrcÆszStreamReader.set_transportcCs*|jr&t|jƒ|jkr&d|_|j ¡dSr3)r5r•rr‹rZÚresume_readingr<rrrÚ_maybe_resume_transportÊsz$StreamReader._maybe_resume_transportcCsd|_| ¡dSrC)rŽr—r<rrrrhÏszStreamReader.feed_eofcCs|jo |j Sr)rŽrr<rrrÚat_eofÓszStreamReader.at_eofcCst|sdS|j |¡| ¡|jdk rp|jspt|jƒd|jkrpz|j ¡Wntk rhd|_YnXd|_dS)NrT) rÚextendr—rZr5r•r‹Z pause_readingrKr€rrrri×s  ÿþ zStreamReader.feed_datacÃsX|jdk rt|›dƒ‚|jr.d|_|j ¡|j ¡|_z|jIdHW5d|_XdS)NzF() called while another coroutine is already waiting for incoming dataF)rÚ RuntimeErrorr5rZr˜r4rI)r8Z func_namerrrÚ_wait_for_dataís ÿ  zStreamReader._wait_for_datac Ãsºd}t|ƒ}z| |¡IdH}Wn”tjk rN}z|jWY¢Sd}~XYnhtjk r´}zH|j ||j¡r„|jd|j|…=n |j  ¡|  ¡t |j dƒ‚W5d}~XYnX|S)Nó r) r•Ú readuntilr ÚIncompleteReadErrorÚpartialÚLimitOverrunErrorrÚ startswithÚconsumedÚclearr™rŠÚargs)r8ÚsepÚseplenÚlineÚerrrÚreadline s  zStreamReader.readlineržcÃsüt|ƒ}|dkrtdƒ‚|jdk r(|j‚d}t|jƒ}|||kr||j ||¡}|dkrZq´|d|}||jkr|t d|¡‚|jr¢t |jƒ}|j  ¡t  |d¡‚|  d¡IdHq,||jkrÊt d|¡‚|jd||…}|jd||…=|  ¡t |ƒS)Nrz,Separator should be at least one-byte stringéÿÿÿÿr z2Separator is not found, and chunk exceed the limitrŸz2Separator is found, but chunk is longer than limit)r•rŠrrÚfindr‹r r¢rŽÚbytesr¥r rr™)r8Z separatorr¨ÚoffsetZbuflenZisepÚchunkrrrrŸ(s>     þ    ÿzStreamReader.readuntilr¬cÃsœ|jdk r|j‚|dkrdS|dkrVg}| |j¡IdH}|s@qL| |¡q(d |¡S|jsr|jsr| d¡IdHt|jd|…ƒ}|jd|…=|  ¡|S)NrrÚread) rr±r‹rxrzrrŽrr®r™)r8ÚnZblocksÚblockrjrrrr±ƒs"     zStreamReader.readcÃsÀ|dkrtdƒ‚|jdk r |j‚|dkr,dSt|jƒ|krr|jr`t|jƒ}|j ¡t ||¡‚|  d¡IdHq,t|jƒ|kr–t|jƒ}|j ¡nt|jd|…ƒ}|jd|…=|  ¡|S)Nrz*readexactly size can not be less than zerorÚ readexactly) rŠrr•rrŽr®r¥r r rr™)r8r²Z incompleterjrrrr´µs&       zStreamReader.readexactlycCs|Srrr<rrrÚ __aiter__ÞszStreamReader.__aiter__cÃs| ¡IdH}|dkrt‚|S)Nr)r«ÚStopAsyncIteration)r8ÚvalrrrÚ __anext__ászStreamReader.__anext__)rž)r¬)rOrPrQrVr–r9r}rnrDr—rcr™rhršrirr«rŸr±r´rµr¸rrrrr†s$  [ 2)r)NN)NN)N)N)Ú__all__Zsocketr’r!rSÚhasattrÚr r r r rÚlogrZtasksrr–rrrrZProtocolr2rrrrrrrÚsF        ÿ !ÿ ' ÿ ÿ DkP