o
    ¯bò  ã                   @   s’   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„ dƒZdS )z
Run a Twisted application.
é    N)ÚSequence)Ú_exitWithSignal)ÚIReactorCoreÚ_ISupportsExitSignalCapturing)ÚOptionsÚ
UsageErroré   )Ú
ExitStatusÚexit)ÚRunner)ÚApplicationÚIServiceÚIServiceMakeré   )ÚTwistOptionsc                   @   s”   e Zd ZdZedee defdd„ƒZede	de
defdd	„ƒZed
ededdfdd„ƒZededdfdd„ƒZeejfdee ddfdd„ƒZdS )ÚTwistz$
    Run a Twisted application.
    ÚargvÚreturnc              
   C   s^   t ƒ }z| | dd… ¡ W |S  ty. } zttjd|› d|› �ƒ W Y d}~|S d}~w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Úe© r   úB/usr/lib/python3/dist-packages/twisted/application/twist/_twist.pyr      s   ý"€ýzTwist.optionsÚpluginr   c                 C   s&   |   |¡}t| 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Úapplicationr   r   r   r   +   s   



zTwist.serviceÚreactorr   Nc                 C   s   |  ¡  |  dd|j¡ dS )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   r   r   r   r#   ;   s   zTwist.startServiceÚtwistOptionsc                 C   sZ   t | d | d | d | d d�}| ¡  | d }t |¡r)|jdur+t|jƒ dS dS dS )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    r   r   r   r+   H   s   ü

þz	Twist.runc                 C   sT   |   |¡}|d }|j}|dusJ ‚| j|j| |jd�}|  ||¡ |  |¡ dS )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#   r+   )Úclsr   r   r    r/   r   r   r   r   Úmain\   s   
	þz
Twist.main)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   Ústrr   r   r   r   r   r   r   r#   r+   ÚclassmethodÚsysr   r3   r   r   r   r   r      s    "r   )r7   r;   Útypingr   Útwisted.application.appr   Útwisted.internet.interfacesr   r   Útwisted.python.usager   r   Úrunner._exitr	   r
   Úrunner._runnerr   r   r   r   r   Ú_optionsr   r   r   r   r   r   Ú<module>   s   