3
Ug                 @   s   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 d dl	m
Z
mZ d dlmZmZ d dlmZmZ ejeZG dd	 d	eZeeed
ddZdS )    N)Values)List)Command)ERRORSUCCESS)FAVORITE_HASHSTRONG_HASHES)read_chunkswrite_outputc               @   s<   e Zd ZdZdZdZddddZeee	 e
dd	d
Zd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> ...TN)returnc          
   C   s:   | j jdddtdtdjdjtd | jjd| j  d S )	Nz-az--algorithm	algorithmstorez$The hash algorithm to use: one of {}z, )destchoicesactiondefaulthelpr   )cmd_opts
add_optionr   r   formatjoinparserinsert_option_group)self r   ?/tmp/pip-unpacked-wheel-0ht26j5g/pip/_internal/commands/hash.pyadd_options   s    zHashCommand.add_options)optionsargsr   c             C   sB   |s| j jtj tS |j}x |D ]}td||t|| q"W tS )Nz%s:
--hash=%s:%s)	r   print_usagesysstderrr   r   r
   _hash_of_filer   )r   r   r   r   pathr   r   r   run(   s    
zHashCommand.run)__name__
__module____qualname____doc__usageignore_require_venvr   r   r   strintr%   r   r   r   r   r      s
   r   )r$   r   r   c          
   C   sD   t | d,}tj|}xt|D ]}|j| q W W dQ R X |j S )z!Return the hash digest of a file.rbN)openhashlibnewr	   update	hexdigest)r$   r   archivehashchunkr   r   r   r#   5   s
    
r#   )r0   loggingr!   optparser   typingr   pip._internal.cli.base_commandr   pip._internal.cli.status_codesr   r   pip._internal.utils.hashesr   r   pip._internal.utils.miscr	   r
   	getLoggerr&   loggerr   r,   r#   r   r   r   r   <module>   s   
&