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/botocore/__pycache__/utils.cpython-36.pyc
3

�T_*D�J@sPddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlmZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4ej5e6�Z7dZ8dZ9dZ:ej;d	�Z<e*e)e+e,fZ=d
gZ>dddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d'd*d+d,d-d.d.dddd/d0d1d2d3d4d5d,d6d7d7d8d2d9d:d;d/d<d=d>d3d?d@dAdBdCdDdDdEd$d<dF�IZ?dGdH�Z@dIdJ�ZAdKdL�ZBdMdN�ZCdOdP�ZDdQdR�ZEd�dTdU�ZFGdVdW�dWeG�ZHGdXdY�dYeG�ZIGdZd[�d[eJ�ZKGd\d]�d]eK�ZLd�d_d`�ZMdadb�ZNeOfdcdd�ZPdedf�ZQe:fdgdh�ZRe:fdidj�ZSdkdl�ZTdmdn�ZUdodp�ZVd�dqdr�ZWd�dsdt�ZXdudv�ZYdwdx�ZZGdydz�dzeJ�Z[Gd{d|�d|eJ�Z\d}d~�Z]dd��Z^d�d��Z_d�d�d��Z`d�d�d��Zad�d��Zbd�d��Zcd�d��Zdd�d��Zed�d�d��Zfd�d�d��Zgd�d��Zhd�d��ZiGd�d��d�eJ�ZjGd�d��d�ek�ZlGd�d��d�eJ�ZmGd�d��d�eJ�ZnGd�d��d�eJ�ZoGd�d��d�eJ�ZpGd�d��d�eJ�ZqGd�d��d�eJ�Zrd�d��Zsd�d��Ztd�d�d��Zud�d��Zvd�d��Zwd�d��Zxd�d��ZyGd�d��d�eJ�ZzGd�d��d�eJ�Z{dS)��N)�tzutc)�json�quote�zip_longest�urlsplit�
urlunsplit�OrderedDict�six�urlparse�get_tzinfo_options�get_md5�
MD5_AVAILABLE)�
getproxies�proxy_bypass)�InvalidExpressionError�ConfigNotFound�InvalidDNSNameError�ClientError�MetadataRetrievalError�EndpointConnectionError�ReadTimeoutError�ConnectionClosedError�ConnectTimeoutError�UnsupportedS3ArnError�*UnsupportedS3AccesspointConfigurationError�SSOTokenLoadError�InvalidRegionError�UnsupportedOutpostResourceError�&UnsupportedS3ControlConfigurationError�UnsupportedS3ControlArnError�InvalidHostLabelError�zhttp://169.254.169.254/z-._~z-z0-9][a-z0-9\-]*[a-z0-9]�	dualstackzalexa-for-businessZmediatailorZpricingZ	sagemakerzapi-gatewayzapplication-auto-scalingZ	appstreamzauto-scalingzauto-scaling-plansz
cost-explorerzcloudhsm-v2zcloudsearch-domainzcognito-identity-providerzconfig-servicezcost-and-usage-report-serviceziot-data-planeziot-jobs-data-planezmediastore-dataz
data-pipelinezdevice-farmziot-1click-devices-servicezdirect-connectzapplication-discovery-servicezdatabase-migration-servicezdirectory-servicezdynamodb-streamszelastic-beanstalkZefszelastic-load-balancingZemrzelastic-transcoderzelastic-load-balancing-v2Zseszmarketplace-entitlement-servicezelasticsearch-serviceZeventbridgeziot-1click-projectszkinesis-analyticsz
kinesis-videozlex-model-building-servicezlex-runtime-servicezcloudwatch-logszmachine-learningzmarketplace-commerce-analyticszmarketplace-meteringz
migration-hubZ
cloudwatchZmturkZ
opsworkscmzresource-groups-tagging-apizroute-53zroute-53-domainszsagemaker-runtimeZsimpledbzsecrets-managerZserverlessapplicationrepositoryzservice-catalogZsfnzstorage-gateway)IZa4bZalexaforbusinesszapi.mediatailorzapi.pricingz
api.sagemakerZ
apigatewayzapplication-autoscalingZ
appstream2Zautoscalingzautoscaling-plansZceZ
cloudhsmv2Zcloudsearchdomainzcognito-idp�configZcurzdata.iotz
data.jobs.iotzdata.mediastoreZdatapipelineZ
devicefarmzdevices.iot1clickZ
directconnectZ	discoveryZdmsZdsZdynamodbstreamsZelasticbeanstalkZelasticfilesystemZelasticloadbalancingZelasticmapreduceZelastictranscoderZelbZelbv2Zemailzentitlement.marketplaceZes�eventszcloudwatch-eventsziot-dataz
iot-jobs-dataziot1click-devicesziot1click-projectsZkinesisanalyticsZkinesisvideoz
lex-modelszlex-runtimeZlogsZmachinelearningzmarketplace-entitlementZmarketplacecommerceanalyticszmetering.marketplaceZmeteringmarketplaceZmghz
models.lexZ
monitoringzmturk-requesterzopsworks-cmzprojects.iot1clickZresourcegroupstaggingapiZroute53Zroute53domainszruntime.lexzruntime.sagemakerZsdbZsecretsmanagerZserverlessrepoZservicecatalogZstatesZ
stepfunctionsZstoragegatewayzstreams.dynamodbZtaggingcCst|t�r|S|j�dkSdS)z~Ensures a boolean value if a string or boolean is provided

    For strings, the value for True/False is case insensitive
    �trueN)�
isinstance�bool�lower)�val�r*�/usr/lib/python3.6/utils.py�ensure_boolean�s
r,cCs2t|d�o0|jjdd�o0|jjd�dko0|jdkS)z�Determines if the provided shape is the special header type jsonvalue.

    :type shape: botocore.shape
    :param shape: Shape to be inspected for the jsonvalue trait.

    :return: True if this type is a jsonvalue, False otherwise
    :rtype: Bool
    �
serializationZ	jsonvalueF�location�header�string)�hasattrr-�get�	type_name)�shaper*r*r+�is_json_value_header�s	
r5cCsD|jjd|jjd|j��}|jdd�}|jdd�}tjdd|�}|S)zvReturns the module name for a service

    This is the value used in both the documentation and client class name
    ZserviceAbbreviationZserviceFullNameZAmazon�ZAWSz\W+)Zmetadatar2Zservice_name�replace�re�sub)Z
service_model�namer*r*r+�get_service_module_name�sr;cCs|sdSt|�S)N�/)�remove_dot_segments)�pathr*r*r+�normalize_url_path�sr?cCs�|sdS|jd�}g}x8|D]0}|r|dkr|dkrB|rL|j�q|j|�qW|ddkrbd}nd}|ddkr||r|d}nd}|dj|�|S)Nr6r<�.z..rr!���)�split�pop�append�join)�urlZ	input_urlZoutput_list�x�firstZlastr*r*r+r=�s"


r=cCs<|s|dkrt|d��xdD]}||krt|d��qWdS)Nr@)�
expression�[�]�*)rJrKrL)r)rIZinvalidr*r*r+�validate_jmespath_for_set�s


rMTcCs||rt|�|jdd�}|dt|�dkr2|dnd}}|sHt|d��|rp||kr\i||<t||||dd�S|||<dS)Nr@r!rr6)rIF)�is_first)rMrB�lenr�set_value_from_jmespath)�sourcerI�valuerN�bitsZcurrent_keyZ	remainderr*r*r+rP�s"
rPc@seZdZdZdS)�_RetriesExceededErrorz@Internal exception used when the number of retries are exceeded.N)�__name__�
__module__�__qualname__�__doc__r*r*r*r+rTsrTc@seZdZdd�ZdS)�BadIMDSRequestErrorcCs
||_dS)N)�request)�selfrZr*r*r+�__init__	szBadIMDSRequestError.__init__N)rUrVrWr\r*r*r*r+rYsrYc@speZdZeZdZdZededdfdd�Z	dd�Z
dd	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zddd�ZdS)�IMDSFetcherzlatest/api/tokenZ21600r!NcCsf||_||_||_|dkr$tjj�}|jdd�j�|_|jdk|_||_	t
jj|jt
|j�d�|_dS)NZAWS_EC2_METADATA_DISABLEDZfalser%)�timeoutZproxies)Z_timeout�
_num_attempts�	_base_url�os�environ�copyr2r(�	_disabled�_user_agent�botocore�httpsession�URLLib3Session�get_environ_proxies�_session)r[r^Znum_attemptsZbase_url�envZ
user_agentr*r*r+r\s
zIMDSFetcher.__init__cCs�|j�|j|j}d|ji}|j|�tjjd||d�}x�t|j	�D]�}yD|j
j|j��}|j
dkrl|jS|j
dkrzdS|j
d
kr�t|��WqFtk
r�dStk
r�}ztjd	||d
d�WYdd}~XqFXqFWdS)Nz$x-aws-ec2-metadata-token-ttl-secondsZPUT)�methodrF�headers������zOCaught retryable HTTP exception while making metadata service request to %s: %sT)�exc_info)rorprq)rr)�_assert_enabledr`�_TOKEN_PATH�
_TOKEN_TTL�_add_user_agentrf�
awsrequest�
AWSRequest�ranger_rj�send�prepare�status_code�textrYr�RETRYABLE_HTTP_ERRORS�logger�debug)r[rFrmrZ�i�response�er*r*r+�_fetch_metadata_token#s,




"z!IMDSFetcher._fetch_metadata_tokenc
Cs�|j�|dkr|j}|j|}i}|dk	r4||d<|j|�xzt|j�D]l}y2tjjd||d�}|j	j
|j��}||�s~|SWqJtk
r�}	zt
jd||	dd�WYdd}	~	XqJXqJW|j��dS)aZMake a get request to the Instance Metadata Service.

        :type url_path: str
        :param url_path: The path component of the URL to make a get request.
            This arg is appended to the base_url that was provided in the
            initializer.

        :type retry_func: callable
        :param retry_func: A function that takes the response as an argument
             and determines if it needs to retry. By default empty and non
             200 OK responses are retried.

        :type token: str
        :param token: Metadata token to send along with GET requests to IMDS.
        Nzx-aws-ec2-metadata-token�GET)rlrFrmzOCaught retryable HTTP exception while making metadata service request to %s: %sT)rs)rt�_default_retryr`rwrzr_rfrxryrjr{r|rr�r��_RETRIES_EXCEEDED_ERROR_CLS)
r[�url_path�
retry_func�tokenrFrmr�rZr�r�r*r*r+�_get_request=s(

"zIMDSFetcher._get_requestcCs|jdk	r|j|d<dS)Nz
User-Agent)re)r[rmr*r*r+rwbs
zIMDSFetcher._add_user_agentcCs|jrtjd�|j��dS)Nz)Access to EC2 metadata has been disabled.)rdr�r�r�)r[r*r*r+rtfs
zIMDSFetcher._assert_enabledcCs|j|�p|j|�S)N)�_is_non_ok_response�	_is_empty)r[r�r*r*r+r�ks
zIMDSFetcher._default_retrycCs"|jdkr|j|ddd�dSdS)Nrnznon-200T)�log_bodyF)r}�_log_imds_response)r[r�r*r*r+r�qs
zIMDSFetcher._is_non_ok_responsecCs|js|j|ddd�dSdS)Nzno bodyT)r�F)�contentr�)r[r�r*r*r+r�wszIMDSFetcher._is_emptyFcCs>d}||j|jg}|r*|d7}|j|j�tj|f|��dS)NzHMetadata service returned %s response with status code of %s for url: %sz, content body: %s)r}rFrDr�r�r�)r[r�Z
reason_to_logr�Z	statementZlogger_argsr*r*r+r�}szIMDSFetcher._log_imds_response)N)F)rUrVrWrTr�rurv� DEFAULT_METADATA_SERVICE_TIMEOUT�METADATA_BASE_URLr\r�r�rwrtr�r�r�r�r*r*r*r+r]
s
%r]c@sXeZdZdZddddgZdd�Zdd	d
�Zddd�Zd
d�Zdd�Z	dd�Z
dd�ZdS)�InstanceMetadataFetcherz*latest/meta-data/iam/security-credentials/�AccessKeyId�SecretAccessKey�Token�
ExpirationcCs�yl|j�}|j|�}|j||�}|j|�rJ||d|d|d|dd�Sd|krfd|krftjd|�iSWnR|jk
r�tjd	|j�Yn0tk
r�}ztjd
|j	�WYdd}~XnXiS)Nr�r�r�r�)�	role_nameZ
access_keyZ
secret_keyr�Zexpiry_time�CodeZMessagez7Error response received when retrievingcredentials: %s.z\Max number of attempts exceeded (%s) when attempting to retrieve data from metadata service.zBad IMDS request: %s)
r��
_get_iam_role�_get_credentials�_contains_all_credential_fieldsr�r�r�r_rYrZ)r[r�r��credentialsr�r*r*r+�retrieve_iam_role_credentials�s(

 z5InstanceMetadataFetcher.retrieve_iam_role_credentialsNcCs|j|j|j|d�jS)N)r�r�r�)r��	_URL_PATH�_needs_retry_for_role_namer~)r[r�r*r*r+r��sz%InstanceMetadataFetcher._get_iam_rolecCs$|j|j||j|d�}tj|j�S)N)r�r�r�)r�r��_needs_retry_for_credentialsr�loadsr~)r[r�r��rr*r*r+r��s
z(InstanceMetadataFetcher._get_credentialscCs6ytj|j�dStk
r0|j|d�dSXdS)NFzinvalid jsonT)rr�r~�
ValueErrorr�)r[r�r*r*r+�_is_invalid_json�sz(InstanceMetadataFetcher._is_invalid_jsoncCs|j|�p|j|�S)N)r�r�)r[r�r*r*r+r��s
z2InstanceMetadataFetcher._needs_retry_for_role_namecCs|j|�p|j|�p|j|�S)N)r�r�r�)r[r�r*r*r+r��s

z4InstanceMetadataFetcher._needs_retry_for_credentialscCs,x&|jD]}||krtjd|�dSqWdS)Nz3Retrieved credentials is missing required field: %sFT)�_REQUIRED_CREDENTIAL_FIELDSr�r�)r[r�Zfieldr*r*r+r��sz7InstanceMetadataFetcher._contains_all_credential_fields)N)N)rUrVrWr�r�r�r�r�r�r�r�r�r*r*r*r+r��s"

r�FcCs�x�|D]�}t||t�rJ||kr<||kr<t||||�q�||||<qt||t�r�|r�||kr�t||t�r�||j||�q�||||<q||||<qWdS)z�Given two dict, merge the second dict into the first.

    The dicts can have arbitrary nesting.

    :param append_lists: If true, instead of clobbering a list with the new
        value, append all of the new values onto the original list.
    N)r&�dict�merge_dicts�list�extend)Zdict1Zdict2Zappend_lists�keyr*r*r+r��s
r�cCs&i}x|D]}||||j�<q
W|S)zECopies the given dictionary ensuring all keys are lowercase strings. )r()�originalrcr�r*r*r+�lowercase_dict�s
r�cCsHy$||��}|j�}t|�SQRXWntk
rBt|d��YnXdS)N)r>)�read�parse_key_val_file_contents�OSErrorr)�filename�_open�f�contentsr*r*r+�parse_key_val_files
r�cCsLi}xB|j�D]6}d|krq|jdd�\}}|j�}|j�}|||<qW|S)N�=r!)�
splitlinesrB�strip)r��final�liner�r)r*r*r+r�sr�cCs�g}t|d�r|j�}n|}x^|D]V\}}t|t�r^xB|D]}|jdt|�t|�f�q:Wq"|jdt|�t|�f�q"Wdj|�S)afUrlencode a dict or list into a string.

    This is similar to urllib.urlencode except that:

    * It uses quote, and not quote_plus
    * It has a default list of safe chars that don't need
      to be encoded, which matches what AWS services expect.

    If any value in the input ``mapping`` is a list type,
    then each list element wil be serialized.  This is the equivalent
    to ``urlencode``'s ``doseq=True`` argument.

    This function should be preferred over the stdlib
    ``urlencode()`` function.

    :param mapping: Either a dict to urlencode or a list of
        ``(key, value)`` pairs.

    �itemsz%s=%s�&)r1r�r&r�rD�percent_encoderE)�mapping�safeZ
encoded_pairsZpairsr�rR�elementr*r*r+�percent_encode_sequences



r�cCs>t|tjtjf�stj|�}t|tj�s2|jd�}t||d�S)a�Urlencodes a string.

    Whereas percent_encode_sequence handles taking a dict/sequence and
    producing a percent encoded string, this function deals only with
    taking a string (not a dict/sequence) and percent encoding it.

    If given the binary type, will simply URL encode it. If given the
    text type, will produce the binary type by UTF-8 encoding the
    text. If given something else, will convert it to the text type
    first.
    zutf-8)r�)r&r	Zbinary_typeZ	text_type�encoder)Z	input_strr�r*r*r+r�Bs



r�cCs�t|ttf�rtjj||��Sytjjt|�|��Sttfk
rJYnXytjj	|dt
�id�Sttfk
r�}ztd||f��WYdd}~XnXdS)z.Parse timestamp with pluggable tzinfo options.ZGMT)ZtzinfoszInvalid timestamp "%s": %sN)r&�int�float�datetimeZ
fromtimestamp�	TypeErrorr��dateutil�parser�parser)rR�tzinfor�r*r*r+�_parse_timestamp_with_tzinfoWsr�cCs`xNt�D]D}y
t||�Stk
rJ}ztjd|j|d�WYdd}~XqXqWtd|��dS)z�Parse a timestamp into a datetime object.

    Supported formats:

        * iso8601
        * rfc822
        * epoch (value is an integer)

    This will return a ``datetime.datetime`` object.

    z2Unable to parse timestamp with "%s" timezone info.)rsNz4Unable to calculate correct timezone offset for "%s")rr�r�r�r�rU�RuntimeError)rRr�r�r*r*r+�parse_timestampjs
"r�cCsDt|tj�r|}nt|�}|jdkr4|jt�d�}n|jt��}|S)a�Converted the passed in value to a datetime object with tzinfo.

    This function can be used to normalize all timestamp inputs.  This
    function accepts a number of different types of inputs, but
    will always return a datetime.datetime object with time zone
    information.

    The input param ``value`` can be one of several types:

        * A datetime object (both naive and aware)
        * An integer representing the epoch time (can also be a string
          of the integer, i.e '0', instead of 0).  The epoch time is
          considered to be UTC.
        * An iso8601 formatted timestamp.  This does not need to be
          a complete timestamp, it can contain just the date portion
          without the time component.

    The returned value will be a datetime object that will have tzinfo.
    If no timezone info was provided in the input value, then UTC is
    assumed, not local time.

    N)r�)r&r�r�r�r7rZ
astimezone)rRZdatetime_objr*r*r+�parse_to_aware_datetime�s
r�cCs~tjddd�}|jdkr2|dkr&t�}|j|d�}|jdd�|j�|}t|d�r\|j�S|j|j|j	ddd
dS)awCalculate the timestamp based on the given datetime instance.

    :type dt: datetime
    :param dt: A datetime object to be converted into timestamp
    :type default_timezone: tzinfo
    :param default_timezone: If it is provided as None, we treat it as tzutc().
                             But it is only used when dt is a naive datetime.
    :returns: The timestamp
    i�r!N)r��
total_seconds�i�
�i@Bi@B)
r�r�rr7Z	utcoffsetr1r�ZmicrosecondsZsecondsZdays)ZdtZdefault_timezoneZepoch�dr*r*r+�datetime2timestamp�s


r�csFtj�}x$t�fdd�d�D]}|j|�qW|r:|j�S|j�SdS)a�Calculate a sha256 checksum.

    This method will calculate the sha256 checksum of a file like
    object.  Note that this method will iterate through the entire
    file contents.  The caller is responsible for ensuring the proper
    starting position of the file and ``seek()``'ing the file back
    to its starting location if other consumers need to read from
    the file like object.

    :param body: Any file like object.  The file must be opened
        in binary mode such that a ``.read()`` call returns bytes.
    :param as_hex: If True, then the hex digest is returned.
        If False, then the digest (as binary bytes) is returned.

    :returns: The sha256 checksum

    cs
�jd�S)Nii)r�r*)�bodyr*r+�<lambda>�sz"calculate_sha256.<locals>.<lambda>�N)�hashlib�sha256�iter�update�	hexdigest�digest)r�Zas_hexZchecksum�chunkr*)r�r+�calculate_sha256�sr�cs�g}d	�tj}x.t��fdd�d�D]}|j||�j��q$W|sN|d�j�SxXt|�dkr�g}x>t|�D]2\}}|dk	r�|j|||�j��qj|j|�qjW|}qPWtj	|d�j
d�S)
a\Calculate a tree hash checksum.

    For more information see:

    http://docs.aws.amazon.com/amazonglacier/latest/dev/checksum-calculations.html

    :param body: Any file like object.  This has the same constraints as
        the ``body`` param in calculate_sha256

    :rtype: str
    :returns: The hex version of the calculated tree hash

    ics
�j��S)N)r�r*)r��required_chunk_sizer*r+r��sz%calculate_tree_hash.<locals>.<lambda>r�r!Nr�asciii)r�r�r�rDr�r�rO�	_in_pairs�binasciiZhexlify�decode)r�Zchunksr�r�Z
new_chunksrH�secondr*)r�r�r+�calculate_tree_hash�sr�cCst|�}t||�S)N)r�r)�iterableZshared_iterr*r*r+r��s	r�c@s eZdZdZdd�Zdd�ZdS)�CachedPropertyz�A read only property that caches the initially computed value.

    This descriptor will only call the provided ``fget`` function once.
    Subsequent access to this property will return the cached value.

    cCs
||_dS)N)�_fget)r[�fgetr*r*r+r\szCachedProperty.__init__cCs,|dkr|S|j|�}||j|jj<|SdS)N)r��__dict__rU)r[�obj�clsZcomputed_valuer*r*r+�__get__s

zCachedProperty.__get__N)rUrVrWrXr\r�r*r*r*r+r�sr�c@sDeZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
�Zdd�Z	dS)�ArgumentGeneratoraGenerate sample input based on a shape model.

    This class contains a ``generate_skeleton`` method that will take
    an input/output shape (created from ``botocore.model``) and generate
    a sample dictionary corresponding to the input/output shape.

    The specific values used are place holder values. For strings either an
    empty string or the member name can be used, for numbers 0 or 0.0 is used.
    The intended usage of this class is to generate the *shape* of the input
    structure.

    This can be useful for operations that have complex input shapes.
    This allows a user to just fill in the necessary data instead of
    worrying about the specific structure of the input arguments.

    Example usage::

        s = botocore.session.get_session()
        ddb = s.get_service_model('dynamodb')
        arg_gen = ArgumentGenerator()
        sample_input = arg_gen.generate_skeleton(
            ddb.operation_model('CreateTable').input_shape)
        print("Sample input for dynamodb.CreateTable: %s" % sample_input)

    FcCs
||_dS)N)�_use_member_names)r[Zuse_member_namesr*r*r+r\=szArgumentGenerator.__init__cCsg}|j||�S)z�Generate a sample input.

        :type shape: ``botocore.model.Shape``
        :param shape: The input shape.

        :return: The generated skeleton input corresponding to the
            provided input shape.

        )�_generate_skeleton)r[r4�stackr*r*r+�generate_skeleton@s
z#ArgumentGenerator.generate_skeletonr6c
Cs�|j|j�z�|jdkr$|j||�S|jdkr:|j||�S|jdkrP|j||�S|jdkrz|jrd|S|jrvtj	|j�SdS|jdkr�dS|jd	kr�d
S|jdkr�dS|jd
kr�t
j
dddddd�SWd|j�XdS)NZ	structurer��mapr0r6�integer�longrr�gZbooleanTZ	timestampi�r!)r�r�)rDr:r3�_generate_type_structure�_generate_type_list�_generate_type_mapr��enum�randomZchoicer�rC)r[r4r�r:r*r*r+r�Ms.







z$ArgumentGenerator._generate_skeletoncCsJ|j|j�dkriSt�}x*|jj�D]\}}|j|||d�||<q&W|S)Nr!)r:)�countr:r�membersr�r�)r[r4r�Zskeleton�member_nameZmember_shaper*r*r+r�gsz*ArgumentGenerator._generate_type_structurecCs$d}|jr|jj}|j|j||�gS)Nr6)r��memberr:r�)r[r4r�r:r*r*r+r�psz%ArgumentGenerator._generate_type_listcCs0|j}|j}|jdkst�td|j||�fg�S)Nr0ZKeyName)r�rRr3�AssertionErrorrr�)r[r4r�Z	key_shapeZvalue_shaper*r*r+r�zs
z$ArgumentGenerator._generate_type_mapN)F)r6)
rUrVrWrXr\r�r�r�r�r�r*r*r*r+r�#s

	
r�cCsZt|�}|j}|dkrdSt|�dkr*dS|ddkrB|dd�}tjdtj�}|j|�S)	z�Verify the endpoint_url is valid.

    :type endpoint_url: string
    :param endpoint_url: An endpoint_url.  Must have at least a scheme
        and a hostname.

    :return: True if the endpoint url is valid. False otherwise.

    NF�r!r@z;^((?!-)[A-Z\d-]{1,63}(?<!-)\.)*((?!-)[A-Z\d-]{1,63}(?<!-))$rArA)r�hostnamerOr8�compile�
IGNORECASE�match)�endpoint_url�partsrZallowedr*r*r+�is_valid_endpoint_url�s
r	cCs2|dkrdStjd�}|j|�}|s.t|d��dS)z0Provided region_name must be a valid host label.Nz)^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?<!-)$)�region_name)r8rrr)r
Zvalid_host_labelZvalidr*r*r+�validate_region_name�s

rcCsRd|krdSt|�}|dks$|dkr(dStj|�}|dksJ|j�t|�krNdSdS)a�
    Check to see if the ``bucket_name`` complies with the
    restricted DNS naming conventions necessary to allow
    access via virtual-hosting style.

    Even though "." characters are perfectly valid in this DNS
    naming scheme, we are going to punt on any name containing a
    "." character because these will cause SSL cert validation
    problems if we try to use virtual-hosting style addressing.
    r@F��?NT)rO�LABEL_REr�end)�bucket_name�nrr*r*r+�check_dns_name�s
rcKs`|jjdd�rd}yt|||�Wn8tk
rZ}z|jd}tjd|�WYdd}~XnXdS)ar
    This handler looks at S3 requests just before they are signed.
    If there is a bucket name on the path (true for everything except
    ListAllBuckets) it checks to see if that bucket name conforms to
    the DNS naming conventions.  If it does, it alters the request to
    use ``virtual hosting`` style addressing rather than ``path-style``
    addressing.

    Zuse_global_endpointFzs3.amazonaws.comrz2Not changing URI, bucket is not DNS compatible: %sN)�contextr2�switch_to_virtual_host_styler�kwargsr�r�)rZ�signature_versionr
�default_endpoint_urlrr�rr*r*r+�fix_s3_host�s
rcKs|jdk	rdSt|�r$tjd�dSt|j�}|j|_|jjd�}|dkrP|j}t	|�dk�r|d}|sndStjd|j�t
|��rt	|�dkr�|jddkr�|jd7_|j|�dj|�p�d}|}|d|}	|j
|	||jdf}
t|
�}||_tjd	|�n
t|d
��dS)a)
    This is a handler to force virtual host style s3 addressing no matter
    the signature version (which is taken in consideration for the default
    case). If the bucket is not DNS compatible an InvalidDNSName is thrown.

    :param request: A AWSRequest object that is about to be sent.
    :param signature_version: The signature version to sign with
    :param default_endpoint_url: The endpoint to use when switching to a
        virtual style. If None is supplied, the virtual host will be
        constructed from the url of the request.
    NzKRequest is GetBucketLocation operation, not checking for DNS compatibility.r<r!z*Checking for DNS compatible bucket for: %s�r@r6zURI updated to: %s)rrA)Z	auth_path�_is_get_bucket_location_requestr�r�rrFr>rB�netlocrOr�removerE�scheme�queryrr)rZrrrr�
path_partsrr>Zglobal_endpoint�hostZ	new_tupleZnew_urir*r*r+r�s<





rcCs|jjd�S)Nz	?location)rF�endswith)rZr*r*r+rsrcs"�j�tj����fdd��}|S)aMethod decorator for caching method calls to a single instance.

    **This is not a general purpose caching decorator.**

    In order to use this, you *must* provide an ``_instance_cache``
    attribute on the instance.

    This decorator is used to cache method calls.  The cache is only
    scoped to a single instance though such that multiple instances
    will maintain their own cache.  In order to keep things simple,
    this decorator requires that you provide an ``_instance_cache``
    attribute on your instance.

    cs\�|f}|r&tt|j���}�||f}|jj|�}|dk	r>|S�|f|�|�}||j|<|S)N)�tuple�sortedr�Z_instance_cacher2)r[�argsr�	cache_keyZkwarg_items�result)�func�	func_namer*r+�_cache_guard&s

z$instance_cache.<locals>._cache_guard)rU�	functools�wraps)r'r)r*)r'r(r+�instance_cachesr,cKsht|j�jjd�}dd�|D�}d}t|�dkrB|dj|�d7}|d7}|d
krVd
St||dd�d
S)z?Switches the current s3 endpoint with an S3 Accelerate endpointr@cSsg|]}|tkr|�qSr*)�S3_ACCELERATE_WHITELIST)�.0�pr*r*r+�
<listcomp>=sz-switch_host_s3_accelerate.<locals>.<listcomp>zhttps://s3-accelerate.rz
amazonaws.com�ListBuckets�CreateBucket�DeleteBucketNF)�use_new_scheme)r1r2r3)rrFrrBrOrE�
_switch_hosts)rZZoperation_namerr�endpointr*r*r+�switch_host_s3_accelerate5sr7cCs2tj|jjd��}|j|�r.||}t||�dS)zBSwitches the host using a parameter value from a JSON request bodyzutf-8N)rr��datar�r2r5)rZ�
param_nameZrequest_json�new_endpointr*r*r+�switch_host_with_paramHs
r;cCst|j||�}||_dS)N)�_get_new_endpointrF)rZr:r4�final_endpointr*r*r+r5Psr5cCsRt|�}t|�}|j}|r |j}||j|j|jdf}t|�}tjd||f�|S)Nr6zUpdating URI from %s to %s)rrrr>rrr�r�)Zoriginal_endpointr:r4Znew_endpoint_componentsZoriginal_endpoint_componentsrZfinal_endpoint_componentsr=r*r*r+r<Vsr<cCsVxP|D]H}||krBt||t�rBt||t�rBt||||�q||||<qWdS)z�Deeply two dictionaries, overriding existing keys in the base.

    :param base: The base dictionary which will be merged into.
    :param extra: The dictionary to merge into the base. Keys from this
        dictionary will take precedence.
    N)r&r��
deep_merge)�baseZextrar�r*r*r+r>is
r>cCs|jdd�j�S)zcTranslate the form used for event emitters.

    :param service_id: The service_id to convert.
    � �-)r7r()Z
service_idr*r*r+�hyphenize_service_id{srBc@sHeZdZddd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�S3RegionRedirectorNcCs,||_||_|jdkri|_tj|�|_dS)N)�_endpoint_resolver�_cache�weakref�proxy�_client)r[Zendpoint_bridgeZclient�cacher*r*r+r\�s

zS3RegionRedirector.__init__cCs<|p|jjj}|jd|j�|jd|j�|jd|j�dS)Nzneeds-retry.s3zbefore-call.s3zbefore-parameter-build.s3)rH�metar$�register�redirect_from_error�set_request_url�redirect_from_cache)r[�
event_emitterZemitterr*r*r+rK�s
zS3RegionRedirector.registercKs�|dkrdS|j|jdi��r,tjd�dS|jdi�jd�rLtjd�dS|djdi�}|jd�}|djd	i�}|d ko�|jdk}|d!ko�|jd
ko�d|jdi�k}	|dko�d|k}
|ddk	o�|djd"k}|dk}t||
||	|g��s�dS|ddd}
|djd�}|j|
|�}|dk�r>tjd||
f�dStjd||
|f�|jj	d|�}|d}||
|d�}||dd<||j
|
<|j||d�d|dd<dS)#a
        An S3 request sent to the wrong region will return an error that
        contains the endpoint the request should be sent to. This handler
        will add the redirect information to the signing context and then
        redirect the request.
        Nrz=S3 request was previously to an accesspoint, not redirecting.Z
s3_redirectedz6S3 request was previously redirected, not redirecting.r!�Errorr��ResponseMetadata�301�400Z
HeadObjectZ
HeadBucketzx-amz-bucket-region�HTTPHeadersZAuthorizationHeaderMalformed�Regionr�-�.�3ZPermanentRedirect�signing�bucket�
client_regionz�S3 client configured for region %s but the bucket %s is not in that region and the proper region could not be automatically determined.z�S3 client configured for region %s but the bucket %s is in region %s; Please configure the proper region to avoid multiple unnecessary redirects and signing attempts.�s3r)�regionrZr6T)rRrS)rRrS)rVrWrX)�_is_s3_accesspointr2r�r�r:r}�any�get_bucket_regionrDZresolverErM)r[Zrequest_dictr�Z	operationr�errorZ
error_codeZresponse_metadataZis_special_head_objectZis_special_head_bucketZis_wrong_signing_regionZis_redirect_statusZis_permanent_redirectrZr[Z
new_regionr6�signing_contextr*r*r+rL�s`





z&S3RegionRedirector.redirect_from_errorcCs�|d}|dd}d|kr$|dS|jdi�jdd�}|dk	rD|Sy|jj|d�}|dd}Wn0tk
r�}z|jdd}WYdd}~XnX|jdd�}|S)	a.
        There are multiple potential sources for the new region to redirect to,
        but they aren't all universally available for use. This will try to
        find region from response elements, but will fall back to calling
        HEAD on the bucket if all else fails.

        :param bucket: The bucket to find the region for. This is necessary if
            the region is not available in the error response.
        :param response: A response representing a service request that failed
            due to incorrect region configuration.
        r!rQrTzx-amz-bucket-regionrPrUN)�Bucket)r2rHZhead_bucketrr�)r[rZr�Zservice_responseZresponse_headersr]rmr�r*r*r+r`�s
 z$S3RegionRedirector.get_bucket_regioncKs4|jdi�jdd�}|dk	r0t|d|d�|d<dS)NrYr6rFF)r2r<)r[�paramsrrr6r*r*r+rMsz"S3RegionRedirector.set_request_urlcKsF|j|�rdS|jd�}|jj|�}|dk	r6||d<nd|i|d<dS)z�
        This handler retrieves a given bucket's signing context from the cache
        and adds it into the request context.
        NrcrYrZ)r^r2rE)r[rdrrrZrbr*r*r+rNs


z&S3RegionRedirector.redirect_from_cachecCsd|kS)N�s3_accesspointr*)r[rr*r*r+r^sz%S3RegionRedirector._is_s3_accesspoint)N)N)
rUrVrWr\rKrLr`rMrNr^r*r*r*r+rC�s


V!rCc@seZdZdS)�InvalidArnExceptionN)rUrVrWr*r*r*r+rf#srfc@seZdZdd�ZdS)�	ArnParsercCsH|jdd�}t|�dkr$td|��|d|d|d|d|dd	�S)
N�:�r�zUProvided ARN: %s must be of the format: arn:partition:service:region:account:resourcer!rr�)�	partition�servicer]�account�resource)rBrOrf)r[�arnZ	arn_partsr*r*r+�	parse_arn(szArnParser.parse_arnN)rUrVrWrpr*r*r*r+rg'srgc@s`eZdZejd�Zejd�ZdgZddd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�S3ArnParamHandlerzA^(?P<resource_type>accesspoint|outpost)[/:](?P<resource_name>.+)$zc^(?P<outpost_name>[a-zA-Z0-9\-]{1,63})[/:]accesspoint[/:](?P<accesspoint_name>[a-zA-Z0-9\-]{1,63}$)r2NcCs||_|dkrt�|_dS)N)�_arn_parserrg)r[�
arn_parserr*r*r+r\DszS3ArnParamHandler.__init__cCs|jd|j�dS)Nzbefore-parameter-build.s3)rK�
handle_arn)r[rOr*r*r+rKIszS3ArnParamHandler.registercKs`|j|jkrdS|j|�}|dkr&dS|ddkrB|j|||�n|ddkr\|j|||�dS)N�
resource_type�accesspoint�outpost)r:�_BLACKLISTED_OPERATIONS�"_get_arn_details_from_bucket_param�_store_accesspoint�_store_outpost)r[rd�modelrr�arn_detailsr*r*r+rtLs
zS3ArnParamHandler.handle_arncCsFd|krBy$|d}|jj|�}|j||�|Stk
r@YnXdS)Nrc)rrrp�_add_resource_type_and_namerf)r[rdror}r*r*r+ryWsz4S3ArnParamHandler._get_arn_details_from_bucket_paramcCs@|jj|d�}|r2|jd�|d<|jd�|d<n
t|d��dS)Nrnru�
resource_name)ro)�_RESOURCE_REGEXr�groupr)r[ror}rr*r*r+r~bs
z-S3ArnParamHandler._add_resource_type_and_namecCs8|d|d<|d|d|d|d|dd�|d<dS)	Nrrcrmrkr]rl)r:rmrkr]rlrer*)r[rdrr}r*r*r+rzjsz$S3ArnParamHandler._store_accesspointcCsd|d}|jj|�}|s"t|d��|jd�}||d<|jd�||d|d|d|d	d
�|d<dS)Nr)r�accesspoint_namerc�outpost_namermrkr]rl)r�r:rmrkr]rlre)�_OUTPOST_RESOURCE_REGEXrrr�)r[rdrr}rrr�r*r*r+r{{s

z S3ArnParamHandler._store_outpost)N)rUrVrWr8rr�r�rxr\rKrtryr~rzr{r*r*r*r+rq8s
rqc@s�eZdZdZdZd$dd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zedd��Zed d!��Zed"d#��ZdS)%�S3EndpointSetter�awsz
amazonaws.comNcCs@||_||_||_|dkr i|_||_||_|dkr<|j|_dS)N)rD�_region�
_s3_config�
_endpoint_url�
_partition�_DEFAULT_PARTITION)r[�endpoint_resolverr]�	s3_configrrkr*r*r+r\�szS3EndpointSetter.__init__cCs|jd|j�dS)Nzbefore-sign.s3)rK�set_endpoint)r[rOr*r*r+rK�szS3EndpointSetter.registercKsn|j|�r8|j|�|j|�}|j|�|j||�dS|jrPtfd|i|��|jrj|jfd|i|��dS)NrZ)�_use_accesspoint_endpoint�_validate_accesspoint_supported�(_resolve_region_for_accesspoint_endpoint�._resolve_signing_name_for_accesspoint_endpoint�_switch_to_accesspoint_endpoint�_use_accelerate_endpointr7�_s3_addressing_handler)r[rZrr
r*r*r+r��s

zS3EndpointSetter.set_endpointcCs
d|jkS)Nre)r)r[rZr*r*r+r��sz*S3EndpointSetter._use_accesspoint_endpointcCsz|jrtdd��|jr tdd��|jdd}||jkrLtd|j|fd��|jdjd�}|rv|jjd�rvtd	d��dS)
NzNClient cannot use a custom "endpoint_url" when specifying an access-point ARN.)�msgzZClient does not support s3 accelerate configuration when an access-point ARN is specified.rerkz�Client is configured for "%s" partition, but access-point ARN provided is for "%s" partition. The client and  access-point partition must be the same.r��use_dualstack_endpointzTClient does not support s3 dualstack configuration when an outpost ARN is specified.)r�rr�rr�r2r�)r[rZ�request_partionr�r*r*r+r��s
z0S3EndpointSetter._validate_accesspoint_supportedcCs2|jjdd�r,|jdd}|j||�|S|jS)N�use_arn_regionTrer])r�r2r�_override_signing_regionr�)r[rZZaccesspoint_regionr*r*r+r��s
z9S3EndpointSetter._resolve_region_for_accesspoint_endpointcCs|jdd}|j||�dS)Nrerl)r�_override_signing_name)r[rZZaccesspoint_servicer*r*r+r��sz?S3EndpointSetter._resolve_signing_name_for_accesspoint_endpointcCsTt|j�}t|j|j|j|�|j|j|j�|jdf�}t	j
d|j|f�||_dS)Nr6zUpdating URI from %s to %s)rrFrr�_get_accesspoint_netlocr�_get_accesspoint_pathr>rr�r�)r[rZr
�original_componentsZaccesspoint_endpointr*r*r+r��s

z0S3EndpointSetter._switch_to_accesspoint_endpointcCs||d}d|d|dfg}d|kr>|ddg}|j|�n
|jd�|jjd�r^|jd	�|j||j|�g�d
j|�S)Nrez%s-%sr:rmr�zs3-outpostszs3-accesspointr�r"r@)r�rDr�r2�_get_dns_suffixrE)r[�request_contextr
reZaccesspoint_netloc_componentsZoutpost_hostr*r*r+r��s

z(S3EndpointSetter._get_accesspoint_netloccCs"|dd}|jd|dd�p dS)Nrer:r<r6r!)r7)r[Z
original_pathr�r:r*r*r+r�sz&S3EndpointSetter._get_accesspoint_pathcCs,|jjd|�}|j}|r(d|kr(|d}|S)Nr\�	dnsSuffix)rD�construct_endpoint�_DEFAULT_DNS_SUFFIX)r[r
�resolved�
dns_suffixr*r*r+r�sz S3EndpointSetter._get_dns_suffixcCs$|jjdi�}||d<||jd<dS)NrYr])rr2)r[rZr
rbr*r*r+r�sz)S3EndpointSetter._override_signing_regioncCs$|jjdi�}||d<||jd<dS)NrY�signing_name)rr2)r[rZr�rbr*r*r+r�sz'S3EndpointSetter._override_signing_namecCs�|jjd�rdS|jdkrdSt|j�j}|jd�s8dS|jd�}|ddkrRdS|dd�}t|�tt|��krvdSt	d
d�|D��S)
N�use_accelerate_endpointTFz
amazonaws.comr@rz
s3-accelerater!rcss|]}|tkVqdS)N)r-)r.r/r*r*r+�	<genexpr>Isz<S3EndpointSetter._use_accelerate_endpoint.<locals>.<genexpr>���)
r�r2r�rrr!rBrO�set�all)r[rrZ
feature_partsr*r*r+r�(s


z)S3EndpointSetter._use_accelerate_endpointcCs"|jr
dS|jjd�}|r|SdS)N�virtualZaddressing_style)r�r�r2)r[Zconfigured_addressing_styler*r*r+�_addressing_styleKs
z"S3EndpointSetter._addressing_stylecCsH|jdkrtjd�tS|jdks,|jdk	r:tjd�dStjd�tS)Nr�z'Using S3 virtual host style addressing.r>zUsing S3 path style addressing.zSDefaulting to S3 virtual host style addressing with path style addressing fallback.)r�r�r�rr�r)r[r*r*r+r�Ws



z'S3EndpointSetter._s3_addressing_handler)NNNN)rUrVrWr�r�r\rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r*r*r*r+r��s&
"
			#r�c@s�eZdZdZdZejd�Zd5dd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdS)6�S3ControlEndpointSetterr�z
amazonaws.comz^[a-zA-Z0-9\-]{1,63}$NcCs@||_||_||_|dkr i|_||_||_|dkr<|j|_dS)N)rDr�r�r�r�r�)r[r�r]r�rrkr*r*r+r\ssz S3ControlEndpointSetter.__init__cCs|jd|j�dS)Nzbefore-sign.s3-control)rKr�)r[rOr*r*r+rKsz S3ControlEndpointSetter.registercKs�|j|�r@|j|�|j|�}|j|�|j||�|j|�nB|j|�r�|j|�|jd}|j	|d�|j
|j�}|j||�dS)N�
outpost_idzs3-outposts)
�_use_endpoint_from_arn_details�-_validate_endpoint_from_arn_details_supported� _resolve_region_from_arn_details�&_resolve_signing_name_from_arn_details�"_resolve_endpoint_from_arn_details�_add_headers_from_arn_details�_use_endpoint_from_outpost_id�#_validate_outpost_redirection_validrr��_construct_outpost_endpointr��_update_request_netloc)r[rZrr
r��
new_netlocr*r*r+r��s






z$S3ControlEndpointSetter.set_endpointcCs
d|jkS)Nr})r)r[rZr*r*r+r��sz6S3ControlEndpointSetter._use_endpoint_from_arn_detailscCs
d|jkS)Nr�)r)r[rZr*r*r+r��sz5S3ControlEndpointSetter._use_endpoint_from_outpost_idcCs�|j�|jjdd�sF|jdd}||jkrFd||jf}t|d��|jdd}||jkrrtd|j|fd��|jjd	�r�td
d��d|jdkr�|j|�dS)Nr�Fr}r]zpThe use_arn_region configuration is disabled but received arn for "%s" when the client is configured to use "%s")r�rkzClient is configured for "%s" partition, but arn provided is for "%s" partition. The client and arn partition must be the same.r�z7S3 control client does not support accelerate endpointsr�)�_validate_no_custom_endpointr�r2rr�rr�r�)r[rZ�
arn_region�	error_msgr�r*r*r+r��s"


zES3ControlEndpointSetter._validate_endpoint_from_arn_details_supportedcCs|jrtdd��dS)NzIClient cannot use a custom "endpoint_url" when specifying a resource ARN.)r�)r�r)r[r*r*r+r��sz4S3ControlEndpointSetter._validate_no_custom_endpointcCs"|j�|jjd�rtdd��dS)Nr�zPClient does not support s3 dualstack configuration when an outpost is specified.)r�)r�r�r2r)r[rZr*r*r+r��sz;S3ControlEndpointSetter._validate_outpost_redirection_validcCs2|jjdd�r,|jdd}|j||�|S|jS)Nr�Fr}r])r�r2rr�r�)r[rZr�r*r*r+r��s
z8S3ControlEndpointSetter._resolve_region_from_arn_detailscCs|jdd}|j||�|S)Nr}rl)rr�)r[rZZarn_servicer*r*r+r��sz>S3ControlEndpointSetter._resolve_signing_name_from_arn_detailscCs|j||�}|j||�dS)N)� _resolve_netloc_from_arn_detailsr�)r[rZr
r�r*r*r+r��sz:S3ControlEndpointSetter._resolve_endpoint_from_arn_detailscCs@t|j�}t|j||j|jdf�}tjd|j|f�||_dS)Nr6zUpdating URI from %s to %s)rrFrrr>rr�r�)r[rZr�r�Zarn_details_endpointr*r*r+r��s
z.S3ControlEndpointSetter._update_request_netloccCs0|jd}d|kr|j|�S|d}|j||�S)Nr}r�rm)rr��_construct_s3_control_endpoint)r[rZr
r}rmr*r*r+r��s


z8S3ControlEndpointSetter._resolve_netloc_from_arn_detailscCs|jj|�S)N)�_HOST_LABEL_REGEXr)r[�labelr*r*r+�_is_valid_host_label�sz,S3ControlEndpointSetter._is_valid_host_labelcGs&x |D]}|j|�st|d��qWdS)N)r�)r�r )r[Zlabelsr�r*r*r+�_validate_host_labels�s

z-S3ControlEndpointSetter._validate_host_labelscCs@|j||�|dg}|j|�|j|�}|j||g�|j|�S)Nz
s3-control)r��_add_dualstackr�r��_construct_netloc)r[r
rmrr�r*r*r+r��s

z6S3ControlEndpointSetter._construct_s3_control_endpointcCs$|j|�d||j|�g}|j|�S)Nzs3-outposts)r�r�r�)r[r
rr*r*r+r��s

z3S3ControlEndpointSetter._construct_outpost_endpointcCs
dj|�S)Nr@)rE)r[rr*r*r+r�sz)S3ControlEndpointSetter._construct_netloccCs|jjd�r|jd�dS)Nr�r")r�r2rD)r[rr*r*r+r�sz&S3ControlEndpointSetter._add_dualstackcCs,|jjd|�}|j}|r(d|kr(|d}|S)Nr\r�)rDr�r�)r[r
r�r�r*r*r+r�sz'S3ControlEndpointSetter._get_dns_suffixcCs$|jjdi�}||d<||jd<dS)NrYr])rr2)r[rZr
rbr*r*r+r�sz0S3ControlEndpointSetter._override_signing_regioncCs$|jjdi�}||d<||jd<dS)NrYr�)rr2)r[rZr�rbr*r*r+r� sz.S3ControlEndpointSetter._override_signing_namecCs(|jd}|jd�}|r$|j||�dS)Nr}r�)rr2�_add_outpost_id_header)r[rZr}r�r*r*r+r�)s

z5S3ControlEndpointSetter._add_headers_from_arn_detailscCs||jd<dS)Nzx-amz-outpost-id)rm)r[rZr�r*r*r+r�/sz.S3ControlEndpointSetter._add_outpost_id_header)NNNN) rUrVrWr�r�r8rr�r\rKr�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�ns8

	
				r�c@s�eZdZejd�Zddd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�S3ControlArnParamHandlerz[/:]NcCs||_|dkrt�|_dS)N)rrrg)r[rsr*r*r+r\6sz!S3ControlArnParamHandler.__init__cCs|jd|j�dS)Nz!before-parameter-build.s3-control)rKrt)r[rOr*r*r+rK;sz!S3ControlArnParamHandler.registercKs:|jdkr|j|||�n|j|||�|j|||�dS)Nr2�ListRegionalBuckets)r2r�)r:�_handle_outpost_id_param�_handle_name_param�_handle_bucket_param)r[rdr|rrr*r*r+rtAs
z#S3ControlArnParamHandler.handle_arncCsT||krdSy.||}|jj|�}||d<|j|�|d<|Stk
rNdSXdS)Nr��	resources)rrrp�_split_resourcerf)r[rdr9ror}r*r*r+�_get_arn_details_from_paramKsz4S3ControlArnParamHandler._get_arn_details_from_paramcCs|jj|d�S)Nrn)�_RESOURCE_SPLIT_REGEXrB)r[r}r*r*r+r�Wsz(S3ControlArnParamHandler._split_resourcecCsD|d}d|kr8|d|kr8d|d}t|d|d��||d<dS)NrmZ	AccountIdzGAccount ID in arn does not match the AccountId parameter provided: "%s"r�)ror�)r)r[rdr}Z
account_idr�r*r*r+�_override_account_id_paramZs
z3S3ControlArnParamHandler._override_account_id_paramcCsd|krdS|d|d<dS)NZ	OutpostIdr�r*)r[rdr|rr*r*r+r�gsz1S3ControlArnParamHandler._handle_outpost_id_paramcCsX|jdkrdS|j|d�}|dkr&dS|j|�r@|j|||�nd}t|d|d��dS)NZCreateAccessPoint�Namez4The Name parameter does not support the provided ARNr�)ror�)r:r��_is_outpost_accesspoint�_store_outpost_accesspointr)r[rdr|rr}r�r*r*r+r�ls

z+S3ControlArnParamHandler._handle_name_paramcCs@|ddkrdS|d}t|�dkr(dS|ddko>|dd	kS)
Nrlzs3-outpostsFr�rjrrwrrv)rO)r[r}r�r*r*r+r�|sz0S3ControlArnParamHandler._is_outpost_accesspointcCsD|j||�|dd}||d<||d<|dd|d<||d<dS)Nr�rr�r�r!r�r})r�)r[rdrr}r�r*r*r+r��sz3S3ControlArnParamHandler._store_outpost_accesspointcCsJ|j|d�}|dkrdS|j|�r2|j|||�nd}t|d|d��dS)Nrcz6The Bucket parameter does not support the provided ARNr�)ror�)r��_is_outpost_bucket�_store_outpost_bucketr)r[rdr|rr}r�r*r*r+r��s
z-S3ControlArnParamHandler._handle_bucket_paramcCs@|ddkrdS|d}t|�dkr(dS|ddko>|dd	kS)
Nrlzs3-outpostsFr�rjrrwrrZ)rO)r[r}r�r*r*r+r��sz+S3ControlArnParamHandler._is_outpost_bucketcCsD|j||�|dd}||d<||d<|dd|d<||d<dS)Nr�rrcrr!r�r})r�)r[rdrr}rr*r*r+r��sz.S3ControlArnParamHandler._store_outpost_bucket)N)rUrVrWr8rr�r\rKrtr�r�r�r�r�r�r�r�r�r�r*r*r*r+r�3s



		r�c@sreZdZdZdZdZdZeddgZdej	fdd	�Z
dd
d�Zdd
�Zdd�Z
dd�Zddd�Zdd�Zdd�ZdS)�ContainerMetadataFetcherrrr!z
169.254.170.2Z	localhostz	127.0.0.1NcCs(|dkrtjj|jd�}||_||_dS)N)r^)rfrgrh�TIMEOUT_SECONDSrj�_sleep)r[Zsession�sleepr*r*r+r\�s

z!ContainerMetadataFetcher.__init__cCs|j|�|j||�S)z�Retrieve JSON metadata from container metadata.

        :type full_url: str
        :param full_url: The full URL of the metadata service.
            This should include the scheme as well, e.g
            "http://localhost:123/foo"

        )�_validate_allowed_url�_retrieve_credentials)r[�full_urlrmr*r*r+�retrieve_full_uri�s	
z*ContainerMetadataFetcher.retrieve_full_uricCs:tjj|�}|j|j�}|s6td|jdj|j�f��dS)NzGUnsupported host '%s'.  Can only retrieve metadata from these hosts: %sz, )rf�compatr
�_check_if_whitelisted_hostrr�rE�_ALLOWED_HOSTS)r[r�ZparsedZis_whitelisted_hostr*r*r+r��sz.ContainerMetadataFetcher._validate_allowed_urlcCs||jkrdSdS)NTF)r�)r[r r*r*r+r��s
z3ContainerMetadataFetcher._check_if_whitelisted_hostcCs|j|�}|j|�S)z�Retrieve JSON metadata from ECS metadata.

        :type relative_uri: str
        :param relative_uri: A relative URI, e.g "/foo/bar?id=123"

        :return: The parsed JSON response.

        )r�r�)r[�relative_urir�r*r*r+�retrieve_uri�s	
z%ContainerMetadataFetcher.retrieve_uricCs�ddi}|dk	r|j|�d}xhy|j|||j�Stk
r�}z6tjd|dd�|j|j�|d7}||jkrr�WYdd}~Xq Xq WdS)NZAcceptzapplication/jsonrzAReceived error when attempting to retrieve container metadata: %sT)rsr!)	r��
_get_responser�rr�r�r��
SLEEP_TIME�RETRY_ATTEMPTS)r[r�Z
extra_headersrmZattemptsr�r*r*r+r��s


z.ContainerMetadataFetcher._retrieve_credentialsc
Cs�y�tjj}|d||d�}|jj|j��}|jjd�}|jdkrRt	d|j|fd��y
t
j|�Stk
r�d}t
jd||�t	|d��YnXWn4tk
r�}	zd	|	}t	|d��WYdd}	~	XnXdS)
Nr�)rlrFrmzutf-8rnz4Received non 200 response (%s) from ECS metadata: %s)r�z8Unable to parse JSON returned from ECS metadata servicesz%s:%sz;Received error when attempting to retrieve ECS metadata: %s)rfrxryrjr{r|r�r�r}rrr�r�r�r�r)
r[r�rmr^ryrZr�Z
response_textr�r�r*r*r+r��s&

z&ContainerMetadataFetcher._get_responsecCsd|j|fS)Nzhttp://%s%s)�
IP_ADDRESS)r[r�r*r*r+r�sz!ContainerMetadataFetcher.full_url)N)N)rUrVrWr�r�r�r�r��timer�r\r�r�r�r�r�r�r�r*r*r*r+r��s



r�cCst|�riSt�SdS)N)�should_bypass_proxiesr)rFr*r*r+risricCs6ytt|�j�rdSWnttjfk
r0YnXdS)z:
    Returns whether we should bypass proxies or not.
    TF)rr
rr��socketZgaierror)rFr*r*r+r�sr��
ISO-8859-1cCsF|jd�}|sdStj|�\}}d|kr6|djd�Sd|krB|SdS)z�Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :param default: default encoding if the content-type is text
    zcontent-typeN�charsetz'"r~)r2�cgiZparse_headerr�)rm�defaultZcontent_typerdr*r*r+�get_encoding_from_headers.s
r�cKs0t|ttf�rt|�}nt|�}tj|�jd�S)Nr�)r&�bytes�	bytearray�_calculate_md5_from_bytes�_calculate_md5_from_file�base64Z	b64encoder�)r�rZ
binary_md5r*r*r+�
calculate_md5Cs
r�cCst|�}|j�S)N)rr�)Z
body_bytes�md5r*r*r+r�Ksr�csF�j�}t�}x$t�fdd�d�D]}|j|�q"W�j|�|j�S)Ncs
�jd�S)Nii)r�r*)�fileobjr*r+r�Ssz*_calculate_md5_from_file.<locals>.<lambda>r�)�tellrr�r��seekr�)r�Zstart_positionr�r�r*)r�r+r�Ps
r�cKs<|d}|d}tr8|r8d|kr8t|f|�}||dd<dS)z1Only add a Content-MD5 if the system supports it.rmr�zContent-MD5N)r
r�)rdrrmr�Z
md5_digestr*r*r+�conditionally_calculate_md5Ys
r�c@s eZdZefdd�Zdd�ZdS)�FileWebIdentityTokenLoadercCs||_||_dS)N)�_web_identity_token_pathr�)r[Zweb_identity_token_pathr�r*r*r+r\csz#FileWebIdentityTokenLoader.__init__c	Cs |j|j��
}|j�SQRXdS)N)r�r�r�)r[Z
token_filer*r*r+�__call__gsz#FileWebIdentityTokenLoader.__call__N)rUrVrW�openr\r�r*r*r*r+r�bsr�c@s&eZdZddd�Zdd�Zdd�ZdS)	�SSOTokenLoaderNcCs|dkri}||_dS)N)rE)r[rIr*r*r+r\mszSSOTokenLoader.__init__cCstj|jd��j�S)Nzutf-8)r�Zsha1r�r�)r[�	start_urlr*r*r+�_generate_cache_keyrsz"SSOTokenLoader._generate_cache_keycCsR|j|�}y|j|}|dStk
rLtjddd�d}t|d��YnXdS)NZaccessTokenzFailed to load SSO token:T)rsz@The SSO access token has either expired or is otherwise invalid.)r�)rrE�KeyErrorr�r�r)r[r�r%r�r�r*r*r+r�us

zSSOTokenLoader.__call__)N)rUrVrWr\rr�r*r*r*r+r�ls
r�)T)F)N)F)N)N)T)T)r�)|r�r8r�Zloggingr�r�r�r*rFr�rar�r�Zdateutil.parserr�Zdateutil.tzrrfZbotocore.awsrequestZbotocore.httpsessionZbotocore.compatrrrrrrr	r
rrr
Z*botocore.vendored.six.moves.urllib.requestrrZbotocore.exceptionsrrrrrrrrrrrrrrrrr Z	getLoggerrUr�r�r�Z
SAFE_CHARSrrrr-Z
EVENT_ALIASESr,r5r;r?r=rMrP�	ExceptionrTrY�objectr]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	rrrrrr,r7r;r5r<r>rBrCr�rfrgrqr�r�r�r�rir�r�r�r�r�r�r�r�r*r*r*r+�<module>
s@4L



!~V
	$-

!`


> 

!W`F{d