ó
öÀ„\c           @   s†  d  Z  d d l Z d d l m Z m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z m Z m Z e rõ d d
 l m Z m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z n  i
 e j  d 6e j! d 6e j" d 6e j# d 6e j  d 6e j$ d 6e j# d 6e j# d 6e j  d 6e j" d 6Z% d e& f d „  ƒ  YZ' d e' f d „  ƒ  YZ( i  g  d „ Z) e j* d ƒ Z+ i  g  d „ Z, e j* d ƒ Z- e j* d  ƒ Z. i  g  d! „ Z/ e j* d" e j0 ƒ Z1 i  g  d# „ Z2 i  g  d$ „ Z3 i
 e' d% e j4 ƒ d& 6e( d' e5 ƒ d( 6e) d) 6e) d* 6e, d+ 6e, d, 6e/ d- 6e/ d. 6e2 d/ 6e3 d0 6Z6 d1 „  Z7 d S(2   s¾   
    sphinx.roles
    ~~~~~~~~~~~~

    Handlers for additional ReST roles.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   nodest   utils(   t	   iteritems(   t   addnodes(   t   SphinxError(   t   _(   t   ws_re(   t   split_explicit_titlet   process_index_entryt   set_role_source_info(   t   Anyt   Dictt   Listt   Tuplet   Type(   t   Inliner(   t   Sphinx(   t   BuildEnvironmentt   commandt   dfnt   kbdt
   mailheadert   makevart   manpaget   mimetypet	   newsgroupt   programt   regexpt   XRefRolec           B   sb   e  Z d  Z e j Z e j Z e	 e	 d d e	 d „ Z d „  Z i  g  d „ Z d „  Z d „  Z RS(   sA  
    A generic cross-referencing role.  To create a callable that can be used as
    a role function, create an instance of this class.

    The general features of this role are:

    * Automatic creation of a reference and a content node.
    * Optional separation of title and target with `title <target>`.
    * The implementation is a class rather than a function to make
      customization easier.

    Customization can be done in two ways:

    * Supplying constructor parameters:
      * `fix_parens` to normalize parentheses (strip from target, and add to
        title if configured)
      * `lowercase` to lowercase the target
      * `nodeclass` and `innernodeclass` select the node classes for
        the reference and the content node

    * Subclassing and overwriting `process_link()` and/or `result_nodes()`.
    c         C   sO   | |  _  | |  _ | |  _ | d  k	 r3 | |  _ n  | d  k	 rK | |  _ n  d  S(   N(   t
   fix_parenst	   lowercaset   warn_danglingt   Nonet	   nodeclasst   innernodeclass(   t   selfR   R   R!   R"   R   (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   __init__K   s    			c         C   sd   | s> | j  d ƒ r" | d  } n  | j j r> | d 7} q> n  | j  d ƒ rZ | d  } n  | | f S(   Ns   ()iþÿÿÿ(   t   endswitht   configt   add_function_parentheses(   R#   t   envt   has_explicit_titlet   titlet   target(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   _fix_parensV   s    c         C   s`  | j  j j } | sT | j j d ƒ } | s< | j j } n  | s` t d ƒ ‚ q` n | j ƒ  } d | k rˆ d | }	 }
 d |
 g } n1 | j	 d d ƒ \ }	 }
 d |	 d |	 |
 f g } | d d !d	 k r=t
 j | ƒ d } |  j r	|  j | t | d ƒ \ } } n  |  j | | d
 | ƒ} |  j | j  | | d t ƒSt | ƒ \ } } } t
 j | ƒ } t
 j | ƒ } |  j rˆ| j ƒ  } n  |  j r²|  j | | | | ƒ \ } } n  |  j | d |
 d |	 d | ƒ} t | | | ƒ |  j | | | | | ƒ \ } } | | d <| |  j | | d
 | ƒ7} | j | d <|  j | d <|  j | j  | | d t ƒS(   Nt   default_roles   cannot determine default role!t   :t    t   xrefi   s   %s-%si    t   !t   classest   is_reft   reftypet	   refdomaint   refexplicitt	   reftargett   refdoct   refwarn(   t   documentt   settingsR(   t	   temp_datat   getR&   R-   R   t   lowert   splitR   t   unescapeR   R,   t   FalseR"   t   result_nodesR   R   R!   R	   t   process_linkt   docnameR   t   True(   R#   t   typt   rawtextt   textt   linenot   inlinert   optionst   contentR(   t   domaint   roleR2   t   tgtt	   innernodeR)   R*   R+   t   refnode(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   __call__d   sL    	!			
c         C   s   | t  j d | ƒ f S(   së   Called after parsing title and target text, and creating the
        reference node (given in *refnode*).  This method can alter the
        reference node and must return a new (or the same) ``(title, target)``
        tuple.
        t    (   R   t   sub(   R#   R(   RQ   R)   R*   R+   (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyRC   š   s    c         C   s   | g g  f S(   s(  Called before returning the finished nodes.  *node* is the reference
        node if one was created (*is_ref* is then true), else the content node.
        This method can add other nodes and must return a ``(nodes, messages)``
        tuple (the usual return value of a role function).
        (    (   R#   R:   R(   t   nodeR3   (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyRB   £   s    N(   t   __name__t
   __module__t   __doc__R   t   pending_xrefR!   R    t   literalR"   RA   R    R$   R,   RR   RC   RB   (    (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyR   0   s   		
	5		t   AnyXRefRolec           B   s   e  Z d  „  Z RS(   c         C   s5   t  j |  | | | | | ƒ } | j j | j ƒ | S(   N(   R   RC   t
   attributest   updatet   ref_context(   R#   R(   RQ   R)   R*   R+   t   result(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyRC   ®   s    (   RV   RW   RC   (    (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyR[   ­   s   c      	   C   sŒ  | j  j j } |  s> | j d s( t ‚ | j d j ƒ  }  n |  j ƒ  }  t | ƒ \ } }	 }
 t j |	 ƒ }	 t j |
 ƒ }
 d | j	 d ƒ } t
 j ƒ  } t j d d d | g ƒ} | j  j | ƒ |  d k r!d t d ƒ |
 | d d f g | d	 <d } |
 j d
 ƒ } | d k r2|
 |  |
 | }
 } n  | sNd t j |	 ƒ }	 n  y t |
 ƒ } WnO t k
 r¯| j j d |
 d | ƒ} | j | | | ƒ } | g | g f SX| j  j j d | } t j |	 |	 ƒ } t j d d d t d | | d |  g ƒ} | | 7} | | | g g  f S|  d k rxd d |
 | d d f g | d	 <d } |
 j d
 ƒ } | d k r†|
 |  |
 | }
 } n  | s¢d t j |	 ƒ }	 n  y t |
 ƒ } WnO t k
 r| j j d |
 d | ƒ} | j | | | ƒ } | g | g f SX| j  j j | j | } t j |	 |	 ƒ } t j d d d t d | | d |  g ƒ} | | 7} | | | g g  f St d |  ƒ ‚ d S(   s9   Role for PEP/RFC references that generate an index entry.R-   s   index-%st   indexR/   t   idst   pept   singles$   Python Enhancement Proposals; PEP %st   entriest   #i    s   PEP s   invalid PEP number %st   lines   pep-%04dt   internalt   refuriR2   t   rfcs   RFC; RFC %ss   RFC s   invalid RFC number %ss   unknown role type: %sN(   R:   R;   R(   R<   t   AssertionErrorR>   R   R   R@   t   new_serialnoR   R`   R    R+   t   note_explicit_targetR   R    t   findt   intt
   ValueErrort   reportert   errort   problematict   pep_base_urlt   strongt	   referenceRA   t   rfc_base_urlt   rfc_url(   RF   RG   RH   RI   RJ   RK   RL   R(   R)   R*   R+   t   targetidt	   indexnodet
   targetnodet   anchort   anchorindext   pepnumt   msgt   prbt   reft   snt   rnt   rfcnum(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   indexmarkup_role·   sp    	
 	
s   (?<!&)&(?![&\s])c         C   s‰  | j  j j } |  s> | j d s( t ‚ | j d j ƒ  }  n |  j ƒ  }  t j | ƒ } |  d k rz | j d d ƒ } n  t	 j
 | ƒ } t j d | ƒ }	 xÍ t | ƒ D]¿ \ }
 } | j d d ƒ } |
 d k rt | ƒ d k r¨ t j | ƒ } |	 | 7}	 q¨ q¨ n  t j ƒ  } t j | d ƒ } | | 7} | d	 j d
 ƒ |	 | 7}	 t j | d ƒ } |	 | 7}	 q¨ W|	 d	 j |  ƒ |	 g g  f S(   NR-   t   menuselections   -->u   â€£RG   s   &&t   &i    R2   t   acceleratori   (   R:   R;   R(   R<   Rj   R>   R   R@   t   replacet   _amp_reR?   R    t   inlinet	   enumeratet   lent   Textt   append(   RF   RG   RH   RI   RJ   RK   RL   R(   t   spansRU   t   it   spant   textnodet
   accel_nodet   letter_node(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   menusel_roleü   s4    

s	   {([^}]+)}s   (\\*{|\\*})c         C   s¦  | j  j j } |  s> | j d s( t ‚ | j d j ƒ  }  n |  j ƒ  }  t j d |  j ƒ  d |  g ƒ } t t	 j
 t j | ƒ ƒ ƒ }	 d g }
 xÍ|	 D]Å} t	 j | ƒ } | rNt | ƒ d } | d d k r|
 d c d t | d d ƒ | d 7<q^| d d	 k r|
 d c d t | d ƒ 7<t |
 ƒ d k rd|
 d
 d	 k rd|
 d c d	 7<qK|
 j d	 ƒ |
 j d ƒ q^|
 d c d t | d ƒ 7<t |
 ƒ d k r,|
 d d	 k r,t |
 d ƒ d k r,|
 d r| t j |
 d |
 d ƒ 7} n  | t j |
 d |
 d ƒ 7} d g }
 q^|
 j d ƒ d j |
 ƒ g }
 q™ |
 d c | 7<q™ Wd j |
 ƒ r™d j |
 ƒ } | t j | | ƒ 7} n  | g g  f S(   NR-   RN   R2   R/   i   i   iÿÿÿÿs   \t   {iþÿÿÿi   i    t   }(   R:   R;   R(   R<   Rj   R>   R    RZ   t   listt	   parens_reR?   R   R@   t   matchRŒ   Rn   RŽ   R   t   emphasist   join(   RF   RG   RH   RI   RJ   RK   RL   R(   t   retnodet   partst   stackt   partt   matchedt   backslashes(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   emph_literal_role"  sB    !	-"8
!s	   \((.*)\)$c   
      C   s   t  j | ƒ } t j | ƒ } | d  k rF t j | | |  g g  f S| | j ƒ   j ƒ  } | j	 d ƒ }	 | j
 ƒ  } |	 | d <t j | | |  g g  f S(   Ni   t   explanation(   R   R@   t   _abbr_ret   searchR    R   t   abbreviationt   startt   stript   groupt   copy(
   RF   RG   RH   RI   RJ   RK   RL   t   mt   abbrt   expl(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt	   abbr_roleW  s    
c         C   s  | j  j j } d | j d ƒ } t j d d d | g ƒ}	 t | ƒ \ }
 } } t j | ƒ } t j | ƒ } |
 rˆ t	 | | ƒ } nJ d } | j
 d ƒ rº | d } | d } d } n  d | | | d  f g } t j ƒ  } | | d	 <t | | | ƒ t j | | ƒ } | |	 | g g  f S(
   Ns   index-%sR`   R/   Ra   R1   i   t   mainRc   Rd   (   R:   R;   R(   Rk   R    R+   R   R   R@   R   t
   startswithR    R   R`   R	   R   (   RF   RG   RH   RI   RJ   RK   RL   R(   Rx   Rz   R)   R*   R+   Rd   R°   Ry   R’   (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt
   index_roled  s&    

	
R!   t   downloadR   t   anyRb   Ri   t   guilabelR…   t   filet   sampR­   R`   c         C   s´   d d l  m } x[ t t ƒ D]M \ } } | j | | ƒ } | j | | i | g d 6ƒ } | j | | ƒ q Wx* t t ƒ D] \ } } | j | | ƒ q{ Wi d d 6t d 6t d 6S(   Niÿÿÿÿ(   t   rolesR2   t   builtint   versiont   parallel_read_safet   parallel_write_safe(	   t   docutils.parsers.rstR¸   R   t   generic_docrolest   GenericRolet
   CustomRolet   register_local_rolet   specific_docrolesRE   (   t   appR¸   t   rolenameR!   t   genericRN   t   func(    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   setup’  s    (8   RX   t   ret   docutilsR    R   t   sixR   t   sphinxR   t   sphinx.errorsR   t   sphinx.localeR   t   sphinx.utilR   t   sphinx.util.nodesR   R   R	   RA   t   typingR
   R   R   R   R   t   docutils.parsers.rst.statesR   t   sphinx.applicationR   t   sphinx.environmentR   t   literal_strongR›   RZ   t   literal_emphasisR   R¾   t   objectR   R[   R„   t   compileR‰   R•   t
   _litvar_reR™   R£   t   SR¥   R¯   R²   t   download_referenceRE   RÂ   RÇ   (    (    (    s+   lib/python2.7/site-packages/sphinx/roles.pyt   <module>
   s^   (








}
B"1
