https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/wiki/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/wiki/__pycache__/formatter.cpython-310.pyc
o

�k�`���@s�ddlZddlZddlTddlTddlmZmZddlmZm	Z	ddl
mZmZm
Z
mZmZddlmZmZmZmZmZmZmZmZddlmZmZddlmZmZdd	lm Z m!Z!gd
�Z"dd�Z#d0d
d�Z$dd�Z%d0dd�Z&Gdd�de'�Z(Gdd�de'�Z)Gdd�de*�Z+Gdd�de*�Z,Gdd�de,�Z-Gdd�de,�Z.Gdd �d e.�Z/Gd!d"�d"e*�Z0Gd#d$�d$e*�Z1d%d&�Z2d0d'd(�Z3d0d)d*�Z4d+d,�Z5		d1d.d/�Z6dS)2�N)�*)�get_relative_resource�get_resource_url)�arity�as_int)�exception_to_unicode�shorten_line�
to_unicode�
unicode_quote�
unquote_label)�Element�Fragment�Markup�TracHTMLSanitizer�escape�	plaintext�tag�to_fragment)�_�tag_)�
WikiSystem�
parse_args)�
WikiParser�parse_processor_args)
�	Formatter�
MacroError�ProcessorError�concat_path_query_fragment�extract_link�	format_to�format_to_html�format_to_oneliner�"split_url_into_path_query_fragment�wiki_to_outlinecCst|t�r	t|�St|�S�N)�
isinstancer
rr	)�markup�r'�5/usr/lib/python3/dist-packages/trac/wiki/formatter.py�_markup_to_unicode.s
r)cCs tjt�|�|ot�|�dd�S)Nzsystem-message��class_)r�div�strong�pre)�msg�textr'r'r(�system_message5s�r1cCsjd}}|�d�}|dkr|d|�||d�}}|�d�}|dkr0|d|�||d�}}|||fS)a�Split a target along `?` and `#` in `(path, query, fragment)`.

    >>> split_url_into_path_query_fragment('http://path?a=1&b=2#frag?ment')
    ('http://path', '?a=1&b=2', '#frag?ment')
    >>> split_url_into_path_query_fragment('http://path#frag?ment')
    ('http://path', '', '#frag?ment')
    >>> split_url_into_path_query_fragment('http://path?a=1&b=2')
    ('http://path', '?a=1&b=2', '')
    >>> split_url_into_path_query_fragment('http://path')
    ('http://path', '', '')
    ��#rN�?)�find)�target�query�fragment�idxr'r'r(r":s


r"cCsNt|�\}}}|r||rdnd|�d�7}|r|}|||dkr$dS|S)a=Assemble `path`, `query` and `fragment` into a proper URL.

    Can be used to re-assemble an URL decomposed using
    `split_url_into_path_query_fragment` after modification.

    >>> concat_path_query_fragment('/wiki/page', '?version=1')
    '/wiki/page?version=1'
    >>> concat_path_query_fragment('/wiki/page#a', '?version=1', '#b')
    '/wiki/page?version=1#b'
    >>> concat_path_query_fragment('/wiki/page?version=1#a', '?format=txt')
    '/wiki/page?version=1&format=txt#a'
    >>> concat_path_query_fragment('/wiki/page?version=1', '&format=txt')
    '/wiki/page?version=1&format=txt'
    >>> concat_path_query_fragment('/wiki/page?version=1', 'format=txt')
    '/wiki/page?version=1&format=txt'
    >>> concat_path_query_fragment('/wiki/page?version=1#a', '?format=txt', '#')
    '/wiki/page?version=1&format=txt'
    �&r4z?&r3r2)r"�lstrip)�pathr7r8�p�q�fr'r'r(rPsrc@�eZdZdZdS)rz�Exception raised on incorrect macro usage.

    The exception is trapped by the wiki formatter and the message is
    rendered in a `pre` tag, wrapped in a div with class `system-message`.

    :since: 1.0.11
    N��__name__�
__module__�__qualname__�__doc__r'r'r'r(rk�rc@r@)rz�Exception raised on incorrect processor usage.

    The exception is trapped by the wiki formatter and the message is
    rendered in a `pre` tag, wrapped in a div with class `system-message`.

    :since: 0.12
    NrAr'r'r'r(rurFrc@seZdZe�d�Ze�dejejB�Zd6dd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Ze�d"ejejB�Ze�d#ejejBejB�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Z d,d-�Z!d7d/d0�Z"d1d2�Z#d8d4d5�Z$dS)9�
WikiProcessorz(^<div(?:\s+class="([^"]+)")?>(.*)</div>$z ^\s*<(?:div|table)(?:\s+[^>]+)?>Nc

Cs�||_|j|_||_||_d|_d|_|j|j|j|j	|j
|j|j|j|j
|j|j|jd�}|jddddd��|�|_t|jj|jjd�|_|�|�|_|js�t|j�jD]1}|��p\gD](}|j|kr�t|d�rn|j|_ntt dt!�"d�d	���||_t#|d
d�|_nq]qU|js�t$|j�}|j%D]}|�&|j�dkr�|j'|_nq�|js�|�(|j�}	|	r�|	|_|j'|_|js�|j|_t)d
|d�|_dSdS)z�Find the processor by name

        :param formatter: the formatter embedding a call for this processor
        :param name: the name of the processor
        :param args: extra parameters for the processor

        (''since 0.11'')
        N)�html�htmlcomment�default�commentr,�rtl�span�Span�td�th�tr�tableT)rHrIrKrMrN)�safe_schemes�safe_origins�expand_macrozCPre-0.11 macros with the %(method)s method are no longer supported.�render_macro)�method�	is_inlineF�z,No macro or processor named '%(name)s' found��name)*�	formatter�envr[�args�error�macro_provider�_html_processor�_htmlcomment_processor�_default_processor�_comment_processor�_div_processor�_rtl_processor�_span_processor�
_td_processor�
_th_processor�
_tr_processor�_table_processor�_html_is_inline�get�inline_checkr�wikirSrT�
_sanitizer�	processorr�macro_providers�
get_macros�hasattr�_macro_processor�	TracErrorrr�code�getattr�Mimeview�	renderers�get_quality_ratio�_mimeview_processor�get_mimetyper)
�selfr\r[r^�builtin_processorsr`�
macro_name�mimeview�renderer�mimetyper'r'r(�__init__�s�	����


�����

���zWikiProcessor.__init__cCsB|r|dd���}|�d�}|dkr|d|�}|��dvSdS)NrY� ���)�arM�bdo�img�big�small�font�tt�i�b�u�s�strike�emr-�dfnrwr>�samp�kbd�var�cite�abbr�acronym�sub�sup)r;r5�lower)r~r0rr9r'r'r(rl�s
�zWikiProcessor._html_is_inlinecC�dS�Nr2r'�r~r0r'r'r(rd��z WikiProcessor._comment_processorcCs<|jrd|jvrt|jj��d�|_|�|�Stj|dd�S)N�linenoz
text/plainror*)	r^ryr\r]r}r[r|rr.r�r'r'r(rc�s
�
z WikiProcessor._default_processorcCs t|j�jr
t|�S|j�|�Sr$)rr]�render_unsafe_contentrrp�sanitizer�r'r'r(ra�szWikiProcessor._html_processorcCs d|vr
ttd��Std|�S)Nz--zGError: Forbidden character sequence "--" in htmlcomment wiki code blockz<!--
%s-->
)r1rrr�r'r'r(rb�sz$WikiProcessor._htmlcomment_processorcCsbtt|�di|jp
i��}t|j�js#tt|�}|j�||j�|_|}|�	||j|j
j|��|S)Nr')rxrr^rr]r�rp�sanitize_attrs�attrib�appendr\�context)r~�eltnamerr0�elt�
sanitized_eltr'r'r(�_elt_processor�s
�zWikiProcessor._elt_processorcCs(|jsi|_|j�dd�|�dt|�S)N�class�wikipager,)r^�
setdefaultr�r r�r'r'r(reszWikiProcessor._div_processorcCs6|jsi|_d|j�dd���|jd<|�dt|�S)Nzrtl r�r2r,)r^rm�rstripr�r r�r'r'r(rfszWikiProcessor._rtl_processorcCs4|jdurt|dd�\}|_d�|�}|�dt|�S)NT)�strictz, rM)r^r�joinr�r!)r~r0r^r'r'r(rgs

zWikiProcessor._span_processorcC�|�d|�S)NrO��_tablecell_processorr�r'r'r(rh�zWikiProcessor._td_processorcCr�)NrPr�r�r'r'r(rir�zWikiProcessor._th_processorc
CsNz|�d|j|�}|j��|WSty&}z
t|�WYd}~Sd}~ww)NrQ)r��_format_rowr\�
open_tablerr1)r~r0r��er'r'r(rjs
��zWikiProcessor._tr_processorc
CsZ|jsi|_|j�dd�z	|�d|j|�WSty,}z
t|�WYd}~Sd}~ww)Nr�rorR)r^r�r��
_format_tablerr1)r~r0r�r'r'r(rk"s��zWikiProcessor._table_processorcCs|j��|�|t|�Sr$)r\�open_table_rowr�r )r~r�r0r'r'r(r�+s
z"WikiProcessor._tablecell_processorz</table>.*?<tablezr\s*
      <table[^>]*>\s*
        ((?:<tr[^>]*>)?
          (.*?)
        (?:</tr>)?)\s*
      </table>\s*$
      cCs`|j�|�rttd|jd���|j�|�}|s ttd|jd���t|�|jdkr,d��Sd��S)Nz)!#%(name)s must contain at most one tablerZzF!#%(name)s must contain at least one table cell (and table cells only)rRrY�)	�_has_multiple_tables_re�searchrrr[�_inner_table_re�matchr�group)r~r0r�r'r'r(�_parse_inner_table=s�� z WikiProcessor._parse_inner_tablecC�0|rt��}t||��||�|�|���}|Sr$��io�StringIOr�formatr��getvalue�r~r]r�r0�outr'r'r(r�H�
zWikiProcessor._format_rowcCr�r$r�r�r'r'r(r�Or�zWikiProcessor._format_tablecCsR|jj�d|j|j�t|jj�dkr|j�|j|j||j�S|j�|j|j|�S)Nz&Executing Wiki macro %s by provider %s�)	r]�log�debugr[r`rrUr\r^r�r'r'r(ruXs
���zWikiProcessor._macro_processorcCs�g}|jj��}|jr|j��n|j}|rQd|vrQt|�d�ddd�}|j|d�t|�dd��p6|j�	d�}|j|dd	�d
|vrL|j|�d
�d�|�
d�|rY|j|d�tjd
d�t
|j�j||j||d��S)Nr�rY)�min)r��idr2r��-)r��marks)r�)�
lexer_optionsz	wiki-coder*)�annotations)r\r��childr^�copyr�pop�	set_hints�str�_unique_anchorr�rr,ryr]�renderr[)r~r0r�r�r^r�r�r'r'r(r|bs(
�

��z!WikiProcessor._mimeview_processorFcCs6|jrttdt�|j�d�|j�}n|�|�}|pdS)Nz(Error: Failed to load processor %(name)srZr2)r_r1rrrwr[rq)r~r0�in_paragraphr'r'r(�processvs
��
zWikiProcessor.processcCst|j�r
|�|�S|jSr$)�callablernr�r'r'r(rXs

zWikiProcessor.is_inlineTcCs�d}d}t|t�r-|j��}|dkr&|j�dd�}|r#d|vr#|j}n5d}n2|dkr,d}n+t|�}t�	|j
|�}|rO|�d�rLd|�d�vrL|�d	�}nd}n	t�	|j|�rXd}|rdtj
d
d�|�}|S|rn|rndt|�}|S)
NFr,r�r2rwTrRrYr�z
code-blockr*z	</p>%s<p>)r%rrr�r�rm�childrenr)�rer��_code_block_rer��_block_elem_rerM)r~r0r��content_for_span�interrupt_paragraph�tagnamer+r�r'r'r(�
ensure_inline�s4

��zWikiProcessor.ensure_inliner$�F)T)%rBrCrDr��compiler��I�Mr�r�rlrdrcrarbr�rerfrgrhrirjrkr��	MULTILINE�DOTALLr��VERBOSEr�r�r�r�rur|r�rXr�r'r'r'r(rG�sD

�
L	
��	

	rGc	@s�eZdZdZdZdd�Zdd�Zddddd	d
ddd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zd�dd�Z
d�dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Zd?d@�Z dAdB�Z!dCdD�Z"dEdF�Z#dGdH�Z$dIdJ�Z%dKdL�Z&dMdN�Z'd�dPdQ�Z(d�dRdS�Z)dTdU�Z*dVdW�Z+dXdY�Z,d�d[d\�Z-d]d^�Z.d_d`�Z/dadb�Z0dcdd�Z1dedf�Z2dgdh�Z3d�didj�Z4d�dldm�Z5dndo�Z6dpdq�Z7drds�Z8dtdu�Z9dvdw�Z:d�dxdy�Z;dzd{�Z<d|d}�Z=d~d�Z>d�d�d��Z?d�d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKeL�Md�eLjN�ZOd�d�d��ZPd�d�d��ZQdS)�rz[Base Wiki formatter.

    Parses and formats wiki text, in a given `RenderingContext`.
    rJcCs�||_|��|_|jjdd�|j|_|j|_|j|_|j|_t|j�|_	t
|j�|_i|_g|_
d|_|j	jsAt|j	j�|_dSdS)NT)�disable_warnings)r]r�r�r��req�href�resource�permrror�
wikiparser�_anchors�
_open_tags�
_safe_schemesr��setrS)r~r]r�r'r'r(r��s
�zFormatter.__init__cC�t|�Sr$)r")r~r6r'r'r(�
split_link��zFormatter.split_link)z<strong>z	</strong>)z<em>z</em>)z<span class="underline">z</span>)z<del>z</del>)z<sub>z</sub>)z<sup>z</sup>)�MM_BOLD�WC_BOLD�	MM_ITALIC�	WC_ITALIC�MM_UNDERLINE�	MM_STRIKE�MM_SUBSCRIPT�MM_SUPERSCRIPTcC�t|t�s
|j|}|dS)z2Retrieve opening tag for direct or indirect `tag`.r�r%�tuple�_indirect_tags�r~rr'r'r(�
_get_open_tag��

zFormatter._get_open_tagcCr)z2Retrieve closing tag for direct or indirect `tag`.rYrrr'r'r(�_get_close_tag�r	zFormatter._get_close_tagcCs
||jvS)z8Do we currently have any open tag with `tag` as end-tag?)r�rr'r'r(�
tag_open_p�s
zFormatter.tag_open_pccs"�|jr|j��V|jsdSdSr$)r�r��r~r'r'r(�pop_tags�s��zFormatter.pop_tagscCs$|��D]}|j�|�|��qdSr$)r
r��writer
rr'r'r(�
flush_tags�s�zFormatter.flush_tagsNcCs2|r|j�||f�|S|j�|�|�|�}|S)zqOpen an inline style tag.

        If `tag_close` is not specified, `tag_open` is an indirect tag (0.12)
        )r�r�r)r~�tag_open�	tag_closer'r'r(�open_tag�s�
zFormatter.open_tagcCs�d}tt|j�ddd�D]8}|j|}||�|�7}||k||f|kft|�rE|j|=t|t|j��D]}||�|j|�7}q5|Sq
|S)zgOpen a inline style tag.

        If `close_tag` is not specified, it's an indirect tag (0.12)
        r2rYr�)�range�lenr�r
�boolr)r~r�	close_tag�tmpr�r�jr'r'r(r�s 

���zFormatter.close_tagcCs2|jr
|js
|��|�|�r|�|�S|�|�S)z4Handle binary inline style tags (indirect way, 0.12))�_list_stack�in_list_item�
close_listrrr)r~r�rr'r'r(�_indirect_tag_handlers



zFormatter._indirect_tag_handlerc
s��jr
�js
�����d�}��d�}|r0|r0�j�d�}�j�d�}||kr+d}nd}d}n|r7d}d}n|r>d}d}nd}d}g}	|	��fdd	�|D��|	��fd
d	�|D��d�|	�S)Nr�r�)r�r�)r�r�r')r�)r�c3��|]}��|�VqdSr$)r��.0rrr'r(�	<genexpr>%��z2Formatter._bolditalic_formatter.<locals>.<genexpr>c3rr$)rrrr'r(r &r!r2)rrrrr��index�extendr�)
r~r��	fullmatch�	bold_open�italic_open�bold_idx�
italic_idx�
close_tags�	open_tagsrr'rr(�_bolditalic_formatters.


zFormatter._bolditalic_formattercC�|�|d�S)Nr��r�r~r�r$r'r'r(�_bold_formatter)r�zFormatter._bold_formattercCr,)Nr�r-r.r'r'r(�_bold_wc_formatter,r�zFormatter._bold_wc_formattercCr,)Nr�r-r.r'r'r(�_italic_formatter/r�zFormatter._italic_formattercCr,)Nr�r-r.r'r'r(�_italic_wc_formatter2r�zFormatter._italic_wc_formattercCr,)Nr�r-r.r'r'r(�_underline_formatter5r�zFormatter._underline_formattercCr,)Nrr-r.r'r'r(�_strike_formatter8r�zFormatter._strike_formattercCr,)Nrr-r.r'r'r(�_subscript_formatter;r�zFormatter._subscript_formattercCr,)Nrr-r.r'r'r(�_superscript_formatter>r�z Formatter._superscript_formattercC�t�|�d��S)N�inline�rrwr�r.r'r'r(�_inlinecode_formatterA�zFormatter._inlinecode_formattercCr7)N�inline2r9r.r'r'r(�_inlinecode2_formatterDr;z Formatter._inlinecode2_formattercCs*|�||f�r
|�||�S|�||�|S)z,Generic handler for simple binary style tags)rrr)r~r�rrr'r'r(�simple_tag_handlerIszFormatter.simple_tag_handlercCr�)N�<br />r'r.r'r'r(�_linebreak_wc_formatterUr�z!Formatter._linebreak_wc_formattercCs<ddlm}||j��|j|�}||kr|�d||�S|S)Nr��Chrome�mailto:)�trac.web.chromerBr]�
format_emailsr��_make_mail_link)r~r�r$rB�omatchr'r'r(�_email_formatterZs
zFormatter._email_formattercCs|dkrdS|dkrdSdS)Nr:z&amp;�<z&lt;z&gt;r'r.r'r'r(�_htmlescape_formatterds

��zFormatter._htmlescape_formattercCs:|�d�}t|�d��}|dd�}d|�|||||�S)N�snsbr�stgtbrrYr�z
&lt;%s&gt;�r�r�
_make_link�r~r�r$�nsr6r'r'r(�_shrefbr_formatterjs
�zFormatter._shrefbr_formattercCs*|�d�}t|�d��}|�|||||�S)N�sns�stgtrMrOr'r'r(�_shref_formatterqs
zFormatter._shref_formattercCs@|�d�}|�d�}t|�d��}|�d�}|�||||||�S)N�rel�lns�ltgt�label)r�r�_make_lhref_link)r~r�r$rUrPr6rXr'r'r(�_lhref_formattervs



zFormatter._lhref_formattercCs|s|r|r|�d�r|d|}n
|�d�}n|}nt|�}|r�|s)|j�|�}|�|�\}}}	|�d�r>d|�d�}n8|�d�rI|j|}n-t|j|�}
t	|j
|
|j�}|
jrvtt
|
j�||	�}|
jdkrld|}|�|
j||||�Stj|t|||	�d�S|�|p�d|p�d|||�S)N�//�:�/ro)r�r2)�
startswithr;rro�make_label_from_targetr�r�rr�rr]r�rr��realmrNrr�)r~r�r$rUrPr6rXr<r7r8r�r'r'r(rY}s@


�
�
��zFormatter._make_lhref_linkcCs4|jjd�||�}||jjvr1|jj|}t|�dkr'||||t|d�|�S||||t|d��S|dkrkddlm}||j�}|j	rI||}	}
n|�
|j|�}	|�
|j|�}
|	|
f||fkrg|�d||�S|
pj|	S|�
d�r�|jdusz||jvr�|�|d	||�St|�S|�|||�p�|�|||�p�t|�S)
N�	intertrac�F�mailtorrArCr[r\)r]�configrmr��link_resolversrrrDrB�never_obfuscate_mailtorEr�rFr^r��_make_ext_link�_make_intertrac_link�_make_interwiki_link)r~rPr6r�rXr$�resolverrB�chrome�otarget�olabelr'r'r(rN�s6�

��zFormatter._make_linkcCs*|�||�}|r|�|d||d�SdS)NrrY)�get_intertrac_urlrg)r~rPr6rX�resr'r'r(rh�s�zFormatter._make_intertrac_linkcCs�|jjd}|�|d�}td|d�}|s!|��dkr!d}td�}|rF|�|d|�}d	|t|�f}|r@td
||d�}||fS|}||fSdS)Nraz.urlzTrac project %(name)srZ�traczhttps://trac.edgewall.orgzThe Trac Projectz.titlez%s/intertrac/%sz%(target)s in %(name)s)r6r[)r]rdrmrr�r
)r~rPr6ra�urlr[�titler'r'r(rn�s��zFormatter.get_intertrac_urlcCsh|r0|���d|�}|r2|��}|jjd}d||t|�d�f}|�|�||�||�p/|SdSdS)N�it_raz%s:%s)�	groupdictrm�stripr]rdrrh)r~rPr6rXr$�it_group�aliasrar'r'r(�shorthand_intertrac_helper�s���z$Formatter.shorthand_intertrac_helpercCsHddlm}||j�}||vr |�||�\}}|r"|�|||�SdSdS)Nr)�InterWikiMap)�trac.wiki.interwikiryr]rqrg)r~rPr6rXry�	interwikirqrrr'r'r(ri�s
�zFormatter._make_interwiki_linkr2cCsR|jjp|jjj}|�|�stjtjddd�|d||pdd�Stj|||p&dd�S)N�​�iconr*zext-link�r+r�rr)r�rr)r]�project_url�abs_href�baser^rr�rM)r~rqr0rr�	local_urlr'r'r(rg�s

�zFormatter._make_ext_linkcCs"tjtjddd�|d||pdd�S)Nr|r}r*z	mail-linkr~)rr�rM)r~rqr0rrr'r'r(rF�s
�zFormatter._make_mail_linkcCs8|�d�}|�d�pd}|rt|j|j|�}d||fS)N�
anchorname�anchorlabelr2z*<span class="wikianchor" id="%s">%s</span>)r�r!r]r�)r~r�r$�anchorrXr'r'r(�_anchor_formatter�s

zFormatter._anchor_formattercCs>d}|}||jvr|t|�}|d7}||jvs	d|j|<|S)NrYT)r�r�)r~r�r��anchor_baser'r'r(r��s

�
zFormatter._unique_anchorcCs�|dd�}|�d�rtj�|�}|r|�||�Stj�|�}|rd|�d�}|�d�}d}|ddk}|��d	ks=|dkr@d}nt|||dd�f|�}|j	rRd}|durd|r]t|d
�}|�
|||�Stj�|�}|�||�S)Nr����z=#�	macroname�	macroargsFr�r4�br�	MacroList)
r^r�_set_anchor_wc_rer�r��	_macro_rer�r�rGr_�_macro_formatter�_creolelink_rerZ)r~r�r$�
macro_or_linkr[r^�macro�	macrolistr'r'r(�_macrolink_formatters,



zFormatter._macrolink_formatterFc	
Cs|�d�}|r|ddkr|dd�pd}n|�d�}|��dkr&|�|�St|dd�p7t|d	d�p7t|d
d�}z
|�|�|�|�WStya}zttd||d�t	|��WYd}~Sd}~wt
y�}z"|jj�
d
|||jt|dd��ttd||d�t	|��WYd}~Sd}~ww)Nr�r�r4rr�r�rT�in_table�in_def_listzMacro %(name)s(%(args)s) failed)r[r^zMacro %s(%s) failed for %s:%s��	tracebackz&Error: Macro %(name)s(%(args)s) failed)r�r��emit_linebreakrxr�r�rr1rr�	Exceptionr]r�r_r�r)	r~r�r$r��only_inliner[r^r�r�r'r'r(r�!s@



�
����
�����zFormatter._macro_formattercCsR|r'd|vrdnd}|�|d�}|ddkr'|ddvr |dnd}d	�|�Sd
S)Nr\�=rYr�clearr�)�left�right�bothz<br style="clear: {0}" />r?)�splitr�)r~r^�sep�kvr�r'r'r(r�7s
zFormatter.emit_linebreakc
Cs�|��}|�d�}t|�}|�d�pd}|�d���}|�|�r'|d|�}t|j|j|d�}|r9|dd�}nt|dd�}	tj	�
d|	�}|rT|d��sT|dd	vrXd
|}|�|�}|rht|j|j|d�}|||fS)N�hdepth�hanchorr2�htextFrY)�keeplinebreaksrz.-r�T)
rur�r�endswithr!r]r�rr�
_anchor_rer��isdigitr�)
r~r�r$�shortenr��depthr�r��heading�sans_markupr'r'r(�_parse_headingBs$



zFormatter._parse_headingcCsX|��|��|��|��|��|�||d�\}}}|j�d||||f�dS)NFz%<h%d class="section" id="%s">%s</h%d>)�close_table�close_paragraph�close_indentationr�close_def_listr�r�r�r~r�r$r�r�r�r'r'r(�_heading_formatterYs

�zFormatter._heading_formattercCs:g}|jD]
}||kr
n|�|�q|�|�||_dS)z�Append a new tab if needed and truncate tabs deeper than `depth`

        given:       -*-----*--*---*--
        setting:              *
        results in:  -*-----*-*-------
        N)�	_tabstopsr�)r~r��tabstops�tsr'r'r(�_set_tabes


zFormatter._set_tabc	Cs�t|�d��}||}d|_d}}|tjvrd}nWd}|�d�}|dkr(d}nI|dkr/d	}nB|��r<|d
kr<t|�}n5|��rWd}t|�dkrV|d
krVt|�td
�d}n|�	�rqd}t|�dkrq|dkrqt|�td�d}|�
||||�dS)N�ldepthT�ul�ol�lstartr��
lowerromanr��
upperroman�1�
loweralpharYr��
upperalpha�Ar2)rr�rr�BULLET_CHARSr��int�islower�ord�isupper�_set_list_depth)	r~r�r$r��listidr+�start�type_r�r'r'r(�_list_formattervs2


�zFormatter._list_formattercCs|jr
|jddSdS)z>Return the space offset associated to the deepest opened list.r�rY)rrr'r'r(�_get_list_depth�szFormatter._get_list_depthcs������fdd�}�fdd����fdd�}����kr"|�dS�jr8�jd\}}�|kr1n||��js%�rr�dkrt�jrm�jd\}	}
�rW|	�krW||	�|�dS|
�krb|	�f�jd<���j�d	�dS|�dSdSdS)
Ncsv����������j���f������rd�nd}�dur)d�nd}�j�d�||d�dS)Nz class="%s"r2z start="%s"rIz><li>)r�r�r�rr�r�r�r)�
class_attr�
start_attr)r��lclass�new_typer~r�r'r(�	open_list�s
 z,Formatter._set_list_depth.<locals>.open_listcs����j�d�dS)Nz</li>)rr�rr'rr'r(�
close_item�sz-Formatter._set_list_depth.<locals>.close_itemcs$�j�����j�d|�dS)N�</%s>)rr�r�r)�tp)r�r~r'r(r�s
z-Formatter._set_list_depth.<locals>.close_listr�rz<li>)r�rr�r)r~r�r�r�r�r�r�deepest_type�deepest_offset�old_type�
old_offsetr')r�r�r�r�r~r�r(r��s.	
�

�zFormatter._set_list_depthr�cCs|�|�dSr$)r�)r~r�r'r'r(r��zFormatter.close_listcCsL|jrd}n|��d}|d|�d��}|dt|j|j|�7}d|_|S)Nz</dd>z<dl class="wiki">z::z<dt>%s</dt><dd>T)r�r�r5r!r]r�)r~r�r$r�
definitionr'r'r(�_definition_formatter�s�zFormatter._definition_formattercCs|jr	|j�d�d|_dS)Nz</dd></dl>
F)r�r�rrr'r'r(r��s
zFormatter.close_def_listcCs�t|�d��}|jr>|jd\}}||kr-|jD]\}}||kr+d|_|�|�dSqn|||dkr5dndkr>d|_dS|jsF|�|�dS)N�idepthr�Tr2r��r�)rr�rrr�r��_set_quote_depth)r~r�r$r��ltyper�rr'r'r(�_indent_formatter�s"
��
zFormatter._indent_formattercCs|�d�dS�Nr)r�rr'r'r(r��r�zFormatter.close_indentationcCs|jr|jdSdS)z?Return the space offset associated to the deepest opened quote.r�r)�_quote_stackrr'r'r(�_get_quote_depth�szFormatter._get_quote_depthc	s����fdd�}�fdd�}����|�kr4��|��jddd�}|r3|��}|�kr1||�|s%n/�jrG�jd}||krAn|��js7�sc|dkrc�jr_�jd}||kr^|�jd<n||�|dkrld�_dSdS)NcsZ�����������fdd�}�r't�d|d�D]}||�qdS||�dS)Ncs6�j�|���|��rdnd}�j�d|�dS)Nz class="citation"r2z<blockquote%s>
)r�r�r�r�r)�dr�)�citationr~r'r(�open_one_quote�s
zFFormatter._set_quote_depth.<locals>.open_quote.<locals>.open_one_quoterY)r�r�rr)r�r�r��r��quote_depthr~r'r(�
open_quote�s
�z.Formatter._set_quote_depth.<locals>.open_quotecs*�������j���j�d�dS)N�</blockquote>
)r�r�r�r�r�rr'rr'r(�close_quote�s
z/Formatter._set_quote_depth.<locals>.close_quoter�rT)r�r�r�r�r��in_quote)	r~r�r�r�r�r��tabr�r�r'r�r(r��s8
��
�

�
�zFormatter._set_quote_depthcs�������d�_|�d�}|�d�}t|�}d}|ddkr%|d8}|ddkr1|d8}d}|d	}|durL|rD|dd
krDd�_|d8}|sLdSd}|dkrXdt|�}|�d�}	|	t�j�koj�j|	d
k}
t	�
d�j|	d��}|o~|�d�d
k}d}
|
r�|s�d}
n+|r�d}
n&|r�|	d}|	|��d}||kr��j|�j|kr�d
kr�nnd}
|
r�|d|
7}d||f}�jr�d�
�fdd����D��}d|�j|f}|�_|S)NrY�table_cell_sep�table_cell_lastrOrr�r�rPr��\r2z
 colspan="%d"r�z([^!])=?\|\|r�r��centerz style="text-align: %s"z<%s%s>c3rr$)r
rrr'r(r Ks��z2Formatter._table_cell_formatter.<locals>.<genexpr>z	%s</%s>%s)r�r��continue_tabler�r�continue_table_rowr��end�liner�r�r��
in_table_cellr�r
)r~r�r$�	separator�is_last�numpipes�cell�colspan�attrs�	after_sep�	alignleft�next_sep�
alignright�	textalign�first_extra�
last_extrarOr)r'rr(�_table_cell_formattersb


�$�zFormatter._table_cell_formattercCsr|��|jdd�|�d�}|r*t|d|�|��}t|�d��}|d|�d��}|�|p/d�d|_	d|_
dS)	NT��force�table_row_paramsrQr2r��>rY)r��close_table_rowr�rGrr)r�r5r�r�r�)r~r�r$�paramsrQ�	processedr'r'r(�_table_row_sep_formatterQs

z"Formatter._table_row_sep_formattercCs8|js|��|��|��d|_|j�d�dSdS)NrYz<table class="wiki">
)r�r�rr�r�rrr'r'r(r�]s�zFormatter.open_tablecCs,|js|��d|_|j�d|�dSdS)NrYz<tr%s>)�in_table_rowr�r�r)r~rr'r'r(r�es
�zFormatter.open_table_rowcCsR|jr$|jr|r$d|_|jr|��|j�d|j�d|_|j�d�d|_dS)Nrr�r2z</tr>)rr�r�rr�r)r~rr'r'r(rks
zFormatter.close_table_rowcCs,|jr|jdd�|j�d�d|_dSdS)NTrz	</table>
r)r�rr�rrr'r'r(r�us

�zFormatter.close_tablecCs |js|j�d�d|_dSdS)Nz<p>
rY)�paragraph_openr�rrr'r'r(�open_paragraph}s
�zFormatter.open_paragraphcCs(|��|jr|j�d�d|_dSdS)Nz</p>
r)rrr�rrr'r'r(r��s

�zFormatter.close_paragraphcCr�r$)r)r~r�r'r'r(r�r�zFormatter.parse_processor_argscs�|rM�jd7_�jdkr:|�d�}|r't||��d��}t�||��_nd�_g�_|d|�tj	���_
dS�j�|��jsKt�d��_dSdS|��tj
kr��jd8_�jdkr��jr��jjdvrm�������jr��j
r�t�fdd��jD��r�t�j
���fdd	��jD��_�j�d
�d��j�}���j|�}�j�t|��dS�j�|�dS�js�tj�|�}|r�|�d��_
|�d�}t||��d��}t�||��_dS�j�|�t�d��_dS�j�|�dS)NrYr�rJr)rPrOrQc3s"�|]}|p|��j�VqdSr$)r^�code_prefix�r�lrr'r(r �s��

�z.Formatter.handle_code_block.<locals>.<genexpr>csg|]}|�d��qSr$r'r)�code_indentr'r(�
<listcomp>�s�z/Formatter.handle_code_block.<locals>.<listcomp>r2�
)�
in_code_blockr�rr�rG�code_processor�code_bufr5r�
STARTBLOCKrr�ru�ENDBLOCKr[r�r��allrr��_exec_processorr�rr)�
_processor_rer�)r~r��
startmatchr[r^�	code_textr
r�r')rr~r(�handle_code_block�sZ

��

��
zFormatter.handle_code_blockcCs(|jdkr|�tj�|jdksdSdSr�)rr"rrrr'r'r(�close_code_blocks�s
�zFormatter.close_code_blockscCs�z|�|�WSty$}zttd|jd�t|��WYd}~Sd}~wtyQ}z"|jj�	d|j|j
t|dd��ttd|jd�t|��WYd}~Sd}~ww)NzProcessor %(name)s failedrZzProcessor %s failed for %s:%sTr�z Error: Processor %(name)s failed)r�rr1rr[rr�r]r�r_r�r)r~rqr0r�r'r'r(r�s*���

�����zFormatter._exec_processorcCsJ|��|�d�}|js||��kr|�|�|j�||dd��dS)Nr
rY)r�r5�
_quote_bufferr�rr�)r~r�r�r'r'r(�handle_quote_block�s


zFormatter.handle_quote_blockcCsn|jr5tdd�|jD��rdd�|jD�|_|j�d�t|j|j��|j|j|�|j�d�g|_dSdS)Ncss"�|]}|p|ddvVqdS)rz> Nr'�rr�r'r'r(r �s� z.Formatter.close_quote_block.<locals>.<genexpr>cSs(g|]}|t|o
|ddk�d��qS)rr�N)rr&r'r'r(r�s �z/Formatter.close_quote_block.<locals>.<listcomp>z<blockquote class="citation">
r�)r$rr�rrr]r�r�)r~�escape_newlinesr'r'r(�close_quote_block�s��
�zFormatter.close_quote_blockcCs�|����D]>\}}|rD||jjvrD|ddkr"t|dd��S||jjvr6|jj|}||||�St|d|�}|||�SqdS)Nr�!rYz
_%s_formatter)rt�itemsr��helper_patternsr�external_handlersrx)r~r$�ityper��external_handler�internal_handlerr'r'r(�handle_match�s��zFormatter.handle_matchcCs|�|�}|rt|�SdS)z2Replace one match with its corresponding expansionN)r0r))r~r$�replacementr'r'r(�replace�s
�zFormatter.replacez[\v\f]cCs�t|t�r
t�|jd|�}||_Gdd�dt�}|p|�|_g|_g|_	g|_
g|_g|_d|_
d|_d|_d|_d|_d|_d|_d|_|S)Nr�c@seZdZdd�ZdS)z Formatter.reset.<locals>.NullOutcSsdSr$r')r~�datar'r'r(rr�z&Formatter.reset.<locals>.NullOut.writeN)rBrCrDrr'r'r'r(�NullOutsr4rr2)r%r�r�r��
_normalize_re�source�objectr�r�rr�r�r$rr�r�rr�r�r�r)r~r6r�r4r'r'r(�resets&
zFormatter.resetcCsH|�||�}t|t�r|��}|D]�}d}tj|vr tj�|�}|jr*|�	||�q|�
��d�r7|�|�q|�
|�|rE|�	||�q|dd�dkrh|��|��|��|��|��|j�d�q|dkr�|��|��|��|��|��q|�dd�}|�d	�s�g|_|�d	�s�|jr�|��d
|_d
|_||_t�|jj|j|�}|js�|��|js�|��|jr�|�d	�s�|��|j r�|j!s�|��d|_!d}|js�|js�|j s�t"|�r�|�#�|r�|j$r�|�%��&d�s�d|}|j�||�|�'�q|�(�|�
|�|��|��|��|��|��dS)
Nr
rr�z----z<hr />
r2�	z        r�Frr?))r8r%r��
splitlinesrr�_startblock_rer�rr"rur^r%r(r�r�r�rr�r�rr2r�r�rr�r�r�r�r��rulesr�r�r�rrrr�r�rr#)r~r0r�r'r��block_start_match�resultr�r'r'r(r�s�





�

zFormatter.formatr$)r2r�)NNN)r��NF)RrBrCrDrE�flavorr�r�rrr
rr
rrrrr+r/r0r1r2r3r4r5r6r:r=r>r@rHrJrQrTrZrYrNrhrnrxrirgrFr�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�rrr�r�rr�rr�rr"r#rr%r(r0r2r�r��UNICODEr5r8r�r'r'r'r(r�s��



# 





)
.3



1

rc@sfeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
ddd�ZdS)�OneLinerFormatterz�
    A special version of the wiki formatter that only implement a
    subset of the wiki formatting functions. This version is useful
    for rendering short wiki-formatted messages on a single line
    �onelinercC�|Sr$r'r.r'r'r(r�}r�z!OneLinerFormatter._list_formattercCrDr$r'r.r'r'r(r�r�z#OneLinerFormatter._indent_formattercC�
t|d�Sr?�rr.r'r'r(�_citation_formatter��
z%OneLinerFormatter._citation_formattercCrEr?rFr.r'r'r(r��rHz$OneLinerFormatter._heading_formattercCrEr?rFr.r'r'r(r��rHz'OneLinerFormatter._definition_formattercCrDr$r'r.r'r'r(r�r�z'OneLinerFormatter._table_cell_formattercCr�r�r'r.r'r'r(r�r�z*OneLinerFormatter._table_row_sep_formattercCr�)Nr�r'r.r'r'r(r@�r�z)OneLinerFormatter._linebreak_wc_formattercCsV|�d�}|��dkr
dS|�d�}|�|�rt�||||�Sd||r'dfSdfS)Nr�r�r�r�z[[%s%s]]z(...)r2�r�r�rXrr��r~r�r$r�r[r^r'r'r(r��s


z"OneLinerFormatter._macro_formatterFc	CsN|sdS|�||�}d}d}t��}|����D]H}tj|vr*tj�|�r*|d7}q|��tjkrG|rF|d8}|dkrF|dkrD|�	d�d}q|rY|sX|�
d�rX|dd���}q|�	|d�q|��dtd��}|rrt
|�}t�|jj|j|�}|�dd	�}|�d
�r�|dd�d}|j�	|�|��|dkr�|j�	d	�dSdS)
NrrYrKz [...]
z#!r�rz[...]u[…]z...���u…)r8r�r�rur:rrr;r�rr^r�rrr�r�r�r<r2r�r�r)	r~r0r�r�rrq�bufr�r>r'r'r(r��sJ

�

�
�
�zOneLinerFormatter.formatNr�)rBrCrDrEr@r�r�rGr�r�rrr@r�r�r'r'r'r(rBts
rBc@s8eZdZdZdZdd�Zddd�Zddd�Zd
d�ZdS)�OutlineFormatterz@Special formatter that generates an outline of all the headings.�outlinecCsB|�d�}|��dkr
dS|�d�}|�|�rt�||||�SdS)Nr�r�r�r�r2rIrJr'r'r(r��s


z!OutlineFormatter._macro_formatterNcCsLtj|vrtj�|�r|jd7_dS|��tjkr$|jd8_dSdS)NrY)rrr;r�rru)r~r�r r'r'r(r"�s

��z"OutlineFormatter.handle_code_block�rYTcCs�||_d}g|_t�||�||kr||}}td|�}td|�}|d}|�d�|jD]�\}}	}||ks:||kr;q-||kr]t||�D]}
|�|d|
d|d|
dd�qDnU||kr�t|d|dd�D]}
|�|d|
dd	|d|
d
�qk|�|d|dd	|d|dd�n|�|d|dd	|d|dd�|}|�|d|d|	|f�q-t|d|dd�D]}
|�|d|
dd	|d|
d
�q�dS)Nz  rOrYrr�z<ol>
z<li>
r�z</li>
z</ol>
z<a href="#%s">%s</a>
)r�rNrr�r��maxrr)r~r0r��	max_depth�	min_depthr��whitespace_indent�
curr_depthr�r�r�r'r'r(r��sb



���
������
�
���zOutlineFormatter.formatcCs:|�|||j�\}}}t�dd|�}|j�|||f�dS)Nz</?a(?: .*?)?>r2)r�r�r�r�rNr�r�r'r'r(r��s

�z#OutlineFormatter._heading_formatterr$)rOrYT)	rBrCrDrEr@r�r"r�r�r'r'r'r(rM�s
	
%rMc@s$eZdZdZdZdd�Zdd�ZdS)�
LinkFormatterz,Special formatter that focuses on TracLinks.�linkcCr�r�r'r.r'r'r(r�
r�z LinkFormatter._heading_formattercCs2|�|�}||_t�|jj|�}|r|�|�SdS)z>Return the Wiki match found at the beginning of the `wikitext`N)r8r�r�r�r�r<r0)r~�wikitextr�r'r'r(r�
s

�zLinkFormatter.matchN)rBrCrDrEr@r�r�r'r'r'r(rUs
rUc@�&eZdZdZdZdd�Zd	dd�ZdS)
�
HtmlFormatterzFormat parsed wiki text to HTMLrJcC�.||_||_t|t�rt|��|�}||_dSr$�r]r�r%r�r�parse�wikidom�r~r]r�r]r'r'r(r��


zHtmlFormatter.__init__FcC�.t��}t|j|j��|j||�t|���S)zpGenerate HTML elements.

        newlines in the wikidom will be preserved if `escape_newlines` is set.
        )	r�r�rr]r�r�r]rr�)r~r'r�r'r'r(�generate$s
�zHtmlFormatter.generateNr��rBrCrDrEr@r�rar'r'r'r(rYs
rYc@rX)
�InlineHtmlFormatterznFormat parsed wiki text to inline elements HTML.

    Block level content will be discarded or compacted.
    rCcCrZr$r[r^r'r'r(r�8r_zInlineHtmlFormatter.__init__FcCr`)z�Generate HTML inline elements.

        If `shorten` is set, the generation will stop once enough characters
        have been emitted.
        )	r�r�rBr]r�r�r]rr�)r~r�r�r'r'r(ra?s
�zInlineHtmlFormatter.generateNr�rbr'r'r'r(rc0s
rccKsD|dur
|�dd�}|dkrt|||fi|��St|||fi|��S)N�wiki_flavorrHrC)�get_hintr!r )r]r@r�r]�optionsr'r'r(rLs
rcC�0|st�S|dur|�dd�}t|||��|�S)N�preserve_newlinesF)rrerYra)r]r�r]r'r'r'r(r T�
r cCrg)N�
shorten_linesF)rrercra)r]r�r]r�r'r'r(r![rir!cCs|st�St||��|�Sr$)rrUr�)r]r�r]r'r'r(rbsrFcCsb|st�S|p|j|p|j}}ddlm}	|	||d�}
t��}t||
��||||�t|�	��S)zB:deprecated: will be removed in 1.0 and replaced by something elser)�web_context)�absurls)
rr�r�rDrkr�r�rMr�r�)rWr]�dbrlrQrRr��abs_refr�rkr�r�r'r'r(r#jsr#r$)NFNNN)7r�r��	trac.core�
trac.mimeview�
trac.resourcerr�	trac.utilrr�trac.util.textrrr	r
r�trac.util.htmlrr
rrrrrr�trac.util.translationrr�
trac.wiki.apirr�trac.wiki.parserrr�__all__r)r1r"rrvrrr7rGrrBrMrUrYrcrr r!rr#r'r'r'r(�<module>sR(


&WQA

�

https://t.me/RX1948 - 2025