U
    -e                     @   s$  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	 e	e
ZG dd	 d	e jZG d
d deZG dd deZG dd deZG dd deZd&ee edddZG dd deZG dd deZG dd deZG dd deZee edddZd'eeed!d"d#Zd$d% ZdS )(    N)sha256)Optional   )config   )
get_loggerc                   @   s   e Zd ZdZdZdZdZdS )VerificationModea  `Enum` that specifies which verification checks to run.

    The default mode is `BASIC_CHECKS`, which will perform only rudimentary checks to avoid slowdowns
    when generating/downloading a dataset for the first time.

    The verification modes:

    |                           | Verification checks                                                           |
    |---------------------------|------------------------------------------------------------------------------ |
    | `ALL_CHECKS`              | Split checks, uniqueness of the keys yielded in case of the GeneratorBuilder  |
    |                           | and the validity (number of files, checksums, etc.) of downloaded files       |
    | `BASIC_CHECKS` (default)  | Same as `ALL_CHECKS` but without checking downloaded files                    |
    | `NO_CHECKS`               | None                                                                          |

    Z
all_checksZbasic_checksZ	no_checksN)__name__
__module____qualname____doc__Z
ALL_CHECKSZBASIC_CHECKSZ	NO_CHECKS r   r   Z/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/datasets/utils/info_utils.pyr      s   r   c                   @   s   e Zd ZdZdS )ChecksumVerificationExceptionz>Exceptions during checksums verifications of downloaded files.Nr	   r
   r   r   r   r   r   r   r   #   s   r   c                   @   s   e Zd ZdZdS )UnexpectedDownloadedFilez(Some downloaded files were not expected.Nr   r   r   r   r   r   '   s   r   c                   @   s   e Zd ZdZdS )ExpectedMoreDownloadedFilesz7Some files were supposed to be downloaded but were not.Nr   r   r   r   r   r   +   s   r   c                   @   s   e Zd ZdZdS )NonMatchingChecksumErrorz?The downloaded file checksum don't match the expected checksum.Nr   r   r   r   r   r   /   s   r   expected_checksumsrecorded_checksumsc                    s    d krt d d S tt t dkrFttt t ttt  dkrvtttt   fdd D }|d k	rd| nd}t|dkrtd| d| d	t d
|  d S )NzUnable to verify checksums.r   c                    s    g | ]} | | kr|qS r   r   ).0urlr   r   r   
<listcomp>;   s      z$verify_checksums.<locals>.<listcomp>z for  zChecksums didn't matchz:
zY
Set `verification_mode='no_checks'` to skip checksums verification and ignore this errorz&All the checksums matched successfully)loggerinfolensetr   strr   r   )r   r   Zverification_nameZbad_urlsZfor_verification_namer   r   r   verify_checksums3   s    
r    c                   @   s   e Zd ZdZdS )SplitsVerificationExceptionz%Exceptions during splis verificationsNr   r   r   r   r   r!   F   s   r!   c                   @   s   e Zd ZdZdS )UnexpectedSplitsz6The expected splits of the downloaded file is missing.Nr   r   r   r   r   r"   J   s   r"   c                   @   s   e Zd ZdZdS )ExpectedMoreSplitsz!Some recorded splits are missing.Nr   r   r   r   r   r#   N   s   r#   c                   @   s   e Zd ZdZdS )NonMatchingSplitsSizesErrorz7The splits sizes don't match the expected splits sizes.Nr   r   r   r   r   r$   R   s   r$   expected_splitsrecorded_splitsc                    s    d krt d d S tt t dkrFttt t ttt  dkrvtttt   fdd D }t|dkrtt|t d d S )NzUnable to verify splits sizes.r   c                    s2   g | ]*} | j | j kr | | d qS ))expectedZrecorded)Znum_examples)r   namer%   r   r   r   ^   s   z!verify_splits.<locals>.<listcomp>z$All the splits matched successfully.)r   r   r   r   r#   r   r"   r$   )r&   r'   Z
bad_splitsr   r%   r   verify_splitsV   s    
r*   T)pathrecord_checksumreturnc              	      sb   |rLt  }t| d0 t fdddD ]}|| q(| }W 5 Q R X nd}tj| |dS )z7Compute the file size and the sha256 checksum of a filerbc                      s
     dS )Ni   )readr   fr   r   <lambda>m       z(get_size_checksum_dict.<locals>.<lambda>r3   N)	num_byteschecksum)r   openiterupdate	hexdigestosr+   getsize)r+   r,   mchunkr5   r   r0   r   get_size_checksum_dicth   s    r>   c                 C   s   | rt jr| t jk S dS dS )zCheck if `dataset_size` is smaller than `config.IN_MEMORY_MAX_SIZE`.

    Args:
        dataset_size (int): Dataset size in bytes.

    Returns:
        bool: Whether `dataset_size` is smaller than `config.IN_MEMORY_MAX_SIZE`.
    FN)r   ZIN_MEMORY_MAX_SIZE)Zdataset_sizer   r   r   is_small_datasetu   s    	

r?   )N)T)enumr:   hashlibr   typingr   r   r   loggingr   r	   r   Enumr   	Exceptionr   r   r   r   dictr    r!   r"   r#   r$   r*   r   boolr>   r?   r   r   r   r   <module>   s&   