3

T'íc‰5ã@sìUdZddlZddlmZmZmZmZmZmZddl	m
Z
mZddlm
Z
mZmZmZddlmZddlmZmZddlmZdd	lmZmZdd
lmZer¶ddlmZddlm Z ej!e
j"e
j#ej$ej!ej%ej$ej$ej!e
j#d
œ
Z&Gdd„deƒZ'Gdd„de'ƒZ(Gdd„deƒZ)Gdd„deƒZ*ej+dƒZ,Gdd„deƒZ-Gdd„de-ƒZ.ej+dƒZ/ej+dƒZ0Gdd„deƒZ1ej+dej2ƒZ3Gd d!„d!eƒZ4e'ej5d"e(d#d$e)ƒe*ƒe-ƒe.ƒe1ƒe1ƒe4ƒd%œ	Z6ee7ef6d&ee7efd'œd(d)„Z8dS)*z#Handlers for additional ReST roles.éN)Ú
TYPE_CHECKINGÚAnyÚDictÚListÚTupleÚType)ÚnodesÚutils)ÚElementÚNodeÚTextElementÚsystem_message)Úaddnodes)Ú_Ú__)Úws_re)Ú
ReferenceRoleÚ
SphinxRole)ÚRoleFunction)ÚSphinx)ÚBuildEnvironment)
ÚcommandÚdfnZkbdZ
mailheaderZmakevarÚmanpageÚmimetypeZ	newsgroupÚprogramÚregexpcseZdZUdZejZeee	j
Zeede
e
eeeee
ddœ‡fdd„
Zeeeeefdœdd	„Zeeeeefd
œdd„Zeeeeefd
œd
d„Zeeeeefd
œdd„Zdee
eeeeefdœdd„Ze	jdee
eeeeefdœdd„Z‡ZS)ÚXRefRoleaA
    A generic cross-referencing role.  To create a callable that can be used as
    a role function, create an instance of this class.

    The general features of this role are:

    * Automatic creation of a reference and a content node.
    * Optional separation of title and target with `title <target>`.
    * The implementation is a class rather than a function to make
      customization easier.

    Customization can be done in two ways:

    * Supplying constructor parameters:
      * `fix_parens` to normalize parentheses (strip from target, and add to
        title if configured)
      * `lowercase` to lowercase the target
      * `nodeclass` and `innernodeclass` select the node classes for
        the reference and the content node

    * Subclassing and overwriting `process_link()` and/or `result_nodes()`.
    FN)Ú
fix_parensÚ	lowercaseÚ	nodeclassÚinnernodeclassÚ
warn_danglingÚreturncs<||_||_||_|dk	r ||_|dk	r.||_tƒjƒdS)N)rrr"r r!ÚsuperÚ__init__)Úselfrrr r!r")Ú	__class__©ú./tmp/pip-build-gk9425m9/sphinx/sphinx/roles.pyr%?szXRefRole.__init__)ÚtitleÚtargetr#cCsJ|js,|jdƒr|dd…}|jjr,|d7}|jdƒrB|dd…}||fS)Nz()ééþÿÿÿr-)Úhas_explicit_titleÚendswithÚconfigZadd_function_parentheses)r&r*r+r(r(r)Úupdate_title_and_targetLs

z XRefRole.update_title_and_target)r#cCsrd|jkr(d|j|_|_d|jg|_n0|jjddƒ\|_|_d|jd|j|jfg|_|jrf|jƒS|jƒSdS)Nú:ÚZxreféz%s-%s)ÚnameÚ	refdomainÚreftypeÚclassesÚsplitÚdisabledÚcreate_non_xref_nodeÚcreate_xref_node)r&r(r(r)ÚrunYs
zXRefRole.runcCs\tj|jdd…ƒ}|jr0d|_|j|dƒ\}}|j|j||jd}|j	|j
j|j|ddS)Nr4Fr3)r8)Úis_ref)
r	ÚunescapeÚtextrr.r1r!Úrawtextr8Úresult_nodesÚinlinerÚdocumentÚenv)r&r@r+Únoder(r(r)r;fszXRefRole.create_non_xref_nodecCs¸|j}|j}|jr|jƒ}|jr0|j||ƒ\}}|jj|j|j	|j
|jdœ}|j|j
f|Ž}|j|ƒ|j|j||j
||ƒ\}}||d<||j|j
||jd7}|j|jj|j|ddS)N)Zrefdocr6r7ZrefexplicitZrefwarnZ	reftarget)r8T)r>)r+r*rÚlowerrr1rEZdocnamer6r7r.r"r rAZset_source_infoÚprocess_linkr!r8rBrCrD)r&r+r*ÚoptionsÚrefnoder(r(r)r<os$

zXRefRole.create_xref_noder)rErJr.r*r+r#cCs|tjd|ƒfS)zëCalled after parsing title and target text, and creating the
        reference node (given in *refnode*).  This method can alter the
        reference node and must return a new (or the same) ``(title, target)``
        tuple.
        ú )rÚsub)r&rErJr.r*r+r(r(r)rHŠszXRefRole.process_link)rDrErFr>r#cCs
|ggfS)a(Called before returning the finished nodes.  *node* is the reference
        node if one was created (*is_ref* is then true), else the content node.
        This method can add other nodes and must return a ``(nodes, messages)``
        tuple (the usual return value of a role function).
        r()r&rDrErFr>r(r(r)rB“szXRefRole.result_nodes)FFNNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rZpending_xrefr rr
rÚliteralr!rÚboolr%Ústrrr1rrr
r=r;r<rHrDrBÚ
__classcell__r(r()r'r)r$s
&

	rcs4eZdZdeeeeeeefdœ‡fdd„Z‡ZS)ÚAnyXRefRoler)rErJr.r*r+r#cs&tƒj|||||ƒ}|jj|jƒ|S)N)r$rHÚ
attributesÚupdateZref_context)r&rErJr.r*r+Úresult)r'r(r)rHžszAnyXRefRole.process_link)	rMrNrOr
rRrSrrHrTr(r()r'r)rUsrUc@s8eZdZeeeeefdœdd„Zedœdd„Z	dS)ÚPEP)r#c

Csd|jjdƒ}dtdƒ|j|ddfg}tj|d}tjdd|gd}|jjj	|ƒyX|j
ƒ}tjddd|d	gd
}|jr’|tj
|j|jƒ7}nd|j}|tj
||ƒ7}WnPtk
rþ|jjjtdƒ|j|jd
}|jj|j|j|ƒ}	|	g|gfSX|||ggfS)Nzindex-%sÚindexÚsinglez$Python Enhancement Proposals; PEP %sr3)Úentries)ÚidsFÚpep)ÚinternalÚrefurir8zPEP zinvalid PEP number %s)Úline)rEÚnew_serialnorr+rrZrrCrDÚnote_explicit_targetÚ	build_uriÚ	referencer.Ústrongr*Ú
ValueErrorÚreporterÚerrorrÚlinenoÚproblematicrA)
r&Ú	target_idr\rZr+r`rer*ÚmsgÚprbr(r(r)r=§s&

zPEP.runcCsZ|jjjj}|jjddƒ}t|ƒdkrB|dt|dƒ|dfS|dt|dƒSdS)Nú#r4r,zpep-%04d/#%srz	pep-%04d/)rCrDÚsettingsZpep_base_urlr+r9ÚlenÚint)r&Úbase_urlÚretr(r(r)rdÀs
z
PEP.build_uriN)
rMrNrOrrrr
r=rSrdr(r(r(r)rY¦srYc@s8eZdZeeeeefdœdd„Zedœdd„Z	dS)ÚRFC)r#c

Csd|jjdƒ}dd|j|ddfg}tj|d}tjdd|gd}|jjj|ƒyX|j	ƒ}tj
ddd|d	gd
}|jrŽ|tj|j
|j
ƒ7}nd|j
}|tj||ƒ7}WnNtk
rø|jjjtdƒ|j|jd
}|jj|j|j|ƒ}	|	g|gfSX|||ggfS)Nzindex-%srZr[zRFC; RFC %sr3)r\)r]FÚrfc)r_r`r8zRFC zinvalid RFC number %s)ra)rErbr+rrZrrCrDrcrdrer.rfr*rgrhrirrjrkrA)
r&rlr\rZr+r`rer*rmrnr(r(r)r=Ês$

zRFC.runcCsf|jjjj}|jjddƒ}t|ƒdkrJ||jjt|dƒd|dS||jjt|dƒSdS)Nror4r,r)	rCrDrpZrfc_base_urlr+r9rqZrfc_urlrr)r&rsrtr(r(r)rdâs
$z
RFC.build_uriN)
rMrNrOrrrr
r=rSrdr(r(r(r)ruÉsruz(?<!&)&(?![&\s])c@s4eZdZejdƒZeeeee	fdœdd„Z
dS)ÚGUILabelz(?<!&)&(?![&\s]))r#cCsštj|j|jgd}|jj|jƒ}|tj|jdƒƒ7}xX|D]P}|j	ddƒ}tj|dƒ}tjdd|dgd}||7}|tj|dd…ƒ7}q<W|ggfS)	N)rAr8rz&&ú&r3Úaccelerator)r8r4)
rÚinlinerAr5Úamp_rer9r@ÚTextÚpopÚreplace)r&rFZspansÚspanÚletterryr(r(r)r=ñs
zGUILabel.runN)rMrNrOÚreÚcompiler{rrrr
r=r(r(r(r)rwîs
rwcs6eZdZdZeeeeefdœ‡fdd„Z‡Z	S)Ú
MenuSelectionu‣)r#cs|jjd|jƒ|_tƒjƒS)Nz-->)r@r~ÚBULLET_CHARACTERr$r=)r&)r'r(r)r=szMenuSelection.run)
rMrNrOr„rrrr
r=rTr(r()r'r)rƒsrƒz	{([^}]+)}z(\\*{|\\*})c@sHeZdZejdƒZeeeee	fdœdd„Z
eeedœdd„ZdS)	ÚEmphasizedLiteralz(\\\\|\\{|\\}|{|}))r#cCs<|j|jƒ}tj|jdf|ž|jjƒ|jgdœŽ}|ggfS)Nr3)Úroler8)Úparser@rrQrAr5rG)r&ÚchildrenrFr(r(r)r=szEmphasizedLiteral.run)r@r#cCsŠg}dg}xP|jj|ƒD]>}|dkr:|dd7<q|dkr‚t|ƒdkrl|d
dkrl|dd7<n|jdƒ|jdƒq|dkrt|ƒdko²|ddko²t|dƒd	krú|d	rØ|jtj|d	|d	ƒƒ|jtj|d|dƒƒdg}n|jdƒdj|ƒg}q|d
kr.|dd7<q|dkrJ|dd7<q|d|7<qWdj|ƒr†dj|ƒ}|jtj||ƒƒ|S)Nr3z\\r4ú\Ú{r,Ú}érz\{z\}éÿÿÿÿr-rrrr)Ú	parens_rer9rqÚappendrr|ÚemphasisÚjoin)r&r@rXÚstackÚpartr(r(r)r‡s6

*



zEmphasizedLiteral.parseN)
rMrNrOrr‚rŽrrrr
r=rSr‡r(r(r(r)r…s
r…z	\((.*)\)$c@s8eZdZejdejƒZeee	ee
fdœdd„ZdS)ÚAbbreviationz	\((.*)\)$)r#cCs`|jjƒ}|jj|jƒ}|rB|jd|jƒ…jƒ}|jdƒ|d<n|j}tj	|j
|f|ŽggfS)Nr4Zexplanation)rIÚcopyÚabbr_reÚsearchr@ÚstartÚstripÚgrouprZabbreviationrA)r&rIÚmatchedr@r(r(r)r=Ds
zAbbreviation.runN)rMrNrOrr‚ÚSr–rrrr
r=r(r(r(r)r”Asr”)r T)r")	ÚdownloadÚanyr^rvZguilabelZ
menuselectionÚfileZsampZabbrr)Úappr#cCs|ddlm}x@tjƒD]4\}}|j||ƒ}|j||d|giƒ}|j||ƒqWx tjƒD]\}}|j||ƒqXWddddœS)Nr)Úrolesr8ÚbuiltinT)ÚversionZparallel_read_safeZparallel_write_safe)Zdocutils.parsers.rstr¡Úgeneric_docrolesÚitemsZGenericRoleZ
CustomRoleZregister_local_roleÚspecific_docroles)r r¡Zrolenamer Zgenericr†Úfuncr(r(r)Úsetup`sr¨)9rPrÚtypingrrrrrrZdocutilsrr	Zdocutils.nodesr
rrr
ZsphinxrZ
sphinx.localerrZsphinx.utilrZsphinx.util.docutilsrrZsphinx.util.typingrZsphinx.applicationrZsphinx.environmentrZliteral_strongrrQZliteral_emphasisrr¤rrUrYrur‚Z_amp_rerwrƒZ
_litvar_rerŽr…rœZ_abbr_rer”Zdownload_referencer¦rSr¨r(r(r(r)Ú<module>sX 
y	#"


2