
    h(                         S r SSKrSSKrSSKrSSKJrJr  SSKJrJ	r	  SSK
JrJrJrJr  SSKJr  SSKJrJrJrJrJrJrJrJr   " S S	\R4                  5      rS
 r " S S\R8                  5      rS rg)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                      \ rS rSrSrSr/ SQ/ SQ/ SQ/r/ SQ/ SQ/r\R                  S	S
S\	R                  R                  < S3S-   /5        \R                  " \R                  " S5      \R                  " S5      \R                  " S5      S.S9rSrS rS r\rS rS rS r\rS r\rS rS rS rS rS rS r\r S r!S  r"S! r#S" r$S#r%g$)%Options   z:
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 zShow 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   )
optActionszThis 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                 ~    [         R                  R                  U 5        / U S'   S U S'   / U S'   / U S'   S =U S'   U S'   g )NindexesrootextraHeadersportsporthttps)r
   r   __init__selfs    V/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/tap.pyr,   Options.__init__X   sK    t$YV!^W'++VtG}    c           	          [         R                  " U R                  [        R                  " SSSS5      5      n[
        R                  " U[        SS9  XS'   g)	zP
(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/   r;   Options.opt_port`   sH    
 33MM;..y"aC
 	c$61EVr1   c           	          [         R                  " U R                  [        R                  " SSSS5      5      n[
        R                  " U[        SS9  XS'   g)	z?
(DEPRECATED: use --listen)
Port to listen on for Secure HTTP.
r3   r4   r5   r   r6   r7   r+   N)r   r:   	opt_httpsr<   r=   r>   r?   r@   rA   s      r/   rE   Options.opt_httpsm   sH    
 33NNK//	2q!D
 	c$61EWr1   c                 ,    U S   R                  U5        g)zQ
Add an strports description of port to start the server on.
[default: tcp:8080]
r)   Nappend)r.   r*   s     r/   
opt_listenOptions.opt_listenx   s    
 	WT"r1   c                 ,    U S   R                  U5        g)zZ
Add the name of a file used to check for directory indexes.
[default: index, index.html]
r&   NrH   )r.   	indexNames     r/   	opt_indexOptions.opt_index   s    
 	Yy)r1   c                 4    [         R                  " 5       U S'   g)zK
Makes a server with ~/public_html and ~/.twistd-web-pb support for
users.
r'   N)r   UserDirectoryr-   s    r/   opt_userOptions.opt_user   s    
 ,,.Vr1   c                    [         R                  " [        R                  R	                  U5      5      U S'   [
        R                  [
        R                  S.U S   l        [        R                  U S   R                  S'   g)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.   rW   s     r/   opt_pathOptions.opt_path   s]     {{277??4#89V''))#
V +0//V'r1   c                     [        U S   [        R                  5      (       d  [        R                  " S5      eUR                  SS5      u  p#[        R                  " U5      U S   R                  U'   g)zP
`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   rU   r
   
UsageErrorsplitr   
namedClassr[   )r.   procextklasss       r/   opt_processorOptions.opt_processor   s\    
 $v,44""#OPPZZQ'
'.'9'9%'@V$r1   c                 D    [         R                  " U5      nU" 5       U S'   g)z>
Create a Resource subclass with a zero-argument constructor.
r'   N)r   re   )r.   	classNameclassObjs      r/   	opt_classOptions.opt_class   s     %%i0zVr1   c                 6    [         R                  " U5      U S'   g)z@
An .rpy file to be used as the root resource of the webserver.
r'   N)r   ResourceScriptWrapper)r.   names     r/   opt_resource_scriptOptions.opt_resource_script   s     33D9Vr1   c                 x    [         R                  " U5      n[        R                  " 5       n[        R                  " UR                  5        [        R                  " SSUR                  5        [        R                  " [        X25      U S'   g! [        [        4 a    [        R
                  " SU< 35      ef = f)zW
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
   rc   r	   
ThreadPoolr   callWhenRunningstartaddSystemEventTriggerstopr   WSGIResource)r.   rr   applicationpools       r/   opt_wsgiOptions.opt_wsgi   s    
	J!**40K $$&

+%%gz499E(($DV 
+ 	J""%?x#HII	Js   B +B9c                     [        U S   [        R                  5      (       d  [        R                  " S5      eXS   l        g)z1
Specify the default mime-type for static files.
r'   z*You can only use --mime_type after --path.N)rb   r   rU   r
   rc   defaultType)r.   r   s     r/   opt_mime_typeOptions.opt_mime_type   s5     $v,44""#OPP#.V r1   c                     [        U S   [        R                  5      (       d  [        R                  " S5      eU S   R                  S5        g)zD
Specify whether or not a request for 'foo' should return 'foo.ext'
r'   z1You can only use --allow_ignore_ext after --path.*Nrb   r   rU   r
   rc   	ignoreExtr-   s    r/   opt_allow_ignore_extOptions.opt_allow_ignore_ext   sC     $v,44""F  	Vs#r1   c                     [        U S   [        R                  5      (       d  [        R                  " S5      eU S   R                  U5        g)zD
Specify an extension to ignore.  These will be processed in order.
r'   z+You can only use --ignore_ext after --path.Nr   )r.   rg   s     r/   opt_ignore_extOptions.opt_ignore_ext   s=     $v,44""#STTVs#r1   c                     UR                  SS5      u  p#U S   R                  UR                  5       UR                  5       45        g)zg
Specify an additional header to be included in all responses. Specified
as "HeaderName: HeaderValue".
:ra   r(   N)rd   rI   strip)r.   headerrr   values       r/   opt_add_headerOptions.opt_add_header   s:    
 ll3*^##TZZ\5;;=$ABr1   c                 \   U S   b  U S   R                  U S   5        U S   bG   [        R                  " S5        SR                  U S   U S   U S	   5      nU S   R                  U5        [        U S   5      S
:X  a  U S   (       am  [        R                  R                  [        R                  R                  S[        R                  R                  5      5      nU S   R                  SU-   5        gU S   R                  S5        gg! [         a    [        R
                  " S5      ef = f)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)rI   r   namedModuleImportErrorr
   rc   formatlenrV   rW   
expanduserjoinr   rQ   userSocketName)r.   
sslStrportrW   s      r/   postOptionsOptions.postOptions   s    <#M  f.=$D##M2 @FFWY]#J
 M  ,tG}"Jww))GGLLg&;&;&J&JK W$$Wt^4W$$Z0 #  D&&'BCCDs   D
 
!D+ N)&__name__
__module____qualname____firstlineno____doc__synopsisoptParametersoptFlagsrI   r   rQ   r   r
   CompletionsCompleteFilescompDatalongdescr,   r;   opt_prE   rJ   rN   opt_irR   opt_ur]   ri   rn   rs   r   r   opt_mr   r   r   r   __static_attributes__r   r1   r/   r   r      s(    H 	R	
	
M"	
	
H( OO %,$9$9$H$HK ..	
	   **73 ..w7**73
HGH,	 E	#* E/ E:A":E/ E$$C1r1   r   c                 V    [         R                  " [        R                  " U 5      5      $ )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=>>r1   c                        \ rS rSrS rS rSrg)_AddHeadersResourcei  c                     Xl         X l        g N)_originalResource_headers)r.   originalResourceheaderss      r/   r,   _AddHeadersResource.__init__  s    !1r1   c                     U R                    H   u  p4UR                  R                  X45        M"     U R                  R	                  X5      $ r   )r   responseHeadersaddRawHeaderr   getChildWithDefault)r.   rr   requestr   vs        r/   r   '_AddHeadersResource.getChildWithDefault  s=    MMDA##006 "%%99$HHr1   )r   r   N)r   r   r   r   r,   r   r   r   r1   r/   r   r     s     Ir1   r   c           	      0   [         R                  " 5       nU S   (       a  U S   nU S   (       a  U S   U S   l        O[        R                  " 5       n[        U[        R                  5      (       a*  UR                  R                  [        R                  U5        U S   (       a  [        X S   5      nU S   (       a  [        R                  " X S   S9nO[        R                  " U5      nU S   (       a  SUl        U S   (       aH  [         R"                  " S	[$        R&                  " S
SSS5      5      n[(        R*                  " U[,        SS9  U S   (       a  [/        U5      nU S    H*  n[0        R                   " XS5      nUR3                  U5        M,     U$ )Nr'   r&   r(   r   )logPathr    Tr   z--notracebacksr3         r   r6   r7   r"   r)   )r   MultiService
indexNamesr   Testrb   r   rU   registrysetComponentr   IServiceCollectionr   r   SitedisplayTracebacksr   _getDeprecationWarningStringr<   r=   r>   r?   r@   r   r   setServiceParent)configsr'   r   rB   r*   svcs          r/   makeServicer     sK   Af~f~)(.y(9F6N% yy{$$$"":#@#@!Dn"4)?@i{{4	):;{{4 "#!% n44k11)RAF
 	c$61Ej(.wt*Q   Hr1   )r   rV   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   r1   r/   <module>r      s^   

 
   1 0 @ @  T T To1emm o1d?I(++ I$r1   