o k`@sdZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlmZmZddlTddlTddlmZmZdd lmZddlTdd lmZmZmZmZmZm Z m!Z!m"Z"m#Z#dd l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd l,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6dd l7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJddlKmLZLmMZMddlNmOZOmPZPddlQmRZRddlSmTZTddlUmVZVmWZWmXZXdZYdZZGddde[Z\Gddde[Z]ddZ^d@ddZ_dAddZ`dBd d!ZadCd#d$Zbifd%d&Zcd'd(Zdd)d*Zed+d,ZfdDd-d.ZgdEd/d0Zh 1 1dFd2d3Zid4d5ZjdEd6d7Zkd8d9Zld:d;Zmedd?d?eoZpdS)GzContent presentation for the web layer. The Chrome module deals with delivering and shaping content to the end user, mostly targeting (X)HTML generation but not exclusively, RSS or other forms of web content are also using facilities provided here. )contextmanagerN)partial)FileSystemLoader)IEnvironmentSetupParticipantISystemInfoProvider)*)RenderingContext get_mimetype)IPermissionRequestor) as_boolas_int get_pkginfoget_reporter_idhtmlpathjoin presentationto_list translation)ElementMarkupescape plaintexttag to_fragmentvalid_html_bytes) exception_to_unicode is_obfuscatedjavascript_quote jinja2envobfuscate_email_address pretty_size shorten_line to_js_string to_unicodeunicode_quote_plus)pretty_timedelta datetime_nowformat_datetime format_date format_timefrom_utimestamp http_dateutcget_date_format_jquery_ui is_24_hoursget_time_format_jquery_ui user_timeget_month_names_jquery_uiget_day_names_jquery_uiget_timezone_list_jquery_uiget_first_week_day_jquery_ui"get_timepicker_separator_jquery_uiget_period_names_jquery_uilocaltz)_get_available_locales)IRequestHandler HTTPNotFound)Href)IWikiSyntaxProvider) format_toformat_to_htmlformat_to_oneliner)wikitimelineroadmapbrowsertickets newticketsearchadmin)loginlogoutprefshelpaboutc@ eZdZdZddZddZdS)INavigationContributorzZExtension point interface for components that contribute items to the navigation. cCdS)zThis method is only called for the `IRequestHandler` processing the request. It should return the name of the navigation item to be highlighted as active/current. NreqrQrQ1/usr/lib/python3/dist-packages/trac/web/chrome.pyget_active_navigation_itemJz1INavigationContributor.get_active_navigation_itemcCrP)aShould return an iterable object over the list of navigation items to add, each being a tuple in the form (category, name, text). The category determines the location of the navigation item and can be `mainnav` or `metanav`. The name is a unique identifier that must match the string returned by get_active_navigation_item. The text is typically a link element with text that corresponds to the desired label for the navigation item, and an href. NrQrRrQrQrTget_navigation_itemsRrVz+INavigationContributor.get_navigation_itemsN)__name__ __module__ __qualname____doc__rUrWrQrQrQrTrOEs rOc@rN)ITemplateProviderzExtension point interface for components that provide their own Jinja2 templates and/or accompanying static resources. cCrP)aReturn a list of directories with static resources (such as style sheets, images, etc.) Each item in the list must be a `(prefix, abspath)` tuple. The `prefix` part defines the path in the URL that requests to these resources are prefixed with. The `abspath` is the absolute path to the directory containing the resources on the local file system. NrQrQrQrQrTget_htdocs_dirsdrVz!ITemplateProvider.get_htdocs_dirscCrP)zUReturn a list of directories containing the provided template files. NrQrQrQrQrTget_templates_dirsprVz$ITemplateProvider.get_templates_dirsN)rXrYrZr[r]r^rQrQrQrTr\^s r\cCs|jdr|SdS)zXHelper function for creating accesskey HTML attribute according to preference values accesskeysN)sessionr )rSkeyrQrQrT accesskeyvsrbcCs*||||||d}|jdg|dS)z;Add a `` tag into the `` of the generated HTML.)contentz http-equivnameschemelangzxml:langmetasN)chrome setdefaultappend)rSrc http_equivrdrerfmetarQrQrTadd_meta|srmc Ksnd||f}|jdt}||vrdS||||d} | ||jdi} | |g| ||dS)zrAdd a link to the chrome info that will be inserted as element in the of the generated HTML z%s:%slinksetN)hreftitletypeclasslinks)rhrisetupdaterjadd) rSrelrorpmimetype classnameattrslinkidrnlinkrsrQrQrTadd_links  r}text/csscKs&t||}t|d|fd|i|dS)aAdd a link to a style sheet to the chrome info so that it gets included in the generated HTML page. If `filename` is a network-path reference (i.e. starts with a protocol or `//`), the return value will not be modified. If `filename` is absolute (i.e. starts with `/`), the generated link will be based off the application root path. If it is relative, the link will be based off the `/chrome/` path. stylesheetrxN)chrome_resource_pathr})rSfilenamerxrzrorQrQrTadd_stylesheets rtext/javascriptcCsp|jdt}||vrdSt||}dd|ii}|dkr'|dur'||dd<|jdg|||dS) aAdd a reference to an external javascript file to the template. If `filename` is a network-path reference (i.e. starts with a protocol or `//`), the return value will not be modified. If `filename` is absolute (i.e. starts with `/`), the generated link will be based off the application root path. If it is relative, the link will be based off the `/chrome/` path. scriptsetFrzsrcrNrqscripts)rhrirtrrjrv)rSrrxrroscriptrQrQrT add_scripts    rcKs&|jdi}||||dS)aAdd data to be made available in javascript scripts as global variables. The keys in `data` and the keyword argument names provide the names of the global variables. The values are converted to JSON and assigned to the corresponding variables. script_dataN)rhriru)rSdatakwargsrrQrQrTadd_script_datas rcGt|d||dS)zAdd a non-fatal warning to the request object. When rendering pages, all warnings will be rendered to the user. Note that the message is escaped (and therefore converted to `Markup`) before it is stored in the request object. warningsN _add_messagerSmsgargsrQrQrT add_warningrcGr)zAdd an informational notice to the request object. When rendering pages, all notices will be rendered to the user. Note that the message is escaped (and therefore converted to `Markup`) before it is stored in the request object. noticesNrrrQrQrT add_noticerrcCsH|r||;}t|tstt|}||j|vr"|j||dSdSN) isinstancerrrhrj)rSrdrrrQrQrTrs  rcCs2|r tj|||d}n|}|jdg|dS)z/Add an entry to the current page's ctxtnav bar.rorpctxtnavN)rarhrirj)rS elm_or_labelrorpelmrQrQrT add_ctxtnavsrc s|jdd}}tfdddDsdSdvr-dd}tj||d|d dd }t|tjtd |p7||s;d ndd |r[dvr[dd}t|tj||d|d ddvrrdd}tj||d|d dd }t|tj|py|td|sd ndd dS)a"Add Previous/Up/Next navigation links. :param req: a `Request` object :param prev_label: the label to use for left (previous) link :param up_label: the label to use for the middle (up) link :param next_label: the label to use for right (next) link rsNc3s|]}|vVqdSrrQ).0lnkrsrQrT szprevnext_nav..)prevupnextrrrorp)rorpclass_z← missingrrrrz →)rhanyrrrspanr) rS prev_label next_labelup_label prev_link next_linkrrnext_rQrrT prevnext_navs.        rFc CsH|r|r|jn|j}|j}nd}d}tt||||d||d}||_|S)aOCreate a rendering context from a request. The `perm` and `href` properties of the context will be initialized from the corresponding properties of the request object. >>> from trac.test import Mock, MockPerm >>> req = Mock(href=Mock(), perm=MockPerm()) >>> context = web_context(req) >>> context.href is req.href True >>> context.perm is req.perm True :param req: the HTTP request object :param resource: the `Resource` object or realm :param id: the resource identifier :param version: the resource version :param absurls: whether URLs generated by the ``href`` object should be absolute (including the protocol scheme and host name) :return: a new rendering context :rtype: `RenderingContext` :since: version 1.0 N)idversionparent)roperm)abs_hrefrorrResourcerS) rSresourcerrrabsurlsrorselfrQrQrT web_context s rcCs|jr |jj|dS|S)zReturn an "authenticated" link to `link` for authenticated users. If the user is anonymous, returns `link` unchanged. For authenticated users, returns a link to `/login` that redirects to `link` after authentication. )referer)is_authenticatedrorI)rSr|rQrQrT auth_link4src Cs<|j}|r|didg}|dg}|di}n4|didg|didg}|dg|dg}i}||d i||d ig}|d d |pZd D|dd |pfiDt}|r~|tjd|dd|D]}|d} |tdt | dt | dfq|S)zGet script elements from chrome info of the request object during rendering template or after rendering. :param req: the HTTP request object. :param use_late: if True, `late_links` will be used instead of `links`. late_linksr late_scriptslate_script_data early_linksrs early_scriptsrearly_script_datarcss,|]}dt|dt|dfVqdS)zjQuery.loadStyleSheet(%s, %s);rorqN)r")rr|rQrQrTrUs  z%chrome_info_script..rQcss&|]\}}d|t|fVqdS)z var %s=%s;N)rto_json)rrdvaluerQrQrTrXs r)rqrzzjQuery.loadScript(%s, %s)rrq) rhgetruextenditemsrrjrjoinr") rSuse_laterhrsrrrcfragmentrrzrQrQrTchrome_info_script@s<      rcCs\|dr|S|drd|jvrt|jd|ddS|dr&|jn|jj}||S)aGet the path for a chrome resource given its `filename`. If `filename` is a network-path reference (i.e. starts with a protocol or `//`), the return value will not be modified. If `filename` is absolute (i.e. starts with `/`), the generated link will be based off the application root path. If it is relative, the link will be based off the `/chrome/` path. )http://https://z//zcommon/htdocs_locationN/) startswithrhr<ro)rSrrorQrQrTrgs rcCs>dD]}t|j|D]\}}t|d|jd||f<q qdS)zdSave warnings and notices in case of redirect, so that they can be displayed after the redirect.rrF chrome.%s.%dN) enumeraterhrr`)rSurl permanenttype_imessagerQrQrT_save_messagesys rc cst||*zdVWnty'}zt|td|jjt|dd}~wwWddS1s3wYdS)z{Traps any runtime exception raised when working with a component, logs the error and adds a warning for the user. Nz!%(component)s failed with %(exc)s) componentexc)component_guard Exceptionrr8 __class__rXr)envrSrerQrQrTrs  "rc @s|eZdZdZeeeeee e dZ dZ e eZe e ZeddddZedddd Zed d dd Zed d ddZed dddddidZed dddddidZed dddddidZeddZeddZeddddZedd d!d"Zedd#d$d%Z e!dd&d'd(Z"e!dd)d'd*Z#ed d+d,d-Z$ed d.d/d0Z%ed d1d,d2Z&ed d3d/d4Z'ed d5d/d6Z(e)d d7d8d9Z*e+d d:d;d<Z,ed d=d/d>Z-d?Z.d?Z/d?Z0id@e1dAe2dBe3dCe4dDe5j6dEe5j5dFe7j8dGe9dHe:j;dIe<dJe=dKe>dLe?dMe@dNeAdOeBdPeCjDeEeFeGeHeIeJe5jKe5jLeMeNdQ ZOdRdSZPdTdUZQdVdWZRdXdYZSdZd[ZTd\d]ZUd^d_ZVd`daZWdbdcZXdddeZYdfdgZZdhdiZ[djdkZ\ddldmZ]dndoZ^ddpdqZ_drdsZ`dtduZadvdwZbddxdyZcdzd{Zdeefd|Zgd}d~ZhddZidddZjdddZkddZlddZmddZnddZoddZpdddZqdddZrddZsdddZtdddZudddZv  ?dddZwdddZxdddZyd?S)ChromezaWeb site chrome assembly manager. Chrome is everything that is not actual page content. TFinherit templates_dira"Path to the //shared templates directory//. Templates in that directory are loaded in addition to those in the environments `templates` directory, but the latter take precedence. Non-absolute paths are relative to the Environment `conf` directory. htdocs_diraPath to the //shared htdocs directory//. Static resources in that directory are mapped to /chrome/shared under the environment URL, in addition to common and site locations. This can be useful in site.html for common interface customization of multiple Trac environments. Non-absolute paths are relative to the Environment `conf` directory. (''since 1.0'')trac auto_reloadz7Automatically reload template files after modification.rasBase URL for serving the core static resources below `/chrome/common/`. It can be left empty, and Trac will simply serve those resources itself. Advanced users can use this together with [TracAdmin trac-admin ... deploy ] to allow serving the static resources for Trac directly from the web server. Note however that this only applies to the `/htdocs/common` directory, the other deployed resources (i.e. those from plugins) will not be made available this way and additional rewrite rules will be needed in the web server.jquery_locationaLocation of the jQuery !JavaScript library (version %(version)s). An empty value loads jQuery from the copy bundled with Trac. Alternatively, jQuery could be loaded from a CDN, for example: http://code.jquery.com/jquery-%(version)s.min.js, http://ajax.aspnetcdn.com/ajax/jQuery/jquery-%(version)s.min.js or https://ajax.googleapis.com/ajax/libs/jquery/%(version)s/jquery.min.js. (''since 1.0'')rz1.12.4)doc_argsjquery_ui_locationaLocation of the jQuery UI !JavaScript library (version %(version)s). An empty value loads jQuery UI from the copy bundled with Trac. Alternatively, jQuery UI could be loaded from a CDN, for example: https://ajax.googleapis.com/ajax/libs/jqueryui/%(version)s/jquery-ui.min.js or http://ajax.aspnetcdn.com/ajax/jquery.ui/%(version)s/jquery-ui.min.js. (''since 1.0'')z1.12.1jquery_ui_theme_locationaLocation of the theme to be used with the jQuery UI !JavaScript library (version %(version)s). An empty value loads the custom Trac jQuery UI theme from the copy bundled with Trac. Alternatively, a jQuery UI theme could be loaded from a CDN, for example: https://ajax.googleapis.com/ajax/libs/jqueryui/%(version)s/themes/start/jquery-ui.css or http://ajax.aspnetcdn.com/ajax/jquery.ui/%(version)s/themes/start/jquery-ui.css. (''since 1.0'')mainnavaConfigures the main navigation bar, which by default contains //Wiki//, //Timeline//, //Roadmap//, //Browse Source//, //View Tickets//, //New Ticket//, //Search// and //Admin//. The `label`, `href`, and `order` attributes can be specified. Entries can be disabled by setting the value of the navigation item to `disabled`. The following example renames the link to WikiStart to //Home//, links the //View Tickets// entry to a specific report and disables the //Search// entry. {{{#!ini [mainnav] wiki.label = Home tickets.href = /report/24 search = disabled }}} See TracNavigation for more details. metanavaConfigures the meta navigation entries, which by default are //Login//, //Logout//, //Preferences//, ''!Help/Guide'' and //About Trac//. The allowed attributes are the same as for `[mainnav]`. Additionally, a special entry is supported - `logout.redirect` is the page the user sees after hitting the logout button. For example: {{{#!ini [metanav] logout.redirect = wiki/Logout }}} See TracNavigation for more details. header_logor|z%URL to link to, from the header logo.rzsite/your_project_logo.pngaURL of the image to use as header logo. It can be absolute, server relative or relative. If relative, it is relative to one of the `/chrome` locations: `site/your-logo.png` if `your-logo.png` is located in the `htdocs` folder within your TracEnvironment; `common/your-logo.png` if `your-logo.png` is located in the folder mapped to the [#trac-section htdocs_location] URL. Only specifying `your-logo.png` is equivalent to the latter.altz8(please configure the [header_logo] section in trac.ini)z%Alternative text for the header logo.widthz)Width of the header logo image in pixels.heightz*Height of the header logo image in pixels.show_email_addressesfalsezShow email addresses instead of usernames. If false, email addresses are obfuscated for users that don't have EMAIL_VIEW permission. show_full_namestruez5Show full names instead of usernames. (//since 1.2//)never_obfuscate_mailtozNever obfuscate `mailto:` links explicitly written in the wiki, even if `show_email_addresses` is false or the user doesn't have EMAIL_VIEW permission. resizable_textareaszBMake `