B “äî\àŽã@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. icCsxxp|j tj¡D]\}t|jtjƒs| d¡s| d¡s| d¡rFqt|ƒdksZt 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|_x&|dD]}||jj|<||j|<qàWx|d D]}||j|<qW|j t|d iƒ¡|j t|d iƒ¡|dd|d<g|d<g|d <|j |¡qWdS) 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úB/tmp/pip-build-uw_ogi45/docutils/docutils/transforms/references.pyÚapply*s<        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 Csdg}g}x*|j tj¡D]}| d¡r| |¡qWx*|j tj¡D]}| d¡rD| |¡qDWt|ƒt|ƒkrà|jj  dt|ƒt|ƒf¡}|j  |¡}x@|D]8}tj |j |j |d}|j  |¡}|  |¡| |¡q WdSx~t||ƒD]p\}} d| _x`|  d¡r| d|d<d|_Pqü| ds:|jj| d} qü| dd|d<|j |¡PqüWqìWdS) 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 rsD           zAnonymousHyperlinks.applyN)r!r"r#r$r%r 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ÌcCs0x*|jjD]}|js| |¡| |¡q WdS)N)rZindirect_targetsr5Úresolve_indirect_targetÚresolve_indirect_references)rrrrrr Ðs zIndirectHyperlinks.applycCsN| d¡}|dkr|d}n>|jj |¡}|sZx&|jjjD]}||ƒr:Pq:W| |¡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 rD|d=d|_ dS)Nr r)rÚmultiply_indirectr(rr )r*rÚnameidsÚ transformerÚunknown_reference_resolversÚnonexistent_indirect_targetr Únote_referenced_byrrrr5rÚcircular_indirect_referencer?r=r)rrr Z reftarget_idÚresolver_functionZ reftargetrrrr=ÖsH                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)rr@Úindirect_target_error)rrrrrrCsz.IndirectHyperlinks.nonexistent_indirect_targetcCs| |d¡dS)Nzforming a circular reference)rG)rrrrrrE sz.IndirectHyperlinks.circular_indirect_referencec Cs d}g}|dr d|dd}x&|dD]}| |jj |g¡¡q*Wx&|dD]}| |jj |g¡¡qRW|drŒ|d|dd7}|jjjd||d|f|d }|j |¡}xFt  |¡D]8} t j | j | j |d } |j | ¡} |  | ¡|  | ¡qÄWd |_dS) NÚr z"%s" rr z (id="%s")z7Indirect hyperlink target %s refers to target "%s", %s.r )Ú base_node)rr()rrÚrefnamesr*Úrefidsr,r-r.rZuniqrr/r0r1r2r5) rrZ explanationÚnamingÚreflistrrr7r8r9r:r;rrrrG s*   z(IndirectHyperlinks.indirect_target_errorc Cs:| d¡rd}|jj}n| d¡r,d}d}ndS||}x||dD]p}|jj |g¡}|rf|j|dxJ|D]B}|jrxql|d=|||<|r’||ƒd|_t|tj ƒrl|  |¡qlWqBWx~|dD]r}|jj  |g¡}|rä|j|dxL|D]D}|jröqê|d=|||<|r||ƒd|_t|tj ƒrê|  |¡qêWqÀWdS) Nrrr )rr r(r )r) rrrrJr*rDr5rrrr>rK) rrZattnameZ call_methodZattvalrrMr9rrrrr>$sH         z.IndirectHyperlinks.resolve_indirect_referencesN) r!r"r#r$r%r r=rCrErGr>rrrrr<šs2-r<c@seZdZdZdZdd„ZdS)ÚExternalTargetsa¸ Given:: direct external The "refname" attribute is replaced by the direct "refuri" attribute:: direct external i€cCsŠx„|j tj¡D]r}| d¡r|d}xZ|dD]N}|jj |g¡}|rT|j|dx(|D] }|jrfqZ|d=||d<d|_qZWq0WqWdS)Nrr )rr r() rrrrrrJr*rDr5)rrrrrMr9rrrr `s   zExternalTargets.applyN)r!r"r#r$r%r rrrrrNLsrNc@s eZdZdZdd„Zdd„ZdS)ÚInternalTargetsi”cCs:x4|j tj¡D]"}| d¡s| d¡s| |¡qWdS)Nrr)rrrrrÚresolve_reference_ids)rrrrrr tszInternalTargets.applycCsrxl|dD]`}|jj |¡}|jj |g¡}|r<|j|dx,|D]$}|jrNqB|r`|d=||d<d|_qBWq WdS)aº Given:: direct internal The "refname" attribute is replaced by "refid" linking to the target's "id":: direct internal r )rr rr(N)rr@r*rJrDr5)rrrrrMr9rrrrPys  z%InternalTargets.resolve_reference_idsN)r!r"r#r%r rPrrrrrOpsrOc @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