o ckF[?@s@ddlZddlZddlmZmZddlmZGdddeZdS)N)TreeHashDoesNotMatchErrorDownloadArchiveError)tree_hash_from_strc@speZdZdZdZdddZddZdd d Zd d Zed e j ffddZ ed e j ffddZ ddZ ddZdS)Jobi@))ActionactionN) ArchiveId archive_idN)ArchiveSizeInBytes archive_sizer) Completed completedF)CompletionDatecompletion_dateN) CreationDate creation_dateN)InventorySizeInBytesinventory_sizer)JobDescription descriptionN)JobIdidN)SHA256TreeHashsha256_treehashN)SNSTopic sns_topicN) StatusCode status_codeN) StatusMessagestatus_messageN)VaultARNarnNNcCsR||_|r|jD] \}}}t||||qdS|jD] \}}}t|||qdSN)vaultResponseDataElementssetattr)selfr# response_data response_name attr_namedefaultr+2/usr/lib/python3/dist-packages/boto/glacier/job.py__init__2sz Job.__init__cCs d|jS)NzJob(%s))r!)r&r+r+r,__repr__;s z Job.__repr__FcCsZ|jj|jj|j|}|r+d|vr+|}t|}|d|kr+td||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#layer1get_job_outputnamerreadrr)r& byte_rangevalidate_checksumresponsedataactual_tree_hashr+r+r, get_output>s   zJob.get_outputcCstt|jt|Sr")intmathceilr float)r& chunk_sizer+r+r,_calc_num_chunksdszJob._calc_num_chunksTcCsL||}t|d}||||||WddS1swYdS)aDownload 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_hashesretry_exceptions num_chunks output_filer+r+r,download_to_filegs   "zJob.download_to_filecCs ||}||||||dS)aDownload 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&rHr?rErFrGr+r+r,download_to_fileobj}s  zJob.download_to_fileobjc Csjt|D].}|||d|df}|||\}} |r-t|} | | kr-td| | |f||qdS)Nr0)range_download_byte_rangerrwrite) r&fileobjrGr?rErFir5r8expected_tree_hashr9r+r+r,rCs  zJob._download_to_fileobc CsjtdD](}z||}|}|d}||fWS|y,}zWYd}~qd}~wwtd||f)Nr/z/There was an error downloadingbyte range %s: %s)rLr:r4r)r&r5rF_r7r8rQer+r+r,rMs   zJob._download_byte_ranger")NF)__name__ __module__ __qualname__DefaultPartSizer$r-r.r:r@socketerrorrIrJrCrMr+r+r+r,rs   &   r) r<rYboto.glacier.exceptionsrrboto.glacier.utilsrobjectrr+r+r+r,s