HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/customizations/s3/__pycache__/results.cpython-310.pyc
o

.&�ah�@s8ddlmZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddlm
Z
ddlmZmZdd	lmZdd
lmZddlmZddlmZdd
lmZe�e�Zedgd��Zdefdd�Zeddg�Zedgd��Zed�Zeddg�Z ed�Z!eddg�Z"ede"d�Z#edddg�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,d-�d-e+�Z,Gd.d/�d/e(�Z-Gd0d1�d1e(�Z.Gd2d3�d3e&�Z/Gd4d5�d5e/�Z0Gd6d7�d7e/�Z1Gd8d9�d9e1�Z2Gd:d;�d;e1�Z3Gd<d=�d=ej4�Z5Gd>d?�d?e&�Z6dS)@�)�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)�name�extra_fields�base_cls�fields�r�B/usr/lib/python3/dist-packages/awscli/customizations/s3/results.py�_create_new_result_cls's
r�QueuedResult�total_transfer_size�ProgressResult)�bytes_transferredr �	timestamp�
SuccessResult�
FailureResult�	exception�DryRunResult�ErrorResult�CtrlCResult)r�
CommandResult�num_tasks_failed�num_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|_||_|dur|j|_dSdS)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__cKs6|�|�|j|jj}tdi|��}|j�|�dS�Nr)�_add_to_result_kwargs_cacher5�meta�transfer_idrr4�put)r8�future�kwargs�
result_kwargs�
queued_resultrrr�	on_queued^s
zBaseResultSubscriber.on_queuedcKs6|j|jj}td|t��d�|��}|j�|�dS)N)r"r#r)r5r=r>r!�timer4r?)r8r@r"rArB�progress_resultrrr�on_progressds��z BaseResultSubscriber.on_progresscCs$|�|�}|j�tdi|���dSr;)�%_on_done_pop_from_result_kwargs_cacher4r?r$�r8r@rBrrr�_on_successks
z BaseResultSubscriber._on_successcCsZ|�|�}t|t�rt}t|t�rt}|j�||d��dS|j�tdd|i|���dS)N�r&r&r)	rH�
isinstancerr)rr(r4r?r%)r8r@�erB�error_result_clsrrr�_on_failureos


z BaseResultSubscriber._on_failurecCs4|�|�\}}|j|||jjd�}||j|jj<dS)N)rrrr )�
_get_src_destr6r=�sizer5r>)r8r@rrrBrrrr<ys�z0BaseResultSubscriber._add_to_result_kwargs_cachecCs|j�|jj�}|�d�|S)Nr )r5�popr=r>rIrrrrH�s
z:BaseResultSubscriber._on_done_pop_from_result_kwargs_cachecC�td��)Nz_get_src_dest()��NotImplementedError)r8r@rrrrP��z"BaseResultSubscriber._get_src_destr)r0r1r2r7r:rDrGrJrOr<rHrPrrrrr3Os


r3c@� eZdZdZdd�Zdd�ZdS)�UploadResultSubscriber�uploadcCs0|jj}|�|j�}d|jd|j}||fS�N�s3://�/)r=�	call_args�_get_src�fileobj�bucket�key�r8r@r]rrrrrrP�sz$UploadResultSubscriber._get_src_destcC�t|�Srr
�r8r_rrrr^�rVzUploadResultSubscriber._get_srcN)r0r1r2r7rPr^rrrrrX��rXc@�eZdZdd�ZdS)�UploadStreamResultSubscribercC�dS�N�-rrdrrrr^��z%UploadStreamResultSubscriber._get_srcN)r0r1r2r^rrrrrg��rgc@rW)�DownloadResultSubscriber�downloadcCs0|jj}d|jd|j}|�|j�}||fSrZ)r=r]r`ra�	_get_destr_rbrrrrP�sz&DownloadResultSubscriber._get_src_destcCrcrr
rdrrrro�rVz"DownloadResultSubscriber._get_destN)r0r1r2r7rProrrrrrm�rermc@rf)�DownloadStreamResultSubscribercCrhrirrdrrrro�rkz(DownloadStreamResultSubscriber._get_destN)r0r1r2rorrrrrp�rlrpc@�eZdZdZdd�ZdS)�CopyResultSubscriber�copycCsB|jj}|j}d|dd|d}d|jd|j}||fS)Nr[�Bucketr\�Key)r=r]�copy_sourcer`ra)r8r@r]rvrrrrrrP�s
z"CopyResultSubscriber._get_src_destN�r0r1r2r7rPrrrrrr��rrc@rq)�DeleteResultSubscriber�deletecCs$|jj}d|jd|j}|dfSrZ)r=r]r`ra)r8r@r]rrrrrP�sz$DeleteResultSubscriber._get_src_destNrwrrrrry�rxryc@rq)�BaseResultHandlerz6Base handler class to be called in the ResultProcessorcCrS)Nz
__call__()rT�r8�resultrrr�__call__�rVzBaseResultHandler.__call__N)r0r1r2�__doc__r~rrrrr{��r{c@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 receivedcCs�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�r8rrrr:�s,

�zResultRecorder.__init__cCs|j|jkSr)r�r�r�rrr�expected_totals_are_final�s��z(ResultRecorder.expected_totals_are_finalcC�|j�t|�|j�|d�dS)z0Record the result of an individual Result object�r}N)r��getr�_record_noopr|rrrr~��
�zResultRecorder.__call__cCsTt|t�s
tdt|���g}|j|j|jfD]
}|dur$|�t|��qd�	|�S)NzdAny result using _get_ongoing_dict_key must subclass from BaseResult. Provided result is of type: %s�:)
rLr�
ValueErrorrrrr�appendr	�join)r8r}�	key_parts�result_propertyrrr�_get_ongoing_dict_key�s
���
z$ResultRecorder._get_ongoing_dict_keycCs.|�|�}|j�|d�}|j�|d�}||fSr�)r�r�rRr�)r8r}�ongoing_key�total_progress�total_file_sizerrr�_pop_result_from_ongoing_dicts�s
z-ResultRecorder._pop_result_from_ongoing_dictscK�dSrr�r8rArrrr��zResultRecorder._record_noopcKsN|jdur
t��|_|j}||j|�|�<|r|j|7_|jd7_dS�N�)r�rEr r�r�r�r�)r8r}rAr rrrr�	s

��z$ResultRecorder._record_queued_resultcKs^|j}|�|�|j|�|�|7<|j|7_|j|jkr-|j|j|j|_dSdSr)r"�(_update_ongoing_transfer_size_if_unknownr�r�r#r�r�)r8r}rAr"rrrr�s
��

��z&ResultRecorder._record_progress_resultcCsn|�|�}|j|dur5|j}|jdur+||j|<|j|}||}|j|7_dS|j|j7_dSdSr)r�r�r r�r�r")r8r}r�r �ongoing_progress�unaccounted_bytesrrrr�&s



�z7ResultRecorder._update_ongoing_transfer_size_if_unknowncKs|�|�|jd7_dSr�)r�r��r8r}rArrrr�@s
z%ResultRecorder._record_success_resultcKsL|�|�\}}|dur||}|j|7_|jd7_|jd7_dSr�)r�r�r�r�)r8r}rAr�r��
progress_leftrrrr�Ds�z%ResultRecorder._record_failure_resultcK�|jd7_dSr�)r�r�rrrr�Q�z%ResultRecorder._record_warning_resultcKr�r�)r�r�rrrr�Tr�z#ResultRecorder._record_error_resultcKs|j|_dSr)r.r�r�rrrr�Wsz+ResultRecorder._record_final_expected_filesN)r0r1r2rr:r�r~r�r�r�r�r�r�r�r�r�r�r�rrrrr��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||_||_|jdurtj|_||_|jdurtj|_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_transfersr�)r8�result_recorder�out_file�
error_filerrrr:zs$


�zResultPrinter.__init__cCr�)z<Print the progress of the ongoing transfer based on a resultr�N)r�r�r�_print_noopr|rrrr~�r�zResultPrinter.__call__cKr�rrr�rrrr��r�zResultPrinter._print_noopcKs0|jj|j|�|�d�}|�|�}|�|�dS�N)r�transfer_location)�DRY_RUN_FORMAT�formatr�_get_transfer_location�_adjust_statement_padding�_print_to_out_file)r8r}rA�	statementrrrr��s�
zResultPrinter._print_dry_runcKs8|jj|j|�|�d�}|�|�}|�|�|��dSr�)�SUCCESS_FORMATr�rr�r�r��_redisplay_progress)r8r}rA�success_statementrrrr��s�

zResultPrinter._print_successcKs<|jj|j|�|�|jd�}|�|�}|�|�|��dS)N)rr�r&)�FAILURE_FORMATr�rr�r&r��_print_to_error_filer�)r8r}rA�failure_statementrrrr��s�

zResultPrinter._print_failurecKs0|jj|jd�}|�|�}|�|�|��dS)N)�message)�WARNING_FORMATr�r�r�r�r�)r8r}rA�warning_statementrrrr��s

zResultPrinter._print_warningcKs|�|jj|jd��dS)NrK)�_flush_error_statement�ERROR_FORMATr�r&r�rrrr��s�zResultPrinter._print_errorcKs|�|j�dSr)r��
CTRL_C_MSGr�rrrr���zResultPrinter._print_ctrl_ccCs|�|�}|�|�dSr)r�r�)r8�error_statementrrrr��s
z$ResultPrinter._flush_error_statementcCs.|jdur
|jj|jd�S|jj|j|jd�S)N)r)rr)r�SRC_TRANSFER_LOCATION_FORMATr�r�!SRC_DEST_TRANSFER_LOCATION_FORMATr|rrrr��s

�z$ResultPrinter._get_transfer_locationcCsd|_|��dSr�)r��_add_progress_if_neededr�rrrr��sz!ResultPrinter._redisplay_progresscCs|��r
|��dSdSr)�_has_remaining_progressr�r�rrrr��s�z%ResultPrinter._add_progress_if_neededcKs�|�t|jj|jj��}|jjdkr9t|jj|jj�}|�t|jj��}t|jj	�d}|j
j||||d�}n
|jj|jj|d�}|j�
�sM||j7}|j|dd�}t|�d|_|�|�dS)Nrz/s)�bytes_completed�expected_bytes_completed�transfer_speed�remaining_files)�files_completedr��
)�ending_charr�)�_get_expected_total�strr�r�r�r�rr"r�r��BYTE_PROGRESS_FORMATr��FILE_PROGRESS_FORMATr��_STILL_CALCULATING_TOTALSr��lenr�r�)r8rAr�r�r�r��progress_statementrrrr��sL���������	�

�zResultPrinter._print_progresscCs|j��s|jj|d�S|S)N)�expected_total)r�r��_ESTIMATED_EXPECTED_TOTALr�)r8r�rrrr�s

�z!ResultPrinter._get_expected_total�
cCs|�|jd�}||S)N� )�ljustr�)r8�print_statementr�rrrr�sz'ResultPrinter._adjust_statement_paddingcCs&|j��sdS|jj}|jj}||kS)NT)r�r�r�r�)r8�actual�expectedrrrr�s

z%ResultPrinter._has_remaining_progresscC�t||j�dSr)r
r��r8r�rrrr�"r�z ResultPrinter._print_to_out_filecCr�r)r
r�r�rrrr�%r�z"ResultPrinter._print_to_error_filecKs,|jr|��st|�d�|j�dSdSdS)N�)r�r�r
r�r�r�rrrr�(s�z;ResultPrinter._clear_progress_if_no_more_expected_transfers)NN)r�)$r0r1r2�_FILES_REMAININGr�r�r�r�r�r�r�r�r�r�r�r�r:r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�[sT�������
"	
/
r�c@rq)�NoProgressResultPrinterz,A result printer that doesn't print progresscKr�rrr�rrrr�/rkz'NoProgressResultPrinter._print_progressN)r0r1r2rr�rrrrr�-r�r�c@rW)�OnlyShowErrorsResultPrinterz,A result printer that only prints out errorscKr�rrr�rrrr�5rkz+OnlyShowErrorsResultPrinter._print_progresscKr�rrr�rrrr�8rkz*OnlyShowErrorsResultPrinter._print_successN)r0r1r2rr�r�rrrrr�3sr�c@s&eZdZddd�Zdd�Zdd�ZdS)	�ResultProcessorNcCs2tj�|�||_||_|jdurg|_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�Threadr:r4�_result_handlers�_result_handlers_enabled)r8r9�result_handlersrrrr:=s	

zResultProcessor.__init__cCsd	z%|j�d�}t|t�rt�d�WdS|jr|�|�t|t�r%d|_Wn
t	j
y0Ynwq)NTzSShutdown request received in result processing thread, shutting down result thread.F)r4r�rLr/�LOGGER�debugr�_process_resultr(r�Emptyr|rrr�runMs"
�

���zResultProcessor.runcCsT|jD]$}z||�Wqty'}ztjd|||dd�WYd}~qd}~wwdS)Nz.Error processing result %s with handler %s: %sT��exc_info)r�	Exceptionrr)r8r}�result_handlerrMrrrrbs
����zResultProcessor._process_resultr)r0r1r2r:r
rrrrrr<s
rc@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)r9r��_result_processor)r8r9r��result_processorrrrr:ms
zCommandResultRecorder.__init__cCs|j��dSr)r�startr�rrrr�szCommandResultRecorder.startcCs|j�t��|j��dSr)r9r?r/rr�r�rrr�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�r�r�r�rrr�get_command_result�s�z(CommandResultRecorder.get_command_resultcCs|j�t|��dSr)r9r?r-)r8�totalrrr�notify_total_submissions�sz.CommandResultRecorder.notify_total_submissionscCs|��|Sr)rr�rrr�	__enter__�szCommandResultRecorder.__enter__cGs>|rtjd|dd�|j�t|d��|��dS|��dS)Nz-Exception caught during command execution: %sTrrK)rrr9r?r(r)r8�exc_type�	exc_value�argsrrr�__exit__�s�zCommandResultRecorder.__exit__N)
r0r1r2r:rrrrrrrrrrrlsr)7�
__future__r�loggingr�rrE�collectionsrr�s3transfer.exceptionsrr�s3transfer.subscribersr�
awscli.compatrr	�awscli.customizations.s3.utilsrr�awscli.customizations.utilsr
rr�	getLoggerr0rrrrr!r$r%r'r(r)r*r-�objectr/r3rXrgrmrprrryr{r�r�r�r�rrrrrrr�<module>sf

���=

	S	0