File: //lib/python3/dist-packages/boto/gs/__pycache__/resumable_upload_handler.cpython-310.pyc
o
ckF[�z � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm Z d dl
mZmZ d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ G d d
� d
e�ZdS )� N)�md5)�config� UserAgent)�AWSAuthConnection)�InvalidUriError)�ResumableTransferDisposition)�ResumableUploadException)�KeyFilec @ s� e Zd ZdZejeejej fZ
dZd*dd�Zdd� Z
dd � Zd
d� Zdd
� Zdd� Zdd� Zd+dd�Zdd� Zdd� Zd,dd�Zdd� Zdd� Zdd � Zd!d"� Z $d-d%d&�Zd.d(d)�ZdS )/�ResumableUploadHandleri )r ���Nc C s. || _ || _d| _d| _|r| �� d| _dS )a
Constructor. Instantiate once for each uploaded file.
:type tracker_file_name: string
:param tracker_file_name: optional file name to save tracker URI.
If supplied and the current process fails the upload, it can be
retried in a new process. If called with an existing file containing
a valid tracker URI, we'll resume the upload from this URI; else
we'll start a new resumable upload (and write the URI to this
tracker file).
:type num_retries: int
:param num_retries: the number of times we'll re-try a resumable upload
making no progress. (Count resets every time we get progress, so
upload can span many more than this number of retries.)
r N)�tracker_file_name�num_retries�server_has_bytes�tracker_uri�_load_tracker_uri_from_file�upload_start_point)�selfr r
� r �B/usr/lib/python3/dist-packages/boto/gs/resumable_upload_handler.py�__init__@ s
zResumableUploadHandler.__init__c
C s� d }z[zt | jd�}|�� �� }| �|� W n< ty8 } z|jtjkr.td| j|j f � W Y d }~nd }~w t
yR } ztd|| jf � W Y d }~nd }~ww W |r\|�� d S d S |re|�� w w )N�rzHCouldn't read URI tracker file (%s): %s. Restarting upload from scratch.zXInvalid tracker URI (%s) found in URI tracker file (%s). Restarting upload from scratch.)�openr �readline�strip�_set_tracker_uri�IOError�errno�ENOENT�print�strerrorr �close)r �f�uri�er r r r [ s.
�������
�z2ResumableUploadHandler._load_tracker_uri_from_filec
C s� | j sdS d}z+t�t�| j tjtjB d�d��}|�| j� W d � W dS 1 s+w Y W dS tyJ } zt d| j |j
f tj��d}~ww )zM
Saves URI to tracker file if one was passed to constructor.
Ni� �wz�Couldn't write URI tracker file (%s): %s.
This can happenif you're using an incorrectly configured upload tool
(e.g., gsutil configured to save tracker files to an unwritable directory))
r �os�fdopenr �O_WRONLY�O_CREAT�writer r r r r �ABORT)r r! r# r r r �_save_tracker_uri_to_files s* ��&�
����z0ResumableUploadHandler._save_tracker_uri_to_filec C sT t � |�}|j�� dvs|jstd| ��|| _|j| _d|j|jf | _ d| _
dS )z�
Called when we start a new resumable upload or get a new tracker
URI for the upload. Saves URI and resets upload state.
Raises InvalidUriError if URI is syntactically invalid.
)�http�httpszInvalid tracker URI (%s)z%s?%sr N)�urlparse�scheme�lower�netlocr r �tracker_uri_host�path�query�tracker_uri_pathr )r r"