Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/tap.cpython-37.opt-1.pyc

B

;��][(�@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@s"eZdZdZdZddddgddd	d
gddd	d
ggZdddgdddggZe�dddej	j
fdg�eje�
d�e�
d�e�
d�d�d�ZdZdd�Zdd�ZeZd d!�Zd"d#�Zd$d%�ZeZd&d'�ZeZd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�ZeZd4d5�Z d6d7�Z!d8d9�Z"d:d;�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�nzY(DEPRECATED: Tracebacks are disabled by default. See --enable-tracebacks to turn them on.zdisplay-tracebacks�z�Show uncaught exceptions during rendering tracebacks to the client. WARNING: This may be a security risk and expose private data!�personalzvInstead 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(�B/opt/alt/python37/lib64/python3.7/site-packages/twisted/web/tap.pyr&Cs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)r1LszOptions.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/r%N)rr0�	opt_httpsr2r3r4r5r6)r'r$r7r(r(r)r8XszOptions.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_listencszOptions.opt_listencCs|d�|�dS)zr
        Add the name of a file used to check for directory indexes.
        [default: index, index.html]
        r N)r9)r'Z	indexNamer(r(r)�	opt_indexkszOptions.opt_indexcCst��|d<dS)zc
        Makes a server with ~/public_html and ~/.twistd-web-pb support for
        users.
        r!N)r
�
UserDirectory)r'r(r(r)�opt_useruszOptions.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'r@r(r(r)�opt_pathszOptions.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)	�
isinstancerr>r�
UsageError�splitr	�
namedClassrB)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	rI)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	Csryt�|�}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�
ValueErrorrrGr
Z
ThreadPoolrZcallWhenRunning�startZaddSystemEventTrigger�stoprZWSGIResource)r'rOZapplicationZpoolr(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)rFrr>rrG�defaultType)r'rVr(r(r)�
opt_mime_type�szOptions.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)rFrr>rrG�	ignoreExt)r'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.N)rFrr>rrGrY)r'rKr(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".
        �:rEr"N)rHr9�strip)r'�headerrO�valuer(r(r)�opt_add_header�szOptions.opt_add_headercCs�|ddk	r|d�|d�|ddk	r�yt�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)r9r	ZnamedModule�ImportErrorrrG�format�lenr?r@�
expanduser�joinr
r<�userSocketName)r'Z
sslStrportr@r(r(r)�postOptions�s$

zOptions.postOptions)$�__name__�
__module__�__qualname__�__doc__ZsynopsisZ
optParametersZoptFlagsr9r
r<rgrZCompletionsZ
CompleteFilesZcompDataZlongdescr&r1Zopt_pr8r:r;Zopt_ir=Zopt_urCrMrNrPrUrWZopt_mrZr[r`rhr(r(r(r)rsT

	


	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)�makePersonalServerFactorysrnc@seZdZdd�Zdd�ZdS)�_AddHeadersResourcecCs||_||_dS)N)�_originalResource�_headers)r'ZoriginalResourceZheadersr(r(r)r&
sz_AddHeadersResource.__init__cCs0x |jD]\}}|j�||�qW|j�||�S)N)rqZresponseHeadersZaddRawHeaderrp�getChildWithDefault)r'rOZrequestr�vr(r(r)rrsz'_AddHeadersResource.getChildWithDefaultN)rirjrkr&rrr(r(r(r)rosroc	Cs
t��}|dr0|d}|dr8|d|d_nt��}t|tj�rT|j�	t
j|�|drjt||d�}|dr�t
j||dd�}n
t
�|�}|dr�d|_|dr�t�d	t�d
ddd
��}tj|tdd�|dr�t|�}x&|dD]}t�||�}|�|�q�W|S)Nr!r r"r)ZlogPathzdisplay-tracebacksTrz--notracebacksr*��rr-)r.r/rr#)rZMultiServiceZ
indexNamesrZTestrFrr>�registryZsetComponentrZIServiceCollectionrorZSiteZdisplayTracebacksrZ_getDeprecationWarningStringr2r3r4r5r6rnrZsetServiceParent)Zconfig�sr!rmr7r$Zsvcr(r(r)�makeServices2
rx)"rlZ
__future__rrr?r4r2Ztwisted.applicationrrZtwisted.internetrrZtwisted.pythonrr	r
rZtwisted.spreadrZtwisted.webr
rrrrrrrrrnZResourcerorxr(r(r(r)�<module>s  i