o
    S‰»_ßŽ  ã                   @   sî   d Z dZddlZddlZddlmZmZ ddlmZm	Z	 G dd„ de	ƒZ
G dd	„ d	e	ƒZG d
d„ de	ƒZG dd„ de	ƒZG dd„ de	ƒZG dd„ de	ƒZG dd„ deƒZG dd„ de	ƒZG dd„ de	ƒZG dd„ de	ƒZG dd„ dejƒZdS )z&
Transforms for resolving references.
ÚreStructuredTexté    N)ÚnodesÚutils)ÚTransformErrorÚ	Transformc                   @   ó   e Zd ZdZdZdd„ ZdS )ÚPropagateTargetsa}  
    Propagate empty internal targets to the next element.

    Given the following nodes::

        <target ids="internal1" names="internal1">
        <target anonymous="1" ids="id1">
        <target ids="internal2" names="internal2">
        <paragraph>
            This is a test.

    PropagateTargets propagates the ids and names of the internal
    targets preceding the paragraph to the paragraph itself::

        <target refid="internal1">
        <target anonymous="1" refid="id1">
        <target refid="internal2">
        <paragraph ids="internal2 id1 internal1" names="internal2 internal1">
            This is a test.
    i  c                 C   sf  | j  tj¡D ]©}t|jtjƒs| d¡s| d¡s| d¡r qt|ƒdks*J dƒ‚|j	dd�}|d ur°t|tj
ƒs@t|tjƒrFt|tjƒr°|d  |d ¡ |d	  |d	 ¡ t|d
ƒs`i |_t|dƒshi |_|d D ]}|| j j|< ||j|< ql|d	 D ]}||j|< q~|j t|d
i ƒ¡ |j t|di ƒ¡ |d d |d< g |d< g |d	< | j  |¡ qd S )NÚrefidÚrefuriÚrefnamer   z&error: block-level target has childrenT)ÚascendÚidsÚnamesÚexpect_referenced_by_nameÚexpect_referenced_by_id)ÚdocumentÚtraverser   ÚtargetÚ
isinstanceÚparentÚTextElementÚhasattrÚlenÚ	next_nodeÚ	InvisibleÚ
TargetableÚextendr   r   r   ÚupdateÚgetattrÚ
note_refid)Úselfr   r   ÚidÚname© r#   ú@/usr/lib/python3/dist-packages/docutils/transforms/references.pyÚapply*   sR   ÿÿþ
ÿ
þ
ý


ÿ
ÿ€ÖzPropagateTargets.applyN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údefault_priorityr%   r#   r#   r#   r$   r      s    r   c                   @   r   )ÚAnonymousHyperlinksa¥  
    Link anonymous references to targets.  Given::

        <paragraph>
            <reference anonymous="1">
                internal
            <reference anonymous="1">
                external
        <target anonymous="1" ids="id1">
        <target anonymous="1" ids="id2" refuri="http://external">

    Corresponding references are linked via "refid" or resolved via "refuri"::

        <paragraph>
            <reference anonymous="1" refid="id1">
                text
            <reference anonymous="1" refuri="http://external">
                external
        <target anonymous="1" ids="id1">
        <target anonymous="1" ids="id2" refuri="http://external">
    i¸  c           
      C   sJ  g }g }| j  tj¡D ]}| d¡r| |¡ q| j  tj¡D ]}| d¡r+| |¡ qt|ƒt|ƒkrj| j j 	dt|ƒt|ƒf ¡}| j  
|¡}|D ]}tj|j|j|d�}| j  
|¡}| |¡ | |¡ qKd S t||ƒD ]3\}}	d|	_	 |	 d¡r†|	d |d< d|_n|	d s“| j j|	d  }	qv|	d d	 |d< | j  |¡ 	 qod S )
NÚ	anonymousz]Anonymous hyperlink mismatch: %s references but %s targets.
See "backrefs" attribute for IDs.©r	   é   Tr
   r   r	   r   )r   r   r   Ú	referenceÚgetÚappendr   r   ÚreporterÚerrorÚset_idÚproblematicÚ	rawsourceÚadd_backrefÚreplace_selfÚzipÚ
referencedr   Úresolvedr   r   )
r    Úanonymous_refsÚanonymous_targetsÚnodeÚmsgÚmsgidÚrefÚprbÚprbidr   r#   r#   r$   r%   r   sT   

€

€ÿþÿ
ÿ

€òzAnonymousHyperlinks.applyNr&   r#   r#   r#   r$   r,   X   s    r,   c                   @   sD   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dS )ÚIndirectHyperlinksaN  
    a) Indirect external references::

           <paragraph>
               <reference refname="indirect external">
                   indirect external
           <target id="id1" name="direct external"
               refuri="http://indirect">
           <target id="id2" name="indirect external"
               refname="direct 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)::

           <paragraph>
               <reference refname="indirect external">
                   indirect external
           <target id="id1" name="direct external"
               refuri="http://indirect">
           <target id="id2" name="indirect external"
               refuri="http://indirect">

       Once the attribute is migrated, the preexisting "refname" attribute
       is dropped.

    b) Indirect internal references::

           <target id="id1" name="final target">
           <paragraph>
               <reference refname="indirect internal">
                   indirect internal
           <target id="id2" name="indirect internal 2"
               refname="final target">
           <target id="id3" name="indirect internal"
               refname="indirect internal 2">

       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::

           <target id="id1" name="final target">
           <paragraph>
               <reference refid="id1">
                   indirect internal
           <target id="id2" name="indirect internal 2" refid="id1">
           <target id="id3" name="indirect internal" refid="id1">
    iÌ  c                 C   s,   | j jD ]}|js|  |¡ |  |¡ qd S ©N)r   Úindirect_targetsr<   Úresolve_indirect_targetÚresolve_indirect_references©r    r   r#   r#   r$   r%   Ð   s
   
ýzIndirectHyperlinks.applyc                 C   sH  |  d¡}|d u r|d }n| jj  |¡}|s-| jjjD ]	}||ƒr% d S q|  |¡ d S | jj| }|j|d� t|t	j
ƒr]|js]| d¡r]t|dƒrS|  |¡ d S d|_|  |¡ |`| d¡rp|d |d< d|v ro|d= n(| d¡r‚|d |d< | j |¡ n|d r‘||d< | j |¡ n|  |¡ d S |d urŸ|d= d|_d S )Nr   r	   ©r!   Úmultiply_indirectr/   r
   r   )r1   r   ÚnameidsÚtransformerÚunknown_reference_resolversÚnonexistent_indirect_targetr   Únote_referenced_byr   r   r   r<   r   Úcircular_indirect_referencerL   rH   r   )r    r   r   Úreftarget_idÚresolver_functionÚ	reftargetr#   r#   r$   rH   Ö   sT   

ÿü
ÿÿ



€


z*IndirectHyperlinks.resolve_indirect_targetc                 C   s0   |d | j jv r|  |d¡ d S |  |d¡ d S )Nr   z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)r   rM   Úindirect_target_errorrJ   r#   r#   r$   rP     s   z.IndirectHyperlinks.nonexistent_indirect_targetc                 C   s   |   |d¡ d S )Nzforming a circular reference)rV   rJ   r#   r#   r$   rR   
  s   z.IndirectHyperlinks.circular_indirect_referencec                 C   sþ   d}g }|d rd|d d  }|d D ]}|  | jj |g ¡¡ q|d D ]}|  | jj |g ¡¡ q&|d rB|d|d d  7 }| jjjd||d |f |d	�}| j |¡}t 	|¡D ]}	t
j|	j|	j|d
�}
| j |
¡}| |¡ |	 |
¡ q]d|_d S )NÚ r   z"%s" r   r   z	(id="%s")z7Indirect hyperlink target %s refers to target "%s", %s.r   ©Ú	base_noder.   r/   )r   r   Úrefnamesr1   Úrefidsr3   r4   r5   r   Úuniqr   r6   r7   r8   r9   r<   )r    r   ÚexplanationÚnamingÚreflistr"   r!   r@   rA   rB   rC   rD   r#   r#   r$   rV     s2   ÿþ
ÿ

z(IndirectHyperlinks.indirect_target_errorc           	      C   s(  |  d¡rd}| jj}n|  d¡rd}d }nd S || }|d D ]6}| jj |g ¡}|r2|j|d� |D ]!}|jr:q4|d= |||< |rG||ƒ d|_t|tj	ƒrU|  
|¡ q4q |d D ]6}| jj |g ¡}|rm|j|d� |D ]!}|jruqo|d= |||< |r‚||ƒ d|_t|tj	ƒr�|  
|¡ qoq[d S )	Nr	   r
   r   ©r"   r   r/   r   rK   )r   r   r   rZ   r1   rQ   r<   r   r   r   rI   r[   )	r    r   ÚattnameÚcall_methodÚattvalr"   r_   rB   r!   r#   r#   r$   rI   $  sR   



€÷

€÷üz.IndirectHyperlinks.resolve_indirect_referencesN)r'   r(   r)   r*   r+   r%   rH   rP   rR   rV   rI   r#   r#   r#   r$   rE   š   s    2-rE   c                   @   r   )ÚExternalTargetsa¸  
    Given::

        <paragraph>
            <reference refname="direct external">
                direct external
        <target id="id1" name="direct external" refuri="http://direct">

    The "refname" attribute is replaced by the direct "refuri" attribute::

        <paragraph>
            <reference refuri="http://direct">
                direct external
        <target id="id1" name="direct external" refuri="http://direct">
    i€  c                 C   s~   | j  tj¡D ]5}| d¡r<|d }|d D ]%}| j j |g ¡}|r(|j|d� |D ]}|jr0q*|d= ||d< d|_q*qqd S )Nr
   r   r`   r   r/   )	r   r   r   r   r   rZ   r1   rQ   r<   )r    r   r
   r"   r_   rB   r#   r#   r$   r%   `  s    
û€ùzExternalTargets.applyNr&   r#   r#   r#   r$   rd   L  s    rd   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚInternalTargetsi”  c                 C   s6   | j  tj¡D ]}| d¡s| d¡s|  |¡ qd S )Nr
   r	   )r   r   r   r   r   Úresolve_reference_idsrJ   r#   r#   r$   r%   t  s
   
€þzInternalTargets.applyc                 C   sj   |d D ].}| j j |¡}| j j |g ¡}|r|j|d� |D ]}|jr%q|r.|d= ||d< d|_qqdS )aº  
        Given::

            <paragraph>
                <reference refname="direct internal">
                    direct internal
            <target id="id1" name="direct internal">

        The "refname" attribute is replaced by "refid" linking to the target's
        "id"::

            <paragraph>
                <reference refid="id1">
                    direct internal
            <target id="id1" name="direct internal">
        r   r`   r   r	   r/   N)r   rM   r1   rZ   rQ   r<   )r    r   r"   r	   r_   rB   r#   r#   r$   rf   y  s   úûz%InternalTargets.resolve_reference_idsN)r'   r(   r)   r+   r%   rf   r#   r#   r#   r$   re   p  s    re   c                   @   sR   e Zd ZdZdZdZ	 g d¢Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZdS )Ú	Footnotesaè  
    Assign numbers to autonumbered footnotes, and resolve links to footnotes,
    citations, and their references.

    Given the following ``document`` as input::

        <document>
            <paragraph>
                A labeled autonumbered footnote referece:
                <footnote_reference auto="1" id="id1" refname="footnote">
            <paragraph>
                An unlabeled autonumbered footnote referece:
                <footnote_reference auto="1" id="id2">
            <footnote auto="1" id="id3">
                <paragraph>
                    Unlabeled autonumbered footnote.
            <footnote auto="1" id="footnote" name="footnote">
                <paragraph>
                    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::

        <document>
            <paragraph>
                A labeled autonumbered footnote referece:
                <footnote_reference auto="1" id="id1" refid="footnote">
                    2
            <paragraph>
                An unlabeled autonumbered footnote referece:
                <footnote_reference auto="1" id="id2" refid="id3">
                    1
            <footnote auto="1" id="id3" backrefs="id2">
                <label>
                    1
                <paragraph>
                    Unlabeled autonumbered footnote.
            <footnote auto="1" id="footnote" name="footnote" backrefs="id1">
                <label>
                    2
                <paragraph>
                    Labeled autonumbered footnote.

    Note that the footnotes are not in the same order as the references.

    The labels and reference text are added to the auto-numbered ``footnote``
    and ``footnote_reference`` elements.  Footnote elements are backlinked to
    their references via "refids" attributes.  References are assigned "id"
    and "refid" attributes.

    After adding labels and reference text, the "auto" attributes can be
    ignored.
    il  N)
Ú*u   â€ u   â€¡õ   Â§õ   Â¶ú#u   â™ u   â™¥u   â™¦u   â™£c                 C   s:   g | _ | jj}|  |¡| j_|  |¡ |  ¡  |  ¡  d S rF   )Úautofootnote_labelsr   Úautofootnote_startÚnumber_footnotesÚnumber_footnote_referencesÚsymbolize_footnotesÚresolve_footnotes_and_citations)r    Ústartnumr#   r#   r$   r%   ë  s   
zFootnotes.applyc                 C   s  | j jD ]‡}	 t|ƒ}|d7 }|| j jvrnq| dt d|¡¡ |d D ]I}| j j |g ¡D ]>}|t 	|¡7 }| 
d¡ t|d ƒt|d ƒ  krPdksSJ ‚ J ‚|d d |d< | |d d ¡ | j  |¡ d|_q/q%|d s‹|d	 s‹|d  |¡ | j  ||¡ | j |¡ q|S )
z«
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        Tr/   r   rW   r   r   r   r	   Údupnames)r   ÚautofootnotesÚstrrM   Úinsertr   ÚlabelÚfootnote_refsr1   ÚTextÚdelattrr   r8   r   r<   r2   Únote_explicit_targetrl   )r    rr   Úfootnoterw   r"   rB   r#   r#   r$   rn   ó  s0   ü
,ù€zFootnotes.number_footnotesc              
   C   s@  d}| j jD ]—}|js| d¡rqz| j| }W nM tye   | j jjdt| jƒ |d�}| j  	|¡}| j j|d… D ]%}|jsE| d¡rFq;t
j|j|j|d�}| j  	|¡}| |¡ | |¡ q;Y  dS w |t
 |¡7 }| j j| }	| j j|	 }
|	|d< | j  |¡ t|d ƒd	ks�J ‚|
 |d d ¡ d	|_|d	7 }qdS )
z3Assign numbers to autonumbered footnote references.r   r	   zUToo many autonumbered footnote references: only %s corresponding footnotes available.rX   Nr   r.   r   r/   )r   Úautofootnote_refsr<   r   rl   Ú
IndexErrorr3   r4   r   r5   r   r6   r7   r8   r9   ry   rM   r   r   )r    rr   ÚirB   rw   r@   rA   rC   rD   r!   r|   r#   r#   r$   ro     sF   þý
ÿ
ò
äz$Footnotes.number_footnote_referencesc              
   C   s’  g }| j jD ]4}t| j jt| jƒƒ\}}| j| |d  }| |¡ | dt 	d|¡¡ | j  jd7  _| j  
|¡ qd}| j jD ]…}z|t || ¡7 }W nL tyš   | j jjdt|ƒ |d�}| j  
|¡}	| j j|d… D ]%}|jsz| d¡r{qptj|j|j|	d�}
| j  
|
¡}| |¡ | |
¡ qpY  dS w | j j| }t|d	 ƒdks«J ‚|d	 d |d< | j  |¡ | |d	 d ¡ |d7 }qAdS )
z<Add symbols indexes to "[*]"-style footnotes and references.r/   r   rW   zOToo many symbol footnote references: only %s corresponding footnotes available.rX   Nr	   r.   r   )r   Úsymbol_footnotesÚdivmodÚsymbol_footnote_startr   Úsymbolsr2   rv   r   rw   r5   Úsymbol_footnote_refsry   r~   r3   r4   r<   r   r6   r7   r8   r9   r   )r    Úlabelsr|   ÚrepsÚindexÚ	labeltextr   rB   r@   rA   rC   rD   r#   r#   r$   rp   1  sP   ÿ
ÿý
ÿ
ò
ézFootnotes.symbolize_footnotesc                 C   s„   | j jD ]}|d D ]}|| j jv r| j j| }|  ||¡ q
q| j jD ]}|d D ]}|| j jv r>| j j| }|  ||¡ q*q$dS )za
        Link manually-labeled footnotes and citations to/from their
        references.
        r   N)r   Ú	footnotesrx   Úresolve_referencesÚ	citationsÚcitation_refs)r    r|   rw   r_   Úcitationr#   r#   r$   rq   V  s   €ý€ýÿz)Footnotes.resolve_footnotes_and_citationsc                 C   sz   t |d ƒdks
J ‚|d d }|D ]%}|jrq| d¡ ||d< t |d ƒdks+J ‚| |d d ¡ d|_qd|_d S )Nr   r/   r   r   r	   )r   r<   rz   r8   )r    Únoter_   r!   rB   r#   r#   r$   rŠ   f  s   

zFootnotes.resolve_references)r'   r(   r)   r*   r+   rl   rƒ   r%   rn   ro   rp   rq   rŠ   r#   r#   r#   r$   rg   ˜  s    ;!%rg   c                   @   s   e Zd ZdS )Ú#CircularSubstitutionDefinitionErrorN)r'   r(   r)   r#   r#   r#   r$   r�   t  s    r�   c                   @   s   e Zd ZdZdZ	 dd„ ZdS )ÚSubstitutionsaD  
    Given the following ``document`` as input::

        <document>
            <paragraph>
                The
                <substitution_reference refname="biohazard">
                    biohazard
                 symbol is deservedly scary-looking.
            <substitution_definition name="biohazard">
                <image alt="biohazard" uri="biohazard.png">

    The ``substitution_reference`` will simply be replaced by the
    contents of the corresponding ``substitution_definition``.

    The transformed result will be::

        <document>
            <paragraph>
                The
                <image alt="biohazard" uri="biohazard.png">
                 symbol is deservedly scary-looking.
            <substitution_definition name="biohazard">
                <image alt="biohazard" uri="biohazard.png">
    éÜ   c              
   C   s   | j j}| j j}i }t| j jddƒ}t| j  tj¡ƒ}|D �]o}d}|d }||v r-|}	n
| 	¡ }
| 
|
d ¡}	|	d u rG| j jjd| |d�}n||	 }t| ¡ ƒ|kr\| j j d|	 ¡}|r| j  |¡}tj|j|j|d�}| j  |¡}| |¡ | |¡ q|j}| |¡}d	|jv s‘d
|jv r«|dkr«t||d  tjƒr«||d   ¡ ||d < d|jv sµd
|jv rÓt|ƒ|d krÓt||d  tjƒrÓ||d   ¡ ||d < | ¡ }z-| tj¡D ]$}||d  	¡  }|| |g ¡v ròt‚||  |	¡ ||d< | |¡ qÞW ni t�ym   |j}t|tjƒ�r.| j jjdt  |j|j¡|j!|d�}| |¡ n=|}| "d¡�r@|d }| "d¡�s6| j jjd| |d�}| j  |¡}tj|j|j|d�}| j  |¡}| |¡ | |¡ Y qw | |j#¡ |j#D ]}t|tj$ƒ�r‹d|v �r‹| j  %|¡ �qwqd S )NÚline_length_limiti'  rW   r   z(Undefined substitution referenced: "%s".rX   z;Substitution definition "%s" exceeds the line-length-limit.r.   ÚltrimÚtrimr   r/   Úrtrimz
ref-originz*Circular substitution definition detected:)ÚlinerY   z2Circular substitution definition referenced: "%s".)&r   Úsubstitution_defsÚsubstitution_namesr   ÚsettingsÚlistr   r   Úsubstitution_referenceÚlowerr1   r3   r4   r   Úastextr5   r6   r7   r8   r9   r   r‡   Ú
attributesr   ry   ÚrstripÚlstripÚdeepcopyÚ
setdefaultr�   r2   Úsubstitution_definitionÚliteral_blockr–   r   ÚchildrenÚReferentialÚnote_refname)r    ÚdefsÚnormedÚnestedr’   Ú
subreflistrB   r@   r   ÚkeyÚnormed_nameÚsubdefrA   rC   rD   r   r‡   Úsubdef_copyÚ
nested_refÚnested_nameÚ
ref_originr?   r#   r#   r$   r%   —  sÊ   ÿ
ÿþÿÿ
ÿ




ÿ

ÿÿùÿüÿÿþ
ÿ

é

€û³zSubstitutions.applyNr&   r#   r#   r#   r$   r�   w  s
    r�   c                   @   s.   e Zd ZdZdZ	 dd„ Zdd„ Zdd„ Zd	S )
ÚTargetNotesz‚
    Creates a footnote for each external target in the text, and corresponding
    footnote references after each reference.
    i  c                 C   s$   t j| ||d� |j dg ¡| _d S )N)Ú	startnodeÚclass)r   Ú__init__Údetailsr1   Úclasses)r    r   r´   r#   r#   r$   r¶      s   zTargetNotes.__init__c           	      C   sþ   i }g }| j  tj¡D ];}| d¡sq|d }g }|D ]}| | j j |g ¡¡ q|s,q|  |d ||¡}|d |vrF|||d < | 	|¡ q| j  tj
¡D ](}| d¡sVqN| d¡rv|  |d |g|¡}|d |vrv|||d < | 	|¡ qN| j |¡ d S )Nr
   r   r-   )r   r   r   r   r   r   rZ   r1   Úmake_target_footnoter2   r0   r´   r9   )	r    ÚnotesÚnodelistr   r   Úrefsr"   r|   rB   r#   r#   r$   r%     s<   
ÿ
€

ÿ
€zTargetNotes.applyc                 C   sV  ||v r|| }t |d ƒdksJ ‚|d d }n6t ¡ }| j |¡}d| }d|d< |g|d< t ¡ }|tjd||d�7 }||7 }| j |¡ | j ||¡ |D ]W}t	|tj
ƒrZqQtj|dd�}	|	d	  | j7  < | j |	¡ | j |	¡ |j |¡d }
|	g}t | jj¡s¡| jr˜| dtjd
| jd�¡ n	| dt d
¡¡ |j |
|¡ qQ|S )Nr   r/   r   zTARGET_NOTE: ÚautorW   )r
   )r   r½   r¸   ú )ÚtextÚClasses)r   r   r|   r   r5   Ú	paragraphr0   Únote_autofootnoter{   r   r   Úfootnote_referencer¸   Únote_autofootnote_refÚnote_footnote_refr   r‡   r   Úget_trim_footnote_ref_spacer™   rv   Úinlinery   )r    r
   r¼   rº   r|   Úfootnote_nameÚfootnote_idÚfootnote_paragraphrB   Úrefnoder‡   r_   r#   r#   r$   r¹   #  s:   
z TargetNotes.make_target_footnoteN)r'   r(   r)   r*   r+   r¶   r%   r¹   r#   r#   r#   r$   r³   ô  s    r³   c                   @   r   )ÚDanglingReferencesze
    Check for dangling references (incl. footnote & citation) and for
    unreferenced targets.
    iR  c                 C   s’   t | j| jjjƒ}| j |¡ | j tj¡D ]0}|jsF| 	d¡r!q|d r,|d d }n|d r7|d d }n|d }| jj
jd| |d� qd S )Nr-   r   r   r   r	   z(Hyperlink target "%s" is not referenced.rX   )ÚDanglingReferencesVisitorr   rN   rO   Úwalkr   r   r   r;   r1   r3   Úinfo)r    Úvisitorr   r^   r#   r#   r$   r%   P  s,   þ
ÿþ€ðzDanglingReferences.applyNr&   r#   r#   r#   r$   rÌ   G  s    rÌ   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Ze ZZdS )rÍ   c                 C   s   t j | |¡ || _|| _d S rF   )r   ÚSparseNodeVisitorr¶   r   rO   )r    r   rO   r#   r#   r$   r¶   n  s   
z"DanglingReferencesVisitor.__init__c                 C   s   d S rF   r#   )r    r?   r#   r#   r$   Úunknown_visits  s   z'DanglingReferencesVisitor.unknown_visitc           	      C   s"  |j s| d¡s
d S |d }| jj |¡}|d u r{| jD ]	}||ƒr% d S q|| jjv r:| jjjd|d  |d�}n| jjjd|d  |d�}| j |¡}t	j
|j|j|d�}z|d d }W n tyn   | j |¡}Y nw | |¡ | |¡ d S |d= ||d< | jj| j|d	� d
|_ d S )Nr   zBDuplicate target name, cannot be used as a unique reference: "%s".rX   zUnknown target name: "%s".r.   r   r   r	   rK   r/   )r<   r   r   rM   r1   rO   r3   r4   r5   r   r6   r7   r~   r8   r9   r   rQ   )	r    r?   r   r!   rT   r@   rA   rC   rD   r#   r#   r$   Úvisit_referencev  sF   
ÿÿþ
þ
ÿÿ

z)DanglingReferencesVisitor.visit_referenceN)r'   r(   r)   r¶   rÒ   rÓ   Úvisit_footnote_referenceÚvisit_citation_referencer#   r#   r#   r$   rÍ   l  s
    !rÍ   )r*   Ú__docformat__ÚsysÚreÚdocutilsr   r   Údocutils.transformsr   r   r   r,   rE   rd   re   rg   Ú	Exceptionr�   r�   r³   rÌ   rÑ   rÍ   r#   r#   r#   r$   Ú<module>   s&   GB 3$( ]}S%