
    Vh                         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    R/home/dcms/DCMS/lib/python3.12/site-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	lln IINN7SN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CTBU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     	7D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 8D<(H8[9He,E=(--H662H$vh/0:M x	2<LML"S(974=Q)!4>NON$'#s(*;WT]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*   