
    Vh                         d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZmZ dd	lmZ dd
lmZmZmZ ddlmZ  G d d      Zy)z
Run a Twisted application.
    N)Sequence)_exitWithSignal)IReactorCore_ISupportsExitSignalCapturing)Options
UsageError   )
ExitStatusexit)Runner)ApplicationIServiceIServiceMaker   )TwistOptionsc                       e Zd ZdZedee   defd       Zede	de
defd       Zeded	edd
fd       Zededd
fd       Zeej$                  fdee   dd
fd       Zy
)Twistz$
    Run a Twisted application.
    argvreturnc                     t               }	 |j                  | dd        |S # t        $ r+}t        t        j
                  d| d|        Y d}~|S d}~ww xY w)z
        Parse command line options.

        @param argv: Command line arguments.
        @return: The parsed options.
        r   NzError: z

)r   parseOptionsr   r   r
   EX_USAGE)r   optionses      P/home/dcms/DCMS/lib/python3.12/site-packages/twisted/application/twist/_twist.pyr   zTwist.options   se     .	B  ab*   	B$$s$wi&@AA	Bs   " 	A AApluginr   c                     | j                  |      }t        | j                        }|j                  |       t	        |      S )a
  
        Create the application service.

        @param plugin: The name of the plugin that implements the service
            application to run.
        @param options: Options to pass to the application.
        @return: The created application service.
        )makeServicer   tapnamesetServiceParentr   )r   r   serviceapplications       r   r!   zTwist.service+   s;     $$W-!&..1  -$$    reactorr!   Nc                 ^    |j                          | j                  dd|j                         y)z
        Start the application service.

        @param reactor: The reactor to run the service with.
        @param service: The application service to run.
        beforeshutdownN)startServiceaddSystemEventTriggerstopService)r$   r!   s     r   r(   zTwist.startService;   s*     	 	%%h
G<O<OPr#   twistOptionsc                     t        | d   | d   | d   | d         }|j                          | d   }t        j                  |      r#|j                  t        |j                         yyy)z
        Run the application service.

        @param twistOptions: Command line options to convert to runner
            arguments.
        r$   logLevellogFilefileLogObserverFactory)r$   defaultLogLevelr.   r/   N)r   runr   
providedBy_exitSignalr   )r+   runnerr$   s      r   r1   z	Twist.runH   sv      +(4 +#/0H#I	
 	

y)(33G<"". 3 34 / =r#   c                     | j                  |      }|d   }|j                  }|J | j                  |j                  |   |j                        }| j                  ||       | j                  |       y)z
        Executable entry point for L{Twist}.
        Processes options and run a twisted reactor with a service.

        @param argv: Command line arguments.
        @type argv: L{list}
        r$   N)r   r   )r   
subCommandr!   plugins
subOptionsr(   r1   )clsr   r   r$   r6   r!   s         r   mainz
Twist.main\   s{     ++d#)$ ''
%%%++??:.&&  

 	'*r#   )__name__
__module____qualname____doc__staticmethodr   strr   r   r   r   r   r!   r   r(   r1   classmethodsysr   r:    r#   r   r   r      s     hsm     % % %H % % 
Ql 
QX 
Q$ 
Q 
Q 5, 54 5 5& (+  T  r#   r   )r>   rB   typingr   twisted.application.appr   twisted.internet.interfacesr   r   twisted.python.usager   r   runner._exitr
   r   runner._runnerr   r!   r   r   r   _optionsr   r   rC   r#   r   <module>rK      s6   
   3 S 4 + # : : "] ]r#   