Ë
    ojä  ã                   óè   — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZmZ d
dlmZmZ d
dlm Z m!Z!m"Z"m#Z#  ed¬«       G d„ d«      «       Z$y)z
Twisted application runner.
é    )Úkill)ÚSIGTERM)Ústderr)ÚAnyÚCallableÚMappingÚTextIO)ÚFactoryÚattribÚattrs)ÚNamedConstant)ÚIReactorCore)ÚFileLogObserverÚFilteringLogObserverÚLoggerÚLogLevelÚLogLevelFilterPredicateÚglobalLogBeginnerÚtextFileLogObserveré   )Ú
ExitStatusÚexit)ÚAlreadyRunningErrorÚInvalidPIDFileErrorÚIPIDFileÚnonePIDFileT)Úfrozenc                   óp  — e Zd ZdZ e«       Z ee¬«      Z ee	e
¬«      Z eed¬«      Z eeej                   ¬«      Z eee¬«      Z eeegef   e¬«      Z eed   d„ ¬«      Z eeeef    ee«      ¬«      Z eed   d„ ¬«      Z  eeeef    ee«      ¬«      Z!dd	„Z"dd
„Z#dd„Z$dd„Z%dd„Z&dd„Z'y)ÚRunnera  
    Twisted application runner.

    @cvar _log: The logger attached to this class.

    @ivar _reactor: The reactor to start and run the application in.
    @ivar _pidFile: The file to store the running process ID in.
    @ivar _kill: Whether this runner should kill an existing running
        instance of the application.
    @ivar _defaultLogLevel: The default log level to start the logging
        system with.
    @ivar _logFile: A file stream to write logging output to.
    @ivar _fileLogObserverFactory: A factory for the file log observer to
        use when starting the logging system.
    @ivar _whenRunning: Hook to call after the reactor is running;
        this is where the application code that relies on the reactor gets
        called.
    @ivar _whenRunningArguments: Keyword arguments to pass to
        C{whenRunning} when it is called.
    @ivar _reactorExited: Hook to call after the reactor exits.
    @ivar _reactorExitedArguments: Keyword arguments to pass to
        C{reactorExited} when it is called.
    )Útype)r    ÚdefaultF).Nc                   ó   — y ©N© ©Ú_s    úD/usr/lib/python3/dist-packages/twisted/application/runner/_runner.pyú<lambda>zRunner.<lambda>C   ó   � ó    c                   ó   — y r#   r$   r%   s    r'   r(   zRunner.<lambda>E   r)   r*   Nc                 ó  — | j                   }| j                  «        	 |5  | j                  «        | j                  «        | j	                  «        ddd«       y# 1 sw Y   yxY w# t
        $ r t        t        j                  d«       Y yw xY w)z#
        Run this command.
        NzAlready running.)	Ú_pidFileÚkillIfRequestedÚstartLoggingÚstartReactorÚreactorExitedr   r   r   Ú	EX_CONFIG)ÚselfÚpidFiles     r'   Úrunz
Runner.runH   s~   € ð —-‘-ˆà×ÑÔð		Øñ %Ø×!Ñ!Ô#Ø×!Ñ!Ô#Ø×"Ñ"Ô$÷%÷ %ñ %ûô
 #ò 	Ü”×%Ñ%Ð'9Ô:áð	ús.   žA&  1AÁA& ÁA#ÁA& Á#A& Á&#BÂBc                 óä  — | j                   }| j                  r‹|t        u rt        t        j
                  d«       y	 |j                  «       }| j                  «        | j                  j                  d|¬«       t        |t        «       t        t        j                   «       yy# t        $ r t        t        j                  d«       Y yt        $ r t        t        j                  d«       Y yw xY w)zj
        If C{self._kill} is true, attempt to kill a running instance of the
        application.
        zNo PID file specified.NzUnable to read PID file.zInvalid PID file.zTerminating process: {pid})Úpid)r-   Ú_killr   r   r   ÚEX_USAGEÚreadÚOSErrorÚEX_IOERRr   Ú
EX_DATAERRr/   Ú_logÚinfor   r   ÚEX_OK)r3   r4   r7   s      r'   r.   zRunner.killIfRequested[   sÄ   € ð
 —-‘-ˆà�:Š:Øœ+Ñ%Ü”Z×(Ñ(Ð*BÔCàð	Ø—l‘l“n�ð ×ÑÔØ�I‰I�N‰NÐ7¸SˆNÔAä�”gÔä”×!Ñ!Ô"àð1 øô ò Ü”Z×(Ñ(Ð*DÔEáÜ&ò Ü”Z×*Ñ*Ð,?Ô@áðús   ½B% Â%#C/Ã
"C/Ã.C/c                 ó¶   — | j                   }| j                  } ||«      }t        | j                  ¬«      }t	        ||g«      }t        j                  |g«       y)z=
        Start the L{twisted.logger} logging system.
        )ÚdefaultLogLevelN)Ú_logFileÚ_fileLogObserverFactoryr   Ú_defaultLogLevelr   r   ÚbeginLoggingTo)r3   ÚlogFileÚfileLogObserverFactoryÚfileLogObserverÚlogLevelPredicateÚfilteringObservers         r'   r/   zRunner.startLogging|   s\   € ð —-‘-ˆà!%×!=Ñ!=Ðá0°Ó9ˆä3Ø ×1Ñ1ô
Ðô 1°ÐCTÐBUÓVÐä×(Ñ(Ð*;Ð)<Õ=r*   c                 ó¸   — | j                   j                  | j                  «       | j                  j	                  d«       | j                   j                  «        y)z’
        Register C{self._whenRunning} with the reactor so that it is called
        once the reactor is running, then start the reactor.
        zStarting reactor...N)Ú_reactorÚcallWhenRunningÚwhenRunningr>   r?   r5   ©r3   s    r'   r0   zRunner.startReactorŽ   s=   € ð
 	�‰×%Ñ% d×&6Ñ&6Ô7à�	‰	�‰Ð,Ô-Ø�‰×ÑÕr*   c                 ó<   —  | j                   di | j                  ¤Ž y)z—
        Call C{self._whenRunning} with C{self._whenRunningArguments}.

        @note: This method is called after the reactor starts running.
        Nr$   )Ú_whenRunningÚ_whenRunningArgumentsrP   s    r'   rO   zRunner.whenRunning˜   s   € ð 	ˆ×ÑÑ7˜D×6Ñ6Ó7r*   c                 ó<   —  | j                   di | j                  ¤Ž y)z’
        Call C{self._reactorExited} with C{self._reactorExitedArguments}.

        @note: This method is called after the reactor exits.
        Nr$   )Ú_reactorExitedÚ_reactorExitedArgumentsrP   s    r'   r1   zRunner.reactorExited    s   € ð 	ˆ×ÑÑ;˜d×:Ñ:Ó;r*   )ÚreturnN)(Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r>   r   r   rM   r   r   r-   Úboolr8   r   r   r?   rE   r	   r   rC   r   r   r   rD   rR   r   Ústrr   r
   ÚdictrS   rU   rV   r5   r.   r/   r0   rO   r1   r$   r*   r'   r   r      så   „ ññ0 ‹8€Dá˜<Ô(€HÙ˜8¨[Ô9€HÙ˜ eÔ,€EÙ =¸(¿-¹-ÔHÐÙ˜6¨6Ô2€HÙ$Ø�v�h Ð/Ñ0Ð:MôÐñ ˜x¨	Ñ2Ñ<LÔM€LÙ"¨°°S°Ñ(9Á7È4Ã=ÔQÐÙ ¨)Ñ!4Ñ>NÔO€NÙ$¨'°#°s°(Ñ*;ÁWÈTÃ]ÔSÐóó&óB>ó$ó8ô<r*   r   N)%r[   Úosr   Úsignalr   Úsysr   Útypingr   r   r   r	   Úattrr
   r   r   Ú
constantlyr   Útwisted.internet.interfacesr   Útwisted.loggerr   r   r   r   r   r   r   Ú_exitr   r   Ú_pidfiler   r   r   r   r   r$   r*   r'   ú<module>ri      sb   ðñ
õ Ý Ý ß 1Ó 1ç 'Ñ 'Ý $å 4÷÷ ñ ÷ $ß UÓ Uñ ˆdÔ÷F<ð F<ó ñF<r*   