U
��.e� � @ s� d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl m
Z
mZ d dlm
Z
mZ e�e�ZG dd� de�Zd d
� ZdS )� )�absolute_importN)�Command)�ERROR)�
FAVORITE_HASH�
STRONG_HASHES)�read_chunks�write_outputc s0 e Zd ZdZdZdZ� fdd�Zdd� Z� ZS )�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] ...Tc sJ t t| �j||� | jjdddtdtdd�t� d� | j� d| j� d S ) Nz-az--algorithm� algorithmZstorez$The hash algorithm to use: one of %sz, )�dest�choices�action�default�helpr )
�superr �__init__Zcmd_optsZ
add_optionr r �join�parserZinsert_option_group)�self�args�kw�� __class__� �?/usr/lib/python3.8/site-packages/pip/_internal/commands/hash.pyr s ��zHashCommand.__init__c C s> |s| j �tj� tS |j}|D ]}td||t||�� q d S )Nz%s:
--hash=%s:%s)r Zprint_usage�sys�stderrr r
r �
_hash_of_file)r Zoptionsr r
�pathr r r �run) s �zHashCommand.run) �__name__�
__module__�__qualname__�__doc__ZusageZignore_require_venvr r �
__classcell__r r r r r s
r c C s@ t | d��(}t�|�}t|�D ]}|�|� qW 5 Q R X |�� S )z!Return the hash digest of a file.�rb)�open�hashlib�newr �updateZ hexdigest)r r
�archive�hash�chunkr r r r 4 s
r )Z
__future__r r' Zloggingr Zpip._internal.cli.base_commandr Zpip._internal.cli.status_codesr Zpip._internal.utils.hashesr r Zpip._internal.utils.miscr r Z getLoggerr Zloggerr r r r r r � s
"