o k`z?@s8ddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZddlmZddlmZmZddlmZddlmZmZGd d d eZGd d d eZGd ddeZGddde eZGdddeZGdddeZ dddZ!ddZ"e#dkre$de e"dSdS)N)ThreadingMixIn) __version__) autoreloaddaemonprinterr)BasicAuthenticationDigestAuthentication)dispatch_request) WSGIServerWSGIRequestHandlerc@seZdZdddZddZdS)AuthenticationMiddlewareNcCs*||_||_||_|rd|_dSd|_dS)Nr) applicationauthssingle_env_namepart)selfrrrr5/usr/lib/python3/dist-packages/trac/web/standalone.py__init__*s   z!AuthenticationMiddleware.__init__cCs|dd}ttd|d}t||jkrB||jdkrB|jp$|d}|rB|j||jd}|rB|||}|s>gS||d<| ||S)N PATH_INFO/loginr* REMOTE_USER) getlistfiltersplitlenrrrdo_authr)renvironstart_response path_info path_partsenv_nameauth remote_userrrr__call__3s   z!AuthenticationMiddleware.__call__N__name__ __module__ __qualname__rr*rrrrr (s  r c@eZdZddZddZdS)BasePathMiddlewarecCsd|d|_||_dS)Nr)strip base_pathr)rrr3rrrrDs zBasePathMiddleware.__init__cCs@|d|dd}|t|jd|d<|j|d<|||S)N SCRIPT_NAMErr)rr!r3r)rr#r$pathrrrr*Hs  zBasePathMiddleware.__call__Nr,rrrrr1Bs r1c@r0)TracEnvironMiddlewarecCsF||_ddi|_|r||jd<dS|r|d|jd<dS||jd<dS)Nz trac.env_pathztrac.env_parent_dirrztrac.env_paths)rr#)rrenv_parent_dir env_paths single_envrrrrQs zTracEnvironMiddleware.__init__cCs,|jD] \}}|||q|||Sr+)r#items setdefaultr)rr#r$kvrrrr*[s zTracEnvironMiddleware.__call__Nr,rrrrr6Os r6c@seZdZdZ dddZdS)TracHTTPServerTFcCs&ttf}tj||||t|ddS)N)request_handler)TracHTTPRequestHandlerTracHTTP11RequestHandlerr rbool)rserver_addressrr7r8 use_http_11request_handlersrrrrds   zTracHTTPServer.__init__N)F)r-r.r/daemon_threadsrrrrrr>asr>c@seZdZdeZddZdS)r@ztracd/cCs|jdddS)Nr)client_addressrrrraddress_stringosz%TracHTTPRequestHandler.address_stringN)r-r.r/VERSIONserver_versionrJrrrrr@ks r@c@seZdZdZdS)rAzHTTP/1.1N)r-r.r/protocol_versionrrrrrAtsrAc Cst}Gdddtj}Gdddtj}|jdddtd|jd |d d d d |}|jdd|d ddd|jddddd|}|jddidd|tdd|jdidd|td d|jd!d"td#d$|jd%d&d'd(d)|jd*d+d,d-d.|jd/d0d1|jd2d3d1|jd4d5dd6d|jd7d'd8d)|}|jd9d:d;ddd d?d@t j dAkr GdBdCdCtj}GdDdEdEtj}GdFdGdGtj}|}|jdHdIddJd|jdKdLddMd|jdN|dOd|jdP|dQdRdSdT|jdU|dVd|jdW|dXdn |jdHdIddJd|j dYdddZ| |}|j s,|js,|d[|jr=t|jd\kr=|d]|jd^krL|jsL|d_|jdur^d`dadbdcddd,|j|_|S)eNc(eZdZdfdd ZdddZZS)zparse_args.._AuthActionNcs(|d|_tj|||fi|dS)Ncls)poprOsuperrroption_stringsdestnargskwargs __class__rrr}s  z(parse_args.._AuthAction.__init__c Ss|d}t|dkrt|d|\}}}tj|} tj| s*t|d|t||j } || vr._AuthAction.__call__r+r-r.r/rr* __classcell__rrrWr _AuthAction{rncrN)zparse_args.._PathActionNcs*|dd|_tj|||fi|dS)N must_existF)rPrprQrrRrWrrrs z(parse_args.._PathAction.__init__csDfddt|trfdd|D}n|}t|j|dS)Ncs2tj|}jrtj|std||S)Nr[)r^r5r_rpr`r\r])r5r_rIrr to_abspaths z._PathAction.__call__..to_abspathcsg|]}|qSrr).0paths)rqrr sz._PathAction.__call__..) isinstancerrcrT)rrdrerfrgrsr)rrqrr*s  z(parse_args.._PathAction.__call__r+rlrrrWr _PathActionrorvz --versionversionz %%(prog)s %s)actionrwenvsTrz"path of the project environment(s))rxrprUhelpz-ez--env-parent-dir PARENTDIRz,parent directory of the project environments)rxrpmetavarrzz-sz --single-env store_truez4only serve a single project without the project list)rxrzz-az--auth DIGESTAUTHrz$[projectdir],[htdigest_file],[realm])defaultr|rTrxrOrzz --basic-auth BASICAUTHz$[projectdir],[htpasswd_file],[realm]z-pz--portzthe port number to bind to)typerzz-bz --hostnamerz&the host name or IP address to bind to)rrzz --protocolhttp)rhttpsscgiajpfcgiz#the server protocol (default: http))rchoicesrzz --certfilezPEM certificate file for HTTPS)rzz --keyfilezPEM key file for HTTPSz-qz --unquotez=unquote PATH_INFO (may be needed when using the ajp protocol)z --base-pathz/the initial portion of the request URL's "path"z--http10 store_falsehttp11z)use HTTP/1.0 protocol instead of HTTP/1.1)rxrTrzz--http11zuse HTTP/1.1 protocol (default))rxrrzposixc@eZdZdddZdS)z parse_args.._GroupActionNc Slddl}zt|}Wn"ty,z ||d}Wnty)t|d|wYnwt||j|dS)NrrGzgroup not found: %r) grpint ValueErrorgetgrnamKeyErrorr\r]rcrT)rrdrerfrgrvaluerrrr*   z)parse_args.._GroupAction.__call__r+r-r.r/r*rrrr _GroupActionrc@r)zparse_args.._UserActionNc Sr)NrrGzuser not found: %r) pwdrrgetpwnamrr\r]rcrT)rrdrerfrgrrrrrr*rz(parse_args.._UserAction.__call__r+rrrrr _UserActionrrc@s$eZdZejeddZdddZdS)z%parse_args.._OctalValueAction)baseNcSs@z||}Wntyt|d|wt||j|dS)NzInvalid octal umask value: %r)octalrr\r]rcrT)rrdrerfrgrrrrr*s z.parse_args.._OctalValueAction.__call__r+)r-r.r/ functoolspartialrrr*rrrr_OctalValueActionsrz-rz --auto-reloadz/restart automatically when sources are modifiedz-dz --daemonizez!run in the background as a daemonz --pidfilez"file to write pid when daemonizingz--umaskMASKzRwhen daemonizing, file mode creation mask to use, in octal notation (default: 022))rxrr|rzz--groupzthe group to run asz--userzthe user to run asF) daemonizeusergroupzUeither the --env-parent-dir (-e) option or at least one environment must be specifiedrzJthe --single-env (-s) option cannot be used with more than one environmentrz?the --certfile option is required when using the https protocolPiiiIi@)r\ArgumentParserAction add_argumentrKadd_mutually_exclusive_groupr rrr^name set_defaults parse_argsr7ryerrorr9r!protocolcertfileport)argsrdrnrv parser_grouprrrrrrrxs                  rc s|tttjjjjr*jr$tj jd}t j|nt jj dr7t jjfjdvrLfdd}n jdvrYfdd}z9jrgtjjdjd jdurrtjjdur}tjjrd d }t||WdS|WdSty}ztd |jj|ft !d WYd}~dSd}~wt"yYdSw)Nrr)rrc s\}}|r |dkrd|j|f}n dj||f}ztjjjd}Wn%tjyP}ztd|td|jt dWYd}~nd}~wwtdt td |jrftd jd krxt j|jd jjd |_|dS)Nz0.0.0.0z'0.0.0.0:%s view at %s://127.0.0.1:%s/%sz %s://%s:%s/%s)rDz Error starting Trac server on %sz [Errno %s] %srzServer starting in PID %s.z Serving on %szUsing HTTP/1.1 protocol versionrT) server_siderkeyfile)rr>r7ryrsocketrprintrsysexitr^getpidssl wrap_socketrr serve_forever)addrrlochttpderr3rCwsgi_apprrserveBs6        zmain..serve)rrrcsdj}zt|j}Wnty"tdjtdYnw}jr2ddl m }||}||d }t|rCddSddS)Nzflup.server.%sz1Install the flup package to use the '%s' protocolrr)FlupMiddleware) bindAddress*) r importlib import_moduler ImportErrorrrrunquotetrac.web.fcgi_frontendrrun)module server_clsflup_apprret)rrCrrrr]s   tracd)pidfileprognameumaskcSstd|dS)Nz(Detected modification of %s, restarting.r)filerrrmodification_callbackvsz#main..modification_callbackz%s: %sr)#rr6r r7ryr9rr^r5basenamer r3r2r1hostnamerrrrrrrsetgidrsetuid auto_reloadrmainOSErrorrrXr-rrKeyboardInterrupt) project_namerrrrrrr0sN             r__main__zTrac==%sr+)%r\rrr^ pkg_resourcesrrr socketserverrtracrrK trac.utilrrtrac.util.textr trac.web.authrr trac.web.mainr trac.web.wsgir r objectr r1r6r>r@rArrr-requirerrrrs8       9S