B
    lz]m                 @   s   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlZd dlmZ d dlZd dlmZ d dlZd dlmZ d d	lmZmZ d dlZd
dlmZmZmZm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'm(Z( d
dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 d
dl1m2Z2m3Z3 d
dl4m5Z5 ee6Z7G dd deZ8e8 Z9Z:G dd deZ;G dd deZ<G dd de<Z=G dd deZ>G dd de>Z?G d d! d!e>Z@G d"d# d#e>ZAG d$d% d%eZBG d&d' d'e<ZCG d(d) d)e<ZDG d*d+ d+eZEG d,d- d-eEZFG d.d/ d/eEZGG d0d1 d1eEZHG d2d3 d3eEZIG d4d5 d5eZJG d6d7 d7eeKZLG d8d9 d9eZMG d:d; d;eZNG d<d= d=eZOG d>d? d?eZPG d@dA dAeZQG dBdC dCeeRZSG dDdE dEeZTG dFdG dGeeUZVG dHdI dIeZWG dJdK dKeZXG dLdM dMeeKZYG dNdO dOeZZG dPdQ dQee[Z\G dRdS dSe\Z]G dTdU dUee^Z_G dVdW dWeZ`G dXdY dYe`ZaG dZd[ d[e`ZbG d\d] d]eZcG d^d_ d_eedZeG d`da daeZfG dbdc dcefZgG ddde deeZhG dfdg dgeZiG dhdi dieZjG djdk dkeZkG dldm dmeZlG dndo doeZmG dpdq dqeZnG drds dseZoG dtdu dueZpG dvdw dweZqG dxdy dyeZrG dzd{ d{eesZtG d|d} d}eeuZvG d~d deewZxG dd deeuZyG dd deZzG dd deZ{G dd deZ|G dd deZ}G dd deZ~G dd deZG dd deeZG dd deeKZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deeuZG dd deZG dd deZG dd deZG dd deZdd ZdddZdddZG dd deZdd ZdS )    )absolute_importdivisionprint_functionunicode_literals)	timedelta)ENOSPC)partialN)	getLogger)join)dedent)format_exceptionformat_exception_only   )
CondaErrorCondaExitZeroCondaMultiError	text_type)EntityEncoder)dals)boolify)groupby)COMPATIBLE_SHELLSPathConflictSafetyChecks)PY2ensure_text_typeinput	iteritemsiterkeyson_winstring_types)dashlisttimeout)get_signal_namec                   s   e Zd Z fddZ  ZS )ResolvePackageNotFoundc                sX   t dd |D | _t dd |D }|| _dddd |D  }tt| | d S )Nc             s   s    | ]}|D ]}|r
|V  q
qd S )N ).0depsdepr%   r%   /lib/python3.7/site-packages/conda/exceptions.py	<genexpr>%   s    z2ResolvePackageNotFound.__init__.<locals>.<genexpr>c             s   s   | ]}d  tt|V  qdS )z -> N)r
   mapstr)r&   	bad_chainr%   r%   r)   r*   &   s    
c             s   s   | ]}d | V  qdS )z  - %sNr%   )r&   r-   r%   r%   r)   r*   (   s    )tuplebad_depsZ_formatted_chainsr
   superr$   __init__)selfr0   Zformatted_chainsmessage)	__class__r%   r)   r2   "   s
    zResolvePackageNotFound.__init__)__name__
__module____qualname__r2   __classcell__r%   r%   )r5   r)   r$   !   s   r$   c                   s   e Zd Z fddZ  ZS )	LockErrorc                s   d| }t t| | d S )Nz%s)r1   r:   r2   )r3   r4   msg)r5   r%   r)   r2   .   s    zLockError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r:   -   s   r:   c                   s    e Zd ZdZ fddZ  ZS )ArgumentError   c                s   t t| j|f| d S )N)r1   r<   r2   )r3   r4   kwargs)r5   r%   r)   r2   6   s    zArgumentError.__init__)r6   r7   r8   return_coder2   r9   r%   r%   )r5   r)   r<   3   s   r<   c                   s    e Zd ZdZ fddZ  ZS )CommandArgumentErrorr=   c                s6   d dd tjD }tt| j|fd|i| d S )N c             s   s   | ]}t |V  qd S )N)r   )r&   sr%   r%   r)   r*   ?   s    z0CommandArgumentError.__init__.<locals>.<genexpr>command)r
   sysargvr1   r@   r2   )r3   r4   r>   rC   )r5   r%   r)   r2   >   s    zCommandArgumentError.__init__)r6   r7   r8   r?   r2   r9   r%   r%   )r5   r)   r@   :   s   r@   c               @   s   e Zd ZdS )HelpN)r6   r7   r8   r%   r%   r%   r)   rF   C   s   rF   c                   s   e Zd Z fddZ  ZS )ActivateHelpc                s   t d}tt| | d S )Na(  
        usage: conda activate [-h] [--stack] [env_name_or_prefix]

        Activate a conda environment.

        Options:

        positional arguments:
          env_name_or_prefix    The environment name or prefix to activate. If the
                                prefix is a relative path, it must start with './'
                                (or '.\' on Windows).

        optional arguments:
          -h, --help            Show this help message and exit.
          --stack               Stack the environment being activated on top of the
                                previous active environment, rather replacing the
                                current active environment with a new one. Currently,
                                only the PATH environment variable is stacked.
        )r   r1   rG   r2   )r3   r4   )r5   r%   r)   r2   I   s    zActivateHelp.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rG   G   s   rG   c                   s   e Zd Z fddZ  ZS )DeactivateHelpc                s   t d}tt| | d S )Nz
        usage: conda deactivate [-h]

        Deactivate the current active conda environment.

        Options:

        optional arguments:
          -h, --help            Show this help message and exit.
        )r   r1   rH   r2   )r3   r4   )r5   r%   r)   r2   b   s    	zDeactivateHelp.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rH   `   s   rH   c                   s   e Zd Z fddZ  ZS )GenericHelpc                s   d| }t t| | d S )Nzhelp requested for %s)r1   rI   r2   )r3   rC   r4   )r5   r%   r)   r2   r   s    zGenericHelp.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rI   p   s   rI   c                   s   e Zd Z fddZ  ZS )CondaSignalInterruptc                s"   t |}tt| jd||d d S )Nz Signal interrupt %(signal_name)s)signal_namesignum)r#   r1   rJ   r2   )r3   rL   rK   )r5   r%   r)   r2   x   s    zCondaSignalInterrupt.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rJ   w   s   rJ   c                   s   e Zd Zd fdd	Z  ZS )TooManyArgumentsError c                s^   || _ || _|| _|| _|| dkr(dnd}d|||d||f }tt| j|f|  d S )Nr   rB   rN   z*%s Got %s argument%s (%s) but expected %s.z, )expectedreceivedoffending_argumentsoptional_messager
   r1   rM   r2   )r3   rO   rP   rQ   rR   argssuffixr;   )r5   r%   r)   r2      s    zTooManyArgumentsError.__init__)rN   )r6   r7   r8   r2   r9   r%   r%   )r5   r)   rM      s   rM   c                   s   e Zd Zd fdd	Z  ZS )TooFewArgumentsErrorrN   c                s:   || _ || _|| _d|||f }tt| j|f|  d S )Nz$%s Got %s arguments but expected %s.)rO   rP   rR   r1   rU   r2   )r3   rO   rP   rR   rS   r;   )r5   r%   r)   r2      s    zTooFewArgumentsError.__init__)rN   )r6   r7   r8   r2   r9   r%   r%   )r5   r)   rU      s   rU   c                   s$   e Zd Z fddZdd Z  ZS )ClobberErrorc                s   || _ tt| j|f| d S )N)path_conflictr1   rV   r2   )r3   r4   rW   r>   )r5   r%   r)   r2      s    zClobberError.__init__c             C   s    | j tjkrdnd}d|| f S )NZClobberWarningrV   z%s: %s
)rW   r   warn)r3   Zclz_namer%   r%   r)   __repr__   s    zClobberError.__repr__)r6   r7   r8   r2   rY   r9   r%   r%   )r5   r)   rV      s   rV   c                   s   e Zd Z fddZ  ZS )BasicClobberErrorc                s:   t d}|jtjkr|d7 }tt| j||j||d d S )Nz
        Conda was asked to clobber an existing path.
          source path: %(source_path)s
          target path: %(target_path)s
        zQConda no longer clobbers existing paths without the use of the --clobber option
.)target_pathsource_path)r   rW   r   preventr1   rZ   r2   )r3   r\   r[   contextr4   )r5   r%   r)   r2      s    zBasicClobberError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rZ      s   rZ   c                   s   e Zd Z fddZ  ZS )KnownPackageClobberErrorc                s<   t d}|jtjkr|d7 }tt| j||j|||d d S )Na  
        The package '%(colliding_dist_being_linked)s' cannot be installed due to a
        path collision for '%(target_path)s'.
        This path already exists in the target prefix, and it won't be removed by
        an uninstall action in this transaction. The path appears to be coming from
        the package '%(colliding_linked_dist)s', which is already installed in the prefix.
        zPIf you'd like to proceed anyway, re-run the command with the `--clobber` flag.
.)r[   colliding_dist_being_linkedcolliding_linked_dist)r   rW   r   r]   r1   r_   r2   )r3   r[   r`   ra   r^   r4   )r5   r%   r)   r2      s    
z!KnownPackageClobberError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r_      s   r_   c                   s   e Zd Z fddZ  ZS )UnknownPackageClobberErrorc                s:   t d}|jtjkr|d7 }tt| j||j||d d S )Nax  
        The package '%(colliding_dist_being_linked)s' cannot be installed due to a
        path collision for '%(target_path)s'.
        This path already exists in the target prefix, and it won't be removed
        by an uninstall action in this transaction. The path is one that conda
        doesn't recognize. It may have been created by another package manager.
        zPIf you'd like to proceed anyway, re-run the command with the `--clobber` flag.
.)r[   r`   )r   rW   r   r]   r1   rb   r2   )r3   r[   r`   r^   r4   )r5   r%   r)   r2      s    
z#UnknownPackageClobberError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rb      s   rb   c                   s   e Zd Z fddZ  ZS )SharedLinkPathClobberErrorc                sJ   t d}|jtjkr|d7 }tt| j||j|ddd |D d d S )Nz
        This transaction has incompatible packages due to a shared path.
          packages: %(incompatible_packages)s
          path: '%(target_path)s'
        zPIf you'd like to proceed anyway, re-run the command with the `--clobber` flag.
.z, c             s   s   | ]}t |V  qd S )N)r   )r&   dr%   r%   r)   r*      s    z6SharedLinkPathClobberError.__init__.<locals>.<genexpr>)r[   Zincompatible_packages)r   rW   r   r]   r1   rc   r2   r
   )r3   r[   Zincompatible_package_distsr^   r4   )r5   r%   r)   r2      s    
z#SharedLinkPathClobberError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rc      s   rc   c                   s   e Zd Z fddZ  ZS )CommandNotFoundErrorc                s  dddh}dddddd	d
ddddddh}ddddddddh}ddl m} ddlm} || ||krdg}tr||td |tddtti  d 	|}n`||krd!}nRd"d#l
m}	 dd$lm}
 d%}||B |B t|
 B }|	||}|r|d&|d"  7 }tt| j||d' d S )(NZactivateZ
deactivaterunZcleanZconfigZcreatehelpinfoZinstalllistpackageremovesearchZ	uninstallupdateZupgradeZbuildZconvertZdevelopindexinspectZmetapackageZrenderZskeletonr   )r^   )init_loggerszGYour shell has not been properly configured to use 'conda %(command)s'.z
                If using 'conda %(command)s' from a batch script, change your
                invocation to 'CALL conda.bat %(command)s'.
                aK  
            To initialize your shell, run

                $ conda init <SHELL_NAME>

            Currently supported shells are:%(supported_shells)s

            See 'conda init --help' for more information and options.

            IMPORTANT: You may need to close and restart your shell after running 'conda init'.
            Zsupported_shellsr.   z0To use 'conda %(command)s', install conda-build.r   )get_close_matches)find_commandszNo command 'conda %(command)s'.z
Did you mean 'conda %s'?)rC   )base.contextr^   Zcli.mainrp   r   appendr   r!   r   r
   Zdifflibrq   Zcli.find_commandsrr   setr1   re   r2   )r3   rC   Zactivate_commandsZconda_commandsZbuild_commandsr^   rp   Zbuilderr4   rq   rr   choicesclose)r5   r%   r)   r2      s\    

zCommandNotFoundError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   re      s   re   c                   s   e Zd Z fddZ  ZS )PathNotFoundErrorc                s   d}t t| j||d d S )Nz%(path)s)path)r1   rx   r2   )r3   ry   r4   )r5   r%   r)   r2   0  s    zPathNotFoundError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rx   /  s   rx   c                   s   e Zd Z fddZ  ZS )DirectoryNotFoundErrorc                s   d}t t| j||d d S )Nz%(path)s)ry   )r1   rz   r2   )r3   ry   r4   )r5   r%   r)   r2   6  s    zDirectoryNotFoundError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   rz   5  s   rz   c                   s   e Zd Z fddZ  ZS )EnvironmentLocationNotFoundc                s   d}t t| j||d d S )Nz%Not a conda environment: %(location)s)location)r1   r{   r2   )r3   r|   r4   )r5   r%   r)   r2   <  s    z$EnvironmentLocationNotFound.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r{   ;  s   r{   c                   s   e Zd Z fddZ  ZS )EnvironmentNameNotFoundc                s    t d}tt| j||d d S )Nz
        Could not find conda environment: %(environment_name)s
        You can list all discoverable environments with `conda info --envs`.
        )environment_name)r   r1   r}   r2   )r3   r~   r4   )r5   r%   r)   r2   B  s    z EnvironmentNameNotFound.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r}   A  s   r}   c                   s   e Zd Z fddZ  ZS )NoBaseEnvironmentErrorc                s   t d}tt| | d S )Nz
        This conda installation has no default base environment. Use
        'conda create' to create new environments and 'conda activate' to
        activate environments.
        )r   r1   r   r2   )r3   r4   )r5   r%   r)   r2   L  s    zNoBaseEnvironmentError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   J  s   r   c                   s   e Zd Z fddZ  ZS )"DirectoryNotACondaEnvironmentErrorc                s    t d}tt| j||d d S )Nz
        The target directory exists, but it is not a conda environment.
        Use 'conda create' to convert the directory to a conda environment.
          target directory: %(target_directory)s
        )target_directory)r   r1   r   r2   )r3   r   r4   )r5   r%   r)   r2   W  s    z+DirectoryNotACondaEnvironmentError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   U  s   r   c                   s   e Zd Z fddZ  ZS )CondaEnvironmentErrorc                s"   d| }t t| j|f|  d S )Nz%s)r1   r   r2   )r3   r4   rS   r;   )r5   r%   r)   r2   b  s    zCondaEnvironmentError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   a  s   r   c                   s   e Zd Z fddZ  ZS )
DryRunExitc                s   d}t t| | d S )NzDry run. Exiting.)r1   r   r2   )r3   r;   )r5   r%   r)   r2   h  s    zDryRunExit.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   g  s   r   c                   s   e Zd Z fddZ  ZS )CondaSystemExitc                s*   d dd | jD }tt| | d S )NrA   c             s   s   | ]}t |V  qd S )N)r   )r&   argr%   r%   r)   r*   o  s    z+CondaSystemExit.__init__.<locals>.<genexpr>)r
   rS   r1   r   r2   )r3   rS   r;   )r5   r%   r)   r2   n  s    zCondaSystemExit.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   m  s   r   c                   s   e Zd Z fddZ  ZS )PaddingErrorc                s    d||f }t t| | d S )NzgPlaceholder of length '%d' too short in package %s.
The package must be rebuilt with conda-build > 2.0.)r1   r   r2   )r3   ZdistplaceholderZplaceholder_lengthr;   )r5   r%   r)   r2   t  s    
zPaddingError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   s  s   r   c                   s   e Zd Z fddZ  ZS )	LinkErrorc                s   t t| | d S )N)r1   r   r2   )r3   r4   )r5   r%   r)   r2   {  s    zLinkError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   z  s   r   c                   s   e Zd Z fddZ  ZS )CondaOSErrorc                s    d| }t t| j|f| d S )Nz%s)r1   r   r2   )r3   r4   r>   r;   )r5   r%   r)   r2     s    zCondaOSError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )
ProxyErrorc                s   t d}tt| | d S )Na-  
        Conda cannot proceed due to an error in your proxy configuration.
        Check for typos and other configuration errors in any '.netrc' file in your home directory,
        any environment variables ending in '_PROXY', and any other system-wide proxy
        configuration settings.
        )r   r1   r   r2   )r3   r4   )r5   r%   r)   r2     s    zProxyError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaIOErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   rS   r;   )r5   r%   r)   r2     s    zCondaIOError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaFileIOErrorc                s,   || _ d||f }tt| j|f|  d S )Nz'%s'. %s)filepathr1   r   r2   )r3   r   r4   rS   r;   )r5   r%   r)   r2     s    zCondaFileIOError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaKeyErrorc                s0   || _ d||f | _tt| j| jf|  d S )Nz'%s': %s)keyr;   r1   r   r2   )r3   r   r4   rS   )r5   r%   r)   r2     s    zCondaKeyError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c               @   s   e Zd ZdS )ChannelErrorN)r6   r7   r8   r%   r%   r%   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )ChannelNotAllowedc                sR   ddl m} ddlm} ||}|j}||j}td}tt| j	|||d d S )Nr   )Channel)maybe_unquotez
        Channel not included in whitelist:
          channel name: %(channel_name)s
          channel url: %(channel_url)s
        )channel_urlchannel_name)
models.channelr   
common.urlr   namebase_urlr   r1   r   r2   )r3   channelr   r   r   r   r4   )r5   r%   r)   r2     s    
zChannelNotAllowed.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )UnavailableInvalidChannelc       	         s|   ddl m} ddlm}m} ||}|j}||j}td}|jdkr`|t	d||j
|j 7 }tt| j||||d d S )Nr   )r   )join_urlr   a  
        The channel is not accessible or is invalid.
          channel name: %(channel_name)s
          channel url: %(channel_url)s
          error code: %(error_code)d

        You will need to adjust your conda configuration to proceed.
        Use `conda config --show channels` to view your configuration's current state,
        and use `conda config --show-sources` to view config file locations.
        filea?  
            As of conda 4.3, a valid channel must contain a `noarch/repodata.json` and
            associated `noarch/repodata.json.bz2` file, even if `noarch/repodata.json` is
            empty. Use `conda index %s`, or create `noarch/repodata.json`
            and associated `noarch/repodata.json.bz2`.
            )r   r   
error_code)r   r   r   r   r   r   r   r   Zschemer   r|   r1   r   r2   )	r3   r   r   r   r   r   r   r   r4   )r5   r%   r)   r2     s    
	
z"UnavailableInvalidChannel.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )OperationNotAllowedc                s   t t| | d S )N)r1   r   r2   )r3   r4   )r5   r%   r)   r2     s    zOperationNotAllowed.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaImportErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2     s    zCondaImportError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )
ParseErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2     s    zParseError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CouldntParseErrorc                s    || _ tt| | jd  d S )Nr   )reasonr1   r   r2   rS   )r3   r   )r5   r%   r)   r2     s    zCouldntParseError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )ChecksumMismatchErrorc                s<   t d}ddlm} ||}tt| j||||||d d S )Na   
        Conda detected a mismatch between the expected content and downloaded content
        for url '%(url)s'.
          download saved to: %(target_full_path)s
          expected %(checksum_type)s: %(expected_checksum)s
          actual %(checksum_type)s: %(actual_checksum)s
        r   )r   )urltarget_full_pathchecksum_typeexpected_checksumactual_checksum)r   r   r   r1   r   r2   )r3   r   r   r   r   r   r4   r   )r5   r%   r)   r2     s    
zChecksumMismatchError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )PackageNotInstalledErrorc                s"   t d}tt| j|||d d S )Nz{
        Package is not installed in prefix.
          prefix: %(prefix)s
          package name: %(package_name)s
        )prefixpackage_name)r   r1   r   r2   )r3   r   r   r4   )r5   r%   r)   r2     s    z!PackageNotInstalledError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Zd fdd	Z  ZS )CondaHTTPErrorNc          	      s   ddl m} td}	t|di d}
|	|
r4d|
 nd7 }	|	| }|pHd}|pPd	}|pXd
}ddlm} |rz||ddp|dnd}||}t|trt	|
ddd }t|tr| }tt| j|||||||d d S )Nr   )r   ze
        HTTP %(status_code)s %(reason)s for url <%(url)s>
        Elapsed: %(elapsed_time)s
        headerszCF-RAYzCF-RAY: %s

r.   Z000zCONNECTION FAILED-)	stringifyi   )Zcontent_max_lenrN   :)r   status_coder   elapsed_timeresponse_details	caused_by)r   r   r   getattrgetZ_vendor.auxlib.logzr   
isinstancer   r   splitr    upperr1   r   r2   )r3   r4   r   r   r   r   responser   r   Z_messageZcf_rayr   r   )r5   r%   r)   r2     s(    

zCondaHTTPError.__init__)NN)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s    r   c                   s   e Zd Z fddZ  ZS )CondaRevisionErrorc                s   d| }t t| | d S )Nz%s.)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2   -  s    zCondaRevisionError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   ,  s   r   c               @   s   e Zd ZdS )AuthenticationErrorN)r6   r7   r8   r%   r%   r%   r)   r   2  s   r   c                   s   e Zd Zd fdd	Z  ZS )PackagesNotFoundErrorr%   c                sX   dd }|r&t d}||}||}nt d}||}d}tt| j|||||d d S )Nc             S   s   dd dd | D  S )Nz  - z
  - c             s   s   | ]}t |V  qd S )N)r   )r&   xr%   r%   r)   r*   :  s    zCPackagesNotFoundError.__init__.<locals>.<lambda>.<locals>.<genexpr>)r
   )iterabler%   r%   r)   <lambda>:      z0PackagesNotFoundError.__init__.<locals>.<lambda>a  
            The following packages are not available from current channels:

            %(packages_formatted)s

            Current channels:

            %(channels_formatted)s

            To search for alternate channels that may provide the conda package you're
            looking for, navigate to

                https://anaconda.org

            and use the search bar at the top of the page.
            z|
            The following packages are missing from the target environment:
            %(packages_formatted)s
            r%   )packagespackages_formattedchannel_urlschannels_formatted)r   r1   r   r2   )r3   r   r   format_listr4   r   r   )r5   r%   r)   r2   8  s    

zPackagesNotFoundError.__init__)r%   )r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   6  s   r   c                   s*   e Zd ZdZdd Zd fdd	Z  ZS )	UnsatisfiableErrora  An exception to report unsatisfiable dependencies.

    Args:
        bad_deps: a list of tuples of objects (likely MatchSpecs).
        chains: (optional) if True, the tuples are interpreted as chains
            of dependencies, from top level to bottom. If False, the tuples
            are interpreted as simple lists of conflicting specs.

    Returns:
        Raises an exception with a formatted message detailing the
        unsatisfiable specifications.
    c          
      s  i  xt |tddD ]}dd |dd  D }|d ftdd |D  }d	td
d |D  }d}xNt D ]B\}}|d t| |krnx t||D ]\}	}
|	|
 qW d}qnW |sdd |D  |< qW xt D ]\}}g }xt||D ]\}}	d|	krn,t|	dkr|	  n|	d |	d |d dkrNd|dd   }||	rnd|d	t |	f n| qW d	| |< qW  fddt t
 D }|S )NT)r   reversec             S   s   g | ]}| d qS )rA   )	partition)r&   rB   r%   r%   r)   
<listcomp>m  s    z8UnsatisfiableError._format_chain_str.<locals>.<listcomp>r   r   c             s   s   | ]}|d  V  qdS )r   Nr%   )r&   vr%   r%   r)   r*   n  s    z7UnsatisfiableError._format_chain_str.<locals>.<genexpr>)rN   c             s   s   | ]}|d  V  qdS )r=   Nr%   )r&   r   r%   r%   r)   r*   o  s    Fc             S   s   g | ]
}|hqS r%   r%   )r&   valr%   r%   r)   r   w  s    rN   *@zfeature:z%s %s|z -> c                s   g | ]} | qS r%   r%   )r&   r   )chainsr%   r)   r     s    )sortedlenr/   r   zipaddclearrk   rt   r
   r   )r3   r0   r(   Zdep1r   ZvalsfoundZkey2ZcsetsZcsetr   r'   r   r%   )r   r)   _format_chain_strj  s8    



*z$UnsatisfiableError._format_chain_strTFc                s  ddl m  tdtdtdtdd}d}t|d	krF|d
7 }nVxR| D ]D\}}|rRg }|dkr.||d 7 }tdd |D }	i }
x`|D ]X}|d	 d j|	kr|
|d	 d jsg |
|d	 d j< |
|d	 d j |d	  qW x|
 D ],\}}|d| 7 }|d	dd |D 7 }qW qRx.|D ]&\}} fdd|D }|| q4W |rp| 
|}ndd |D }||| jt||d7 }qRW |r|d7 }tt| | d S )Nr   )	MatchSpeca  

The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:
{specs}

Your python: {ref}

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

        z

The following specifications were found to be incompatible with a past
explicit spec that is not an explicit spec in this operation ({ref}):
{specs}

                    zd

The following specifications were found to be incompatible with each other:


                    z

The following specifications were found to be incompatible with your CUDA driver:
{specs}

Your installed CUDA driver is: {ref}
)ZpythonZrequest_conflict_with_historydirectZcudarN   r   z
Did not find conflicting dependencies. If you would like to know which
packages conflict ensure that you have enabled unsatisfiable hints.

conda config --set unsatisfiable_hints True
            r   c             s   s   | ]}|d  d j V  qdS )r   r   N)r   )r&   rd   r%   r%   r)   r*     s    z.UnsatisfiableError.__init__.<locals>.<genexpr>r   z
Package %s conflicts for:
r.   c             S   s    g | ]}d  dd |D qS )z -> c             S   s   g | ]}t |qS r%   )r,   )r&   ir%   r%   r)   r     s    z:UnsatisfiableError.__init__.<locals>.<listcomp>.<listcomp>)r
   )r&   cr%   r%   r)   r     s    z/UnsatisfiableError.__init__.<locals>.<listcomp>c                s   g | ]}t  |d dqS )N)target)r,   )r&   r(   )r   r%   r)   r     s    c             S   s   g | ]}d  |qS )z, )r
   )r&   r   r%   r%   r)   r     s    )ZspecsrefzY
Note that strict channel priority may have removed packages required for satisfiability.)Zmodels.match_specr   r   r   itemsru   r   r   rt   r
   r   formatr!   r1   r   r2   )r3   r0   r   strictZmessagesr;   
class_nameZ	dep_classZ_chainsZlast_dep_entryZdep_constraint_mapr(   chainZ	dep_chainZinstalled_blocker)r5   )r   r)   r2     sN    



 zUnsatisfiableError.__init__)TF)r6   r7   r8   __doc__r   r2   r9   r%   r%   )r5   r)   r   ]  s   r   c                   s   e Zd Z fddZ  ZS )InstallErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2     s    zInstallError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )RemoveErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2     s    zRemoveError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )DisallowedPackageErrorc                s@   ddl m} ||}d}tt| j|f|| d| d S )Nr   )PackageRecordziThe package '%(dist_str)s' is disallowed by configuration.
See 'conda config --show disallowed_packages'.)package_refdist_str)models.recordsr   from_objectsr1   r   r2   r   )r3   r   r>   r   r4   )r5   r%   r)   r2     s
    
zDisallowedPackageError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )SpecsConfigurationConflictErrorc                sD   t djt|dt|dt|ddd}tt| j||||d d S )Nap  
        Requested specs conflict with configured specs.
          requested specs: {requested_specs_formatted}
          pinned specs: {pinned_specs_formatted}
        Use 'conda config --show-sources' to look for 'pinned_specs' and 'track_features'
        configuration parameters.  Pinned specs may also be defined in the file
        {pinned_specs_path}.
           z
conda-metaZpinned)Zrequested_specs_formattedZpinned_specs_formattedZpinned_specs_path)requested_specspinned_specsr   )r   r   r!   r
   r1   r   r2   )r3   r   r   r   r4   )r5   r%   r)   r2     s    
z(SpecsConfigurationConflictError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaIndexErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2     s    zCondaIndexError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaValueErrorc                s   t t| j|f|| d S )N)r1   r   r2   )r3   r4   rS   r>   )r5   r%   r)   r2   	  s    zCondaValueError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaTypeErrorc                s   d}t t| | d S )Nz(Expected type '%s' and got type '%s'. %s)r1   r   r2   )r3   Zexpected_typeZreceived_typerR   r;   )r5   r%   r)   r2     s    zCondaTypeError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CyclicalDependencyErrorc                sX   ddl m  t fdd|D }dtdd |D  }tt| j|fd|i| d S )Nr   )r   c             3   s   | ]}  |V  qd S )N)r   )r&   p)r   r%   r)   r*     s    z3CyclicalDependencyError.__init__.<locals>.<genexpr>z/Cyclic dependencies exist among these items: %sc             s   s   | ]}|  V  qd S )N)r   )r&   r   r%   r%   r)   r*     s    packages_with_cycles)r   r   r/   r!   r1   r   r2   )r3   r   r>   r4   )r5   )r   r)   r2     s    
z CyclicalDependencyError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CorruptedEnvironmentErrorc                s*   t d}tt| j|f||d| d S )Na-  
        The target environment has been corrupted. Corrupted environments most commonly
        occur when the conda process is force-terminated while in an unlink-link
        transaction.
          environment location: %(environment_location)s
          corrupted file: %(corrupted_file)s
        )environment_locationcorrupted_file)r   r1   r   r2   )r3   r   r   r>   r4   )r5   r%   r)   r2      s    
z"CorruptedEnvironmentError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r     s   r   c                   s   e Zd Z fddZ  ZS )CondaHistoryErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2   1  s    zCondaHistoryError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   0  s   r   c                   s   e Zd Z fddZ  ZS )CondaUpgradeErrorc                s   d| }t t| | d S )Nz%s)r1   r   r2   )r3   r4   r;   )r5   r%   r)   r2   7  s    zCondaUpgradeError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   6  s   r   c                   s   e Zd Z fddZ  ZS )CaseInsensitiveFileSystemErrorc                s*   t d}tt| j|f||d| d S )Nz
        Cannot extract package to a case-insensitive file system.
          package location: %(package_location)s
          extract location: %(extract_location)s
        )package_locationextract_location)r   r1   r   r2   )r3   r   r   r>   r4   )r5   r%   r)   r2   =  s    
z'CaseInsensitiveFileSystemError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   <  s   r   c                   s   e Zd Z fddZ  ZS )CondaVerificationErrorc                s   t t| | d S )N)r1   r   r2   )r3   r4   )r5   r%   r)   r2   L  s    zCondaVerificationError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r   K  s   r   c                   s   e Zd Z fddZ  ZS )SafetyErrorc                s   t t| | d S )N)r1   r  r2   )r3   r4   )r5   r%   r)   r2   Q  s    zSafetyError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r  P  s   r  c                   s   e Zd Z fddZ  ZS )CondaMemoryErrorc                s$   d}t t| j|fd|i| d S )NzMThe conda process ran out of memory. Increase system memory and/or try again.r   )r1   r  r2   )r3   r   r>   r4   )r5   r%   r)   r2   V  s    zCondaMemoryError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r  U  s   r  c                   s   e Zd Z fddZ  ZS )NotWritableErrorc                sV   | ||d trtd}n td}| t t d tt| j|f| d S )N)ry   errnoz{
            The current user does not have write permissions to a required path.
              path: %(path)s
            a  
            The current user does not have write permissions to a required path.
              path: %(path)s
              uid: %(uid)s
              gid: %(gid)s

            If you feel that permissions on this path are set incorrectly, you can manually
            change them by executing

              $ sudo chown %(uid)s:%(gid)s %(path)s

            In general, it's not advisable to use 'sudo conda'.
            )uidgid)	rm   r   r   osgeteuidgetegidr1   r  r2   )r3   ry   r  r>   r4   )r5   r%   r)   r2   ]  s    
zNotWritableError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r  [  s   r  c                   s   e Zd Z fddZ  ZS )NoWritableEnvsDirErrorc                s,   dt | }tt| j|fd|i| d S )Nz+No writeable envs directories configured.%s	envs_dirs)r!   r1   r
  r2   )r3   r  r>   r4   )r5   r%   r)   r2   ~  s    zNoWritableEnvsDirError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r
  |  s   r
  c                   s   e Zd Z fddZ  ZS )NoWritablePkgsDirErrorc                s,   dt | }tt| j|fd|i| d S )Nz+No writeable pkgs directories configured.%s	pkgs_dirs)r!   r1   r  r2   )r3   r  r>   r4   )r5   r%   r)   r2     s    zNoWritablePkgsDirError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )EnvironmentNotWritableErrorc                sT   | d|i trtd}n td}| t t d tt| j|f| d S )Nr   z
            The current user does not have write permissions to the target environment.
              environment location: %(environment_location)s
            z
            The current user does not have write permissions to the target environment.
              environment location: %(environment_location)s
              uid: %(uid)s
              gid: %(gid)s
            )r  r  )	rm   r   r   r  r  r	  r1   r  r2   )r3   r   r>   r4   )r5   r%   r)   r2     s    
z$EnvironmentNotWritableError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )CondaDependencyErrorc                s   t t| | d S )N)r1   r  r2   )r3   r4   )r5   r%   r)   r2     s    zCondaDependencyError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )BinaryPrefixReplacementErrorc                s0   t d}|||||d}tt| j|f| d S )Na  
        Refusing to replace mismatched data length in binary file.
          path: %(path)s
          placeholder: %(placeholder)s
          new prefix: %(new_prefix)s
          original data Length: %(original_data_length)d
          new data length: %(new_data_length)d
        )ry   r   
new_prefixoriginal_data_lengthnew_data_length)r   r1   r  r2   )r3   ry   r   r  r  r  r4   r>   )r5   r%   r)   r2     s    z%BinaryPrefixReplacementError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )InvalidSpecc                s   t t| j|f| d S )N)r1   r  r2   )r3   r4   r>   )r5   r%   r)   r2     s    zInvalidSpec.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )InvalidVersionSpecc                s   d}t t| j|||d d S )Nz/Invalid version '%(invalid_spec)s': %(details)s)invalid_specdetails)r1   r  r2   )r3   r  r  r4   )r5   r%   r)   r2     s    zInvalidVersionSpec.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )InvalidMatchSpecc                s   d}t t| j|||d d S )Nz,Invalid spec '%(invalid_spec)s': %(details)s)r  r  )r1   r  r2   )r3   r  r  r4   )r5   r%   r)   r2     s    zInvalidMatchSpec.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )EncodingErrorc                s,   t d| }tt| j|fd|i| d S )Na  
        A unicode encoding or decoding error has occurred.
        Python 2 is the interpreter under which conda is running in your base environment.
        Replacing your base environment with one having Python 3 may help resolve this issue.
        If you still have a need for Python 2 environments, consider using 'conda create'
        and 'conda activate'.  For example:

            $ conda create -n py2 python=2
            $ conda activate py2

        Error details: %r

        r   )r   r1   r  r2   )r3   r   r>   r4   )r5   r%   r)   r2     s    
zEncodingError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c                   s   e Zd Z fddZ  ZS )NoSpaceLeftErrorc                s$   d}t t| j|fd|i| d S )NzNo space left on devices.r   )r1   r  r2   )r3   r   r>   r4   )r5   r%   r)   r2     s    zNoSpaceLeftError.__init__)r6   r7   r8   r2   r9   r%   r%   )r5   r)   r    s   r  c             C   s2  t | trtdd | j}|dd}tdd |dd}|dd}|dd}|rd|jtjks~|rz|jt	j
krz|jr~|r| n.|r|jtjks|r|jt	jkr|jst|  nzt | tr|jt	j
kr|js| n|jt	jkr|jst|  n<t | tr*|jtjkr| n|jtjkr.t|  n| d S )Nc             S   s
   t | tS )N)r   rV   )er%   r%   r)   r     r   zmaybe_raise.<locals>.<lambda>Tr%   c             S   s
   t | tS )N)r   r  )r  r%   r%   r)   r     r   F)r   r   r   errorsr   Zsafety_checksr   ZenabledrW   r   r]   ZclobberrX   print_conda_exceptionrV   r  )errorr^   groupsZclobber_errorsZsafety_errorsZother_errorsr%   r%   r)   maybe_raise  s4    




r   c             C   s   ddl m} t| dd }|js<|jdks<t| tsR|jdkrRtt| |t	j
d n^|jrt| trfd S t|rpdnd}tj|  dd	td
}|d|  ntd}|d|  d S )Nr   )r^   r?   r=   r   )r   zconda.stdoutzconda.stderrT)indent	sort_keysclsz%s
z
%r
)rs   r^   r   debug	verbosityr   r   print_format_excrD   stderrjsonr	   dumpsdump_mapr   rh   r  )exc_valexc_tbr^   rcloggerZexc_jsonZ	stderrlogr%   r%   r)   r    s    

r  c             C   sF   | d krt  \}} }nt| }|r2t|| |}n
t|| }d|S )NrN   )rD   exc_infotyper   r   r
   )r,  r-  exc_typeZformatted_exceptionr%   r%   r)   r'  "  s    
r'  c               @   s   e Zd Zdd Zdd Zedd Zedd Zed	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#S )$ExceptionHandlerc             O   s0   y
|||S    t  \}}}| ||S d S )N)rD   r0  handle_exception)r3   funcrS   r>   _r,  r-  r%   r%   r)   __call__0  s
    
zExceptionHandler.__call__c             C   s0   ddl m} td|jrdnd }|| d S )Nr   )r^   zconda.%sstdoutr(  )rs   r^   r	   r)  rh   )r3   Zcontent_strr^   r/  r%   r%   r)   	write_out7  s    zExceptionHandler.write_outc             C   s   ddl m} |j|jfS )Nr   )r^   )rs   r^   Zremote_connect_timeout_secsZremote_read_timeout_secs)r3   r^   r%   r%   r)   http_timeout@  s    zExceptionHandler.http_timeoutc             C   s   ddl m} |jS )Nr   )r^   )rs   r^   
user_agent)r3   r^   r%   r%   r)   r;  E  s    zExceptionHandler.user_agentc             C   s   ddl m} |jS )Nr   )r^   )rs   r^   error_upload_url)r3   r^   r%   r%   r)   r<  J  s    z!ExceptionHandler.error_upload_urlc             C   s   t |tr(|jr| ||S | ||S t |trFtrF| t||S t |trpt	|dd t
krp| t||S t |tr| t||S t |tr| tdt  dS t |tr|jS | ||S )Nr  KeyboardInterruptr   )r   r   Z
reportable'handle_reportable_application_exceptionhandle_application_exceptionUnicodeErrorr   r  EnvironmentErrorr   r   r  MemoryErrorr  r=  _print_conda_exceptionr'  
SystemExitcodehandle_unexpected_exception)r3   r,  r-  r%   r%   r)   r4  O  s"    




z!ExceptionHandler.handle_exceptionc             C   s   |  || |jS )N)rC  r?   )r3   r,  r-  r%   r%   r)   r?  c  s    z-ExceptionHandler.handle_application_exceptionc             C   s   t || d S )N)r  )r3   r,  r-  r%   r%   r)   rC  g  s    z'ExceptionHandler._print_conda_exceptionc             C   sr   |  ||}| | |  \}}|r.|  n|d f\}}|rH| | | ||| t|dd }|d k	rn|S dS )Nr?   r   )get_error_reportprint_unexpected_error_report_calculate_ask_do_uploadask_for_upload_execute_uploadprint_upload_confirmr   )r3   r,  r-  error_reportrJ  	do_uploadask_responser.  r%   r%   r)   rF  j  s    

z,ExceptionHandler.handle_unexpected_exceptionc             C   s|   |  ||}ddlm} |jr,||  | | |  \}}|rN|  n|d f\}}|rh| 	| | 
||| |jS )Nr   )r^   )rG  rs   r^   r)  rm   r+  print_expected_error_reportrI  rJ  rK  rL  r?   )r3   r,  r-  rM  r^   rJ  rN  rO  r%   r%   r)   r>  u  s    

z8ExceptionHandler.handle_reportable_application_exceptionc       	   
   C   s   d dd tjD }i }d|kr~yddlm} | }W nD tk
r| } z&t }t||jj	t
|j|d}W d d }~X Y nX t||jj	t
|j|t|||d}t|tr| |d	< |S )
NrA   c             s   s   | ]}t |V  qd S )N)r   )r&   rB   r%   r%   r)   r*     s    z4ExceptionHandler.get_error_report.<locals>.<genexpr>z infor   )get_info_dict)r  exception_nameexception_type	traceback)r  rR  rS  rC   rT  
conda_infoZconda_error_components)r
   rD   rE   cli.main_inforQ  	Exceptionr'  reprr5   r6   r   r   r   r+  )	r3   r,  r-  rC   Z	info_dictrQ  Zinfo_eZinfo_tracebackrM  r%   r%   r)   rG    s*    

z!ExceptionHandler.get_error_reportc          
   C   sP  ddl m} |jr*ddlm} || n"g }|d |d |d |dd |d  D  |d |d	|d
   |d |d rddlm	}m
} y(|||d  |||d  W nL tk
r } z,tjd|dd |d |d|  W d d }~X Y nX |d |d |d | d| d S )Nr   )r^   )stdout_jsonrN   z<# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<c             s   s   | ]}d | V  qdS )z    Nr%   )r&   liner%   r%   r)   r*     s   zAExceptionHandler.print_unexpected_error_report.<locals>.<genexpr>rT  z`$ %s`rC   rU  )get_env_vars_strget_main_info_strz%rT)r0  z$conda info could not be constructed.zFAn unexpected error has occurred. Conda has prepared the above report.r.   )rs   r^   r)  
cli.commonrY  rt   extend
splitlinesrV  r[  r\  rW  logrX   r9  r
   )r3   rM  r^   rY  message_builderr[  r\  r  r%   r%   r)   rH    s6    







 

z.ExceptionHandler.print_unexpected_error_reportc          
   C   sV  ddl m} |jr*ddlm} || n(g }|d |d |d |d|d   |d |d rdd	lm}m} y(|||d  |||d  W nJ t	k
r } z,t
jd
|dd |d |d
|  W d d }~X Y nX |d |d |d ||d   |d |d |d | d| d S )Nr   )r^   )rY  rN   z<# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<z`$ %s`rC   rU  )r[  r\  z%rT)r0  z$conda info could not be constructed.z=V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V Vr  zQA reportable application error has occurred. Conda has prepared the above report.r.   )rs   r^   r)  r]  rY  rt   rV  r[  r\  rW  r`  rX   r^  r_  r9  r
   )r3   rM  r^   rY  ra  r[  r\  r  r%   r%   r)   rP    s8    




 




z,ExceptionHandler.print_expected_error_reportc          
   C   s   ddl m} ytdpt}W n2 tk
rP } ztd| d}W d d }~X Y nX |jdkrfd}d}nZ|jdksv|j	rd}d}n@|j
s|jrd}|j o|j	}n |sd}|j o|j	}nd}d}||fS )Nr   )r^   r   z%rTF)rs   r^   r  isattyr   rW  r`  r$  Zreport_errorsZ
always_yesr)  quietZoffline)r3   r^   rb  r  rJ  rN  r%   r%   r)   rI    s*    
z)ExceptionHandler._calculate_ask_do_uploadc          
   C   sn   |  td d }y tdttd}|o.t|}W n2 tk
rd } ztd| d}W d d }~X Y nX ||fS )Nz
        If submitted, this report will be used by core maintainers to improve
        future releases of conda.
        Would you like conda to send this report to the core maintainers?
        (   z[y/N]: z%rF)	r9  r   r"   r   r   r   rW  r`  r$  )r3   rO  rN  r  r%   r%   r)   rJ    s    zExceptionHandler.ask_for_uploadc          
   C   s  d| j i}| j}t }tdd |D r.dnd|d< dt|krFdnd|d< tj|dtd	d
 }|	t|d}d }ydd l
}d}| j}	|j|	|||dd}|  xX|jdkr|jdr|jd }	|j|	|||dd}|  |d7 }|dkrtdqW td|o|j W n0 tk
rF }
 ztd|
 W d d }
~
X Y nX yF|rd|jrd| d n(| d |r|jr| d|j  W n2 tk
r }
 ztd|
  W d d }
~
X Y nX d S )Nz
User-Agentc             s   s   | ]}t |d k V  qdS )   N)ord)r&   r   r%   r%   r)   r*     s    z3ExceptionHandler._execute_upload.<locals>.<genexpr>TFZis_asciirA   Z
has_spaces)r"  r#  r.   ZUSERNAME_REMOVEDr   )r   r"   dataZallow_redirects)i-  i.  ZLocationr      zRedirect limit exceededzupload response status: %sz%rzUpload successful.zUpload did not complete.z HTTP %s)r;  r:  getpassZgetuserallr,   r)  r*  r   replacerequestsr<  ZpostZraise_for_statusr   r   r   r   r`  r$  rW  rh   okr9  )r3   rM  r   Z_timeoutZusernamerg  r   rl  Zredirect_counterr   r  r%   r%   r)   rK    sD    


z ExceptionHandler._execute_uploadc             C   s>   |r|r|  d n&|d kr,|r,|  d n|r:|  d d S )Nz
Thank you for helping to improve conda.
Opt-in to always sending reports (and not see this message again)
by running

    $ conda config --set report_errors true

z"
Timeout reached. No report sent.
z\
No report sent. To permanently opt-out, use

    $ conda config --set report_errors false

)r9  )r3   rN  rJ  rO  r%   r%   r)   rL  :  s    z%ExceptionHandler.print_upload_confirmN)r6   r7   r8   r7  r9  propertyr:  r;  r<  r4  r?  rC  rF  r>  rG  rH  rP  rI  rJ  rK  rL  r%   r%   r%   r)   r3  .  s"   	  #*r3  c             O   s(   t  }|| f||}t|tr$|S d S )N)r3  r   int)r5  rS   r>   Zexception_handlerZreturn_valuer%   r%   r)   conda_exception_handlerT  s    
rp  )N)NN)Z
__future__r   r   r   r   Zdatetimer   r  r   	functoolsr   r)  Zloggingr	   r  os.pathr
   rD   textwrapr   rT  r   r   ri  rN   r   r   r   r   Z_vendor.auxlib.entityr   Z_vendor.auxlib.ishr   Z_vendor.auxlib.type_coercionr   Z_vendor.toolzr   Zbase.constantsr   r   r   Zcommon.compatr   r   r   r   r   r   r    Z	common.ior!   r"   Zcommon.signalsr#   r6   r`  r$   ZNoPackagesFoundZNoPackagesFoundErrorr:   r<   r@   rF   rG   rH   rI   rJ   rM   rU   rV   rZ   r_   rb   rc   re   OSErrorrx   rz   r{   r}   r   r   rA  r   r   rD  r   r   r   r   r   IOErrorr   r   KeyErrorr   r   r   r   r   ImportErrorr   r   r   r   r   r   r   r   r   r   r   r   r   r   
IndexErrorr   
ValueErrorr   	TypeErrorr   r   r   r   r   r   r   r  rB  r  r  r
  r  r  r  r  r  r  r  r  r  r   r  r'  objectr3  rp  r%   r%   r%   r)   <module>   s   $		
F	 '|	!"

  (