ó
ÒŸ8Qc           @   sI  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	 d e	 f d „  ƒ  YZ
 d e	 f d	 „  ƒ  YZ d
 e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   s&   
Transforms for resolving references.
t   reStructuredTextiÿÿÿÿN(   t   nodest   utils(   t   TransformErrort	   Transformt   PropagateTargetsc           B   s   e  Z d  Z d Z d „  Z RS(   s}  
    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   s  xþ|  j  j t j ƒ D]ç} t | j t j ƒ s | j d ƒ s | j d ƒ s | j d ƒ rd q n  t | ƒ d k s‚ t	 d ƒ ‚ | j
 d t ƒ } | d  k	 r t | t j ƒ rÆ t | t j ƒ sØ t | t j ƒ r | d j | d ƒ | d j | d ƒ t | d	 ƒ si  | _ n  t | d
 ƒ s8i  | _ n  x/ | d D]# } | |  j  j | <| | j | <qCWx | d D] } | | j | <quW| j j t | d	 i  ƒ ƒ | j j t | d
 i  ƒ ƒ | d d | d <g  | d <g  | d <|  j  j | ƒ q q Wd  S(   Nt   refidt   refurit   refnamei    s&   error: block-level target has childrent   ascendt   idst   namest   expect_referenced_by_namet   expect_referenced_by_id(   t   documentt   traverseR   t   targett
   isinstancet   parentt   TextElementt   hasattrt   lent   AssertionErrort	   next_nodet   Truet   Nonet	   Invisiblet
   Targetablet   extendR   R   R
   t   updatet   getattrt
   note_refid(   t   selfR   R   t   idt   name(    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyt   apply*   s<    		

(   t   __name__t
   __module__t   __doc__t   default_priorityR#   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR      s   t   AnonymousHyperlinksc           B   s   e  Z d  Z d Z d „  Z RS(   s¥  
    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   sé  g  } g  } x< |  j  j t j ƒ D]% } | j d ƒ r" | j | ƒ q" q" Wx< |  j  j t j ƒ D]% } | j d ƒ ra | j | ƒ qa qa Wt | ƒ t | ƒ k r>|  j  j j	 d t | ƒ t | ƒ f ƒ } |  j  j
 | ƒ } xX | D]P } t j | j | j d | ƒ} |  j  j
 | ƒ } | j | ƒ | j | ƒ qæ Wd  Sx¤ t | | ƒ D]“ \ } }	 d |	 _ x{ t rà|	 j d ƒ r–|	 d | d <d | _ Pqf|	 d sº|  j  j |	 d }	 qfn  |	 d d | d <|  j  j | ƒ PqfWqNWd  S(   Nt	   anonymouss]   Anonymous hyperlink mismatch: %s references but %s targets.
See "backrefs" attribute for IDs.R   i   R   R
   i    (   R   R   R   t	   referencet   gett   appendR   R   t   reportert   errort   set_idt   problematict	   rawsourcet   add_backreft   replace_selft   zipt
   referencedR   R   t   resolvedR
   R   (
   R    t   anonymous_refst   anonymous_targetst   nodet   msgt   msgidt   reft   prbt   prbidR   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   r   sD    				
(   R$   R%   R&   R'   R#   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR(   X   s   t   IndirectHyperlinksc           B   sJ   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sN  
    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   sA   x: |  j  j D], } | j s, |  j | ƒ n  |  j | ƒ q Wd  S(   N(   R   t   indirect_targetsR6   t   resolve_indirect_targett   resolve_indirect_references(   R    R   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   Ð   s    	c         C   sÉ  | j  d ƒ } | d  k r( | d } nV |  j j j  | ƒ } | s~ x4 |  j j j D] } | | ƒ rS PqS qS W|  j | ƒ d  S|  j j | } | j d | ƒ t	 | t
 j ƒ r| j r| j d ƒ rt | d ƒ ré |  j | ƒ d  Sd | _ |  j | ƒ | ` n  | j d ƒ r>| d | d <d | k r¦| d =q¦nh | j d ƒ rn| d | d <|  j j | ƒ n8 | d r•| | d <|  j j | ƒ n |  j | ƒ d  S| d  k	 r¼| d =n  d | _ d  S(   NR   R   R!   t   multiply_indirecti   R   R
   (   R+   R   R   t   nameidst   transformert   unknown_reference_resolverst   nonexistent_indirect_targetR
   t   note_referenced_byR   R   R   R6   R   t   circular_indirect_referenceRC   RA   R   (   R    R   R   t   reftarget_idt   resolver_functiont	   reftarget(    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRA   Ö   sH    		


c         C   s=   | d |  j  j k r) |  j | d ƒ n |  j | d ƒ d  S(   NR   s>   which is a duplicate, and cannot be used as a unique references   which does not exist(   R   RD   t   indirect_target_error(   R    R   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRG     s    c         C   s   |  j  | d ƒ d  S(   Ns   forming a circular reference(   RM   (   R    R   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRI   
  s    c         C   se  d } g  } | d r+ d | d d } n  x1 | d D]% } | j  |  j j j | g  ƒ ƒ q6 Wx1 | d D]% } | j  |  j j j | g  ƒ ƒ qj W| d r¶ | d | d d 7} n  |  j j j d | | d | f d	 | ƒ} |  j j | ƒ } xa t j	 | ƒ D]P }	 t
 j |	 j |	 j d
 | ƒ}
 |  j j |
 ƒ } | j | ƒ |	 j |
 ƒ qWd | _ d  S(   Nt    R   s   "%s" i    R
   s	   (id="%s")s7   Indirect hyperlink target %s refers to target "%s", %s.R   t	   base_nodeR   i   (   R   R   t   refnamesR+   t   refidsR-   R.   R/   R   t   uniqR   R0   R1   R2   R3   R6   (   R    R   t   explanationt   namingt   reflistR"   R!   R:   R;   R<   R=   R>   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRM     s*    
##
c   	      C   s¾  | j  d ƒ r$ d } |  j j } n" | j  d ƒ rB d } d  } n d  S| | } x² | d D]¦ } |  j j j | g  ƒ } | r’ | j d | ƒ n  xl | D]d } | j r® q™ n  | d =| | | <| rÒ | | ƒ n  d | _ t | t	 j
 ƒ r™ |  j | ƒ q™ q™ Wq[ Wx² | d D]¦ } |  j j j | g  ƒ } | rG| j d | ƒ n  xl | D]d } | j rcqNn  | d =| | | <| r‡| | ƒ n  d | _ t | t	 j
 ƒ rN|  j | ƒ qNqNWqWd  S(	   NR   R   R   R"   R   i   R
   R!   (   R   R   R   R   RP   R+   RH   R6   R   R   R   RB   RQ   (	   R    R   t   attnamet   call_methodt   attvalR"   RU   R<   R!   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRB   $  sH    	
	
		
	(
   R$   R%   R&   R'   R#   RA   RG   RI   RM   RB   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR?   š   s   2		-			t   ExternalTargetsc           B   s   e  Z d  Z d Z d „  Z RS(   s¸  
    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  j t j ƒ D]¢ } | j d ƒ r | d } x€ | d D]q } |  j  j j | g  ƒ } | rw | j d | ƒ n  x7 | D]/ } | j r“ q~ n  | d =| | d <d | _ q~ Wq@ Wq q Wd  S(   NR   R   R"   R   i   (	   R   R   R   R   R   RP   R+   RH   R6   (   R    R   R   R"   RU   R<   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   `  s    
	
(   R$   R%   R&   R'   R#   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRY   L  s   t   InternalTargetsc           B   s    e  Z d  Z d „  Z d „  Z RS(   i”  c         C   sT   xM |  j  j t j ƒ D]6 } | j d ƒ r | j d ƒ r |  j | ƒ q q Wd  S(   NR   R   (   R   R   R   R   R   t   resolve_reference_ids(   R    R   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   t  s     c         C   s¢   x› | d D] } |  j  j j | ƒ } |  j  j j | g  ƒ } | rW | j d | ƒ n  x@ | D]8 } | j rs q^ n  | r | d =| | d <n  d | _ q^ Wq Wd S(   sº  
        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   i   N(   R   RD   R+   RP   RH   R6   (   R    R   R"   R   RU   R<   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR[   y  s    	(   R$   R%   R'   R#   R[   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRZ   p  s   	t	   Footnotesc        
   B   st   e  Z d  Z d Z d Z d d d d d d d d	 d
 d g
 Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   sè  
    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  t   *u   â€ u   â€¡u   Â§u   Â¶t   #u   â™ u   â™¥u   â™¦u   â™£c         C   sO   g  |  _  |  j j } |  j | ƒ |  j _ |  j | ƒ |  j ƒ  |  j ƒ  d  S(   N(   t   autofootnote_labelsR   t   autofootnote_startt   number_footnotest   number_footnote_referencest   symbolize_footnotest   resolve_footnotes_and_citations(   R    t   startnum(    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   ë  s    	
c         C   s‹  x„|  j  j D]v} x6 t rK t | ƒ } | d 7} | |  j  j k r Pq q W| j d t j d | ƒ ƒ xË | d D]¿ } x¶ |  j  j j	 | g  ƒ D]œ } | t j
 | ƒ 7} | j d ƒ t | d ƒ t | d ƒ k oã d k n sî t ‚ | d d | d <| j | d d ƒ |  j  j | ƒ d | _ q’ Wqs W| d r | d r | d j | ƒ |  j  j | | ƒ |  j j | ƒ q q W| S(	   s«   
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        i   i    RN   R   R   R
   R   t   dupnames(   R   t   autofootnotesR   t   strRD   t   insertR   t   labelt   footnote_refsR+   t   Textt   delattrR   R   R2   R   R6   R,   t   note_explicit_targetR_   (   R    Re   t   footnoteRj   R"   R<   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRa   ó  s*    	
6c         C   s³  d } x¦|  j  j D]˜} | j s | j d ƒ r7 q n  y |  j | } WnÏ t k
 r|  j  j j d t |  j ƒ d | ƒ} |  j  j	 | ƒ } x€ |  j  j | D]n } | j s£ | j d ƒ rÇ q£ n  t
 j | j | j d | ƒ} |  j  j	 | ƒ } | j | ƒ | j | ƒ q£ WPn X| t
 j | ƒ 7} |  j  j | }	 |  j  j |	 }
 |	 | d <|  j  j | ƒ t | d ƒ d k sƒt ‚ |
 j | d d ƒ d | _ | d 7} q Wd S(	   s3   Assign numbers to autonumbered footnote references.i    R   sU   Too many autonumbered footnote references: only %s corresponding footnotes available.RO   R   R
   i   N(   R   t   autofootnote_refsR6   R   R_   t
   IndexErrorR-   R.   R   R/   R   R0   R1   R2   R3   Rl   RD   R
   R   R   (   R    Re   t   iR<   Rj   R:   R;   R=   R>   R!   Ro   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRb     s:    
	c         C   s  g  } x˜ |  j  j D]Š } t |  j  j t |  j ƒ ƒ \ } } |  j | | d } | j | ƒ | j d t j	 d | ƒ ƒ |  j  j d 7_ |  j  j
 | ƒ q Wd } xk|  j  j D]]} y | t j | | ƒ 7} WnÌ t k
 r£|  j  j j d t | ƒ d | ƒ} |  j  j
 | ƒ }	 x€ |  j  j | D]n } | j s-| j d ƒ rQq-n  t j | j | j d |	 ƒ}
 |  j  j
 |
 ƒ } | j | ƒ | j |
 ƒ q-WPn X|  j  j | } t | d ƒ d k sÐt ‚ | d d | d <|  j  j | ƒ | j | d d ƒ | d 7} q´ Wd S(	   s<   Add symbols indexes to "[*]"-style footnotes and references.i   i    RN   sO   Too many symbol footnote references: only %s corresponding footnotes available.RO   R   R
   N(   R   t   symbol_footnotest   divmodt   symbol_footnote_startR   t   symbolsR,   Ri   R   Rj   R/   t   symbol_footnote_refsRl   Rq   R-   R.   R6   R   R0   R1   R2   R3   R   R   (   R    t   labelsRo   t   repst   indext	   labeltextRr   R<   R:   R;   R=   R>   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRc   1  sD    	c         C   sÆ   x^ |  j  j D]P } xG | d D]; } | |  j  j k r |  j  j | } |  j | | ƒ q q Wq Wx^ |  j  j D]P } xG | d D]; } | |  j  j k r |  j  j | } |  j | | ƒ q q Wqn Wd S(   sa   
        Link manually-labeled footnotes and citations to/from their
        references.
        R   N(   R   t	   footnotesRk   t   resolve_referencest	   citationst   citation_refs(   R    Ro   Rj   RU   t   citation(    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRd   V  s    c         C   s¨   t  | d ƒ d k s t ‚ | d d } xn | D]f } | j rF q1 n  | j d ƒ | | d <t  | d ƒ d k sy t ‚ | j | d d ƒ d | _ q1 Wd | _ d  S(   NR
   i   i    R   R   (   R   R   R6   Rm   R2   (   R    t   noteRU   R!   R<   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR}   f  s    	
N(   R$   R%   R&   R'   R   R_   Rv   R#   Ra   Rb   Rc   Rd   R}   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR\   ˜  s&   ;				!	%	t#   CircularSubstitutionDefinitionErrorc           B   s   e  Z RS(    (   R$   R%   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR‚   t  s    t   Substitutionsc           B   s   e  Z d  Z d Z d „  Z RS(   sD  
    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">
    iÜ   c         C   só  |  j  j } |  j  j } |  j  j t j ƒ } i  } x¹| D]±} | d } d  } | | k re | } n% | j ƒ  } | | k rŠ | | } n  | d  k r|  j  j j	 d | d | ƒ}	 |  j  j
 |	 ƒ }
 t j | j | j d |
 ƒ} |  j  j
 | ƒ } |	 j | ƒ | j | ƒ q: | | } | j } | j | ƒ } d | j k sTd | j k r¦| d k r¦t | | d t j ƒ r¦| j | | d | | d j ƒ  ƒ q¦n  d	 | j k sÄd | j k r t | ƒ | d k r t | | d t j ƒ r | j | | d | | d j ƒ  ƒ q n  | j ƒ  } yt xm | j t j ƒ D]Y } | | d j ƒ  } | | j | g  ƒ k r}t ‚ qB| | j | ƒ | j | ƒ qBWWnð t k
 r’| j } t | t j ƒ r|  j  j j	 d
 t j | j | j ƒ d | j d | ƒ}	 | j |	 ƒ që|  j  j j	 d | d | ƒ}	 |  j  j
 |	 ƒ }
 t j | j | j d |
 ƒ} |  j  j
 | ƒ } |	 j | ƒ | j | ƒ q: X| j | j ƒ xE | j D]: } t | t j  ƒ r­d | k rç|  j  j! | ƒ qçq­q­Wq: Wd  S(   NR   s(   Undefined substitution referenced: "%s".RO   R   t   ltrimt   trimi    i   t   rtrims*   Circular substitution definition detected:t   lines2   Circular substitution definition referenced: "%s".("   R   t   substitution_defst   substitution_namesR   R   t   substitution_referenceR   t   lowerR-   R.   R/   R0   R1   R2   R3   R   Rz   t
   attributesR   Rl   t   replacet   rstripR   t   lstript   deepcopyt
   setdefaultR‚   R,   t   substitution_definitiont   literal_blockR‡   t   childrent   Referentialt   note_refname(   R    t   defst   normedt
   subreflistt   nestedR<   R   t   keyt   normed_nameR:   R;   R=   R>   t   subdefR   Rz   t   subdef_copyt
   nested_reft   nested_nameR9   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   —  sŠ    
	
				(   R$   R%   R&   R'   R#   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyRƒ   w  s   t   TargetNotesc           B   s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   s‚   
    Creates a footnote for each external target in the text, and corresponding
    footnote references after each reference.
    i  c         C   s2   t  j |  | d | ƒ| j j d g  ƒ |  _ d  S(   Nt	   startnodet   class(   R   t   __init__t   detailsR+   t   classes(   R    R   R¢   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR¤   õ  s    c   	      C   sy  i  } g  } xÅ |  j  j t j ƒ D]® } | j d ƒ s= q" n  | d } g  } x- | D]% } | j |  j  j j | g  ƒ ƒ qT W| s‰ q" n  |  j | d | | ƒ } | d | k r" | | | d <| j	 | ƒ q" q" WxŽ |  j  j t j
 ƒ D]w } | j d ƒ sqê n  | j d ƒ rê |  j | d | g | ƒ } | d | k ra| | | d <| j	 | ƒ qaqê qê W|  j j | ƒ d  S(   NR   R   R)   (   R   R   R   R   R   R   RP   R+   t   make_target_footnoteR,   R*   R¢   R3   (	   R    t   notest   nodelistR   R   t   refsR"   Ro   R<   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   ú  s4    
#		c         C   sã  | | k rC | | } t  | d ƒ d k s2 t ‚ | d d } n” t j ƒ  } |  j j | ƒ } d | } d | d <| g | d <t j ƒ  } | t j d | d | ƒ7} | | 7} |  j j | ƒ |  j j	 | | ƒ x| D]ý } t
 | t j ƒ rü qÞ n  t j d | d d ƒ }	 |	 d	 c |  j 7<|  j j |	 ƒ |  j j |	 ƒ | j j | ƒ d }
 |	 g } t j |  j j ƒ sÈ|  j r¬| j d t j d
 d d |  j ƒ ƒ qÈ| j d t j d ƒ ƒ n  | j j |
 | ƒ qÞ W| S(   NR   i   i    s   TARGET_NOTE: t   autoRN   R   R   R¦   t   textt    t   Classes(   R   R   R   Ro   R   R/   t	   paragraphR*   t   note_autofootnoteRn   R   R   t   footnote_referenceR¦   t   note_autofootnote_reft   note_footnote_refR   Rz   R   t   get_trim_footnote_ref_spacet   settingsRi   t   inlineRl   (   R    R   Rª   R¨   Ro   t   footnote_namet   footnote_idt   footnote_paragraphR<   t   refnodeRz   RU   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR§     s:    



		((   R$   R%   R&   R'   R¤   R#   R§   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR¡   é  s
   		t   DanglingReferencesc           B   s   e  Z d  Z d Z d „  Z RS(   se   
    Check for dangling references (incl. footnote & citation) and for
    unreferenced targets.
    iR  c         C   sÍ   t  |  j |  j j j ƒ } |  j j | ƒ x› |  j j t j ƒ D]„ } | j sA | j	 d ƒ re qA n  | d r€ | d d } n% | d r› | d d } n
 | d } |  j j
 j d | d | ƒqA qA Wd  S(   NR)   R   i    R
   R   s(   Hyperlink target "%s" is not referenced.RO   (   t   DanglingReferencesVisitorR   RE   RF   t   walkR   R   R   R5   R+   R-   t   info(   R    t   visitorR   RT   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR#   E  s     	


(   R$   R%   R&   R'   R#   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR»   <  s   R¼   c           B   s-   e  Z d  „  Z d „  Z d „  Z e Z Z RS(   c         C   s)   t  j j |  | ƒ | |  _ | |  _ d  S(   N(   R   t   SparseNodeVisitorR¤   R   RF   (   R    R   RF   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR¤   c  s    	c         C   s   d  S(   N(    (   R    R9   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyt   unknown_visith  s    c   	      C   s^  | j  s | j d ƒ r d  S| d } |  j j j | ƒ } | d  k r&x|  j D] } | | ƒ rR PqR qR W| |  j j k r¤ |  j j j d | d d | ƒ} n# |  j j j d | d d | ƒ} |  j j	 | ƒ } t
 j | j | j d | ƒ} |  j j	 | ƒ } | j | ƒ | j | ƒ n4 | d =| | d <|  j j | j d | ƒ d | _  d  S(   NR   sB   Duplicate target name, cannot be used as a unique reference: "%s".RO   s   Unknown target name: "%s".R   R!   i   (   R6   R   R   RD   R+   R   RF   R-   R.   R/   R   R0   R1   R2   R3   R
   RH   (	   R    R9   R   R!   RK   R:   R;   R=   R>   (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyt   visit_referencek  s2    
	
(   R$   R%   R¤   RÁ   RÂ   t   visit_footnote_referencet   visit_citation_reference(    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyR¼   a  s   			(   R&   t   __docformat__t   syst   ret   docutilsR   R   t   docutils.transformsR   R   R   R(   R?   RY   RZ   R\   t	   ExceptionR‚   Rƒ   R¡   R»   RÀ   R¼   (    (    (    sB   /usr/lib/python2.7/dist-packages/docutils/transforms/references.pyt   <module>   s    GB²$(ÜrS%