3

g2                 @   s  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W n ek
r   d dlZY nX yd dlmZ W n ek
r   dZY nX d d	lmZ eZej Zd e_e	d
ZG dd deZer&erdd Z ndd Z ner6dd Z ndd Z ej!d%ddZ"dd Z#G dd dej$Z%dd Z&G dd dej'Z(G dd dej)j*Z+G dd  d eZ,G d!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-unpacked-wheel-v59g9nu1/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_errorI   s    r   c             C   s"   | t kp | tko |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   O   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   U   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   Z   s       c             c   s.   t  j| 7  _z
dV  W dt  j| 8  _X dS )zv
    A context manager which will cause the log output to be indented for any
    log messages emitted inside it.
    N)
_log_stateindentation)numr   r   r   
indent_loge   s    
r   c               C   s   t tddS )Nr   r   )getattrr   r   r   r   r   get_indentationr   s    r!   c                   s0   e Zd Z fddZdd Z fddZ  ZS )IndentingFormatterc                s$   |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&   x   s    zIndentingFormatter.__init__c             C   s.   |t jk rdS |jtrdS |t jk r*dS d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                sz   t t| j|}| j||j}|| }d | jrJ| j|d}d||jf   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%s,%03d  c                s   g | ]} | qS r   r   ).0line)prefixr   r   
<listcomp>   s   z-IndentingFormatter.format.<locals>.<listcomp>T)r%   r"   formatr2   r1   r#   
formatTimemsecsr!   join
splitlines)r'   recordr0   message_startt)r*   )r6   r   r8      s    
zIndentingFormatter.format)r   r   r   r&   r2   r8   __classcell__r   r   )r*   r   r"   v   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   )rE   rF   r   )rE   r   _color_wrap   s    rG   c                   sh   e Zd Zer.ejeejfej	eej
fgZng ZdddZdd Zdd Zdd	 Z fd
dZ  ZS )ColorizedStreamHandlerNc             C   s.   t jj| | || _tr*tr*tj| j| _d S )N)r,   StreamHandlerr&   	_no_colorr   r	   AnsiToWin32stream)r'   rL   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	   rL   rF   sysstdout)r'   r   r   r   _using_stdout   s    z$ColorizedStreamHandler._using_stdoutc             C   sZ   t  s| jrdS t| jt js$| jn| jj}t|drB|j rBdS tj	j
ddkrVdS dS )NFisattyTTERMANSI)r	   rJ   
isinstancerL   rK   rF   hasattrrQ   osenvironget)r'   real_streamr   r   r   should_color   s    z#ColorizedStreamHandler.should_colorc             C   sB   t jj| |}| j r>x&| jD ]\}}|j|kr||}P qW |S )N)r,   rI   r8   rZ   COLORSr1   )r'   r=   msglevelcolorr   r   r   r8      s    
zColorizedStreamHandler.formatc                s@   t j d d \}}|r0| j r0t||r0t tt| j|S )Nr   )rN   exc_inforP   r   r   r%   rH   handleError)r'   r=   r   r   )r*   r   r   r`      s
    
z"ColorizedStreamHandler.handleError)NN)r   r   r   r	   r,   r/   rG   r
   REDr-   YELLOWr[   r&   rP   rZ   r8   r`   r@   r   r   )r*   r   rH      s   

rH   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   rV   pathdirnamebaseFilenamer,   handlersRotatingFileHandler_open)r'   r   r   r   ri      s    zBetterRotatingFileHandler._openN)r   r   r   ri   r   r   r   r   rc      s   rc   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&   rk   r   r   r   r   rj      s   rj   c                   s    e Zd ZdZ fddZ  ZS )ExcludeLoggerFilterzQ
    A logging Filter that excludes records from a logger (or its children).
    c                s   t t| j| S )N)r%   rl   rk   )r'   r=   )r*   r   r   rk     s    zExcludeLoggerFilter.filter)r   r   r   r   rk   r@   r   r   )r*   r   rl   	  s   rl   c             C   sf  | dkrd}n.| d1krd}n | d2kr*d}n| d3kr8d}nd}t t|}|d	k	}|r\|}d}nd
}|}|d4krpdnd}ddd}	ddd}
dddg|rdgng  }tjjdddtjddtjddtjddtddtdddd ||
d! ||	d" d#d$gd%d&d|
d! ||	d' d#gd%d&||
d! ||	d' d(gd%d&d|
d) |dd*d+d,||d-d.d/|iid0 |S )5znConfigures and sets up all of the logging

    Returns the requested logging level, as its integer value.
       DEBUGr-   r   r/      CRITICALINFONz	/dev/nullzext://sys.stdoutzext://sys.stderr)rO   stderrz2pip._internal.utils.logging.ColorizedStreamHandlerz5pip._internal.utils.logging.BetterRotatingFileHandler)rL   fileconsoleconsole_errorsconsole_subprocessuser_logFz*pip._internal.utils.logging.MaxLevelFilter)z()r]   zlogging.Filter)z()namez/pip._internal.utils.logging.ExcludeLoggerFilter)exclude_warningsrestrict_to_subprocessexclude_subprocessz%(message)s)z()r8   T)z()r8   r#   )indentindent_with_timestamprL   rO   r{   ry   r|   )r]   classrM   rL   filters	formatterrr   rz   rs   r}   )r]   r~   filenamedelayr   )rt   ru   rv   rw   )r]   rg   zpip._vendorr]   )versiondisable_existing_loggersr   
formattersrg   rootloggers)rq   r/   )r    r,   config
dictConfigr-   subprocess_loggerrx   r"   )	verbosityrM   user_log_filer]   level_numberinclude_user_logadditional_log_file
root_levelvendored_log_levellog_streamshandler_classesrg   r   r   r   setup_logging  s    


r   )r   )/
__future__r   
contextlibr   r,   logging.handlersrV   rN   r   r   pip._vendor.sixr   pip._internal.utils.compatr   pip._internal.utils.deprecationr   pip._internal.utils.miscr   	threadingImportErrordummy_threadingpip._vendorr	   	_colorama	ExceptionZpip._vendor.coloramar
   localr   r   r   r   r   contextmanagerr   r!   	Formatterr"   rG   rI   rH   rg   rh   rc   rj   rl   r   r   r   r   r   <module>   sT   

		


2K	