HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/__pycache__/testutils.cpython-38.pyc
U

>�^ˌ�
@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZddlmZzddlZWn&ek
r�ZzdZW5dZ[XYnXddlmZddlmZddlmZdd	lmZddlZdd
lm Z ddl!Z"ddl#m$Z$ddl!m%Z%dd
l"m&Z&ddl'Z'ej(�rLe'j)j*e'j)_+ej,�-�Z.e�/d�Z0da1dd�Z2dd�Z3dd�Z4dd�Z5dd�Z6dd�Z7e
j8dd��Z9dTdd�Z:dd �Z;dUd#d$�Z<Gd%d&�d&e'j)�Z=Gd'd(�d(e=�Z>Gd)d*�d*e?�Z@Gd+d,�d,e?�ZAe
j8d-d.��ZBe
j8dVd0d1��ZCGd2d3�d3e'j)�ZDGd4d5�d5eD�ZEGd6d7�d7e'j)�ZFGd8d9�d9e?�ZGGd:d;�d;eH�ZIGd<d=�d=e?�ZJd>d?�ZKdWdBdC�ZLdDdE�ZMdFdG�ZNdHdI�ZOGdJdK�dKe'j)�ZPGdLdM�dMe�ZQGdNdO�dOe?�ZRGdPdQ�dQeH�ZSGdRdS�dSe?�ZTdS)Xa^Test utilities for the AWS CLI.

This module includes various classes/functions that help in writing
CLI unit/integration tests.  This module should not be imported by
any module **except** for test code.  This is included in the CLI
package so that code that is not part of the CLI can still take
advantage of all the testing utilities we provide.

�N)�pformat)�Popen�PIPE)�StringIO)�six)�Session)�ClientError)�WaiterError)�AWSResponse)�load_plugins)�	CLIDriver)�EnvironmentVariableszawscli.tests.integrationcs�fdd�}|S)z�Decorator to skip tests that should not be run on windows.

    Example usage:

        @skip_if_windows("Not valid")
        def test_some_non_windows_stuff(self):
            self.assertEqual(...)

    cst�t��dk��|�S)N)�Darwin�Linux)�unittestZskipIf�platform�system)�func��reason��2/usr/lib/python3/dist-packages/awscli/testutils.py�	decoratorXs
��z"skip_if_windows.<locals>.decoratorr)rrrrr�skip_if_windowsNs
rc	Cs:zt�|d�Wn$ttfk
r4t�|d�YnXdS)z4Helper function to set an invalid last modified time)���l����h�])rrN)�os�utime�OSError�
OverflowError)�pathrrr�set_invalid_utime^sr cCsFtj��}|j}|�d��tj�}|s*g}tj	�
|�|�dt�|S)N�	data_pathZdata_loader)�awscliZ	clidriver�create_clidriver�sessionZget_config_variable�splitr�pathsep�_LOADERZsearch_paths�extendZregister_component)�driverr$r!rrrr#js
r#cCsbddl}tdkr^tj�tj�|j��}tj�|dd�}tj�|�sZt	d�}|dkrZt
d��|atS)Nr�bin�awsz�Could not find "aws" executable.  Either make sure it is on your PATH, or you can explicitly set this value using "set_aws_cmd()")r"�AWS_CMDrr�dirname�abspath�__file__�join�isfile�_search_path_for_cmd�
ValueError)r"Z	repo_root�aws_cmdrrr�get_aws_cmdusr5cCsBtj�dd��tj�D]&}tj�||�}tj�|�r|SqdS)N�PATH�)r�environ�getr%r&rr0r1)Zcmd_namerZ
full_cmd_pathrrrr2�s

r2cCs|adS�N)r,)r4rrr�set_aws_cmd�sr;c	csft��}dttd��}tj�||�}t|d���z t||��}|VW5QRXW5t	�
|�XdS)afThis is a cross platform temporary file creation.

    tempfile.NamedTemporary file on windows creates a secure temp file
    that can't be read by other processes and can't be opened a second time.

    For tests, we generally *want* them to be read multiple times.
    The test fixture writes the temp file contents, the test reads the
    temp file.

    z
tmpfile-%s��wN)�tempfile�mkdtemp�str�random_charsrrr0�open�close�shutil�rmtree)�modeZtemporary_directory�basenameZ
full_filename�frrr�temporary_file�srIc
Cs�|sd}|jd|d�}|r |}nt�}d|i}|dkrBd|i|d<z|jf|�Wn:tk
r�}z|jd�d	�d
krzn�W5d}~XYnX|S)zG
    Creates a bucket
    :returns: the name of the bucket created
    �	us-west-2�s3�Zregion_name�Bucket�	us-east-1ZLocationConstraintZCreateBucketConfiguration�Error�CodeZBucketAlreadyOwnedByYouN)�
create_client�random_bucket_name�
create_bucketr�responser9)r$�name�region�client�bucket_name�params�errrrS�s rScCst�t�t|d����d�S)zZReturns random hex characters.

    Useful for creating resources with random names.

    ��ascii)�binasciiZhexlifyr�urandom�int�decode)Z	num_charsrrrrA�srA�awscli-s3integ-�cCs|t|�S)aGenerate a random S3 bucket name.

    :param prefix: A prefix to use in the bucket name.  Useful
        for tracking resources.  This default value makes it easy
        to see which buckets were created from CLI integ tests.
    :param num_random: Number of random chars to include in the bucket name.

    :returns: The name of a randomly generated bucket name as a string.

    )rA)�prefixZ
num_randomrrrrR�srRc@s eZdZdZdd�Zdd�ZdS)�BaseCLIDriverTestz�Base unittest that use clidriver.

    This will load all the default plugins as well so it
    will simulate the behavior the user will see.
    cCsHtjdddddd�|_t�d|j�|_|j��t�|_|jj|_dS)N�
AWS_DATA_PATHrN�
access_key�
secret_keyr7�re�AWS_DEFAULT_REGION�AWS_ACCESS_KEY_ID�AWS_SECRET_ACCESS_KEY�AWS_CONFIG_FILE�
os.environ)	rr8�mock�patch�
environ_patch�startr#r)r$��selfrrr�setUp�s�
zBaseCLIDriverTest.setUpcCs|j��dSr:)rp�stoprrrrr�tearDown�szBaseCLIDriverTest.tearDownN)�__name__�
__module__�__qualname__�__doc__rtrvrrrrrd�s
rdcsHeZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Z�Z	S)
�BaseAWSHelpOutputTestcs<tt|���t�d�|_|j��|_t�|_	|j	|j_
dS)Nzawscli.help.get_renderer)�superr{rtrnro�renderer_patchrqZ
renderer_mock�CapturedRenderer�renderer�return_valuerr��	__class__rrrt�s
zBaseAWSHelpOutputTest.setUpcstt|���|j��dSr:)r|r{rvr}rurrr�rrrv�szBaseAWSHelpOutputTest.tearDowncCs&||jjkr"|�d||jjf�dS)NzFThe expected contents:
%s
were not in the actual rendered contents:
%s�r�rendered_contents�fail)rs�containsrrr�assert_containss��z%BaseAWSHelpOutputTest.assert_containscCs4|jj�|�}||kr0|�d|||jj|f�dS)NzkThe expected contents:
%s
, with the count:
%d
were not in the actual rendered  contents:
%s
with count:
%d)rr��countr�)rsr�r�Zr_countrrr�assert_contains_with_counts��z0BaseAWSHelpOutputTest.assert_contains_with_countcCs&||jjkr"|�d||jjf�dS)NzKThe contents:
%s
were not suppose to be in the actual rendered contents:
%sr��rs�contentsrrr�assert_not_containss��z)BaseAWSHelpOutputTest.assert_not_containscs�|�d�}t|�}|jj�|�|����|����fdd�|D�}|d}t|dd�d�D]R\}}|dkr�|�d||�f�||kr�|�d||||d�f�|}q^dS)	N�
starting_fromcsg|]}��|���qSr)�find)�.0�arg�r�Zstart_indexrr�
<listcomp>sz;BaseAWSHelpOutputTest.assert_text_order.<locals>.<listcomp>r�rz/The string %r was not found in the contents: %szBThe string %r came before %r, but was suppose to come after it.
%s)�pop�listrr��assertInr��	enumerater�)rs�args�kwargsr�Zarg_indicesZprevious�i�indexrr�r�assert_text_orders"


��z'BaseAWSHelpOutputTest.assert_text_order)
rwrxryrtrvr�r�r�r��
__classcell__rrr�rr{�sr{c@seZdZdd�Zdd�ZdS)r~cCs
d|_dS)Nr7)r�rrrrr�__init__)szCapturedRenderer.__init__cCs|�d�|_dS)N�utf-8)r`r�r�rrr�render,szCapturedRenderer.renderN)rwrxryr�r�rrrrr~(sr~c@seZdZdd�ZdS)�CapturedOutputcCs||_||_dSr:)�stdout�stderr)rsr�r�rrrr�1szCapturedOutput.__init__N)rwrxryr�rrrrr�0sr�c
csPt��}t��}t�d|��*t�d|��t||�VW5QRXW5QRXdS)Nz
sys.stderrz
sys.stdout)rrrnror�)r�r�rrr�capture_output6s
r��c	csFt�|�}tjr t��}||_n|}t�d|��|VW5QRXdS)Nz	sys.stdin)r�BytesIO�PY3rn�Mock�bufferro)Zinput_bytes�
input_dataZmock_objectrrr�
capture_input?s
r�c@sTeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	dd�Z
ddd�ZdS)�BaseAWSCommandParamsTestNcCs�i|_d|_tjddddddd�|_t�d|j�|_|j��tddid�|_	i|_
t�d	�|_d
|_g|_
d|_t�|_dS)NrerNrfrgr7)rerirjrkrlZAWS_SHARED_CREDENTIALS_FILErm��z'botocore.endpoint.Endpoint.make_requestF)�last_params�last_kwargsrr8rnrorprqr
�
http_response�parsed_response�make_request_patch�make_request_is_patched�operations_called�parsed_responsesr#r)rrrrrrtOs$�
zBaseAWSCommandParamsTest.setUpcCs$|j��|jr |j��d|_dS�NF)rprur�r�rrrrrrvis

z!BaseAWSCommandParamsTest.tearDowncKs|�|�dSr:)�
_store_params)rsrYr�rrr�before_callpsz$BaseAWSCommandParamsTest.before_callcCs||_|d|_dS)NZbody)Zlast_request_dictr�)rsrYrrrr�ssz&BaseAWSCommandParamsTest._store_paramscsR�jr�j��d�_�j��}�jdk	r:�fdd�|_n�j�jf|_d�_dS)NFcs�j�j�d�fS�Nr)r�r�r�)r�r�rrrr�<lambda>�sz=BaseAWSCommandParamsTest.patch_make_request.<locals>.<lambda>T)	r�r�rurqr�Zside_effectr�r�r�)rsr�rrrr�patch_make_requestws


z+BaseAWSCommandParamsTest.patch_make_requestrc	Cs�|�||�\}}}|dk	r&|�||�|dk	r�t�|j�}	|dk	rl|D]$}
z
|	|
=WqFtk
rhYqFXqF||	kr�|�dt|�t|	�f�|||fS)NzGActual params did not match expected params.
Expected:

%s
Actual:

%s
)�run_cmdr��copyr��KeyErrorr�r)rs�cmdrY�expected_rcZstderr_containsZ
ignore_paramsr�r��rcr��keyrrr�assert_params_for_cmd�s$
��z.BaseAWSCommandParamsTest.assert_params_for_cmdcKs||_|j�||��f�dSr:)r�r��appendr�)rsrYZmodelr�rrr�before_parameter_build�sz/BaseAWSCommandParamsTest.before_parameter_buildc
Cs�t�d|�|��|jj�d�}|�d|j�|�d|j	�t
|t�sR|��}n|}t
��@}z|j�|�}Wn(tk
r�}z
|j}W5d}~XYnXW5QRX|j��}|j��}	|�||d||||	|f�|	||fS)NzCalling cmd: %s�
event_emitterzbefore-callzbefore-parameter-build.*.*�MUnexpected rc (expected: %s, actual: %s) for command: %s
stdout:
%sstderr:
%s)�logging�debugr�r)r$�
get_component�registerr�Zregister_firstr��
isinstancer�r%r��main�
SystemExit�coder��getvaluer��assertEqual)
rsr�r�r��cmdlist�capturedr�rZr�r�rrrr��s>�

"

���z BaseAWSCommandParamsTest.run_cmd)NrNN)r)rwrxryZmaxDiffrtrvr�r�r�r�r�r�rrrrr�Ls�
r�cs(eZdZ�fdd�Z�fdd�Z�ZS)�BaseAWSPreviewCommandParamsTestcs(t�d�|_|j��tt|���dS)Nz-awscli.customizations.preview.mark_as_preview)rnro�
preview_patchrqr|r�rtrrr�rrrt�s
�
z%BaseAWSPreviewCommandParamsTest.setUpcs|j��tt|���dSr:)r�rur|r�rvrrr�rrrv�s
z(BaseAWSPreviewCommandParamsTest.tearDown)rwrxryrtrvr�rrr�rr��sr�c@s6eZdZdd�Zdd�Zdidfdd�Zd
d
d�ZdS)�BaseCLIWireResponseTestcCsPtjdddddd�|_t�d|j�|_|j��t�d�|_d	|_t�|_	dS)
NrerNrfrgr7rhrmz botocore.endpoint.Endpoint._sendF)
rr8rnrorprq�
send_patch�send_is_patchedr#r)rrrrrrt�s�
zBaseCLIWireResponseTest.setUpcCs$|j��|jr |j��d|_dSr�)rprur�r�rrrrrrv�s

z BaseCLIWireResponseTest.tearDownr�r�cCs<|jr|j��d|_|j��}tj|||d�|_d|_dS)NF)�status_code�headers�contentT)r�r�rurqrnr�r�)rsr�r�r�r�rrr�
patch_send�s

�z"BaseCLIWireResponseTest.patch_sendrc	Cs�t|t�s|��}n|}t��@}z|j�|�}Wn(tk
rX}z
|j}W5d}~XYnXW5QRX|j�	�}|j
�	�}|�||d|||||f�|||fS)Nr�)r�r�r%r�r)r�r�r�r�r�r�r�)	rsr�r�r�r�r�rZr�r�rrrr��s.

"

���zBaseCLIWireResponseTest.run_cmdN)r)rwrxryrtrvr�r�rrrrr��s
r�c@s6eZdZdd�Zdd�Zd
dd�Zd	d
�Zdd�ZdS)�FileCreatorcCst��|_dSr:)r>r?�rootdirrrrrrr�szFileCreator.__init__cCstj�|j�rt�|j�dSr:)rr�existsr�rDrErrrrr�
remove_allszFileCreator.remove_allNr=c	Cs�tj�|j|�}tj�tj�|��s6t�tj�|��t||��}|�|�W5QRXtj�	|�}t�
|||df�|dk	r�t�
|||f�|S)a�Creates a file in a tmpdir

        ``filename`` should be a relative path, e.g. "foo/bar/baz.txt"
        It will be translated into a full path in a tmp dir.

        If the ``mtime`` argument is provided, then the file's
        mtime will be set to the provided value (must be an epoch time).
        Otherwise the mtime is left untouched.

        ``mode`` is the mode the file should be opened either as ``w`` or
        `wb``.

        Returns the full path to the file.

        i�N)rrr0r��isdirr-�makedirsrB�write�getmtimer)rs�filenamer��mtimerF�	full_pathrHZcurrent_timerrr�create_file	szFileCreator.create_filec	CsZtj�|j|�}tj�tj�|��s6t�tj�|��t|d��}|�|�W5QRX|S)z�Append contents to a file

        ``filename`` should be a relative path, e.g. "foo/bar/baz.txt"
        It will be translated into a full path in a tmp dir.

        Returns the full path to the file.
        �a)	rrr0r�r�r-r�rBr�)rsr�r�r�rHrrr�append_file%szFileCreator.append_filecCstj�|j|�S)zzTranslate relative path to full path in temp dir.

        f.full_path('foo/bar.txt') -> /tmp/asdfasd/foo/bar.txt
        )rrr0r�)rsr�rrrr�4szFileCreator.full_path)Nr=)rwrxryr�r�r�r�r�rrrrr�s

r�c@seZdZdS)�ProcessTerminatedErrorN�rwrxryrrrrr�<sr�c@s"eZdZddd�Zedd��ZdS)�ResultNcCsL||_||_||_t�d|�t�d|�t�d|�|dkrBg}||_dS)Nzrc: %sz
stdout: %sz
stderr: %s)r�r�r��	INTEG_LOGr��memory_usage)rsr�r�r�r�rrrr�AszResult.__init__cCst�|j�Sr:)�json�loadsr�rrrrrr�LszResult.json)N)rwrxryr��propertyr�rrrrr�@s
r�cCs|�dd�}|�dd�}|S)N�"z\"�')�replace)�commandrrr�_escape_quotesQsr�FTcCst��dkrt|�}dtjkr*tjd}n
dt�}d||f}t�}t|tj	�rbtj
sb|�|�}t�
d|�tj��}	d|	kr�d|	d<|dk	r�|}	|dkr�t}t|tt|d	|	d
�}
|s�|
Sd}|s�i}|r�d|i}|
jf|�\}
}nt|
�\}
}}t|
j|
�|�|�|�|�S)a]Run an aws command.

    This help function abstracts the differences of running the "aws"
    command on different platforms.

    If collect_memory is ``True`` the the Result object will have a list
    of memory usage taken at 2 second intervals.  The memory usage
    will be in bytes.

    If env_vars is None, this will set the environment variables
    to be used by the aws process.

    If wait_for_finish is False, then the Process object is returned
    to the caller.  It is then the caller's responsibility to ensure
    proper cleanup.  This can be useful if you want to test timeout's
    or how the CLI responds to various signals.

    :type input_data: string
    :param input_data: This string will be communicated to the process through
        the stdin of the process.  It essentially allows the user to
        avoid having to use a file handle to pass information to the process.
        Note that this string is not passed on creation of the process, but
        rather communicated to the process.

    :type input_file: a file handle
    :param input_file: This is a file handle that will act as the
        the stdin of the process immediately on creation.  Essentially
        any data written to the file will be read from stdin of the
        process. This is needed if you plan to stream data into stdin while
        collecting memory.
    ZWindowsZAWS_TEST_COMMANDz	python %sz%s %szRunning command: %srirNNT)r�r��stdin�shell�env�input)rrr�rr8r5�get_stdout_encodingr�rZ	text_typer��encoder�r�r�rr�communicate�_wait_and_collect_memr��
returncoder`)r�Zcollect_memoryZenv_varsZwait_for_finishr�Z
input_fileZaws_commandZfull_commandZstdout_encodingr��process�memoryr�r�r�rrrr+[sF!




��r+cCsttjdd�}|dkrd}|S)N�encodingr�)�getattr�sys�
__stdout__)rrrrr��sr�cCs�t��dkrt}n"t��dkr$t}ntdt����g}|��dkrxz||j�}Wntk
rjYqxYnX|�|�q8|��\}}|||fS)Nrrz0Can't collect memory for process on platform %s.)	rr�_get_memory_with_psr3Zpoll�pidr�r�r�)rZ
get_memoryrZcurrentr�r�rrrr��s$��
r�cCsfd��}|�t|��t|td�}|��d}|jdksFtt|���nt|�	�d��d�dSdS)Nzps u -p)r�rr��i)
r%r�r@rrr�rr�r_�
splitlines)rZcommand_list�pr�rrrr�s
rc@s�eZdZdZddddgZdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zd;dd�Zd<dd�Z
d=dd�Zdd�Zdd �Zd!d"�Zd>d$d%�Zd&d'�Zd?d(d)�Zd@d*d+�Zd,d-�Zd.d/�Zd0d1�ZdAd2d3�ZdBd4d5�ZdCd7d8�Zd9d:�ZdS)D�BaseS3CLICommandz�Base class for aws s3 command.

    This contains convenience functions to make writing these tests easier
    and more streamlined.

    ZSSECustomerAlgorithmZSSECustomerKeyZSSECustomerKeyMD5ZRequestPayercCs@t�|_tj��|_i|_d|_|jjd|jd�|_|�	�dS)NrJrKrL)
r��files�botocorer$Zget_session�regionsrVrQrW�extra_setuprrrrrrt�szBaseS3CLICommand.setUpcCsdSr:rrrrrrr�szBaseS3CLICommand.extra_setupcCs|j��|��dSr:)r
r��extra_teardownrrrrrrv�s
zBaseS3CLICommand.tearDowncCsdSr:rrrrrrr�szBaseS3CLICommand.extra_teardowncKs|j�d�}|jf|�dS)NZresponse_parser_factory)r$r�Zset_parser_defaults)rsr��factoryrrr�override_parser�sz BaseS3CLICommand.override_parsercCs$|j�||j�}|jjd|d�}|S)NrKrL)rr9rVr$rQ)rsrXrVrWrrr�create_client_for_bucket�sz)BaseS3CLICommand.create_client_for_bucketcCsd|�||�t|tj�r&|���d�}|�||�}|�t|�t|��||kr`|�	d||f�dS)Nr�z?Contents for %s/%s do not match (but they have the same length))
�wait_until_key_existsr�rr�r�r`�get_key_contentsr��lenr�)rsZbucketr�Zexpected_contentsZactual_contentsrrr�assert_key_contents_equal�s�z*BaseS3CLICommand.assert_key_contents_equalNcCs>|s
|j}t|j||�}||j|<|�|j|�|�|�|Sr:)rVrSr$r�
addCleanup�
delete_bucket�wait_bucket_exists)rsrUrVrXrrrrSs

zBaseS3CLICommand.create_bucketr7c	sz��|�}|||d�}|dk	r(|�|�|jf|�}���j||�i}|rft�fdd�|��D��}�j|||d�|S)N)rM�Key�Bodyc3s$|]\}}|�jkr||fVqdSr:)�_PUT_HEAD_SHARED_EXTRAS)r��k�vrrrr�	<genexpr>s
�z.BaseS3CLICommand.put_object.<locals>.<genexpr>)�extra_params)r�update�
put_objectr�
delete_key�dict�itemsr)	rsrX�key_namer�Z
extra_argsrWZ	call_argsrTZextra_head_paramsrrrrr$s(
�
��zBaseS3CLICommand.put_objectr	cCs�|�|�|�|�}|}|d8}z|j|d�WqrWq|jjk
rn|�|�rVYqr|dkr`�t�|�YqXq|j�	|d�dS)Nr��rMr)
�remove_all_objectsrr�
exceptionsZNoSuchBucket�bucket_not_exists�time�sleeprr�)rsrX�attempts�delayrWZattempts_remainingrrrr's


zBaseS3CLICommand.delete_bucketcCsb|�|�}|�d�}|j|d�}g}|D]}|dd�|�dg�D�7}q(|D]}|�||�qLdS)NZlist_objectsr)cSsg|]}|d�qS)rr)r��objrrrr�Dsz7BaseS3CLICommand.remove_all_objects.<locals>.<listcomp>ZContents)rZ
get_paginatorZpaginater9r%)rsrXrWZ	paginatorZpagesZ	key_namesZpager(rrrr*>s

z#BaseS3CLICommand.remove_all_objectscCs|�|�}|j||d�}dS�N�rMr)rZ
delete_object�rsrXr(rWrTrrrr%Hs
zBaseS3CLICommand.delete_keycCs6|�||�|�|�}|j||d�}|d���d�S)Nr3rr�)rrZ
get_object�readr`r4rrrrLs
z!BaseS3CLICommand.get_key_contents�cs8|���}|�d��t|dd�}|���fdd��dS)NZ
bucket_existsT)�
min_successes�delay_initial_pollcs�j�d�dkS)Nr))�waitr�rX�waiterrrr�Xr�z5BaseS3CLICommand.wait_bucket_exists.<locals>.<lambda>)r�
get_waiter�ConsistencyWaiterr9)rsrXr7rWZconsistency_waiterrr:rrRs

��z#BaseS3CLICommand.wait_bucket_existsc
Cs`|�|�}z|j|d�WdStk
rZ}z |j�d�dkrHWY�
dS�W5d}~XYnXdS)Nr)TrPZ404F)rZhead_bucketrrTr9)rsrXrW�errorrrrr,[s

z"BaseS3CLICommand.bucket_not_existsc	Cs6z|j|||d�WdSttfk
r0YdSXdS�N)r7TF)rrr	�rsrXr(r7rrr�
key_existses�zBaseS3CLICommand.key_existsc	Cs6z|j|||d�WdSttfk
r0YdSXdSr?)�wait_until_key_not_existsrr	r@rrr�key_not_existsms�zBaseS3CLICommand.key_not_existscCs|j��}|dS)NZBuckets)rW�list_buckets)rsrTrrrrDus
zBaseS3CLICommand.list_bucketscCs|�||�}|dS)NZContentType)�head_object)rsrXr(Zparsedrrr�content_type_for_keyysz%BaseS3CLICommand.content_type_for_keycCs|�|�}|j||d�}|Sr2)rrEr4rrrrE}s
zBaseS3CLICommand.head_objectcCs|j||||dd�dS)NT�r���
_wait_for_key�rsrXr(r"r7rrrr�s
�z&BaseS3CLICommand.wait_until_key_existscCs|j||||dd�dS)NFrGrHrJrrrrB�s
�z*BaseS3CLICommand.wait_until_key_not_existsTc
Cs^|�|�}|r|�d�}n
|�d�}||d�}|dk	r@|�|�t|�D]}	|jf|�qHdS)NZ
object_existsZobject_not_existsr3)rr<r#�ranger9)
rsrXr(r"r7r�rWr;rY�_rrrrI�s



zBaseS3CLICommand._wait_for_keycCs^|�|jdd|j|j|jf�|�d|j�|�d|j�|�d|j�|�d|j�dS)NrzNon zero rc (%s) received: %szError:zfailed:zclient errorzserver error)r�r�r�r�ZassertNotIn)rsrrrr�assert_no_errors�s�z!BaseS3CLICommand.assert_no_errors)NN)r7N)r	r	)r6)r6)r6)Nr6)Nr6)Nr6T)rwrxryrzrrtrrvrrrrrSr$rr*r%rrr,rArCrDrFrErrBrIrMrrrrr�sJ�




	


�
�
�

rc@seZdZdd�ZdS)�StringIOWithFileNocCsdSr�rrrrrr�fileno�szStringIOWithFileNo.filenoN)rwrxryrOrrrrrN�srNc@s*eZdZddd�Zedd��Zdd�ZdS)	�TestEventHandlerNcCs||_d|_dSr�)�_handler�_called)rs�handlerrrrr��szTestEventHandler.__init__cCs|jSr:)rRrrrrr�called�szTestEventHandler.calledcKs d|_|jdk	r|jf|�dS)NT)rRrQ)rsr�rrrrS�s
zTestEventHandler.handler)N)rwrxryr�r�rTrSrrrrrP�s

rPc@seZdZdS)�ConsistencyWaiterExceptionNr�rrrrrU�srUc@s*eZdZdZd
dd�Zdd	�Zd
d�ZdS)r=a�
    A waiter class for some check to reach a consistent state.

    :type min_successes: int
    :param min_successes: The minimum number of successful check calls to
    treat the check as stable. Default of 1 success.

    :type max_attempts: int
    :param min_successes: The maximum number of times to attempt calling
    the check. Default of 20 attempts.

    :type delay: int
    :param delay: The number of seconds to delay the next API call after a
    failed check call. Default of 5 seconds.
    r��r	FcCs||_||_||_||_dSr:)r7�max_attemptsr0r8)rsr7rWr0r8rrrr��szConsistencyWaiter.__init__cOstd}d}|jrt�|j�||jkr\|d7}|||�rN|d7}||jkrZdSqt�|j�q|�||�}t|��dS)a�
        Wait until the check succeeds the configured number of times

        :type check: callable
        :param check: A callable that returns True or False to indicate
        if the check succeeded or failed.

        :type args: list
        :param args: Any ordered arguments to be passed to the check.

        :type kwargs: dict
        :param kwargs: Any keyword arguments to be passed to the check.
        rr�N)r8r-r.r0rWr7�
_fail_messagerU)rsZcheckr�r�r/�	successesZfail_msgrrrr9�s


zConsistencyWaiter.waitcCs||f}d|S)Nz/Failed after %s attempts, only had %s successesr)rsr/rYZformat_argsrrrrX�szConsistencyWaiter._fail_messageN)r�rVr	F)rwrxryrzr�r9rXrrrrr=�s�
r=)NN)rarb)r�)FNTNN)Urzrrr�rDr-r�r�r>r�
contextlib�stringr]Zpprintr�
subprocessrrZ
awscli.compatrrn�ImportErrorrZrZbotocore.sessionrZbotocore.exceptionsrr	Zbotocore.loadersrZbotocore.awsrequestr
Zawscli.clidriverr"Z
awscli.pluginrrr
rZPY2ZTestCaseZassertItemsEqualZassertCountEqual�loaders�Loaderr'Z	getLoggerr�r,rr r#r5r2r;�contextmanagerrIrSrArRrdr{�objectr~r�r�r�r�r�r�r��	Exceptionr�r�r�r+r�r�rrrNrPrUr=rrrr�<module>
s�	



	
3
t5;
�
EV