
þîh�  ã               @   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 m	 Z	 d  d l
 m Z m Z d  d l m Z m Z e j e ƒ Z Gd d „  d e ƒ Z e e e d	 d
 d � „  Z d S)é    N)ÚValues)ÚCommand)ÚERRORÚSUCCESS)ÚFAVORITE_HASHÚSTRONG_HASHES)Úread_chunksÚwrite_outputc               @   sV   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 d d t d d d t d	 d
 j 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 {}z, r   )Úcmd_optsÚ
add_optionr   r   ÚformatÚjoinÚparserÚinsert_option_group)Úself© r   ú:/tmp/pip-build-zijwfla7/pip/pip/_internal/commands/hash.pyÚadd_options   s    	zHashCommand.add_options)ÚoptionsÚargsr   c             C   sW   | s |  j  j t j ƒ t S| j } x* | D]" } t d | | t | | ƒ ƒ q- Wt 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__ÚusageZignore_require_venvr   r   ÚlistÚstrÚintr$   r   r   r   r   r
      s
   r
   )r#   r   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   ÚarchiveÚhashÚchunkr   r   r   r"   4   s
    r"   )r/   Úloggingr    Úoptparser   Zpip._internal.cli.base_commandr   Zpip._internal.cli.status_codesr   r   Zpip._internal.utils.hashesr   r   Zpip._internal.utils.miscr   r	   Ú	getLoggerr%   Úloggerr
   r+   r"   r   r   r   r   Ú<module>   s   &