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: //usr/lib/python3/dist-packages/botocore/__pycache__/utils.cpython-310.pyc
o

YZ�a�y�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlmZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZm Z ddl!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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:ddl;m<Z<e�=e>�Z?dZ@dZAd	ZBd
ZCdZDe�Ed�ZFe+e*e,e-fZGd
gZHidd�dd�dd�dd�dd�dd�dd�dd�dd�dd �d!d"�d#d$�d%d&�d'd(�d)d*�d+d,�d-d.�id/d0�d1d2�d3d4�d5d6�d7d8�d9d:�d;d<�d=d>�d?d@�dAdB�dCdD�dEdF�dGdH�dIdJ�dKdL�dMdH�dNdO��idPdQ�dRdS�dTdU�dVdW�dXdW�dYd.�dZd0�d[d8�d\d]�d^d_�d`da�dbdc�ddde�dfdg�dhdi�djdS�dkdl��idmdn�dodn�dpdq�drdc�dsdt�dudv�dwdx�dyd]�dzd{�d|d}�d~d�d�de�d�d��d�d��d�d��d�d��d�d���d�d�d�dBd{d���ZId�ZJd�ZKd�jLeKeJd��ZMeKeMd��ZNgd��ZOd�ZPd�d��Qd�d��eOD��d�ZRd�ePd�ZSd�eRd�eSd�ZTe�Ed�eTd��ZUeVd��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`�d d�d��Zad�d��ZbGd�d��d�ec�ZdGd�d��d�ec�ZeGd�d��d�ef�ZgGd�d��d�eg�Zh�d!d�d„Zid�dĄZjekfd�dƄZld�dȄZmeDfd�dʄZneDfd�d̄Zod�d΄Zpd�dЄZqd�d҄Zr�d"d�dԄZs�d!d�dքZtd�d؄Zud�dڄZvGd�d܄d�ef�ZwGd�dބd�ef�Zxd�d�Zyd�d�Zzd�d�Z{d�d�Z|d�d�Z}	�d"d�d�Z~	�d"d�d�Zd�d�Z�d�d�Z�d�d�Z�d�d�Z��d d�d��Z��d d�d��Z�d�d��Z�d�d��Z�Gd�d��d�ef�Z�Gd��d��de��Z�G�d�d��def�Z�G�d�d��def�Z�G�d�d��def�Z�G�d�d��def�Z�G�d	�d
��d
ef�Z�G�d�d��def�Z��d
�d�Z��d�d�Z��d#�d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z�G�d�d��def�Z�G�d�d��def�Z�dS($�N)�tzutc)�json�quote�zip_longest�urlsplit�
urlunsplit�OrderedDict�six�urlparse�get_tzinfo_options�get_md5�
MD5_AVAILABLE�HAS_CRT)�
getproxies�proxy_bypass)�InvalidExpressionError�ConfigNotFound�InvalidDNSNameError�ClientError�MetadataRetrievalError�EndpointConnectionError�ReadTimeoutError�ConnectionClosedError�ConnectTimeoutError�UnsupportedS3ArnError�*UnsupportedS3AccesspointConfigurationError�SSOTokenLoadError�InvalidRegionError�InvalidIMDSEndpointError�InvalidIMDSEndpointModeError�UnsupportedOutpostResourceError�&UnsupportedS3ControlConfigurationError�UnsupportedS3ControlArnError�InvalidHostLabelError�HTTPClientError�UnsupportedS3ConfigurationError�MissingDependencyException)�LocationParseError�zhttp://169.254.169.254/zhttp://[fd00:ec2::254]/)�ipv4�ipv6z-._~z-z0-9][a-z0-9\-]*[a-z0-9]�	dualstack�a4bzalexa-for-business�alexaforbusinesszapi.mediatailor�mediatailorzapi.pricing�pricingz
api.sagemaker�	sagemaker�
apigatewayzapi-gatewayzapplication-autoscalingzapplication-auto-scaling�
appstream2�	appstream�autoscalingzauto-scalingzautoscaling-planszauto-scaling-plans�cez
cost-explorer�
cloudhsmv2zcloudhsm-v2�cloudsearchdomainzcloudsearch-domainzcognito-idpzcognito-identity-provider�configzconfig-service�curzcost-and-usage-report-servicezdata.iotziot-data-planez
data.jobs.iotziot-jobs-data-planezdata.mediastorezmediastore-data�datapipelinez
data-pipeline�
devicefarmzdevice-farmzdevices.iot1clickziot-1click-devices-service�
directconnectzdirect-connect�	discoveryzapplication-discovery-service�dmszdatabase-migration-service�dszdirectory-service�dynamodbstreamszdynamodb-streams�elasticbeanstalkzelastic-beanstalk�elasticfilesystem�efs�elasticloadbalancingzelastic-load-balancing�elasticmapreduce�emr�elastictranscoderzelastic-transcoder�elb�elbv2zelastic-load-balancing-v2�email�seszentitlement.marketplacezmarketplace-entitlement-service�eszelasticsearch-service�events�eventbridgezcloudwatch-eventsziot-dataz
iot-jobs-dataziot1click-devicesziot1click-projectsziot-1click-projects�kinesisanalyticszkinesis-analytics�kinesisvideoz
kinesis-videoz
lex-modelszlex-model-building-servicezlex-runtimezlex-runtime-service�logszcloudwatch-logs�machinelearningzmachine-learningzmarketplace-entitlement�marketplacecommerceanalyticszmarketplace-commerce-analyticszmetering.marketplacezmarketplace-metering�meteringmarketplace�mghz
migration-hubz
models.lex�
monitoring�
cloudwatchzmturk-requester�mturkzopsworks-cm�
opsworkscmzprojects.iot1click�resourcegroupstaggingapizresource-groups-tagging-api�route53zroute-53�route53domainszroute-53-domainszruntime.lexzruntime.sagemakerzsagemaker-runtime�sdb�simpledb�secretsmanagerzsecrets-manager�serverlessrepo�serverlessapplicationrepository�servicecatalogzservice-catalog�sfnzstorage-gateway)�states�
stepfunctions�storagegatewayzstreams.dynamodb�taggingz(?:[0-9]{1,3}\.){3}[0-9]{1,3}z[0-9A-Fa-f]{1,4}z(?:{hex}:{hex}|{ipv4}))�hexr))rh�ls32)	z(?:%(hex)s:){6}%(ls32)sz::(?:%(hex)s:){5}%(ls32)sz%(?:%(hex)s)?::(?:%(hex)s:){4}%(ls32)sz2(?:(?:%(hex)s:)?%(hex)s)?::(?:%(hex)s:){3}%(ls32)sz6(?:(?:%(hex)s:){0,2}%(hex)s)?::(?:%(hex)s:){2}%(ls32)sz/(?:(?:%(hex)s:){0,3}%(hex)s)?::%(hex)s:%(ls32)sz'(?:(?:%(hex)s:){0,4}%(hex)s)?::%(ls32)sz&(?:(?:%(hex)s:){0,5}%(hex)s)?::%(hex)sz(?:(?:%(hex)s:){0,6}%(hex)s)?::zDABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._!\-~z(?:�|cCsg|]}|t�qS�)�_subs)�.0�xrkrk�0/usr/lib/python3/dist-packages/botocore/utils.py�
<listcomp>�srp�)z
(?:%25|%)(?:[z]|%[a-fA-F0-9]{2})+z\[z)?\]�^�$z	
cCs(t|t�r|St|t�r|��dkSdS)z~Ensures a boolean value if a string or boolean is provided

    For strings, the value for True/False is case insensitive
    �trueF)�
isinstance�bool�str�lower��valrkrkro�ensure_boolean�s


r{cCsP|�d�}|dur|��}|tvr|td�}tdi|���|S|�d�r&dSdS)z�Resolving IMDS endpoint mode to either IPv6 or IPv4.

    ec2_metadata_service_endpoint_mode takes precedence over imds_use_ipv6.
    �"ec2_metadata_service_endpoint_modeN)�mode�valid_modes�
imds_use_ipv6r*r)rk)�get_config_variablerx�METADATA_ENDPOINT_MODESr)�session�
endpoint_mode�lendpoint_mode�error_msg_kwargsrkrkro�resolve_imds_endpoint_mode�s��
r�cCs2t|d�o|j�dd�o|j�d�dko|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
    �
serialization�	jsonvalueF�location�header�string)�hasattrr��get�	type_name)�shaperkrkro�is_json_value_header�s

���r�cCs<|durdSt|tjj�r||vS|��dd�|��D�vS)z&Case-insensitive check for header key.NFcSsg|]}|���qSrk�rx)rm�keyrkrkrorp�s�zhas_header.<locals>.<listcomp>)ru�botocore�
awsrequest�HeadersDictrx�keys)�header_name�headersrkrkro�
has_header�s�r�cCsD|j�d|j�d|j��}|�dd�}|�dd�}t�dd|�}|S)zvReturns the module name for a service

    This is the value used in both the documentation and client class name
    �serviceAbbreviation�serviceFullName�Amazon��AWSz\W+)�metadatar��service_name�replace�re�sub)�
service_model�namerkrkro�get_service_module_name�s��r�cCs|sdSt|�S)N�/)�remove_dot_segments��pathrkrkro�normalize_url_pathsr�cCs|dur|St|�S)zLReturns None if val is None, otherwise ensure value
    converted to booleanN)r{ryrkrkro�normalize_boolean
sr�cCs�|sdS|�d�}g}|D]}|r%|dkr%|dkr |r|��q
|�|�q
|ddkr/d}nd}|ddkr<|r<d}nd}|d�|�|S)Nr�r��.z..r���)�split�pop�append�join)�url�	input_url�output_listrn�first�lastrkrkror�s&
�
�r�cCs6|r|dkrt|d��dD]}||vrt|d��q
dS)Nr���
expression)�[�]�*)r)r��invalidrkrkro�validate_jmespath_for_set.s

��r�TcCs||rt|�|�dd�}|dt|�dkr|dnd}}|s$t|d��|r8||vr.i||<t||||dd�S|||<dS)Nr�r(rr�r�F)�is_first)r�r��lenr�set_value_from_jmespath)�sourcer��valuer��bits�current_key�	remainderrkrkror�9s "
�r�cCs|�di�}|�d�dk}|S)z9Determine if request is intended for an MRAP accesspoint.�s3_accesspoint�regionr��r�)�contextr��	is_globalrkrkro�is_global_accesspointZsr�c@seZdZdZdS)�_RetriesExceededErrorz@Internal exception used when the number of retries are exceeded.N)�__name__�
__module__�__qualname__�__doc__rkrkrkror�asr�c@�eZdZdd�ZdS)�BadIMDSRequestErrorcC�
||_dS�N��request��selfr�rkrkro�__init__g�
zBadIMDSRequestError.__init__N)r�r�r�r�rkrkrkror�f�r�c@s�eZdZeZdZdZededddfdd�Z	dd�Z
d	d
�Zdd�Zdd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zddd�ZdS)�IMDSFetcherzlatest/api/token�21600r(NcCsn||_||_|�||�|_|durtj��}|�dd���|_	|j	dk|_	||_
tjj
|jt|j�d�|_dS)N�AWS_EC2_METADATA_DISABLED�falsert)�timeout�proxies)�_timeout�
_num_attempts�_select_base_url�	_base_url�os�environ�copyr�rx�	_disabled�_user_agentr��httpsession�URLLib3Session�get_environ_proxies�_session)r�r��num_attempts�base_url�env�
user_agentr8rkrkror�qs
�zIMDSFetcher.__init__cCs|jSr�)r��r�rkrkro�get_base_url�szIMDSFetcher.get_base_urlcCs�|duri}|�d�dk}|�d�}|r|rt�d�d}|tkr$|}n|r)|}n|r.t}nt}t�d|�t|�s@t|d��|S)Nr|r*�ec2_metadata_service_endpointzFCustom endpoint and IMDS_USE_IPV6 are both set. Using custom endpoint.zIMDS ENDPOINT: %s)�endpoint)r��logger�warning�METADATA_BASE_URL�METADATA_BASE_URL_IPv6�debug�is_valid_urir)r�r�r8�
requires_ipv6�custom_metadata_endpoint�chosen_base_urlrkrkror��s0��
�
zIMDSFetcher._select_base_urlcCs|��|j|j}d|ji}|�|�tjjd||d�}t|j	�D]i}z'|j
�|���}|j
dkr8|jWS|j
dvrAWdS|j
dvrJt|��Wq"tyVYdStyp}ztjd||dd	�WYd}~q"d}~wty�}zt|j�d
�t�r�t||d���d}~wwdS)Nz$x-aws-ec2-metadata-token-ttl-seconds�PUT��methodr�r���)i�i�i�)i��OCaught retryable HTTP exception while making metadata service request to %s: %sT��exc_info�error)r�r)�_assert_enabledr��_TOKEN_PATH�
_TOKEN_TTL�_add_user_agentr�r��
AWSRequest�ranger�r��send�prepare�status_code�textr�r�RETRYABLE_HTTP_ERRORSr�r�r$ru�kwargsr�r'r)r�r�r�r��i�response�erkrkro�_fetch_metadata_token�sB�
�


�����z!IMDSFetcher._fetch_metadata_tokenc
Cs�|��|dur|j}|j|}i}|dur||d<|�|�t|j�D]9}ztjjd||d�}|j	�
|���}||�sA|WSWq$ty]}	zt
jd||	dd�WYd}	~	q$d}	~	ww|���)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�GETrrTr)r	�_default_retryr�rrr�r�r�r
r�rrrr�r��_RETRIES_EXCEEDED_ERROR_CLS)
r��url_path�
retry_func�tokenr�r�rr�rrrkrkro�_get_request�s2

�
����zIMDSFetcher._get_requestcCs|jdur|j|d<dSdS)Nz
User-Agent)r�)r�r�rkrkror�s
�zIMDSFetcher._add_user_agentcCs|jrt�d�|���dS)Nz)Access to EC2 metadata has been disabled.)r�r�r�rr�rkrkror	�s
�zIMDSFetcher._assert_enabledcC�|�|�p	|�|�Sr���_is_non_ok_response�	_is_empty�r�rrkrkror��
�zIMDSFetcher._default_retrycCs"|jdkr|j|ddd�dSdS)Nrznon-200T��log_bodyF)r�_log_imds_responser$rkrkror"�s
zIMDSFetcher._is_non_ok_responsecCs|js
|j|ddd�dSdS)Nzno bodyTr&F)�contentr(r$rkrkror#�szIMDSFetcher._is_emptyFcCs@d}||j|jg}|r|d7}|�|j�tj|g|�R�dS)NzHMetadata service returned %s response with status code of %s for url: %sz, content body: %s)rr�r�r)r�r�)r�r�
reason_to_logr'�	statement�logger_argsrkrkror(s�
�zIMDSFetcher._log_imds_responser��F)r�r�r�r�rr
r� DEFAULT_METADATA_SERVICE_TIMEOUTr�r�r�r�rrrr	rr"r#r(rkrkrkror�ks$
�
%r�c@sTeZdZdZgd�Zdd�Zddd�Zddd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�InstanceMetadataFetcherz*latest/meta-data/iam/security-credentials/)�AccessKeyId�SecretAccessKey�Token�
Expirationc
Cs�z6|��}|�|�}|�||�}|�|�r&||d|d|d|dd�WSd|vr4d|vr4t�d|�iWS|jyHt�d	|j�YiStya}zt�d
|j	�WYd}~iSd}~ww)Nr0r1r2r3)�	role_name�
access_key�
secret_keyr�expiry_time�Code�Messagez7Error 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�rr�r�r�)r�rr4�credentialsrrkrkro�retrieve_iam_role_credentialss4

������z5InstanceMetadataFetcher.retrieve_iam_role_credentialsNcCs|j|j|j|d�jS�N)rrr)r�	_URL_PATH�_needs_retry_for_role_namer)r�rrkrkror:8s��z%InstanceMetadataFetcher._get_iam_rolecCs$|j|j||j|d�}t�|j�Sr?)rr@�_needs_retry_for_credentialsr�loadsr)r�r4r�rrkrkror;?s�z(InstanceMetadataFetcher._get_credentialscCs4z	t�|j�WdSty|�|d�YdSw)NFzinvalid jsonT)rrCr�
ValueErrorr(r$rkrkro�_is_invalid_jsonGs�z(InstanceMetadataFetcher._is_invalid_jsoncCr r�r!r$rkrkrorAOr%z2InstanceMetadataFetcher._needs_retry_for_role_namecCs|�|�p|�|�p|�|�Sr�)r"r#rFr$rkrkrorBUs

��z4InstanceMetadataFetcher._needs_retry_for_credentialscCs*|jD]}||vrt�d|�dSqdS)Nz3Retrieved credentials is missing required field: %sFT)�_REQUIRED_CREDENTIAL_FIELDSr�r�)r�r=�fieldrkrkror<\s
��z7InstanceMetadataFetcher._contains_all_credential_fieldsr�)r�r�r�r@rGr>r:r;rFrArBr<rkrkrkror/s
"
r/FcCs�|D]M}t||t�r$||vr||vrt||||�q||||<qt||t�rI|rI||vrBt||t�rB||�||�q||||<q||||<qdS)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)ru�dict�merge_dicts�list�extend)�dict1�dict2�append_listsr�rkrkrorJfs�rJcCs"i}|D]
}||||��<q|S)zECopies the given dictionary ensuring all keys are lowercase strings. r�)�originalr�r�rkrkro�lowercase_dict�srQcCsZz ||��}|��}t|�Wd�WS1swYWdSty,t|d��w)Nr�)�read�parse_key_val_file_contents�OSErrorr)�filename�_open�f�contentsrkrkro�parse_key_val_file�s
(�
�rYcCsHi}|��D]}d|vr
q|�dd�\}}|��}|��}|||<q|S)N�=r()�
splitlinesr��strip)rX�final�liner�rzrkrkrorS�s
rScCs~g}t|d�r|��}n|}|D])\}}t|t�r,|D]}|�dt|�t|�f�qq|�dt|�t|�f�qd�|�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�&)r�r_rurKr��percent_encoder�)�mapping�safe�
encoded_pairs�pairsr�r��elementrkrkro�percent_encode_sequence�s



��
�
rgcCs>t|tjtjf�st�|�}t|tj�s|�d�}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.
    �utf-8)rc)rur	�binary_type�	text_type�encoder)�	input_strrcrkrkrora�s


rac
Cs�t|ttf�rtj�||��Sztj�t|�|��WSttfy%Ynwztjj	|dt
�id�WSttfyH}ztd||f��d}~ww)z.Parse timestamp with pluggable tzinfo options.�GMT)�tzinfoszInvalid timestamp "%s": %sN)ru�int�float�datetime�
fromtimestamp�	TypeErrorrE�dateutil�parser�parser�r��tzinforrkrkro�_parse_timestamp_with_tzinfo�s���rycCs^t�D]%}zt||�WSty(}ztjd|j|d�WYd}~qd}~wwtd|��)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.rNz4Unable to calculate correct timezone offset for "%s")rryrTr�r�r��RuntimeErrorrwrkrkro�parse_timestamp�s
����r{cCsFt|tj�r	|}nt|�}|jdur|jt�d�}|S|�t��}|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�rx)rurqr{rxr�r�
astimezone)r��datetime_objrkrkro�parse_to_aware_datetimes
�rcCs~t�ddd�}|jdur|durt�}|j|d�}|jdd�|��|}t|d�r.|��S|j|j|j	ddddS)	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
    �r(Nr|�
total_seconds�ii@B)
rqrxrr��	utcoffsetr�r��microseconds�seconds�days)�dt�default_timezone�epoch�drkrkro�datetime2timestamp2s


"r�cs>t��}t�fdd�d�D]}|�|�q
|r|��S|��S)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

    c�
��d�S�N��rRrk��bodyrkro�<lambda>Z�
z"calculate_sha256.<locals>.<lambda>�)�hashlib�sha256�iter�update�	hexdigest�digest)r��as_hex�checksum�chunkrkr�ro�calculate_sha256Gsr�cs�g}d�tj}t��fdd�d�D]}|�||����q|s%|d���St|�dkrSg}t|�D]\}}|durE|�|||����q1|�|�q1|}t|�dks+t�	|d��
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

    r�cs
����Sr�r�rk�r��required_chunk_sizerkror�sr�z%calculate_tree_hash.<locals>.<lambda>r�r(Nr�ascii)r�r�r�r�r�r�r��	_in_pairs�binascii�hexlify�decode)r��chunksr�r��
new_chunksr��secondrkr�ro�calculate_tree_hashbs �	r�cCst|�}t||�Sr�)r�r)�iterable�shared_iterrkrkror��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.

    cCr�r�)�_fget)r��fgetrkrkror��r�zCachedProperty.__init__cCs(|dur|S|�|�}||j|jj<|Sr�)r��__dict__r�)r��obj�cls�computed_valuerkrkro�__get__�s

zCachedProperty.__get__N)r�r�r�r�r�r�rkrkrkror��sr�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)

    FcCr�r�)�_use_member_names)r��use_member_namesrkrkror��r�zArgumentGenerator.__init__cCsg}|�||�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�r��stackrkrkro�generate_skeleton�s
z#ArgumentGenerator.generate_skeletonr�cCs>|�|j�z�|jdkr|�||�W|��S|jdkr'|�||�W|��S|jdkr7|�||�W|��S|jdkr[|jrF|W|��S|jrTt	�
|j�W|��SW|��dS|jdvrgW|��dS|jdvrsW|��d	S|jd
krW|��dS|jdkr�t�d
ddddd�W|��SW|��dS|��w)N�	structurerK�mapr�r�)�integer�longr)rp�doubleg�booleanT�	timestampr�r()r�r�r��_generate_type_structurer��_generate_type_list�_generate_type_mapr��enum�random�choicerq�r�r�r�r�rkrkror��sD


�

�

�

�
�

�
�
�
�
�z$ArgumentGenerator._generate_skeletoncCsF|�|j�dkr
iSt�}|j��D]\}}|j|||d�||<q|S)Nr()r�)�countr�r�membersr_r�)r�r�r��skeleton�member_name�member_shaperkrkror��s�z*ArgumentGenerator._generate_type_structurecCs$d}|jr	|jj}|�|j||�gS)Nr�)r��memberr�r�r�rkrkror��s
�z%ArgumentGenerator._generate_type_listcCs0|j}|j}|jdks
J�td|�||�fg�S)Nr��KeyName)r�r�r�rr�)r�r�r��	key_shape�value_shaperkrkror��s�z$ArgumentGenerator._generate_type_mapNr-)r�)
r�r�r�r�r�r�r�r�r�r�rkrkrkror��s


	
r�cCs,t�|�rdSd�t|�j�}t�|�duS)NFz[{}])�UNSAFE_URL_CHARS�intersection�formatr
�hostname�
IPV6_ADDRZ_RE�match)�endpoint_urlr�rkrkro�is_valid_ipv6_endpoint_urls
r�cCsht�|�rdSt|�}|j}|durdSt|�dkrdS|ddkr(|dd�}t�dtj�}|�|�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.

    FN�r�r�z;^((?!-)[A-Z\d-]{1,63}(?<!-)\.)*((?!-)[A-Z\d-]{1,63}(?<!-))$)	r�r�rr�r�r��compile�
IGNORECASEr�)r��partsr��allowedrkrkro�is_valid_endpoint_urls
�
r�cCst|�pt|�Sr�)r�r�)r�rkrkror�+�r�cCs2|durdSt�d�}|�|�}|st|d��dS)z0Provided region_name must be a valid host label.Nz)^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?<!-)$)�region_name)r�r�r�r)r��valid_host_label�validrkrkro�validate_region_name/s


�r�cCsRd|vrdSt|�}|dks|dkrdSt�|�}|dus%|��t|�kr'dSdS)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)r��LABEL_REr��end)�bucket_name�nr�rkrkro�check_dns_name9s
r�c
Ksb|j�dd�r	d}z	t|||�WdSty0}z|jd}t�d|�WYd}~dSd}~ww)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.

    �use_global_endpointFzs3.amazonaws.comr�z2Not changing URI, bucket is not DNS compatible: %sN)r�r��switch_to_virtual_host_stylerrr�r�)r��signature_versionr��default_endpoint_urlrrr�rkrkro�fix_s3_hostPs
�
���r�cKs|jdurdSt|�rt�d�dSt|j�}|j|_|j�d�}|dur(|j}t	|�dkr�|d}|s6dSt�d|j�t
|�r�t	|�dkrU|jddkrU|jd7_|�|�d�|�p`d}|}|d|}	|j
|	||jd	f}
t|
�}||_t�d
|�dSt|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�r�r�zURI updated to: %s)r�)�	auth_path�_is_get_bucket_location_requestr�r�rr�r�r��netlocr�r��remover��scheme�queryrr)r�r�r�rr��
path_partsr�r��global_endpoint�host�	new_tuple�new_urirkrkror�fsB



�
�
�r�cCs|j�d�S)Nz	?location)r��endswithr�rkrkror���r�cs"�j�t�����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.

    csb�|f}|rtt|����}�||f}|j�|�}|dur|S�|g|�Ri|��}||j|<|Sr�)�tuple�sortedr_�_instance_cacher�)r��argsr�	cache_key�kwarg_items�result��func�	func_namerkro�_cache_guard�s

z$instance_cache.<locals>._cache_guard)r��	functools�wraps)rrrkrro�instance_cache�srcKsht|j�j�d�}dd�|D�}d}t|�dkr!|d�|�d7}|d7}|dvr+dSt||d	d
�dS)z?Switches the current s3 endpoint with an S3 Accelerate endpointr�cSsg|]}|tvr|�qSrk��S3_ACCELERATE_WHITELIST�rm�prkrkrorp�sz-switch_host_s3_accelerate.<locals>.<listcomp>zhttps://s3-accelerate.r�
amazonaws.com)�ListBuckets�CreateBucket�DeleteBucketNF)�use_new_scheme)rr�r�r�r�r��
_switch_hosts)r��operation_namerr�r�rkrkro�switch_host_s3_accelerate�srcCs6t�|j�d��}|�|�r||}t||�dSdS)zBSwitches the host using a parameter value from a JSON request bodyrhN)rrC�datar�r�r)r��
param_name�request_json�new_endpointrkrkro�switch_host_with_param�s

�rcCst|j||�}||_dSr�)�_get_new_endpointr�)r�rr�final_endpointrkrkror�s�
rcCsRt|�}t|�}|j}|r|j}||j|j|jdf}t|�}t�d||f�|S�Nr�zUpdating URI from %s to %s)rr�r�r�r�rr�r�)�original_endpointrr�new_endpoint_components�original_endpoint_componentsr��final_endpoint_componentsrrkrkror�s ��rcCsR|D]$}||vr t||t�r t||t�r t||||�q||||<qdS)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)rurI�
deep_merge)�base�extrar�rkrkror$�s��r$cCs|�dd���S)zcTranslate the form used for event emitters.

    :param service_id: The service_id to convert.
    � �-)r�rx)�
service_idrkrkro�hyphenize_service_idsr*c@sHeZdZddd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�S3RegionRedirectorNcCs,||_||_|jduri|_t�|�|_dSr�)�_endpoint_resolver�_cache�weakref�proxy�_client)r��endpoint_bridge�client�cacherkrkror�s

zS3RegionRedirector.__init__cCs<|p|jjj}|�d|j�|�d|j�|�d|j�dS)Nzneeds-retry.s3zbefore-call.s3�before-parameter-build.s3)r0�metarM�register�redirect_from_error�set_request_url�redirect_from_cache)r��
event_emitter�emitterrkrkror6"s�zS3RegionRedirector.registercKs�|durdS|�|�di��rt�d�dS|�di��d�r&t�d�dS|d�di�}|�d�}|d�d	i�}|d
voC|jdk}|d
voT|jdkoTd
|�di�v}	|dko\d|v}
|dduoi|djdv}|dk}t||
||	|g�sydS|ddd}
|d�d�}|�|
|�}|dur�t�d||
f�dSt�d||
|f�|j�	d|�}|d}||
|d�}||dd<||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.
        Nr�z=S3 request was previously to an accesspoint, not redirecting.�
s3_redirectedz6S3 request was previously redirected, not redirecting.r(�Errorr8�ResponseMetadata)�301�400�
HeadObject�
HeadBucket�x-amz-bucket-region�HTTPHeaders�AuthorizationHeaderMalformed�Regionr)i-i.i3�PermanentRedirect�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�)r�rIr�T)�_is_s3_accesspointr�r�r�r�r�any�get_bucket_regionr,�resolver-r8)r��request_dictr�	operationrr�
error_code�response_metadata�is_special_head_object�is_special_head_bucket�is_wrong_signing_region�is_redirect_status�is_permanent_redirectrIrJ�
new_regionr��signing_contextrkrkror7)s|��
������������
z&S3RegionRedirector.redirect_from_errorc
Cs�|d}|dd}d|vr|dS|�di��dd�}|dur"|Sz|jj|d�}|dd}WntyJ}z
|jdd}WYd}~nd}~ww|�dd�}|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(r>rDrCr=rFN)�Bucket)r�r0�head_bucketrr)r�rIr�service_response�response_headersr�r�rrkrkrorNs 
��z$S3RegionRedirector.get_bucket_regioncKs8|�di��dd�}|durt|d|d�|d<dSdS)NrHr�r�F)r�r)r��paramsr�rr�rkrkror8�s�z"S3RegionRedirector.set_request_urlcKsH|�|�rdS|�d�}|j�|�}|dur||d<dSd|i|d<dS)z�
        This handler retrieves a given bucket's signing context from the cache
        and adds it into the request context.
        Nr[rHrI)rLr�r-)r�r_r�rrIrZrkrkror9�s

z&S3RegionRedirector.redirect_from_cachecCsd|vS�Nr�rk)r�r�rkrkrorL�sz%S3RegionRedirector._is_s3_accesspointr�)
r�r�r�r�r6r7rNr8r9rLrkrkrkror+s


V!r+c@seZdZdS)�InvalidArnExceptionN)r�r�r�rkrkrkrora�srac@r�)�	ArnParsercCsH|�dd�}t|�dkrtd|��|d|d|d|d|dd	�S)
N�:��zUProvided ARN: %s must be of the format: arn:partition:service:region:account:resourcer(r�r��)�	partition�servicer��account�resource)r�r�ra)r��arn�	arn_partsrkrkro�	parse_arn�s���zArnParser.parse_arnN)r�r�r�rmrkrkrkrorb�r�rbc@s`eZdZe�d�Ze�d�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}$)rNcC�||_|dur
t�|_dSdSr���_arn_parserrb�r��
arn_parserrkrkror����zS3ArnParamHandler.__init__cC�|�d|j�dS)Nr4�r6�
handle_arn�r�r:rkrkror6��zS3ArnParamHandler.registercKsf|j|jvrdS|�|�}|durdS|ddkr"|�|||�dS|ddkr1|�|||�dSdS)N�
resource_type�accesspoint�outpost)r��_BLACKLISTED_OPERATIONS�"_get_arn_details_from_bucket_param�_store_accesspoint�_store_outpost)r�r_�modelr�r�arn_detailsrkrkrorw�s
�zS3ArnParamHandler.handle_arncCsHd|vr"z|d}|j�|�}|�||�|WSty!YdSwdS)Nr[)rqrm�_add_resource_type_and_namera)r�r_rkr�rkrkror~�s�z4S3ArnParamHandler._get_arn_details_from_bucket_paramcCs>|j�|d�}|r|�d�|d<|�d�|d<dSt|d��)Nrjrz�
resource_name)rk)�_RESOURCE_REGEXr��groupr)r�rkr�r�rkrkror��s

z-S3ArnParamHandler._add_resource_type_and_namecCs8|d|d<|d|d|d|d|dd�|d<dS)	Nr�r[rirgr�rh)r�rirgr�rhr�rk)r�r_r�r�rkrkror�s�z$S3ArnParamHandler._store_accesspointcCsd|d}|j�|�}|st|d��|�d�}||d<|�d�||d|d|d|d	d
�|d<dS)Nr�)r��accesspoint_namer[�outpost_namerirgr�rh)r�r�rirgr�rhr�)�_OUTPOST_RESOURCE_REGEXr�r r�)r�r_r�r�r�r�r�rkrkror�s

�z S3ArnParamHandler._store_outpostr�)r�r�r�r�r�r�r�r}r�r6rwr~r�rr�rkrkrkrorn�s ���
rnc@s�eZdZdZdZ			d7dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zed1d2��Zed3d4��Zed5d6��ZdS)8�S3EndpointSetter�awsrNFcC�J||_||_||_||_|duri|_||_||_|dur#|j|_dSdSr��r,�_region�
_s3_config�_use_fips_endpoint�
_endpoint_url�
_partition�_DEFAULT_PARTITION�r��endpoint_resolverr��	s3_configr�rg�use_fips_endpointrkrkror�'s�zS3EndpointSetter.__init__cCs.|�d|j�|�d|j�|�d|j�dS)Nzbefore-sign.s3zchoose-signer.s3z%before-call.s3.WriteGetObjectResponse)r6�set_endpoint�
set_signer�#update_endpoint_to_s3_object_lambdarxrkrkror66s�zS3EndpointSetter.registercKsh|jrtdd��|�|d�|jrdS|j}|�d|j�}dj|d|dd�}t|d|d	�|d<dS)
NzOS3 client does not support accelerate endpoints for S3 Object Lambda operations��msg�s3-object-lambdazhttps://{host_prefix}{hostname}�host_prefixr�)r�r�r�F)	�_use_accelerate_endpointr%�_override_signing_namer�r,�construct_endpointr�r�r)r�r_r�r�resolver�resolvedrrkrkror�>s��z4S3EndpointSetter.update_endpoint_to_s3_object_lambdacKs�|�|�r&|�|�|�|�|�|�|�|�}|�|�|�||�dS|jr=|jr4t	d|j
d��tdd|i|��|jrL|jdd|i|��dSdS)Nz{Client is configured to use the FIPS psuedo region for "%s", but S3 Accelerate does not have any FIPS compatible endpoints.r�r�rk)
�_use_accesspoint_endpoint�_validate_accesspoint_supported�_validate_fips_supported�_validate_global_regions�(_resolve_region_for_accesspoint_endpoint�._resolve_signing_name_for_accesspoint_endpoint�_switch_to_accesspoint_endpointr�r�r%r�r�_s3_addressing_handler)r�r�rr�rkrkror�Ws.



�����zS3EndpointSetter.set_endpointcC�
d|jvSr`�r�r�rkrkror�or�z*S3EndpointSetter._use_accesspoint_endpointcCs�|jsdSd|jddvrtdhd��d|jdvr#td|jd��|jdd}||jkr@|j�dd	�sBtd
|j|fd��dSdS)N�fipsr�r��,Invalid ARN, FIPS region not allowed in ARN.r�r�zhClient is configured to use the FIPS psuedo-region "%s", but outpost ARNs do not support FIPS endpoints.�use_arn_regionTz�Client is configured to use the FIPS psuedo-region for "%s", but the access-point ARN provided is for the "%s" region. For clients using a FIPS psuedo-region calls to access-point ARNs in another region are not allowed.)r�r�rr�r�r��r�r��accesspoint_regionrkrkror�rs2����
����z)S3EndpointSetter._validate_fips_supportedcCs0|j�dd�r	dS|jdvrtd|jd��dS)Nr�T)z
aws-globalz
s3-external-1z�Client is configured to use the global psuedo-region "%s". When providing access-point ARNs a regional endpoint must be specified.r�)r�r�r�rr�rkrkror��s
���z)S3EndpointSetter._validate_global_regionscCs�|jrtdd��|jdd}||jkrtd|j|fd��|jd�d�}|dkr5|j�d�r5td	d��|jd�d
�}|rJ|j�d�rJtdd��|�|�dS)NzZClient does not support s3 accelerate configuration when an access-point ARN is specified.r�r�rgz�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.rhr��use_dualstack_endpointzjClient does not support s3 dualstack configuration when an S3 Object Lambda access point ARN is specified.r�zTClient does not support s3 dualstack configuration when an outpost ARN is specified.)r�rr�r�r�r��_validate_mrap_s3_config)r�r��request_partition�
s3_servicer�rkrkror��s.�
�����z0S3EndpointSetter._validate_accesspoint_supportedcCs>t|j�sdS|j�d�rtdd��|j�d�rtdd��dS)N�$s3_disable_multiregion_access_pointszCInvalid configuration, Multi-Region Access Point ARNs are disabled.r�r�zeClient does not support s3 dualstack configuration when a Multi-Region Access Point ARN is specified.)r�r�r�r�rr�rkrkror��s
���z)S3EndpointSetter._validate_mrap_s3_configcCsNt|j�r|�|d�|jS|j�dd�r$|jdd}|�||�|S|jS)Nr�r�Tr�r�)r�r��_override_signing_regionr�r�r�r�rkrkror��s
�z9S3EndpointSetter._resolve_region_for_accesspoint_endpointcKst|�r
trdStdd��dS)N�s3v4azzUsing S3 with an MRAP arn requires an additional dependency. You will need to pip install botocore[crt] before proceeding.r�)r�rr&)r�r�rrkrkror��s��zS3EndpointSetter.set_signercCs |jdd}|�|j|�dS)Nr�rh�r�r�)r�r��accesspoint_servicerkrkror��sz?S3EndpointSetter._resolve_signing_name_for_accesspoint_endpointcCsTt|j�}t|j|�|j|�|�|j|j�|jdf�}t	�
d|j|f�||_dSr)rr�rr��_get_netlocr��_get_accesspoint_pathr�r�r�r�)r�r�r��original_components�accesspoint_endpointrkrkror��s
���
z0S3EndpointSetter._switch_to_accesspoint_endpointcCst|�r	|�|�S|�||�Sr�)r��_get_mrap_netloc�_get_accesspoint_netloc)r��request_contextr�rkrkror�s
zS3EndpointSetter._get_netloccCs\|d}d}|dg}|jrt|j�j}|�|�n|d}|�d||�|�g�d�|�S)Nr�z	s3-globalr�rgr{r�)r�rr�r�rL�_get_partition_dns_suffixr�)r�r�r�r��mrap_netloc_components�endpoint_url_netlocrgrkrkror�s���
z!S3EndpointSetter._get_mrap_netlocc	Cs�|d}d|d|dfg}|�d�}|jr*|r|�|�t|j�j}|�|�n>|r6|dg}|�|�n|ddkrH|�d|�}|�|�n|�d	|�}|�|�|j�d
�r^|�d�|�||�|�g�d�	|�S)
Nr�z%s-%sr�rir��s3-outpostsrhr�zs3-accesspointr�r+r�)
r�r�r�rr�rL�_inject_fips_if_neededr��_get_dns_suffixr�)	r�r�r�r��accesspoint_netloc_componentsr�r��outpost_host�	componentrkrkror�s:�

��

��
z(S3EndpointSetter._get_accesspoint_netloccCs|jrd|S|S)Nz%s-fips�r�)r�r�r�rkrkror�;sz'S3EndpointSetter._inject_fips_if_neededcCs"|dd}|�d|dd�pdS)Nr�r�r�r�r()r�)r��
original_pathr�r�rkrkror�@sz&S3EndpointSetter._get_accesspoint_pathcCs|j�|�}|dur
|j}|Sr�)r,�get_partition_dns_suffix�_DEFAULT_DNS_SUFFIX)r��partition_name�
dns_suffixrkrkror�Is�z*S3EndpointSetter._get_partition_dns_suffixcC�,|j�d|�}|j}|rd|vr|d}|S�NrK�	dnsSuffix�r,r�r��r�r�r�r�rkrkror�Q��z S3EndpointSetter._get_dns_suffixcC�$|j�di�}||d<||jd<dS�NrHr��r�r��r�r�r�rZrkrkror�Y�z)S3EndpointSetter._override_signing_regioncCs |�di�}||d<||d<dS�NrH�signing_namer�)r�r�r�rZrkrkror�bsz'S3EndpointSetter._override_signing_namecCs�|j�d�rdS|jdurdSt|j�j}|�d�sdS|�d�}|ddkr)dS|dd	�}t|�tt|��kr;dSt	d
d�|D��S)N�use_accelerate_endpointTFrr�rz
s3-accelerater(���css�|]}|tvVqdSr�rrrkrkro�	<genexpr>�s�z<S3EndpointSetter._use_accelerate_endpoint.<locals>.<genexpr>)
r�r�r�rr�r�r�r��set�all)r�r�r��
feature_partsrkrkror�ks


z)S3EndpointSetter._use_accelerate_endpointcCs"|jrdS|j�d�}|r|SdS)N�virtual�addressing_style)r�r�r�)r��configured_addressing_stylerkrkro�_addressing_style�s�z"S3EndpointSetter._addressing_stylecCsH|jdkrt�d�tS|jdks|jdurt�d�dSt�d�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�r�r�r�r�rkrkror��s



z'S3EndpointSetter._s3_addressing_handler�NNNNF)r�r�r�r�r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rkrkrkror�#sD
�"$
!			
"
r�c@s�eZdZdZdZe�d�Z			d6dd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZdS)7�S3ControlEndpointSetterr�rz^[a-zA-Z0-9\-]{1,63}$NFcCr�r�r�r�rkrkror��s�z S3ControlEndpointSetter.__init__cCru)Nzbefore-sign.s3-control)r6r�rxrkrkror6�ryz S3ControlEndpointSetter.registercKs�|�|�r!|�|�|�|�}|�|�|�||�|�|�dS|�|�r?|�|�|�|d�|�	|j
�}|�||�dSdS�Nr�)�_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_validr��_construct_outpost_endpointr��_update_request_netloc)r�r�rr��
new_netlocrkrkror��s





�z$S3ControlEndpointSetter.set_endpointcCr�)Nr�r�r�rkrkror��r�z6S3ControlEndpointSetter._use_endpoint_from_arn_detailscCr�)N�
outpost_idr�r�rkrkror��r�z5S3ControlEndpointSetter._use_endpoint_from_outpost_idcCs�d|jddvrt|jdddhd��|j�dd�s4|jdd}||jkr4d	||jf}t|d
��|jdd}||jkrJtd|j|fd
��|j�d
�rUtdd
��d|jdvrc|�|�dSdS)Nr�r�r�rPr��rkr�r�FzpThe use_arn_region configuration is disabled but received arn for "%s" when the client is configured to use "%s"r�rgzClient 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�)r�r"r�r�r�r!r�r�)r�r��
arn_region�	error_msg�request_partionrkrkror��s8��
�

�����zES3ControlEndpointSetter._validate_endpoint_from_arn_details_supportedcCs|j�d�rtdd��dS)Nr�zPClient does not support s3 dualstack configuration when an outpost is specified.r�)r�r�r!r�rkrkror��s
��z;S3ControlEndpointSetter._validate_outpost_redirection_validcCs2|j�dd�r|jdd}|�||�|S|jS)Nr�Fr�r�)r�r�r�r�r�)r�r�r�rkrkror�s
z8S3ControlEndpointSetter._resolve_region_from_arn_detailscCs|jdd}|�||�|S)Nr�rhr�)r�r��arn_servicerkrkror�sz>S3ControlEndpointSetter._resolve_signing_name_from_arn_detailscCs|�||�}|�||�dSr�)� _resolve_netloc_from_arn_detailsr�)r�r�r�r�rkrkror�sz:S3ControlEndpointSetter._resolve_endpoint_from_arn_detailscCs@t|j�}t|j||j|jdf�}t�d|j|f�||_dSr)rr�rr�r�r�r�r�)r�r�r�r��arn_details_endpointrkrkror�s
��
z.S3ControlEndpointSetter._update_request_netloccCs0|jd}d|vr|�|�S|d}|�||�S)Nr�r�ri)r�r��_construct_s3_control_endpoint)r�r�r�r�rirkrkror�%s


z8S3ControlEndpointSetter._resolve_netloc_from_arn_detailscCs|j�|�Sr�)�_HOST_LABEL_REGEXr�)r��labelrkrkro�_is_valid_host_label,r�z,S3ControlEndpointSetter._is_valid_host_labelcGs"|D]}|�|�st|d��qdS)N)r)rr#)r��labelsrrkrkro�_validate_host_labels/s


��z-S3ControlEndpointSetter._validate_host_labelscCs\|�||�|jrt|j�j}||g}n|dg}|�|�|�|�}|�||g�|�|�S)Nz
s3-control)rr�rr��_add_dualstackr�rL�_construct_netloc)r�r�rir�r�r�rkrkror�4s
�


z6S3ControlEndpointSetter._construct_s3_control_endpointcCs@|�|�|jrt|j�jSd||�|�g}|�|�|�|�Sr�)rr�rr�r��	_add_fipsr)r�r�r�rkrkror�Cs
�

z3S3ControlEndpointSetter._construct_outpost_endpointcCs
d�|�S)Nr�)r��r�r�rkrkrorPr�z)S3ControlEndpointSetter._construct_netloccCs|jr
|dd|d<dSdS)Nrz-fipsr�rrkrkrorSs�z!S3ControlEndpointSetter._add_fipscCs|j�d�r
|�d�dSdS)Nr�r+)r�r�r�rrkrkrorWs�z&S3ControlEndpointSetter._add_dualstackcCr�r�r�r�rkrkror�[r�z'S3ControlEndpointSetter._get_dns_suffixcCr�r�r�r�rkrkror�cr�z0S3ControlEndpointSetter._override_signing_regioncCr�r�r�)r�r�r�rZrkrkror�lr�z.S3ControlEndpointSetter._override_signing_namecCs,|jd}|�d�}|r|�||�dSdS)Nr�r�)r�r��_add_outpost_id_header)r�r�r�r�rkrkror�us


�z5S3ControlEndpointSetter._add_headers_from_arn_detailscCs||jd<dS)Nzx-amz-outpost-id)r�)r�r�r�rkrkror	{�z.S3ControlEndpointSetter._add_outpost_id_headerr�) r�r�r�r�r�r�r�rr�r6r�r�r�r�r�r�r�r�r�r�rrr�r�rrrr�r�r�r�r	rkrkrkror��s>

�
"		
		r�c@s�eZdZe�d�Zddd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�S3ControlArnParamHandlerz[/:]NcCror�rprrrkrkror��rtz!S3ControlArnParamHandler.__init__cCru)Nz!before-parameter-build.s3-controlrvrxrkrkror6�s�z!S3ControlArnParamHandler.registercKs<|jdvr|�|||�dS|�|||�|�|||�dS)N)r�ListRegionalBuckets)r��_handle_outpost_id_param�_handle_name_param�_handle_bucket_param)r�r_r�r�rrkrkrorw�s
z#S3ControlArnParamHandler.handle_arncCsR||vrdSz||}|j�|�}||d<|�|�|d<|WSty(YdSw)NrP�	resources)rqrm�_split_resourcera)r�r_rrkr�rkrkro�_get_arn_details_from_param�s�z4S3ControlArnParamHandler._get_arn_details_from_paramcCs|j�|d�S)Nrj)�_RESOURCE_SPLIT_REGEXr�)r�r�rkrkror�r�z(S3ControlArnParamHandler._split_resourcecCsD|d}d|vr|d|krd|d}t|d|d��||d<dS)Nri�	AccountIdzGAccount ID in arn does not match the AccountId parameter provided: "%s"rPr�)r")r�r_r��
account_idr�rkrkro�_override_account_id_param�s��z3S3ControlArnParamHandler._override_account_id_paramcCsd|vrdS|d|d<dS)N�	OutpostIdr�rk)r�r_r�r�rkrkror
�sz1S3ControlArnParamHandler._handle_outpost_id_paramcCsV|jdkrdS|�|d�}|durdS|�|�r!|�|||�dSd}t|d|d��)N�CreateAccessPoint�Namez4The Name parameter does not support the provided ARNrPr�)r�r�_is_outpost_accesspoint�_store_outpost_accesspointr"�r�r_r�r�r�r�rkrkror�s

�z+S3ControlArnParamHandler._handle_name_paramcC�@|ddkrdS|d}t|�dkrdS|ddko|dd	kS)
Nrhr�Frrfrr|r�r{�r��r�r�rrkrkror��z0S3ControlArnParamHandler._is_outpost_accesspointcC�D|�||�|dd}||d<||d<|dd|d<||d<dS)Nrr�rr�r(r�r��r)r�r_r�r�r�rkrkror��z3S3ControlArnParamHandler._store_outpost_accesspointcCsH|�|d�}|durdS|�|�r|�|||�dSd}t|d|d��)Nr[z6The Bucket parameter does not support the provided ARNrPr�)r�_is_outpost_bucket�_store_outpost_bucketr"rrkrkror�s
��z-S3ControlArnParamHandler._handle_bucket_paramcCr)
Nrhr�Frrfrr|r�rIrrrkrkror$�r z+S3ControlArnParamHandler._is_outpost_bucketcCr!)Nrr�r[r�r(r�r�r")r�r_r�r�r�rkrkror%�r#z.S3ControlArnParamHandler._store_outpost_bucketr�)r�r�r�r�r�rr�r6rwrrrr
rrrrr$r%rkrkrkrors



		rc@sreZdZdZdZdZdZeddgZdej	fdd	�Z
dd
d�Zdd
�Zdd�Z
dd�Zddd�Zdd�Zdd�ZdS)�ContainerMetadataFetcherr�r�r(z
169.254.170.2�	localhostz	127.0.0.1NcCs(|durtjj|jd�}||_||_dS)N)r�)r�r�r��TIMEOUT_SECONDSr��_sleep)r�r��sleeprkrkror�	s�
z!ContainerMetadataFetcher.__init__cCs|�|�|�||�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_urlr�rkrkro�retrieve_full_uri
	s
	z*ContainerMetadataFetcher.retrieve_full_uricCs:tj�|�}|�|j�}|std|jd�|j�f��dS)NzGUnsupported host '%s'.  Can only retrieve metadata from these hosts: %sz, )r��compatr
�_check_if_whitelisted_hostr�rEr��_ALLOWED_HOSTS)r�r-�parsed�is_whitelisted_hostrkrkror+	s����z.ContainerMetadataFetcher._validate_allowed_urlcCs||jvrdSdS)NTF)r1)r�r�rkrkror0 	s
z3ContainerMetadataFetcher._check_if_whitelisted_hostcCs|�|�}|�|�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-rkrkro�retrieve_uri%	s
	
z%ContainerMetadataFetcher.retrieve_uric
Cs�ddi}|dur
|�|�d}	z	|�|||j�WStyC}ztjd|dd�|�|j�|d7}||jkr9�WYd}~nd}~wwq)N�Acceptzapplication/jsonrTzAReceived error when attempting to retrieve container metadata: %srr()	r��
_get_responser(rr�r�r)�
SLEEP_TIME�RETRY_ATTEMPTS)r�r-�
extra_headersr��attemptsrrkrkror,1	s*
��
����z.ContainerMetadataFetcher._retrieve_credentialsc

Cs�zEtjj}|d||d�}|j�|���}|j�d�}|jdkr)t	d|j|fd��zt
�|�WWStyEd}t
�d||�t	|d��wtyZ}	z	d	|	}t	|d��d}	~	ww)
Nrrrhrz4Received 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)r�r�r
r�rrr)r�rrrrCrEr�r�r)
r�r-r�r�r
r�r�
response_textr�rrkrkror7B	s4
���
��
��z&ContainerMetadataFetcher._get_responsecCsd|j|fS)Nzhttp://%s%s)�
IP_ADDRESS)r�r4rkrkror-Z	r
z!ContainerMetadataFetcher.full_urlr�)r�r�r�r(r9r8r>r1�timer*r�r.r+r0r5r,r7r-rkrkrkror&�s



r&cCst|�riSt�Sr�)�should_bypass_proxiesr�r�rkrkror�^	sr�c	Cs6z
tt|�j�rWdSWdSttjfyYdSw)z:
    Returns whether we should bypass proxies or not.
    TF)rr
r�rs�socket�gaierrorrArkrkror@e	s���r@�
ISO-8859-1cCsF|�d�}|s	dSt�|�\}}d|vr|d�d�Sd|vr!|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)r��cgi�parse_headerr\)r��default�content_typer_rkrkro�get_encoding_from_headersz	s
�rJcKs0t|ttf�rt|�}nt|�}t�|��d�S)Nr�)ru�bytes�	bytearray�_calculate_md5_from_bytes�_calculate_md5_from_file�base64�	b64encoder�)r�r�
binary_md5rkrkro�
calculate_md5�	s
rRcCst|�}|��Sr�)rr�)�
body_bytes�md5rkrkrorM�	srMcsB���}t�}t�fdd�d�D]}|�|�q��|�|��S)Ncr�r�r�rk��fileobjrkror��	r�z*_calculate_md5_from_file.<locals>.<lambda>r�)�tellrr�r��seekr�)rV�start_positionrTr�rkrUrorN�	s
rNcKsP|d}|d}tr"|dur$d|vr&t|fi|��}||dd<dSdSdSdS)z1Only add a Content-MD5 if the system supports it.r�r�NzContent-MD5)r
rR)r_rr�r��
md5_digestrkrkro�conditionally_calculate_md5�	s�r[c@s eZdZefdd�Zdd�ZdS)�FileWebIdentityTokenLoadercCs||_||_dSr�)�_web_identity_token_pathrV)r��web_identity_token_pathrVrkrkror��	s
z#FileWebIdentityTokenLoader.__init__cCs8|�|j��}|��Wd�S1swYdSr�)rVr]rR)r��
token_filerkrkro�__call__�	s$�z#FileWebIdentityTokenLoader.__call__N)r�r�r��openr�r`rkrkrkror\�	sr\c@s&eZdZddd�Zdd�Zdd�ZdS)	�SSOTokenLoaderNcCs|duri}||_dSr�)r-)r�r3rkrkror��	s
zSSOTokenLoader.__init__cCst�|�d����S)Nrh)r��sha1rkr�)r��	start_urlrkrkro�_generate_cache_key�	sz"SSOTokenLoader._generate_cache_keycCsJ|�|�}z
|j|}|dWSty$tjddd�d}t|d��w)N�accessTokenzFailed to load SSO token:Trz@The SSO access token has either expired or is otherwise invalid.r<)rer-�KeyErrorr�r�r)r�rdrrr�rkrkror`�	s


�
�zSSOTokenLoader.__call__r�)r�r�r�r�rer`rkrkrkrorb�	s
rb)Tr-r�)rD)�rOr�r?�loggingrqr�r�r	r.r�r�rBrF�dateutil.parserrt�dateutil.tzrr��botocore.awsrequest�botocore.httpsession�botocore.compatrrrrrrr	r
rrr
r�six.moves.urllib.requestrr�botocore.exceptionsrrrrrrrrrrrrrrrr r!r"r#r$r%r&�urllib3.exceptionsr'�	getLoggerr�r�r.r�r�r��
SAFE_CHARSr�r�rr
�
EVENT_ALIASES�IPV4_PAT�HEX_PATr��LS32_PATrl�_variations�UNRESERVED_PATr��IPV6_PAT�ZONE_ID_PAT�IPV6_ADDRZ_PATr��	frozensetr�r{r�r�r�r�r�r�r�r�r�r��	Exceptionr�r��objectr�r/rJrQrarYrSrgraryr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr$r*r+rErarbrnr�r�rr&r�r@rJrRrMrNr[r\rbrkrkrkro�<module>s8`


���������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�5�6�7�8�9�:�;�<�=�>�?�@�A�B�C�D�E�N

	!&V	$-!`
��? !WO{d