3 \+@sdddgZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z dd lm Z dd l mZejd Zejj oeejjd ZyejZejZWnek rdZdZYnXy ejZWnek rd dZYnXyddlmZ m!Z"Wne#k r*dZ Z"YnXddZ$e$Z%[$ddZ&GdddZ'ddZe(Z)ddZej*e'fZ+e dk re+e f7Z+edk refe+Z+ddZ,ddZ-dS) coroutineiscoroutinefunction iscoroutineN)compat) constants)events) base_futures)loggerZ YIELD_FROMZPYTHONASYNCIODEBUGcCsdS)NF)funcr r */usr/lib64/python3.6/asyncio/coroutines.py/sr) Coroutine AwaitablecCsFGddd}dd}d}|}||}t||j||j|fkS) Nc@s,eZdZddZddZddZddZd S) z!has_yield_from_bug..MyGencSs d|_dS)N) send_args)selfr r r __init__;sz*has_yield_from_bug..MyGen.__init__cSs|S)Nr )rr r r __iter__=sz*has_yield_from_bug..MyGen.__iter__cSsdS)N*r )rr r r __next__?sz*has_yield_from_bug..MyGen.__next__cWs ||_dS)N)r)rZwhatr r r sendAsz&has_yield_from_bug..MyGen.sendN)__name__ __module__ __qualname__rrrrr r r r MyGen:srcss|EdHdS)Nr )genr r r yield_from_genDsz*has_yield_from_bug..yield_from_genr)rrr)nextrr)rrvaluercoror r r has_yield_from_bug9s  r#cCs t|dS)N) CoroWrapper)rr r r debug_wrapperPsr%c@seZdZd%ddZddZddZdd Zer8d d Znd d Zd&d dZ ddZ e ddZ e ddZ e ddZejrddZe ddZe ddZe ddZe dd Ze d!d"Zd#d$ZdS)'r$NcCsZtj|stj|st|||_||_tjtj d|_ t |dd|_ t |dd|_ dS)Nrrr)inspect isgeneratorrAssertionErrorrr r extract_stacksys _getframe_source_tracebackgetattrrr)rrr r r r r[s zCoroWrapper.__init__cCs@t|}|jr0|jd}|d|d|df7}d|jj|fS)Nrz, created at %s:%srz<%s %s>)_format_coroutiner, __class__r)r coro_reprframer r r __repr__cs  zCoroWrapper.__repr__cCs|S)Nr )rr r r rjszCoroWrapper.__iter__cCs |jjdS)N)rr)rr r r rmszCoroWrapper.__next__cGsBtj}|j}|jdkst|jj|jtkr6|d}|jj |S)Nr) r*r+f_backf_lastir(f_codeco_code _YIELD_FROMrr)rr!r2Zcallerr r r rus zCoroWrapper.sendcCs |jj|S)N)rr)rr!r r r r}scCs|jj|||S)N)rthrow)rtyper! tracebackr r r r9szCoroWrapper.throwcCs |jjS)N)rclose)rr r r r<szCoroWrapper.closecCs|jjS)N)rgi_frame)rr r r r=szCoroWrapper.gi_framecCs|jjS)N)r gi_running)rr r r r>szCoroWrapper.gi_runningcCs|jjS)N)rgi_code)rr r r r?szCoroWrapper.gi_codecCs,t|jdd}|dk r(tdj|j||S)Ncr_awaitz;Cannot await on coroutine {!r} while it's awaiting for {!r})r-r RuntimeErrorformat)rr@r r r __await__s  zCoroWrapper.__await__cCs|jjS)N)r gi_yieldfrom)rr r r rDszCoroWrapper.gi_yieldfromcCs|jjS)N)rr@)rr r r r@szCoroWrapper.cr_awaitcCs|jjS)N)r cr_running)rr r r rEszCoroWrapper.cr_runningcCs|jjS)N)rcr_code)rr r r rFszCoroWrapper.cr_codecCs|jjS)N)rcr_frame)rr r r rGszCoroWrapper.cr_framecCst|dd}t|dd}|dkr,t|dd}|dk r|jd krd|}t|df}|rdjtj|}|dtjd 7}||j7}tj |dS) Nrr=rGrz%r was never yielded fromr,zB Coroutine object created at (most recent call last, truncated to z last lines): r.) r-r5joinr; format_listrZDEBUG_STACK_DEPTHrstripr error)rrr2msgtbr r r __del__s     zCoroWrapper.__del__)N)NN)rrrrr3rr_YIELD_FROM_BUGrr9r<propertyr=r>r?rZPY35rCrDr@rErFrGrOr r r r r$Xs(           r$csptr StjrntjfddtsNtdkrD}qft}ntjfdd}t|_|S)zDecorator to mark coroutines. If the coroutine is not yielded from before it is destroyed, an error message is logged. c ?sv||}tj|s(tj|s(t|tr4|EdH}n>tdk rry |j}Wntk rZYnXt|trr|EdH}|S)N) r Zisfuturer&r' isinstancer$ _AwaitableABCrCAttributeError)argskwresZ await_meth)r r r r"s      zcoroutine..coroNcs@t||d}|jr |jd=tdd|_tdd|_|S)N)r rrrr.)r$r,r-rr)rUkwdsw)r"r r r wrappers zcoroutine..wrapper)_inspect_iscoroutinefunctionr&isgeneratorfunction functoolswraps_DEBUG_types_coroutine _is_coroutine)r rZr )r"r r rs   cCst|ddtkpt|S)z6Return True if func is a decorated coroutine function.raN)r-rar[)r r r r rscCs t|tS)z)Return True if obj is a coroutine object.)rR_COROUTINE_TYPES)objr r r rsc Cs&t|s tt|d rt|d rt|dt|dt|j}dj|}d}y |j}Wn4tk ry |j }Wntk rYnXYnX|rdj|S|Sd}t |t r|j }|j }|dk rdj|}n|}|dkrtj|fi}d}t|do|jr|j}nt|dr|jr|j}d}t|dr>|jr>|j}nt|d rX|jrX|j}d }|rp|jrp|j}d }|}t |t rtj|j  r|j dk rtj|j } | dk r| \}}|dkrd |||f}nd |||f}n:|dk r|j}d|||f}n|r"|j}d |||f}|S)NrFr?rrz{}()Fz {} runningrGr=zrz%s done, defined at %s:%sz%s running, defined at %s:%sz%s running at %s:%s)rr(hasattrr-r:rrBrErTr>rRr$r rrZ_format_callbackrFr?rGr= co_filenamer&r\Z_get_function_sourcef_linenoco_firstlineno) r"Z coro_nameZrunningr Z coro_codeZ coro_framefilenamelinenor1sourcer r r r/sz               r/).__all__r]r&Zopcodeosr*r;typesrHrrrr logr Zopmapr8flagsignore_environmentboolenvirongetr_rr` CoroutineTypeZ_types_CoroutineTyperTrr[collections.abcrZ _CoroutineABCrrS ImportErrorr#rPr%r$objectra GeneratorTyperbrr/r r r r sZ         j: