3
ÙLôY¹  ã               @   sd  d Z ddlmZ ddlmZmZmZ ddlm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
ƒ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ƒ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ƒZG d)d*„ d*eƒZd+S ),z"Exceptions used throughout packageé    )Úabsolute_import)ÚchainÚgroupbyÚrepeat)Ú	iteritemsc               @   s   e Zd ZdZdS )ÚPipErrorzBase pip exceptionN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úa/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/pip/pip/exceptions.pyr   	   s   r   c               @   s   e Zd ZdZdS )ÚInstallationErrorz%General exception during installationN)r   r	   r
   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )ÚUninstallationErrorz'General exception during uninstallationN)r   r	   r
   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )ÚDistributionNotFoundzCRaised when a distribution cannot be found to satisfy a requirementN)r   r	   r
   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )ÚRequirementsFileParseErrorzDRaised when a general error occurs parsing a requirements file line.N)r   r	   r
   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )ÚBestVersionAlreadyInstalledzNRaised when the most up-to-date version of a package is already
    installed.N)r   r	   r
   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )Ú
BadCommandz0Raised when virtualenv or a command is not foundN)r   r	   r
   r   r   r   r   r   r   "   s   r   c               @   s   e Zd ZdZdS )ÚCommandErrorz7Raised when there is an error in command-line argumentsN)r   r	   r
   r   r   r   r   r   r   &   s   r   c               @   s   e Zd ZdZdS )ÚPreviousBuildDirErrorz:Raised when there's a previous conflicting build directoryN)r   r	   r
   r   r   r   r   r   r   *   s   r   c               @   s   e Zd ZdZdS )ÚInvalidWheelFilenamezInvalid wheel filename.N)r   r	   r
   r   r   r   r   r   r   .   s   r   c               @   s   e Zd ZdZdS )ÚUnsupportedWheelzUnsupported wheel.N)r   r	   r
   r   r   r   r   r   r   2   s   r   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )Ú
HashErrorsz:Multiple HashError instances rolled into one for reportingc             C   s
   g | _ d S )N)Úerrors)Úselfr   r   r   Ú__init__9   s    zHashErrors.__init__c             C   s   | j j|ƒ d S )N)r   Úappend)r   Úerrorr   r   r   r   <   s    zHashErrors.appendc             C   sf   g }| j jdd„ d x<t| j dd„ ƒD ](\}}|j|jƒ |jdd„ |D ƒƒ q(W |rbdj|ƒS d S )Nc             S   s   | j S )N)Úorder)Úer   r   r   Ú<lambda>A   s    z$HashErrors.__str__.<locals>.<lambda>)Úkeyc             S   s   | j S )N)Ú	__class__)r   r   r   r   r    B   s    c             s   s   | ]}|j ƒ V  qd S )N)Úbody)Ú.0r   r   r   r   ú	<genexpr>D   s    z%HashErrors.__str__.<locals>.<genexpr>Ú
)r   Úsortr   r   ÚheadÚextendÚjoin)r   ÚlinesÚclsÚerrors_of_clsr   r   r   Ú__str__?   s    zHashErrors.__str__c             C   s
   t | jƒS )N)Úboolr   )r   r   r   r   Ú__nonzero__H   s    zHashErrors.__nonzero__c             C   s   | j ƒ S )N)r0   )r   r   r   r   Ú__bool__K   s    zHashErrors.__bool__N)	r   r	   r
   r   r   r   r.   r0   r1   r   r   r   r   r   6   s   	r   c               @   s0   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ ZdS )
Ú	HashErrora”  
    A failure to verify a package against known-good hashes

    :cvar order: An int sorting hash exception classes by difficulty of
        recovery (lower being harder), so the user doesn't bother fretting
        about unpinned packages when he has deeper issues, like VCS
        dependencies, to deal with. Also keeps error reports in a
        deterministic order.
    :cvar head: A section heading for display above potentially many
        exceptions of this kind
    :ivar req: The InstallRequirement that triggered this error. This is
        pasted on after the exception is instantiated, because it's not
        typically available earlier.

    NÚ c             C   s   d| j ƒ  S )a)  Return a summary of me for display under the heading.

        This default implementation simply prints a description of the
        triggering requirement.

        :param req: The InstallRequirement that provoked this error, with
            populate_link() having already been called

        z    %s)Ú_requirement_name)r   r   r   r   r#   b   s    
zHashError.bodyc             C   s   d| j | jƒ f S )Nz%s
%s)r(   r#   )r   r   r   r   r.   n   s    zHashError.__str__c             C   s   | j rt| j ƒS dS )z¨Return a description of the requirement that triggered me.

        This default implementation returns long description of the req, with
        line numbers

        zunknown package)ÚreqÚstr)r   r   r   r   r4   q   s    zHashError._requirement_name)	r   r	   r
   r   r5   r(   r#   r.   r4   r   r   r   r   r2   O   s   r2   c               @   s   e Zd ZdZdZdZdS )ÚVcsHashUnsupportedzuA hash was provided for a version-control-system-based requirement, but
    we don't have a method for hashing those.r   zlCan't verify hashes for these requirements because we don't have a way to hash version control repositories:N)r   r	   r
   r   r   r(   r   r   r   r   r7   {   s   r7   c               @   s   e Zd ZdZdZdZdS )ÚDirectoryUrlHashUnsupportedzuA hash was provided for a version-control-system-based requirement, but
    we don't have a method for hashing those.é   zUCan't verify hashes for these file:// requirements because they point to directories:N)r   r	   r
   r   r   r(   r   r   r   r   r8   „   s   r8   c               @   s(   e Zd ZdZdZdZdd„ Zdd„ ZdS )	ÚHashMissingz2A hash was needed for a requirement but is absent.é   aw  Hashes are required in --require-hashes mode, but they are missing from some requirements. Here is a list of those requirements along with the hashes their downloaded archives actually had. Add lines like these to your requirements files to prevent tampering. (If you did not enable --require-hashes manually, note that it turns on automatically when any package has a hash.)c             C   s
   || _ dS )zq
        :param gotten_hash: The hash of the (possibly malicious) archive we
            just downloaded
        N)Úgotten_hash)r   r<   r   r   r   r   ™   s    zHashMissing.__init__c             C   sH   ddl m} d }| jr4| jjr&| jjnt| jdd ƒ}d|p<d|| jf S )Nr   )ÚFAVORITE_HASHr5   z    %s --hash=%s:%szunknown package)Úpip.utils.hashesr=   r5   Úoriginal_linkÚgetattrr<   )r   r=   Úpackager   r   r   r#       s    zHashMissing.bodyN)r   r	   r
   r   r   r(   r   r#   r   r   r   r   r:      s
   r:   c               @   s   e Zd ZdZdZdZdS )ÚHashUnpinnedzPA requirement had a hash specified but was not pinned to a specific
    version.é   zaIn --require-hashes mode, all requirements must have their versions pinned with ==. These do not:N)r   r	   r
   r   r   r(   r   r   r   r   rB   ±   s   rB   c               @   s0   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
S )ÚHashMismatchzî
    Distribution file hash values don't match.

    :ivar package_name: The name of the package that triggered the hash
        mismatch. Feel free to write to this after the exception is raise to
        improve its error message.

    é   zÞTHESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.c             C   s   || _ || _dS )zí
        :param allowed: A dict of algorithm names pointing to lists of allowed
            hex digests
        :param gots: A dict of algorithm names pointing to hashes we
            actually got from the files under suspicion
        N)ÚallowedÚgots)r   rF   rG   r   r   r   r   É   s    zHashMismatch.__init__c             C   s   d| j ƒ | jƒ f S )Nz
    %s:
%s)r4   Ú_hash_comparison)r   r   r   r   r#   Ó   s    zHashMismatch.bodyc                sj   dd„ }g }xRt | jƒD ]D\}}||ƒ‰ |j‡ fdd„|D ƒƒ |jd| j| jƒ  ƒ d‰ qW dj|ƒS )aE  
        Return a comparison of actual and expected hash values.

        Example::

               Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
                            or 123451234512345123451234512345123451234512345
                    Got        bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef

        c             S   s   t | gtdƒƒS )Nz    or)r   r   )Ú	hash_namer   r   r   Úhash_then_orâ   s    z3HashMismatch._hash_comparison.<locals>.hash_then_orc             3   s   | ]}d t ˆ ƒ|f V  qdS )z        Expected %s %sN)Únext)r$   r   )Úprefixr   r   r%   ê   s   z0HashMismatch._hash_comparison.<locals>.<genexpr>z             Got        %s
z    orr&   )r   rF   r)   r   rG   Ú	hexdigestr*   )r   rJ   r+   rI   Ú	expectedsr   )rL   r   rH   ×   s    
zHashMismatch._hash_comparisonN)	r   r	   r
   r   r   r(   r   r#   rH   r   r   r   r   rD   º   s   
rD   c               @   s   e Zd ZdZdS )ÚUnsupportedPythonVersionzMUnsupported python version according to Requires-Python package
    metadata.N)r   r	   r
   r   r   r   r   r   rO   ò   s   rO   N)r   Ú
__future__r   Ú	itertoolsr   r   r   Úpip._vendor.sixr   Ú	Exceptionr   r   r   r   r   r   r   r   r   r   r   r   r2   r7   r8   r:   rB   rD   rO   r   r   r   r   Ú<module>   s,   ,		$	8