o
    rMf?                     @   s@   d dl Z d dlZd dlmZmZ d dlmZ G dd deZdS )    N)TreeHashDoesNotMatchErrorDownloadArchiveError)tree_hash_from_strc                   @   sp   e Zd ZdZdZdddZdd Zdd	d
Zdd Zede	j
ffddZede	j
ffddZdd Zdd ZdS )Jobi  @ ))ActionactionN)	ArchiveId
archive_idN)ArchiveSizeInBytesarchive_sizer   )	Completed	completedF)CompletionDatecompletion_dateN)CreationDatecreation_dateN)InventorySizeInBytesinventory_sizer   )JobDescriptiondescriptionN)JobIdidN)SHA256TreeHashsha256_treehashN)SNSTopic	sns_topicN)
StatusCodestatus_codeN)StatusMessagestatus_messageN)VaultARNarnNNc                 C   sR   || _ |r| jD ]\}}}t| |||  qd S | jD ]\}}}t| || qd S N)vaultResponseDataElementssetattr)selfr#   response_dataresponse_name	attr_namedefault r+   R/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/boto/glacier/job.py__init__2   s   zJob.__init__c                 C   s
   d| j  S )NzJob(%s))r!   )r&   r+   r+   r,   __repr__;   s   
zJob.__repr__Fc                 C   sZ   | j j| j j| j|}|r+d|v r+| }t|}|d |kr+td||d |f |S )a&  
        This operation downloads the output of the job.  Depending on
        the job type you specified when you initiated the job, the
        output will be either the content of an archive or a vault
        inventory.

        You can download all the job output or download a portion of
        the output by specifying a byte range. In the case of an
        archive retrieval job, depending on the byte range you
        specify, Amazon Glacier returns the checksum for the portion
        of the data. You can compute the checksum on the client and
        verify that the values match to ensure the portion you
        downloaded is the correct data.

        :type byte_range: tuple
        :param range: A tuple of integer specifying the slice (in bytes)
            of the archive you want to receive

        :type validate_checksum: bool
        :param validate_checksum: Specify whether or not to validate
            the associate tree hash.  If the response does not contain
            a TreeHash, then no checksum will be verified.

        TreeHashZThe calculated tree hash %s does not match the expected tree hash %s for the byte range %s)r#   layer1get_job_outputnamer   readr   r   )r&   
byte_rangevalidate_checksumresponsedataactual_tree_hashr+   r+   r,   
get_output>   s   
zJob.get_outputc                 C   s   t t| jt| S r"   )intmathceilr   float)r&   
chunk_sizer+   r+   r,   _calc_num_chunksd   s   zJob._calc_num_chunksTc                 C   sL   |  |}t|d}| ||||| W d   dS 1 sw   Y  dS )a  Download an archive to a file by name.

        :type filename: str
        :param filename: The name of the file where the archive
            contents will be saved.

        :type chunk_size: int
        :param chunk_size: The chunk size to use when downloading
            the archive.

        :type verify_hashes: bool
        :param verify_hashes: Indicates whether or not to verify
            the tree hashes for each downloaded chunk.

        wbN)r@   open_download_to_fileob)r&   filenamer?   verify_hashesretry_exceptions
num_chunksoutput_filer+   r+   r,   download_to_fileg   s   

"zJob.download_to_filec                 C   s    |  |}| ||||| dS )a  Download an archive to a file object.

        :type output_file: file
        :param output_file: The file object where the archive
            contents will be saved.

        :type chunk_size: int
        :param chunk_size: The chunk size to use when downloading
            the archive.

        :type verify_hashes: bool
        :param verify_hashes: Indicates whether or not to verify
            the tree hashes for each downloaded chunk.

        N)r@   rC   )r&   rH   r?   rE   rF   rG   r+   r+   r,   download_to_fileobj}   s   

zJob.download_to_fileobjc                 C   sj   t |D ].}|| |d | d f}| ||\}}	|r-t|}
|	|
kr-td|
|	|f || qd S )N   r0   )range_download_byte_ranger   r   write)r&   fileobjrG   r?   rE   rF   ir5   r8   expected_tree_hashr9   r+   r+   r,   rC      s    zJob._download_to_fileobc                 C   sj   t dD ](}z| |}| }|d }||fW   S  |y, } zW Y d }~qd }~ww td||f )N   r/   z/There was an error downloadingbyte range %s: %s)rL   r:   r4   r   )r&   r5   rF   _r7   r8   rQ   er+   r+   r,   rM      s   
zJob._download_byte_ranger"   )NF)__name__
__module____qualname__DefaultPartSizer$   r-   r.   r:   r@   socketerrorrI   rJ   rC   rM   r+   r+   r+   r,   r      s     
	
&

r   )	r<   rY   boto.glacier.exceptionsr   r   boto.glacier.utilsr   objectr   r+   r+   r+   r,   <module>   s
   