
}_=                 @   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
 d  d l m Z m Z e j e  Z Gd d   d e  Z d	 d
   Z d S)    )absolute_importN)Command)ERROR)read_chunks)FAVORITE_HASHSTRONG_HASHESc                   sF   e  Z d  Z d Z d Z d Z d Z   f d d   Z d d   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.c                sq   t  t |   j | |   |  j j d d d d d t d d d t d	 d
 d j t  |  j j	 d |  j  d  S)Nz-az--algorithmdest	algorithmchoicesactionstoredefaulthelpz$The hash algorithm to use: one of %sz, r   )
superr   __init__cmd_opts
add_optionr   r   joinparserinsert_option_group)selfargskw)	__class__ 0/tmp/pip-build-3_sjtvrs/pip/pip/commands/hash.pyr      s    		zHashCommand.__init__c             C   sZ   | s |  j  j t j  t S| j } x- | D]% } t j d | | t | |   q- Wd  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summaryr   r&   r   r   )r   r   r      s   r   c          
   C   sV   t  |  d  : } t j |  } x! t |  D] } | j |  q. WWd QRX| j   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   r0   loggingr   pip.basecommandr   pip.status_codesr   	pip.utilsr   pip.utils.hashesr   r   	getLoggerr'   r!   r   r#   r   r   r   r   <module>   s   #