⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.144
Server IP:
157.245.143.252
Server:
Linux www 6.11.0-9-generic #9-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 14 13:19:59 UTC 2024 x86_64
Server Software:
nginx/1.26.0
PHP Version:
8.3.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
lib
/
python3
/
dist-packages
/
boto3
/
s3
/
__pycache__
/
View File Name :
transfer.cpython-312.pyc
e8> R d Z ddlZddlZddlmZmZmZ ddlmZ ddl m Z ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ddlmc mZ ddlmZmZ er ddlZdd lm Z dZ!e!e!z Z" ejF e$ Z%ddZ&d Z'd Z(d Z) G d de Z G d d Z* G d de Z+y)az Abstractions over S3's upload/download operations. This module provides high level abstractions for efficient uploads/downloads. It handles several things for the user: * Automatically switching to multipart transfers when a file is over a specific size threshold * Uploading/downloading a file in parallel * Progress callbacks to monitor transfers * Retries. While botocore handles retries for streaming uploads, it is not possible for it to handle retries for streaming downloads. This module handles retries for both cases so you don't need to implement any retry logic yourself. This module has a reasonable set of defaults. It also allows you to configure many aspects of the transfer process including: * Multipart threshold size * Max parallel downloads * Socket timeouts * Retry amounts There is no support for s3->s3 multipart copies at this time. .. _ref_s3transfer_usage: Usage ===== The simplest way to use this module is: .. code-block:: python client = boto3.client('s3', 'us-west-2') transfer = S3Transfer(client) # Upload /tmp/myfile to s3://bucket/key transfer.upload_file('/tmp/myfile', 'bucket', 'key') # Download s3://bucket/key to /tmp/myfile transfer.download_file('bucket', 'key', '/tmp/myfile') The ``upload_file`` and ``download_file`` methods also accept ``**kwargs``, which will be forwarded through to the corresponding client operation. Here are a few examples using ``upload_file``:: # Making the object public transfer.upload_file('/tmp/myfile', 'bucket', 'key', extra_args={'ACL': 'public-read'}) # Setting metadata transfer.upload_file('/tmp/myfile', 'bucket', 'key', extra_args={'Metadata': {'a': 'b', 'c': 'd'}}) # Setting content type transfer.upload_file('/tmp/myfile.json', 'bucket', 'key', extra_args={'ContentType': "application/json"}) The ``S3Transfer`` class also supports progress callbacks so you can provide transfer progress to users. Both the ``upload_file`` and ``download_file`` methods take an optional ``callback`` parameter. Here's an example of how to print a simple progress percentage to the user: .. code-block:: python class ProgressPercentage(object): def __init__(self, filename): self._filename = filename self._size = float(os.path.getsize(filename)) self._seen_so_far = 0 self._lock = threading.Lock() def __call__(self, bytes_amount): # To simplify we'll assume this is hooked up # to a single filename. with self._lock: self._seen_so_far += bytes_amount percentage = (self._seen_so_far / self._size) * 100 sys.stdout.write( " %s %s / %s (%.2f%%)" % ( self._filename, self._seen_so_far, self._size, percentage)) sys.stdout.flush() transfer = S3Transfer(boto3.client('s3', 'us-west-2')) # Upload /tmp/myfile to s3://bucket/key and print upload progress. transfer.upload_file('/tmp/myfile', 'bucket', 'key', callback=ProgressPercentage('/tmp/myfile')) You can also provide a TransferConfig object to the S3Transfer object that gives you more fine grained control over the transfer. For example: .. code-block:: python client = boto3.client('s3', 'us-west-2') config = TransferConfig( multipart_threshold=8 * 1024 * 1024, max_concurrency=10, num_download_attempts=10, ) transfer = S3Transfer(client, config) transfer.upload_file('/tmp/foo', 'bucket', 'key') N)PathLikefspathgetpid)HAS_CRT)ClientError)RetriesExceededError)NonThreadedExecutor)TransferConfig)TransferManager)BaseSubscriber)OSUtils)r S3UploadFailedError)create_crt_transfer_manageri c & t | rEt | | }|7t j dt dt j |S t j dt dt j t | || S )a Creates a transfer manager based on configuration :type client: boto3.client :param client: The S3 client to use :type config: boto3.s3.transfer.TransferConfig :param config: The transfer config to use :type osutil: s3transfer.utils.OSUtils :param osutil: The os utility to use :rtype: s3transfer.manager.TransferManager :returns: A transfer manager based on parameters provided zUsing CRT client. pid: z , thread: zUsing default client. pid: )_should_use_crtr loggerdebugr threading get_ident _create_default_transfer_manager)clientconfigosutilcrt_transfer_managers 3/usr/lib/python3/dist-packages/boto3/s3/transfer.pycreate_transfer_managerr s v:66J+LL)&(:i>Q>Q>S=TU (' LL %fhZz):M:M:O9PQ ,FFFCC c 8 t r*t d rt j j }nd}| j j }|r)|t j k( rt j d yt j d| dt d| d y) N)r FzEAttempting to use CRTTransferManager. Config settings may be ignored.Tz6Opting out of CRT Transfer Manager. Preferred client: z, CRT available: z, Instance Optimized: .)r has_minimum_crt_versionawscrts3is_optimized_for_systempreferred_transfer_clientlower constantsAUTO_RESOLVE_TRANSFER_CLIENTr r )r is_optimized_instancepref_transfer_clients r r r s *;7 & A A C %!;;AAC I$J$JJS LL@ 1' ;45Q 8 r c t syt j } t t |j d }t | }|| k\ S # t t f$ r Y yw xY w)z#Not intended for use outside boto3.Fr! ) r r# __version__mapintsplittuple TypeError ValueError)minimum_versioncrt_version_strcrt_version_intscrt_version_tuples r r" r" sb ((OsO$9$9#$>?!"23 // z" s *A AAc F d}|j st }t | ||| S )zACreate the default TransferManager implementation for s3transfer.N)use_threadsr r )r r r executor_clss r r r s&