Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/mercurial/minirst.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


��c@sWdZddlZddlZddlZddlmZddlZd�Zd�Zd�Z	d�Z
d�Zejd	�Z
d
�Zd�Zejd�Zejd
�Zejd�Zejd�Zejd�Zd�ZdZd�Zd�Zd�Zejd�Zd�Zd�Zd�Zd�Zd�Zd�Z ejddej!�Z"d�Z#i	ed �d!6ed"�d#6ed$�d%6ed&�d'6ed(�d)6ed*�d+6ed,�d-6ed.�d/6ed0�d16Z$d2�Z%d3�Z&d4�Z'd5dd6�Z)d7�Z*d8d5dd9d:�Z+d;�Z,d<�Z-d5e.d=�Z/dS(>s�simplified reStructuredText parser.

This parser knows just enough about reStructuredText to parse the
Mercurial docstrings.

It cheats in a major way: nested blocks are not really nested. They
are just indented blocks that look like they are nested. This relies
on the user to keep the right indentation for the blocks.

Remember to update http://mercurial.selenic.com/wiki/HelpStyleGuide
when adding support for new constructs.
i�N(t_cCsd|dtj|�fS(Ns%s
%s

s"(tencodingtcolwidth(ts((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytsectionscCsd|dtj|�fS(Ns%s
%s

t=(RR(R((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
subsectionscCsd|dtj|�fS(Ns%s
%s

t-(RR(R((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
subsubsection!scCsd|dtj|�fS(Ns%s
%s

t.(RR(R((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytsubsubsubsection$scCsK|jtj�}x&|D]\}}|j||�}qW|jtj�S(s5
    Apply a list of (find, replace) pairs to a text.

    >>> replace("foo bar", [('f', 'F'), ('b', 'B')])
    'Foo Bar'
    >>> encoding.encoding = 'latin1'
    >>> replace('\x81\\', [('\\', '/')])
    '\x81/'
    >>> encoding.encoding = 'shiftjis'
    >>> replace('\x81\\', [('\\', '/')])
    '\x81\\'
    (tdecodeRtreplacetencode(ttexttsubststutexttftt((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyR'ss\n(?:\s*\n)+cCs�g}x�tj|jd�j��D]j}|j�}|r%td�|D��}g|D]}||^qZ}|jtd|d|��q%q%W|S(s�Find continuous blocks of lines in text.

    Returns a list of dictionaries representing the blocks. Each block
    has an 'indent' field and a 'lines' field.
    s
css+|]!}t|�t|j��VqdS(N(tlentlstrip(t.0tl((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pys	<genexpr>Jstindenttlines(t_blockretsplitRtrstript
splitlinestmintappendtdict(RtblockstbRRR((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
findblocks@s%#cCs�d}x�|t|�kr�d||d<||ddjd�r�|dt|�kr�||d}||dd|}||ddgkr�||=|d8}nb||ddjd	�r�|ddd
 ||dd<n"||ddd ||dd<tj||dd�}|rO||j�7}||j�8}nxi|dt|�kr�||dd|kr�d||dd<||ddc|8<|d7}qRWn|d7}q	W|S(s�Finds literal blocks and adds a 'type' field to the blocks.

    Literal blocks are given the type 'literal', all other blocks are
    given type the 'paragraph'.
    it	paragraphttypeRi�s::iRs ::i�tliteral(Rtendswitht	_bulletretmatchtend(R tiRt
adjustmenttm((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytfindliteralblocksOs,
1
%"1s((-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)|\|) s0^(-([a-zA-Z0-9]), )?(--[a-z0-9-]+)((.*)  +)(.*)$s:(?![: ])([^:]*)(?<! ):[ ]+(.*)s[^ ]s
(=+\s+)*=+cCsOdttfdttfdttfdttfg}d�}d}x|t|�krJ||ddkr=||d	}x�|D]�\}}}||d||�r�g}xqt|�D]c\}	}
|||	||�r|jt	d|d	gd
||d
��n|dd	j|
�q�W||||d+Pq�q�Wn|d7}qHW|S(
sSplit paragraphs into lists.tbullettoptiontfieldt
definitioncSs�||}|dt|�kr.||dp1d}|j|�sGtS|rv|dkpu|ddkpu|j|�S|jd�SdS(s�Does itemre match an item at line i?

        A list item can be followed by an indented line or another list
        item (but only if singleline is True).
        itit N(RR(tFalset
startswith(RR*titemret
singlelinetline1tline2((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyR(�s
*)iR$R#RRi�i(
R'tTruet	_optionret_fieldret
_definitionreR4Rt	enumerateRR(R t	listtypesR(R*RR$R6R7titemstjtline((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytsplitparagraphs�s*	icCs�d}x�|t|�kr�||ddkr?|d7}q	n|}x�|t|�kr�||ddkr�tj||dd�}|j�\}}|||dd<|||d<|d7}qHW|d}q	W|S(sFind key for field lists.iR$R0iRtkey(RR<R(tgroups(R R*RAR,RDtrest((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytupdatefieldlists�s
)c
	Cs�d}x�|t|�kr�||ddkr?|d7}q	nd}|}x-|t|�krz||ddkrztj||dd�}|jd�}|jd�}|dj�}|jd�j�}|jd	�j�}	|||dd<d
}
|sd}
nd|r!d
|p$d
d|
||	ff}|j�}|||d<t|tj|��}|d7}qNWx|||!D]}||d<q�W|d}q	W|S(NiR$R/iRiiiiR2s   s%s%ss-%s s	%s--%s %stoptstrtoptstrwidth(	RR;R(tgrouptstripRtmaxRR(
R R*RIRAR,tshortoptiontgroup3t
longoptiontdesct
longoptionargt	noshortoptopttblock((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytupdateoptionlists�s:
)		c	Cs=g}d}x$|dt|�kr2||ddkr%||ddjd�r%||d}||dd|}||ddd}||k}|r�|j|�n||=|}|d8}x[|t|�kr!||d|kr!|r||=q�||dc|8<|d7}q�Wn|d7}qW||fS(	s�Prune unwanted containers.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    iiR$R#Rs.. container::Ri(RR5R(	R tkeeptprunedR*RR+t
containertypetpruneRA((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytprunecontainers�s*
)
s^([-=`:.'"~^_*+#])\1+$c
Cs�x�|D]�}|ddkrt|d�dkrtj|dd�r|dd|ddkrd|d<t|d<|dd}gtt|��D]<}||d	kr�|dks�||d
dkr�|^q�}g}x�dd
d!D]�}||krt|d<q�g}|d}x�t|�D]�\}	}
|	d
t|�kr�||	d
|
}tj|||�}|t|�7}|j	|j
��q4|j	||j
��q4W|j	|�q�|d<qqW|S(sQFind simple tables

       Only simple one-line table elements are supported
    R$R#Riii�ttabletheaderRiR3(Rt_tablereR(R4txrangeR:R>RtgetcolsRRK(
R RTtdivtxtcolumnstrowsRtrowtpostntstarttwidthtv((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
findtabless6
	

<

cCs�x�|D]�}|ddkrt|d�dkrtj|dd�t|dd�krtj|dd�r|ddd|d<d|d<|dd=qqW|S(	s�Finds sections.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    R$R#Riiit	underlineR(RRRt
_sectionreR((R RT((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytfindsectionsGs
+
cCs[dg}xK|D]C}|ddkrg|dD]}t||�^q1|d<qqW|S(	Ns``t"R$R#RR(s``Rn(s	paragraphssection(R(R RR!R((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytinlineliterals]s
	
1cCs^d	d
g}xK|D]C}|ddkrg|dD]}t||�^q4|d<qqW|S(Ns:hg:`s"hg t`RnR$R#RR(s:hg:`s"hg (RpRn(s	paragraphssection(R(R RR!R((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pythgroleds

1c
Cs�d}x�|t|�kr�||d||ddkr\||ddkr\|d7}q	|j|tddgdd	dd
��|d7}q	W|S(
s�Adds empty blocks for vertical spacing.

    This groups bullets, options, and definitions together with no vertical
    space between them, and adds an empty block between all other blocks.
    iR$R.R/R0RR2Ritmargini(sbulletsoptionsfield(RtinsertR(R R*((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
addmarginsos 
(cCs�d}x�|t|�kr�||}|ddkr�|ddjd�s_|ddgkr�||=|t|�kr�||ddkr�||=q�q	|d7}q	W|S(	sRemove comments.iR$R#Rs.. s..Rri(RR5(R R*R!((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
prunecommentss
'&
sR\.\. (admonition|attention|caution|danger|error|hint|important|note|tip|warning)::tflagscCs�d}x�|t|�kr�j||dd�}|r�d||d<||ddd|j�d!j�}||dd|j�d}|r�||djdd|�n|||d	<||dd=n|d}q	W|S(
sj
    Makes the type of the block an admonition block if
    the first line is an admonition directive
    iRt
admonitionR$iiis   tadmonitiontitle(Rt
_admonitionreR(R)tlowerRs(R R*R,Rxt	firstline((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytfindadmonitions�s) s
Attention:t	attentionsCaution:tcautions!Danger!tdangersError:terrorsHint:thints
Important:t	importantsNote:tnotesTip:ttipsWarning!twarningcCs�djttj|d��}tj|d�}|d}|d}d|dd||f}dtj|�d}dtj||d|d	|�S(
NR3RRHiRIs%s%s  s %s
t
initindentt
hangindent(tjointmaptstrRKRRtutiltwrap(RTRhRPRtusablewidththangingR�R�((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytformatoption�s

c
Cs�|dkrd}nd|d}|ddkr�t|d}t|dd	�t|dd	j��}||d}djttj|d��}d
||tj|d|d|d
|�fS|ddkr�dS|ddkr|d7}|d|j|d�dS|ddkr]t	j
|dd�|d}d||dd||fS|ddkr�|d}gt|�D].}	tg|	D]}
t	j
|
�^q��^q�}d}t
|�t|�d}d|d}dt|�||d	}x�|D]�}
g}xEt||
�D]4\}}d|t	j
|�}|j||�q%Wdj|�}tj|d|d|d
|�}|r�|dr�|d|dt||�d}q	||d7}q	W|S|ddkr�||dd}t|dd	�t|dd	j��}||d}djttj|dd��}d
|tj|d|d|d
|�fS|}|ddkr�ddjd�r�|ddd|dd<q�tj|dd�}||j�d}n�|ddkrv|d}|td}t|�dtkrJ|j|�}n|jt�}||dd|dd<n|dd kr�t||�Sdjttj|d��}tj|d|d|d
|�dS(!s"Format a block according to width.iiNR3RR$RwRxRi�s%s
%s
RhR�R�Rrs
R%s  RRks
%s%s
%s%s
R[R2iR\RR1R.s| iR0RDR/(t_admonitiontitlesRRR�R�R�RKR�R�RRtzipRLtsumRRR5R'R(R)t_fieldwidthtljustR�(RTRhRRwthangt	defindentRRkR[tctetwidthstspanRdRtwRitpadttermt	subindentR,RD((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytformatblock�s�	,


A
!&,#

cs�g�d}g�d�}��fd�}g|D]}|ddkr4|^q4}xvt|�D]h\}}|d}|d}|d}|dkr�t|d	�}	|d
jttj|���}
�jd|	|
f�n8|dkr�jd
|dj|���n	|dkr&n�dkrU�jd|dj|���n�|dkr�|d}||kr�||7}n|j|�d}�jd|||d�|f�nb|dkrq|d}�jd�x}|D]u}
�jd�xH|
D]@}�jd��j||���jd��jd�qW�j��jd�q��jd�n�|dkr�|d|�||d�}|d
jttj|d���}
�jd||
f�nG|d krX|dj	d
d�\}}|d!kr|d"|�n
|d#|��jd$|d
j|g|d���n�|d%kr�|d|�||d&�}|d
jttj|���}
�jd||
f�nd|d'kr |d|�||d(�}|d
jttj|���}�jd||f�n�rc�d)\}}|t
|�dkrj�jd*|��j�q�||d}|d}||ks�||kr�|dd+kr��jd*|��j�q�qcqcWdj��S(,sFormat RST blocks as HTMLR2cSstj|t�S(N(tcgitescapeR:(R((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyR�scsF�s�dd|krB�j||f��jd|�ndS(Ni�is<%s>
(R(Rgtlevel(tlistnesttout(s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytopenlistsR$RrRRRwRxR3s<p>
<b>%s</b> %s
</p>
R#s<p>
%s
</p>
s
R%s<pre>
%s
</pre>
RRkis<h%d>%s</h%d>
iR[s<table>
s<tr>s<td>s</td>s</tr>
s	</table>
R1tdls <dt>%s
 <dd>%s
R.Rtultols	 <li> %s
R0RDR/RHi�s</%s>
sdefinition bullet field option(R>R�R�R�R�RKRtindextpopRR(R t
headernestR�R�R!RetbtypeR�RRwRR*R[RdRiR�R.theadRDRSRPRgtnbtni((R�R�s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt
formathtml
s�	)


!##

'








%
.
!
!

icCs�g}t|�}x|D]}|dc|7<qWt|�}t|�}t||pZg�\}}t|�}t|�}t|�}t|�}t|�}t	|�}t
|�}t|�}t|�}||fS(s Parse text into a list of blocksR(
R"R-RjRZRmRoRqRCRGRURtRuR|(RRRVRWR R!((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytparsees"
cs#dj�fd�|D��}|S(NR2c3s|]}t|��VqdS(N(R�(RR!(Rh(s5/sys/lib/python2.7/site-packages/mercurial/minirst.pys	<genexpr>zs(R�(R RhR((Rhs5/sys/lib/python2.7/site-packages/mercurial/minirst.pytformatblocksysiPtplaincsvt|||pg�\}}|dkr9t|�}ndj�fd�|D��}|dkrh|S||fSdS(s-Parse and format the text according to width.thtmlR2c3s|]}t|��VqdS(N(R�(RR!(Rh(s5/sys/lib/python2.7/site-packages/mercurial/minirst.pys	<genexpr>�sN(R�R�R�tNone(RRhRRVtstyleR RW((Rhs5/sys/lib/python2.7/site-packages/mercurial/minirst.pytformat}scCs�d}d}g}x�|D]�}|ddkr�|d}||krR||7}n|j|�d}|| }|j|dd||gf�q|s�ddgfg}n|dd	j|�qW|S(
s=return a list of (section name, nesting level, blocks) tuplesR2iR$RRkiRi�i(R�R(R tnestR�tsecsR!R*((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytgetsections�s



$cCsmg}x`t|�D]R}|d}t|d|�}|jg|jt�D]}||f^qL�qW|S(s=generate a list of (section name, line text) pairs for searchii(R�R�RRR:(R RhRRRRR((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pytdecorateblocks�s
3cCsgt|�D]}td�|D��^q
}d|}|djd�|D��d}|g}xz|D]r}g}xEt||�D]4\}	}
d|	tj|
�}|j|
|�q�W|j|dj|�d�qjW|rt|�dkr|jd|�n|j|�|S(sAGenerate an RST table for the given table data as a list of linescss|]}tj|�VqdS(N(RR(RR�((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pys	<genexpr>�sR3css|]}d|VqdS(RN((RR�((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pys	<genexpr>�ss
ii(R�RLR�RRRRRs(tdataRR\R�R�R`R�RdRR�RiR�((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt	maketable�s/
!	
"
(0t__doc__treR�Rti18nRR�RRRR
RtcompileRR"R-R'R;R<R=R]RCR�RGRURZRlRjRmRoRqRtRut
IGNORECASERyR|R�R�R�R�R�R�R�R�R�R�R4R�(((s5/sys/lib/python2.7/site-packages/mercurial/minirst.pyt<module>sd							3	*		$	&	2						






		O	[				

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.