σ
φΐ\c           @@  sζ   d  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 d d l m Z d d l m Z n  d   Z d	 e f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   s8  
    sphinx.util.docfields
    ~~~~~~~~~~~~~~~~~~~~~

    "Doc fields" are reST field lists in object descriptions that will
    be domain-specifically transformed to a more appealing presentation.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
i    (   t   absolute_import(   t   nodes(   t   addnodes(   t   Anyt   Dictt   Listt   Tuple(   t   Domain(   t   BuildEnvironmentc         C@  st   t  |   d k r t St  |   d k rV x+ |  d D] } t | t j  s3 t Sq3 Wn  t |  d t j  rp t St S(   sC   True if the node only contains one paragraph (and system messages).i    i   (   t   lent   Falset
   isinstanceR   t   system_messaget	   paragrapht   True(   t   nodet   subnode(    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt   _is_single_paragraph   s    t   Fieldc           B@  sq   e  Z d  Z e Z e Z d d e d d d  Z e	 j
 d d d  Z e	 j
 d d d  Z d   Z d d  Z RS(   sΌ  A doc field that is never grouped.  It can have an argument or not, the
    argument can be linked using a specified *rolename*.  Field should be used
    for doc fields that usually don't occur more than once.

    The body can be linked using a specified *bodyrolename* if the content is
    just a single inline or text node.

    Example::

       :returns: description of the return value
       :rtype: description of the return type
    c         C@  s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   namet   namest   labelt   has_argt   rolenamet   bodyrolename(   t   selfR   R   R   R   R   R   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt   __init__7   s    					c      
   C@  sz   | s | p | | |  St  j d d | d t d | d | } | | pU | | |  7} | rv | j | j |  n  | S(   Nt    t	   refdomaint   refexplicitt   reftypet	   reftarget(   R   t   pending_xrefR
   t   domainst   process_field_xref(   R   R   t   domaint   targett	   innernodet   contnodet   envt   refnode(    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt	   make_xrefA   s    	c         C@  s   |  j  | | | | | |  g S(   N(   R)   (   R   R   R#   R$   R%   R&   R'   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt
   make_xrefsS   s    	c         C@  s
   | | f S(   N(    (   R   t   fieldargt   content(    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt
   make_entry^   s    c   	      C@  s?  | \ } } t  j d |  j  } | rh | t  j d  7} | j |  j |  j | | t  j d |  n  t |  d k rt | d t  j  sΦ t | d t  j	  rt | d  d k rt | d d t  j  r|  j |  j
 | | d j   d | d d | } n  t  j d t  j d d |   } t  j d | |  S(   NR   t    R'   i   i    R&   (   R   t
   field_nameR   t   Textt   extendR*   R   R	   R   t   inlineR   t   astextt
   field_bodyR   t   field(	   R   t   typesR#   t   itemR'   R+   R,   t	   fieldnamet	   fieldbody(    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt
   make_fieldb   s    ,&!(    N(   t   __name__t
   __module__t   __doc__R
   t
   is_groupedt   is_typedt   NoneR   R   R   t   literal_emphasisR)   R*   R-   R:   (    (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR   '   s   	t   GroupedFieldc           B@  s>   e  Z d  Z e Z e j Z d d d e	 d  Z
 d d  Z RS(   sΧ  
    A doc field that is grouped; i.e., all fields of that type will be
    transformed into one field with its body being a bulleted list.  It always
    has an argument.  The argument can be linked using the given *rolename*.
    GroupedField should be used for doc fields that can occur more than once.
    If *can_collapse* is true, this field will revert to a Field if only used
    once.

    Example::

       :raises ErrorClass: description when it is raised
    c         C@  s)   t  j |  | | | t |  | |  _ d  S(   N(   R   R   R   t   can_collapse(   R   R   R   R   R   RC   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR      s    c      	   C@  s  t  j d |  j  } |  j   } x~ | D]v \ } } t  j   }	 |	 j |  j |  j | | t j	 d |  |	 t  j
 d  7}	 |	 | 7}	 | t  j d |	  7} q( Wt |  d k rκ |  j rκ t  j d | d d  }
 t  j d | |
  St  j d |  }
 t  j d | |
  S(   NR   R'   s    -- i   i    (   R   R/   R   t	   list_typeR   R1   R*   R   R   t   literal_strongR0   t	   list_itemR	   RC   R4   R5   (   R   R6   R#   t   itemsR'   R8   t   listnodeR+   R,   t   parR9   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR:      s    
(    N(   R;   R<   R=   R   R>   R   t   bullet_listRD   R@   R
   R   R:   (    (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyRB   z   s   			t
   TypedFieldc           B@  s;   e  Z d  Z e Z d d d d d e d  Z d d  Z RS(   sa  
    A doc field that is grouped and has type information for the arguments.  It
    always has an argument.  The argument can be linked using the given
    *rolename*, the type using the given *typerolename*.

    Two uses are possible: either parameter and type description are given
    separately, using a field from *names* and one from *typenames*,
    respectively, or both are given using a field from *names*, see the example.

    Example::

       :param foo: description of parameter foo
       :type foo:  SomeClass

       -- or --

       :param SomeClass foo: description of parameter foo
    c         C@  s2   t  j |  | | | | |  | |  _ | |  _ d  S(   N(   RB   R   t	   typenamest   typerolename(   R   R   R   RL   R   R   RM   RC   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR   Ύ   s    	c         @  sΡ        f d   } t  j d  j  } t |  d k rj  j rj | d \ } } | | |  }	 nB  j   }	 x3 | D]+ \ } } |	 t  j d | | |   7}	 q} Wt  j d |	  }
 t  j d | |
  S(   Nc         @  s  t  j   } | j  j  j   |  t j d   |   k rτ | t  j d  7}  j |   } t	 |  d k rΤ t
 | d t  j  rΤ d j d   | D  } | j  j  j   | t j d   n
 | | 7} | t  j d  7} n  | t  j d  7} | | 7} | S(	   NR'   s    (i   i    u    c         s@  s   |  ] } | j    Vq d  S(   N(   R3   (   t   .0t   n(    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pys	   <genexpr>Ψ   s    t   )s    -- (   R   R   R1   R*   R   R   RE   R0   t   popR	   R   t   joinRM   RA   (   R+   R,   RI   t	   fieldtypet   typename(   R#   R'   R   R6   (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt   handle_itemΜ   s    (

R   i   i    (	   R   R/   R   R	   RC   RD   RF   R4   R5   (   R   R6   R#   RG   R'   RU   R8   R+   R,   t   bodynodeR9   (    (   R#   R'   R   R6   s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR:   Ε   s    #(    (    N(	   R;   R<   R=   R   R?   R@   R
   R   R:   (    (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyRK   ©   s
   	
t   DocFieldTransformerc           B@  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   
    Transforms field lists in "doc field" syntax into better-looking
    equivalents, using the field type definitions given on a domain.
    c         C@  sI   | |  _  d | j j k r9 |  j | j j  | j _ n  | j |  _ d  S(   Nt   _doc_field_type_map(   t	   directivet	   __class__t   __dict__t   preprocess_fieldtypest   doc_field_typesRX   t   typemap(   R   RY   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR   τ   s    	c         C@  so   i  } xb | D]Z } x! | j  D] } | t f | | <q W| j r x$ | j D] } | t f | | <qJ Wq q W| S(   N(   R   R
   R?   RL   R   (   R   R6   R^   RS   R   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR\   ό   s    	c         C@  s7   x0 | D]( } t  | t j  r |  j |  q q Wd S(   s,   Transform all field list children of a node.N(   R   R   t
   field_listt	   transform(   R   R   t   child(    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt   transform_all  s    c         C@  sz  |  j  } g  } i  } i  } x΄| D]¬} | \ } } y" | j   j d d  \ }	 }
 Wn$ t k
 r| | j   d }	 }
 n X| j |	 d	  \ } } t |  r΄ | j d j } n	 | j } | d k sή | j t	 |
  k r
|	 d d !j
   |	 d } |
 r| d |
 7} n  t j |  | d <| j |  | r" | r" | r" t |  d k r" t | d t j  r" | d j   } | j | j |  j j | d | d } t |  rΦ| j d j   | j d j |  q| j   | t j   7} | d j |  q" q" n  | j } | r{g  | D]0 } t | t j  sJt | t j  r | ^ q } | r" | | j | i   |
 <q" q" n  | j rίy |
 j d d  \ } } Wn t k
 r³qίXt j |  g | j | i   | <| }
 n  t j | j d t } | j j | _ | j j  | _  | j j! | _! | | 7} | j" r¦| | k rT| | | } n) t |  | | <| g  g } | j |  | j# |
 | g  } | d j |  q" | j# |
 | g  } | j | | g  q" Wt j$   } x | D] } t | t j%  r
| | 7} qε| \ }	 } | j |	 j i   } |  j j& j j' j( } | |	 j) | |  j j | d | 7} qεW| j* |  d S(
   s%   Transform a single field list *node*.i   R   i    R.   R&   t   translatableR'   N(   NN(+   R^   R3   t   splitR@   t
   ValueErrort   getR   t   childrenR   t   boolt   upperR   R0   t   appendR	   R   R*   RM   RY   R#   t   clearR1   R   R   t   Inlinet
   setdefaultR?   R2   t	   rawsourceR   t   parentt   documentt   sourcet   lineR>   R-   R_   R5   t   statet   settingsR'   R:   t   replace_self(   R   R   R^   t   entriest   groupindicesR6   R5   R8   R9   RS   R+   t   typedesct   is_typefieldR,   t   new_fieldnameR$   t   xrefsRT   RO   t   argtypet   argnamet   translatable_contentt   groupt   entryt   new_listt
   fieldtypesR'   (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyR`     s    	"	!(	
		"		
	(   R;   R<   R=   R   R\   Rb   R`   (    (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyRW   ξ   s
   			N(   R=   t
   __future__R    t   docutilsR   t   sphinxR   R
   t   typingR   R   R   R   t   sphinx.domainsR   t   sphinx.environmentR   R   t   objectR   RB   RK   RW   (    (    (    s4   lib/python2.7/site-packages/sphinx/util/docfields.pyt   <module>   s   "	S/E