%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib64/python2.7/site-packages/tornado/platform/
Upload File :
Create Path :
Current File : //usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyo

�
��L]c@�s�dZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
mZddlmZddlmZmZmZmZmZddlmZmZddlmZddlZddlZddlZddlZdd	l m!Z!dd
l"m#Z#ddl$m%Z%ddl&m'Z'ddl(Z&dd
l)m*Z*ddl+m,Z,ddl-m.Z.m/Z/ddl(m0Z0ddl1m2Z2e!e�de3fd��Y�Z4e!ee�defd��Y�Z5de5fd��YZ6dd�Z8e!ee�de3fd��Y�Z9de&j:j0fd��YZ;de,fd��YZ<e=e'j>d�r�e'j>j?e�d ��Z@ndS(!sBridges between the Twisted reactor and Tornado IOLoop.

This module lets you run applications and libraries written for
Twisted in a Tornado application.  It can be used in two modes,
depending on which library's underlying event loop you want to use.

This module has been tested with Twisted versions 11.0.0 and newer.

Twisted on Tornado
------------------

`TornadoReactor` implements the Twisted reactor interface on top of
the Tornado IOLoop.  To use it, simply call `install` at the beginning
of the application::

    import tornado.platform.twisted
    tornado.platform.twisted.install()
    from twisted.internet import reactor

When the app is ready to start, call `IOLoop.current().start()`
instead of `reactor.run()`.

It is also possible to create a non-global reactor by calling
`tornado.platform.twisted.TornadoReactor(io_loop)`.  However, if
the `IOLoop` and reactor are to be short-lived (such as those used in
unit tests), additional cleanup may be required.  Specifically, it is
recommended to call::

    reactor.fireSystemEvent('shutdown')
    reactor.disconnectAll()

before closing the `IOLoop`.

Tornado on Twisted
------------------

`TwistedIOLoop` implements the Tornado IOLoop interface on top of the Twisted
reactor.  Recommended usage::

    from tornado.platform.twisted import TwistedIOLoop
    from twisted.internet import reactor
    TwistedIOLoop().install()
    # Set up your tornado application as usual using `IOLoop.instance`
    reactor.run()

`TwistedIOLoop` always uses the global Twisted reactor.
i(tabsolute_importtdivisiontprint_functiontwith_statementN(tDeferred(tPosixReactorBase(t
IReactorFDSettIDelayedCalltIReactorTimetIReadDescriptortIWriteDescriptor(tfailuretlog(terror(timplementer(tFuture(tutf8(tgen(tapp_log(tResolver(tNullContexttwrap(tIOLoop(ttimedelta_to_secondstTornadoDelayedCallcB�sMeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	RS(sDelayedCall object for Tornado.cO�se||_tj|||�|_|jj�||_|jjj|j|j�|_	t
|_dS(N(t_reactort	functoolstpartialt_functsecondst_timet_io_looptadd_timeoutt_calledt_timeouttTruet_active(tselftreactorRtftargstkw((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt__init__gs	cC�sHt|_|jj|�y|j�Wntjddt�nXdS(Ns_called caught exceptiontexc_info(tFalseR$Rt_removeDelayedCallRRR
R#(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR!os	cC�s|jS(N(R(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytgetTimewscC�s3t|_|jjj|j�|jj|�dS(N(R,R$RRtremove_timeoutR"R-(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytcancelzs	cC�sJ|jjj|j�|j|7_|jjj|j|j�|_dS(N(RRR/R"RR R!(R%R((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytdelayscC�sQ|jjj|j�|jj�||_|jjj|j|j�|_dS(N(RRR/R"RRR R!(R%R((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytreset�scC�s|jS(N(R$(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytactive�s(
t__name__t
__module__t__doc__R*R!R.R0R1R2R3(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRds						tTornadoReactorcB�s�eZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(sTwisted reactor built on the Tornado IOLoop.

    Since it is intended to be used in applications where the top-level
    event loop is ``io_loop.start()`` rather than ``reactor.run()``,
    it is implemented a little differently than other Twisted reactors.
    We override `mainLoop` instead of `doIteration` and must implement
    timed call functionality on top of `IOLoop.add_timeout` rather than
    using the implementation in `PosixReactorBase`.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.
    c�s�|stjjj�}n|�_i�_i�_i�_i�_t	j
���jdd�j��fd�}�jj
|�dS(Ntduringtshutdownc�s�js�jd�ndS(Ntstartup(t_startedtfireSystemEvent((R%(s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytstart_if_necessary�s	(ttornadotioloopRtcurrentRt_readerst_writerst_fdst
_delayedCallsRR*taddSystemEventTriggertcrashtadd_callback(R%tio_loopR=((R%s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR*�s					
cC�s
|jj�S(N(Rttime(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR�scO�s)t|||||�}t|j|<|S(N(RR#RD(R%RR'R(R)tdc((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt	callLater�s
cC�s#g|jD]}|jr
|^q
S(N(RDR$(R%tx((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytgetDelayedCalls�scC�s ||jkr|j|=ndS(N(RD(R%RJ((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR-�scO�s*t��|jj|||�WdQXdS(s@See `twisted.internet.interfaces.IReactorThreads.callFromThread`N(RRRG(R%R'R(R)((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytcallFromThread�s
cC�sdS(N((R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytinstallWaker�scC�sdS(N((R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytwakeUp�scC�s�||jkrdS|j|\}}|r�d}|j�dkrStj�}n%|tj@rxtj||j	�}n|dkr�|tj
@r�tj�}n|dk	r�|j|�|jt
j|��q�n|r�d}|j�dkrtj�}n%|tj@r'tj||j�}n|dkrO|tj
@rOtj�}n|dk	r�|j|�|jt
j|��q�ndS(Ni����(RCtNonetfilenoR
tConnectionLostRtREADRtcallWithLoggertdoReadtERRORtremoveReadertreadConnectionLostRtFailuretWRITEtdoWritetremoveWritertwriteConnectionLost(R%tfdteventstreadertwriterterr((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt_invoke_callback�s2



cC�s�||jkrdS|j�}||j|<||jkr�|j|\}}||f|j|<|r�|jj|tjtjB�q�n?t��4|df|j|<|jj
||jtj�WdQXdS(s@Add a FileDescriptor for notification of data available to read.N(RARRRCRtupdate_handlerRRTR[RRQtadd_handlerRd(R%RaR_t_Rb((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt	addReader�s
#
cC�s�||jkrdS|j�}||j|<||jkr�|j|\}}||f|j|<|r�|jj|tjtjB�q�n?t��4d|f|j|<|jj
||jtj�WdQXdS(sAAdd a FileDescriptor for notification of data available to write.N(RBRRRCRReRRTR[RRQRfRd(R%RbR_RaRg((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt	addWriters
#
cC�s�||jkr�|jj|�}|j|\}}|rfd|f|j|<|jj|tj�q�|j|=|jj|�ndS(s?Remove a Selectable for notification of data available to read.N(	RAtpopRCRQRReRR[tremove_handler(R%RaR_RgRb((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRXs
cC�s�||jkr�|jj|�}|j|\}}|rf|df|j|<|jj|tj�q�|j|=|jj|�ndS(s@Remove a Selectable for notification of data available to write.N(	RBRjRCRQRReRRTRk(R%RbR_RaRg((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR]'s
cC�s|j|j|j�S(N(t
_removeAllRARB(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt	removeAll8scC�s
|jj�S(N(RAtkeys(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt
getReaders;scC�s
|jj�S(N(RBRn(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt
getWriters>scC�s6tj|�tj|jd�}|jj|�dS(NR9(RtstopRRR<RRG(R%t
fire_shutdown((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRqDs
cC�stj|�|jj�dS(N(RRFRRq(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRFIs
cC�std��dS(NtdoIteration(tNotImplementedError(R%R1((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRsMscC�s|jj�dS(N(Rtstart(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytmainLoopPsN(R4R5R6RQR*RRKRMR-RNRORPRdRhRiRXR]RmRoRpRqRFRsRv(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR7�s*
																		t_TestReactorcB�s5eZdZd�Zddd�Zddd�ZRS(s�Subclass of TornadoReactor for use in unittests.

    This can't go in the test.py file because of import-order dependencies
    with the Twisted reactor test builder.
    cC�stt|�jt��dS(N(tsuperRwR*R(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR*Zsi2tcC�s4|sd}ntt|�j||d|d|�S(Ns	127.0.0.1tbacklogt	interface(RxRwt	listenTCP(R%tporttfactoryRzR{((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR|^s	i cC�s4|sd}ntt|�j||d|d|�S(Ns	127.0.0.1R{t
maxPacketSize(RxRwt	listenUDP(R%R}tprotocolR{R((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR�es	(R4R5R6R*R|R�(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRwTs	cC�sE|stjjj�}nt|�}ddlm}||�|S(s�Install this package as the default Twisted reactor.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.
    i(tinstallReactor(R>R?RR@R7ttwisted.internet.mainR�(RHR&R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytinstallls
t_FDcB�s>eZd�Zd�Zd�Zd�Zd�Zd�ZRS(cC�s:||_||_||_t|_t|_t|_dS(N(R_tfileobjthandlerR,treadingtwritingtlost(R%R_R�R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR*|s					cC�s|jS(N(R_(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRR�scC�s,|js(|j|jtjjj�ndS(N(R�R�R�R>R?RRT(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRV�s	cC�s,|js(|j|jtjjj�ndS(N(R�R�R�R>R?RR[(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR\�s	cC�s5|js1|j|jtjjj�t|_ndS(N(R�R�R�R>R?RRWR#(R%treason((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytconnectionLost�s	cC�sdS(NRy((R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt	logPrefix�s(R4R5R*RRRVR\R�R�(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR�zs					t
TwistedIOLoopcB�sweZdZdd�Zed�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�ZRS(
s�IOLoop implementation that runs on Twisted.

    Uses the global Twisted reactor by default.  To create multiple
    `TwistedIOLoops` in the same process, you must pass a unique reactor
    when constructing each one.

    Not compatible with `tornado.process.Subprocess.set_exit_callback`
    because the ``SIGCHLD`` handlers used by Tornado and Twisted conflict
    with each other.
    cK�sftt|�j|�|dkr=ddl}|jj}n||_i|_|jj|j	�dS(Ni(
RxR�t
initializeRQttwisted.internet.reactortinternetR&tfdstcallWhenRunningtmake_current(R%R&tkwargsttwisted((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR��s		cC�sn|j}|jj�x!|jj�D]}|j�q&W|rjx'|j�D]}|j|j�qMWndS(N(R�R&RmRMR0tvaluestclose_fdR�(R%tall_fdsR�tcR_((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytclose�s	
cC�s�||jkr"td|��n|j|�\}}t||t|��|j|<|tjjj@r�t	|j|_
|jj|j|�n|tjjj
@r�t	|j|_|jj|j|�ndS(Nsfd %s added twice(R�t
ValueErrortsplit_fdR�RR>R?RRTR#R�R&RhR[R�Ri(R%R_R�R`R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRf�scC�s-|j|�\}}|tjjj@re|j|js�t|j|_|jj	|j|�q�n:|j|jr�t
|j|_|jj|j|�n|tjjj@r�|j|j
s)t|j|_
|jj|j|�q)n:|j|j
r)t
|j|_
|jj|j|�ndS(N(R�R>R?RRTR�R�R#R&RhR,RXR[R�RiR](R%R_R`R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRe�scC�s�|j|�\}}||jkr(dSt|j|_|j|jrb|jj|j|�n|j|jr�|jj|j|�n|j|=dS(N(	R�R�R#R�R�R&RXR�R](R%R_R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRk�scC�s|j�|jj�dS(N(t_setup_loggingR&trun(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRu�s
cC�s|jj�dS(N(R&RF(R%((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRq�scO�s�t|tj�r.t||j�d�}n-t|tj�rOt|�}ntd��|j	j
||jtj
t|�||��S(NisUnsupported deadline %r(t
isinstancetnumberstRealtmaxRItdatetimet	timedeltaRt	TypeErrorR&RKt
_run_callbackRRR(R%tdeadlinetcallbackR(R�R1((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR �s		cC�s|j�r|j�ndS(N(R3R0(R%ttimeout((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR/�scO�s/|jj|jtjt|�||��dS(N(R&RNR�RRR(R%R�R(R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRG�s	cO�s|j|||�dS(N(RG(R%R�R(R�((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pytadd_callback_from_signal�sN(R4R5R6RQR�R,R�RfReRkRuRqR R/RGR�(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR��s
										tTwistedResolvercB�s/eZdZdd�Zejdd��ZRS(s`Twisted-based asynchronous resolver.

    This is a non-blocking and non-threaded resolver.  It is
    recommended only when threads cannot be used, since it has
    limitations compared to the standard ``getaddrinfo``-based
    `~tornado.netutil.Resolver` and
    `~tornado.netutil.ThreadedResolver`.  Specifically, it returns at
    most one result, and arguments other than ``host`` and ``family``
    are ignored.  It may fail to resolve when ``family`` is not
    ``socket.AF_UNSPEC``.

    Requires Twisted 12.1 or newer.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.
    cC�s�|ptj�|_tjjj|�|_tjj	j
d�}tjjjd|j�}tjj
j
dd|j�}tjjj|||g�|_dS(Ns
/etc/hostsR&s/etc/resolv.conf(RR@RHR>tplatformR�R7R&tnamesthostsRtcachet
CacheResolvertclienttresolvet
ResolverChaintresolver(R%RHt
host_resolvertcache_resolvert
real_resolver((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR�sicc�s?tjjj|�r'|}tj}n�tjjj|�rN|}tj}n�|jj	t
|��}tj|j
�V}t|tj�r�|j�nKtjjj|�r�tj}n*tjjj|�r�tj}n	tj}|tjkr||krtd||f��n|||ffg}tj|��dS(Ns%Requested socket family %d but got %d(R�R�tabstracttisIPAddresstsockettAF_INETt
isIPv6AddresstAF_INET6R�t
getHostByNameRRtTasktaddBothR�RRZtraiseExceptiont	AF_UNSPECt	ExceptiontReturn(R%thostR}tfamilytresolvedtresolved_familytdeferredtresult((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR�s(
	N(R4R5R6RQR�Rt	coroutineR�(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyR�s
tregisterc�s/t���fd�}|j�j|��S(Nc�s;y|j�td��Wn�jtj��nXdS(Nserrback called without error(R�R�tset_exc_infotsysR+(R(R'(s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyterrbackAs

(RtaddCallbackst
set_result(tdR�((R's>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyRg=s	(AR6t
__future__RRRRR�RR�R�R�ttwisted.internet.abstractR�ttwisted.internet.deferRttwisted.internet.posixbaseRttwisted.internet.interfacesRRRR	R
ttwisted.pythonRRttwisted.internetR
ttwisted.names.cachettwisted.names.clientttwisted.names.hoststtwisted.names.resolvetzope.interfaceRttornado.concurrentRttornado.escapeRR>Rttornado.ioloopttornado.logRttornado.netutilRttornado.stack_contextRRRttornado.utilRtobjectRR7RwRQR�R�R?R�R�thasattrtconvert_yieldedR�Rg(((s>/usr/lib64/python2.7/site-packages/tornado/platform/twisted.pyt<module>AsL"(*�i;

Zerion Mini Shell 1.0