Ϫfy+dZddlZddlZddlmZmZddlmZmZm Z ddl m Z ddl m Z ddlmZddlmZmZmZdd lmZdd lmZe eGd d eZdd Zy)z' asyncio-based reactor implementation. N)AbstractEventLoopget_event_loop)DictOptionalType) implementer)FileDescriptor) IReactorFDSet) _NO_FILEDESCPosixReactorBase_ContinuousPolling)Logger)callWithLoggerceZdZdZdZeZddeeffd Z dZ dZ dZ dZ d Zd Zd Zd Zd ZdZddZfdZfdZdZdZdZdZdZxZS)AsyncioSelectorReactora Reactor running on top of L{asyncio.SelectorEventLoop}. On POSIX platforms, the default event loop is L{asyncio.SelectorEventLoop}. On Windows, the default event loop on Python 3.7 and older is C{asyncio.WindowsSelectorEventLoop}, but on Python 3.8 and newer the default event loop is C{asyncio.WindowsProactorEventLoop} which is incompatible with L{AsyncioSelectorReactor}. Applications that use L{AsyncioSelectorReactor} on Windows with Python 3.8+ must call C{asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())} before instantiating and running L{AsyncioSelectorReactor}. F eventloopc | t}n|}tjdk(r ddlm}t ||rt d|||_i|_i|_ t||_ d|_ d|_ t|=y)Nwin32r)ProactorEventLoopz)ProactorEventLoop is not supported, got: )rsysplatformasyncior isinstance TypeError_asyncioEventloop_writers_readersr _continuousPolling _scheduledAt _timerHandlesuper__init__)selfr _eventloopr __class__s A/usr/lib/python3/dist-packages/twisted/internet/asyncioreactor.pyr"zAsyncioSelectorReactor.__init__0s  ,:,z-AsyncioSelectorReactor.stop..sr')r!rc callLaterr#r%s r&rczAsyncioSelectorReactor.stops   q,'r'cVt||jjyrW)r!crashrrcrqs r&rszAsyncioSelectorReactor.crashs   ##%r'cRd|_|j|jyrW)rrunUntilCurrent _reschedulerZs r&_onTimerzAsyncioSelectorReactor._onTimer s"   r'c|j}|v|jj|z}||_|j|jj |jj ||j|_yyrW)rertimerr cancelcall_atrw)r#reabs_times r&rvz"AsyncioSelectorReactor._reschedulesv,,.  --224w>H (D   ,!!((* $ 6 6 > >x WD  r'cPtj|||jyrW)r _moveCallLaterSoonerrv)r#tples r&r~z+AsyncioSelectorReactor._moveCallLaterSooners--dD9 r'ctj|||g|i|}|jj|j z}|j ||j kr|j |SrW)r rprryrerrv)r#secondsfargskwargsdcr|s r&rpz AsyncioSelectorReactor.callLatersi  ' 'gq J4 J6 J))..04<<>A    $43D3D(D     r'cRfd}jj|y)Nc2jdgiS)Nr)rp)rrrr#sr&roz7AsyncioSelectorReactor.callFromThread..%sNDNN1a9$9&9r')rcall_soon_threadsafe)r#rrrgs```` r&callFromThreadz%AsyncioSelectorReactor.callFromThread$s 9 33A6r'rW)T)__name__ __module__ __qualname____doc__ _asyncClosedrr6rrr"r-r=rDrIrOrTrYr]r`rfrkrcrsrwrvr~rpr __classcell__)r%s@r&rrs L 8D(+<"=65n >(.1.10 QQ-& ( & X7r'rc6t|}ddlm}||y)z Install an asyncio-based reactor. @param eventloop: The asyncio eventloop to wrap. If default, the global one is selected. r)installReactorN)rtwisted.internet.mainr)rreactorrs r&installr)s%Y/G47r'rW)rrBrrrrtypingrrrzope.interfacertwisted.internet.abstractr twisted.internet.interfacesr twisted.internet.posixbaser r r twisted.loggerrtwisted.python.logrrrrnr'r&rs`   5''&45 "- ]I7-I7I7X r'