ó
öÀ„\c           @@  s-  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l 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 Z d d l m Z d d	 l m Z d d
 l m Z m Z 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" e" j# e$ ƒ Z% e j& d ƒ Z' e( rÛd d l) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ d d l m0 Z0 m1 Z1 d d l2 m3 Z3 d d l4 m5 Z5 d d l6 m7 Z7 n  e8 e e j9 ƒ j: ƒ Z; e< ƒ  Z= e	 d „  ƒ Z> d „  Z? d „  Z@ d „  ZA e	 d „  ƒ ZB e	 d „  ƒ ZC e	 d d „ ƒ ZE d eF f d „  ƒ  YZG d  eH f d! „  ƒ  YZI d" eH f d# „  ƒ  YZJ d$ e f d% „  ƒ  YZK d& e f d' „  ƒ  YZL d( „  ZM d d d) „ ZN e	 d* „  ƒ ZO d+ e f d, „  ƒ  YZP d- e f d. „  ƒ  YZQ d aR d d/ „ ZS d S(0   sÊ   
    sphinx.util.docutils
    ~~~~~~~~~~~~~~~~~~~~

    Utility functions for docutils.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
i    (   t   absolute_importN(   t   contextmanager(   t   copy(   t   LooseVersion(   t   path(   t   nodes(   t
   FileOutput(   t	   Directivet
   directivest   rolest   convert_directive_function(   t   StateMachine(   t   Reporter(   t   RemovedInSphinx30Warning(   t   ExtensionError(   t   __(   t   loggings>   ^(.+?:(?:\d+)?): \((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\d+)?\) (   t   Anyt   Callablet	   Generatort   Listt   Sett   Tuple(   t   Statet   ViewList(   t   Config(   t   BuildEnvironment(   t   SphinxFileInputc          c@  so   z' t  t j ƒ }  t  t j ƒ } d VWd |  t _ | t _ x+ t t ƒ D] } t | ƒ t j | ƒ qI WXd S(   s"   Create namespace for reST parsers.N(	   R   R   t   _directivesR	   t   _rolest   listt   additional_nodest   unregister_nodet   discard(   R   R   t   node(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   docutils_namespace3   s    			
c         C@  s   t  t j d |  j ƒ S(   s'   Check the *node* is already registered.t   visit_(   t   hasattrR   t   GenericNodeVisitort   __name__(   R"   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   is_node_registeredE   s    c         C@  s@   t  t j d |  j ƒ s< t j |  j g ƒ t j |  ƒ n  d S(   s­   Register a node to docutils.

    This modifies global state of some visitors.  So it is better to use this
    inside ``docutils_namespace()`` to prevent side-effects.
    R$   N(   R%   R   R&   R'   t   _add_node_class_namesR   t   add(   R"   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   register_nodeK   s    c         C@  s|   t  t j d |  j ƒ rx t t j d |  j ƒ t t j d |  j ƒ t t j d |  j ƒ t t j d |  j ƒ n  d S(   sa   Unregister a node from docutils.

    This is inverse of ``nodes._add_nodes_class_names()``.
    R$   t   depart_N(   R%   R   R&   R'   t   delattrt   SparseNodeVisitor(   R"   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyR    W   s
    c          #@  sK   d d l  m ‰  d ‡  f d † }  z |  t j _ d VWd ˆ  t j _ Xd S(   s½   Patch docutils.languages.get_language() temporarily.

    This ignores the second argument ``reporter`` to suppress warnings.
    refs: https://github.com/sphinx-doc/sphinx/issues/3788
    i    (   t   get_languagec         @  s
   ˆ  |  ƒ S(   N(    (   t   language_codet   reporter(   R/   (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   patched_get_languagen   s    N(   t   docutils.languagesR/   t   Nonet   docutilst	   languages(   R2   (    (   R/   s3   lib/python2.7/site-packages/sphinx/util/docutils.pyR2   d   s    	c         c@  s€   zI t  j j d d ƒ } |  rC t j t j |  ƒ d ƒ t  j d <n  d VWd | d k rn t  j j d d ƒ n | t  j d <Xd S(   s?   Let docutils know the location of ``docutils.conf`` for Sphinx.t   DOCUTILSCONFIGs   docutils.confN(   t   ost   environt   getR4   R   t   joint   abspatht   pop(   t   confdirt   docutilsconfig(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   using_user_docutils_confz   s    %	c      	   c@  s,   t  ƒ   t |  ƒ 
 d VWd QXWd QXd S(   s   Patch to docutils temporarily.N(   R2   R@   (   R>   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   patch_docutils‹   s    
 t   ElementLookupErrorc           B@  s   e  Z RS(    (   R'   t
   __module__(    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRB   “   s   t   sphinx_domainsc           B@  sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sc   Monkey-patch directive and role dispatch, so that domain-specific
    markup takes precedence.
    c         C@  s   | |  _  d  |  _ d  |  _ d  S(   N(   t   envR4   t   directive_funct
   roles_func(   t   selfRE   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   __init__›   s    		c         C@  s   |  j  ƒ  d  S(   N(   t   enable(   RH   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt	   __enter__¡   s    c         C@  s   |  j  ƒ  d  S(   N(   t   disable(   RH   t   typet   valuet	   traceback(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   __exit__¥   s    c         C@  s4   t  j |  _ t j |  _ |  j t  _ |  j t _ d  S(   N(   R   t	   directiveRF   R	   t   rolet	   role_funct   lookup_directivet   lookup_role(   RH   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRJ   ©   s    c         C@  s   |  j  t _ |  j t _ d  S(   N(   RF   R   RQ   RS   R	   RR   (   RH   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRL   ±   s    c         C@  s  | j  ƒ  } d | k r… | j d d ƒ \ } } | |  j j k rÔ |  j j | ƒ } t | | ƒ | ƒ } | d k	 r‚ | g  f SqÔ nO |  j j j d ƒ } | d k	 rÔ t | | ƒ | ƒ } | d k	 rÔ | g  f Sn  t |  j j d ƒ | ƒ | ƒ } | d k	 r| g  f St	 ‚ d S(   st   Lookup a markup element (directive or role), given its name which can
        be a full name (with domain).
        t   :i   t   default_domaint   stdN(
   t   lowert   splitRE   t   domainst
   get_domaint   getattrR4   t	   temp_dataR:   RB   (   RH   RM   t   namet   domain_namet   domaint   elementt
   def_domain(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   lookup_domain_element¶   s"    !
c         C@  s<   y |  j  d | ƒ SWn! t k
 r7 |  j | | | ƒ SXd  S(   NRQ   (   Rd   RB   RF   (   RH   R_   t   lang_modulet   document(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRT   Ó   s    c         C@  s?   y |  j  d | ƒ SWn$ t k
 r: |  j | | | | ƒ SXd  S(   NRR   (   Rd   RB   RS   (   RH   R_   Re   t   linenoR1   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRU   Ú   s    (   R'   RC   t   __doc__RI   RK   RP   RJ   RL   Rd   RT   RU   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRD   —   s   							t   WarningStreamc           B@  s   e  Z d  „  Z RS(   c         C@  su   t  j | ƒ } | s. t j | j d ƒ ƒ nC | j ƒ  \ } } } t  j d | ƒ j ƒ  } t j | | d | ƒd  S(   Ns   
t    t   location(   t	   report_ret   searcht   loggert   warningt   rstript   groupst   subt   log(   RH   t   textt   matchedRk   RM   t   levelt   message(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   writeã   s    (   R'   RC   Rx   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRi   â   s   t   LoggingReporterc           B@  s2   e  Z e d  „  ƒ Z e j e j e d d „ Z RS(   c         C@  s%   |  | j  | j | j | j | j ƒ S(   sA   Create an instance of LoggingReporter from other reporter object.(   t   sourcet   report_levelt
   halt_levelt
   debug_flagt   error_handler(   t   clsR1   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   from_reporterï   s    t   backslashreplacec      	   C@  s/   t  ƒ  } t j |  | | | | | d | ƒd  S(   NR~   (   Ri   R   RI   (   RH   Rz   R{   R|   t   debugR~   t   stream(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRI   ö   s    	(	   R'   RC   t   classmethodR€   R   t   WARNING_LEVELt   SEVERE_LEVELt   FalseRI   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRy   î   s   	t   NullReporterc           B@  s   e  Z d  Z d „  Z RS(   s    A dummy reporter; write nothing.c         C@  s   t  j |  d d d ƒ d  S(   NRj   iç  i   (   R   RI   (   RH   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRI     s    (   R'   RC   Rh   RI   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRˆ   ÿ   s   c           C@  s
   t  d k S(   Ni    i   (   i    i   i    (   t   __version_info__(    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   is_html5_writer_available  s    c         K@  sŽ   t  j d t ƒ t |  t j t j f ƒ r_ | |  _ | pF d d t f |  _	 | |  _
 t |  ƒ S| sq | sq | r† t t d ƒ ƒ ‚ n  |  Sd  S(   NsV   function based directive support is now deprecated. Use class based directive instead.i    sC   when adding directive classes, no additional arguments may be given(   t   warningst   warnR   t
   isinstancet   typest   FunctionTypet
   MethodTypet   contentR‡   t	   argumentst   optionsR
   R   R   (   t   objt   has_contentt   argument_spect   option_spec(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   directive_helper  s    			
c         c@  sY   zB |  j  j j } t g  d ƒ } | | _ | j |  j  j _ d VWd | |  j  j _ Xd S(   s1   Switch current source input of state temporarily.N(   t   memoR1   t   get_source_and_lineR   R4   t   input_lines(   t   stateR‘   Rš   t   state_machine(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   switch_source_input  s    		t   SphinxFileOutputc           B@  s    e  Z d  Z d „  Z d „  Z RS(   s#   Better FileOutput class for Sphinx.c         K@  s)   | j  d t ƒ |  _ t j |  |  d  S(   Nt   overwrite_if_changed(   R=   R‡   R    R   RI   (   RH   t   kwargs(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRI   4  s    c         C@  sŒ   |  j  r| |  j r| d |  j k r| |  j r| t j j |  j  ƒ r| t j |  j  d |  j	 ƒ } | j
 ƒ  | k rs | SWd  QXn  t j |  | ƒ S(   Nt   bt   encoding(   t   destination_patht	   autocloset   modeR    R8   R   t   existst   codecst   openR£   t   readR   Rx   (   RH   t   datat   f(    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRx   9  s    !(   R'   RC   Rh   RI   Rx   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRŸ   1  s   	t   SphinxDirectivec           B@  s,   e  Z d  Z e d „  ƒ Z e d „  ƒ Z RS(   së   A base class for Sphinx directives.

    This class provides helper methods for Sphinx directives.

    .. note:: The subclasses of this class might not work with docutils.
              This class is strongly coupled with Sphinx.
    c         C@  s   |  j  j j j S(   s3   Reference to the :class:`.BuildEnvironment` object.(   Rœ   Rf   t   settingsRE   (   RH   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyRE   N  s    c         C@  s
   |  j  j S(   s)   Reference to the :class:`.Config` object.(   RE   t   config(   RH   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyR¯   T  s    (   R'   RC   Rh   t   propertyRE   R¯   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyR­   E  s   c         C@  sn   t  d k r! t j j |  ƒ a  n  | d k r? t t  j ƒ } n  t j | t  j	 d |  ƒ} | j
 |  d ƒ | S(   s&  Return a new empty document object.  This is an alternative of docutils'.

    This is a simple wrapper for ``docutils.utils.new_document()``.  It
    caches the result of docutils' and use it on second call for instanciation.
    This makes an instantiation of document nodes much faster.
    Rz   iÿÿÿÿN(   t   __document_cache__R4   R5   t   utilst   new_documentR   R®   R   Rf   R1   t   note_source(   t   source_pathR®   Rf   (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyR³   `  s    	(T   Rh   t
   __future__R    R¨   R8   t   reRŽ   R‹   t
   contextlibR   R   t   distutils.versionR   R   R5   R   t   docutils.ioR   t   docutils.parsers.rstR   R   R	   R
   t   docutils.statemachineR   t   docutils.utilsR   t   sphinx.deprecationR   t   sphinx.errorsR   t   sphinx.localeR   t   sphinx.utilR   t	   getLoggerR'   Rn   t   compileRl   R‡   t   typingR   R   R   R   R   R   R   R   t   sphinx.configR   t   sphinx.environmentR   t	   sphinx.ioR   t   tuplet   __version__t   versionR‰   t   setR   R#   R(   R+   R    R2   R@   R4   RA   t	   ExceptionRB   t   objectRD   Ri   Ry   Rˆ   RŠ   R˜   Rž   RŸ   R­   R±   R³   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/docutils.pyt   <module>
   sd   ".				K	