
    Yf                         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$dS )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                      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'd	S )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                      d S N _s    T/var/www/html/env/lib/python3.11/site-packages/twisted/application/runner/_runner.py<lambda>zRunner.<lambda>C   s         c                      d S r#   r$   r%   s    r'   r(   zRunner.<lambda>E   s    $ r)   returnNc                 B   | j         }|                                  	 |5  |                                  |                                  |                                  ddd           dS # 1 swxY w Y   dS # t
          $ r t          t          j        d           Y dS 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:::FF	s4   A6 =A)A6 )A--A6 0A-1A6 6$BBc                    | j         }| j        r|t          u rt          t          j        d           dS 	 |                                }nQ# t          $ r t          t          j        d           Y dS t          $ r t          t          j
        d           Y dS w xY w|                                  | j                            d|           t          |t                     t          t          j                   dS dS )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CC	llnn   Z(*DEEE&   Z*,?@@@
 INN7SNAAAg!"""F1	 	s   A
 
$B1#BBc                     | j         }| j        } ||          }t          | j                  }t	          ||g          }t          j        |g           dS )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|   sp     -!%!=00993 1
 
 
 1CTBUVV(*;)<=====r)   c                     | j                             | j                   | j                            d           | j                                          dS )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   sL    
 	%%d&6777	,---r)   c                 *     | j         di | j         dS )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7D677777r)   c                 *     | j         di | j         dS )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)   )r+   N)(__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 688Dv<(((Hv8[999HFe,,,Ev=(-HHHv66222H$fvh/0:M   6x	2<L<LMMML"FS(9774==QQQV)!4>N>NOOON$f'#s(*;WWT]]SSS   &   B> > > >$   8 8 8 8< < < < < <r)   r   N)%rZ   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>rh      s  
                    1 1 1 1 1 1 1 1 1 1 1 1 ' ' ' ' ' ' ' ' ' ' $ $ $ $ $ $ 4 4 4 4 4 4                  $ # # # # # # # U U U U U U U U U U U U dF< F< F< F< F< F< F< F< F< F<r)   