ó
öÀ„\c           @@  se  d  Z  d d l m Z d d l 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 e rÏ d d	 l m Z m Z m Z m Z m Z m Z m Z d d
 l m Z d d l m Z n  e j e ƒ Z e j d e j ƒ Z  e  Z! d „  Z" d d „ Z# d „  Z$ e j% e j& e j' e	 j( f Z) d „  Z* d „  Z+ e j& e j' e j, f Z- e j. f Z/ e	 j0 f Z1 d „  Z2 d „  Z3 d d „ Z5 d „  Z6 d „  Z7 d „  Z8 d „  Z9 d „  Z: d d d d d d  g Z; d! „  Z< d" „  Z= d d# „ Z> d$ „  Z? d% „  Z@ e jA e jB e jC e j. e j, e jD e	 jE f ZF d& „  ZG d' „  ZH d( „  ZI eI e jJ _K d S()   sØ   
    sphinx.util.nodes
    ~~~~~~~~~~~~~~~~~

    Docutils node-related utility functions for Sphinx.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
i    (   t   absolute_importN(   t   nodes(   t	   text_type(   t   addnodes(   t   __(   t   logging(   t   Anyt   Callablet   Iterablet   Listt   Sett   Tuplet   Optional(   t   Builder(   t   Tagss   ^(.+?)\s*(?<!\x00)<(.*?)>$c         C@  s   d j  |  j |  j j ƒ S(   s—   
    return full module dotted path like: 'docutils.nodes.paragraph'

    :param nodes.Node node: target node
    :return: full module dotted path
    s   {}.{}(   t   formatt
   __module__t	   __class__t   __name__(   t   node(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   get_full_module_name$   s    iP   c         C@  sc   y |  j  ƒ  j ƒ  } Wn t k
 r5 t |  ƒ } n X| r_ t | ƒ | k r_ | |  d } n  | S(   s†  
    return DOM XML representation of the specified node like:
    '<paragraph translatable="False"><inline classes="versionmodified">New in version...'

    :param nodes.Node node: target node
    :param int length:
       length of return value to be striped. if false-value is specified, repr_domxml
       returns full of DOM XML representation.
    :return: DOM XML representation
    s   ...(   t   asdomt   toxmlt	   ExceptionR   t   len(   R   t   lengtht   text(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   repr_domxml/   s    c         C@  sˆ  t  |  t j ƒ rr |  j rr t j d t |  ƒ t |  ƒ ƒ |  j } | j	 |  _	 | j
 d |  _
 |  j ƒ  |  _ n  t  |  t j ƒ rÔ |  j	 d  k rÔ t j d t |  ƒ t |  ƒ ƒ |  j j	 |  j j
 |  _	 |  _
 n  t  |  t j ƒ r6|  j	 d  k r6t j d t |  ƒ t |  ƒ ƒ |  j j	 |  j j
 |  _	 |  _
 n  t  |  t j ƒ r¾t j d t |  ƒ t |  ƒ ƒ xT t |  j j t j ƒ ƒ D]4 } t j d t j | j ƒ  ƒ d |  j ƒ |  _ qƒWn  t  |  t j ƒ rñ|  j	 d  k rñt |  ƒ |  _	 n  |  j s|  j ƒ  |  _ n  |  j	 r"|  j r"d  St  |  t j t j
 t j t j f ƒ r„t j d t |  ƒ t |  ƒ ƒ t |  ƒ |  _	 d	 |  _
 d  Sd  S(
   Ns7   [i18n] PATCH: %r to have source, line and rawsource: %si   s)   [i18n] PATCH: %r to have source, line: %ss#   [i18n] PATCH: %r to have source: %ss&   [i18n] PATCH: %r to have rawsource: %ss	   \s*:\s*%st    s,   [i18n] PATCH: %r to have source and line: %si    (   t
   isinstanceR   t
   classifiert	   rawsourcet   loggert   debugR   R   t   parentt   sourcet   linet   astextt   imaget   Nonet   titlet   termt   reversedt   traverset   ret   subt   escapet   literal_blockt   find_source_nodet   rubrict
   field_name(   R   t   definition_list_itemR   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   apply_source_workaroundD   sJ    		!	"!	"	"!			c         C@  sF   t  |  t j ƒ r> t  |  j j d d  g ƒ d t j ƒ r> t St	 Sd  S(   NR   i    (
   R   R   t   pendingt   detailst   getR'   R   t   metat   Truet   False(   R   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   is_pending_meta„   s    (c         C@  s„  t  |  t j ƒ r t St  |  t j ƒ r8 d |  k r8 t St  |  t j ƒ r5|  j sv t	 j
 d t |  ƒ t |  ƒ ƒ t St  |  t ƒ r´ d |  k r´ t	 j
 d t |  ƒ t |  ƒ ƒ t S|  j d t ƒ sé t	 j
 d t |  ƒ t |  ƒ ƒ t St  |  t j ƒ r1|  j d d k r1t	 j
 d t |  ƒ t |  ƒ ƒ t St St  |  t j ƒ rZ|  j d ƒ rZt St  |  t j ƒ rpt St |  ƒ r€t St S(   Nt   translatables)   [i18n] SKIP %r because no node.source: %ssO   [i18n] SKIP %r because node is in IGNORED_NODES and no node['translatable']: %ss3   [i18n] SKIP %r because not node['translatable']: %si    t   orphans&   [i18n] SKIP %r because orphan node: %s(   R   R   R<   R9   R   t   InlineR:   t   TextElementR#   R    R!   R   R   t   IGNORED_NODESR7   R2   t   childrenR&   R8   R;   (   R   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   is_translatable   s:    				%	!c         c@  s9  x2|  j  t ƒ D]!} t | t j ƒ rP x | j ƒ  D] } | | f Vq5 Wq n  t | t ƒ r€ | j } | s| j ƒ  } qn t | t	 ƒ rÄ d | d } | j
 d ƒ r| d | d 7} qnY t | t ƒ rß | j } n> t | ƒ r| j d d j } n | j j d d ƒ j ƒ  } | r | | f Vq q Wd	 S(
   s3   Extract translatable messages from a document tree.s   .. image:: %st   urit   alts   
   :alt: %sR   i    s   
t    N(   R+   RB   R   R   R<   t   extract_original_messagest   LITERAL_TYPE_NODESR   R%   t   IMAGE_TYPE_NODESR7   t   META_TYPE_NODESt
   rawcontentR;   R6   t   replacet   strip(   t   doctreeR   t   msg(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   extract_messagesÅ   s(    	c         C@  s+   x$ t  |  ƒ D] } | j r | j Sq Wd  S(   N(   t   traverse_parentR#   R'   (   R   t   pnode(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyR0   á   s    	c         c@  s=   x6 |  r8 | d  k s$ t |  | ƒ r, |  Vn  |  j }  q Wd  S(   N(   R'   R   R"   (   R   t   cls(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyRP   é   s    	c         C@  s5   |  j  j |  ƒ } | d k r- |  j  | d Sd  Sd  S(   Ni    i   (   R"   t   indexR'   (   R   t   pos(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   get_prev_nodeñ   s    c         c@  sU   d „  } xE |  j  | ƒ D]4 } d | k r8 | d } n
 | d } | | f Vq Wd S(   s6   Traverse translatable index node from a document tree.c         S@  s%   t  |  t j ƒ o$ |  j d ƒ t k S(   Nt   inline(   R   R   RS   R7   R:   (   R   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   is_block_indexý   s    t   raw_entriest   entriesN(   R+   (   RM   RW   R   RY   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   traverse_translatable_indexú   s    	
c         C@  sm   |  j  j } |  j  j } g  |  j  _ d |  j  _ z |  j | d | d d ƒSWd | |  j  _ | |  j  _ Xd S(   sû   Version of state.nested_parse() that allows titles and does not require
    titles to have the same decoration as the calling document.

    This is useful when the parsed content comes from a completely different
    context, such as docstrings.
    i    t   match_titlesi   N(   t   memot   title_stylest   section_levelt   nested_parse(   t   statet   contentR   t   surrounding_title_stylest   surrounding_section_level(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   nested_parse_with_titles	  s    	c         C@  sj   |  j  ƒ  }  x$ |  j t j ƒ D] } d | d <q Wx* |  j t j ƒ D] } | j j | ƒ qF W|  j ƒ  S(   s&   Like node.astext(), but ignore images.R   RD   (   t   deepcopyR+   R   R&   t   rawR"   t   removeR%   (   R   t   imgRf   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   clean_astext  s    c         C@  sA   t  j |  ƒ } | r4 t | j d ƒ | j d ƒ f St |  |  f S(   s3   Split role content into title and target, if given.i   i   (   t   explicit_title_ret   matchR9   t   groupR:   (   R   Rk   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   split_explicit_title(  s    t   singlet   pairt   doublet   triplet   seet   seealsoc         C@  s¹  d d l  m } g  } |  j ƒ  }  |  } d } |  j d ƒ rV d } |  d j ƒ  }  n  x\| D]e } |  j | d ƒ r] |  t | ƒ d j ƒ  } | | d | } | j d	 | | | d  f ƒ Pq] q] Wxì t D]h } |  j | d ƒ rÍ |  t | ƒ d j ƒ  } | d
 k rd	 } n  | j | | | | d  f ƒ PqÍ qÍ Wxy | j	 d ƒ D]h } | j ƒ  } d } | j d ƒ r‰d } | d j ƒ  } n  | s•qIn  | j d | | | d  f ƒ qIW| S(   Ni    (   t   pairindextypesR   t   !t   maini   t   :s   ; Ro   Rp   t   ,Rn   (
   t   sphinx.domains.pythonRt   RL   t
   startswitht   lstripR   t   appendR'   t
   indextypest   split(   t   entryt   targetidRt   t   indexentriest   oentryRv   t   typet   value(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   process_index_entry6  s>    	 c      	   C@  sl  | j  ƒ  } xY| j t j ƒ D]E} g  } t t | d ƒ } x| D]}	 |	 | k rE yb | j |	 ƒ t j | |	 ƒ d d d ƒt	 |  | |	 |  j
 j |	 ƒ | | ƒ }
 | j |	 ƒ Wn- t k
 rè t j t d ƒ |	 d | ƒqMXt j d |	 ƒ } |
 j | _ x3 | j t j ƒ D] } d | k r|	 | d <qqW| j | ƒ qE qE W| j j | | ƒ q W| S(   sw   Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    t   includefilesRE   t   nonli   s+   toctree contains ref to nonexisting file %rt   locationt   docname(   Re   R+   R   t   toctreet   mapR   R|   R    t   infot   inline_all_toctreest   envt   get_doctreet   addR   t   warningR   t   start_of_fileRA   R   t   sectionR"   RK   (   t   buildert
   docnamesetR‰   t   treet	   colorfunct	   traversedt   toctreenodet   newnodesR†   t   includefilet   subtreet   soft   sectionnode(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyR   ]  s0    c         C@  s˜   t  j d d d t ƒ} | | k r7 | r7 | | d <n= | r^ |  j | | ƒ d | | d <n |  j | | ƒ | d <| r‡ | | d <n  | j | ƒ | S(   s$   Shortcut to create a reference node.R   t   internalt   refidt   #t   refurit   reftitle(   R   t	   referenceR9   t   get_relative_uriR|   (   R”   t   fromdocnamet	   todocnameR€   t   childR(   R   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   make_refnode~  s    !c         C@  s%   |  j  j |  j ƒ \ | _ | _ d  S(   N(   t   state_machinet   get_source_and_linet   linenoR#   R$   (   t	   directiveR   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   set_source_info  s    c         C@  s"   |  j  j | ƒ \ | _ | _ d  S(   N(   t   reporterR«   R#   R$   (   t   inlinerR¬   R   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   set_role_source_info–  s    c         C@  sY   t  |  j t ƒ r t S|  j j d d ƒ t k r5 t St |  d d ƒ t k rQ t St Sd S(   s(   Check the node is smart-quotable or not.t   support_smartquotesN(   R   R"   t   NON_SMARTQUOTABLE_PARENT_NODESR:   R7   R'   t   getattrR9   (   R   (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   is_smartquotable¦  s    c         C@  s¾   x· |  j  t j ƒ D]£ } y | j | d ƒ } WnK t k
 r} } t j t d ƒ | d | ƒ| j | j	 pv t
 j ƒ  ƒ q X| r£ | j | j	 pœ t
 j ƒ  ƒ q | j t
 j ƒ  ƒ q Wd S(   s2   Filter ``only`` nodes which does not match *tags*.t   exprs8   exception while evaluating only directive expression: %sRˆ   N(   R+   R   t   onlyt   eval_conditionR   R    R‘   R   t   replace_selfRA   R   t   comment(   t   documentt   tagsR   t   rett   err(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   process_only_nodes³  s     c         C@  sI   |  j  |  j |  j  } t |  t j ƒ rE |  j | _ |  j | _ n  | S(   N(   R   R   t
   attributesR   R   t   ElementR#   R$   (   t   selft   newnode(    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt	   _new_copyÊ  s
    (L   t   __doc__t
   __future__R    R,   t   docutilsR   t   sixR   t   sphinxR   t   sphinx.localeR   t   sphinx.utilR   R:   t   typingR   R   R   R	   R
   R   R   t   sphinx.buildersR   t   sphinx.utils.tagsR   t	   getLoggerR   R    t   compilet   DOTALLRj   t   caption_ref_reR   R   R4   t	   InvisibleR/   t   doctest_blockt   versionmodifiedR@   R;   RB   Rf   RG   R&   RH   R8   RI   RO   R0   R'   RP   RU   RZ   Rd   Ri   Rm   R}   R…   R   R©   R®   R±   t   FixedTextElementt   literalt   matht   problematict   not_smartquotableR³   Rµ   R¿   RÄ   RÁ   t   copy(    (    (    s0   lib/python2.7/site-packages/sphinx/util/nodes.pyt   <module>
   sj   4		8			,								
	'	!						