a 7êdg 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éNÚAF_UNIX)Úopen_unix_connectionÚstart_unix_serveré)Ú coroutines)Úevents)Ú exceptions)Úformat_helpers)Ú protocols)Úlogger)Úsleepi)ÚloopÚlimitc ‹sx|durt ¡}ntjdtddt||d}t||d‰|j‡fdd„||fi|¤Ž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ú+/usr/local/lib/python3.9/asyncio/streams.pyÚ5óz!open_connection..) r Úget_event_loopÚwarningsÚwarnÚDeprecationWarningrrÚcreate_connectionr) ÚhostÚportrrÚkwdsÚreaderÚ transportÚ_Úwriterrrrrs þ  ÿÿrc‹sNˆdurt ¡‰ntjdtdd‡‡‡fdd„}ˆj|||fi|¤ŽIdHS)Nrrrcstˆˆd}t|ˆˆd}|S©Nrr©rr©r)r©Úclient_connected_cbrrrrÚfactoryXs  ÿzstart_server..factory)r r!r"r#r$Ú create_server)r1r&r'rrr(r2rr0rr:s þrc‹sv|durt ¡}ntjdtddt||d}t||d‰|j‡fdd„|fi|¤ŽIdH\}}t|ˆ||ƒ}||fS)NrrrrrcsˆSrrrrrrrpr z&open_unix_connection..) r r!r"r#r$rrZcreate_unix_connectionr)Úpathrrr(r)r*r+r,rrrrds þ   ÿÿrc‹sLˆdurt ¡‰ntjdtdd‡‡‡fdd„}ˆj||fi|¤ŽIdHS)Nrrrcstˆˆd}t|ˆˆd}|Sr-r.r/r0rrr2~s  ÿz"start_unix_server..factory)r r!r"r#r$Zcreate_unix_server)r1r4rrr(r2rr0rr ts þr c@s>eZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „ZdS)ÚFlowControlMixinNcCs0|durt ¡|_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)r8r7Ú get_debugrÚdebug©r;rrrÚ pause_writingšs zFlowControlMixin.pause_writingcCsFd|_|j ¡rt d|¡|j}|durBd|_| ¡sB| d¡dS)NFz%r resumes writing)r8r7r=rr>r9ÚdoneÚ set_result©r;ÚwaiterrrrÚresume_writing s  zFlowControlMixin.resume_writingcCsVd|_|jsdS|j}|dur"dSd|_| ¡r4dS|durH| d¡n | |¡dS©NT)r:r8r9rArBÚ set_exception©r;ÚexcrDrrrÚconnection_lost¬s z FlowControlMixin.connection_lostcÃs<|jrtdƒ‚|jsdS|j}|j ¡}||_|IdHdS)NzConnection lost)r:ÚConnectionResetErrorr8r9r7Ú create_futurerCrrrÚ _drain_helper¼s zFlowControlMixin._drain_helpercCst‚dSr)ÚNotImplementedError©r;ÚstreamrrrÚ_get_close_waiterÇsz"FlowControlMixin._get_close_waiter)N) Ú__name__Ú __module__Ú __qualname__r<r@rErJrMrQrrrrr5‡s    r5csbeZdZdZd‡fdd„ Zedd„ƒZdd„Z‡fdd „Zd d „Z d d „Z dd„Z dd„Z ‡Z S)rNcsntƒj|d|dur,t |¡|_|j|_nd|_|dur@||_d|_d|_d|_ ||_ d|_ |j   ¡|_dS)NrF)Úsuperr<ÚweakrefÚrefÚ_stream_reader_wrÚ_source_tracebackÚ_strong_readerÚ_reject_connectionÚ_stream_writerÚ _transportÚ_client_connected_cbÚ _over_sslr7rLÚ_closed)r;Z stream_readerr1r©Ú __class__rrr<Ös  zStreamReaderProtocol.__init__cCs|jdurdS| ¡Sr)rXr?rrrÚ_stream_readerés z#StreamReaderProtocol._stream_readercCs®|jr6ddi}|jr|j|d<|j |¡| ¡dS||_|j}|durT| |¡| d¡du|_ |j durª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)r[rYr7Zcall_exception_handlerÚabortr]rcÚ set_transportÚget_extra_infor_r^rr\r Z iscoroutineZ create_taskrZ)r;r*Úcontextr)ÚresrrrÚconnection_madeïs0ÿ    þÿ  z$StreamReaderProtocol.connection_madecsx|j}|dur*|dur | ¡n | |¡|j ¡sV|durJ|j d¡n |j |¡tƒ |¡d|_d|_ d|_ dSr) rcÚfeed_eofrGr`rArBrUrJrXr\r])r;rIr)rarrrJ s     z$StreamReaderProtocol.connection_lostcCs|j}|dur| |¡dSr)rcÚ feed_data)r;Údatar)rrrÚ data_receivedsz"StreamReaderProtocol.data_receivedcCs$|j}|dur| ¡|jr dSdS)NFT)rcrkr_)r;r)rrrÚ eof_received s z!StreamReaderProtocol.eof_receivedcCs|jSr)r`rOrrrrQ+sz&StreamReaderProtocol._get_close_waitercCs"|j}| ¡r| ¡s| ¡dSr)r`rAÚ cancelledÚ exception)r;ÚclosedrrrÚ__del__.szStreamReaderProtocol.__del__)NN)rRrSrTrYr<ÚpropertyrcrjrJrnrorQrsÚ __classcell__rrrarrË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)r]Ú _protocolÚ_readerr7rLZ _complete_futrB)r;r*rr)rrrrr<@s  zStreamWriter.__init__cCs@|jjd|j›g}|jdur0| d|j›¡d d |¡¡S)Nú transport=zreader=ú<{}>ú )rbrRr]rwÚappendÚformatÚjoin©r;ÚinforrrÚ__repr__Js zStreamWriter.__repr__cCs|jSr©r]r?rrrr*PszStreamWriter.transportcCs|j |¡dSr)r]Úwrite©r;rmrrrr‚TszStreamWriter.writecCs|j |¡dSr)r]Ú writelinesrƒrrrr„WszStreamWriter.writelinescCs |j ¡Sr)r]Ú write_eofr?rrrr…ZszStreamWriter.write_eofcCs |j ¡Sr)r]Ú can_write_eofr?rrrr†]szStreamWriter.can_write_eofcCs |j ¡Sr)r]Úcloser?rrrr‡`szStreamWriter.closecCs |j ¡Sr)r]Ú is_closingr?rrrrˆcszStreamWriter.is_closingcÃs|j |¡IdHdSr)rvrQr?rrrÚ wait_closedfszStreamWriter.wait_closedNcCs|j ||¡Sr)r]rg)r;ÚnameÚdefaultrrrrgiszStreamWriter.get_extra_infocÃsL|jdur |j ¡}|dur |‚|j ¡r8tdƒIdH|j ¡IdHdS)Nr)rwrqr]rˆrrvrM)r;rIrrrÚdrainls   zStreamWriter.drain)N)rRrSrTr<r€rtr*r‚r„r…r†r‡rˆr‰rgrŒ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ƒ‚||_|dur*t ¡|_n||_tƒ|_d|_d|_d|_ d|_ d|_ |j  ¡rrt  t d¡¡|_dS)NrzLimit cannot be <= 0Fr )Ú ValueErrorÚ_limitr r!r7Ú bytearrayÚ_bufferÚ_eofÚ_waiterÚ _exceptionr]r8r=rÚ extract_stackÚsysÚ _getframerY)r;rrrrrr<Š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=rxZpausedryrz) rr{Úlenr‘rŽÚ_DEFAULT_LIMITr’r“r]r8r|r}r~rrrr€ s    zStreamReader.__repr__cCs|jSr)r“r?rrrrq²szStreamReader.exceptioncCs0||_|j}|dur,d|_| ¡s,| |¡dSr)r“r’rprGrHrrrrGµs zStreamReader.set_exceptioncCs*|j}|dur&d|_| ¡s&| d¡dSr)r’rprBrCrrrÚ_wakeup_waiter¾s zStreamReader._wakeup_waitercCs ||_dSrr)r;r*rrrrfÆszStreamReader.set_transportcCs*|jr&t|jƒ|jkr&d|_|j ¡dSr6)r8r˜rrŽr]Úresume_readingr?rrrÚ_maybe_resume_transportÊsz$StreamReader._maybe_resume_transportcCsd|_| ¡dSrF)r‘ršr?rrrrkÏszStreamReader.feed_eofcCs|jo |j Sr)r‘rr?rrrÚat_eofÓszStreamReader.at_eofcCsr|sdS|j |¡| ¡|jdurn|jsnt|jƒd|jkrnz|j ¡Wntyfd|_Yn0d|_dS)NrT) rÚextendršr]r8r˜rŽZ pause_readingrNrƒrrrrl×s  ÿþ  zStreamReader.feed_datacÃs^|jdurt|›dƒ‚|jr.d|_|j ¡|j ¡|_z|jIdHWd|_nd|_0dS)NzF() called while another coroutine is already waiting for incoming dataF)r’Ú RuntimeErrorr8r]r›r7rL)r;Ú func_namerrrÚ_wait_for_dataís ÿ  zStreamReader._wait_for_datac Ãsºd}t|ƒ}z| |¡IdH}Wn”tjyL}z|jWYd}~Sd}~0tjy´}zP|j ||j¡r€|jd|j|…=n |j  ¡|  ¡t |j dƒ‚WYd}~n d}~00|S)Nó r) r˜Ú readuntilr ÚIncompleteReadErrorÚpartialÚLimitOverrunErrorrÚ startswithÚconsumedÚclearrœrÚargs)r;ÚsepÚseplenÚlineÚerrrÚreadline s $zStreamReader.readliner¢cÃsüt|ƒ}|dkrtdƒ‚|jdur(|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˜rr“rÚfindrŽr r¦r‘Úbytesr©r¤r¡rœ)r;Ú separatorr¬ÚoffsetÚbuflenZisepÚchunkrrrr£(s<     þ    ÿzStreamReader.readuntilr°cÃsœ|jdur|j‚|dkrdS|dkrVg}| |j¡IdH}|s@qL| |¡q(d |¡S|jsr|jsr| d¡IdHt|jd|…ƒ}|jd|…=|  ¡|S)Nrr Úread) r“r·rŽr{r}rr‘r¡r²rœ)r;ÚnZblocksÚblockrmrrrr·ƒs"     zStreamReader.readcÃsÀ|dkrtdƒ‚|jdur |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) rr“r˜rr‘r²r©r r¤r¡rœ)r;r¸Z incompletermrrrrºµs&       zStreamReader.readexactlycCs|Srrr?rrrÚ __aiter__ÞszStreamReader.__aiter__cÃs| ¡IdH}|dkrt‚|S)Nr )r¯ÚStopAsyncIteration)r;ÚvalrrrÚ __anext__ászStreamReader.__anext__)r¢)r°)rRrSrTrYr™r<r€rqrGršrfrœrkrrlr¡r¯r£r·rºr»r¾rrrrr†s$  [ 2)r)NN)NN)N)N)Ú__all__Úsocketr•r"rVÚhasattrÚr r r rrÚlogrZtasksrr™rrrr ÚProtocolr5rrrrrrrÚs>        ÿ !ÿ ' ÿ ÿ DkP