HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/boto/s3/__pycache__/resumable_download_handler.cpython-310.pyc
o

ckF[�<�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddlm
Z
ddlmZddlmZ	Gdd	�d	e�Zddd�ZGd
d�de�ZdS)�N)�config�storage_uri_for_key)�AWSAuthConnection)�ResumableDownloadException)�ResumableTransferDisposition)�KeyFile)�Keyc@s eZdZdZdd�Zdd�ZdS)�ByteTranslatingCallbackHandlerz�
    Proxy class that translates progress callbacks made by
    boto.s3.Key.get_file(), taking into account that we're resuming
    a download.
    cCs||_||_dS�N��
proxied_cb�download_start_point)�selfrr
�r�D/usr/lib/python3/dist-packages/boto/s3/resumable_download_handler.py�__init__?s
z'ByteTranslatingCallbackHandler.__init__cCs|�|j||�dSr
r)r�total_bytes_uploaded�
total_sizerrr�callCs�z#ByteTranslatingCallbackHandler.callN)�__name__�
__module__�__qualname__�__doc__rrrrrrr	9sr	FcCsPt|t�r|s|��jS|s|��}|�dtj�|��}|s&|�|tj�|S)zH
    Returns size of file, optionally leaving fp positioned at EOF.
    r)	�
isinstancer�getkey�size�tell�seek�os�SEEK_END�SEEK_SET)�fp�position_to_eof�cur_pos�
cur_file_sizerrr�get_cur_file_sizeHs
r%c@s^eZdZdZdZejeej	ej
fZddd�Zdd�Z
dd	�Zd
d�Zdd
�Z		ddd�ZdS)�ResumableDownloadHandlerz*
    Handler for resumable downloads.
    �NcCs(||_||_d|_|r|��d|_dS)a
        Constructor. Instantiate once for each downloaded file.

        :type tracker_file_name: string
        :param tracker_file_name: optional file name to save tracking info
            about this download. If supplied and the current process fails
            the download, it can be retried in a new process. If called
            with an existing file containing an unexpired timestamp,
            we'll resume the transfer for this file; else we'll start a
            new resumable download.

        :type num_retries: int
        :param num_retries: the number of times we'll re-try a resumable
            download making no progress. (Count resets every time we get
            progress, so download can span many more than this number of
            retries.)
        N)�tracker_file_name�num_retries�etag_value_for_current_download�_load_tracker_file_etagr
)rr(r)rrrrbs
z!ResumableDownloadHandler.__init__c
Cs�d}zMzt|jd�}|���d�|_t|j�|jkr!td|j�Wn"tyD}z|j	t	j
kr:td|j|jf�WYd}~nd}~wwW|rN|��dSdS|rW|��ww)N�r�
zJCouldn't read etag in tracker file (%s). Restarting download from scratch.zJCouldn't read URI tracker file (%s): %s. Restarting download from scratch.)
�openr(�readline�rstripr*�len�MIN_ETAG_LEN�print�IOError�errno�ENOENT�strerror�close)r�f�errrr+~s,��
����
�
�z0ResumableDownloadHandler._load_tracker_file_etagc
Cs�|j�d�|_|jsdSd}z4zt|jd�}|�d|j�Wnty7}ztd|j|jft	j
��d}~wwW|rA|��dSdS|rJ|��ww)N�"'�wz%s
z�Couldn't write tracker file (%s): %s.
This can happenif you're using an incorrectly configured download tool
(e.g., gsutil configured to save tracker files to an unwritable directory))�etag�stripr*r(r.�writer4rr7r�ABORTr8)r�keyr9r:rrr�_save_tracker_info�s,
�����
�
�z+ResumableDownloadHandler._save_tracker_infocCs,|jrtj�|j�rt�|j�dSdSdSr
)r(r�path�exists�unlink)rrrr�_remove_tracker_file�s
��z-ResumableDownloadHandler._remove_tracker_filec	

Cs<t|dd�}	|	ra|jra|j|j�d�kra|	|jkr+td|j|	tt|��|jft	j
��|	|jkr=|jjj
dkr;td�dS|jjj
dkrHtd�|��}d	|	|jdf|d
<t||	�j}|	|_n|jjj
dkrltd�|�|�d|_|�d�t|t�r�|j||||||d|d
�n|j||||||dd�|��dS)zr
        Attempts a resumable download.

        Raises ResumableDownloadException if any problems occur.
        T)r"r;zp%s is larger (%d) than %s (%d).
Deleting tracker file, so if you re-try this download it will start from scratch�zDownload complete.NzResuming download.zbytes=%d-%d�Rangez Starting new resumable download.r��override_num_retries�	hash_algs�rJ)r%r*r=r>rr�name�strrrr@�bucket�
connection�debugr3�copyr	rr
rB�truncater�GSKey�get_file�flush)
rrAr!�headers�cb�num_cb�torrent�
version_idrKr$rrr�_attempt_resumable_download�sJ�
���



��z4ResumableDownloadHandler._attempt_resumable_download�
Fc	
Cs
|jjj}	|s	i}|jdurt�ddd�|_d}
	t|�}z|�||||||||�|��|	dkr6t	d�WdS|j
y�}z<|	dkrMt	d	|���t|t
�rw|jtjkrwt|t�rk|j||||||d|d
�n|j||||||dd�WYd}~nId}~wty�}z9|jtjkr�|	dkr�t	d|j��|jtjkr�|	dkr�t	d
|j�|���|	dkr�t	d|j�WYd}~nd}~wwt|�|kr�d}
n|
d7}
|
|jkr�tdtj��z|��Wn
tjy�Ynwd|
}
|	dkr�t	d|
|
f�t�|
�q)a�
        Retrieves a file from a Key
        :type key: :class:`boto.s3.key.Key` or subclass
        :param key: The Key object from which upload is to be downloaded
        
        :type fp: file
        :param fp: File pointer into which data should be downloaded
        
        :type headers: string
        :param: headers to send when retrieving the files
        
        :type cb: function
        :param cb: (optional) a callback function that will be called to report
             progress on the download.  The callback should accept two integer
             parameters, the first representing the number of bytes that have
             been successfully transmitted from the storage service and
             the second representing the total number of bytes that need
             to be transmitted.
        
        :type num_cb: int
        :param num_cb: (optional) If a callback is specified with the cb
             parameter this parameter determines the granularity of the callback
             by defining the maximum number of times the callback will be
             called during the file transfer.
             
        :type torrent: bool
        :param torrent: Flag for whether to get a torrent for the file

        :type version_id: string
        :param version_id: The version ID (optional)

        :type hash_algs: dictionary
        :param hash_algs: (optional) Dictionary of hash algorithms and
            corresponding hashing class that implements update() and digest().
            Defaults to {'md5': hashlib/md5.md5}.

        Raises ResumableDownloadException if a problem occurs during
            the transfer.
        N�Botor)�rTrGzResumable download complete.zCaught exception (%s)rIrLz4Caught non-retryable ResumableDownloadException (%s)zXCaught non-retryable ResumableDownloadException (%s); aborting and removing tracker filez3Caught ResumableDownloadException (%s) - will retryzeToo many resumable download attempts failed without progress. You might try this download again later�zWGot retryable failure (%d progress-less in a row).
Sleeping %d seconds before re-trying)rOrPrQr)r�getintr%r\rFr3�RETRYABLE_EXCEPTIONS�__repr__rr4r5�EPIPErTrUr�dispositionr�ABORT_CUR_PROCESS�messager@r8�httplib�IncompleteRead�time�sleep)rrAr!rWrXrYrZr[rKrQ�progress_less_iterations�had_file_bytes_before_attemptr:�sleep_time_secsrrrrU�s�
*
�
����������
���
�z!ResumableDownloadHandler.get_file)NN)Nr]FNN)rrrrr2rh�
HTTPExceptionr4�socket�error�gaierrorrbrr+rBrFr\rUrrrrr&Xs
�
0�r&)F)r5rhr�rerprj�botorr�boto.connectionr�boto.exceptionrr�boto.s3.keyfiler�boto.gs.keyrrT�objectr	r%r&rrrr�<module>s"