HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/site-packages/botocore/__pycache__/utils.cpython-38.pyc
U

KD�g?�D@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddlmZddlmZmZddlZddlmZddlmZddlZddlZddl Zddl!m"Z"dd	l!m#Z#dd
l!m$Z$ddl!m%Z%ddl!m&Z&dd
l!m'Z'ddl!m(Z(ddl!m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNe�OeP�ZQdZRdZSdZTdZUdZVe�Wd�ZXeGe<e:e;fZYdgZZddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d2d5d6d7d8d9d9d&d'd:d;d<d=d>d?d7d@dAdAdBd<dCdDdEdFdGdHd=dIdJdKdLdMdNdNdOd/dFdP�CZ[ejWdQej\dR�Z]dSdT�Z^dUdV�Z_dWdX�Z`dYdZ�Zad[d\�Zbd]d^�Zcd_d`�Zddadb�Zedcdd�Zf�ddfdg�Zgdhdi�ZhGdjdk�dkei�ZjGdldm�dmei�ZkGdndo�do�ZlGdpdq�dqel�ZmGdrds�ds�ZnGdtdu�duel�Zo�ddwdx�Zpdydz�Zqerfd{d|�Zsd}d~�ZteVfdd��ZueVfd�d��Zvd�d��Zwd�d��Zxd�d��Zyd�d��Zz�dd�d��Z{�d	d�d��Z|d�d��Z}d�d��Z~Gd�d��d��ZGd�d��d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z��d
d�d��Z��dd�d��Z�d�d��Z�d�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��Z�Gd�d��d�e��Z�Gd�d��d��Z�Gd�d��d��Z�Gd�d„dƒZ�Gd�dĄd�e��Z�Gd�dƄdƃZ�Gd�dȄdȃZ�Gd�dʄdʃZ�Gd�d̄d̃Z�Gd�d΄d΃Z�Gd�dЄd�e��Z�Gd�d҄d҃Z�d�dԄZ�d�dքZ�d�d؄Z��dd�dۄZ�d�d݄Z�d�d߄Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�Gd�d�d�Z�Gd�d�d�Z�Gd�d�d�Z�d�d�Z�Gd�d��d��Z�d�d��Z�d�dIiZ�ddd�ddd d!d"d#d$d%d)d+d*d,d-d.d�d/d0d4d2d5d8d9d�d&d'd�d�d�d:d�d;d<�dd=�dd>d?d@d7dAdB�ddFdGdH�ddJdKdLdM�ddNdO�d�8Z�dS(�N)�datetime)�
ip_address)�Path)�
getproxies�proxy_bypass)�tzutc)�LocationParseError)�HEX_PAT)�IPV4_PAT)�IPV6_ADDRZ_PAT)�IPV6_PAT)�LS32_PAT)�UNRESERVED_PAT)�ZONE_ID_PAT)�HAS_CRT�IPV4_RE�
IPV6_ADDRZ_RE�
MD5_AVAILABLE�UNSAFE_URL_CHARS�OrderedDict�get_md5�get_tzinfo_options�json�quote�urlparse�urlsplit�
urlunsplit�zip_longest)�ClientError�ConfigNotFound�ConnectionClosedError�ConnectTimeoutError�EndpointConnectionError�HTTPClientError�InvalidDNSNameError�!InvalidEndpointConfigurationError�InvalidExpressionError�InvalidHostLabelError�InvalidIMDSEndpointError�InvalidIMDSEndpointModeError�InvalidRegionError�MetadataRetrievalError�MissingDependencyException�ReadTimeoutError�SSOTokenLoadError�UnsupportedOutpostResourceError�*UnsupportedS3AccesspointConfigurationError�UnsupportedS3ArnError�UnsupportedS3ConfigurationError�UnsupportedS3ControlArnError�&UnsupportedS3ControlConfigurationError�zhttp://169.254.169.254/zhttp://[fd00:ec2::254]/)�ipv4�ipv6z-._~z-z0-9][a-z0-9\-]*[a-z0-9]�	dualstackZmediatailorZpricingZ	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-farmzdirect-connectzapplication-discovery-servicezdatabase-migration-servicezdirectory-servicezdynamodb-streamszelastic-beanstalkZefszelastic-load-balancingZemrzelastic-transcoderzelastic-load-balancing-v2Zseszmarketplace-entitlement-servicezelasticsearch-serviceZeventbridgezkinesis-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-catalog�sfnzstorage-gateway)Czapi.mediatailorzapi.pricingz
api.sagemaker�
apigateway�application-autoscalingZ
appstream2�autoscaling�autoscaling-plans�ce�
cloudhsmv2�cloudsearchdomain�cognito-idp�config�curzdata.iotz
data.jobs.iotzdata.mediastore�datapipeline�
devicefarm�
directconnect�	discovery�dms�ds�dynamodbstreams�elasticbeanstalkZelasticfilesystemZelasticloadbalancingZelasticmapreduce�elastictranscoder�elb�elbv2�emailzentitlement.marketplace�es�eventszcloudwatch-events�iot-data�
iot-jobs-data�kinesisanalytics�kinesisvideo�
lex-models�lex-runtime�logs�machinelearning�marketplace-entitlement�marketplacecommerceanalyticszmetering.marketplace�meteringmarketplace�mghz
models.lexZ
monitoringzmturk-requesterzopsworks-cm�resourcegroupstaggingapi�route53�route53domainszruntime.lex�runtime.sagemaker�sdb�secretsmanager�serverlessrepo�servicecatalogZstates�
stepfunctions�storagegatewayzstreams.dynamodbZtaggingz^X-Amz-Checksum-([a-z0-9]*)$)�flagscCs,t|t�r|St|t�r$|��dkSdSdS)z~Ensures a boolean value if a string or boolean is provided

    For strings, the value for True/False is case insensitive
    �trueFN)�
isinstance�bool�str�lower��val�rp�;/opt/cppython/lib/python3.8/site-packages/botocore/utils.py�ensure_boolean�s


rrcCsL|�d�}|dk	r:|��}|tkr6|td�}tf|��|S|�d�rHdSdS)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)�modeZvalid_modesZ
imds_use_ipv6r7r6)�get_config_variablerm�METADATA_ENDPOINT_MODESr))�sessionZ
endpoint_modeZlendpoint_modeZerror_msg_kwargsrprprq�resolve_imds_endpoint_mode�s��

rxcCs2t|d�o0|j�dd�o0|j�d�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)�hasattrry�get�	type_name)�shaperprprq�is_json_value_header�s

���r�cCs@|dkrdSt|tjj�r"||kS|��dd�|��D�kSdS)z&Case-insensitive check for header key.NFcSsg|]}|���qSrp�rm)�.0�keyrprprq�
<listcomp>�szhas_header.<locals>.<listcomp>)rj�botocore�
awsrequestZHeadersDictrm�keys)�header_name�headersrprprq�
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
    ZserviceAbbreviationZserviceFullNameZAmazon�ZAWSz\W+)�metadatar~�service_name�replace�re�sub)Z
service_model�namerprprq�get_service_module_name�s��r�cCs|sdSt|�S)N�/)�remove_dot_segments��pathrprprq�normalize_url_pathsr�cCs|dkr|St|�SdS)zLReturns None if val is None, otherwise ensure value
    converted to booleanN)rrrnrprprq�normalize_booleansr�cCs�|sdS|�d�}g}|D]0}|r|dkr|dkr@|rJ|��q|�|�q|ddkr^d}nd}|ddkrx|rxd}nd}|d�|�|S)Nr�r��.z..r���)�split�pop�append�join)�urlZ	input_urlZoutput_list�x�first�lastrprprqr�s"

r�cCs6|r|dkrt|d��dD]}||krt|d��qdS)Nr���
expression)�[�]�*)r&)r��invalidrprprq�validate_jmespath_for_set6s

r�TcCs||rt|�|�dd�}|dt|�dkr2|dnd}}|sHt|d��|rp||kr\i||<t||||dd�S|||<dS)Nr�r5rr�r�F)�is_first)r�r��lenr&�set_value_from_jmespath)�sourcer��valuer��bits�current_key�	remainderrprprqr�As "
�r�cCs|�di�}|�d�dk}|S)z9Determine if request is intended for an MRAP accesspoint.�s3_accesspoint�regionr��r~)�contextr��	is_globalrprprq�is_global_accesspoint_sr�c@seZdZdZdS)�_RetriesExceededErrorz@Internal exception used when the number of retries are exceeded.N)�__name__�
__module__�__qualname__�__doc__rprprprqr�fsr�c@seZdZdd�ZdS)�BadIMDSRequestErrorcCs
||_dS�N��request��selfr�rprprq�__init__mszBadIMDSRequestError.__init__N)r�r�r�r�rprprprqr�lsr�c@s�eZdZeZdZdZededddfdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
d dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd!dd�ZdS)"�IMDSFetcherzlatest/api/tokenZ21600r5NcCs�||_||_|dkri}|�||�|_||_|dkr>tj��}|�dd��	�dk|_
|�d�|_||_t
jj|jt|j�d�|_dS)NZAWS_EC2_METADATA_DISABLED�falseri�ec2_metadata_v1_disabled)�timeout�proxies)�_timeout�
_num_attempts�_select_base_url�	_base_url�_config�os�environ�copyr~rm�	_disabled�_imds_v1_disabled�_user_agentr��httpsession�URLLib3Session�get_environ_proxies�_session)r�r��num_attempts�base_url�env�
user_agentrBrprprqr�vs 	
��zIMDSFetcher.__init__cCs|jSr�)r��r�rprprq�get_base_url�szIMDSFetcher.get_base_urlcCs�|dkri}|�d�dk}|�d�}|r6|r6t�d�d}|tkrH|}n|rR|}n|r\t}nt}t�d|���t|�s�t|d��|S)Nrsr7�ec2_metadata_service_endpointzFCustom endpoint and IMDS_USE_IPV6 are both set. Using custom endpoint.zIMDS ENDPOINT: )�endpoint)r~�logger�warning�METADATA_BASE_URL�METADATA_BASE_URL_IPv6�debug�is_valid_urir()r�r�rBZ
requires_ipv6Zcustom_metadata_endpointZchosen_base_urlrprprqr��s*�
�
zIMDSFetcher._select_base_urlcCs,d}|jr|j�d�sd}|j�|�|��S)Nr�r�)r��endswith)r�r��seprprprq�_construct_url�szIMDSFetcher._construct_urlcCs.|��|�|j�}d|ji}|�|�tjjd||d�}t|j	�D]�}zN|j
�|���}|j
dkrp|jWS|j
dkr�WdS|j
dkr�t|��WqDtk
r�YdStk
r�}ztjd||dd	�W5d}~XYqDtk
�r&}z(t|j�d
�t��rt||d��n�W5d}~XYqDXqDdS)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#rj�kwargsr~rr()r�r�r�r��i�response�erprprq�_fetch_metadata_token�sD�
�


�z!IMDSFetcher._fetch_metadata_tokenc
Cs�|��|s|��|dkr"|j}|�|�}i}|dk	r@||d<|�|�t|j�D]r}z8tjj	d||d�}|j
�|���}||�s�|WSWqTt
k
r�}	ztjd||	dd�W5d}	~	XYqTXqT|���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�GETr�r�Tr�)r��_assert_v1_enabled�_default_retryr�r�r�r�r�r�r�r�r�r�r�r�r��_RETRIES_EXCEEDED_ERROR_CLS)
r��url_path�
retry_func�tokenr�r�r�r�r�rrprprq�_get_request�s8

��zIMDSFetcher._get_requestcCs|jdk	r|j|d<dS)Nz
User-Agent)r�)r�r�rprprqr�
s
zIMDSFetcher._add_user_agentcCs|jrt�d�|���dS)Nz)Access to EC2 metadata has been disabled.)r�r�r�rr�rprprqr�s
zIMDSFetcher._assert_enabledcCs|jrtdd��dS)NzLUnable to retrieve token for use in IMDSv2 call and IMDSv1 has been disabled��	error_msg)r�r+r�rprprqrs�zIMDSFetcher._assert_v1_enabledcCs|�|�p|�|�Sr���_is_non_ok_response�	_is_empty�r�r�rprprqrszIMDSFetcher._default_retrycCs"|jdkr|j|ddd�dSdS)Nr�znon-200T��log_bodyF)r��_log_imds_responserrprprqr
s
zIMDSFetcher._is_non_ok_responsecCs|js|j|ddd�dSdS)Nzno bodyTrF)�contentrrrprprqr"szIMDSFetcher._is_emptyFcCs>d}||j|jg}|r*|d7}|�|j�tj|f|��dS)NzHMetadata service returned %s response with status code of %s for url: %sz, content body: %s)r�r�r�rr�r�)r�r�Z
reason_to_logrZ	statementZlogger_argsrprprqr(s�zIMDSFetcher._log_imds_response)N)F)r�r�r�r�rr�r�� DEFAULT_METADATA_SERVICE_TIMEOUTr�r�r�r�r�rr	r�r�rrr
rrrprprprqr�qs,�
$
,r�c@s`eZdZdZddddgZdd�Zdd	d
�Zddd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�ZdS)�InstanceMetadataFetcherz*latest/meta-data/iam/security-credentials/�AccessKeyId�SecretAccessKey�Token�
Expirationc
Cs�z~|��}|�|�}|�||�}|�|�rZ||d|d|d|dd�}|�|�|WSd|krvd|krvt�d|�iWSWnR|jk
r�t�d	|j�Yn0t	k
r�}zt�d
|j
�W5d}~XYnXiS)Nrrrr)�	role_name�
access_key�
secret_keyr�expiry_time�Code�Messagez7Error response received when retrievingcredentials: %s.�\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_fields�_evaluate_expirationr�r�rr�r�r�)r�rr�credentialsrrprprq�retrieve_iam_role_credentials=s6

�

�
� z5InstanceMetadataFetcher.retrieve_iam_role_credentialsNcCs|j|j|j|d�jS�N�rrr)r	�	_URL_PATH�_needs_retry_for_role_namer�)r�rrprprqr!fs
�z%InstanceMetadataFetcher._get_iam_rolecCs$|j|j||j|d�}t�|j�Sr')r	r)�_needs_retry_for_credentialsr�loadsr�)r�rr�rrprprqr"ms�z(InstanceMetadataFetcher._get_credentialscCs:zt�|j�WdStk
r4|�|d�YdSXdS)NFzinvalid jsonT)rr,r��
ValueErrorrrrprprq�_is_invalid_jsonusz(InstanceMetadataFetcher._is_invalid_jsoncCs|�|�p|�|�Sr�rrrprprqr*}sz2InstanceMetadataFetcher._needs_retry_for_role_namecCs|�|�p|�|�p|�|�Sr�)r
rr/rrprprqr+�s

��z4InstanceMetadataFetcher._needs_retry_for_credentialscCs*|jD]}||krt�d|�dSqdS)Nz3Retrieved credentials is missing required field: %sFT)�_REQUIRED_CREDENTIAL_FIELDSr�r�)r�r%�fieldrprprqr#�s
�z7InstanceMetadataFetcher._contains_all_credential_fieldsc
Cs�|�d�}|dkrdSz�tj�|d�}|j�dd�}t�dd�}||}tj��}tj|d�}||}||kr�||}	|	�d�|d<t	�
d|dd	�d
��Wn(tk
r�t	�d|d���YnXdS)Nrz%Y-%m-%dT%H:%M:%SZZec2_credential_refresh_windowiX�x��secondsz�Attempting credential expiration extension due to a credential service availability issue. A refresh of these credentials will be attempted again within the next �<z.0fz	 minutes.zUnable to parse expiry_time in )
r~r�strptimer��random�randint�utcnow�	timedelta�strftimer��infor.r�)
r�r%�
expirationZrefresh_intervalZjitterZrefresh_interval_with_jitter�current_timeZrefresh_offsetZextension_timeZnew_timerprprqr$�s>
��
����z,InstanceMetadataFetcher._evaluate_expiration)N)N)
r�r�r�r)r0r&r!r"r/r*r+r#r$rprprprqr4s�)


rc@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�IMDSRegionProviderNcCs$||_|dkrtj}||_||_dS)aUInitialize IMDSRegionProvider.
        :type session: :class:`botocore.session.Session`
        :param session: The session is needed to look up configuration for
            how to contact the instance metadata service. Specifically the
            whether or not it should use the IMDS region at all, and if so how
            to configure the timeout and number of attempts to reach the
            service.
        :type environ: None or dict
        :param environ: A dictionary of environment variables to use. If
            ``None`` is the argument then ``os.environ`` will be used by
            default.
        :type fecther: :class:`botocore.utils.InstanceMetadataRegionFetcher`
        :param fetcher: The class to actually handle the fetching of the region
            from the IMDS. If not provided a default one will be created.
        N)r�r�r��_environ�_fetcher)r�rwr��fetcherrprprqr��s
zIMDSRegionProvider.__init__cCs|��}|S)z#Provide the region value from IMDS.)�_get_instance_metadata_region)r�Zinstance_regionrprprq�provide�szIMDSRegionProvider.providecCs|��}|��}|Sr�)�_get_fetcher�retrieve_region)r�rBr�rprprqrC�sz0IMDSRegionProvider._get_instance_metadata_regioncCs|jdkr|��|_|jSr�)rA�_create_fetcherr�rprprqrE�s

zIMDSRegionProvider._get_fetchercCsX|j�d�}|j�d�}|j�d�t|j�|j�d�d�}t|||j|j��|d�}|S)NZmetadata_service_timeoutZmetadata_service_num_attemptsr�r�)r�rsr�)r�r�r�r�rB)r�rurx�InstanceMetadataRegionFetcherr@r�)r�Zmetadata_timeoutZmetadata_num_attemptsZimds_configrBrprprqrG�s0�������z"IMDSRegionProvider._create_fetcher)NN)r�r�r�r�rDrCrErGrprprprqr?�s

r?c@s eZdZdZdd�Zdd�ZdS)rHz-latest/meta-data/placement/availability-zone/cCs8z|��}|WS|jk
r2t�d|j�YnXdS)aRGet the current region from the instance metadata service.
        :rvalue: str
        :returns: The region the current instance is running in or None
            if the instance metadata service cannot be contacted or does not
            give a valid response.
        :rtype: None or str
        :returns: Returns the region as a string if it is configured to use
            IMDS as a region source. Otherwise returns ``None``. It will also
            return ``None`` if it fails to get the region from IMDS due to
            exhausting its retries or not being able to connect.
        r N)�_get_regionrr�r�r�)r�r�rprprqrF�s�
z-InstanceMetadataRegionFetcher.retrieve_regioncCs2|��}|j|j|j|d�}|j}|dd�}|S)Nr(r�)rr	r)rr�)r�rr�Zavailability_zoner�rprprqrIs�z)InstanceMetadataRegionFetcher._get_regionN)r�r�r�r)rFrIrprprprqrH�srHFcCs�|D]�}t||t�rH||kr:||kr:t||||�q�||||<qt||t�r�|r�||kr�t||t�r�||�||�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)rj�dict�merge_dicts�list�extend)Zdict1Zdict2Zappend_listsr�rprprqrKsrKcCs"i}|D]}||||��<q|S)zDCopies the given dictionary ensuring all keys are lowercase strings.r�)�originalr�r�rprprq�lowercase_dict9srOc
CsVz2||�� }|��}t|�W5QR�WSQRXWntk
rPt|d��YnXdS)Nr�)�read�parse_key_val_file_contents�OSErrorr)�filename�_open�f�contentsrprprq�parse_key_val_fileAs
 rWcCsHi}|��D]6}d|krq|�dd�\}}|��}|��}|||<q|S)N�=r5)�
splitlinesr��strip)rV�final�liner�rorprprqrQJs
rQcCs�g}t|d�r|��}n|}|D]V\}}t|t�rZ|D] }|�t|��dt|����q6q |�t|��dt|����q d�|�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.

    �itemsrX�&)r}r]rjrLr��percent_encoder�)�mapping�safeZ
encoded_pairs�pairsr�r��elementrprprq�percent_encode_sequenceYs


��rdcCs6t|ttf�st|�}t|t�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)ra)rj�bytesrl�encoder)�	input_strrarprprqr_s



r_c	Cs6tjddddddt�d�}|�|��}|tj|d�S)a�Parse numerical epoch timestamps (seconds since 1970) into a
    ``datetime.datetime`` in UTC using ``datetime.timedelta``. This is intended
    as fallback when ``fromtimestamp`` raises ``OverflowError`` or ``OSError``.

    :type value: float or int
    :param value: The Unix timestamps as number.

    :type tzinfo: callable
    :param tzinfo: A ``datetime.tzinfo`` class or compatible callable.
    �r5r��tzinfor3)rr�
astimezoner:)r�rkZ
epoch_zeroZepoch_zero_localizedrprprq�_epoch_seconds_to_datetime�srmc
Cs�t|ttf�rtj�||��Sztj�t|�|��WSttfk
rLYnXztjj	|dt
�id�WSttfk
r�}ztd|�d|����W5d}~XYnXdS)z.Parse timestamp with pluggable tzinfo options.�GMT)ZtzinfoszInvalid timestamp "z": N)rj�int�floatr�
fromtimestamp�	TypeErrorr.�dateutil�parser�parser)r�rkrrprprq�_parse_timestamp_with_tzinfo�srvcCs�t�}|D]N}zt||�WSttfk
rV}ztjd|j|d�W5d}~XYq
Xq
zt|�}Wntt	fk
r~YnZXz|D]}t
||d�WSWn8ttfk
r�}ztjd|j|d�W5d}~XYnXtd|�d���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.r�NrjzHUnable to parse timestamp using fallback method with "%s" timezone info.z1Unable to calculate correct timezone offset for "�")rrvrR�
OverflowErrorr�r�r�rprrr.rm�RuntimeError)r�Ztzinfo_optionsrkrZ
numeric_valuerprprq�parse_timestamp�s4��
�rzcCsBt|t�r|}nt|�}|jdkr2|jt�d�}n|�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.

    Nrj)rj�_DatetimeClassrzrkr�rrl)r��datetime_objrprprq�parse_to_aware_datetime�s

r}cCsRt�ddd�}|jdkr2|dkr&t�}|j|d�}|jdd�|��|}|��S)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
    rir5Nrj)rrkrr��	utcoffset�
total_seconds)�dtZdefault_timezone�epoch�drprprq�datetime2timestamps

r�csBt��}t�fdd�d�D]}|�|�q|r6|��S|��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
��d�S�N��rPrp��bodyrprq�<lambda>:�z"calculate_sha256.<locals>.<lambda>r�N)�hashlib�sha256�iter�update�	hexdigest�digest)r�Zas_hex�checksum�chunkrpr�rq�calculate_sha256'sr�cs�g}d�tj}t��fdd�d�D]}|�||����q"|sJ|d���St|�dkr�g}t|�D]2\}}|dk	r�|�|||����qb|�|�qb|}qJt�	|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�rp�r�Zrequired_chunk_sizerprqr�Sr�z%calculate_tree_hash.<locals>.<lambda>r�r5Nr�ascii)r�r�r�r�r�r�r��	_in_pairs�binascii�hexlify�decode)r��chunksr�r�Z
new_chunksr��secondrpr�rq�calculate_tree_hashBsr�cCst|�}t||�Sr�)r�r)�iterableZshared_iterrprprqr�cs	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
||_dSr�)�_fget)r��fgetrprprqr�|szCachedProperty.__init__cCs,|dkr|S|�|�}||j|jj<|SdSr�)r��__dict__r�)r��obj�clsZcomputed_valuerprprq�__get__s

zCachedProperty.__get__N)r�r�r�r�r�r�rprprprqr�tsr�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
||_dSr�)�_use_member_names)r�Zuse_member_namesrprprqr��szArgumentGenerator.__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��stackrprprq�generate_skeleton�s
z#ArgumentGenerator.generate_skeletonr�cCs�|�|j�z�|jdkr(|�||�W��S|jdkrB|�||�W��S|jdkr\|�||�W��S|jdkr�|jrt|W�|S|jr�t	�
|j�W�fSW�`dS|jdkr�W�NdS|jdkr�W�<d	S|jd
kr�W�*dS|jdkr�t�d
ddddd�W�SW5|��XdS)NZ	structurerL�mapr|r�)�integer�longr)rp�doubleg�booleanT�	timestamprir5)r�r�r�r�_generate_type_structure�_generate_type_list�_generate_type_mapr��enumr7�choicer�r�r�r�r�rprprqr��s.







z$ArgumentGenerator._generate_skeletoncCsF|�|j�dkriSt�}|j��D]\}}|j|||d�||<q$|S)Nr5)r�)�countr�r�membersr]r�)r�r�r�Zskeleton�member_nameZmember_shaperprprqr��s�z*ArgumentGenerator._generate_type_structurecCs$d}|jr|jj}|�|j||�gS)Nr�)r��memberr�r�r�rprprqr��s
�z%ArgumentGenerator._generate_type_listcCs0|j}|j}|jdkst�td|�||�fg�S)Nr|ZKeyName)r�r�r�AssertionErrorrr�)r�r�r�Z	key_shapeZvalue_shaperprprqr��s��z$ArgumentGenerator._generate_type_mapN)F)r�)
r�r�r�r�r�r�r�r�r�r�rprprprqr��s



r�cCs.t�|�rdSdt|�j�d�}t�|�dk	S)NFr�r�)r�intersectionr�hostnamer�match��endpoint_urlr�rprprq�is_valid_ipv6_endpoint_url�s
r�cCst|�j}t�|�dk	Sr�)rr�rr�r�rprprq�is_valid_ipv4_endpoint_url�s
r�cCsht�|�rdSt|�}|j}|dkr(dSt|�dkr8dS|ddkrP|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}(?<!-))$)	rr�rr�r�r��compile�
IGNORECASEr�)r��partsr��allowedrprprq�is_valid_endpoint_url�s
�r�cCst|�pt|�Sr�)r�r�)r�rprprqr�s
�r�cCs2|dkrdSt�d�}|�|�}|s.t|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�Zvalid_host_labelZvalidrprprq�validate_region_names

r�cCsRd|krdSt|�}|dks$|dkr(dSt�|�}|dksJ|��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)r��LABEL_REr��end)�bucket_name�nr�rprprq�check_dns_name%s
r�c
Ks`|j�dd�rd}zt|||�Wn8tk
rZ}z|jd}t�d|�W5d}~XYnXdS)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.comr�z2Not changing URI, bucket is not DNS compatible: %sN)r�r~�switch_to_virtual_host_styler$r�r�r�)r��signature_versionr��default_endpoint_urlr�rr�rprprq�fix_s3_host<s�
�r�cKs|jdk	rdSt|�r$t�d�dSt|j�}|j|_|j�d�}|dkrP|j}t	|�dk�r|d}|sndSt�d|j�t
|��rt	|�dkr�|jddkr�|jd7_|�|�d�|�p�d}|}|d|}	|j
|	||jd	f}
t|
�}||_t�d
|�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�r5z*Checking for DNS compatible bucket for: %s�r�r�r�zURI updated to: %s)r�)Z	auth_path�_is_get_bucket_location_requestr�r�rr�r�r��netlocr�r��remover��scheme�queryrr$)r�r�r�r�r��
path_partsr�r�Zglobal_endpoint�hostZ	new_tupleZnew_urirprprqr�Ys<
�


r�cCs|j�d�S)Nz	?location)r�r�r�rprprqr��sr�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.

    cs\�|f}|r&tt|����}�||f}|j�|�}|dk	r>|S�|f|�|�}||j|<|Sr�)�tuple�sortedr]Z_instance_cacher~)r��argsr��	cache_keyZkwarg_items�result��func�	func_namerprq�_cache_guard�s

z$instance_cache.<locals>._cache_guard)r��	functools�wraps)r�r�rpr�rq�instance_cache�sr�cs��fdd�}|S)a
    Version of functools.lru_cache that stores a weak reference to ``self``.

    Serves the same purpose as :py:func:`instance_cache` but uses Python's
    functools implementation which offers ``max_size`` and ``typed`` properties.

    lru_cache is a global cache even when used on a method. The cache's
    reference to ``self`` will prevent garbage collection of the object. This
    wrapper around functools.lru_cache replaces the reference to ``self`` with
    a weak reference to not interfere with garbage collection.
    cs:tj����fdd���t����fdd��}�j|_|S)Ncs�|�f|�|�Sr�rp)Zweakref_to_selfr�r�)r�rprq�func_with_weakref�sz=lru_cache_weakref.<locals>.wrapper.<locals>.func_with_weakrefcs>|��D]\}}t|t�rt|�||<q�t�|�f|�|�Sr�)r]rjrLr��weakref�ref)r�r�r�Z	kwarg_keyZkwarg_value)r�rprq�inner�s
z1lru_cache_weakref.<locals>.wrapper.<locals>.inner)r��	lru_cacher��
cache_info)r�r���
cache_args�cache_kwargs)r�r�rq�wrapper�s
z"lru_cache_weakref.<locals>.wrapperrp)r�r�r�rpr�rq�lru_cache_weakref�s
r�cKsht|j�j�d�}dd�|D�}d}t|�dkrB|d�|�d7}|d7}|dkrVdSt||d	d
�dS)z?Switches the current s3 endpoint with an S3 Accelerate endpointr�cSsg|]}|tkr|�qSrp��S3_ACCELERATE_WHITELIST�r��prprprqr��sz-switch_host_s3_accelerate.<locals>.<listcomp>zhttps://s3-accelerate.r�
amazonaws.com)ZListBuckets�CreateBucketZDeleteBucketNF)�use_new_scheme)rr�r�r�r�r��
_switch_hosts)r��operation_namer�r�r�rprprq�switch_host_s3_accelerate�sr�cCs2t�|j�d��}|�|�r.||}t||�dS)zBSwitches the host using a parameter value from a JSON request bodyreN)rr,�datar�r~r�)r��
param_nameZrequest_json�new_endpointrprprq�switch_host_with_param�s
rcCst|j||�}||_dSr�)�_get_new_endpointr�)r�rr��final_endpointrprprqr��s�r�cCsVt|�}t|�}|j}|r |j}||j|j|jdf}t|�}t�d|�d|���|S�Nr�zUpdating URI from � to )rr�r�r�r�rr�r�)Zoriginal_endpointrr�Znew_endpoint_componentsZoriginal_endpoint_componentsr�Zfinal_endpoint_componentsrrprprqr�s�rcCsR|D]H}||kr@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)rjrJ�
deep_merge)�base�extrar�rprprqrs���rcCs|�dd���S)zcTranslate the form used for event emitters.

    :param service_id: The service_id to convert.
    � �-)r�rm)Z
service_idrprprq�hyphenize_service_id&src@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�
IdentityCachez�Base IdentityCache implementation for storing and retrieving
    highly accessed credentials.

    This class is not intended to be instantiated in user code.
    Zbase_identity_cachecCs||_||_dSr���_client�_credential_cls�r��client�credential_clsrprprqr�7szIdentityCache.__init__cKs.|jf|�}|�}|jj|||jddd�}|S)N�-�
)r�Z
refresh_usingr�Zadvisory_timeoutZmandatory_timeout)�build_refresh_callbackrZcreate_from_metadata�METHOD)r�r��callbackr�Zcredential_entryrprprq�get_credentials;s�zIdentityCache.get_credentialscKs
t��dS)z�Callback to be implemented by subclasses.

        Returns a set of metadata to be converted into a new
        credential instance.
        N)�NotImplementedError)r�rprprqrGsz$IdentityCache.build_refresh_callbackN)r�r�r�r�rr�rrrprprprqr.s
rcsJeZdZdZdZdd�Zejdd��fdd��Zd	d
�Z	ddd
�Z
�ZS)�S3ExpressIdentityCachez�S3Express IdentityCache for retrieving and storing
    credentials from CreateSession calls.

    This class is not intended to be instantiated in user code.
    �	s3expresscCs||_||_dSr�r
rrprprqr�YszS3ExpressIdentityCache.__init__�d)�maxsizecst�j|d�S)N��bucket)�superr)r�r��	__class__rprqr]sz&S3ExpressIdentityCache.get_credentialscs��fdd�}|S)NcsB�jj�d�}|d}�j|ddd�}|d|d|d|d	�S)
N��Bucket�CredentialsrT)�isorrZSessionToken)rrrr)rZcreate_session�_serialize_if_needed)r��credsr=�rr�rprq�	refresherbs��z@S3ExpressIdentityCache.build_refresh_callback.<locals>.refresherrp)r�rr*rpr)rqras
z-S3ExpressIdentityCache.build_refresh_callbackFcCs$t|t�r |r|��S|�d�S|S�Nz%Y-%m-%dT%H:%M:%S%Z�rjr{�	isoformatr;�r�r�r&rprprqr'qs


z+S3ExpressIdentityCache._serialize_if_needed)F)r�r�r�r�rr�r�r�rrr'�
__classcell__rprpr!rqrPs
rc@s0eZdZd
dd�Zddd�Zdd�Zdd	�ZdS)�S3ExpressIdentityResolverNcCs*t�|�|_|dkr t|j|�}||_dSr�)r��proxyrr�_cache)r�rr�cacherprprqr�zsz"S3ExpressIdentityResolver.__init__cCs8t�d�|p|jjj}|�d|j�|�d|j�dS)Nz'Registering S3Express Identity Resolver�before-call.s3�before-sign.s3)r�r�r�metarQ�register�apply_signing_cache_key�resolve_s3express_identity�r��
event_emitterZemitterrprprqr7�s
z"S3ExpressIdentityResolver.registercKsV|�di�}|�dd�}|�di��d�}|dkrR|dk	rR|�di�||dd<dS)N�endpoint_properties�backendZinput_paramsr$�	S3Express�signingr�)r~�
setdefault)r��paramsr�r�r<r=r�rprprqr8�sz1S3ExpressIdentityResolver.apply_signing_cache_keyc	Ks`|j�di�}|�d�}|dkr\|�d�r\|j|d<d|kr\|j�di��di��d	�|d<dS)
Nr?�signing_namerzv4-s3expressZidentity_cacher��s3_redirectrAr$)r�r~�
startswithr2)	r�r�rBr�r�Zrequest_signerr�r��signing_contextrprprqr9�s

�
���z4S3ExpressIdentityResolver.resolve_s3express_identity)N)N)r�r�r�r�r7r8r9rprprprqr0ys


r0c@sLeZdZdZddd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�S3RegionRedirectorv2a
Updated version of S3RegionRedirector for use when
    EndpointRulesetResolver is in use for endpoint resolution.

    This class is considered private and subject to abrupt breaking changes or
    removal without prior announcement. Please do not use it directly.
    NcCs|pi|_t�|�|_dSr�)r2r�r1r�r�Zendpoint_bridgerr3rprprqr��s
zS3RegionRedirectorv2.__init__cCsFt�d�|p|jjj}|�d|j�|�d|j�|�d|j�dS)Nz(Registering S3 region redirector handler�needs-retry.s3�before-parameter-build.s3zbefore-endpoint-resolution.s3)	r�r�rr6rQr7�redirect_from_error�annotate_request_context�redirect_from_cacher:rprprqr7�s
��zS3RegionRedirectorv2.registerc	Ks,|dkrdS|�di��di�}t�|�d��r>t�d�dS|�d�rVt�d�dS|d�d	i�}|�d
�}|d�di�}|dko�|jd
k}	|dko�|jdko�d|�di�k}
|dko�d|k}|ddk	o�|djdk}|dk}
|dko�|jdk}t|	||
|
||g��sdS|ddd}|d�d�}|�||�}|dk�rbt�d|�d|�d��dSt�d|�d|�d|�d��||j	|<|j
j}|j||ddd|dd�}|�
|d |j�|d <d!|ddd<|j�d"�}|dk	�r(|�|�}|\}}||dd#<|d�d$i�|�|dd$<dS)%�
        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�rCrzBS3 request was previously for an Accesspoint ARN, not redirecting.�
redirected�6S3 request was previously redirected, not redirecting.r5�Errorr�ResponseMetadata�Z301Z400�
HeadObject�
HeadBucket�x-amz-bucket-region�HTTPHeaders�AuthorizationHeaderMalformed�Regionr�i-i.i3�PermanentRedirectZ"IllegalLocationConstraintExceptionr��
client_region� S3 client configured for region � but the bucket �S is not in that region and the proper region could not be automatically determined.� is in region �b; Please configure the proper region to avoid multiple unnecessary redirects and signing attempts.rA)Zoperation_modelZ	call_args�request_contextr�TZauthSchemes�	auth_typer?)r~�	ArnParser�is_arnr�r�r�r��any�get_bucket_regionr2rZ_ruleset_resolver�construct_endpoint�set_request_urlr��
propertiesZauth_schemes_to_signing_ctx)r��request_dictr��	operationr�Zredirect_ctxr��
error_code�response_metadata�is_special_head_object�is_special_head_bucket�is_wrong_signing_region�is_redirect_status�is_permanent_redirectZis_opt_in_region_redirectrr[�
new_regionZep_resolverZep_infoZauth_schemesZ	auth_inforbrErprprqrJ�s��
�
��
��������

��
��

�z(S3RegionRedirectorv2.redirect_from_errorc
Cs�|d}|dd}d|kr$|dS|�di��dd�}|dk	rD|Sz|jj|d�}|dd}Wn0tk
r�}z|jdd}W5d}~XYnX|�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.
        r5rQrVrUrPrXNr#�r~rZhead_bucketrr��r�rr�Zservice_response�response_headersr�r�rrprprqrf0s
 z&S3RegionRedirectorv2.get_bucket_regioncKst||d�S)z�
        Splice a new endpoint into an existing URL. Note that some endpoints
        from the the endpoint provider have a path component which will be
        discarded by this function.
        F)r)r��old_urlrr�rprprqrhQsz$S3RegionRedirectorv2.set_request_urlcKs4|�d�}|dk	r0||jkr0|j�|�}||d<dS)a
        If a bucket name has been redirected before, it is in the cache. This
        handler will update the AWS::Region endpoint resolver builtin param
        to use the region from cache instead of the client region to avoid the
        redirect.
        r$NzAWS::Region)r~r2)r��builtinsrAr�rrsrprprqrLYs
z(S3RegionRedirectorv2.redirect_from_cachecKs|�d�}d||d�|d<dS)z�Store the bucket name in context for later use when redirecting.
        The bucket name may be an access point ARN or alias.
        r$F)rNrrArCNr�)r�rAr�r�rrprprqrKes

�z-S3RegionRedirectorv2.annotate_request_context)N)N)r�r�r�r�r�r7rJrfrhrLrKrprprprqrF�s

p!rFc@sLeZdZdZddd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�S3RegionRedirectorz�This handler has been replaced by S3RegionRedirectorv2. The original
    version remains in place for any third-party libraries that import it.
    NcCs:||_||_|jdkri|_t�|�|_tjdtd�dS)Nz�The S3RegionRedirector class has been deprecated for a new internal replacement. A future version of botocore may remove this class.��category)�_endpoint_resolverr2r�r1r�warnings�warn�
FutureWarningrGrprprqr�vs
�zS3RegionRedirector.__init__cCs<|p|jjj}|�d|j�|�d|j�|�d|j�dS)NrHr4rI)rr6rQr7rJrhrLr:rprprqr7�szS3RegionRedirector.registerc	Ks�|dkrdS|�|�di��r,t�d�dS|�di��d�rLt�d�dS|d�di�}|�d�}|d�d	i�}|d
ko�|jdk}|d
ko�|jdko�d
|�di�k}	|dko�d|k}
|ddk	o�|djdk}|dk}t||
||	|g�s�dS|ddd}
|d�d�}|�|
|�}|dk�rBt�d|�d|
�d��dSt�d|�d|
�d|�d��|j�	d|�}|d}||
|d�}||dd<||j
|
<|�||d�d|dd<dS) rMNr�z=S3 request was previously to an accesspoint, not redirecting.Z
s3_redirectedrOr5rPrrQrRrSrTrUrVrWrXrrYrZr?rr[r\r]r^r_r`�s3r�)r�rr�T)�_is_s3_accesspointr~r�r�r�r�rerfr}�resolver2rh)r�rjr�rkr�r�rlrmrnrorprqrrrr[rsr�rErprprqrJ�s~��
��
�������	
���
z&S3RegionRedirector.redirect_from_errorc
Cs�|d}|dd}d|kr$|dS|�di��dd�}|dk	rD|Sz|jj|d�}|dd}Wn0tk
r�}z|jdd}W5d}~XYnX|�dd�}|Srtrurvrprprqrf�s
 z$S3RegionRedirector.get_bucket_regioncKs4|�di��dd�}|dk	r0t|d|d�|d<dS)Nr?r�r�F)r~r�r�rAr�r�r�rprprqrhsz"S3RegionRedirector.set_request_urlcKsF|�|�rdS|�d�}|j�|�}|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.
        Nr$r?r)r�r~r2)r�rAr�r�rrErprprqrLs


z&S3RegionRedirector.redirect_from_cachecCsd|kS�Nr�rp)r�r�rprprqr�sz%S3RegionRedirector._is_s3_accesspoint)N)N)r�r�r�r�r�r7rJrfrhrLr�rprprprqrzqs

^!rzc@seZdZdS)�InvalidArnExceptionN)r�r�r�rprprprqr�#sr�c@s eZdZdd�Zedd��ZdS)rccCsL|�dd�}t|�dkr(td|�d���|d|d|d|d	|dd
�S)N�:��zProvided ARN: zE must be of the format: arn:partition:service:region:account:resourcer5r�r��)�	partition�servicer��account�resource)r�r�r�)r��arnZ	arn_partsrprprq�	parse_arn(s
��zArnParser.parse_arncCsJt|t�r|�d�sdSt�}z|�|�WdStk
rDYdSXdS)Nzarn:FT)rjrlrDrcr�r�)r��
arn_parserrprprqrd7s
zArnParser.is_arnN)r�r�r�r��staticmethodrdrprprprqrc'srcc@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}$)r�NcCs||_|dkrt�|_dSr���_arn_parserrc�r�r�rprprqr�MszS3ArnParamHandler.__init__cCs|�d|j�dS)NrI�r7�
handle_arn�r�r;rprprqr7RszS3ArnParamHandler.registercKs`|j|jkrdS|�|�}|dkr&dS|ddkrB|�|||�n|ddkr\|�|||�dS)N�
resource_type�accesspoint�outpost)r��_BLACKLISTED_OPERATIONS�"_get_arn_details_from_bucket_param�_store_accesspoint�_store_outpost)r�rA�modelr�r��arn_detailsrprprqr�Us
zS3ArnParamHandler.handle_arncCsHd|krDz&|d}|j�|�}|�||�|WStk
rBYnXdS)Nr$)r�r��_add_resource_type_and_namer�)r�rAr�r�rprprqr�`sz4S3ArnParamHandler._get_arn_details_from_bucket_paramcCs@|j�|d�}|r2|�d�|d<|�d�|d<n
t|d��dS)Nr�r��
resource_name)r�)�_RESOURCE_REGEXr��groupr1)r�r�r�r�rprprqr�ks
z-S3ArnParamHandler._add_resource_type_and_namecCs8|d|d<|d|d|d|d|dd�|d<dS)	Nr�r$r�r�r�r�)r�r�r�r�r�r�rp�r�rAr�r�rprprqr�ss�z$S3ArnParamHandler._store_accesspointcCsd|d}|j�|�}|s"t|d��|�d�}||d<|�d�||d|d|d|d	d
�|d<dS)Nr�)r��accesspoint_namer$�outpost_namer�r�r�r�)r�r�r�r�r�r�r�)�_OUTPOST_RESOURCE_REGEXr�r/r�)r�rAr�r�r�r�r�rprprqr��s

�z S3ArnParamHandler._store_outpost)N)r�r�r�r�r�r�r�r�r�r7r�r�r�r�r�rprprprqr�Cs��
r�c@s�eZdZdZdZd7dd�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�awsr�NFcCsF||_||_||_||_|dkr&i|_||_||_|dkrB|j|_dSr��r}�_region�
_s3_config�_use_fips_endpoint�
_endpoint_url�
_partition�_DEFAULT_PARTITION�r��endpoint_resolverr��	s3_configr�r��use_fips_endpointrprprqr��s
zS3EndpointSetter.__init__cCs.|�d|j�|�d|j�|�d|j�dS)Nr5zchoose-signer.s3z%before-call.s3.WriteGetObjectResponse)r7�set_endpoint�
set_signer�#update_endpoint_to_s3_object_lambdar�rprprqr7�s�zS3EndpointSetter.registercKsh|jrtdd��|�|d�|jr&dS|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_endpointr2�_override_signing_namer�r}rgr��formatr)r�rAr�r��resolver�resolvedrrprprqr��s"���z4S3EndpointSetter.update_endpoint_to_s3_object_lambdacKs�|�|�rL|�|�|�|�|�|�|�|�}|�|�|�||�dS|jr~|jrlt	d|j
�d�d��tfd|i|��|jr�|jfd|i|��dS)Nz8Client is configured to use the FIPS psuedo region for "zA", but S3 Accelerate does not have any FIPS compatible endpoints.r�r�)
�_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�r2r�r��_s3_addressing_handler)r�r�r�r�rprprqr��s$



�
�zS3EndpointSetter.set_endpointcCs
d|jkSr��r�r�rprprqr��sz*S3EndpointSetter._use_accesspoint_endpointcCs�|js
dSd|jddkr(tdhd��d|jdkrJtd|j�d�d��|jdd}||jkr�|j�d	d
�s�td|j�d|�d
�d��dS)N�fipsr�r��,Invalid ARN, FIPS region not allowed in ARN.r�r�z4Client is configured to use the FIPS psuedo-region "z2", but outpost ARNs do not support FIPS endpoints.�use_arn_regionTz8Client is configured to use the FIPS psuedo-region for "z1", but the access-point ARN provided is for the "zn" region. For clients using a FIPS psuedo-region calls to access-point ARNs in another region are not allowed.)r�r�r0r�r�r~�r�r�Zaccesspoint_regionrprprqr��s ��
�z)S3EndpointSetter._validate_fips_supportedcCs4|j�dd�rdS|jdkr0td|j�d�d��dS)Nr�T)z
aws-globalz
s3-external-1z6Client is configured to use the global psuedo-region "zJ". When providing access-point ARNs a regional endpoint must be specified.r�)r�r~r�r0r�rprprqr�
	s
�z)S3EndpointSetter._validate_global_regionscCs�|jrtdd��|jdd}||jkrBtd|j�d|�d�d��|jd�d�}|d	krp|j�d
�rptdd��|jd�d�}|r�|j�d
�r�td
d��|�|�dS)NzZClient does not support s3 accelerate configuration when an access-point ARN is specified.r�r�r��Client is configured for "z3" partition, but access-point ARN provided is for "zE" partition. The client and  access-point partition must be the same.r�r��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�r0r�r�r~r��_validate_mrap_s3_config)r�r�Zrequest_partitionZ
s3_servicer�rprprqr�	s,�
����z0S3EndpointSetter._validate_accesspoint_supportedcCs@t|j�sdS|j�d�r&tdd��n|j�d�r<tdd��dS)NZ$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~r0r�rprprqr�>	s
��z)S3EndpointSetter._validate_mrap_s3_configcCsJt|j�r|�|d�n,|j�dd�rD|jdd}|�||�|S|jS)Nr�r�Tr�r�)r�r��_override_signing_regionr�r~r�r�rprprqr�P	s
z9S3EndpointSetter._resolve_region_for_accesspoint_endpointcKst|�rtrdStdd��dS)NZs3v4azzUsing S3 with an MRAP arn requires an additional dependency. You will need to pip install botocore[crt] before proceeding.r�)r�rr,)r�r�r�rprprqr�]	s�zS3EndpointSetter.set_signercCs |jdd}|�|j|�dS)Nr�r��r�r�)r�r�Zaccesspoint_servicerprprqr�h	sz?S3EndpointSetter._resolve_signing_name_for_accesspoint_endpointcCsXt|j�}t|j|�|j|�|�|j|j�|jdf�}t	�
d|j�d|���||_dSr)rr�rr��_get_netlocr��_get_accesspoint_pathr�r�r�r�)r�r�r��original_componentsZaccesspoint_endpointrprprqr�l	s 
����z0S3EndpointSetter._switch_to_accesspoint_endpointcCs"t|�r|�|�S|�||�SdSr�)r��_get_mrap_netloc�_get_accesspoint_netloc)r�rar�rprprqr�~	s
zS3EndpointSetter._get_netloccCs\|d}d}|dg}|jr4t|j�j}|�|�n|d}|�d||�|�g�d�|�S)Nr�z	s3-globalr�r�r�r�)r�rr�r�rM�_get_partition_dns_suffixr�)r�rar�r�Zmrap_netloc_components�endpoint_url_netlocr�rprprqr��	s
��z!S3EndpointSetter._get_mrap_netlocc	Cs�|d}d�|d|d�g}|�d�}|jrT|r<|�|�t|j�j}|�|�n||rl|dg}|�|�n:|ddkr�|�d|�}|�|�n|�d	|�}|�|�|j�d
�r�|�d�|�||�	|�g�d�
|�S)
Nr�z{}-{}r�r�r��s3-outpostsr�r�zs3-accesspointr�r8r�)r�r~r�r�rr�rM�_inject_fips_if_neededr��_get_dns_suffixr�)	r�rar�r�Zaccesspoint_netloc_componentsr�r�Zoutpost_host�	componentrprprqr��	s:�

��

�z(S3EndpointSetter._get_accesspoint_netloccCs|jr|�d�S|S)N�-fips�r�)r�r�rarprprqr��	s
z'S3EndpointSetter._inject_fips_if_neededcCs"|dd}|�d|dd�p dS)Nr�r�r�r�r5)r�)r�Z
original_pathrar�rprprqr��	sz&S3EndpointSetter._get_accesspoint_pathcCs|j�|�}|dkr|j}|Sr�)r}�get_partition_dns_suffix�_DEFAULT_DNS_SUFFIX)r�Zpartition_name�
dns_suffixrprprqr��	s�z*S3EndpointSetter._get_partition_dns_suffixcCs,|j�d|�}|j}|r(d|kr(|d}|S�Nr�Z	dnsSuffix�r}rgr��r�r�r�r�rprprqr��	s�z S3EndpointSetter._get_dns_suffixcCs$|j�di�}||d<||jd<dS�Nr?r��r�r~�r�r�r�rErprprqr��	sz)S3EndpointSetter._override_signing_regioncCs |�di�}||d<||d<dS�Nr?rBr�)r�r�rBrErprprqr��	sz'S3EndpointSetter._override_signing_namecCs�|j�d�rdS|jdkrdSt|j�j}|�d�s8dS|�d�}|ddkrRdS|dd	�}t|�tt|��krvdSt	d
d�|D��S)N�use_accelerate_endpointTFr�r�r�
s3-accelerater5���css|]}|tkVqdSr�r�r�rprprq�	<genexpr>
sz<S3EndpointSetter._use_accelerate_endpoint.<locals>.<genexpr>)
r�r~r�rr�r�r�r��set�all)r�r�r��
feature_partsrprprqr��	s


z)S3EndpointSetter._use_accelerate_endpointcCs"|jr
dS|j�d�}|r|SdS)N�virtualZaddressing_style)r�r�r~)r�Zconfigured_addressing_stylerprprq�_addressing_style

s
z"S3EndpointSetter._addressing_stylecCsH|jdkrt�d�tS|jdks,|jdk	r:t�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�rprprqr�
s


�z'S3EndpointSetter._s3_addressing_handler)NNNNF)r�r�r�r�r�r�r7r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rprprprqr��sF�
%
 				
"
r�c@s�eZdZdZdZe�d�Zd6dd�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�r�z^[a-zA-Z0-9\-]{1,63}$NFcCsF||_||_||_||_|dkr&i|_||_||_|dkrB|j|_dSr�r�r�rprprqr�4
s	z S3ControlEndpointSetter.__init__cCs|�d|j�dS)Nzbefore-sign.s3-control)r7r�r�rprprqr7H
sz S3ControlEndpointSetter.registercKs||�|�r@|�|�|�|�}|�|�|�||�|�|�n8|�|�rx|�|�|�|d�|�	|j
�}|�||�dS�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�r�r��
new_netlocrprprqr�K
s





z$S3ControlEndpointSetter.set_endpointcCs
d|jkS)Nr�r�r�rprprqr�X
sz6S3ControlEndpointSetter._use_endpoint_from_arn_detailscCs
d|jkS)N�
outpost_idr�r�rprprqr�[
sz5S3ControlEndpointSetter._use_endpoint_from_outpost_idcCs�d|jddkr(t|jdddd��|j�dd�sl|jdd}||jkrld	|�d
|j�d�}t|d��|jdd
}||jkr�td|j�d|�d�d��|j�d�r�tdd��d|jdkr�|�|�dS)Nr�r�r�rNr��r�r�r�FzCThe use_arn_region configuration is disabled but received arn for "z(" when the client is configured to use "rwr�r�r�z&" partition, but arn provided is for "z;" partition. The client and arn partition must be the same.r��7S3 control client does not support accelerate endpointsr�)r�r3r�r~r�r4r�r�)r�r��
arn_regionrZrequest_partionrprprqr�^
s,�
�

��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~r4r�rprprqr�}
s�z;S3ControlEndpointSetter._validate_outpost_redirection_validcCs2|j�dd�r,|jdd}|�||�|S|jS)Nr�Fr�r�)r�r~r�r�r�)r�r�rrprprqr��
s
z8S3ControlEndpointSetter._resolve_region_from_arn_detailscCs|jdd}|�||�|S)Nr�r�r�)r�r�Zarn_servicerprprqr��
sz>S3ControlEndpointSetter._resolve_signing_name_from_arn_detailscCs|�||�}|�||�dSr�)� _resolve_netloc_from_arn_detailsr)r�r�r�rrprprqr��
s
�z:S3ControlEndpointSetter._resolve_endpoint_from_arn_detailscCsDt|j�}t|j||j|jdf�}t�d|j�d|���||_dSr)rr�rr�r�r�r�r�)r�r�rr�Zarn_details_endpointrprprqr�
s
��	�z.S3ControlEndpointSetter._update_request_netloccCs0|jd}d|kr|�|�S|d}|�||�S)Nr�r�r�)r�r�_construct_s3_control_endpoint)r�r�r�r�r�rprprqr�
s


z8S3ControlEndpointSetter._resolve_netloc_from_arn_detailscCs|j�|�Sr�)�_HOST_LABEL_REGEXr�)r��labelrprprq�_is_valid_host_label�
sz,S3ControlEndpointSetter._is_valid_host_labelcGs"|D]}|�|�st|d��qdS)N)r
)rr')r��labelsr
rprprq�_validate_host_labels�
s
z-S3ControlEndpointSetter._validate_host_labelscCs\|�||�|jr(t|j�j}||g}n*|dg}|�|�|�|�}|�||g�|�|�S)N�
s3-control)r
r�rr��_add_dualstackr�rM�_construct_netloc)r�r�r�r�r�r�rprprqr�
s
�

z6S3ControlEndpointSetter._construct_s3_control_endpointcCs@|�|�|jrt|j�jSd||�|�g}|�|�|�|�Sr�)r
r�rr�r��	_add_fipsr)r�r�r�rprprqr�
s
�
z3S3ControlEndpointSetter._construct_outpost_endpointcCs
d�|�S)Nr�)r��r�r�rprprqr�
sz)S3ControlEndpointSetter._construct_netloccCs|jr|dd|d<dS)Nrr�r�rrprprqr�
sz!S3ControlEndpointSetter._add_fipscCs|j�d�r|�d�dS)Nr�r8)r�r~r�rrprprqr�
sz&S3ControlEndpointSetter._add_dualstackcCs,|j�d|�}|j}|r(d|kr(|d}|Sr�r�r�rprprqr��
s�z'S3ControlEndpointSetter._get_dns_suffixcCs$|j�di�}||d<||jd<dSr�r�r�rprprqr��
sz0S3ControlEndpointSetter._override_signing_regioncCs$|j�di�}||d<||jd<dSr�r�)r�r�rBrErprprqr��
sz.S3ControlEndpointSetter._override_signing_namecCs(|jd}|�d�}|r$|�||�dS)Nr�r�)r�r~�_add_outpost_id_header)r�r�r�r�rprprqr��
s

z5S3ControlEndpointSetter._add_headers_from_arn_detailscCs||jd<dS)Nzx-amz-outpost-id)r�)r�r�r�rprprqrsz.S3ControlEndpointSetter._add_outpost_id_header)NNNNF) r�r�r�r�r�r�r�r	r�r7r�r�r�r�r�r�r�r�rrrr
rrrrrr�r�r�r�rrprprprqr�/
s@
�

		
			r�c@s�eZdZdZe�d�Zddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�S3ControlArnParamHandlerz�This handler has been replaced by S3ControlArnParamHandlerv2. The
    original version remains in place for any third-party importers.
    z[/:]NcCs(||_|dkrt�|_tjdtd�dS)Nz�The S3ControlArnParamHandler class has been deprecated for a new internal replacement. A future version of botocore may remove this class.r{)r�rcr~rr�r�rprprqr�s�z!S3ControlArnParamHandler.__init__cCs|�d|j�dS)Nz!before-parameter-build.s3-controlr�r�rprprqr7s�z!S3ControlArnParamHandler.registercKs:|jdkr|�|||�n|�|||�|�|||�dS)N)r�ZListRegionalBuckets)r��_handle_outpost_id_param�_handle_name_param�_handle_bucket_param)r�rAr�r�r�rprprqr�s
z#S3ControlArnParamHandler.handle_arncCsX||krdSz0||}|j�|�}||d<|�|�|d<|WStk
rRYdSXdS)NrN�	resources)r�r��_split_resourcer�)r�rAr�r�r�rprprq�_get_arn_details_from_param'sz4S3ControlArnParamHandler._get_arn_details_from_paramcCs|j�|d�S)Nr�)�_RESOURCE_SPLIT_REGEXr�)r�r�rprprqr3sz(S3ControlArnParamHandler._split_resourcecCsF|d}d|kr:|d|kr:d�|d�}t|d|d��||d<dS)Nr�Z	AccountIdzGAccount ID in arn does not match the AccountId parameter provided: "{}"rNr)r�r3)r�rAr�Z
account_idrrprprq�_override_account_id_param6s���z3S3ControlArnParamHandler._override_account_id_paramcCsd|krdS|d|d<dS)NZ	OutpostIdrrp)r�rAr�r�rprprqrCsz1S3ControlArnParamHandler._handle_outpost_id_paramcCsX|jdkrdS|�|d�}|dkr&dS|�|�r@|�|||�nd}t|d|d��dS�NZCreateAccessPoint�Namez4The Name parameter does not support the provided ARNrNr)r�r�_is_outpost_accesspoint�_store_outpost_accesspointr3�r�rAr�r�r�rrprprqrHs

�z+S3ControlArnParamHandler._handle_name_paramcCs@|ddkrdS|d}t|�dkr(dS|ddko>|dd	kS)
Nr�r�Frr�rr�r�r��r��r�r�rrprprqrXsz0S3ControlArnParamHandler._is_outpost_accesspointcCsD|�||�|dd}||d<||d<|dd|d<||d<dS)Nrr�rr�r5r�r��r)r�rAr�r�r�rprprqr asz3S3ControlArnParamHandler._store_outpost_accesspointcCsJ|�|d�}|dkrdS|�|�r2|�|||�nd}t|d|d��dS�Nr$z6The Bucket parameter does not support the provided ARNrNr)r�_is_outpost_bucket�_store_outpost_bucketr3r!rprprqris
��z-S3ControlArnParamHandler._handle_bucket_paramcCs@|ddkrdS|d}t|�dkr(dS|ddko>|dd	kS)
Nr�r�Frr�rr�r�rr"r#rprprqr&xsz+S3ControlArnParamHandler._is_outpost_bucketcCsD|�||�|dd}||d<||d<|dd|d<||d<dS)Nrr�r$r�r5r�r�r$)r�rAr�r�r�rprprqr'�sz.S3ControlArnParamHandler._store_outpost_bucket)N)r�r�r�r�r�r�rr�r7r�rrrrrrr rr&r'rprprprqrs



		rc@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�S3ControlArnParamHandlerv2aUpdated version of S3ControlArnParamHandler for use when
    EndpointRulesetResolver is in use for endpoint resolution.

    This class is considered private and subject to abrupt breaking changes or
    removal without prior announcement. Please do not use it directly.
    NcCs||_|dkrt�|_dSr�r�r�rprprqr��sz#S3ControlArnParamHandlerv2.__init__cCs|�d|j�dS)Nz%before-endpoint-resolution.s3-controlr�r�rprprqr7�s�z#S3ControlArnParamHandlerv2.registercCsl|jdkrdS|�|d�}|dkr&dS|�|�|�|�|�|�rT|�|||�nd}t|d|d��dSr)r�r�_raise_for_fips_pseudo_region�_raise_for_accelerate_endpointrr r3r!rprprqr�s



�z-S3ControlArnParamHandlerv2._handle_name_paramcCs|�||�dSr�r$r�rprprqr �sz5S3ControlArnParamHandlerv2._store_outpost_accesspointcCs^|�|d�}|dkrdS|�|�|�|�|�|�rF|�|||�nd}t|d|d��dSr%)rr)r*r&r'r3r!rprprqr�s


��z/S3ControlArnParamHandlerv2._handle_bucket_paramcCs|�||�dSr�r$r�rprprqr'�sz0S3ControlArnParamHandlerv2._store_outpost_bucketcCs0|d}|�d�s|�d�r,t|ddd��dS)Nr�zfips-rNr�r)rDr�r3)r�r�rrprprqr)�s�z8S3ControlArnParamHandlerv2._raise_for_fips_pseudo_regioncCs&|djpi}|�d�r"tdd��dS)N�
client_configr�rr�)r�r~r4)r�r�r�rprprqr*�s

�z9S3ControlArnParamHandlerv2._raise_for_accelerate_endpoint)N)r�r�r�r�r�r7rr rr'r)r*rprprprqr(�s
	r(c@s|eZdZdZdZdZdZedddgZdej	fd	d
�Z
ddd�Zd
d�Zdd�Z
dd�Zdd�Zddd�Zdd�Zdd�ZdS)�ContainerMetadataFetcherr�r�r5z
169.254.170.2z169.254.170.23zfd00:ec2::23�	localhostNcCs(|dkrtjj|jd�}||_||_dS)N)r�)r�r�r��TIMEOUT_SECONDSr��_sleep)r�rw�sleeprprprqr��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�rprprq�retrieve_full_uri�s	
z*ContainerMetadataFetcher.retrieve_full_uricCsNtj�|�}|�|j�rdS|�|j�}|sJtd|j�dd�|j�����dS)NzUnsupported host 'zN'.  Can only retrieve metadata from a loopback address or one of these hosts: z, )	r��compatr�_is_loopback_addressr��_check_if_whitelisted_hostr.r��_ALLOWED_HOSTS)r�r3�parsedZis_whitelisted_hostrprprqr1�s�z.ContainerMetadataFetcher._validate_allowed_urlcCs,zt|�}|jWStk
r&YdSXdS)NF)r�is_loopbackr.)r�r��iprprprqr6s
z-ContainerMetadataFetcher._is_loopback_addresscCs||jkrdSdS)NTF)r8)r�r�rprprqr7	s
z3ContainerMetadataFetcher._check_if_whitelisted_hostcCs|�|�}|�|�S)z�Retrieve JSON metadata from container metadata.

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

        :return: The parsed JSON response.

        )r3r2)r��relative_urir3rprprq�retrieve_uris	
z%ContainerMetadataFetcher.retrieve_uric
Cs�ddi}|dk	r|�|�d}z|�|||j�WStk
r�}z4tjd|dd�|�|j�|d7}||jkrr�W5d}~XYqXqdS)N�Acceptzapplication/jsonrzAReceived error when attempting to retrieve container metadata: %sTr�r5)	r��
_get_responser.r+r�r�r/�
SLEEP_TIME�RETRY_ATTEMPTS)r�r3�
extra_headersr�Zattemptsrrprprqr2s(
��
z.ContainerMetadataFetcher._retrieve_credentialsc

Cs�z�tjj}|d||d�}|j�|���}|j�d�}|jdkrVt	d|j�d|��d��zt
�|�WWStk
r�d}t
�d	||�t	|d��YnXWn6tk
r�}	zd
|	��}t	|d��W5d}	~	XYnXdS)Nrr�rer�zReceived non 200 response z from container metadata: r
z>Unable to parse JSON returned from container metadata servicesz%s:%sz?Received error when attempting to retrieve container metadata: )r�r�r�r�r�r�rr�r�r+rr,r.r�r�r�)
r�r3r�r�r�r�r�Z
response_textrrrprprqr?0s&
��z&ContainerMetadataFetcher._get_responsecCsd|j�|��S)Nzhttp://)�
IP_ADDRESS)r�r<rprprqr3Jsz!ContainerMetadataFetcher.full_url)N)N)r�r�r�r.rAr@rCr8�timer0r�r4r1r6r7r=r2r?r3rprprprqr,�s$�

r,cCst|�riSt�SdSr�)�should_bypass_proxiesr�r�rprprqr�Nsr�c	Cs8ztt|�j�rWdSWnttjfk
r2YnXdS)z:
    Returns whether we should bypass proxies or not.
    TF)rrr�rr�socket�gaierrorrFrprprqrEUs
rEc	Cs�|sdSz
t|�WSttfk
r*YnXt|d�r�t|d�r�z0|��}|�dd�|��}|�|�||WStjk
r�YnXdS)Nr�seek�tellr�)r��AttributeErrorrrr}rJrI�io�UnsupportedOperation)r�Zorig_posZend_file_posrprprq�determine_content_lengthjs 


rN�
ISO-8859-1cCsJ|�d�}|sdStj��}||d<|�d�}|dk	r:|Sd|krF|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�charsetr�)r~rO�messager�	get_param)r��default�content_typerQrPrprprq�get_encoding_from_headers�s


rUcKs0t|ttf�rt|�}nt|�}t�|��d�S)�KThis function has been deprecated, but is kept for backwards compatibility.r�)rjrf�	bytearray�_calculate_md5_from_bytes�_calculate_md5_from_file�base64�	b64encoder�)r�r�Z
binary_md5rprprq�
calculate_md5�s
r\cCst|�}|��S)rV)rr�)Z
body_bytes�md5rprprqrX�srXcsB���}t�}t�fdd�d�D]}|�|�q ��|�|��S)rVcs
��d�Sr�r�rp��fileobjrprqr��r�z*_calculate_md5_from_file.<locals>.<lambda>r�)rJrr�r�rIr�)r_Zstart_positionr]r�rpr^rqrY�s
rYcCs"|�di��di�}|�d�dkS)Nr�r<r=r>r�)rAr<rprprq�_is_s3express_request�s
�r`cCs&|d}|D]}t�|�rdSqdS)z�
    Checks if a header starting with "x-amz-checksum-" is provided in a request.

    This function is considered private and subject to abrupt breaking changes or
    removal without prior announcement. Please do not use it directly.
    r�TF)�CHECKSUM_HEADER_PATTERNr�)rAr�r{rprprq�has_checksum_header�s

rbcKs$t|�s t|f|�t|f|�dS)rVN)rb�conditionally_calculate_md5�conditionally_enable_crc32)rAr�rprprq� conditionally_calculate_checksum�srecKsV|�di��di�}|�d�}t|�rR|ddk	rR|dkrRdddd	d
�i|dd<dS)rVr�r��request_algorithmr�N)N�conditional-md5�crc32r{zx-amz-checksum-crc32)�	algorithm�inr�)r~r`)rAr��checksum_context�checksum_algorithmrprprqrd�s
�
����rdcKsv|d}|�di��di�}|�d�}|r6|dkr6dSt|�rBdSt|�rNdStrr|dk	rrt|f|�}||dd<dS)	z�Only add a Content-MD5 if the system supports it.

    This function has been deprecated, but is kept for backwards compatibility.
    r�r�r�rfrgNr�zContent-MD5)r~rbr`rr\)rAr�r�rkrlZ
md5_digestrprprqrc�s
rcc@s eZdZefdd�Zdd�ZdS)�FileWebIdentityTokenLoadercCs||_||_dSr�)�_web_identity_token_pathrT)r�Zweb_identity_token_pathrTrprprqr�
sz#FileWebIdentityTokenLoader.__init__c
Cs,|�|j��}|��W5QR�SQRXdSr�)rTrnrP)r�Z
token_filerprprq�__call__
sz#FileWebIdentityTokenLoader.__call__N)r�r�r��openr�rorprprprqrm
srmc@s2eZdZd
dd�Zdd�Zddd�Zddd	�ZdS)
�SSOTokenLoaderNcCs|dkri}||_dSr�)r2)r�r3rprprqr�

szSSOTokenLoader.__init__cCs$|}|dk	r|}t�|�d����S)Nre)r��sha1rgr�)r��	start_url�session_namerhrprprq�_generate_cache_key
sz"SSOTokenLoader._generate_cache_keycCs|�||�}||j|<dSr�)rur2)r�rsrrtr�rprprq�
save_token
szSSOTokenLoader.save_tokencCs�|�||�}t�d|���||jkrL|}|dk	r6|}d|�d�}t|d��|j|}d|ksfd|kr|d|�d�}t|d��|S)NzChecking for cached token at: z
Token for z does not existr
ZaccessTokenZ	expiresAtz is invalid)rur�r�r2r.)r�rsrtr�r�rrrprprqro
s



zSSOTokenLoader.__call__)N)N)N)r�r�r�r�rurvrorprprprqrq
s

rqc@s@eZdZdZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Z	dS)�EventbridgeSignerSetterr�r�NcCs||_||_||_dSr�)r}r�r�)r�r�r�r�rprprqr�1
sz EventbridgeSignerSetter.__init__cCs |�d|j�|�d|j�dS)Nz'before-parameter-build.events.PutEventszbefore-call.events.PutEvents)r7�check_for_global_endpoint�set_endpoint_urlr�rprprqr76
s��z EventbridgeSignerSetter.registercKs6d|kr2|d}t�d|d�d|���||d<dS)N�eventbridge_endpointzRewriting URL from r�r)r�r�r�rprprqry?
sz(EventbridgeSignerSetter.set_endpoint_urlc	Ks�|�d�}|dkrdSt|�dkr,tdd��ts:tdd��|�d�}d}|dk	rl|jr`tdd��|jrldg}|jdkr�td	|���}|j	|kr�td
d��|j
||d�}n|j}||d<d
|d<dS)NZ
EndpointIdrz+EndpointId must not be a zero length stringr�zqUsing EndpointId requires an additional dependency. You will need to pip install botocore[crt] before proceeding.r+z>FIPS is not supported with EventBridge multi-region endpoints.r8�https://z-EndpointId is not a valid hostname component.��endpoint_variant_tagsrzZv4arb)r~r�r%rr,r�r�r�rr��_get_global_endpoint)	r�rAr�r�r�rBr}r�Zresolved_endpointrprprqrxE
sB
��
�

��z1EventbridgeSignerSetter.check_for_global_endpointcCsN|j}|�|j�}|dkr |j}|j||d�}|dkr<|j}d|�d|�d�S)Nr|r{z.endpoint.events.r�)r}Zget_partition_for_regionr�r�r�r�)r�r�r}r�r�r�rprprqr~q
s�z,EventbridgeSignerSetter._get_global_endpoint)NN)N)
r�r�r�r�r�r�r7ryrxr~rprprprqrw-
s
	,rwcCs�|dkrdSt|�}|j�d�r*|jdkr.dS|j�d�}|ddkrJdS|dd	�}t|�tt|��krndStd
d�|D��S)z�Does the URL match the S3 Accelerate endpoint scheme?

    Virtual host naming style with bucket names in the netloc part of the URL
    are not allowed by this function.
    NFr�)�https�httpr�rr�r5r�css|]}|tkVqdSr�r�r�rprprqr��
sz'is_s3_accelerate_url.<locals>.<genexpr>)rr�r�r�r�r�r�r�)r�Z	url_partsr�r�rprprq�is_s3_accelerate_url�
s ��r�c@sreZdZdZej�ej�dddd��Zedfdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zddd�ZdS)�
JSONFileCachez�JSON file cache.
    This provides a dict like interface that stores JSON serializable
    objects.
    The objects are serialized to JSON and stored in a file.  These
    values can be retrieved at a later time.
    �~z.awsZbotor3NcCs||_|dkr|j}||_dSr�)�_working_dir�_default_dumps�_dumps)r�Zworking_dirZ
dumps_funcrprprqr��
szJSONFileCache.__init__cCstj||jd�S)N)rS)r�dumpsr')r�r�rprprqr��
szJSONFileCache._default_dumpscCs|�|�}tj�|�Sr�)�_convert_cache_keyr�r��isfile)r�r��
actual_keyrprprq�__contains__�
s
zJSONFileCache.__contains__c
Cs\|�|�}z,t|��}t�|�W5QR�WSQRXWn ttfk
rVt|��YnXdS)z Retrieve value from a cache key.N)r�rpr�loadrRr.�KeyError)r�r�r�rUrprprq�__getitem__�
s

"zJSONFileCache.__getitem__cCs@|�|�}zt|�}|��Wntk
r:t|��YnXdSr�)r�r�unlink�FileNotFoundErrorr�)r�r�r�Zkey_pathrprprq�__delitem__�
s
zJSONFileCache.__delitem__c	Cs�|�|�}z|�|�}Wn&ttfk
r>td|����YnXtj�|j�sZt�|j�t�	t�
|tjtjBd�d��}|�
�|�|�W5QRXdS)Nz3Value cannot be cached, must be JSON serializable: i��w)r�r�rrr.r�r��isdirr��makedirs�fdopenrp�O_WRONLY�O_CREAT�truncate�write)r�r�r�Zfull_keyZfile_contentrUrprprq�__setitem__�
s 
�
�zJSONFileCache.__setitem__cCstj�|j|d�}|S)Nz.json)r�r�r�r�)r�r��	full_pathrprprqr��
sz JSONFileCache._convert_cache_keyFcCs$t|t�r |r|��S|�d�S|Sr+r,r.rprprqr'�
s


z"JSONFileCache._serialize_if_needed)F)r�r�r�r�r�r��
expanduserr�Z	CACHE_DIRr�r�r�r�r�r�r�r'rprprprqr��
s	r�cCs|dkrdS|�d�S)NFz--x-s3)r�rrprprq�is_s3express_bucket�
sr�razapp-meshzdirectory-service-datazglobal-acceleratorziot-events-dataz
iot-eventsziot-wirelesszkinesis-analytics-v2z
lex-models-v2zlex-runtime-v2zpinpoint-sms-voicerzservice-catalog-appregistry)8r:r;Zappmeshr<r=r>r?r@rArBrCrDrFrErGrHrIzds-datarJrKrLrMrNrPrQZglobalacceleratorrRrSziotevents-dataZ	ioteventsZiotwirelessrTZkinesisanalyticsv2rUrVzlexv2-modelsrWz
lexv2-runtimerXrYr[rZr\r]z	sms-voicer^r_r`Z	s3controlrbrcrdrezservicecatalog-appregistryrfrg)T)F)N)F)N)N)T)T)rO)�rZr�r�
email.messagerOr�r�rL�loggingr�r7r�rGrDr~r�r{�	ipaddressr�pathlibr�urllib.requestrrZdateutil.parserrsZdateutil.tzrZurllib3.exceptionsrr�Zbotocore.awsrequestZbotocore.httpsessionZbotocore.compatr	r
rrr
rrrrrrrrrrrrrrrrZbotocore.exceptionsrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4�	getLoggerr�r�rr�r�rvZ
SAFE_CHARSr�r�r�r�Z
EVENT_ALIASESr�rarrrxr�r�r�r�r�r�r�r�r��	Exceptionr�r�r�rr?rHrKrOrprWrQrdr_rmrvrzr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�rrrrrr0rFrzr.r�rcr�r�r�rr(r,r�rErNrUr\rXrYr`rbrerdrcrmrqrwr�r�r�ZSERVICE_NAME_ALIASESZ.CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDESrprprprq�<module>
s@d

��H�

	DB&	&0-!d
�
�
@!")0I3UWMw	

!S!E
�