Ϫf(dZddlZddlZddlZddlmZmZddlmZm Z ddl m Z m Z m Z mZddlmZddlmZmZmZmZmZmZmZmZGdd ej4Zd ZGd d ej8Zd Zy)z9 Support for creating a service which runs a web server. N)servicestrports) interfacesreactor) deprecatereflect threadpoolusage)pb)demodistribresourcescriptserverstatictwcgiwsgiceZdZdZdZgdgdgdgZgdgdgZejdd d ejjd d zge je jd e jde jddZdZdZdZeZdZdZdZeZdZeZdZdZdZdZdZdZeZdZ dZ!d Z"d!Z#y")#OptionszB Define the options accepted by the I{twistd web} plugin. z [web options])logfilelNz/Path to web CLF (Combined Log Format) log file.) certificatec server.pemz=(DEPRECATED: use --listen) SSL certificate to use for HTTPS. )privkeykrz<(DEPRECATED: use --listen) SSL certificate to use for HTTPS.) notracebacksnzY(DEPRECATED: Tracebacks are disabled by default. See --enable-tracebacks to turn them on.)display-tracebackszShow 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 ~/ zif --listen is not specified.z*.logz*.pem)rrr) 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~tjj|g|d<d|d<g|d<g|d<dx|d<|d<y)Nindexesroot extraHeadersportsporthttps)r r__init__selfs 1/usr/lib/python3/dist-packages/twisted/web/tap.pyr+zOptions.__init__XsK t$YV !^W '++V tG}c tj|jtjdddd}t j |td||d<y) zh (DEPRECATED: use --listen) Strports description of port to start the server on Twistedrcategory stacklevelr)N)rgetDeprecationWarningStringopt_port incrementalVersionwarningswarnDeprecationWarningr-r)msgs r.r9zOptions.opt_port`sJ 33 MM;..y"aC   c$61EV r/c tj|jtjdddd}t j |td||d<y) zW (DEPRECATED: use --listen) Port to listen on for Secure HTTP. r1r2r3rr4r5r*N)rr8 opt_httpsr:r;r<r=r>r?s r.rBzOptions.opt_httpsmsJ 33 NNK// 2q!D   c$61EW r/c,|dj|y)zi Add an strports description of port to start the server on. [default: tcp:8080] r(Nappend)r-r)s r. opt_listenzOptions.opt_listenxs W T"r/c,|dj|y)zr Add the name of a file used to check for directory indexes. [default: index, index.html] r%NrD)r- indexNames r. opt_indexzOptions.opt_indexs Yy)r/c2tj|d<y)zc Makes a server with ~/public_html and ~/.twistd-web-pb support for users. r&N)r UserDirectoryr,s r.opt_userzOptions.opt_users ,,.V r/ctjtjj ||d<t j t jd|d_tj|djd<y)z 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) rFileospathabspathr PythonScriptResourceScript processorsr CGIScript)r-rPs r.opt_pathzOptions.opt_paths] {{277??4#89V ''))# V +0//V 'r/ct|dtjstjd|j dd\}}t j||dj|<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) isinstancerrNr UsageErrorsplitr namedClassrT)r-procextklasss r. opt_processorzOptions.opt_processors[ $v, 4""#OP PZZQ' U'.'9'9%'@V $r/cBtj|}||d<y)zN Create a Resource subclass with a zero-argument constructor. r&N)rr])r- classNameclassObjs r. opt_classzOptions.opt_classs%%i0zV r/c4tj||d<y)zP An .rpy file to be used as the root resource of the webserver. r&N)rResourceScriptWrapper)r-names r.opt_resource_scriptzOptions.opt_resource_scripts33D9V r/cj tj|}t j}tj|jtjdd|jtjt|||d<y#ttf$rt j d|wxYw)zo The FQPN of a WSGI application object to serve as the root resource of the webserver. zNo such WSGI application: aftershutdownr&N)rnamedAnyAttributeError ValueErrorr r[r ThreadPoolrcallWhenRunningstartaddSystemEventTriggerstopr WSGIResource)r-rh applicationpools r.opt_wsgizOptions.opt_wsgis  J!**40K$$& +%%gz499E(($ DV  + J""%?x#HI I Js B (B2c|t|dtjstjd||d_y)zA Specify the default mime-type for static files. r&z*You can only use --mime_type after --path.N)rZrrNr r[ defaultType)r-rzs r. opt_mime_typezOptions.opt_mime_types4$v, 4""#OP P#.V  r/ct|dtjstjd|dj dy)zT Specify whether or not a request for 'foo' should return 'foo.ext' r&z1You can only use --allow_ignore_ext after --path.*NrZrrNr r[ ignoreExtr,s r.opt_allow_ignore_extzOptions.opt_allow_ignore_exts@$v, 4""F  V s#r/ct|dtjstjd|dj |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_extzOptions.opt_ignore_exts:$v, 4""#ST T V s#r/c|jdd\}}|dj|j|jfy)z Specify an additional header to be included in all responses. Specified as "HeaderName: HeaderValue". :rYr'N)r\rEstrip)r-headerrhvalues r.opt_add_headerzOptions.opt_add_headers< ll3* e ^##TZZ\5;;=$ABr/cF|d|dj|d|dF tjddj |d|d|d }|dj|t|dd k(r|d rmtjjtjjd tjj}|djd |zy|djdyy#t$rt j dwxYw)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.SSLzSSL support not installedz$ssl:port={}:privateKey={}:certKey={}rrrr!~zunix:ztcp:8080)rEr namedModule ImportErrorr r[formatlenrOrP expanduserjoinr rKuserSocketName)r- sslStrportrPs r. postOptionszOptions.postOptionss < # M f . = $ D##M2@FFW Y]#J M  , tG}  "Jww))GGLLg&;&;&J&JKW $$Wt^4W $$Z0 # D&&'BCC Ds DD N)$__name__ __module__ __qualname____doc__synopsis optParametersoptFlagsrEr rKrr Completions CompleteFilescompDatalongdescr+r9opt_prBrFrIopt_irLopt_urVrarerirxr{opt_mrrrrr/r.rrs0H R  M"  H( OO  %,$9$9$H$H K. .  !u  *u**73.5..w7*u**73 HGH,  E #* E/ E :A": E/ E$$C1r/rcRtjtj|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.makePersonalServerFactoryrs    g77= >>r/ceZdZdZdZy)_AddHeadersResourcec ||_||_yN)_originalResource_headers)r-originalResourceheaderss r.r+z_AddHeadersResource.__init__s!1 r/c|jD]!\}}|jj||#|jj ||Sr)rresponseHeaders addRawHeaderrgetChildWithDefault)r-rhrequestrvs r.rz'_AddHeadersResource.getChildWithDefaultsHMM 7DAq  # # 0 0A 6 7%%99$HHr/N)rrrr+rrr/r.rrs  Ir/rc tj}|dr|d}|dr"|d|d_ntj}t |t jr*|jjtj||drt||d}|drtj||d}ntj|}|drd|_|drHt!j"d t%j&d d d d }t)j*|t,d|dr t/|}|dD])}t1j||}|j3|+|S)Nr&r%r'r)logPathrTrz--notracebacksr1rr4r5r!r()r MultiService indexNamesr TestrZrrNregistry setComponentrIServiceCollectionrrSitedisplayTracebacksr_getDeprecationWarningStringr:r;r<r=r>rrsetServiceParent)configsr&rr@r)svcs r. makeServicersRA f~f~ ) (.y(9F6N %yy{$ $ "":#@#@!D n"4)?@ i{{4 ):;{{4  "#!%n44 k11)RAF   c$61E j(.w tT* Q  Hr/)rrOr<r:twisted.applicationrrtwisted.internetrrtwisted.pythonrrr r twisted.spreadr twisted.webr r rrrrrrrrResourcerrrr/r.rs^   10@@TTTo1emmo1d?I(++I$ r/