File manager - Edit - /home/u478019808/domains/bestandroidphones.store/public_html/static/img/logo/boto_resumable_upload.cpython-39.pyc.tar
Back
opt/gsutil/gslib/__pycache__/boto_resumable_upload.cpython-39.pyc 0000644 00000035563 15025234161 0021177 0 ustar 00 a +(Wg�b � @ s d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl Z ddl Z ddlZddlm Z ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ejr�e Z!G dd� de"�Z#dS )ap Boto translation layer for resumable uploads. See https://cloud.google.com/storage/docs/resumable-uploads-xml for details. Resumable uploads will retry interrupted uploads, resuming at the byte count completed by the last upload attempt. If too many retries happen with no progress (per configurable num_retries param), the upload will be aborted in the current process. Unlike the boto implementation of resumable upload handler, this class does not directly interact with tracker files. Originally Google wrote and contributed this code to the boto project, then copied that code back into gsutil on the release of gsutil 4.0 which supports both boto and non-boto codepaths for resumable uploads. Any bug fixes made to this file should also be integrated to resumable_upload_handler.py in boto, where applicable. TODO: gsutil-beta: Add a similar comment to the boto code. � )�absolute_import)�print_function)�division)�unicode_literalsN)�urllib)�http_client)�config)� UserAgent)�AWSAuthConnection)�ResumableTransferDisposition)�ResumableUploadException)�InvalidUrlError)�GetMaxRetryDelay)� GetNumRetries)�XML_PROGRESS_CALLBACKS)�UTF8c @ s� e Zd ZdZdZejeej ej fZdZddd�Z dd� Zdd d�Zdd � Zdd� Zddd�Zdd� Zdd� Zdd� Zd dd�Zddefdd�ZdS )!�BotoResumableUploadz3Upload helper class for resumable uploads via boto.i )r ���Nc C s8 |r| � |� nd| _|| _d| _d| _|| _|| _dS )ae Constructor. Instantiate once for each uploaded file. Args: tracker_callback: Callback function that takes a string argument. Used by caller to track this upload across upload interruption. logger: logging.logger instance to use for debug messages. resume_url: If present, attempt to resume the upload at this URL. num_retries: Number of times to retry the upload making no progress. This count resets every time we make progress, so the upload can span many more than this number of retries. Nr )� _SetUploadUrl� upload_url�num_retries�service_has_bytes�upload_start_point�tracker_callback�logger)�selfr r � resume_urlr � r �*/opt/gsutil/gslib/boto_resumable_upload.py�__init__U s zBotoResumableUpload.__init__c C sd t j�|�}|j�� dvs |js,td| ��|| _t� ddd�pD|j| _ d|j|jf | _ d| _dS )z�Saves URL and resets upload state. Called when we start a new resumable upload or get a new tracker URL for the upload. Args: url: URL string for the upload. Raises InvalidUrlError if URL is syntactically invalid. )�http�httpszInvalid upload URL (%s)�Credentials�gs_hostNz%s?%sr )r �parse�urlparse�scheme�lower�netlocr r r �get�upload_url_host�path�query�upload_url_pathr )r �url�parse_resultr r r r r s ��z!BotoResumableUpload._SetUploadUrl�*c C s d||f S )Nzbytes %s/%sr )r � range_specZlength_specr r r �_BuildContentRangeHeader� s z,BotoResumableUpload._BuildContentRangeHeaderc C s. | � d|�dd�}tj|d| j| j|| jd�S )a� Queries service to find out state of given upload. Note that this method really just makes special case use of the fact that the upload service always returns the current start/end state whenever a PUT doesn't complete. Args: conn: HTTPConnection to use for the query. file_length: Total length of the file. Returns: HTTP response from sending request. Raises: ResumableUploadException if problem querying service. r0 �0)� Content-Range�Content-Length�PUT�r+ � auth_path�headers�host)r2 r �make_requestr- r* )r �conn�file_length�put_headersr r r �_QueryServiceState� s ��z&BotoResumableUpload._QueryServiceStatec C s� | � ||�}|jdkr"d|d fS |jdkr>td|j tj��d}|�d�}|r�t�d|�}|r�t|� d��}t|� d ��}d }n| j S |s�tdt|�� � tj��|j dkr�| j� d||� ||fS ) a� Queries service to find out what bytes it currently has. Args: conn: HTTPConnection to use for the query. file_length: Total length of the file. Returns: (service_start, service_end), where the values are inclusive. For example, (0, 2) would mean that the service has bytes 0, 1, *and* 2. Raises: ResumableUploadException if problem querying service. �� r � i4 z2Got non-308 response (%s) from service state queryF�rangezbytes=(\d+)-(\d+)� Tz7Couldn't parse upload service state query response (%s)zService has: Range: %d - %d.)r? �statusr r � START_OVER� getheader�re�search�long�group�SERVICE_HAS_NOTHING�str� getheaders�debugr ) r r<