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/web/__pycache__/tap.cpython-38.pyc
U


W[v&�@s�dZddlmZmZddlZddlZddlZddlmZm	Z	ddl
mZmZddl
mZmZmZmZddlmZddlmZdd	lmZmZmZmZmZmZdd
lmZGdd�dej�Zd
d�ZGdd�dej�Z dd�Z!dS)z9
Support for creating a service which runs a web server.
�)�absolute_import�divisionN)�service�strports)�
interfaces�reactor)�usage�reflect�
threadpool�	deprecate)�pb)�distrib)�resource�server�static�script�demo�wsgi)�twcgic@seZdZdZdZddddgddd	d
gddd	d
ggZdddggZe�dddej	j
fdg�eje�
d�e�
d�e�
d�d�d�ZdZdd�Zdd�ZeZdd�Zd d!�Zd"d#�ZeZd$d%�ZeZd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�ZeZd2d3�Z d4d5�Z!d6d7�Z"d8d9�Z#dS):�OptionszB
    Define the options accepted by the I{twistd web} plugin.
    z
[web options]�logfile�lNz/Path to web CLF (Combined Log Format) log file.�certificate�cz
server.pemz=(DEPRECATED: use --listen) SSL certificate to use for HTTPS. �privkey�kz<(DEPRECATED: use --listen) SSL certificate to use for HTTPS.�notracebacks�nzcDo not display tracebacks in broken web pages. Displaying tracebacks to users may be security risk!�personal�zvInstead of generating a webserver, generate a ResourcePublisher which listens on  the port given by --listen, or ~/%s zif --listen is not specified.z*.logz*.pem)rrr)Z
optActionsz�This starts a webserver.  If you specify no arguments, it will be a
demo webserver that has the Test class from twisted.web.demo in it.cCs@tj�|�g|d<d|d<g|d<g|d<d|d<|d<dS)N�indexes�root�extraHeaders�ports�port�https)rr�__init__��self�r)�1/usr/lib/python3/dist-packages/twisted/web/tap.pyr&?szOptions.__init__c	Cs6t�|jt�dddd��}tj|tdd�||d<dS)	zh
        (DEPRECATED: use --listen)
        Strports description of port to start the server on
        �Twisted��r���category�
stacklevelr$N)r�getDeprecationWarningString�opt_port�incremental�Version�warnings�warn�DeprecationWarning�r(r$�msgr)r)r*r3Hs�zOptions.opt_portc	Cs6t�|jt�dddd��}tj|tdd�||d<dS)	zW
        (DEPRECATED: use --listen)
        Port to listen on for Secure HTTP.
        r+r,r-rr.r/r%N)rr2�	opt_httpsr4r5r6r7r8r9r)r)r*r;Ts�zOptions.opt_httpscCs|d�|�dS)zi
        Add an strports description of port to start the server on.
        [default: tcp:8080]
        r#N��append)r(r$r)r)r*�
opt_listen_szOptions.opt_listencCs|d�|�dS)zr
        Add the name of a file used to check for directory indexes.
        [default: index, index.html]
        r Nr<)r(Z	indexNamer)r)r*�	opt_indexgszOptions.opt_indexcCst��|d<dS)zc
        Makes a server with ~/public_html and ~/.twistd-web-pb support for
        users.
        r!N)r
�
UserDirectoryr'r)r)r*�opt_userqszOptions.opt_usercCs>t�tj�|��|d<tjtjd�|d_t	j
|djd<dS)z�
        <path> is either a specific file or a directory to be set as the root
        of the web server. Use this if you have a directory full of HTML, cgi,
        epy, or rpy files or any other files that you want to be served up raw.
        r!)z.epyz.rpyz.cgiN)r�File�os�path�abspathrZPythonScriptZResourceScript�
processorsrZ	CGIScript)r(rDr)r)r*�opt_path{s
�zOptions.opt_pathcCsBt|dtj�st�d��|�dd�\}}t�|�|dj|<dS)zh
        `ext=class' where `class' is added as a Processor for files ending
        with `ext'.
        r!z*You can only use --processor after --path.�=�N)	�
isinstancerrBr�
UsageError�splitr	�
namedClassrF)r(�proc�ext�klassr)r)r*�
opt_processor�s�zOptions.opt_processorcCst�|�}|�|d<dS)zN
        Create a Resource subclass with a zero-argument constructor.
        r!N)r	rM)r(Z	classNameZclassObjr)r)r*�	opt_class�s
zOptions.opt_classcCst�|�|d<dS)zP
        An .rpy file to be used as the root resource of the webserver.
        r!N)rZResourceScriptWrapper)r(�namer)r)r*�opt_resource_script�szOptions.opt_resource_scriptc	Csrzt�|�}Wn(ttfk
r6t�d|f��YnXt��}t�	|j
�t�dd|j�t
�t||�|d<dS)zo
        The FQPN of a WSGI application object to serve as the root resource of
        the webserver.
        zNo such WSGI application: %rZafterZshutdownr!N)r	ZnamedAny�AttributeError�
ValueErrorrrKr
Z
ThreadPoolrZcallWhenRunning�startZaddSystemEventTrigger�stoprZWSGIResource)r(rSZapplicationZpoolr)r)r*�opt_wsgi�szOptions.opt_wsgicCs(t|dtj�st�d��||d_dS)zA
        Specify the default mime-type for static files.
        r!z*You can only use --mime_type after --path.N)rJrrBrrK�defaultType)r(rZr)r)r*�
opt_mime_type�s
�zOptions.opt_mime_typecCs,t|dtj�st�d��|d�d�dS)zT
        Specify whether or not a request for 'foo' should return 'foo.ext'
        r!z1You can only use --allow_ignore_ext after --path.�*N�rJrrBrrKZ	ignoreExtr'r)r)r*�opt_allow_ignore_ext�s
zOptions.opt_allow_ignore_extcCs,t|dtj�st�d��|d�|�dS)zT
        Specify an extension to ignore.  These will be processed in order.
        r!z+You can only use --ignore_ext after --path.Nr])r(rOr)r)r*�opt_ignore_ext�s
zOptions.opt_ignore_extcCs.|�dd�\}}|d�|��|��f�dS)z
        Specify an additional header to be included in all responses. Specified
        as "HeaderName: HeaderValue".
        �:rIr"N)rLr=�strip)r(�headerrS�valuer)r)r*�opt_add_header�szOptions.opt_add_headercCs�|ddk	r|d�|d�|ddk	r�zt�d�Wntk
rVt�d��YnXd�|d|d|d	�}|d�|�t|d�d
kr�|dr�tj	�
tj	�dtj
j��}|d�d
|�n|d�d�dS)a@
        Set up conditional defaults and check for dependencies.

        If SSL is not available but an HTTPS server was configured, raise a
        L{UsageError} indicating that this is not possible.

        If no server port was supplied, select a default appropriate for the
        other options supplied.
        r$Nr#r%zOpenSSL.SSLzSSL support not installedz$ssl:port={}:privateKey={}:certKey={}rrrr�~zunix:ztcp:8080)r=r	ZnamedModule�ImportErrorrrK�format�lenrCrD�
expanduser�joinr
r@�userSocketName)r(Z
sslStrportrDr)r)r*�postOptions�s(
��zOptions.postOptions)$�__name__�
__module__�__qualname__�__doc__ZsynopsisZ
optParametersZoptFlagsr=r
r@rkrZCompletionsZ
CompleteFilesZcompDataZlongdescr&r3Zopt_pr;r>r?Zopt_irAZopt_urGrQrRrTrYr[Zopt_mr^r_rdrlr)r)r)r*rsh�����������	


	rcCst�t�|��S)z�
    Create and return a factory which will respond to I{distrib} requests
    against the given site.

    @type site: L{twisted.web.server.Site}
    @rtype: L{twisted.internet.protocol.Factory}
    )rZPBServerFactoryr
ZResourcePublisher)�siter)r)r*�makePersonalServerFactory�srrc@seZdZdd�Zdd�ZdS)�_AddHeadersResourcecCs||_||_dS�N)�_originalResource�_headers)r(ZoriginalResourceZheadersr)r)r*r&	sz_AddHeadersResource.__init__cCs,|jD]\}}|j�||�q|j�||�Srt)rvZresponseHeadersZaddRawHeaderru�getChildWithDefault)r(rSZrequestr�vr)r)r*rwsz'_AddHeadersResource.getChildWithDefaultN)rmrnror&rwr)r)r)r*rssrscCs�t��}|dr0|d}|dr8|d|d_nt��}t|tj�rT|j�	t
j|�|drjt||d�}|dr�t
j||dd�}n
t
�|�}|d|_|dr�t|�}|dD]}t�||�}|�|�q�|S)	Nr!r r"r)ZlogPathrrr#)rZMultiServiceZ
indexNamesrZTestrJrrB�registryZsetComponentrZIServiceCollectionrsrZSiteZdisplayTracebacksrrrZsetServiceParent)Zconfig�sr!rqr$Zsvcr)r)r*�makeServices(
r{)"rpZ
__future__rrrCr6r4Ztwisted.applicationrrZtwisted.internetrrZtwisted.pythonrr	r
rZtwisted.spreadrZtwisted.webr
rrrrrrrrrrZResourcersr{r)r)r)r*�<module>s  e