3
ÀÞL]S2  ã               @   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 d dl	m
Z
 d dlmZ d dlmZ d dlmZ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_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)ÚPY2)ÚWINDOWS)ÚDEPRECATION_MSG_PREFIX)Ú
ensure_dirÚsubprocess_logger)Úcolorama)ÚForec               @   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-69lrc5qx/pip/pip/_internal/utils/logging.pyr   7   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_errorE   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   K   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   Q   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   V   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_loga   s    
r   c               C   s   t tddƒS )Nr   r   )Úgetattrr   r   r   r   r   Úget_indentationn   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&   t   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   Zmessage_startÚt)r*   )r6   r   r8   Ž   s    
zIndentingFormatter.format)r   r   r   r&   r2   r8   Ú__classcell__r   r   )r*   r   r"   r   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   )rD   rE   r   )rD   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j| |ƒ || _tr*tr*tj| jƒ| _d S )N)r,   ÚStreamHandlerr&   Ú	_no_colorr   r	   ÚAnsiToWin32Ústream)r'   rK   Ú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	   rK   rE   Ú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	   rI   Ú
isinstancerK   rJ   rE   ÚhasattrrP   Ú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,   rH   r8   rY   Ú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   )rM   Úexc_inforO   r   r   r%   rG   ÚhandleError)r'   r=   r   r   )r*   r   r   r_   è   s
    
z"ColorizedStreamHandler.handleError)NN)r   r   r   r	   r,   r/   rF   r
   ÚREDr-   ÚYELLOWrZ   r&   rO   rY   r8   r_   r?   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| jƒƒ tjjj| ƒS )N)	r   rU   ÚpathÚdirnameÚbaseFilenamer,   ÚhandlersÚRotatingFileHandlerÚ_open)r'   r   r   r   rh   ÷   s    zBetterRotatingFileHandler._openN)r   r   r   rh   r   r   r   r   rb   õ   s   rb   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&   rj   r   r   r   r   ri   ü   s   ri   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%   rk   rj   )r'   r=   )r*   r   r   rj     s    zExcludeLoggerFilter.filter)r   r   r   r   rj   r?   r   r   )r*   r   rk     s   rk   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|ršd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)rN   Ústderrz2pip._internal.utils.logging.ColorizedStreamHandlerz5pip._internal.utils.logging.BetterRotatingFileHandler)rK   Ú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_timestamprK   rN   rz   rx   r{   )r\   ÚclassrL   rK   ÚfiltersÚ	formatterrq   ry   rr   r|   )r\   r}   ÚfilenameÚdelayr   )rs   rt   ru   rv   )r\   rf   zpip._vendorr\   )ÚversionÚdisable_existing_loggersr~   Ú
formattersrf   ÚrootÚloggerséÿÿÿÿéþÿÿÿéýÿÿÿ)rp   r/   )r    r,   ÚconfigÚ
dictConfigr-   r   rw   r"   )Ú	verbosityrL   Zuser_log_filer\   Zlevel_numberZinclude_user_logZadditional_log_fileÚ
root_levelZvendored_log_levelÚlog_streamsZhandler_classesrf   r   r   r   Úsetup_logging  s‚    


r�   )r   ).Ú
__future__r   Ú
contextlibr   r,   Úlogging.handlersrU   rM   r   Zpip._vendor.sixr   Zpip._internal.utils.compatr   Zpip._internal.utils.deprecationr   Zpip._internal.utils.miscr   r   Ú	threadingÚImportErrorÚdummy_threadingÚpip._vendorr	   Z	_coloramaÚ	ExceptionZpip._vendor.coloramar
   Úlocalr   r   r   r   Úcontextmanagerr   r!   Ú	Formatterr"   rF   rH   rG   rf   rg   rb   ri   rk   r�   r   r   r   r   Ú<module>   sR   

		


2K	