ó
öÀ„\c           @@  s"  d  Z  d d l m 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 m Z 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 m Z d d l	 m
 Z
 d d l m Z n  d Z  d Z! e d „  ƒ Z" e" j# i e j$ d 6e j$ d 6e j% d 6e j& d 6e j' d 6e! d 6e j( d 6ƒ e d „  ƒ Z) e) j# i e j' d 6e! d 6e j( d 6ƒ e d „  ƒ Z* e* j# i d e j% 6d e j& 6d e j( 6ƒ d „  Z+ d „  Z, d  e j- f d! „  ƒ  YZ. d" e. f d# „  ƒ  YZ/ d$ e. f d% „  ƒ  YZ0 d& e j1 f d' „  ƒ  YZ2 d( e j3 f d) „  ƒ  YZ4 d* e j3 f d+ „  ƒ  YZ5 d, e j3 f d- „  ƒ  YZ6 e r­e5 Z7 n e6 Z7 d. e j8 j9 f d/ „  ƒ  YZ: e d0 „  ƒ Z; e d1 „  ƒ Z< e e= d2 „ ƒ Z> d3 e? f d4 „  ƒ  YZ@ d5 e jA f d6 „  ƒ  YZB d7 „  ZC d8 e jA f d9 „  ƒ  YZD d: e jA f d; „  ƒ  YZE d< e jA f d= „  ƒ  YZF d> e jA f d? „  ƒ  YZG d@ eG f dA „  ƒ  YZH dB eG f dC „  ƒ  YZI dD „  ZJ dE e jK f dF „  ƒ  YZL dG e? f dH „  ƒ  YZM dI e? f dJ „  ƒ  YZN dK „  ZO d S(L   sÎ   
    sphinx.util.logging
    ~~~~~~~~~~~~~~~~~~~

    Logging 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   defaultdict(   t   contextmanager(   t   nodes(   t   get_source_line(   t   PY2t   StringIO(   t   SphinxWarning(   t   colorize(   t   Anyt   Dictt	   Generatort   IOt   Listt   Tuplet   Typet   Union(   t   Sphinxt   sphinxi   c           C@  s   t  j S(   N(   t   loggingt   WARNING(    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   <lambda>#   s    t   CRITICALt   SEVEREt   ERRORR   t   INFOt   VERBOSEt   DEBUGc           C@  s   d S(   Ni    (    (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR   .   s    i   i   c           C@  s   d S(   Nt   blue(    (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR   5   s    t   darkredt   redt   darkgrayc         C@  s-   t  j t d |  ƒ } t | _ t | i  ƒ S(   sü  Get logger wrapped by :class:`sphinx.util.logging.SphinxLoggerAdapter`.

    Sphinx logger always uses ``sphinx.*`` namespace to be independent from
    settings of root logger.  It ensures logging is consistent even if a
    third-party extension or imported application resets logger settings.

    Example usage::

        >>> from sphinx.util import logging
        >>> logger = logging.getLogger(__name__)
        >>> logger.info('Hello, this is an extension!')
        Hello, this is an extension!
    t   .(   R   t	   getLoggert	   NAMESPACEt   Falset   disabledt   SphinxLoggerAdapter(   t   namet   logger(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR!   =   s    	c         C@  sc   x\ |  D]T } | j  ƒ  | _ d | _ t | d d ƒ } t | t j ƒ r t | ƒ | _	 q q Wd S(   s   Convert LogRecord serializable.t   locationN(    (
   t
   getMessaget   msgt   argst   getattrt   Nonet
   isinstanceR   t   Nodet   get_node_locationR(   (   t   recordst   rR(   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   convert_serializableT   s    	t   SphinxLogRecordc           B@  s#   e  Z d  Z d Z d Z d „  Z RS(   s$   Log record class supporting locationt    c         C@  si   t  t |  ƒ j ƒ  } t |  d d  ƒ } | rF d | |  j | f } n |  j | k re |  j | } n  | S(   NR(   s   %s: %s%s(   t   superR4   R)   R,   R-   t   prefix(   t   selft   messageR(   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR)   f   s    N(   t   __name__t
   __module__t   __doc__R7   R-   R(   R)   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR4   a   s   t   SphinxInfoLogRecordc           B@  s   e  Z d  Z d Z RS(   s)   Info log record class supporting locationR5   (   R:   R;   R<   R7   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR=   r   s   t   SphinxWarningLogRecordc           B@  s   e  Z d  Z d Z RS(   s,   Warning log record class supporting locations	   WARNING: (   R:   R;   R<   R7   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR>   w   s   R%   c           B@  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s9   LoggerAdapter allowing ``type`` and ``subtype`` keywords.c         O@  s^   t  | t ƒ r1 t t |  ƒ j | | | | Ž n) t | } t t |  ƒ j | | | | Ž d  S(   N(   R.   t   intR6   R%   t   logt   LEVEL_NAMES(   R8   t   levelR*   R+   t   kwargst   levelno(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR@      s    "
c         O@  s   |  j  t | | | Ž d  S(   N(   R@   R   (   R8   R*   R+   RC   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   verbose‡   s    c         C@  sÆ   | j  d i  ƒ } d | k r4 | j d ƒ | d <n  d | k rV | j d ƒ | d <n  d | k rx | j d ƒ | d <n  d | k rš | j d ƒ | d <n  d | k r¼ | j d ƒ | d <n  | | f S(   Nt   extrat   typet   subtypeR(   t   nonlt   color(   t
   setdefaultt   pop(   R8   R*   RC   RF   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   process‹   s    c         C@  s   |  j  j | ƒ d  S(   N(   R'   t   handle(   R8   t   record(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRN   ›   s    (   R:   R;   R<   R@   RE   RM   RN   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR%   |   s
   			t   WarningStreamHandlerc           B@  s   e  Z d  Z RS(   s   StreamHandler for warnings.(   R:   R;   R<   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRP       s   t   NewLineStreamHandlerPY2c           B@  s   e  Z d  Z d „  Z RS(   sA   StreamHandler which switches line terminator by record.nonl flag.c         C@  s£   zˆ |  j  ƒ  |  j } t | d t ƒ rq t ƒ  |  _ t t |  ƒ j | ƒ | j |  j j	 ƒ  d  ƒ | j
 ƒ  n t t |  ƒ j | ƒ Wd  | |  _ |  j ƒ  Xd  S(   NRI   iÿÿÿÿ(   t   acquiret   streamR,   R#   R   R6   RQ   t   emitt   writet   getvaluet   flusht   release(   R8   RO   RS   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRT   ¨   s    
		(   R:   R;   R<   RT   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRQ   ¥   s   t   NewLineStreamHandlerPY3c           B@  s   e  Z d  Z d „  Z RS(   sA   StreamHandler which switches line terminator by record.nonl flag.c         C@  s]   zB |  j  ƒ  t | d t ƒ r+ d |  _ n  t t |  ƒ j | ƒ Wd  d |  _ |  j ƒ  Xd  S(   NRI   R5   s   
(   RR   R,   R#   t
   terminatorR6   RY   RT   RX   (   R8   RO   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRT   ½   s    
	(   R:   R;   R<   RT   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRY   º   s   t   MemoryHandlerc           B@  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Handler buffering all logs.c         C@  s   t  t |  ƒ j d ƒ d  S(   Niÿÿÿÿ(   R6   R[   t   __init__(   R8   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\   Ó   s    c         C@  s   t  S(   N(   R#   (   R8   RO   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   shouldFlush×   s    c         C@  sJ   |  j  ƒ  z. x |  j D] } | j | ƒ q Wg  |  _ Wd  |  j ƒ  Xd  S(   N(   RR   t   bufferRN   RX   (   R8   R'   RO   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   flushToÛ   s    
c         C@  s   |  j  g  } |  _  | S(   N(   R^   (   R8   R^   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   clearå   s    (   R:   R;   R<   R\   R]   R_   R`   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR[   Ð   s
   			
c          c@  sÅ   t  j t ƒ }  t ƒ  } | j t  j ƒ z] g  } x> |  j D]2 } t | t ƒ r< |  j	 | ƒ | j
 | ƒ q< q< W|  j | ƒ | VWd |  j	 | ƒ x | D] } |  j | ƒ qœ W| j |  ƒ Xd S(   s`   Contextmanager to pend logging warnings temporary.

    Similar to :func:`pending_logging`.
    N(   R   R!   R"   R[   t   setLevelR   t   handlersR.   RP   t   removeHandlert   appendt
   addHandlerR_   (   R'   t
   memhandlerRb   t   handler(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   pending_warningsë   s    		c          c@  s£   t  j t ƒ }  t ƒ  } zK g  } x, |  j D]  } |  j | ƒ | j | ƒ q, W|  j | ƒ | VWd |  j | ƒ x | D] } |  j | ƒ qz W| j |  ƒ Xd S(   s  Contextmanager to pend logging all logs temporary.

    For example::

        >>> with pending_logging():
        >>>     logger.warning('Warning message!')  # not flushed yet
        >>>     some_long_process()
        >>>
        Warning message!  # the warning is flushed here
    N(	   R   R!   R"   R[   Rb   Rc   Rd   Re   R_   (   R'   Rf   Rb   Rg   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   pending_logging  s    		c         c@  s…   t  j t ƒ } |  t k r# d Vn^ z9 t ƒ  } x$ | j D] } | j j d | ƒ q9 Wd VWd x | j D] } | j | ƒ qi WXd S(   s8   contextmanager to skip WarningIsErrorFilter for a while.Ni    (	   R   R!   R"   R#   t   DisableWarningIsErrorFilterRb   t   filterst   insertt   removeFilter(   t   skipR'   t   disablerRg   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   skip_warningiserror)  s    		t   LogCollectorc           B@  s    e  Z d  „  Z e d „  ƒ Z RS(   c         C@  s   g  |  _  d  S(   N(   t   logs(   R8   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\   ?  s    c         c@  s*   t  ƒ   } d  V| j ƒ  |  _ Wd  QXd  S(   N(   Ri   R`   Rr   (   R8   Rf   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   collectC  s    (   R:   R;   R\   R   Rs   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRq   >  s   	t
   InfoFilterc           B@  s   e  Z d  Z d „  Z RS(   s"   Filter error and warning messages.c         C@  s   | j  t j k  r t St Sd  S(   N(   RD   R   R   t   TrueR#   (   R8   RO   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   filterO  s    (   R:   R;   R<   Rv   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRt   L  s   c         C@  sœ   |  d k r t Sx… | D]} } d | k rD | j d d ƒ \ } } n | d } } | |  k r | d k s | d k s | | k s | d k r” t Sq q Wt S(   s'   Check the warning is suppressed or not.R    i   t   *N(   R-   R#   t   splitRu   (   RG   RH   t   suppress_warningst   warning_typet   targett	   subtarget(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   is_suppressed_warningW  s    t   WarningSuppressorc           B@  s    e  Z d  Z d „  Z d „  Z RS(   s#   Filter logs by `suppress_warnings`.c         C@  s    | |  _  t t |  ƒ j ƒ  d  S(   N(   t   appR6   R~   R\   (   R8   R   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\   n  s    	c         C@  s   t  | d d  ƒ } t  | d d  ƒ } y |  j j j } Wn t k
 rP g  } n Xt | | | ƒ rg t S|  j j d 7_ t	 Sd  S(   NRG   RH   i   (
   R,   R-   R   t   configRy   t   AttributeErrorR}   R#   t
   _warncountRu   (   R8   RO   RG   RH   Ry   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRv   s  s    
(   R:   R;   R<   R\   Rv   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR~   k  s   	t   WarningIsErrorFilterc           B@  s    e  Z d  Z d „  Z d „  Z RS(   s#   Raise exception if warning emitted.c         C@  s    | |  _  t t |  ƒ j ƒ  d  S(   N(   R   R6   Rƒ   R\   (   R8   R   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\   ˆ  s    	c         C@  sŸ   t  | d t ƒ r t S|  j j r— t  | d d ƒ } y | j | j } Wn  t t f k
 rj | j } n X| rˆ t	 | d | ƒ ‚ q› t	 | ƒ ‚ n t Sd  S(   Nt   skip_warningsiserrorR(   R5   t   :(
   R,   R#   Ru   R   t   warningiserrorR*   R+   t	   TypeErrort
   ValueErrorR   (   R8   RO   R(   R9   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRv     s    (   R:   R;   R<   R\   Rv   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRƒ   …  s   	Rj   c           B@  s   e  Z d  Z d „  Z RS(   s6   Disable WarningIsErrorFilter if this filter installed.c         C@  s   t  | _ t  S(   N(   Ru   R„   (   R8   RO   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRv   ¤  s    	(   R:   R;   R<   Rv   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRj   ¡  s   t   SphinxLogRecordTranslatorc           B@  s&   e  Z d  Z d Z d „  Z d „  Z RS(   s‚   Converts a log record to one Sphinx expects

    * Make a instance of SphinxLogRecord
    * docname to path if location given
    c         C@  s    | |  _  t t |  ƒ j ƒ  d  S(   N(   R   R6   R‰   R\   (   R8   R   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\   ²  s    	c         C@  s	  t  | t j ƒ r! |  j | _ n  t | d d  ƒ } t  | t ƒ r° | \ } } | r | r d |  j j	 j
 | ƒ | f | _ q| r¤ d |  j j	 j
 | ƒ | _ qd  | _ nU t  | t j ƒ rÔ t | ƒ | _ n1 | rd | k rd |  j j	 j
 | ƒ | _ n  t S(   NR(   s   %s:%ss   %sR…   (   R.   R   t	   LogRecordt   LogRecordClasst	   __class__R,   R-   t   tupleR   t   envt   doc2pathR(   R   R/   R0   Ru   (   R8   RO   R(   t   docnamet   lineno(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRv   ·  s    %N(   R:   R;   R<   R-   R‹   R\   Rv   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR‰   ª  s   	t   InfoLogRecordTranslatorc           B@  s   e  Z d  Z e Z RS(   s/   LogRecordTranslator for INFO level log records.(   R:   R;   R<   R=   R‹   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR’   Î  s   t   WarningLogRecordTranslatorc           B@  s   e  Z d  Z e Z RS(   s2   LogRecordTranslator for WARNING level log records.(   R:   R;   R<   R>   R‹   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR“   Ó  s   c         C@  sP   t  |  ƒ \ } } | r, | r, d | | f S| r: d | S| rH d | Sd  Sd  S(   Ns   %s:%ss   %s:s   <unknown>:%s(   R   R-   (   t   nodet   sourcet   line(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR0   Ø  s    t   ColorizeFormatterc           B@  s   e  Z d  „  Z RS(   c         C@  sf   t  t |  ƒ j | ƒ } t | d d  ƒ } | d  k rK t j | j ƒ } n  | r^ t | | ƒ S| Sd  S(   NRJ   (	   R6   R—   t   formatR,   R-   t	   COLOR_MAPt   getRD   R   (   R8   RO   R9   RJ   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR˜   æ  s    (   R:   R;   R˜   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR—   å  s   t   SafeEncodingWriterc           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s7   Stream writer which ignores UnicodeEncodeError silentlyc         C@  s(   | |  _  t | d d ƒ p d |  _ d  S(   Nt   encodingt   ascii(   RS   R,   Rœ   (   R8   RS   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\   õ  s    	c         C@  sW   y |  j  j | ƒ Wn< t k
 rR |  j  j | j |  j d ƒ j |  j ƒ ƒ n Xd  S(   Nt   replace(   RS   RU   t   UnicodeEncodeErrort   encodeRœ   t   decode(   R8   t   data(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRU   ú  s    c         C@  s&   t  |  j d ƒ r" |  j j ƒ  n  d  S(   NRW   (   t   hasattrRS   RW   (   R8   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRW     s    (   R:   R;   R<   R\   RU   RW   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR›   ó  s   			t   LastMessagesWriterc           B@  s    e  Z d  Z d „  Z d „  Z RS(   s?   Stream writer which memories last 10 messages to save trackbackc         C@  s   | |  _  d  S(   N(   R   (   R8   R   RS   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR\     s    c         C@  s   |  j  j j | ƒ d  S(   N(   R   t
   messagelogRd   (   R8   R¢   (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyRU     s    (   R:   R;   R<   R\   RU   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyR¤   	  s   	c         C@  s…  t  j t ƒ } | j t  j ƒ t | _ x | j D] } | j | ƒ q3 Wt	 t
 | ƒ ƒ } | j t ƒ  ƒ | j t |  ƒ ƒ | j t |  j ƒ | j t ƒ  ƒ t t
 | ƒ ƒ } | j t |  ƒ ƒ | j t |  ƒ ƒ | j t |  ƒ ƒ | j t  j ƒ | j t ƒ  ƒ t  j t |  | ƒ ƒ } | j t ƒ  ƒ | j t |  j ƒ | j t ƒ  ƒ | j | ƒ | j | ƒ | j | ƒ d S(   s   Setup root logger for SphinxN(   R   R!   R"   Ra   R   R#   t	   propagateRb   Rc   t   NewLineStreamHandlerR›   t	   addFilterRt   R’   t   VERBOSITY_MAPt	   verbosityt   setFormatterR—   RP   R~   R“   Rƒ   R   t   StreamHandlerR¤   Re   (   R   t   statust   warningR'   Rg   t   info_handlert   warning_handlert   messagelog_handler(    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   setup  s.    	(P   R<   t
   __future__R    R   t   logging.handlerst   collectionsR   t
   contextlibR   t   docutilsR   t   docutils.utilsR   t   sixR   R   t   sphinx.errorsR   t   sphinx.util.consoleR   R#   t   typingR	   R
   R   R   R   R   R   R   t   sphinx.applicationR   R"   R   RA   t   updateR   R   R   R   R   R©   R™   R!   R3   RŠ   R4   R=   R>   t   LoggerAdapterR%   R¬   RP   RQ   RY   R§   Rb   t   BufferingHandlerR[   Rh   Ri   Ru   Rp   t   objectRq   t   FilterRt   R}   R~   Rƒ   Rj   R‰   R’   R“   R0   t	   FormatterR—   R›   R¤   R²   (    (    (    s2   lib/python2.7/site-packages/sphinx/util/logging.pyt   <module>
   s„   :	




	
	

		$	!		$	