HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/awscli/customizations/s3/__pycache__/results.cpython-36.opt-1.pyc
3

�T_h�@s<ddlmZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddlm
Z
ddlmZmZdd	lmZdd
lmZddlmZddlmZdd
lmZeje�Zeddddg�Zdefdd�Zeddg�Zeddddg�Zed�Zeddg�Z ed�Z!eddg�Z"ede"d�Z#ed d!d"g�Z$ed#d$g�Z%Gd%d&�d&e&�Z'Gd'd(�d(e�Z(Gd)d*�d*e(�Z)Gd+d,�d,e)�Z*Gd-d.�d.e(�Z+Gd/d0�d0e+�Z,Gd1d2�d2e(�Z-Gd3d4�d4e(�Z.Gd5d6�d6e&�Z/Gd7d8�d8e/�Z0Gd9d:�d:e/�Z1Gd;d<�d<e1�Z2Gd=d>�d>e1�Z3Gd?d@�d@ej4�Z5GdAdB�dBe&�Z6dS)C�)�divisionN)�
namedtuple)�defaultdict)�CancelledError)�
FatalError)�BaseSubscriber)�queue�ensure_text_type)�
relative_path)�human_readable_size)�	uni_print)�
WarningResult)�OnDoneFilteredSubscriber�
BaseResult�
transfer_type�src�destcCs,t|j�}|r||7}t|t||�|fi�S)N)�list�_fields�typer)�nameZextra_fields�base_clsZfields�r�/usr/lib/python3.6/results.py�_create_new_result_cls's
r�QueuedResult�total_transfer_size�ProgressResult�bytes_transferred�	timestamp�
SuccessResult�
FailureResult�	exception�DryRunResult�ErrorResult�CtrlCResult)r�
CommandResultZnum_tasks_failedZnum_tasks_warned�FinalTotalSubmissionsResult�total_submissionsc@seZdZdS)�ShutdownThreadRequestN)�__name__�
__module__�__qualname__rrrrr)Ksr)c@sReZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�BaseResultSubscriberNcCs&||_i|_||_|dkr"|j|_dS)z�Subscriber to send result notifications during transfer process

        :param result_queue: The queue to place results to be processed later
            on.
        N)�
_result_queue�_result_kwargs_cache�_transfer_type�
TRANSFER_TYPE)�self�result_queuerrrr�__init__Rs
zBaseResultSubscriber.__init__cKs2|j|�|j|jj}tf|�}|jj|�dS)N)�_add_to_result_kwargs_cacher/�meta�transfer_idrr.�put)r2�future�kwargs�
result_kwargsZ
queued_resultrrr�	on_queued^s

zBaseResultSubscriber.on_queuedcKs6|j|jj}tf|tj�d�|��}|jj|�dS)N)rr)r/r6r7r�timer.r8)r2r9rr:r;Zprogress_resultrrr�on_progressds
z BaseResultSubscriber.on_progresscCs |j|�}|jjtf|��dS)N)�%_on_done_pop_from_result_kwargs_cacher.r8r )r2r9r;rrr�_on_successks
z BaseResultSubscriber._on_successcCsX|j|�}t|t�r:t}t|t�r&t}|jj||d��n|jjtfd|i|���dS)N)r"r")	r?�
isinstancerr%rr$r.r8r!)r2r9�er;Zerror_result_clsrrr�_on_failureos


z BaseResultSubscriber._on_failurecCs4|j|�\}}|j|||jjd�}||j|jj<dS)N)rrrr)�
_get_src_destr0r6�sizer/r7)r2r9rrr;rrrr5ysz0BaseResultSubscriber._add_to_result_kwargs_cachecCs|jj|jj�}|jd�|S)Nr)r/�popr6r7)r2r9r;rrrr?�s
z:BaseResultSubscriber._on_done_pop_from_result_kwargs_cachecCstd��dS)Nz_get_src_dest())�NotImplementedError)r2r9rrrrD�sz"BaseResultSubscriber._get_src_dest)N)r*r+r,r1r4r<r>r@rCr5r?rDrrrrr-Os


r-c@s eZdZdZdd�Zdd�ZdS)�UploadResultSubscriberZuploadcCs0|jj}|j|j�}d|jd|j}||fS)Nzs3://�/)r6�	call_args�_get_src�fileobj�bucket�key)r2r9rJrrrrrrD�sz$UploadResultSubscriber._get_src_destcCst|�S)N)r
)r2rLrrrrK�szUploadResultSubscriber._get_srcN)r*r+r,r1rDrKrrrrrH�srHc@seZdZdd�ZdS)�UploadStreamResultSubscribercCsdS)N�-r)r2rLrrrrK�sz%UploadStreamResultSubscriber._get_srcN)r*r+r,rKrrrrrO�srOc@s eZdZdZdd�Zdd�ZdS)�DownloadResultSubscriberZdownloadcCs0|jj}d|jd|j}|j|j�}||fS)Nzs3://rI)r6rJrMrN�	_get_destrL)r2r9rJrrrrrrD�sz&DownloadResultSubscriber._get_src_destcCst|�S)N)r
)r2rLrrrrR�sz"DownloadResultSubscriber._get_destN)r*r+r,r1rDrRrrrrrQ�srQc@seZdZdd�ZdS)�DownloadStreamResultSubscribercCsdS)NrPr)r2rLrrrrR�sz(DownloadStreamResultSubscriber._get_destN)r*r+r,rRrrrrrS�srSc@seZdZdZdd�ZdS)�CopyResultSubscriber�copycCsB|jj}|j}d|dd|d}d|jd|j}||fS)Nzs3://ZBucketrIZKey)r6rJ�copy_sourcerMrN)r2r9rJrVrrrrrrD�s
z"CopyResultSubscriber._get_src_destN)r*r+r,r1rDrrrrrT�srTc@seZdZdZdd�ZdS)�DeleteResultSubscriber�deletecCs$|jj}d|jd|j}|dfS)Nzs3://rI)r6rJrMrN)r2r9rJrrrrrD�sz$DeleteResultSubscriber._get_src_destN)r*r+r,r1rDrrrrrW�srWc@seZdZdZdd�ZdS)�BaseResultHandlerz6Base handler class to be called in the ResultProcessorcCstd��dS)Nz
__call__())rG)r2�resultrrr�__call__�szBaseResultHandler.__call__N)r*r+r,�__doc__r[rrrrrY�srYc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�ResultRecorderz@Records and track transfer statistics based on results receievedcCs�d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
tt�|_
i|_t|jt|jt|jt|jt|jt|jt|jt|ji|_dS)Nr)r�bytes_failed_to_transfer�files_transferred�files_failed�files_warned�errors�expected_bytes_transferred�expected_files_transferred� final_expected_files_transferred�
start_time�bytes_transfer_speedr�int�_ongoing_progress�_ongoing_total_sizesr�_record_queued_resultr�_record_progress_resultr �_record_success_resultr!�_record_failure_resultr
�_record_warning_resultr$�_record_error_resultr%r'�_record_final_expected_files�_result_handler_map)r2rrrr4�s*
zResultRecorder.__init__cCs|j|jkS)N)rerd)r2rrr�expected_totals_are_final�sz(ResultRecorder.expected_totals_are_finalcCs|jjt|�|j�|d�dS)z0Record the result of an individual Result object)rZN)rr�getr�_record_noop)r2rZrrrr[�szResultRecorder.__call__cCsXt|t�stdt|���g}x.|j|j|jgD]}|dk	r0|jt|��q0Wdj	|�S)NzdAny result using _get_ongoing_dict_key must subclass from BaseResult. Provided result is of type: %s�:)
rAr�
ValueErrorrrrr�appendr	�join)r2rZZ	key_partsZresult_propertyrrr�_get_ongoing_dict_key�s
z$ResultRecorder._get_ongoing_dict_keycCs.|j|�}|jj|d�}|jj|d�}||fS)Nr)rzrirFrj)r2rZ�ongoing_key�total_progress�total_file_sizerrr�_pop_result_from_ongoing_dicts�s
z-ResultRecorder._pop_result_from_ongoing_dictscKsdS)Nr)r2r:rrrruszResultRecorder._record_noopcKsN|jdkrtj�|_|j}||j|j|�<|r<|j|7_|jd7_dS)N�)rfr=rrjrzrcrd)r2rZr:rrrrrk	s

z$ResultRecorder._record_queued_resultcKsZ|j}|j|�|j|j|�|7<|j|7_|j|jkrV|j|j|j|_dS)N)r�(_update_ongoing_transfer_size_if_unknownrirzrrfrg)r2rZr:rrrrrls
z&ResultRecorder._record_progress_resultcCsh|j|�}|j|dkrd|j}|jdk	rT||j|<|j|}||}|j|7_n|j|j7_dS)N)rzrjrrircr)r2rZr{rZongoing_progressZunaccounted_bytesrrrr�&s



z7ResultRecorder._update_ongoing_transfer_size_if_unknowncKs|j|�|jd7_dS)Nr)r~r_)r2rZr:rrrrm@s
z%ResultRecorder._record_success_resultcKsL|j|�\}}|dk	r,||}|j|7_|jd7_|jd7_dS)Nr)r~r^r`r_)r2rZr:r|r}Z
progress_leftrrrrnDs
z%ResultRecorder._record_failure_resultcKs|jd7_dS)Nr)ra)r2r:rrrroQsz%ResultRecorder._record_warning_resultcKs|jd7_dS)Nr)rb)r2r:rrrrpTsz#ResultRecorder._record_error_resultcKs|j|_dS)N)r(re)r2rZr:rrrrqWsz+ResultRecorder._record_final_expected_filesN)r*r+r,r\r4rsr[rzr~rurkrlr�rmrnrorprqrrrrr]�s
r]c@s�eZdZdZdZdZdeZdeZdZdeZ	dZ
d	Zd
ZdZ
dZd
Zd8dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd9d.d/�Zd0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#dS):�
ResultPrinterz#{remaining_files} file(s) remainingz~{expected_total}z (calculating...)zOCompleted {bytes_completed}/{expected_bytes_completed} ({transfer_speed}) with z)Completed {files_completed} file(s) with z${transfer_type}: {transfer_location}z	(dryrun) z7{transfer_type} failed: {transfer_location} {exception}z	{message}zfatal error: {exception}zcancelled: ctrl-c receivedz{src} to {dest}z{src}NcCsv||_||_|jdkrtj|_||_|jdkr6tj|_d|_t|jt	|j
t|jt
|jt|jt|jt|jt|ji|_dS)a�Prints status of ongoing transfer

        :type result_recorder: ResultRecorder
        :param result_recorder: The associated result recorder

        :type out_file: file-like obj
        :param out_file: Location to write progress and success statements.
            By default, the location is sys.stdout.

        :type error_file: file-like obj
        :param error_file: Location to write warnings and errors.
            By default, the location is sys.stderr.
        Nr)�_result_recorder�	_out_file�sys�stdout�_error_file�stderr�_progress_lengthr�_print_progressr �_print_successr!�_print_failurer
�_print_warningr$�_print_errorr%�
_print_ctrl_cr#�_print_dry_runr'�-_clear_progress_if_no_more_expected_transfersrr)r2�result_recorderZout_fileZ
error_filerrrr4zs"

zResultPrinter.__init__cCs|jjt|�|j�|d�dS)z<Print the progress of the ongoing transfer based on a result)rZN)rrrtr�_print_noop)r2rZrrrr[�szResultPrinter.__call__cKsdS)Nr)r2r:rrrr��szResultPrinter._print_noopcKs0|jj|j|j|�d�}|j|�}|j|�dS)N)r�transfer_location)�DRY_RUN_FORMAT�formatr�_get_transfer_location�_adjust_statement_padding�_print_to_out_file)r2rZr:�	statementrrrr��s

zResultPrinter._print_dry_runcKs8|jj|j|j|�d�}|j|�}|j|�|j�dS)N)rr�)�SUCCESS_FORMATr�rr�r�r��_redisplay_progress)r2rZr:Zsuccess_statementrrrr��s

zResultPrinter._print_successcKs<|jj|j|j|�|jd�}|j|�}|j|�|j�dS)N)rr�r")�FAILURE_FORMATr�rr�r"r��_print_to_error_filer�)r2rZr:Zfailure_statementrrrr��s


zResultPrinter._print_failurecKs0|jj|jd�}|j|�}|j|�|j�dS)N)�message)�WARNING_FORMATr�r�r�r�r�)r2rZr:Zwarning_statementrrrr��s

zResultPrinter._print_warningcKs|j|jj|jd��dS)N)r")�_flush_error_statement�ERROR_FORMATr�r")r2rZr:rrrr��szResultPrinter._print_errorcKs|j|j�dS)N)r��
CTRL_C_MSG)r2rZr:rrrr��szResultPrinter._print_ctrl_ccCs|j|�}|j|�dS)N)r�r�)r2Zerror_statementrrrr��s
z$ResultPrinter._flush_error_statementcCs.|jdkr|jj|jd�S|jj|j|jd�S)N)r)rr)r�SRC_TRANSFER_LOCATION_FORMATr�r�!SRC_DEST_TRANSFER_LOCATION_FORMAT)r2rZrrrr��s
z$ResultPrinter._get_transfer_locationcCsd|_|j�dS)Nr)r��_add_progress_if_needed)r2rrrr��sz!ResultPrinter._redisplay_progresscCs|j�r|j�dS)N)�_has_remaining_progressr�)r2rrrr��sz%ResultPrinter._add_progress_if_neededcKs�|jt|jj|jj��}|jjdkrrt|jj|jj�}|jt|jj��}t|jj	�d}|j
j||||d�}n|jj|jj|d�}|jj
�s�||j7}|j|dd�}t|�d|_|j|�dS)Nrz/s)�bytes_completed�expected_bytes_completed�transfer_speed�remaining_files)Zfiles_completedr��
)�ending_charr)�_get_expected_total�strr�rdr_rcrrr^rg�BYTE_PROGRESS_FORMATr��FILE_PROGRESS_FORMATrs�_STILL_CALCULATING_TOTALSr��lenr�r�)r2r:r�r�r�r�Zprogress_statementrrrr��s4



zResultPrinter._print_progresscCs|jj�s|jj|d�S|S)N)�expected_total)r�rs�_ESTIMATED_EXPECTED_TOTALr�)r2r�rrrr�s
z!ResultPrinter._get_expected_total�
cCs|j|jd�}||S)N� )�ljustr�)r2Zprint_statementr�rrrr�sz'ResultPrinter._adjust_statement_paddingcCs&|jj�sdS|jj}|jj}||kS)NT)r�rsr_rd)r2�actualZexpectedrrrr�s

z%ResultPrinter._has_remaining_progresscCst||j�dS)N)rr�)r2r�rrrr�"sz ResultPrinter._print_to_out_filecCst||j�dS)N)rr�)r2r�rrrr�%sz"ResultPrinter._print_to_error_filecKs&|jr"|j�r"t|jd�|j�dS)N�)r�r�rr�r�)r2r:rrrr�(sz;ResultPrinter._clear_progress_if_no_more_expected_transfers)NN)r�)$r*r+r,Z_FILES_REMAININGr�r�r�r�r�r�r�r�r�r�r�r�r4r[r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�[sD
"	
/
r�c@seZdZdZdd�ZdS)�NoProgressResultPrinterz,A result printer that doesn't print progresscKsdS)Nr)r2r:rrrr�/sz'NoProgressResultPrinter._print_progressN)r*r+r,r\r�rrrrr�-sr�c@s eZdZdZdd�Zdd�ZdS)�OnlyShowErrorsResultPrinterz,A result printer that only prints out errorscKsdS)Nr)r2r:rrrr�5sz+OnlyShowErrorsResultPrinter._print_progresscKsdS)Nr)r2rZr:rrrr�8sz*OnlyShowErrorsResultPrinter._print_successN)r*r+r,r\r�r�rrrrr�3sr�c@s&eZdZddd�Zdd�Zdd�ZdS)	�ResultProcessorNcCs2tjj|�||_||_|jdkr(g|_d|_dS)aQThread to process results from result queue

        This includes recording statistics and printing transfer status

        :param result_queue: The result queue to process results from
        :param result_handlers: A list of callables that take a result in as
            a parameter to process the result for that handler.
        NT)�	threading�Threadr4r.�_result_handlers�_result_handlers_enabled)r2r3Zresult_handlersrrrr4=s	
zResultProcessor.__init__cCshxbyF|jjd�}t|t�r&tjd�P|jr6|j|�t|t�rFd|_Wqt	j
k
r^YqXqWdS)NTzSShutdown request received in result processing thread, shutting down result thread.F)r.rtrAr)�LOGGER�debugr��_process_resultr$rZEmpty)r2rZrrr�runMs



zResultProcessor.runcCsXxR|jD]H}y||�Wqtk
rN}ztjd|||dd�WYdd}~XqXqWdS)Nz.Error processing result %s with handler %s: %sT)�exc_info)r��	Exceptionr�r�)r2rZZresult_handlerrBrrrr�bszResultProcessor._process_result)N)r*r+r,r4r�r�rrrrr�<s
r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�CommandResultRecordercCs||_||_||_dS)a�Records the result for an entire command

        It will fully process all results in a result queue and determine
        a CommandResult representing the entire command.

        :type result_queue: queue.Queue
        :param result_queue: The result queue in which results are placed on
            and processed from

        :type result_recorder: ResultRecorder
        :param result_recorder: The result recorder to track the various
            results sent through the result queue

        :type result_processor: ResultProcessor
        :param result_processor: The result processor to process results
            placed on the queue
        N)r3r��_result_processor)r2r3r�Zresult_processorrrrr4mszCommandResultRecorder.__init__cCs|jj�dS)N)r��start)r2rrrr��szCommandResultRecorder.startcCs|jjt��|jj�dS)N)r3r8r)r�ry)r2rrr�shutdown�szCommandResultRecorder.shutdowncCst|jj|jj|jj�S)z�Get the CommandResult representing the result of a command

        :rtype: CommandResult
        :returns: The CommandResult representing the total result from running
            a particular command
        )r&r�r`rbra)r2rrr�get_command_result�sz(CommandResultRecorder.get_command_resultcCs|jjt|��dS)N)r3r8r')r2Ztotalrrr�notify_total_submissions�sz.CommandResultRecorder.notify_total_submissionscCs|j�|S)N)r�)r2rrr�	__enter__�szCommandResultRecorder.__enter__cGs>|r2tjd|dd�|jjt|d��|j�dS|j�dS)Nz-Exception caught during command execution: %sT)r�)r")r�r�r3r8r$r�)r2�exc_type�	exc_value�argsrrr�__exit__�s
zCommandResultRecorder.__exit__N)
r*r+r,r4r�r�r�r�r�r�rrrrr�lsr�)7Z
__future__rZloggingr�r�r=�collectionsrrZs3transfer.exceptionsrrZs3transfer.subscribersrZ
awscli.compatrr	Zawscli.customizations.s3.utilsr
rZawscli.customizations.utilsrr
rZ	getLoggerr*r�rrrrr r!r#r$r%r&r'�objectr)r-rHrOrQrSrTrWrYr]r�r�r�r�r�r�rrrr�<module>
s`


=

	S	0