
0c@_%3                 @   sW  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 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 y d  d l Z Wn e k
 r d  d l Z Yn Xy d  d l m Z Wn e k
 rd Z Yn Xd  d	 l m Z e Z e j   Z e	 d
  Z Gd d   d e  Z e r|e rmd d   Z qd d   Z n! e rd d   Z n d d   Z e j  d d d   Z! d d   Z" Gd d   d e j#  Z$ d d   Z% Gd d   d e j&  Z' Gd d   d e j( j)  Z* Gd d    d  e  Z+ Gd! d"   d" e  Z, d# d$   Z- d S)%    )absolute_importN)Filter	getLogger)PY2)WINDOWS)DEPRECATION_MSG_PREFIX)
ensure_dir)colorama)Forezpip.subprocessorc               @   s   e  Z d  Z d Z d S)BrokenStdoutLoggingErrorzO
    Raised if BrokenPipeError occurs for the stdout stream while logging.
    N)__name__
__module____qualname____doc__ r   r   :/tmp/pip-build-jynh7p1z/pip/pip/_internal/utils/logging.pyr   :   s   r   c             C   s%   |  t  k o$ | j t j t j f k S)z1See the docstring for non-Windows Python 3 below.)IOErrorerrnoEINVALEPIPE)	exc_classexcr   r   r   _is_broken_pipe_errorH   s    r   c             C   s1   |  t  k p0 |  t k o0 | j t j t j f k S)z1See the docstring for non-Windows Python 3 below.)BrokenPipeErrorOSErrorr   r   r   )r   r   r   r   r   r   N   s    c             C   s   |  t  k o | j t j k S)z1See the docstring for non-Windows Python 3 below.)r   r   r   )r   r   r   r   r   r   T   s    c             C   s
   |  t  k S)z
        Return whether an exception is a broken pipe error.

        Args:
          exc_class: an exception class.
          exc: an exception instance.
        )r   )r   r   r   r   r   r   Y   s       c             c   s;   t    t _ t j |  7_ z	 d VWd t j |  8_ Xd S)zv
    A context manager which will cause the log output to be indented for any
    log messages emitted inside it.
    N)get_indentation
_log_stateindentation)numr   r   r   
indent_logd   s
    	r    c               C   s   t  t d d  S)Nr   r   )getattrr   r   r   r   r   r   s   s    r   c                   s@   e  Z d  Z   f d d   Z d d   Z   f d d   Z   S)IndentingFormatterc                s2   | j  d d  |  _ t t |   j | |   d S)z
        A logging.Formatter that obeys the indent_log() context manager.

        :param add_timestamp: A bool indicating output lines should be prefixed
            with their record's timestamp.
        add_timestampFN)popr#   superr"   __init__)selfargskwargs)	__class__r   r   r&   y   s    zIndentingFormatter.__init__c             C   s=   | t  j k  r d S| j t  r& d S| t  j k  r9 d Sd S)zv
        Return the start of the formatted log message (not counting the
        prefix to add to each line).
         z	WARNING: zERROR: )loggingWARNING
startswithr   ERROR)r'   	formattedlevelnor   r   r   get_message_start   s    z$IndentingFormatter.get_message_startc                s   t  t |   j |  } |  j | | j  } | | } d   |  j rj |  j | d  } d j t         d t   7  d j	   f d d   | j
 d  D  } | S)z
        Calls the standard formatter, but will indent all of the log message
        lines by our current indentation level.
        r+   z%Y-%m-%dT%H:%M:%Sz{t},{record.msecs:03.0f}  c                s   g  |  ] }   |  q Sr   r   ).0line)prefixr   r   
<listcomp>   s   	z-IndentingFormatter.format.<locals>.<listcomp>T)r%   r"   formatr2   r1   r#   
formatTimelocalsr   join
splitlines)r'   recordr0   Zmessage_startt)r*   )r6   r   r8      s    
	zIndentingFormatter.format)r   r   r   r&   r2   r8   r   r   )r*   r   r"   w   s   
r"   c                 s     f d d   } | S)Nc                s#   d j  t    |  t j j g  S)Nr+   )r;   listr	   Style	RESET_ALL)inp)colorsr   r   wrapped   s    z_color_wrap.<locals>.wrappedr   )rC   rD   r   )rC   r   _color_wrap   s    rE   c                   s   e  Z d  Z e rE e j e e j  f e j	 e e j
  f g Z n g  Z d d d d  Z d d   Z d d   Z d d	   Z   f d
 d   Z   S)ColorizedStreamHandlerNc             C   sA   t  j j |  |  | |  _ t r= t r= t j |  j  |  _ d  S)N)r,   StreamHandlerr&   	_no_colorr   r	   AnsiToWin32stream)r'   rJ   no_colorr   r   r   r&      s    	zColorizedStreamHandler.__init__c             C   s/   t  r t r |  j j t j k S|  j t j k S)zA
        Return whether the handler is using sys.stdout.
        )r   r	   rJ   rD   sysstdout)r'   r   r   r   _using_stdout   s    z$ColorizedStreamHandler._using_stdoutc             C   s}   t  s |  j r d St |  j t  j  s2 |  j n	 |  j j } t | d  r] | j   r] d St j	 j
 d  d k ry d Sd S)NFisattyTTERMANSI)r	   rH   
isinstancerJ   rI   rD   hasattrrO   osenvironget)r'   real_streamr   r   r   should_color   s    z#ColorizedStreamHandler.should_colorc             C   s[   t  j j |  |  } |  j   rW x3 |  j D]( \ } } | j | k r+ | |  } Pq+ W| S)N)r,   rG   r8   rX   COLORSr1   )r'   r=   msglevelcolorr   r   r   r8      s    zColorizedStreamHandler.formatc                s\   t  j   d  d  \ } } | rF |  j   rF t | |  rF t    t t |   j |  S)Nr   )rL   exc_inforN   r   r   r%   rF   handleError)r'   r=   r   r   )r*   r   r   r^      s
    	z"ColorizedStreamHandler.handleError)r   r   r   r	   r,   r/   rE   r
   REDr-   YELLOWrY   r&   rN   rX   r8   r^   r   r   )r*   r   rF      s   
rF   c               @   s   e  Z d  Z d d   Z d S)BetterRotatingFileHandlerc             C   s,   t  t j j |  j   t j j j |   S)N)	r   rT   pathdirnamebaseFilenamer,   handlersRotatingFileHandler_open)r'   r   r   r   rg      s    zBetterRotatingFileHandler._openN)r   r   r   rg   r   r   r   r   ra      s   ra   c               @   s(   e  Z d  Z d d   Z d d   Z d S)MaxLevelFilterc             C   s   | |  _  d  S)N)r[   )r'   r[   r   r   r   r&     s    zMaxLevelFilter.__init__c             C   s   | j  |  j k  S)N)r1   r[   )r'   r=   r   r   r   filter  s    zMaxLevelFilter.filterN)r   r   r   r&   ri   r   r   r   r   rh     s   rh   c                   s(   e  Z d  Z d Z   f d d   Z   S)ExcludeLoggerFilterzQ
    A logging Filter that excludes records from a logger (or its children).
    c                s   t  t |   j |  S)N)r%   rj   ri   )r'   r=   )r*   r   r   ri     s    zExcludeLoggerFilter.filter)r   r   r   r   ri   r   r   )r*   r   rj   
  s   rj   c             C   s}  |  d k r d } nE |  d4 k r* d } n0 |  d5 k r? d } n |  d6 k rT d } n d } t  t |  } | d	 k	 } | r | } d } n d
 } | } | d7 k r d n d } d d d d i }	 d d d d i }
 d d d g | r d g n g  } t j j d d d d d d d d d t j i d d d  d! t j i d" d d# d! t j i i d$ d% d t d& d' i d( d t d& d' d) d* i i d+ d d | d, |
 d d- | d |	 d d d" d g d. d% i d d d d, |
 d d- | d |	 d d d" g d. d% i d d | d, |
 d d- | d |	 d d d g d. d% i d d d d, |
 d d/ | d0 d* d. d( i i d1 d | d+ | i d2 d3 d | i i i  | S)8znConfigures and sets up all of the logging

    Returns the requested logging level, as its integer value.
       DEBUGr-   r   r/      CRITICALINFONz	/dev/nullrM   zext://sys.stdoutstderrzext://sys.stderrrJ   z2pip._internal.utils.logging.ColorizedStreamHandlerfilez5pip._internal.utils.logging.BetterRotatingFileHandlerconsoleconsole_errorsZconsole_subprocessuser_logversiondisable_existing_loggersFfiltersexclude_warningsz()z*pip._internal.utils.logging.MaxLevelFilterr[   Zrestrict_to_subprocesszlogging.FilternameZexclude_subprocessz/pip._internal.utils.logging.ExcludeLoggerFilter
formattersindentr8   z%(message)sZindent_with_timestampr#   Tre   classrK   	formatterfilenamedelayrootloggerszpip._vendor)zINFOzERROR)r!   r,   config
dictConfigr-   subprocess_loggerry   r"   )	verbosityrK   Zuser_log_filer[   Zlevel_numberZinclude_user_logZadditional_log_fileZ
root_levelZvendored_log_levellog_streamsZhandler_classesre   r   r   r   setup_logging  s    							

	

		

		
	r   ).
__future__r   
contextlibr   r,   logging.handlersrT   rL   r   r   Zpip._vendor.sixr   Zpip._internal.utils.compatr   Zpip._internal.utils.deprecationr   Zpip._internal.utils.miscr   	threadingImportErrordummy_threadingZpip._vendorr	   Z	_colorama	ExceptionZpip._vendor.coloramar
   localr   r   r   r   contextmanagerr    r   	Formatterr"   rE   rG   rF   re   rf   ra   rh   rj   r   r   r   r   r   <module>   sR   
		2K	