U å€C^pŽã@sîdZdZddlZddlZddlmZmZddlmZm Z Gdd„de ƒZ Gdd „d e ƒZ Gd d „d e ƒZ Gd d „d e ƒZ Gdd„de ƒZGdd„de ƒZGdd„deƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„dejƒZdS)z& Transforms for resolving references. ZreStructuredTextéN)ÚnodesÚutils)ÚTransformErrorÚ Transformc@seZdZdZdZdd„ZdS)ÚPropagateTargetsa} Propagate empty internal targets to the next element. Given the following nodes:: This is a test. PropagateTargets propagates the ids and names of the internal targets preceding the paragraph to the paragraph itself:: This is a test. icCsj|j tj¡D]T}t|jtjƒs| d¡s| d¡s| d¡rBqt|ƒdksVt dƒ‚|j dd}|dk rt|tj ƒs‚t|tj ƒrŽt|tjƒr|d  |d¡|d   |d ¡t|d ƒsÂi|_t|d ƒsÒi|_|dD]}||jj|<||j|<qÚ|d D]}||j|<qþ|j t|d iƒ¡|j t|d iƒ¡|dd|d<g|d<g|d <|j |¡qdS) NÚrefidÚrefuriÚrefnamerz&error: block-level target has childrenT)ZascendÚidsÚnamesÚexpect_referenced_by_nameÚexpect_referenced_by_id)ÚdocumentÚtraverserÚtargetÚ isinstanceÚparentZ TextElementÚhasattrÚlenÚAssertionErrorÚ next_nodeZ InvisibleZ TargetableÚextendr r r ÚupdateÚgetattrÚ note_refid)ÚselfrrÚidÚname©rúD/tmp/pip-install-6_kvzl1k/docutils/docutils/transforms/references.pyÚapply*sNÿÿþ  ÿ þ ý       ÿ ÿzPropagateTargets.applyN©Ú__name__Ú __module__Ú __qualname__Ú__doc__Údefault_priorityr rrrrrsrc@seZdZdZdZdd„ZdS)ÚAnonymousHyperlinksa¥ Link anonymous references to targets. Given:: internal external Corresponding references are linked via "refid" or resolved via "refuri":: text external i¸c CsPg}g}|j tj¡D]}| d¡r| |¡q|j tj¡D]}| d¡r>| |¡q>t|ƒt|ƒkrÔ|jj  dt|ƒt|ƒf¡}|j  |¡}|D]8}tj |j |j |d}|j  |¡}|  |¡| |¡q–dSt||ƒD]l\}} d| _|  d¡r| d|d<d|_qÞqì| ds*|jj| d} qì| dd|d<|j |¡qÞqìqÞdS) NÚ anonymousz]Anonymous hyperlink mismatch: %s references but %s targets. See "backrefs" attribute for IDs.©rérr rr)rrrÚ referenceÚgetÚappendrrÚreporterÚerrorÚset_idÚ problematicÚ rawsourceÚ add_backrefÚ replace_selfÚzipÚ referencedrÚresolvedr r) rZanonymous_refsZanonymous_targetsÚnodeÚmsgÚmsgidÚrefÚprbÚprbidrrrrr rsN    ÿþÿ ÿ       zAnonymousHyperlinks.applyNr!rrrrr'Xsr'c@sDeZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dS)ÚIndirectHyperlinksaN a) Indirect external references:: indirect external The "refuri" attribute is migrated back to all indirect targets from the final direct target (i.e. a target not referring to another indirect target):: indirect external Once the attribute is migrated, the preexisting "refname" attribute is dropped. b) Indirect internal references:: indirect internal Targets which indirectly refer to an internal target become one-hop indirect (their "refid" attributes are directly set to the internal target's "id"). References which indirectly refer to an internal target become direct internal references:: indirect internal iÌcCs,|jjD]}|js| |¡| |¡qdS©N)rZindirect_targetsr7Úresolve_indirect_targetÚresolve_indirect_references©rrrrrr Ðs  zIndirectHyperlinks.applycCsL| d¡}|dkr|d}n<|jj |¡}|sX|jjjD]}||ƒr8qTq8| |¡dS|jj|}|j|dt|t j ƒr¸|j s¸|  d¡r¸t |dƒr¤|  |¡dSd|_| |¡|`|  d¡rÞ|d|d<d|krÜ|d=nT|  d¡r|d|d<|j |¡n.|dr$||d<|j |¡n| |¡dS|dk rB|d=d|_ dS)Nr r©rÚmultiply_indirectr*rr )r,rÚnameidsÚ transformerÚunknown_reference_resolversÚnonexistent_indirect_targetr Únote_referenced_byrrrr7rÚcircular_indirect_referencerDr@r)rrr Z reftarget_idÚresolver_functionZ reftargetrrrr@ÖsN  ÿ    ÿÿ          z*IndirectHyperlinks.resolve_indirect_targetcCs.|d|jjkr| |d¡n | |d¡dS)Nr z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)rrEÚindirect_target_errorrBrrrrHsz.IndirectHyperlinks.nonexistent_indirect_targetcCs| |d¡dS)Nzforming a circular reference)rLrBrrrrJ sz.IndirectHyperlinks.circular_indirect_referencec Csþd}g}|dr d|dd}|dD]}| |jj |g¡¡q(|dD]}| |jj |g¡¡qL|dr„|d|dd7}|jjjd||d|f|d }|j |¡}t  |¡D]8} t j | j | j |d } |j | ¡} |  | ¡|  | ¡qºd |_dS) NÚr z"%s" rr z (id="%s")z7Indirect hyperlink target %s refers to target "%s", %s.r ©Ú base_noder)r*)rrÚrefnamesr,Úrefidsr.r/r0rZuniqrr1r2r3r4r7) rrZ explanationÚnamingÚreflistrrr9r:r;r<r=rrrrL s6   ÿþ ÿ   z(IndirectHyperlinks.indirect_target_errorc Cs*| d¡rd}|jj}n| d¡r,d}d}ndS||}|dD]l}|jj |g¡}|rd|j|d|D]B}|jrtqh|d=|||<|rŽ||ƒd|_t|tj ƒrh|  |¡qhq@|dD]n}|jj  |g¡}|rÚ|j|d|D]D}|jrêqÞ|d=|||<|r||ƒd|_t|tj ƒrÞ|  |¡qÞq¶dS) Nrrr ©rr r*r rC) rrrrPr,rIr7rrrrArQ) rrZattnameZ call_methodZattvalrrSr;rrrrrA$sH         z.IndirectHyperlinks.resolve_indirect_referencesN) r"r#r$r%r&r r@rHrJrLrArrrrr>šs2-r>c@seZdZdZdZdd„ZdS)ÚExternalTargetsa¸ Given:: direct external The "refname" attribute is replaced by the direct "refuri" attribute:: direct external i€cCs~|j tj¡D]j}| d¡r|d}|dD]J}|jj |g¡}|rP|j|d|D] }|jr`qT|d=||d<d|_qTq,qdS)Nrr rTr r*) rrrrrrPr,rIr7)rrrrrSr;rrrr `s   zExternalTargets.applyNr!rrrrrULsrUc@s eZdZdZdd„Zdd„ZdS)ÚInternalTargetsi”cCs6|j tj¡D]"}| d¡s| d¡s| |¡qdS)Nrr)rrrrrÚresolve_reference_idsrBrrrr tszInternalTargets.applycCsj|dD]\}|jj |¡}|jj |g¡}|r:|j|d|D]$}|jrJq>|r\|d=||d<d|_q>qdS)aº Given:: direct internal The "refname" attribute is replaced by "refid" linking to the target's "id":: direct internal r rTr rr*N)rrEr,rPrIr7)rrrrrSr;rrrrWys  z%InternalTargets.resolve_reference_idsN)r"r#r$r&r rWrrrrrVpsrVc @s`eZdZdZdZdZdddddd d d d d g Zdd„Zdd„Zdd„Z dd„Z dd„Z dd„Z dS)Ú Footnotesaè Assign numbers to autonumbered footnotes, and resolve links to footnotes, citations, and their references. Given the following ``document`` as input:: A labeled autonumbered footnote referece: An unlabeled autonumbered footnote referece: Unlabeled autonumbered footnote. Labeled autonumbered footnote. Auto-numbered footnotes have attribute ``auto="1"`` and no label. Auto-numbered footnote_references have no reference text (they're empty elements). When resolving the numbering, a ``label`` element is added to the beginning of the ``footnote``, and reference text to the ``footnote_reference``. The transformed result will be:: A labeled autonumbered footnote referece: 2 An unlabeled autonumbered footnote referece: 1