a
    `%3                     @   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 zd dlZW n ey   d dlZY n0 zd dlmZ W n ey   dZY n0 d d	lmZ eZe Ze	d
ZG dd deZererdd Zndd Zner,d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   =/usr/lib/python3/dist-packages/pip/_internal/utils/logging.pyr   :   s   r   c                 C   s   | t u o|jtjtjfv 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   s"   | t u p | tu o |jtjtjfv S r   )BrokenPipeErrorOSErrorr   r   r   r   r   r   r   r   N   s    c                 C   s   | t u o|jtjkS r   )r   r   r   r   r   r   r   r   T   s    c                 C   s   | t u 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   Y   s       c              	   c   sD   t  t_t j| 7  _zdV  W t j| 8  _nt j| 8  _0 d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)Z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                       s0   e Zd Z fddZdd Z fddZ  ZS )IndentingFormatterc                    s(   | dd| _tt| j|i | 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 |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                    s~   t t| |}| ||j}|| }d | jrN| |d}djf i t   dt  7  d	 fdd|
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S r   r   ).0lineprefixr   r   
<listcomp>   s   z-IndentingFormatter.format.<locals>.<listcomp>T)r&   r#   formatr4   r3   r$   Z
formatTimelocalsr   join
splitlines)r(   recordr2   Zmessage_starttr+   r8   r   r;      s    zIndentingFormatter.format)r   r   r   r'   r4   r;   __classcell__r   r   r+   r   r#   w   s   
r#   c                     s    fdd}|S )Nc                    s   d t | tjjg S )Nr-   )r=   listr	   ZStyleZ	RESET_ALL)Zinpcolorsr   r   wrapped   s    z_color_wrap.<locals>.wrappedr   )rD   rE   r   rC   r   _color_wrap   s    rF   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| | || _tr*tr*t| 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u S | jtju S )zA
        Return whether the handler is using sys.stdout.
        )r   r	   rL   rE   sysstdoutr(   r   r   r   _using_stdout   s    z$ColorizedStreamHandler._using_stdoutc                 C   sX   t r
| jrdS t| jt js"| jn| jj}t|dr@| r@dS tj	
ddkrTdS dS )NFisattyTZTERMZANSI)r	   rJ   
isinstancerL   rK   rE   hasattrrR   osenvironget)r(   Zreal_streamr   r   r   should_color   s    
z#ColorizedStreamHandler.should_colorc                 C   s@   t j| |}|  r<| jD ]\}}|j|kr||} q<q|S rH   )r.   rI   r;   rX   COLORSr3   )r(   r?   msglevelZcolorr   r   r   r;      s    
zColorizedStreamHandler.formatc                    s@   t  d d \}}|r0|  r0t||r0t tt| |S )Nr   )rN   exc_inforQ   r   r   r&   rG   handleError)r(   r?   r   r   r+   r   r   r]      s    z"ColorizedStreamHandler.handleError)NN)r   r   r   r	   r.   r1   rF   r
   ZREDr/   ZYELLOWrY   r'   rQ   rX   r;   r]   rA   r   r   r+   r   rG      s   

rG   c                   @   s   e Zd Zdd ZdS )BetterRotatingFileHandlerc                 C   s    t tj| j tjj| S rH   )	r   rU   pathdirnameZbaseFilenamer.   handlersRotatingFileHandler_openrP   r   r   r   rc      s    zBetterRotatingFileHandler._openN)r   r   r   rc   r   r   r   r   r^      s   r^   c                   @   s   e Zd Zdd Zdd ZdS )MaxLevelFilterc                 C   s
   || _ d S rH   )r[   )r(   r[   r   r   r   r'     s    zMaxLevelFilter.__init__c                 C   s   |j | jk S rH   )r3   r[   r(   r?   r   r   r   filter  s    zMaxLevelFilter.filterN)r   r   r   r'   rf   r   r   r   r   rd     s   rd   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| | S rH   )r&   rg   rf   re   r+   r   r   rf     s    zExcludeLoggerFilter.filter)r   r   r   r   rf   rA   r   r   r+   r   rg   
  s   rg   c                 C   sd  | dkrd}n.| dkrd}n | dkr*d}n| dkr8d}nd	}t t|}|d
u}|r\|}d}nd}|}|dv rpdnd}ddd}	ddd}
g d|rdgng  }t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 )1znConfigures and sets up all of the logging

    Returns the requested logging level, as its integer value.
       DEBUGr/   r1   ZCRITICALINFONz	/dev/null)rm   r1   z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)()r[   zlogging.Filter)rt   namez/pip._internal.utils.logging.ExcludeLoggerFilter)exclude_warningsrestrict_to_subprocessexclude_subprocessz%(message)s)rt   r;   T)rt   r;   r$   )indentindent_with_timestamprL   rO   rx   rv   ry   )r[   classrM   rL   filters	formatterrn   rw   ro   rz   )r[   r{   filenameZdelayr}   )rp   rq   rr   rs   )r[   ra   zpip._vendorr[   )versionZdisable_existing_loggersr|   Z
formattersra   rootZloggers)r"   r.   ZconfigZ
dictConfigr/   subprocess_loggerru   r#   )	verbosityrM   Zuser_log_filer[   Zlevel_numberZinclude_user_logZadditional_log_fileZ
root_levelZvendored_log_levelZlog_streamsZhandler_classesra   r   r   r   setup_logging  s    
		$Jr   )r   ).Z
__future__r   
contextlibr   r.   Zlogging.handlersrU   rN   r   r   Zpip._vendor.sixr   Zpip._internal.utils.compatr   Zpip._internal.utils.deprecationr   Zpip._internal.utils.miscr   Z	threadingImportErrorZdummy_threadingZpip._vendorr	   Z	_colorama	ExceptionZpip._vendor.coloramar
   Zlocalr   r   r   r   contextmanagerr!   r   Z	Formatterr#   rF   rI   rG   ra   rb   r^   rd   rg   r   r   r   r   r   <module>   sR   

		


2K	