U
    «ÃT_Ç  ã                   @   s‚   d dl m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
mZ d dlmZmZ e e¡ZG dd„ deƒZd	d
„ ZdS )é    )Úabsolute_importN)ÚCommand)ÚERROR)ÚFAVORITE_HASHÚSTRONG_HASHES)Úread_chunksÚwrite_outputc                       s0   e Zd ZdZdZdZ‡ fdd„Zdd„ Z‡  ZS )ÚHashCommandz�
    Compute a hash of a local package archive.

    These can be used with --hash in a requirements file to do repeatable
    installs.
    z%prog [options] <file> ...Tc                    sJ   t t| ƒj||Ž | jjdddtdtdd t¡ d� | j 	d| j¡ d S )	Nz-az--algorithmÚ	algorithmÚstorez$The hash algorithm to use: one of %sz, )ÚdestÚchoicesÚactionÚdefaultÚhelpr   )
Úsuperr	   Ú__init__Úcmd_optsÚ
add_optionr   r   ÚjoinÚparserÚinsert_option_group)ÚselfÚargsÚkw©Ú	__class__© ú?/tmp/pip-unpacked-wheel-8u7dkzi1/pip/_internal/commands/hash.pyr      s     ÿúzHashCommand.__init__c                 C   s>   |s| j  tj¡ tS |j}|D ]}td||t||ƒƒ q d S )Nz%s:
--hash=%s:%s)r   Úprint_usageÚsysÚstderrr   r
   r   Ú_hash_of_file)r   Úoptionsr   r
   Úpathr   r   r   Úrun)   s      ÿzHashCommand.run)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚusageÚignore_require_venvr   r%   Ú__classcell__r   r   r   r   r	      s
   r	   c              	   C   s@   t | dƒ�(}t |¡}t|ƒD ]}| |¡ qW 5 Q R X | ¡ S )z!Return the hash digest of a file.Úrb)ÚopenÚhashlibÚnewr   ÚupdateÚ	hexdigest)r$   r
   ÚarchiveÚhashÚchunkr   r   r   r"   4   s
    
r"   )Ú
__future__r   r/   Úloggingr    Úpip._internal.cli.base_commandr   Úpip._internal.cli.status_codesr   Úpip._internal.utils.hashesr   r   Úpip._internal.utils.miscr   r   Ú	getLoggerr&   Úloggerr	   r"   r   r   r   r   Ú<module>   s   
"