File: //usr/lib/python3/dist-packages/s3transfer/__pycache__/download.cpython-310.pyc
o
�y�`�m � @ s� d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl m
Z
d dlmZ d dlm
Z
d dlmZ d d lmZ d d
lmZ d dlmZ d dlmZ d d
lmZ d dlmZ d dlmZ d dlmZ e �e�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Z G dd� de�Z!G dd� de�Z"G dd � d e"�Z#G d!d"� d"e�Z$G d#d$� d$e�Z%G d%d&� d&e�Z&G d'd(� d(e�Z'G d)d*� d*e�Z(G d+d,� d,e�Z)G d-d.� d.e�Z*dS )/� N)�six��seekable)�RetriesExceededError��IN_MEMORY_DOWNLOAD_TAG)�S3_RETRYABLE_DOWNLOAD_ERRORS)�
get_callbacks)�invoke_progress_callbacks)�calculate_num_parts)�calculate_range_parameter)�FunctionContainer)�CountCallbackInvoker)�StreamReaderProgress)�DeferredOpenFile)�Task)�SubmissionTaskc @ sT e Zd ZdZdd� Zedd� �Zdd� Zdd � Zd
d� Z dd
� Z
dd� Zdd� ZdS )�DownloadOutputManagera� Base manager class for handling various types of files for downloads
This class is typically used for the DownloadSubmissionTask class to help
determine the following:
* Provides the fileobj to write to downloads to
* Get a task to complete once everything downloaded has been written
The answers/implementations differ for the various types of file outputs
that may be accepted. All implementations must subclass and override
public methods from this class.
c C s || _ || _|| _d S �N)�_osutil�_transfer_coordinator�_io_executor��self�osutil�transfer_coordinator�io_executor� r �5/usr/lib/python3/dist-packages/s3transfer/download.py�__init__4 s
zDownloadOutputManager.__init__c C � t d��)ae Determines if the target for the download is compatible with manager
:param download_target: The target for which the upload will write
data to.
:param osutil: The os utility to be used for the transfer
:returns: True if the manager can handle the type of target specified
otherwise returns False.
zmust implement is_compatible()��NotImplementedError��cls�download_targetr r r r �
is_compatible9 s z#DownloadOutputManager.is_compatiblec C s dS )z�Get the tag (if any) to associate all GetObjectTasks
:rtype: s3transfer.futures.TaskTag
:returns: The tag to associate all GetObjectTasks with
Nr �r r r r �get_download_task_tagG s z+DownloadOutputManager.get_download_task_tagc C r )a Get file-like object to use for io writes in the io executor
:type transfer_future: s3transfer.futures.TransferFuture
:param transfer_future: The future associated with upload request
returns: A file-like object to write to
z*must implement get_fileobj_for_io_writes()r! �r �transfer_futurer r r �get_fileobj_for_io_writesO s z/DownloadOutputManager.get_fileobj_for_io_writesc C s | j �| j| �|||�� dS )a Queue IO write for submission to the IO executor.
This method accepts an IO executor and information about the
downloaded data, and handles submitting this to the IO executor.
This method may defer submission to the IO executor if necessary.
N)r �submitr �get_io_write_task�r �fileobj�data�offsetr r r �queue_file_io_taskY s �z(DownloadOutputManager.queue_file_io_taskc C s t | j|||d�d�S )a Get an IO write task for the requested set of data
This task can be ran immediately or be submitted to the IO executor
for it to run.
:type fileobj: file-like object
:param fileobj: The file-like object to write to
:type data: bytes
:param data: The data to write out
:type offset: integer
:param offset: The offset to write the data to in the file-like object
:returns: An IO task to be used to write data to a file-like object
)r/ r0 r1 ��main_kwargs)�IOWriteTaskr r. r r r r- g s ��z'DownloadOutputManager.get_io_write_taskc C r )a� Get the final io task to complete the download
This is needed because based on the architecture of the TransferManager
the final tasks will be sent to the IO executor, but the executor
needs a final task for it to signal that the transfer is done and
all done callbacks can be run.
:rtype: s3transfer.tasks.Task
:returns: A final task to completed in the io executor
z"must implement get_final_io_task()r! r'