B
    Uvg                 @   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 eeZG dd deZd	d
 ZdS )    )absolute_importN)Command)ERROR)FAVORITE_HASHSTRONG_HASHES)read_chunksc                   s8   e Zd Zd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.

    hashz%prog [options] <file> ...z#Compute hashes of package archives.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-install-r_9ig3yj/pip/pip/_internal/commands/hash.pyr      s    zHashCommand.__init__c          	   C   sD   |s| j tj tS |j}x"|D ]}td||t|| q"W d S )Nz%s:
--hash=%s:%s)	r   print_usagesysstderrr   r
   loggerinfo_hash_of_file)r   optionsr   r
   pathr   r   r   run(   s    
zHashCommand.run)__name__
__module____qualname____doc__nameusagesummaryignore_require_venvr   r&   __classcell__r   r   )r   r   r      s   r   c          	   C   sD   t | d,}t|}xt|D ]}|| q W W dQ R X | S )z!Return the hash digest of a file.rbN)openhashlibnewr   update	hexdigest)r%   r
   archiver	   chunkr   r   r   r#   3   s
    
r#   )
__future__r   r2   loggingr   pip._internal.cli.base_commandr   pip._internal.cli.status_codesr   pip._internal.utils.hashesr   r   pip._internal.utils.miscr   	getLoggerr'   r!   r   r#   r   r   r   r   <module>   s   
$