HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/application/__pycache__/app.cpython-38.pyc
U

��W[�[�@s�ddlmZmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZddlmZmZddlmZddlmZddlmZmZmZmZmZmZdd	lm Z dd
l!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(dd
l'm)Z)Gdd�de*�Z+Gdd�de+�Z,Gdd�de+�Z-Gdd�de*�Z.Gdd�de*�Z/dd�Z0d2dd�Z1dd�Z2dd�Z3Gd d!�d!e*�Z4d"d#�Z5d$d%�Z6e Gd&d'�d'��Z7Gd(d)�d)ej8e7�Z9d*d+�Z:d,d-�Z;d.d/�Z<d0d1�Z=dS)3�)�absolute_import�division�print_functionN)�
attrgetter)�	copyright�plugin�logger)�service�reactors)�defer)�sob)�runtime�log�usage�failure�util�logfile)�	_oldStyle)�qual�namedAny�namedModule)�_ISupportsExitSignalCapturing)�installReactor)�
NoSuchReactorc@s eZdZdZdd�Zdd�ZdS)�_BasicProfilerz�
    @ivar saveStats: if C{True}, save the stats information instead of the
        human readable format
    @type saveStats: C{bool}

    @ivar profileOutput: the name of the file use to print profile data.
    @type profileOutput: C{str}
    cCs||_||_dS�N)�
profileOutput�	saveStats)�selfrr�r�9/usr/lib/python3/dist-packages/twisted/application/app.py�__init__)sz_BasicProfiler.__init__cCs d||f}|d7}t|��dS)z�
        Helper method to report an import error with a profile module. This
        has to be explicit because some of these modules are removed by
        distributions due to them being non-free.
        zFailed to import module %s: %sz�
This is most likely caused by your operating system not including
the module due to it being non-free. Either do not use the option
--profile, or install the module; your operating system vendor
may provide it in a separate package.
N)�
SystemExit)r�module�e�srrr �_reportImportError.sz!_BasicProfiler._reportImportErrorN)�__name__�
__module__�__qualname__�__doc__r!r&rrrr rs	rc@seZdZdZdd�ZdS)�
ProfileRunnerz1
    Runner for the standard profile module.
    c
Cs�zddl}Wn.tk
r:}z|�d|�W5d}~XYnX|��}|�|j�|jrd|�|j�n<t	j
t|jd�}t	_
z|�
�W5|t	j
t	_
}|��XdS)z:
        Run reactor under the standard profiler.
        rN�profile�a)r,�ImportErrorr&�Profile�runcall�runr�
dump_statsr�sys�stdout�open�close�print_stats)r�reactorr,r$�pZtmprrr r1DszProfileRunner.runN�r'r(r)r*r1rrrr r+?sr+c@seZdZdZdd�ZdS)�CProfileRunnerz)
    Runner for the cProfile module.
    c
Cs�zddl}ddl}Wn.tk
rB}z|�d|�W5d}~XYnX|��}|�|j�|jrl|�|j	�n@t
|j	d��.}|j||d�}|��|�
d�|��W5QRXdS)z:
        Run reactor under the cProfile profiler.
        rN�cProfile�w)�stream���)r<�pstatsr.r&r/r0r1rr2rr5ZStatsZ
strip_dirsZ
sort_statsr7)rr8r<r@r$r9r>r%rrr r1`s
zCProfileRunner.runNr:rrrr r;[sr;c@s"eZdZdZeed�Zdd�ZdS)�AppProfilerz�
    Class which selects a specific profile runner based on configuration
    options.

    @ivar profiler: the name of the selected profiler.
    @type profiler: C{str}
    )r,�cprofilecCsf|�dd�}|�dd�}|�dd���|_|j|jkrR|j|j||�}|j|_ntd|jf��dS)N�	savestatsFr,�profilerrBzUnsupported profiler name: %s)�get�lowerrD�	profilersr1r")r�optionsrrrDrrr r!�s
�zAppProfiler.__init__N)r'r(r)r*r+r;rGr!rrrr rAws
rAc@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	dS)
�	AppLoggera]
    An L{AppLogger} attaches the configured log observer specified on the
    commandline to a L{ServerOptions} object, a custom L{logger.ILogObserver},
    or a legacy custom {log.ILogObserver}.

    @ivar _logfilename: The name of the file to which to log, if other than the
        default.
    @type _logfilename: C{str}

    @ivar _observerFactory: Callable object that will create a log observer, or
        None.

    @ivar _observer: log observer added at C{start} and removed at C{stop}.
    @type _observer: a callable that implements L{logger.ILogObserver} or
        L{log.ILogObserver}.
    NcCs"|�dd�|_|�d�pd|_dS)zE
        Initialize an L{AppLogger} with a L{ServerOptions}.
        r�rN)rE�_logfilename�_observerFactory�rrHrrr r!�szAppLogger.__init__cCs�|jdk	r|��}n$|�tjd�}|dkr8|�tjd�}|dkrH|��}||_tj�|j�rf|jg}n<tj�|j�r�t�|j�g}nt	j
dtdd�t�|j�g}tj�
|�|��dS)a�
        Initialize the global logging system for the given application.

        If a custom logger was specified on the command line it will be used.
        If not, and an L{logger.ILogObserver} or legacy L{log.ILogObserver}
        component has been set on C{application}, then it will be used as the
        log observer. Otherwise a log observer will be created based on the
        command line options for built-in loggers (e.g. C{--logfile}).

        @param application: The application on which to check for an
            L{logger.ILogObserver} or legacy L{log.ILogObserver}.
        @type application: L{twisted.python.components.Componentized}
        NaZPassing a logger factory which makes log observers which do not implement twisted.logger.ILogObserver or twisted.python.log.ILogObserver to twisted.application.app.AppLogger was deprecated in Twisted 16.2. Please use a factory that produces twisted.logger.ILogObserver (or the legacy twisted.python.log.ILogObserver) implementing objects instead.�)�
stacklevel)rLZgetComponentrZILogObserverr�_getLogObserver�	_observer�
providedByZLegacyLogObserverWrapper�warnings�warn�DeprecationWarningZglobalLogBeginnerZbeginLoggingTo�_initialLog)r�applicationZobserverZ	observersrrr �start�s(


�zAppLogger.startcCsJddlm}t�|�jdtjtjt	�
�d�t�|�jdt|j�d�dS)z1
        Print twistd start log message.
        r�r8z1twistd {version} ({exe} {pyVersion}) starting up.)�version�exeZ	pyVersionzreactor class: {reactor}.N)
�twisted.internetr8r�
_loggerFor�inforrZr3�
executabler
ZshortPythonVersionr�	__class__)rr8rrr rV�s
��zAppLogger._initialLogcCs0|jdks|jstj}ntj�|j�}t�|�S)zr
        Create a log observer to be added to the logging system before running
        this application.
        �-)rKr3r4rZLogFileZfromFullPathrZtextFileLogObserver)rZlogFilerrr rP�szAppLogger._getLogObservercCs2t�|��d�|jdk	r.tj�|j�d|_dS)zS
        Remove all log observers previously set up by L{AppLogger.start}.
        zServer Shut Down.N)rr]r^rQZglobalLogPublisherZremoveObserver�rrrr �stop�s
zAppLogger.stop)
r'r(r)r*rQr!rXrVrPrcrrrr rI�s0
rIcCs4dd�}dd�}dd�}|tj_|tj_|tj_dS)NcSs.|��|��ddlm}|�d|j�dS)NrrY�)Zclear_all_breaksZset_continuer\r8Z	callLaterrc)r�argr8rrr �do_stop�s
zfixPdb.<locals>.do_stopcSstd�dS)NzEstop - Continue execution, then cleanly shutdown the twisted reactor.)�printrbrrr �	help_stopszfixPdb.<locals>.help_stopcSst�d�dS)Nr)�os�_exitrbrrr �set_quitszfixPdb.<locals>.set_quit)�pdbZPdbrkrfrh)rfrhrkrrr �fixPdb�srmcCs�|dkrddlm}z~|dr2|dk	r�|�|�n^|dr�|t_|t_tjdkrtt�tj	dd��t�tj
d	d��t�t�
|j�n|��WnTd
}|dr�|}ntdd
�}d}ztj|d�|��W5|r�|��XYnXdS)aN
    Start the reactor, using profiling if specified by the configuration, and
    log any error happening in the process.

    @param config: configuration of the twistd application.
    @type config: L{ServerOptions}

    @param oldstdout: initial value of C{sys.stdout}.
    @type oldstdout: C{file}

    @param oldstderr: initial value of C{sys.stderr}.
    @type oldstderr: C{file}

    @param profiler: object used to run the reactor with profiling.
    @type profiler: L{AppProfiler}

    @param reactor: The reactor to use.  If L{None}, the global reactor will
        be used.
    NrrYr,�debug�posixcWst��Sr�rlZ	set_trace��argsrrr �<lambda>3�z'runReactorWithLogging.<locals>.<lambda>cWst��Srrprqrrr rs4rtFZnodaemonzTWISTD-CRASH.logr-T��file)r\r8r1r3r4�stderrr
ZplatformType�signal�SIGUSR2�SIGINTrmrlr0r5r6�	traceback�	print_exc�flush)�config�	oldstdout�	oldstderrrDr8r6rvrrr �runReactorWithLoggings4

r�cCs|rt�d�SdSdS)NzPassphrase: )�getpass�Zneededrrr �
getPassphraseIs
r�cCs|rt�d�SdSdS)NzEncryption passphrase: )rZgetPasswordr�rrr �getSavePassphraseQs
r�c@sHeZdZdZeZeZdd�Zdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dS)�ApplicationRunnera
    An object which helps running an application based on a config object.

    Subclass me and implement preApplication and postApplication
    methods. postApplication generally will want to run the reactor
    after starting the application.

    @ivar config: The config object, which provides a dict-like interface.

    @ivar application: Available in postApplication, but not
       preApplication. This is the application object.

    @ivar profilerFactory: Factory for creating a profiler object, able to
        profile the application if options are set accordingly.

    @ivar profiler: Instance provided by C{profilerFactory}.

    @ivar loggerFactory: Factory for creating object responsible for logging.

    @ivar logger: Instance provided by C{loggerFactory}.
    cCs"||_|�|�|_|�|�|_dSr)r~�profilerFactoryrD�
loggerFactoryr)rr~rrr r!rszApplicationRunner.__init__cCs6|��|��|_|j�|j�|��|j��dS)z&
        Run the application.
        N)�preApplication�createOrGetApplicationrWrrX�postApplicationrcrbrrr r1xs

zApplicationRunner.runcCsF|dkrddlm}t|j|||j|�t�|�r<|j|_nd|_dS)z�
        Run the reactor with the given configuration.  Subclasses should
        probably call this from C{postApplication}.

        @see: L{runReactorWithLogging}
        NrrY)r\r8r�r~rDrrRZ_exitSignal)rr8rr�rrr �startReactor�s�

zApplicationRunner.startReactorcCs
t��dS)z�
        Override in subclass.

        This should set up any state necessary before loading and
        running the Application.
        N��NotImplementedErrorrbrrr r��sz ApplicationRunner.preApplicationcCs
t��dS)z�
        Override in subclass.

        This will be called after the application has been loaded (so
        the C{application} attribute will be set). Generally this
        should start the application and run the reactor.
        Nr�rbrrr r��sz!ApplicationRunner.postApplicationcCs\|jjr>|jj|jj}|�|jj�}t�|j�}|�|�nt	|jd�}t
|j|�}|S)a�
        Create or load an Application based on the parameters found in the
        given L{ServerOptions} instance.

        If a subcommand was used, the L{service.IServiceMaker} that it
        represents will be used to construct a service to be added to
        a newly-created Application.

        Otherwise, an application will be loaded based on parameters in
        the config.
        �	encrypted)r~�
subCommand�
loadedPluginsZmakeServiceZ
subOptionsr	ZApplication�tapnameZsetServiceParentr��getApplication)rZplgZserrW�
passphraserrr r��sz(ApplicationRunner.createOrGetApplicationN)r'r(r)r*rAr�rIr�r!r1r�r�r�r�rrrr r�Ys

r�c
s��fdd�dD�d}|dddi�|d|d�}}z*t�d|�t�|||�}t�d	�Wn|tk
r�}z^d
|}t|t�r�|jddkr�|d7}t	j
tjd
�t�|�t��t
�d|d�W5d}~XYnX|S)Ncs g|]}�|r�||f�qSrr)�.0�t�r~rr �
<listcomp>�s�z"getApplication.<locals>.<listcomp>)�python�sourcervrrv�picklerdz
Loading %s...zLoaded.zFailed to load application: %srWaN
Could not find 'application' in the file. To use 'twistd -y', your .tac
file must create a suitable object (e.g., by calling service.Application())
and store it in a variable named 'application'. twistd loads your .tac file
and scans the global variables for one of this name.

Please read the 'Using Application' HOWTO for details.
ru�
)rEr�msgr	�loadApplication�	Exception�
isinstance�KeyErrorrrr{r|rZdeferrr3�exit)r~r�r%�filenameZstylerWr$rr�r r��s&
��"
$r�cCst�dd�t��D��S)NcSsg|]
}|j�qSr)�	shortName)r��rrrr r��sz"_reactorAction.<locals>.<listcomp>)rZCompleteListr
�getReactorTypesrrrr �_reactorAction�s
�r�c@sDeZdZdZejdeid�Zej	Z
eej
�Zdd�Zdd�ZeZdS)	�ReactorSelectionMixinz�
    Provides options for selecting a reactor to install.

    If a reactor is installed, the short name which was used to locate it is
    saved as the value for the C{"reactor"} key.
    r8)�
optActionscCs�t|��td�d�}d}|D]j}z&t|j�|j�d|j|jf�Wqt	k
r�}z |d|j|j|j
df7}W5d}~XYqXq|r�|j�d�|j�d	�|j�|�td��dS)
zE
        Display a list of possibly available reactor names.
        r���keyrJz    %-4s	%s
z    !%-4s	%s (%s)
rNr�z.    reactors not available on this platform:

)�sorted�_getReactorTypesrrZ
moduleName�
messageOutput�writer��descriptionr.rrr")rZrctsZnotWorkingReactorsr�r$rrr �opt_help_reactors�s"

�
�z'ReactorSelectionMixin.opt_help_reactorsc
Csvzt|�Wn\tk
r4d|f}t�|��Yn>tk
rh}zd|f}t�|��W5d}~XYn
X||d<dS)zX
        Which reactor to use (see --help-reactors for a list of possibilities)
        zcThe specified reactor does not exist: '%s'.
See the list of available reactors with --help-reactorsztThe specified reactor cannot be used, failed with error: %s.
See the list of available reactors with --help-reactorsNr8)rrr�
UsageErrorr�)rr�r�r$rrr �opt_reactors	��z!ReactorSelectionMixin.opt_reactorN)r'r(r)r*r�Completionsr��compDatar3r4r��staticmethodr
r�r�r�r�Zopt_rrrrr r��s�
r�c@seZdZdZdddgdddgdd	d
ggZdddd
gddddgddddgddddd�ej�gddddgddddgdddd gd!d"d#d$ggZe	j
d%ge	�d&�e	�d'�e	�d(�e	��d)�d*�Z
eej�Zd+d,�Zd-d.�ZeZd/d0�Zd7d1d2�Zd3d4�Zd5d6�Zee�ZdS)8�
ServerOptionszQtwistd reads a twisted.application.service.Application out of a file and runs it.rCNzBsave the Stats object rather than the text output of the profiler.�no_save�ozdo not save state on shutdownr�r$z(The specified tap/aos file is encrypted.r�lz%log to a specified file, - for stdoutrz�A fully-qualified name to a log observer factory to use for the initial log observer.  Takes precedence over --logfile and --syslog (when available).r,r9z7Run in profile mode, dumping results to specified file.rDrBz!Name of the profiler to use (%s).z, rv�fz
twistd.tapzread the given .tap filer��yz:read an application from within a Python file (implies -o)r�r%z2Read an application from a .tas file (AOT format).�rundir�d�.z-Change to a supplied directory before running)rvr�r�z*.tapz
*.(tac|py)z*.tas)rvr�r�r�)ZmutuallyExclusiver�cOs4d|d<d|kr|d|_ntj|_tj�|�dS)NFrnr4)r4r3r�Optionsr!)rr-�kwrrr r!Xs
zServerOptions.__init__cCst�d�t��d|d<dS)z�
        Run the application in the Python Debugger (implies nodaemon),
        sending SIGUSR2 will drop into debugger
        TrnN)rZsetDebuggingrZstartDebugModerbrrr �	opt_debugas
zServerOptions.opt_debugcCs@t�tj�zddl}Wntk
r.YdSX|�tj�dS)z�
        Print an insanely verbose log of everything that happens.
        Useful when debugging freezes or locks in complex code.
        rN)r3�settracerZspewer�	threadingr.)rr�rrr �opt_spewlszServerOptions.opt_spewcCs.|dkrtjdd�pdg}tj�||�dS)Nrdz--help)r3�argvrr��parseOptionsrMrrr r�yszServerOptions.parseOptionsc
Cst|js|drd|d<|ddk	rpzt|d�|d<Wn8tk
rn}zt�d|d|f��W5d}~XYnXdS)Nr�Tr�rz%Logger '%s' could not be imported: %s)r�rr�rr�)rr$rrr �postOptionss
�zServerOptions.postOptionsccsR|�tj�}i|_t|td�d�D]*}||j|j<|jd|fdd�|jfVq"dS)Nr�r�cSs|��Sr)rH)�plugrrr rs�rtz+ServerOptions.subCommands.<locals>.<lambda>)�_getPluginsr	Z
IServiceMakerr�r�rr�r�)rZpluginsr�rrr �subCommands�s
�zServerOptions.subCommands)N)r'r(r)ZlongdescZoptFlags�joinrArGZ
optParametersrr�Z
CompleteFilesZCompleteDirsr�r�rZ
getPluginsr�r!r�Zopt_br�r�r�r��propertyrrrr r�,sj������
���������
	
r�c
Csb|�}z|��WnBtjk
rT}z"t|�tdtjd|f�W5d}~XYn
X||�dS)Nz%s: %sr)r�r�errorrgr3r�)ZrunAppr�r~Zuerrr r1�s(r1cCsFt�|||�}t�|��|�t|�}|r.d}t�|�j||d�dS)N)r�r�)r	r�r�IPersistableZsetStyler��save)ZfileinZtypeinr�ZfileoutZtypeoutZencryptrWrrr �convertStyle�sr�cCsTddlm}t�|���|r:t�|�}|�dd|jd�|�ddt�|�j	�dS)NrrYZafterZshutdownZbefore)
r\r8r	ZIServiceZstartServicerr�ZaddSystemEventTriggerr�ZstopService)rWr�r8r9rrr �startApplication�s

�r�cCs"t�|tj�t�t��|�dS)a
    Force the application to terminate with the specified signal by replacing
    the signal handler with the default and sending the signal to ourselves.

    @param sig:  Signal to use to terminate the process with C{os.kill}.
    @type sig:  C{int}
    N)rx�SIG_DFLri�kill�getpid)Zsigrrr �_exitWithSignal�sr�)NN)>Z
__future__rrrr3rirlr�r{rxrS�operatorrZtwistedrrrZtwisted.applicationr	r
r\rZtwisted.persistedrZtwisted.pythonr
rrrrrZtwisted.python._oldstylerZtwisted.python.reflectrrrZtwisted.internet.interfacesrZtwisted.application.reactorsrr�objectrr+r;rArIrmr�r�r�r�r�r�r�r�r�r1r�r�r�rrrr �<module>sN  o�
5q@n