B
    ç<[àŽ  ã               @   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.
ZreStructuredTexté    N)ÚnodesÚutils)ÚTransformErrorÚ	Transformc               @   s   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   sx  xp| j  tj¡D ]\}t|jtjƒs| d¡s| d¡s| d¡rFqt|ƒdksZt	dƒ‚|j
dd}|d k	rt|tjƒs†t|tjƒr’t|tjƒr|d  |d ¡ |d	  |d	 ¡ t|d
ƒsÆi |_t|dƒsÖi |_x&|d D ]}|| j j|< ||j|< qàW x|d	 D ]}||j|< qW |j t|d
i ƒ¡ |j t|di ƒ¡ |d d |d< g |d< g |d	< | j  |¡ qW d S )NÚrefidÚrefuriÚrefnamer   z&error: block-level target has childrenT)ZascendÚ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)Úselfr   r   ÚidÚname© r   ú=lib/python3.7/site-packages/docutils/transforms/references.pyÚapply*   s<    


zPropagateTargets.applyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údefault_priorityr    r   r   r   r   r      s   r   c               @   s   e Zd ZdZdZdd„ ZdS )Ú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   sd  g }g }x*| j  tj¡D ]}| d¡r| |¡ qW x*| j  tj¡D ]}| d¡rD| |¡ qDW t|ƒt|ƒkrà| j j 	dt|ƒt|ƒf ¡}| j  
|¡}x@|D ]8}tj|j|j|d}| j  
|¡}| |¡ | |¡ q W d S x~t||ƒD ]p\}}	d|	_x`|	 d¡r|	d |d< d|_P qü|	d s:| j j|	d  }	qü|	d d |d< | j  |¡ P qüW qìW d S )	NÚ	anonymousz]Anonymous hyperlink mismatch: %s references but %s targets.
See "backrefs" attribute for IDs.)r   é   r   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   Zanonymous_refsZanonymous_targetsÚnodeÚmsgÚmsgidÚrefÚprbÚprbidr   r   r   r   r    r   sD    





zAnonymousHyperlinks.applyN)r!   r"   r#   r$   r%   r    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   s0   x*| j jD ]}|js|  |¡ |  |¡ q
W d S )N)r   Zindirect_targetsr5   Úresolve_indirect_targetÚresolve_indirect_references)r   r   r   r   r   r    Ð   s    
zIndirectHyperlinks.applyc             C   sN  |  d¡}|d kr|d }n>| jj  |¡}|sZx&| jjjD ]}||ƒr:P q:W |  |¡ d S | jj| }|j|d t|t	j
ƒrº|jsº| d¡rºt|dƒr¦|  |¡ d S d|_|  |¡ |`| d¡rà|d |d< d|krÞ|d= nT| d¡r|d |d< | j |¡ n.|d r&||d< | j |¡ n|  |¡ d S |d k	rD|d= d|_d S )Nr	   r   )r   Úmultiply_indirectr(   r   r
   )r*   r   ÚnameidsÚtransformerÚunknown_reference_resolversÚnonexistent_indirect_targetr
   Únote_referenced_byr   r   r   r5   r   Úcircular_indirect_referencer?   r=   r   )r   r   r	   Zreftarget_idÚresolver_functionZ	reftargetr   r   r   r=   Ö   sH    









z*IndirectHyperlinks.resolve_indirect_targetc             C   s.   |d | j jkr|  |d¡ n|  |d¡ d S )Nr	   z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)r   r@   Úindirect_target_error)r   r   r   r   r   rC     s    z.IndirectHyperlinks.nonexistent_indirect_targetc             C   s   |   |d¡ d S )Nzforming a circular reference)rG   )r   r   r   r   r   rE   
  s    z.IndirectHyperlinks.circular_indirect_referencec             C   s
  d}g }|d r d|d d  }x&|d D ]}|  | jj |g ¡¡ q*W x&|d D ]}|  | jj |g ¡¡ qRW |d rŒ|d|d d  7 }| jjjd||d |f |d	}| j |¡}xFt 	|¡D ]8}	t
j|	j|	j|d
}
| j |
¡}| |¡ |	 |
¡ qÄW d|_d S )NÚ r   z"%s" r   r
   z	(id="%s")z7Indirect hyperlink target %s refers to target "%s", %s.r	   )Ú	base_node)r   r(   )r   r   Úrefnamesr*   Úrefidsr,   r-   r.   r   Zuniqr   r/   r0   r1   r2   r5   )r   r   ZexplanationÚnamingÚreflistr   r   r7   r8   r9   r:   r;   r   r   r   rG     s*    
z(IndirectHyperlinks.indirect_target_errorc       	      C   s:  |  d¡rd}| jj}n|  d¡r,d}d }nd S || }x||d D ]p}| jj |g ¡}|rf|j|d xJ|D ]B}|jrxql|d= |||< |r’||ƒ d|_t|tj	ƒrl|  
|¡ qlW qBW x~|d D ]r}| jj |g ¡}|rä|j|d xL|D ]D}|jröqê|d= |||< |r||ƒ d|_t|tj	ƒrê|  
|¡ qêW qÀW d S )	Nr   r   r   )r   r	   r(   r
   )r   )r   r   r   rJ   r*   rD   r5   r   r   r   r>   rK   )	r   r   ZattnameZcall_methodZattvalr   rM   r9   r   r   r   r   r>   $  sH    




z.IndirectHyperlinks.resolve_indirect_referencesN)r!   r"   r#   r$   r%   r    r=   rC   rE   rG   r>   r   r   r   r   r<   š   s   2-r<   c               @   s   e Zd ZdZdZdd„ ZdS )Ú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Š   x„| j  tj¡D ]r}| d¡r|d }xZ|d D ]N}| j j |g ¡}|rT|j|d x(|D ] }|jrfqZ|d= ||d< d|_qZW q0W qW d S )Nr   r   )r   r	   r(   )	r   r   r   r   r   rJ   r*   rD   r5   )r   r   r   r   rM   r9   r   r   r   r    `  s    

zExternalTargets.applyN)r!   r"   r#   r$   r%   r    r   r   r   r   rN   L  s   rN   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚInternalTargetsi”  c             C   s:   x4| j  tj¡D ]"}| d¡s| d¡s|  |¡ qW d S )Nr   r   )r   r   r   r   r   Úresolve_reference_ids)r   r   r   r   r   r    t  s    zInternalTargets.applyc             C   sr   xl|d D ]`}| j j |¡}| j j |g ¡}|r<|j|d x,|D ]$}|jrNqB|r`|d= ||d< d|_qBW q
W 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   r@   r*   rJ   rD   r5   )r   r   r   r   rM   r9   r   r   r   rP   y  s    
z%InternalTargets.resolve_reference_idsN)r!   r"   r#   r%   r    rP   r   r   r   r   rO   p  s   rO   c            
   @   s`   e Zd ZdZdZdZdddddd	d
dddg
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 )N)Úautofootnote_labelsr   Zautofootnote_startÚnumber_footnotesÚnumber_footnote_referencesÚsymbolize_footnotesÚresolve_footnotes_and_citations)r   Ústartnumr   r   r   r    ë  s    
zFootnotes.applyc             C   s,  x$| j jD ]}x"t|ƒ}|d7 }|| j jkrP qW | dt d|¡¡ x |d D ]”}xŽ| j j |g ¡D ]z}|t 	|¡7 }| 
d¡ t|d ƒt|d ƒ  krªdks°n t‚|d d |d< | |d d ¡ | j  |¡ d|_qjW qTW |d s|d s|d  |¡ | j  ||¡ | j |¡ qW |S )	z«
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        r(   r   rH   r   r	   r
   r   Zdupnames)r   ZautofootnotesÚstrr@   Úinsertr   ÚlabelÚfootnote_refsr*   ÚTextÚdelattrr   r   r1   r   r5   r+   Únote_explicit_targetrV   )r   r[   Úfootnoter^   r   r9   r   r   r   rW   ó  s*    
*zFootnotes.number_footnotesc          
   C   sN  d}xB| j jD ]4}|js| d¡r(qy| j| }W nž tk
rÔ   | j jjdt| jƒ |d}| j  	|¡}x^| j j|d… D ]J}|js€| d¡r–q€t
j|j|j|d}| j  	|¡}| |¡ | |¡ q€W P Y nX |t
 |¡7 }| j j| }	| j j|	 }
|	|d< | j  |¡ t|d ƒd	ks&t‚|
 |d d ¡ d	|_|d	7 }qW dS )
z3Assign numbers to autonumbered footnote references.r   r   zUToo many autonumbered footnote references: only %s corresponding footnotes available.)rI   Nr	   )r   r
   r(   )r   Zautofootnote_refsr5   r   rV   Ú
IndexErrorr,   r-   r   r.   r   r/   r0   r1   r2   r`   r@   r
   r   r   )r   r[   Úir9   r^   r7   r8   r:   r;   r   rc   r   r   r   rX     s:    
z$Footnotes.number_footnote_referencesc          
   C   s¨  g }xt| j jD ]h}t| j jt| jƒƒ\}}| j| |d  }| |¡ | dt 	d|¡¡ | j  jd7  _| j  
|¡ qW d}x"| j jD ]}y|t || ¡7 }W n  tk
rF   | j jjdt|ƒ |d}| j  
|¡}	x`| j j|d… D ]L}|jsð| d¡rqðtj|j|j|	d}
| j  
|
¡}| |¡ | |
¡ qðW P Y nX | j j| }t|d	 ƒdksjt‚|d	 d |d< | j  |¡ | |d	 d ¡ |d7 }qŠW dS )
z<Add symbols indexes to "[*]"-style footnotes and references.r(   r   rH   zOToo many symbol footnote references: only %s corresponding footnotes available.)rI   Nr   )r   r
   )r   Zsymbol_footnotesÚdivmodZsymbol_footnote_startr   Úsymbolsr+   r]   r   r^   r.   Zsymbol_footnote_refsr`   rd   r,   r-   r5   r   r/   r0   r1   r2   r   r   )r   Úlabelsrc   ZrepsÚindexZ	labeltextre   r9   r7   r8   r:   r;   r   r   r   rY   1  sD    

zFootnotes.symbolize_footnotesc             C   s”   xF| j jD ]:}x4|d D ](}|| j jkr| j j| }|  ||¡ qW q
W xF| j jD ]:}x4|d D ](}|| j jkr`| j j| }|  ||¡ q`W qRW dS )za
        Link manually-labeled footnotes and citations to/from their
        references.
        r   N)r   Z	footnotesr_   Úresolve_referencesZ	citationsZcitation_refs)r   rc   r^   rM   Zcitationr   r   r   rZ   V  s    z)Footnotes.resolve_footnotes_and_citationsc             C   s~   t |d ƒdkst‚|d d }xR|D ]J}|jr2q&| d¡ ||d< t |d ƒdksXt‚| |d d ¡ d|_q&W d|_d S )Nr
   r(   r   r	   r   )r   r   r5   ra   r1   )r   ZnoterM   r   r9   r   r   r   rj   f  s    


zFootnotes.resolve_references)r!   r"   r#   r$   r%   rV   rg   r    rW   rX   rY   rZ   rj   r   r   r   r   rQ   ˜  s&   ;!%rQ   c               @   s   e Zd ZdS )Ú#CircularSubstitutionDefinitionErrorN)r!   r"   r#   r   r   r   r   rk   t  s    rk   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}| j  tj¡}i }xî|D ]ä}|d }d }||krJ|}n| ¡ }||krb|| }|d krÂ| j jjd| |d}	| j  	|	¡}
tj
|j|j|
d}| j  	|¡}|	 |¡ | |¡ q*|| }|j}| |¡}d|jksðd|jkr0|dkr0t||d  tjƒr0| ||d  ||d   ¡ ¡ d	|jksHd|jkrt|ƒ|d krt||d  tjƒr| ||d  ||d   ¡ ¡ | ¡ }ydx^| tj¡D ]N}||d  ¡  }|| |g ¡krÔt‚n ||  |¡ ||d
< | |¡ q¨W W nÐ tk
rÌ   |j}t|tjƒrR| j jjdt |j|j¡|j|d}	| |	¡ nv|}x| d
¡rp|d
 }qXW | j jjd| |d}	| j  	|	¡}
tj
|j|j|
d}| j  	|¡}|	 |¡ | |¡ Y q*X | |j¡ x4|jD ]*}t|tj ƒrâd|krâ| j  !|¡ qâW q*W d S )Nr	   z(Undefined substitution referenced: "%s".)rI   )r   ZltrimZtrimr   r(   Zrtrimz
ref-originz*Circular substitution definition detected:)ÚlinerI   z2Circular substitution definition referenced: "%s".)"r   Zsubstitution_defsZsubstitution_namesr   r   Zsubstitution_referenceÚlowerr,   r-   r.   r/   r0   r1   r2   r   ri   Z
attributesr   r`   ÚreplaceÚrstripr   ÚlstripÚdeepcopyÚ
setdefaultrk   r+   Zsubstitution_definitionZliteral_blockrn   r   ZchildrenZReferentialZnote_refname)r   ZdefsZnormedZ
subreflistÚnestedr9   r	   ÚkeyZnormed_namer7   r8   r:   r;   Zsubdefr   ri   Zsubdef_copyZ
nested_refZnested_nameZ
ref_originr6   r   r   r   r    —  s’    





zSubstitutions.applyN)r!   r"   r#   r$   r%   r    r   r   r   r   rl   w  s   rl   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__Zdetailsr*   Úclasses)r   r   rx   r   r   r   rz   ú  s    zTargetNotes.__init__c       	      C   s
  i }g }xŒ| j  tj¡D ]z}| d¡s(q|d }g }x"|D ]}| | j j |g ¡¡ q:W |s^q|  |d ||¡}|d |kr|||d < | 	|¡ qW xb| j  tj
¡D ]P}| d¡s¶q¦| d¡r¦|  |d |g|¡}|d |kr¦|||d < | 	|¡ q¦W | j |¡ d S )Nr   r   r'   )r   r   r   r   r   r   rJ   r*   Úmake_target_footnoter+   r)   rx   r2   )	r   ÚnotesZnodelistr   r   Úrefsr   rc   r9   r   r   r   r    ÿ  s4    



zTargetNotes.applyc             C   s^  ||kr2|| }t |d ƒdks$t‚|d d }nlt ¡ }| j |¡}d| }d|d< |g|d< t ¡ }|tjd||d7 }||7 }| j |¡ | j 	||¡ xº|D ]²}t
|tjƒr¶q¤tj|dd}	|	d	  | j7  < | j |	¡ | j |	¡ |j |¡d }
|	g}t | jj¡sH| jr6| dtjd
| jd¡ n| dt d
¡¡ |j |
|¡ q¤W |S )Nr   r(   r   zTARGET_NOTE: ÚautorH   )r   )r	   r   r{   ú )ÚtextZClasses)r   r   r   rc   r   r.   Z	paragraphr)   Znote_autofootnoterb   r   r   Zfootnote_referencer{   Znote_autofootnote_refZnote_footnote_refr   ri   r   Zget_trim_footnote_ref_spaceZsettingsr]   Zinliner`   )r   r   r~   r}   rc   Zfootnote_nameZfootnote_idZfootnote_paragraphr9   Zrefnoderi   rM   r   r   r   r|     s:    

z TargetNotes.make_target_footnoteN)r!   r"   r#   r$   r%   rz   r    r|   r   r   r   r   rw   î  s
   rw   c               @   s   e Zd ZdZdZdd„ ZdS )ÚDanglingReferencesze
    Check for dangling references (incl. footnote & citation) and for
    unreferenced targets.
    iR  c             C   s–   t | j| jjjƒ}| j |¡ xr| j tj¡D ]`}|js.| 	d¡rDq.|d rZ|d d }n|d rp|d d }n|d }| jj
jd| |d q.W d S )Nr'   r   r   r
   r   z(Hyperlink target "%s" is not referenced.)rI   )ÚDanglingReferencesVisitorr   rA   rB   Úwalkr   r   r   r4   r*   r,   Úinfo)r   Zvisitorr   rL   r   r   r   r    J  s     
zDanglingReferences.applyN)r!   r"   r#   r$   r%   r    r   r   r   r   r‚   A  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 )N)r   ÚSparseNodeVisitorrz   r   rB   )r   r   rB   r   r   r   rz   h  s    z"DanglingReferencesVisitor.__init__c             C   s   d S )Nr   )r   r6   r   r   r   Úunknown_visitm  s    z'DanglingReferencesVisitor.unknown_visitc       	      C   s"  |j s| d¡sd S |d }| jj |¡}|d kröxê| jD ]}||ƒr:P q:W || jjkrt| jjjd|d  |d}n| jjjd|d  |d}| j |¡}t	j
|j|j|d}y|d d }W n  tk
rÞ   | j |¡}Y nX | |¡ | |¡ n(|d= ||d< | jj| j|d	 d
|_ d S )Nr	   zBDuplicate target name, cannot be used as a unique reference: "%s".)rI   zUnknown target name: "%s".)r   r
   r   r   )r   r(   )r5   r   r   r@   r*   rB   r,   r-   r.   r   r/   r0   rd   r1   r2   r
   rD   )	r   r6   r	   r   rF   r7   r8   r:   r;   r   r   r   Úvisit_referencep  s8    

z)DanglingReferencesVisitor.visit_referenceN)r!   r"   r#   rz   r‡   rˆ   Zvisit_footnote_referenceZvisit_citation_referencer   r   r   r   rƒ   f  s   !rƒ   )r$   Z__docformat__ÚsysÚreZdocutilsr   r   Zdocutils.transformsr   r   r   r&   r<   rN   rO   rQ   Ú	Exceptionrk   rl   rw   r‚   r†   rƒ   r   r   r   r   Ú<module>   s$   GB 3$( ]wS%