o k`O@sddlZddlmZddlmZmZddlTddlmZddl m Z m Z ddl m Z ddlmZdd lmZGd d d eZGd d d eZGdddeZGdddeZdddZddZGdddeZdS)N)cached) BoolOption ListOption)*)IResourceManager)is_safe_origintag) unquote_label)_) WikiParserc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)IWikiChangeListenerzComponents that want to get notified about the creation, deletion and modification of wiki pages should implement that interface. cCdS)z)Called whenever a new Wiki page is added.Npagerr//usr/lib/python3/dist-packages/trac/wiki/api.pywiki_page_added%z#IWikiChangeListener.wiki_page_addedcCr )z%Called when a page has been modified.Nr)rversiontcommentauthorrrrwiki_page_changed(rz%IWikiChangeListener.wiki_page_changedcCr )z$Called when a page has been deleted.Nrrrrrwiki_page_deleted+rz%IWikiChangeListener.wiki_page_deletedcCr )z1Called when a version of a page has been deleted.Nrrrrrwiki_page_version_deleted.rz-IWikiChangeListener.wiki_page_version_deletedcCr )z$Called when a page has been renamed.Nr)rold_namerrrwiki_page_renamed1rz%IWikiChangeListener.wiki_page_renamedcCr )z-Called when a page comment has been modified.Nr)r old_commentrrrwiki_page_comment_modified4rz.IWikiChangeListener.wiki_page_comment_modifiedN) __name__ __module__ __qualname____doc__rrrrrrrrrrr s r c@ eZdZdZddZddZdS)IWikiPageManipulatorzComponents that need to do specific pre- and post- processing of wiki page changes have to implement this interface. Unlike change listeners, a manipulator can reject changes being committed to the database. cCr )aXValidate a wiki page before rendering it. :param page: is the `WikiPage` being viewed. :param fields: is a dictionary which contains the wiki `text` of the page, initially identical to `page.text` but it can eventually be transformed in place before being used as input to the formatter. Nr)reqrfieldsrrrprepare_wiki_page@rz&IWikiPageManipulator.prepare_wiki_pagecCr )apValidate a wiki page after it's been populated from user input. :param page: is the `WikiPage` being edited. :return: a list of `(field, message)` tuples, one for each problem detected. `field` can be `None` to indicate an overall problem with the page. Therefore, a return value of `[]` means everything is OK. Nr)r%rrrrvalidate_wiki_pageKrz'IWikiPageManipulator.validate_wiki_pageN)rr r!r"r'r(rrrrr$8s r$c@s2eZdZdZddZddZddZd d d ZdS) IWikiMacroProviderzAugment the Wiki markup with new Wiki macros. .. versionchanged :: 0.12 new Wiki processors can also be added that way. cCr )zKReturn an iterable that provides the names of the provided macros. Nrrrrr get_macros^rzIWikiMacroProvider.get_macroscCr )aReturn a tuple of a domain name to translate and plain text description of the macro or only the description with the specified name. .. versionchanged :: 1.0 `get_macro_description` can return a domain to translate the description. .. versionchanged :: 1.3.6 the macro will be hidden from the macro index (`[[MacroList]]`) if `None` is returned. Nr)namerrrget_macro_descriptionbrz(IWikiMacroProvider.get_macro_descriptioncCr )zkReturn `True` if the content generated is an inline XHTML element. .. versionadded :: 1.0 Nr)contentrrr is_inlineprzIWikiMacroProvider.is_inlineNcCr )aMCalled by the formatter when rendering the parsed wiki text. .. versionadded:: 0.11 .. versionchanged:: 0.12 added the `args` parameter :param formatter: the wiki `Formatter` currently processing the wiki markup :param name: is the name by which the macro has been called; remember that via `get_macros`, multiple names could be associated to this macros. Note that the macro names are case sensitive. :param content: is the content of the macro call. When called using macro syntax (`[[Macro(content)]]`), this is the string contained between parentheses, usually containing macro arguments. When called using wiki processor syntax (`{{{!#Macro ...}}}`), it is the content of the processor block, that is, the text starting on the line following the macro name. :param args: will be a dictionary containing the named parameters passed when using the Wiki processor syntax. The named parameters can be specified when calling the macro using the wiki processor syntax:: {{{#!Macro arg1=value1 arg2="value 2"` ... some content ... }}} In this example, `args` will be `{'arg1': 'value1', 'arg2': 'value 2'}` and `content` will be `"... some content ..."`. If no named parameters are given like in:: {{{#!Macro ... }}} then `args` will be `{}`. That makes it possible to differentiate the above situation from a call made using the macro syntax:: [[Macro(arg1=value1, arg2="value 2", ... some content...)]] in which case `args` will always be `None`. Here `content` will be the `"arg1=value1, arg2="value 2", ... some content..."` string. If like in this example, `content` is expected to contain some arguments and named parameters, one can use the `parse_args` function to conveniently extract them. Nr) formatterr+r-argsrrr expand_macrovrzIWikiMacroProvider.expand_macroN)rr r!r"r*r,r.r1rrrrr)Ws r)c@r#)IWikiSyntaxProviderz'Enrich the Wiki syntax with new markup.cCr )aAReturn an iterable that provides additional wiki syntax. Additional wiki syntax correspond to a pair of `(regexp, cb)`, the `regexp` for the additional syntax and the callback `cb` which will be called if there's a match. That function is of the form `cb(formatter, ns, match)`. Nrrrrrget_wiki_syntaxrz#IWikiSyntaxProvider.get_wiki_syntaxcCr )aReturn an iterable over `(namespace, formatter)` tuples. Each formatter should be a function of the form:: def format(formatter, ns, target, label, fullmatch=None): pass and should return some HTML fragment. The `label` is already HTML escaped, whereas the `target` is not. The `fullmatch` argument is optional, and is bound to the regexp match object for the link. Nrrrrrget_link_resolversrz&IWikiSyntaxProvider.get_link_resolversN)rr r!r"r4r5rrrrr3s r3TcCsgi}}|rCtd|D]5}|dd}|rtd|}ntd|}|r=|d|d}||d||<q ||q ||fS)a%Utility for parsing macro "content" and splitting them into arguments. The content is split along commas, unless they are escaped with a backquote (see example below). :param args: a string containing macros arguments :param strict: if `True`, only Python-like identifiers will be recognized as keyword arguments Example usage:: >>> parse_args('') ([], {}) >>> parse_args('Some text') (['Some text'], {}) >>> parse_args(r'Some text, mode= 3, some other arg\, with a comma.') (['Some text', ' some other arg, with a comma.'], {'mode': ' 3'}) >>> sorted(parse_args('milestone=milestone1,status!=closed', ... strict=False)[1].items()) [('milestone', 'milestone1'), ('status!', 'closed')] z(?sz%validate_page_name../)allr9)pagenamerrrvalidate_page_namesrPc@sLeZdZdZeeeeeZ ee Z eeZ dZ dZdZeddddZedddd Zedd dd Zedd d ddZedddddZeddZd:ddZddZd:ddZddZdZedZ d !d!d"e"d#DZ#d !d$d"e"d#DZ$d;d&d'Z%d(d)Z&d*d+Z'd,d-Z( d:d.d/Z)d0d1Z*d2d3Z+d4d5Z,d6d7Z-d8d9Z.dS)< WikiSystemzWiki system manager.wiki WikiStart TitleIndexignore_missing_pagesfalsezFEnable/disable highlighting CamelCase links to missing pages. split_page_nameszJEnable/disable splitting the WikiPageNames with space characters. render_unsafe_contenta Enable/disable the use of unsafe HTML tags such as `