Ë
    oj(  ã                   óì   — d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	 ddl
mZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZ  G d„ d	ej4                  «      Zd
„ Z G d„ dej8                  «      Zd„ Zy)z9
Support for creating a service which runs a web server.
é    N)ÚserviceÚstrports)Ú
interfacesÚreactor)Ú	deprecateÚreflectÚ
threadpoolÚusage)Úpb)ÚdemoÚdistribÚresourceÚscriptÚserverÚstaticÚtwcgiÚwsgic                   óš  — e Zd ZdZdZg d¢g d¢g d¢gZg d¢g d¢gZej                  dd	d
ej                  j                  ›d�dz   g«        ej                   ej                  d«       ej                  d«       ej                  d«      dœ¬«      ZdZd„ Zd„ ZeZd„ Zd„ Zd„ ZeZd„ ZeZd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZeZd„ Z d„ Z!d „ Z"d!„ Z#y")#Ú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Úcú
server.pemz=(DEPRECATED: use --listen) SSL certificate to use for HTTPS. )ÚprivkeyÚkr   z<(DEPRECATED: use --listen) SSL certificate to use for HTTPS.)ÚnotracebacksÚnzY(DEPRECATED: Tracebacks are disabled by default. See --enable-tracebacks to turn them on.)údisplay-tracebacksÚ z�Show uncaught exceptions during rendering tracebacks to the client. WARNING: This may be a security risk and expose private data!Úpersonalr    zsInstead of generating a webserver, generate a ResourcePublisher which listens on  the port given by --listen, or ~/ú zif --listen is not specified.z*.logz*.pem)r   r   r   )Ú
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.c                 ó~   — t         j                  j                  | «       g | d<   d | d<   g | d<   g | d<   d x| d<   | d<   y )NÚindexesÚrootÚextraHeadersÚportsÚportÚhttps)r
   r   Ú__init__©Úselfs    ú1/usr/lib/python3/dist-packages/twisted/web/tap.pyr+   zOptions.__init__X   sK   € Ü�‰×Ñ˜tÔ$ØˆˆY‰ØˆˆV‰Ø!ˆˆ^ÑØˆˆW‰Ø'+Ð+ˆˆV‰�t˜G’}ó    c           	      ó²   — t        j                  | j                  t        j                  dddd«      «      }t        j                  |t        d¬«       || d<   y)	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)   Úmsgs      r.   r9   zOptions.opt_port`   sJ   € ô
 ×3Ñ3Ø�M‰Mœ;×.Ñ.¨y¸"¸aÀÓCó
ˆô 	�‰�cÔ$6À1ÕEØˆˆVŠr/   c           	      ó²   — t        j                  | j                  t        j                  dddd«      «      }t        j                  |t        d¬«       || d<   y)	zW
        (DEPRECATED: use --listen)
        Port to listen on for Secure HTTP.
        r1   r2   r3   r   r4   r5   r*   N)r   r8   Ú	opt_httpsr:   r;   r<   r=   r>   r?   s      r.   rB   zOptions.opt_httpsm   sJ   € ô
 ×3Ñ3Ø�N‰NœK×/Ñ/°	¸2¸qÀ!ÓDó
ˆô 	�‰�cÔ$6À1ÕEØˆˆWŠr/   c                 ó,   — | d   j                  |«       y)zi
        Add an strports description of port to start the server on.
        [default: tcp:8080]
        r(   N©Úappend)r-   r)   s     r.   Ú
opt_listenzOptions.opt_listenx   s   € ð
 	ˆW‰×Ñ˜TÕ"r/   c                 ó,   — | d   j                  |«       y)zr
        Add the name of a file used to check for directory indexes.
        [default: index, index.html]
        r%   NrD   )r-   Ú	indexNames     r.   Ú	opt_indexzOptions.opt_index   s   € ð
 	ˆY‰×Ñ˜yÕ)r/   c                 ó2   — t        j                  «       | d<   y)zc
        Makes a server with ~/public_html and ~/.twistd-web-pb support for
        users.
        r&   N)r   ÚUserDirectoryr,   s    r.   Úopt_userzOptions.opt_userˆ   s   € ô
 ×,Ñ,Ó.ˆˆVŠr/   c                 ó   — t        j                  t        j                  j	                  |«      «      | d<   t
        j                  t
        j                  dœ| d   _        t        j                  | d   j                  d<   y)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Úabspathr   ÚPythonScriptÚResourceScriptÚ
processorsr   Ú	CGIScript)r-   rP   s     r.   Úopt_pathzOptions.opt_path‘   s]   € ô —{‘{¤2§7¡7§?¡?°4Ó#8Ó9ˆˆV‰ä×'Ñ'Ü×)Ñ)ñ#
ˆˆV‰Ôô +0¯/©/ˆˆV‰×Ñ Ò'r/   c                 óÜ   — t        | d   t        j                  «      st        j                  d«      ‚|j                  dd«      \  }}t        j                  |«      | d   j                  |<   y)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)	Ú
isinstancer   rN   r
   Ú
UsageErrorÚsplitr   Ú
namedClassrT   )r-   ÚprocÚextÚklasss       r.   Úopt_processorzOptions.opt_processorž   s[   € ô
 ˜$˜v™,¬¯©Ô4Ü×"Ñ"Ð#OÓPÐPØ—Z‘Z  QÓ'‰
ˆˆUÜ'.×'9Ñ'9¸%Ó'@ˆˆV‰×Ñ Ò$r/   c                 óB   — t        j                  |«      } |«       | d<   y)zN
        Create a Resource subclass with a zero-argument constructor.
        r&   N)r   r]   )r-   Ú	classNameÚclassObjs      r.   Ú	opt_classzOptions.opt_class¨   s   € ô ×%Ñ% iÓ0ˆÙ“zˆˆVŠr/   c                 ó4   — t        j                  |«      | d<   y)zP
        An .rpy file to be used as the root resource of the webserver.
        r&   N)r   ÚResourceScriptWrapper)r-   Únames     r.   Úopt_resource_scriptzOptions.opt_resource_script¯   s   € ô ×3Ñ3°DÓ9ˆˆVŠr/   c                 ój  — 	 t        j                  |«      }t        j                  «       }t        j                  |j                  «       t        j                  dd|j                  «       t        j                  t        ||«      | d<   y# t        t        f$ r t	        j
                  d|›�«      ‚w xY w)zo
        The FQPN of a WSGI application object to serve as the root resource of
        the webserver.
        zNo such WSGI application: ÚafterÚshutdownr&   N)r   ÚnamedAnyÚAttributeErrorÚ
ValueErrorr
   r[   r	   Ú
ThreadPoolr   ÚcallWhenRunningÚstartÚaddSystemEventTriggerÚstopr   ÚWSGIResource)r-   rh   ÚapplicationÚpools       r.   Úopt_wsgizOptions.opt_wsgiµ   s™   € ð
	JÜ!×*Ñ*¨4Ó0ˆKô ×$Ñ$Ó&ˆÜ×Ñ §
¡
Ô+Ü×%Ñ% g¨z¸4¿9¹9ÔEÜ×(Ñ(¬°$¸ÓDˆˆVŠøô ¤
Ð+ò 	JÜ×"Ñ"Ð%?À¸xÐ#HÓIÐIð	Jús   ‚B
 Â
(B2c                 ó|   — t        | d   t        j                  «      st        j                  d«      ‚|| d   _        y)zA
        Specify the default mime-type for static files.
        r&   z*You can only use --mime_type after --path.N)rZ   r   rN   r
   r[   ÚdefaultType)r-   rz   s     r.   Úopt_mime_typezOptions.opt_mime_typeÃ   s4   € ô ˜$˜v™,¬¯©Ô4Ü×"Ñ"Ð#OÓPÐPØ#.ˆˆV‰Õ r/   c                 ó�   — t        | d   t        j                  «      st        j                  d«      ‚| d   j                  d«       y)zT
        Specify whether or not a request for 'foo' should return 'foo.ext'
        r&   z1You can only use --allow_ignore_ext after --path.Ú*N©rZ   r   rN   r
   r[   Ú	ignoreExtr,   s    r.   Úopt_allow_ignore_extzOptions.opt_allow_ignore_extÍ   s@   € ô ˜$˜v™,¬¯©Ô4Ü×"Ñ"ØFóð ð 	ˆV‰×Ñ˜sÕ#r/   c                 ó�   — t        | d   t        j                  «      st        j                  d«      ‚| d   j                  |«       y)zT
        Specify an extension to ignore.  These will be processed in order.
        r&   z+You can only use --ignore_ext after --path.Nr~   )r-   r_   s     r.   Úopt_ignore_extzOptions.opt_ignore_ext×   s:   € ô ˜$˜v™,¬¯©Ô4Ü×"Ñ"Ð#SÓTÐTØˆV‰×Ñ˜sÕ#r/   c                 ó’   — |j                  dd«      \  }}| d   j                  |j                  «       |j                  «       f«       y)z
        Specify an additional header to be included in all responses. Specified
        as "HeaderName: HeaderValue".
        ú:rY   r'   N)r\   rE   Ústrip)r-   Úheaderrh   Úvalues       r.   Úopt_add_headerzOptions.opt_add_headerß   s<   € ð
 —l‘l 3¨Ó*‰ˆˆeØˆ^Ñ×#Ñ# T§Z¡Z£\°5·;±;³=Ð$AÕBr/   c                 óF  — | d   �| d   j                  | d   «       | d   �F	 t        j                  d«       dj                  | d   | d   | d	   «      }| d   j                  |«       t        | d   «      d
k(  r‡| d   rmt        j                  j                  t        j                  j                  dt        j                  j                  «      «      }| d   j                  d|z   «       y| d   j                  d«       yy# t        $ r t	        j
                  d«      ‚w xY w)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*   zOpenSSL.SSLzSSL support not installedz$ssl:port={}:privateKey={}:certKey={}r   r   r   r!   ú~zunix:ztcp:8080)rE   r   ÚnamedModuleÚImportErrorr
   r[   ÚformatÚlenrO   rP   Ú
expanduserÚjoinr   rK   ÚuserSocketName)r-   Ú
sslStrportrP   s      r.   ÚpostOptionszOptions.postOptionsç   s  € ð �‰<Ð#Ø�‰M× Ñ   f¡Ô.Ø�‰=Ð$ðDÜ×#Ñ# MÔ2ð @×FÑFØ�W‘Ø�Y‘Ø�]Ñ#óˆJð
 �‰M× Ñ  Ô,Üˆt�G‰}Ó Ò"Ø�JÒÜ—w‘w×)Ñ)Ü—G‘G—L‘L ¤g×&;Ñ&;×&JÑ&JÓKó�ð �W‘×$Ñ$ W¨t¡^Õ4à�W‘×$Ñ$ ZÕ0ð #øô ò DÜ×&Ñ&Ð'BÓCÐCðDús   £D ÄD N)$Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚsynopsisÚoptParametersÚoptFlagsrE   r   rK   r‘   r
   ÚCompletionsÚCompleteFilesÚcompDataÚlongdescr+   r9   Úopt_prB   rF   rI   Úopt_irL   Úopt_urV   ra   re   ri   rx   r{   Úopt_mr€   r‚   rˆ   r“   © r/   r.   r   r      s0  „ ñð €Hò 	Rò	
ò	
ð€Mò"	
ò	
ð€Hð( ‡O�OàÙð %,×$9Ñ$9×$HÓ$HðKð .ñ.ð	
ô	ð !ˆu× Ñ à*�u×*Ñ*¨7Ó3Ø.˜5×.Ñ.¨wÓ7Ø*�u×*Ñ*¨7Ó3ñ
ô€HðG€Hò,ò	ð €Eò	ò#ò*ð €Eò/ð €Eò:òAò"ò:òEò/ð €Eò$ò$òCó1r/   r   c                 óR   — t        j                  t        j                  | «      «      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   ÚPBServerFactoryr   ÚResourcePublisher)Úsites    r.   ÚmakePersonalServerFactoryr¨     s    € ô ×Ñœg×7Ñ7¸Ó=Ó>Ð>r/   c                   ó   — e Zd Zd„ Zd„ Zy)Ú_AddHeadersResourcec                 ó    — || _         || _        y ©N)Ú_originalResourceÚ_headers)r-   ÚoriginalResourceÚheaderss      r.   r+   z_AddHeadersResource.__init__  s   € Ø!1ˆÔØˆ�r/   c                 óš   — | j                   D ]!  \  }}|j                  j                  ||«       Œ# | j                  j	                  ||«      S r¬   )r®   ÚresponseHeadersÚaddRawHeaderr­   ÚgetChildWithDefault)r-   rh   Úrequestr   Úvs        r.   r´   z'_AddHeadersResource.getChildWithDefault  sH   € Ø—M‘Mò 	7‰DˆAˆqØ×#Ñ#×0Ñ0°°AÕ6ð	7à×%Ñ%×9Ñ9¸$ÀÓHÐHr/   N)r”   r•   r–   r+   r´   r£   r/   r.   rª   rª     s   „ ò óIr/   rª   c           	      óÞ  — t        j                  «       }| d   r| d   }| d   r"| d   | d   _        nt        j                  «       }t        |t        j                  «      r*|j                  j                  t        j                  |«       | d   rt        || d   «      }| d   rt        j                  || d   ¬«      }nt        j                  |«      }| d   rd|_        | d   rHt!        j"                  d	t%        j&                  d
ddd«      «      }t)        j*                  |t,        d¬«       | d   rt/        |«      }| d   D ])  }t1        j                   ||«      }|j3                  |«       Œ+ |S )Nr&   r%   r'   r   )ÚlogPathr   Tr   z--notracebacksr1   é   é   r   r4   r5   r!   r(   )r   ÚMultiServiceÚ
indexNamesr   ÚTestrZ   r   rN   ÚregistryÚsetComponentr   ÚIServiceCollectionrª   r   ÚSiteÚdisplayTracebacksr   Ú_getDeprecationWarningStringr:   r;   r<   r=   r>   r¨   r   ÚsetServiceParent)ÚconfigÚsr&   r§   r@   r)   Úsvcs          r.   ÚmakeServicerÈ     sR  € Ü×ÑÓ€AØˆf‚~Ø�f‰~ˆØ�)ÒØ(.¨yÑ(9ˆF�6‰NÕ%ô �y‰y‹{ˆä�$œŸ™Ô$Ø�‰×"Ñ"¤:×#@Ñ#@À!ÔDàˆnÒÜ" 4¨°Ñ)?Ó@ˆàˆiÒÜ�{‰{˜4¨°	Ñ):Ô;‰ä�{‰{˜4Ó ˆàÐ"Ò#Ø!%ˆÔð ˆnÒÜ×4Ñ4Øœk×1Ñ1°)¸RÀÀAÓFó
ˆô 	�‰�cÔ$6À1ÕEàˆjÒÜ(¨Ó.ˆØ�w‘ò  ˆÜ×Ñ˜t TÓ*ˆØ×Ñ˜QÕð ð €Hr/   )r—   rO   r<   r:   Útwisted.applicationr   r   Útwisted.internetr   r   Útwisted.pythonr   r   r	   r
   Útwisted.spreadr   Útwisted.webr   r   r   r   r   r   r   r   r   r¨   ÚResourcerª   rÈ   r£   r/   r.   ú<module>rÏ      s^   ðñ
ó
 
Û ã ç 1ß 0ß @Ó @Ý ß T× TÓ Tôo1ˆe�m‰mô o1òd?ôI˜(×+Ñ+ô Ió$r/   