o k`L@sddlZddlZddlmZddlZddlZddlZddlZddlZddl m Z m Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZmZmZmZmZmZmZddlTdd lmZdd l m!Z!m"Z"dd l#m$Z$m%Z%dd l&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9m:Z:ddl;mZ>m?Z?m@Z@mAZAddlBmCZCmDZDmEZEmFZFmGZGddlHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTddlUmVZVmWZWmXZXmYZYmZZZddl[m\Z\ddl]m^Z^m_Z_dZ`Gddde^ZaGdddebZcGdddeQZdGdddeeZfe gd Zhd!d"Zid#d$d%difd&d'Zjd(d)Zkd*d+Zl  d3d,d-Zmd.d/Znd4d1d2ZodS)5N)partial)pformatpprint)urlparse)FileSystemLoader) __version__) BoolOption ChoiceOption ConfigSectionConfigurationErrorExtensionOptionOptionOrderedExtensionsOption)*)open_environment)get_plugin_infomatch_plugins_to_frames)PermissionCachePermissionError)ResourceNotFound)arityget_frame_infoget_last_traceback hex_entropylazy read_file safe_repr translation) get_thread_id)format_datetimelocaltztimezone user_time)tagvalid_html_bytes)exception_to_unicode jinja2env shorten_line to_unicodeto_utf8 unicode_quote)_get_negotiated_locale has_babelsafefmttag_) HTTPBadRequest HTTPException HTTPForbiddenHTTPInternalServerError HTTPNotFoundIAuthenticatorIRequestFilterIRequestHandlerRequest RequestDoneTracNotImplementedErroris_valid_default_handler)ChromeITemplateProvider add_noticeadd_stylesheet add_warning)Href) SessionDictSessionzhttps://trac.edgewall.orgc@seZdZdddZddZdS) FakeSessionFcCdSN)selfsid authenticatedrGrG//usr/lib/python3/dist-packages/trac/web/main.py get_sessionGzFakeSession.get_sessioncCrErFrGrHrGrGrKsaveJrMzFakeSession.saveNF)__name__ __module__ __qualname__rLrOrGrGrGrKrDEs  rDc@s>eZdZdZd ddZ  d ddZeZ  d dd ZeZdS) FakePerm anonymousFcCs|SrFrG)rHrealm_or_resourceidversionrGrGrK__call__RrMzFakePerm.__call__NcCsdS)NFrG)rHactionrVrWrXrGrGrKhas_permissionUszFakePerm.has_permissioncCs|durt|t|d)Nmsg)r)rHrZrVrWrXmessagerGrGrKrequire[s zFakePerm.require)FF)NFF)NFFN) rQrRrSusernamerYr[ __contains__r_assert_permissionrGrGrGrKrTNs   rTcs"eZdZdZdfdd ZZS)RequestWithSessionzCA request that saves its associated session when sending the reply.cs"|dkr |jt|dS)Ni)sessionrOsuper send_response)rHcode __class__rGrKrghs z RequestWithSession.send_response)rd)rQrRrS__doc__rg __classcell__rGrGrirKrcesrcc@sHeZdZdZdZeeeeZ ee Z e dde ddZedde dd Zedd d d Zedd d dZeddddZeddddZeddddZeddZddZddZddZd d!Zd"d#Ze d$d%Z!d&d'Z"d(d)Z#d*d+Z$d,d-Z%d.d/Z&d0d1Z'd2d3Z(d4d5Z)e d6d7Z*d8d9Z+e d:d;Z,dd?Z.d@dAZ/dBS)CRequestDispatcherzWeb request dispatcher. This component dispatches incoming requests to registered handlers. It also takes care of user authentication and request pre- and post-processing. Ttracrequest_filtersz1Ordered list of filters to apply to all requests.)docdefault_handler WikiModuleaXName of the component that handles requests to the base URL. Options include `TimelineModule`, `RoadmapModule`, `BrowserModule`, `QueryModule`, `ReportModule`, `TicketModule` and `WikiModule`. The [/prefs/userinterface session preference] for default handler take precedence, when set. default_timezonezThe default timezone to usedefault_languagezJThe preferred language to use if no user preference has been set. default_date_format)rtiso8601zThe date format. Valid options are 'iso8601' for selecting ISO 8601 format, or leave it empty which means the default date format will be inferred from the browser's default language. (''since 1.0'') use_xsendfilefalsea*When true, send a `X-Sendfile` header and no content when sending files from the filesystem, so that the web server handles the content. This requires a web server that knows how to handle such a header, like Apache with `mod_xsendfile` or lighttpd. (''since 1.0'') xsendfile_headerz X-SendfileztThe header to use if `use_xsendfile` is enabled. If Nginx is used, set `X-Accel-Redirect`. (''since 1.0.6'')z http-headersa; Headers to be added to the HTTP request. (''since 1.2.3'') The header name must conform to [https://tools.ietf.org/html/rfc7230 RFC7230] and the following reserved names are not allowed: content-type, content-length, location, etag, pragma, cache-control, expires. c Cs~|jD]9}z||}Wn)ty5}z|jd|jjt|ddt|t dWYd}~dSd}~ww|r<|SqdS)NzCan't authenticate using %s: %sT tracebackz8Authentication error. Please contact your administrator.rU) authenticators authenticate TracErrorlogerrorrjrQr%r@r+)rHreq authenticatorauthnameerGrGrKr~s"   zRequestDispatcher.authenticatec Cs|jd|t|j}zd}|jD] }||r |}nq|s-|jdvr-||}|jd|| ||}|sd|j dr^t |j d}|j rT|d|j 7}|j|j|ddtd |jt|j|d |jd <|jd kr|d }|rt|\}}|dvr|jd|jkr|jjr|jdkrtd}ntd}ttd|d||} | r|j |g| R\} } } d|jvr|j!"dt#j$t#%dddd} t&| | | d| | j'(} Wdn1swY|)| d|jd| | *d|j+| d}|,|| | | }|)||pdWdS|jd | |WdSt-y3t.y}zt/0}z| |WnQt-yOt1yj}z|j2d!t3|WYd}~n2d}~wt.y}z!t4|t4|ur|j|jks|j5d!t3|dd"WYd}~nd}~wwt6|t7rt8||t6|t9rt||t6|t:rt;<|d#d$}|j2d%|j=j>|d&|d'|d#t?|pd(t@tA||t6|t1rt@|||d}~ww))zFind a registered handler that matches the request and let it process it. In addition, this method initializes the data dictionary passed to the the template and adds the web site chrome. zDispatching %rN)rt/zChosen handler is %sr?T) permanentz No handler matched request to %s)handlerchromePOST Content-Type)z!application/x-www-form-urlencodedzmultipart/form-data __FORM_TOKENhttpz?Secure cookies are enabled, you must use https to submit forms.zDo you have cookies enabled?z&Missing or invalid form token. %(msg)sr\hdfdump TRAC_ADMINutf-8 )encodingnewline write_through)templatemetadatadata text/plainz#Rendering response with template %siterable content_type text/htmlzAEmpty or no response from handler. Entering post_process_request.z2Exception caught while post-processing request: %sr{z%s caught from %s:%d in %s: %srz (no message))Brdebugr<env_request_handlersvalues match_request path_info_get_valid_default_handler_pre_process_requestendswithr*rstrip query_stringredirecthrefr4rprepare_request callbacksmethod get_headercgi parse_headerargsget form_tokensecure_cookiesschemer+r0process_request_post_process_requestpermr_io TextIOWrapperBytesIOrbuffergetvaluesend setdefaultuse_chunked_encodingrender_templater9 Exceptionsysexc_inforwarningr%typer isinstancerr2rNotImplementedErrorr| extract_tbrjrQr(r3r:)rHrrchosen_handlerrtargetctypeoptionsr]resprrroutroutputrerre2tbrGrGrKdispatchs                           zRequestDispatcher.dispatchcCsgSrFrGrNrGrGrKget_htdocs_dirs2rMz!RequestDispatcher.get_htdocs_dirscCstddgS)Nztrac.web templates) pkg_resourcesresource_filenamerNrGrGrKget_templates_dirs5sz$RequestDispatcher.get_templates_dirscCsD|j|jt|jj|j|j|j|j |j |j |j |j |jd dS)zASetup request callbacks for lazily-evaluated properties. ) rrrlc_timelocalerretzrxrzconfigurable_headersN)rupdater~r<rr_get_form_token _get_lc_time _get_locale _get_perm _get_session _get_timezone_get_use_xsendfile_get_xsendfile_header_get_configurable_headersrHrrGrGrKset_default_callbacks:s  z'RequestDispatcher.set_default_callbackscCsdd|jDS)NcSsi|]}|jj|qSrG)rjrQ).0rrGrGrK Msz7RequestDispatcher._request_handlers..)handlersrNrGrGrKrKsz#RequestDispatcher._request_handlersc Csx|jd}|j|}|rt|sd}|s:|j}t|s:ttdt|j j tdtj t d|j ddd|S)Nrqz%(handler)s is not a valid default handler. Please update %(option)s through the %(page)s page or by directly editing trac.ini.z[trac] default_handlerzBasic Settingszgeneral/basicsr)roptionpage)rerrr;rqr r/r#rhrjrQar+radmin)rHrnamerrGrGrKrPs"      z,RequestDispatcher._get_valid_default_handlercCs t|jtr tSt|j|jSrF)rrerDrTrrrrrGrGrKres zRequestDispatcher._get_permc Csjzt|j|WSty4}z!d}t|tr|j||n |j|t|t WYd}~Sd}~ww)Nzcan't retrieve session: %s) rCrrrTracValueErrorrrrr%rD)rHrrr]rGrGrKrks zRequestDispatcher._get_sessioncCs@tr|jd}|j}t||g|j}|jd|||SdS)NlanguagezNegotiated locale: %s -> %s)r-rerrur, languagesrr)rHr preferreddefault negotiatedrGrGrKrvs  zRequestDispatcher._get_localecCs4|jd}|r|dkrts|j}|dkrdS|jS)Nrrrw)rerr-rvr)rHrrrGrGrKrs zRequestDispatcher._get_lc_timecCs2z t|jd|jp dWStytYSw)Nrmissing)r!rerrsrr rrGrGrKrs zRequestDispatcher._get_timezonecCsdd|jvr |jdjStd|jd<}|jpd|jdd<|jjr)d|jdd<d|jdd<|S)aUsed to protect against CSRF. The 'form_token' is strong shared secret stored in a user cookie. By requiring that every POST form to contain this value we're able to protect against CSRF attacks. Since this value is only known by the user and not by an attacker. If the the user does not have a `trac_form_token` cookie a new one is generated. trac_form_tokenrpathTsecurehttponly)incookievaluer outcookie base_pathrr)rHrrrGrGrKrs z!RequestDispatcher._get_form_tokencC|jSrF)rxrrGrGrKrz$RequestDispatcher._get_use_xsendfilecCs6|j}t|r |S|jsd|_|jd|dS)NTz([trac] xsendfile_header is invalid: '%s')rzstripr8is_valid_header_warn_xsendfile_headerrr)rHheaderrGrGrK_xsendfile_headers  z#RequestDispatcher._xsendfile_headercCrrF)r rrGrGrKrrz'RequestDispatcher._get_xsendfile_headercCspg}g}|jD]\}}t||r|||fq |||fq |r4|jdddd|Dt|S)Nz.[http-headers] invalid headers are ignored: %s, cs|]}d|VqdS)z%r: %rNrG)rirGrGrK z:RequestDispatcher._configurable_headers..) rrr8rappendrrjointuple)rHheadersinvalidsrvalrGrGrK_configurable_headerss z'RequestDispatcher._configurable_headerscCs t|jSrF)iterrrrGrGrKrs z+RequestDispatcher._get_configurable_headerscCs|jD]}|||}q|SrF)filterspre_process_request)rHrrfilter_rGrGrKrs z&RequestDispatcher._pre_process_requestcGsi}|}t|dkr|d}nt|dkr||f7}nt|dkr#d}t|jD]}|j|g|R}t|dkr>||f7}q(|S)Nrr)NNN)lenreversedrpost_process_request)rHrrrrfrGrGrKrs       z'RequestDispatcher._post_process_requestN)0rQrRrSrkrequired implementsr=ExtensionPointr5r}r7rrr6rr rqr rsrur rvrrxrzr rr~rrrrrrrrrrrrrrr rrrrrrGrGrGrKrmnsl   q        rmz/+c s|d}|dur1|d}|s||d<ntd|}td|}||r1|dt| |d<|dtd|dtd |d td |d td |dd|dtdt tj |d|d}|s |d}|d}|s|r |dd d d}| d}|st||||gSd}|dd} zt| tr| d} t| d} Wn tyd| }Yn-wt| ||d<dd||d<|rtj||}nt||}|rtj|sd}|r |d}|dddtt|fg|gS|std|d} d} } z t|| d} Wnty8} z| } WYd} ~ nKd} ~ ww| jrB| j|d<t| ds|d}|rpd d!d"d#|D|d$|d%ped&f}|d'|d(|d)| _| jr|d*| _ t!||| r| j"j#sj"| _"t$%fd+d,| r| jndg}zz0| rt&| t'| }|(z|)Wnt*y}z |j+}WYd}~nd}~wwWn2t,y} zj-st.| | WYd} ~ n#d} ~ wtyj-st/| t01Yn w|pj2pg}Wt$3| r$| s$| 4t5t67}|St$3| r:| s:| 4t5t67}|YS)-zMain entry point for the Trac web interface. :param environ: the WSGI environment dict :param start_response: the WSGI callback for starting the response SCRIPT_URLN PATH_INFO SCRIPT_NAMErz trac.env_pathTRAC_ENVtrac.env_parent_dirTRAC_ENV_PARENT_DIRtrac.env_index_templateTRAC_ENV_INDEX_TEMPLATEtrac.template_varsTRAC_TEMPLATE_VARSz trac.localertz trac.base_url TRAC_BASE_URLtrac.env_pathsrz iso-8859-1rzInvalid URL encoding (was %r)zEnvironment not foundz 404 Not Found)rrzContent-LengthzThe environment options "TRAC_ENV" or "TRAC_ENV_PARENT_DIR" or the mod_python options "TracEnv" or "TracEnvParentDir" are missing. Trac requires one of these options to locate the Trac environment(s). wsgi.run_once use_cache webfrontendzmod_wsgi.versionz0%s (WSGIProcessGroup %s WSGIApplicationGroup %s).css|]}t|VqdSrF)str)rxrGrGrKrKrz#dispatch_request..zmod_wsgi.process_groupzmod_wsgi.application_groupz %{GLOBAL}mod_wsgi)trac.web.frontendtrac.web.versionr8r9csjSrF)rrGrrGrKZsz"dispatch_request..)8r _slashes_resubrrrosgetenvr setlocaleLC_ALLlstripsplitpopsend_project_indexrr5encodeUnicodeDecodeErrorrArrget_environmentsisdirEnvironmentErrorrrbase_url_for_redirectbase_urlhasattrrr3webfrontend_versionrcabs_hrefbasermake_activabler3rmrrr9rr1response_started_send_user_errorsend_internal_errorrr _response deactivateshutdownrgccollect)environstart_response script_urlrenv_pathenv_parent_dir env_pathsenv_nameerrmsg script_namerun_oncer env_errorrmod_wsgi_versionr dispatcherreq_done unreachablerGr:rKdispatch_requests                                riz error.htmlrc Cs|rAt|dddd}z t|||||}Wn:ty@d|d<z t|||||}Wnty=t}d}YnwYnwd}d|d |d |d f}t|tr]|d }z | ||||WdSt yrYdSw) Nzcommon/css/code.cssrF)rrTtrac_error_renderingrz %s %s: %stitlerr^r) r?r<rrrrrr5rF send_errorr9) rrrrstatusrrrcontentrGrGrK _send_errors>          rpc Cs|r|jd|jt|||jd|jd|jgdd}|jdkr:|j s:t j t d|j d}t|td|d t|t|j||d dS) Nz[%s] %s, %r, referrer %r HTTP_REFERERr)rlrr^framesr|izdo sorz?You are currently not logged in. You may want to %(do_so)s now.)do_sornrr)rr remote_addrr%rZrrlr^rhis_authenticatedr#rr+rloginr>r/rprr)rrrrrsrGrGrKrSs   rScsrjdjjdt|dddt|d}tggggf\}}}d}zdjvWn ty>dYnwt }i} rt |dt st |d }rd d t Dt|d d D}|jd dd|r|dd} | dd} d| vr| d}nt| jt|jkr|}| ddddd} d| i} t}fdd} | dd}z| t}Wn ty|}Ynwdd||tt|||| ||d}rtttd|ddS) Nz-[%s] Internal Server Error: %r, referrer %r%srqrTr{zhttp://trac-hacks.orgrFrcSs*g|]}tdd|dDr|qS)css*|]}|dD]}|dVq qdS) componentsenabledN)r)rmcrGrGrKrs z1send_internal_error...modules)anyrrprGrGrK s   z'send_internal_error..cSsg|]}d|vr|qS) frame_idxrGr~rGrGrKrscSs|dS)NrrG)rrGrGrKr;sz%send_internal_error..keyrinfo home_pagertrnrr componentc sr6r6dfddjD}|d7}dfddD}t}dddt|D}n d}d}d }d jjtj |||t d S) Nrtc3s4|]\}}d||r|ddndfVqdS)|| '''`%s`''' || `%s` || rz ` [[br]] `N/AN)replacerkvr+rGrKrs z?send_internal_error..get_description..z{|| '''`jQuery`''' || `#JQUERY#` || || '''`jQuery UI`''' || `#JQUERYUI#` || || '''`jQuery Timepicker`''' || `#JQUERYTP#` || c3s,|]}d|d|dpdfVqdS)rrrXrNrGr~rrGrKrs  css0|]\}}d|ddd|DfVqdS)z|| **%s** || %s || r csr )z`%s`NrG)rr rGrGrKrrzIsend_internal_error..get_description...N)rrrGrGrKrs  z%''System information not available'' z%''Plugin information not available'' z6''Interface customization information not available'' a==== How to Reproduce While doing a %(method)s operation on `%(path_info)s`, Trac issued an internal error. ''(please provide additional details here)'' Request parameters: {{{ %(req_args)s }}} User agent: `#USER_AGENT#` ==== System Information %(sys_info)s ==== Enabled Plugins %(enabled_plugins)s ==== Interface Customization %(interface_customization)s ==== Python Traceback {{{ %(traceback)s}}})rrreq_argssys_infoenabled_pluginsinterface_customizationr|) r system_infor<!get_interface_customization_filessorteditemsrrrrr()r+rrfilesinterface_filesr has_adminpluginsrr|rrKget_descriptions,     z,send_internal_error..get_descriptionc[s t||SrF)r.)skwrGrGrKr;s zInternal Errorinternal)rlrr^r|rrr'reprrfaulty_plugins interfacetracker tracker_args descriptiondescription_enrjrt)rrrurZrr%rrrdefault_trackerr MemoryErrorrrrsortrnetlocrrCr<rr+r'r add_jquery_uirprr)rrrr^rrrinterface_customthrrrr plugin_namerrrrrGrrKrTsl         4   rTc Cst||}tddg}|jdr&|jd}tj|\}}|d|nd}t t |t d|d} |jdrO|jdd D] } | d \} } | | | <qAt |j } g}t|D]9\}}z t||d  d }Wnty}z |t|d }WYd}~nd}~ww||j|j| |d}||q\|jddd|| d<tt|d}|jtj||}t|jdi|  d}|!drdnd}z |"||WdSt#yYdSw)Nrnrr*rz index.html)rXtime)rnrr,,=r0r1)rr)rrrrcSs |dS)Nr)lower)projrGrGrKr;Hs z$send_project_index..rprojects)loaderrz.xmlztext/xmlrrG)$r8rrrZrr>rrCinsert TRAC_VERSIONr"rrArrHrrrr( project_nameproject_descriptionrrr&rglobalsrr functions get_templater$renderrFrrr9)rZr[ parent_dirr_r loadpathsenv_index_template tmpl_pathrrpairrrrrr`r]rrrjenvtmplrrrGrGrKrE$sZ          rEcCsPtj|d}z ddt|D}Wn ty dgYSwdd|DS)z~Return the list of patterns from env_parent_dir/.tracignore or a default pattern of `".*"` if the file doesn't exist. z .tracignorecSsg|]}|qSrG)rrlinerGrGrKr]sz+get_tracignore_patterns..z.*cSsg|] }|r|ds|qS)#) startswithrrGrGrKr`s)r>rrr splitlinesIOError)r^rlinesrGrGrKget_tracignore_patternsWs  rFcs|dg}|dr0tjtfddtD}|fdd|Di}|D]/}tj|}tj|sCq4tj|d}||vr_|r^t d|||ft j d q4|||<q4|S) zRetrieve canonical environment name to path mapping. The environments may not be all valid environments, but they are good candidates. r/r(cs<g|]tjtjrtfddDsqS)c3s|] }t|VqdSrF)fnmatch)rpatternrrGrKrqsz.get_environments...)r>rrIrr})rr^ignore_patternsrrKros  z$get_environments..c3s|] }tj|VqdSrF)r>rr)rproject)r^rGrKrssz#get_environments..rzCWarning: Ignoring project "%s" since it conflicts with project "%s")file) rr>rnormpathrlistdirextendrIrCprintrstderr)rZwarnr_pathsenvsr]r`rGrrKrHcs2       rH)NNrP)prr functoolsrrXrrr>rrrrerr| urllib.parserjinja2rrnrr trac.configrr r r r r r trac.coretrac.envr trac.loaderrr trac.permrr trac.resourcer trac.utilrrrrrrrrtrac.util.concurrencyrtrac.util.datefmtrr r!r"trac.util.htmlr#r$trac.util.textr%r&r'r(r)r*trac.util.translationr+r,r-r.r/ trac.web.apir0r1r2r3r4r5r6r7r8r9r:r;trac.web.chromer<r=r>r?r@ trac.web.hrefrAtrac.web.sessionrBrCrrDobjectrTrc Componentrmcompiler<rirprSrTrErrHrGrGrGrKsf    $  (  8    p%  r 3