U
    «ÃT_é2  ã                   @   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k
r¤   d dlZY nX zd dlmZ W n ek
rÎ   dZY nX d d	lmZ eZe ¡ 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-8u7dkzi1/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 r   )ÚBrokenPipeErrorÚOSErrorr   r   r   r   r   r   r   r   O   s    þc                 C   s   | t ko|jtjkS 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   Z   s    é   c              	   c   s.   t  j| 7  _z
dV  W 5 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$   |  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 | 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¡}|| }d‰ | jrJ|  |d¡}d||jf ‰ ˆ 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%s,%03d ú c                    s   g | ]}ˆ | ‘qS r   r   )Ú.0Úline©Úprefixr   r   Ú
<listcomp>¡   s   ÿz-IndentingFormatter.format.<locals>.<listcomp>T)r'   r$   Úformatr5   r4   r%   Ú
formatTimeÚmsecsr#   ÚjoinÚ
splitlines)r)   Úrecordr3   Úmessage_startÚtr,   r9   r   r<   ’   s    þzIndentingFormatter.format)r   r   r   r(   r5   r<   Ú__classcell__r   r   r,   r   r$   v   s   
r$   c                     s   ‡ fdd„}|S )Nc                    s   d  tˆ ƒ| tjjg ¡S )Nr.   )r?   Úlistr	   ÚStyleÚ	RESET_ALL)Úinp©Úcolorsr   r   Úwrapped©   s    z_color_wrap.<locals>.wrappedr   )rJ   rK   r   rI   r   Ú_color_wrap¨   s    rL   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)   rR   Ú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	   rR   rK   Ú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ÚisattyTÚTERMÚANSI)r	   rP   Ú
isinstancerR   rQ   rK   ÚhasattrrX   ÚosÚenvironÚget)r)   Úreal_streamr   r   r   Úshould_colorË   s    
þz#ColorizedStreamHandler.should_colorc                 C   s@   t j | |¡}|  ¡ r<| jD ]\}}|j|kr||ƒ} q<q|S rN   )r/   rO   r<   ra   ÚCOLORSr4   )r)   rA   ÚmsgÚlevelÚcolorr   r   r   r<   à   s    
zColorizedStreamHandler.formatc                    s@   t  ¡ d d… \}}|r0|  ¡ r0t||ƒr0tƒ ‚tt| ƒ |¡S )Nr   )rT   Úexc_inforW   r   r   r'   rM   ÚhandleError)r)   rA   r   r   r,   r   r   rg   ì   s    ÿz"ColorizedStreamHandler.handleError)NN)r   r   r   r	   r/   r2   rL   r
   ÚREDr0   ÚYELLOWrb   r(   rW   ra   r<   rg   rD   r   r   r,   r   rM   ®   s   ý

rM   c                   @   s   e Zd Zdd„ ZdS )ÚBetterRotatingFileHandlerc                 C   s    t tj | j¡ƒ tjj | ¡S rN   )	r   r]   ÚpathÚdirnameÚbaseFilenamer/   ÚhandlersÚRotatingFileHandlerÚ_openrV   r   r   r   rp   û   s    zBetterRotatingFileHandler._openN)r   r   r   rp   r   r   r   r   rj   ù   s   rj   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚMaxLevelFilterc                 C   s
   || _ d S rN   )rd   )r)   rd   r   r   r   r(     s    zMaxLevelFilter.__init__c                 C   s   |j | jk S rN   )r4   rd   ©r)   rA   r   r   r   Úfilter  s    zMaxLevelFilter.filterN)r   r   r   r(   rs   r   r   r   r   rq      s   rq   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 rN   )r'   rt   rs   rr   r,   r   r   rs     s    zExcludeLoggerFilter.filter)r   r   r   r   rs   rD   r   r   r,   r   rt   	  s   rt   c                 C   sf  | dkrd}n.| dkrd}n | dkr*d}n| dkr8d}nd	}t t|ƒ}|d
k	}|r\|}d}nd}|}|dkrpdnd}dddœ}	dddœ}
dddg|ršd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/œd0d1|iid2œ¡ |S )3znConfigures and sets up all of the logging

    Returns the requested logging level, as its integer value.
    é   ÚDEBUGéÿÿÿÿr0   éþÿÿÿr2   éýÿÿÿÚCRITICALÚINFONz	/dev/null)r{   r2   zext://sys.stdoutzext://sys.stderr)rU   Ústderrz2pip._internal.utils.logging.ColorizedStreamHandlerz5pip._internal.utils.logging.BetterRotatingFileHandler)rR   ÚfileÚconsoleÚconsole_errorsÚconsole_subprocessÚuser_logFz*pip._internal.utils.logging.MaxLevelFilter)ú()rd   zlogging.Filter)r‚   Únamez/pip._internal.utils.logging.ExcludeLoggerFilter)Úexclude_warningsÚrestrict_to_subprocessÚexclude_subprocessz%(message)s)r‚   r<   T)r‚   r<   r%   )ÚindentÚindent_with_timestamprR   rU   r†   r„   r‡   )rd   ÚclassrS   rR   ÚfiltersÚ	formatterr|   r…   r}   rˆ   )rd   r‰   ÚfilenameÚdelayr‹   )r~   r   r€   r�   )rd   rn   zpip._vendorrd   )ÚversionÚdisable_existing_loggersrŠ   Ú
formattersrn   ÚrootÚloggers)r"   r/   ÚconfigÚ
dictConfigr0   Úsubprocess_loggerrƒ   r$   )Ú	verbosityrS   Úuser_log_filerd   Úlevel_numberÚinclude_user_logÚadditional_log_fileÚ
root_levelÚvendored_log_levelÚlog_streamsÚhandler_classesrn   r   r   r   Úsetup_logging  sª    
þþÿþþþ÷þýûú	úú	ûå$þ ÿÿ½JrŸ   )r   )/Ú
__future__r   Ú
contextlibr   r/   Úlogging.handlersr]   rT   r   r   Zpip._vendor.sixr   Úpip._internal.utils.compatr   Úpip._internal.utils.deprecationr   Úpip._internal.utils.miscr   Ú	threadingÚImportErrorZdummy_threadingÚpip._vendorr	   Ú	_coloramaÚ	ExceptionZpip._vendor.coloramar
   Úlocalr   r   r•   r   r   Úcontextmanagerr!   r#   Ú	Formatterr$   rL   rO   rM   rn   ro   rj   rq   rt   rŸ   r   r   r   r   Ú<module>   sT   

		


2K	