B ç0œ`UãJ@s ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl ZddlmZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e 1e2¡Z3dZ4dZ5dZ6e 7d ¡Z8e*e)e+e,fZ9d gZ:d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d'd*d+d,d-d.d.dddd/d0d1d2d3d4d5d,d6d7d7d8d2d9d:d;d/dd3d?d@dAdBdCdDdDdEd$ddMdN„Z?dOdP„Z@dQdR„ZAd¶dTdU„ZBGdVdW„dWeCƒZDGdXdY„dYeCƒZEGdZd[„d[eFƒZGGd\d]„d]eGƒZHd·d_d`„ZIdadb„ZJeKfdcdd„ZLdedf„ZMe6fdgdh„ZNe6fdidj„ZOdkdl„ZPdmdn„ZQdodp„ZRd¸dqdr„ZSd¹dsdt„ZTdudv„ZUdwdx„ZVGdydz„dzeFƒZWGd{d|„d|eFƒZXd}d~„ZYdd€„ZZdd‚„Z[dºdƒd„„Z\d»d…d†„Z]d‡dˆ„Z^d‰dŠ„Z_d‹dŒ„Z`ddŽ„Zad¼dd„Zbd½d‘d’„Zcd“d”„Zdd•d–„ZeGd—d˜„d˜eFƒZfGd™dš„dšegƒZhGd›dœ„dœeFƒZiGddž„džeFƒZjGdŸd „d eFƒZkGd¡d¢„d¢eFƒZld£d¤„Zmd¥d¦„Znd¾d¨d©„Zodªd«„Zpd¬d­„Zqd®d¯„Zrd°d±„ZsGd²d³„d³eFƒZtGd´dµ„dµeFƒZudS)¿éN)Útzutc) ÚjsonÚquoteÚ zip_longestÚurlsplitÚ urlunsplitÚ OrderedDictÚsixÚurlparseÚget_tzinfo_optionsÚget_md5Ú MD5_AVAILABLE)Ú getproxiesÚ proxy_bypass) ÚInvalidExpressionErrorÚConfigNotFoundÚInvalidDNSNameErrorÚ ClientErrorÚMetadataRetrievalErrorÚEndpointConnectionErrorÚReadTimeoutErrorÚConnectionClosedErrorÚConnectTimeoutErrorÚUnsupportedS3ArnErrorÚ*UnsupportedS3AccesspointConfigurationErrorÚSSOTokenLoadErrorÚInvalidRegionErrorézhttp://169.254.169.254/z-._~z-z0-9][a-z0-9\-]*[a-z0-9]Ú dualstackzalexa-for-businessZ mediatailorZpricingZ sagemakerz api-gatewayzapplication-auto-scalingZ appstreamz auto-scalingzauto-scaling-plansz cost-explorerz cloudhsm-v2zcloudsearch-domainzcognito-identity-providerzconfig-servicezcost-and-usage-report-serviceziot-data-planeziot-jobs-data-planezmediastore-dataz data-pipelinez device-farmziot-1click-devices-servicezdirect-connectzapplication-discovery-servicezdatabase-migration-servicezdirectory-servicezdynamodb-streamszelastic-beanstalkZefszelastic-load-balancingZemrzelastic-transcoderzelastic-load-balancing-v2Zseszmarketplace-entitlement-servicezelasticsearch-serviceZ eventbridgeziot-1click-projectszkinesis-analyticsz kinesis-videozlex-model-building-servicezlex-runtime-servicezcloudwatch-logszmachine-learningzmarketplace-commerce-analyticszmarketplace-meteringz migration-hubZ cloudwatchZmturkZ opsworkscmzresource-groups-tagging-apizroute-53zroute-53-domainszsagemaker-runtimeZsimpledbzsecrets-managerZserverlessapplicationrepositoryzservice-catalogÚsfnzstorage-gateway)IZa4bZalexaforbusinesszapi.mediatailorz api.pricingz api.sagemakerZ apigatewayzapplication-autoscalingZ appstream2Z autoscalingzautoscaling-plansZceZ cloudhsmv2Zcloudsearchdomainz cognito-idpÚconfigÚcurzdata.iotz data.jobs.iotzdata.mediastoreZ datapipelineZ devicefarmzdevices.iot1clickZ directconnectZ discoveryZdmsZdsZdynamodbstreamsZelasticbeanstalkZelasticfilesystemZelasticloadbalancingZelasticmapreduceZelastictranscoderZelbZelbv2Úemailzentitlement.marketplaceÚesÚeventszcloudwatch-eventsziot-dataz iot-jobs-dataziot1click-devicesziot1click-projectsZkinesisanalyticsZ kinesisvideoz lex-modelsz lex-runtimeZlogsZmachinelearningzmarketplace-entitlementZmarketplacecommerceanalyticszmetering.marketplaceZmeteringmarketplaceZmghz models.lexZ monitoringzmturk-requesterz opsworks-cmzprojects.iot1clickZresourcegroupstaggingapiZroute53Zroute53domainsz runtime.lexzruntime.sagemakerZsdbZsecretsmanagerZserverlessrepoZservicecatalogZstatesZ stepfunctionsZstoragegatewayzstreams.dynamodbZtaggingcCst|tƒr|S| ¡dkSdS)z~Ensures a boolean value if a string or boolean is provided For strings, the value for True/False is case insensitive ÚtrueN)Ú isinstanceÚboolÚlower)Úval©r*úi/private/var/folders/sf/wxz_36012wxg_prv29r6623x5vlqx8/T/pip-target-tft40_m7/lib/python/botocore/utils.pyÚensure_boolean‹s r,cCs2t|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)Úhasattrr-ÚgetÚ type_name)Úshaper*r*r+Úis_json_value_header–s r5cCsD|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+)Úmetadatar2Ú service_nameÚreplaceÚreÚsub)Z service_modelÚnamer*r*r+Úget_service_module_name¥s   r=cCs|sdSt|ƒS)Nú/)Úremove_dot_segments)Úpathr*r*r+Únormalize_url_path´srAcCs’|sdS| d¡}g}x8|D]0}|r|dkr|dkrB|rL| ¡q| |¡qW|ddkrbd}nd}|ddkr||r|d}nd}|d |¡|S)Nr6r>Ú.z..réÿÿÿÿ)ÚsplitÚpopÚappendÚjoin)ÚurlZ input_urlZ output_listÚxÚfirstÚlastr*r*r+r?ºs"     r?cCs:|r |dkrt|d‚xdD]}||krt|d‚qWdS)NrB)Ú expression)ú[ú]Ú*)r)rLÚinvalidr*r*r+Úvalidate_jmespath_for_setÕs    rQTcCs||r t|ƒ| dd¡}|dt|ƒdkr2|dnd}}|sHt|d‚|rp||kr\i||<t||||ddS|||<dS)NrBrrr6)rLF)Úis_first)rQrDÚlenrÚset_value_from_jmespath)ÚsourcerLÚvaluerRÚbitsÚ current_keyÚ remainderr*r*r+rTàs " rTc@seZdZdZdS)Ú_RetriesExceededErrorz@Internal exception used when the number of retries are exceeded.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r*r*r*r+rZsrZc@seZdZdd„ZdS)ÚBadIMDSRequestErrorcCs ||_dS)N)Úrequest)Úselfr`r*r*r+Ú__init__szBadIMDSRequestError.__init__N)r[r\r]rbr*r*r*r+r_sr_c@speZdZeZdZdZededdfdd„Z dd„Z dd d „Z d d „Z d d„Z dd„Zdd„Zdd„Zddd„ZdS)Ú IMDSFetcherzlatest/api/tokenZ21600rNcCsf||_||_||_|dkr$tj ¡}| dd¡ ¡|_|jdk|_||_ t j j |jt |jƒd|_dS)NZAWS_EC2_METADATA_DISABLEDÚfalser%)ÚtimeoutÚproxies)Ú_timeoutÚ _num_attemptsÚ _base_urlÚosÚenvironÚcopyr2r(Ú _disabledÚ _user_agentÚbotocoreÚ httpsessionÚURLLib3SessionÚget_environ_proxiesÚ_session)rareZ num_attemptsÚbase_urlÚenvÚ user_agentr*r*r+rbs  zIMDSFetcher.__init__c CsÞ| ¡|j|j}d|ji}| |¡tjjd||d}xžt|j ƒD]}yD|j   |  ¡¡}|j dkrl|jS|j dkrzdS|j dkrŒt|ƒ‚WqFtk r¢dStk rÔ}ztjd||dd Wdd}~XYqFXqFWdS) Nz$x-aws-ec2-metadata-token-ttl-secondsÚPUT)ÚmethodrHÚheaderséÈ)i”i“i•)izOCaught retryable HTTP exception while making metadata service request to %s: %sT)Úexc_info)Ú_assert_enabledriÚ _TOKEN_PATHÚ _TOKEN_TTLÚ_add_user_agentroÚ awsrequestÚ AWSRequestÚrangerhrsÚsendÚprepareÚ status_codeÚtextr_rÚRETRYABLE_HTTP_ERRORSÚloggerÚdebug)rarHryr`ÚiÚresponseÚer*r*r+Ú_fetch_metadata_token!s,        "z!IMDSFetcher._fetch_metadata_tokenc CsÆ| ¡|dkr|j}|j|}i}|dk r4||d<| |¡xzt|jƒD]l}y2tjjd||d}|j   |  ¡¡}||ƒs~|SWqJt k r´} zt jd|| ddWdd} ~ XYqJXqJW| ¡‚dS)aZMake a get request to the Instance Metadata Service. :type url_path: str :param url_path: The path component of the URL to make a get request. This arg is appended to the base_url that was provided in the initializer. :type retry_func: callable :param retry_func: A function that takes the response as an argument and determines if it needs to retry. By default empty and non 200 OK responses are retried. :type token: str :param token: Metadata token to send along with GET requests to IMDS. Nzx-aws-ec2-metadata-tokenÚGET)rxrHryzOCaught retryable HTTP exception while making metadata service request to %s: %sT)r{)r|Ú_default_retryrirr‚rhror€rrsrƒr„r‡rˆr‰Ú_RETRIES_EXCEEDED_ERROR_CLS) raÚurl_pathÚ retry_funcÚtokenrHryrŠr`r‹rŒr*r*r+Ú _get_request;s(   "zIMDSFetcher._get_requestcCs|jdk r|j|d<dS)Nz User-Agent)rn)raryr*r*r+r`s zIMDSFetcher._add_user_agentcCs|jrt d¡| ¡‚dS)Nz)Access to EC2 metadata has been disabled.)rmrˆr‰r)rar*r*r+r|ds zIMDSFetcher._assert_enabledcCs| |¡p| |¡S)N)Ú_is_non_ok_responseÚ _is_empty)rar‹r*r*r+ris zIMDSFetcher._default_retrycCs"|jdkr|j|ddddSdS)Nrzznon-200T)Úlog_bodyF)r…Ú_log_imds_response)rar‹r*r*r+r•os zIMDSFetcher._is_non_ok_responsecCs|js|j|ddddSdS)Nzno bodyT)r—F)Úcontentr˜)rar‹r*r*r+r–uszIMDSFetcher._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…rHrFr™rˆr‰)rar‹Z reason_to_logr—Z statementZ logger_argsr*r*r+r˜{s  zIMDSFetcher._log_imds_response)N)F)r[r\r]rZrr}r~Ú DEFAULT_METADATA_SERVICE_TIMEOUTÚMETADATA_BASE_URLrbrr”rr|rr•r–r˜r*r*r*r+rc s %rcc@sXeZdZdZddddgZdd„Zdd d „Zdd d „Zd d„Zdd„Z dd„Z dd„Z dS)ÚInstanceMetadataFetcherz*latest/meta-data/iam/security-credentials/Ú AccessKeyIdÚSecretAccessKeyÚTokenÚ Expirationc CsÄyl| ¡}| |¡}| ||¡}| |¡rJ||d|d|d|ddœSd|krfd|krft d|¡iSWnR|jk rt d |j¡Yn0tk r¾}zt d |j ¡Wdd}~XYnXiS) NrržrŸr )Ú role_nameZ access_keyZ secret_keyr“Z 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‰rrhr_r`)rar“r¡Ú credentialsrŒr*r*r+Úretrieve_iam_role_credentialss(      z5InstanceMetadataFetcher.retrieve_iam_role_credentialsNcCs|j|j|j|djS)N)r‘r’r“)r”Ú _URL_PATHÚ_needs_retry_for_role_namer†)rar“r*r*r+r¤±sz%InstanceMetadataFetcher._get_iam_rolecCs$|j|j||j|d}t |j¡S)N)r‘r’r“)r”r©Ú_needs_retry_for_credentialsrÚloadsr†)rar¡r“Úrr*r*r+r¥¸s z(InstanceMetadataFetcher._get_credentialscCs6yt |j¡dStk r0| |d¡dSXdS)NFz invalid jsonT)rr¬r†Ú ValueErrorr˜)rar‹r*r*r+Ú_is_invalid_jsonÀs   z(InstanceMetadataFetcher._is_invalid_jsoncCs| |¡p| |¡S)N)r•r–)rar‹r*r*r+rªÈs z2InstanceMetadataFetcher._needs_retry_for_role_namecCs| |¡p| |¡p| |¡S)N)r•r–r¯)rar‹r*r*r+r«Îs  z4InstanceMetadataFetcher._needs_retry_for_credentialscCs,x&|jD]}||krt d|¡dSqWdS)Nz3Retrieved credentials is missing required field: %sFT)Ú_REQUIRED_CREDENTIAL_FIELDSrˆr‰)rar§Úfieldr*r*r+r¦Õs z7InstanceMetadataFetcher._contains_all_credential_fields)N)N) r[r\r]r©r°r¨r¤r¥r¯rªr«r¦r*r*r*r+rœ‰s "  rœFcCs¨x¢|D]š}t||tƒrJ||kr<||krt|tjtjfƒst |¡}t|tjƒs2| d¡}t||dS)aÂUrlencodes a string. Whereas percent_encode_sequence handles taking a dict/sequence and producing a percent encoded string, this function deals only with taking a string (not a dict/sequence) and percent encoding it. If given the binary type, will simply URL encode it. If given the text type, will produce the binary type by UTF-8 encoding the text. If given something else, will convert it to the text type first. zutf-8)rÊ)r&r Ú binary_typeÚ text_typeÚencoder)Z input_strrÊr*r*r+rÈ@s    rÈc Csžt|ttfƒrtj ||ƒ¡Sytj t|ƒ|ƒ¡Sttfk rJYnXytjj |dt ƒidSttfk r˜}ztd||fƒ‚Wdd}~XYnXdS)z.Parse timestamp with pluggable tzinfo options.ÚGMT)ZtzinfoszInvalid timestamp "%s": %sN) r&ÚintÚfloatÚdatetimeÚ fromtimestampÚ TypeErrorr®ÚdateutilÚparserÚparser)rVÚtzinforŒr*r*r+Ú_parse_timestamp_with_tzinfoUsrÛc Cs`xNtƒD]D}y t||ƒStk rJ}ztjd|j|dWdd}~XYqXqWtd|ƒ‚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{Nz4Unable to calculate correct timezone offset for "%s")r rÛr»rˆr‰r[Ú RuntimeError)rVrÚrŒr*r*r+Úparse_timestamphs  "rÝcCsDt|tjƒr|}nt|ƒ}|jdkr4|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. N)rÚ)r&rÔrÝrÚr9rÚ astimezone)rVZ datetime_objr*r*r+Úparse_to_aware_datetime~s   rßcCs~t ddd¡}|jdkr2|dkr&tƒ}|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 i²rN)rÚÚ total_secondséii@B) rÔrÚrr9Ú utcoffsetr1ràÚ microsecondsÚsecondsÚdays)ÚdtZdefault_timezoneÚepochÚdr*r*r+Údatetime2timestamp«s    récsFt ¡}x$t‡fdd„dƒD]}| |¡qW|r:| ¡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)Ni)r¹r*)Úbodyr*r+ÚÓóz"calculate_sha256..rìN)ÚhashlibÚsha256ÚiterÚupdateÚ hexdigestÚdigest)rêZas_hexZchecksumÚchunkr*)rêr+Úcalculate_sha256Às rôcs¼g}d‰tj}x.t‡‡fdd„dƒD]}| ||ƒ ¡¡q$W|sN|dƒ ¡SxXt|ƒdkr¦g}x>t|ƒD]2\}}|dk r’| |||ƒ ¡¡qj| |¡qjW|}qPWt  |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 ics ˆ ˆ¡S)N)r¹r*)rêÚrequired_chunk_sizer*r+rëìrìz%calculate_tree_hash..rìrNrÚascii) rírîrïrFròrñrSÚ _in_pairsÚbinasciiÚhexlifyÚdecode)rêÚchunksrîróZ new_chunksrJÚsecondr*)rêrõr+Úcalculate_tree_hashÛs rýcCst|ƒ}t||ƒS)N)rïr)ÚiterableZ shared_iterr*r*r+r÷üs r÷c@s eZdZdZdd„Zdd„ZdS)ÚCachedPropertyzÒA read only property that caches the initially computed value. This descriptor will only call the provided ``fget`` function once. Subsequent access to this property will return the cached value. cCs ||_dS)N)Ú_fget)raÚfgetr*r*r+rbszCachedProperty.__init__cCs,|dkr |S| |¡}||j|jj<|SdS)N)rÚ__dict__r[)raÚobjÚclsZcomputed_valuer*r*r+Ú__get__s  zCachedProperty.__get__N)r[r\r]r^rbrr*r*r*r+rÿ srÿc@sDeZdZdZddd„Zdd„Zddd „Zd d „Zd d „Zdd„Z dS)ÚArgumentGeneratoraGenerate sample input based on a shape model. This class contains a ``generate_skeleton`` method that will take an input/output shape (created from ``botocore.model``) and generate a sample dictionary corresponding to the input/output shape. The specific values used are place holder values. For strings either an empty string or the member name can be used, for numbers 0 or 0.0 is used. The intended usage of this class is to generate the *shape* of the input structure. This can be useful for operations that have complex input shapes. This allows a user to just fill in the necessary data instead of worrying about the specific structure of the input arguments. Example usage:: s = botocore.session.get_session() ddb = s.get_service_model('dynamodb') arg_gen = ArgumentGenerator() sample_input = arg_gen.generate_skeleton( ddb.operation_model('CreateTable').input_shape) print("Sample input for dynamodb.CreateTable: %s" % sample_input) FcCs ||_dS)N)Ú_use_member_names)raZuse_member_namesr*r*r+rb;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)rar4Ústackr*r*r+Úgenerate_skeleton>s z#ArgumentGenerator.generate_skeletonr6cCsÔ| |j¡z¸|jdkr$| ||¡S|jdkr:| ||¡S|jdkrP| ||¡S|jdkrz|jrd|S|jrvt  |j¡SdS|jdkrˆdS|jdkr–d S|jd kr¤d S|jd krÂt   d ddddd¡SWd|  ¡XdS)NZ structurer´Úmapr0r6)ÚintegerÚlongrrÓgÚbooleanTÚ timestampi²r) rFr<r3Ú_generate_type_structureÚ_generate_type_listÚ_generate_type_maprÚenumÚrandomÚchoicerÔrE)rar4r r<r*r*r+rKs.             z$ArgumentGenerator._generate_skeletoncCsJ| |j¡dkriStƒ}x*|j ¡D]\}}|j|||d||<q&W|S)Nr)r<)Úcountr<rÚmembersrÆr)rar4r ZskeletonÚ member_nameZ member_shaper*r*r+resz*ArgumentGenerator._generate_type_structurecCs$d}|jr|jj}| |j||¡gS)Nr6)rÚmemberr<r)rar4r r<r*r*r+rnsz%ArgumentGenerator._generate_type_listcCs0|j}|j}|jdkst‚td| ||¡fgƒS)Nr0ZKeyName)r¶rVr3ÚAssertionErrorrr)rar4r Z key_shapeZ value_shaper*r*r+rxs z$ArgumentGenerator._generate_type_mapN)F)r6) r[r\r]r^rbr rrrrr*r*r*r+r!s    rcCsZt|ƒ}|j}|dkrdSt|ƒdkr*dS|ddkrB|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. NFéÿrCrBz;^((?!-)[A-Z\d-]{1,63}(?rz*Checking for DNS compatible bucket for: %sérCrBr6zURI updated to: %s)r*)Z auth_pathÚ_is_get_bucket_location_requestrˆr‰rrHr@rDÚnetlocrSr,ÚremoverGÚschemeÚqueryrr) r`r0r1r/r!Ú path_partsr*r@Zglobal_endpointÚhostZ new_tupleZnew_urir*r*r+r.Ðs<         r.cCs |j d¡S)Nz ?location)rHÚendswith)r`r*r*r+r4sr4cs"ˆ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|<|S)N)ÚtupleÚsortedrÆZ_instance_cacher2)raÚargsr/Ú cache_keyZ kwarg_itemsÚresult)ÚfuncÚ func_namer*r+Ú _cache_guard$s   z$instance_cache.._cache_guard)r[Ú functoolsÚwraps)rArCr*)rArBr+Úinstance_caches rFcKsht|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 endpointrBcSsg|]}|tkr|‘qSr*)ÚS3_ACCELERATE_WHITELIST)Ú.0Úpr*r*r+ú ;sz-switch_host_s3_accelerate..zhttps://s3-accelerate.rz amazonaws.com)Z ListBucketsÚ CreateBucketZ DeleteBucketNF)Úuse_new_scheme)rrHr5rDrSrGÚ _switch_hosts)r`Zoperation_namer/r!Úendpointr*r*r+Úswitch_host_s3_accelerate3s rOcCs2t |j d¡¡}| |¡r.||}t||ƒdS)zBSwitches the host using a parameter value from a JSON request bodyzutf-8N)rr¬Údatarúr2rM)r`Ú param_nameZ request_jsonÚ new_endpointr*r*r+Úswitch_host_with_paramFs rScCst|j||ƒ}||_dS)N)Ú_get_new_endpointrH)r`rRrLÚfinal_endpointr*r*r+rMNs rMcCsRt|ƒ}t|ƒ}|j}|r |j}||j|j|jdf}t|ƒ}t d||f¡|S)Nr6zUpdating URI from %s to %s)rr7r5r@r8rrˆr‰)Zoriginal_endpointrRrLZnew_endpoint_componentsZoriginal_endpoint_componentsr7Zfinal_endpoint_componentsrUr*r*r+rTTs rTcCsVxP|D]H}||krBt||tƒrBt||tƒrBt||||ƒq||||<qWdS)zõDeeply two dictionaries, overriding existing keys in the base. :param base: The base dictionary which will be merged into. :param extra: The dictionary to merge into the base. Keys from this dictionary will take precedence. N)r&r²Ú deep_merge)ÚbaseÚextrar¶r*r*r+rVgs  rVcCs| dd¡ ¡S)zcTranslate the form used for event emitters. :param service_id: The service_id to convert. ú ú-)r9r()Z service_idr*r*r+Úhyphenize_service_idysr[c@sHeZdZddd„Zddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dS)ÚS3RegionRedirectorNcCs,||_||_|jdkri|_t |¡|_dS)N)Ú_endpoint_resolverÚ_cacheÚweakrefÚproxyÚ_client)raZendpoint_bridgeÚclientÚcacher*r*r+rb‚s  zS3RegionRedirector.__init__cCs<|p |jjj}| d|j¡| d|j¡| d|j¡dS)Nzneeds-retry.s3zbefore-call.s3zbefore-parameter-build.s3)raÚmetar$ÚregisterÚredirect_from_errorÚset_request_urlÚredirect_from_cache)raÚ event_emitterZemitterr*r*r+reŒs zS3RegionRedirector.registercKs¨|dkr dS| | di¡¡r,t d¡dS| di¡ d¡rLt d¡dS|d di¡}| d¡}|d d i¡}|d ko†|jd k}|d ko¨|jd ko¨d | di¡k} |dko¸d|k} |ddk oÒ|djdk} |dk} t|| | | | gƒsòdS|ddd} |d d¡}| | |¡}|dkr.+)$rKNcCs||_|dkrtƒ|_dS)N)Ú _arn_parserr)raZ arn_parserr*r*r+rb>szS3ArnParamHandler.__init__cCs| d|j¡dS)Nzbefore-parameter-build.s3)reÚ handle_arn)rarir*r*r+reCszS3ArnParamHandler.registercKsD|j|jkrdS| |¡}|dkr&dS|ddkr@| |||¡dS)NÚ resource_typeÚ accesspoint)r<Ú_BLACKLISTED_OPERATIONSÚ"_get_arn_details_from_bucket_paramÚ_store_accesspoint)rar~Úmodelr-r/Ú arn_detailsr*r*r+rŽFs   zS3ArnParamHandler.handle_arncCsFd|krBy$|d}|j |¡}| ||¡|Stk r@YnXdS)Nr|)rr‹Ú_add_resource_type_and_namer€)rar~rŠr•r*r*r+r’Os  z4S3ArnParamHandler._get_arn_details_from_bucket_paramcCs:|j |d¡}|r,d|d<| d¡|d<n t|d‚dS)Nr‰rrÚ resource_name)rŠ)Ú_ACCESSPOINT_RESOURCE_REGEXrÚgroupr)rarŠr•rr*r*r+r–Zs z-S3ArnParamHandler._add_resource_type_and_namecCs2|d|d<|d|d|d|ddœ|d<dS)Nr—r|rˆr†rr)r<rˆr†rrrr*)rar~r-r•r*r*r+r“bs  z$S3ArnParamHandler._store_accesspoint)N) r[r\r]r:rr˜r‘rbrerŽr’r–r“r*r*r*r+rŒ6s   rŒc@s’eZdZdZdZd dd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zedd„ƒZedd„ƒZedd„ƒZdS)!ÚS3EndpointSetterZawsz amazonaws.comNcCs@||_||_||_|dkr i|_||_||_|dkr<|j|_dS)N)r]Ú_regionÚ _s3_configÚ _endpoint_urlÚ _partitionÚ_DEFAULT_PARTITION)raZendpoint_resolverrrZ s3_configr r†r*r*r+rbwszS3EndpointSetter.__init__cCs| d|j¡dS)Nzbefore-sign.s3)reÚ set_endpoint)rarir*r*r+reƒszS3EndpointSetter.registercKsd| |¡r.| |¡| |¡}| ||¡dS|jrFtfd|i|—Ž|jr`|jfd|i|—ŽdS)Nr`)Ú_use_accesspoint_endpointÚ_validate_accesspoint_supportedÚ(_resolve_region_for_accesspoint_endpointÚ_switch_to_accesspoint_endpointÚ_use_accelerate_endpointrOÚ_s3_addressing_handler)rar`r/r$r*r*r+r †s   zS3EndpointSetter.set_endpointcCs d|jkS)Nr)r-)rar`r*r*r+r¡’sz*S3EndpointSetter._use_accesspoint_endpointcCsP|jrtdd‚|jr tdd‚|jdd}||jkrLtd|j|fd‚dS)NzNClient cannot use a custom "endpoint_url" when specifying an access-point ARN.)Úmsgz[Client does not support s3 accelerate configuration when and access-point ARN is specified.rr†z–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.)rrr¥r-rž)rar`Zrequest_partionr*r*r+r¢•s z0S3EndpointSetter._validate_accesspoint_supportedcCs2|j dd¡r,|jdd}| ||¡|S|jS)NZuse_arn_regionTrrr)rœr2r-Ú_override_signing_regionr›)rar`Zaccesspoint_regionr*r*r+r£¯s  z9S3EndpointSetter._resolve_region_for_accesspoint_endpointcCsTt|jƒ}t|j| |j|¡| |j|j¡|jdfƒ}t   d|j|f¡||_dS)Nr6zUpdating URI from %s to %s) rrHrr7Ú_get_accesspoint_netlocr-Ú_get_accesspoint_pathr@r8rˆr‰)rar`r$Zoriginal_componentsZaccesspoint_endpointr*r*r+r¤¹s   z0S3EndpointSetter._switch_to_accesspoint_endpointcCsT|d}d|d|dfdg}|j d¡r6| d¡| || |¡g¡d |¡S) Nrz%s-%sr<rˆzs3-accesspointZuse_dualstack_endpointrrB)rœr2rFrµÚ_get_dns_suffixrG)raÚrequest_contextr$rZaccesspoint_netloc_componentsr*r*r+r©Çs  z(S3EndpointSetter._get_accesspoint_netloccCs"|dd}| d|dd¡p dS)Nrr<r>r6r)r9)raZ original_pathr¬r<r*r*r+rª×s z&S3EndpointSetter._get_accesspoint_pathcCs,|j d|¡}|j}|r(d|kr(|d}|S)NrqZ dnsSuffix)r]Zconstruct_endpointÚ_DEFAULT_DNS_SUFFIX)rar$ÚresolvedZ dns_suffixr*r*r+r«às  z S3EndpointSetter._get_dns_suffixcCsd|i}||jd<dS)Nrrrn)r-)rar`r$r{r*r*r+r¨èsz)S3EndpointSetter._override_signing_regioncCsˆ|j d¡rdS|jdkrdSt|jƒj}| d¡s8dS| d¡}|ddkrRdS|dd …}t|ƒtt|ƒƒkrvdSt d d „|DƒƒS) NZuse_accelerate_endpointTFz amazonaws.comrBrz s3-accelerateréþÿÿÿcss|]}|tkVqdS)N)rG)rHrIr*r*r+ú sz.) rœr2rrr5r;rDrSÚsetÚall)rar5r!Z feature_partsr*r*r+r¥ós       z)S3EndpointSetter._use_accelerate_endpointcCs"|jr dS|j d¡}|r|SdS)NÚvirtualZaddressing_style)r¥rœr2)raZconfigured_addressing_styler*r*r+Ú_addressing_styles  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.rr2)rar*r*r+r¦"s    z'S3EndpointSetter._s3_addressing_handler)NNNN)r[r\r]rŸr­rbrer r¡r¢r£r¤r©rªr«r¨rÿr¥r´r¦r*r*r*r+ršss"     # ršc@sreZdZdZdZdZdZeddgZdej fdd „Z dd d „Z d d „Z dd„Z dd„Zddd„Zdd„Zdd„ZdS)ÚContainerMetadataFetcherr3r&rz 169.254.170.2Ú localhostz 127.0.0.1NcCs(|dkrtjj|jd}||_||_dS)N)re)rorprqÚTIMEOUT_SECONDSrsÚ_sleep)raÚsessionÚsleepr*r*r+rbAs  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)raÚfull_urlryr*r*r+Úretrieve_full_uriIs z*ContainerMetadataFetcher.retrieve_full_uricCs:tj |¡}| |j¡}|s6td|jd |j¡fƒ‚dS)NzGUnsupported host '%s'. Can only retrieve metadata from these hosts: %sz, )roÚcompatr Ú_check_if_whitelisted_hostrr®rGÚ_ALLOWED_HOSTS)rar½ÚparsedZis_whitelisted_hostr*r*r+r»Us z.ContainerMetadataFetcher._validate_allowed_urlcCs||jkrdSdS)NTF)rÁ)rar:r*r*r+rÀ_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¼)raÚ relative_urir½r*r*r+Ú retrieve_urids z%ContainerMetadataFetcher.retrieve_uric CsŒddi}|dk r| |¡d}xhy| |||j¡Stk r‚}z4tjd|dd| |j¡|d7}||jkrr‚Wdd}~XYq Xq WdS)NÚAcceptzapplication/jsonrzAReceived error when attempting to retrieve container metadata: %sT)r{r) rðÚ _get_responser·rrˆr‰r¸Ú SLEEP_TIMEÚRETRY_ATTEMPTS)rar½Ú extra_headersryÚattemptsrŒr*r*r+r¼ps     z.ContainerMetadataFetcher._retrieve_credentialsc CsÊytjj}|d||d}|j | ¡¡}|j d¡}|jdkrRt d|j|fd‚y t   |¡St k rŒd}t  d||¡t |d‚YnXWn4tk rÄ} zd | }t |d‚Wdd} ~ XYnXdS) NrŽ)rxrHryzutf-8rzz4Received non 200 response (%s) from ECS metadata: %s)Ú error_msgz8Unable to parse JSON returned from ECS metadata servicesz%s:%sz;Received error when attempting to retrieve ECS metadata: %s)ror€rrsrƒr„r™rúr…rrr¬r®rˆr‰r‡) rar½ryrerr`r‹Z response_textrËrŒr*r*r+rÆs&   z&ContainerMetadataFetcher._get_responsecCsd|j|fS)Nz http://%s%s)Ú IP_ADDRESS)rarÃr*r*r+r½™sz!ContainerMetadataFetcher.full_url)N)N)r[r\r]r·rÈrÇrÌrÁÚtimerºrbr¾r»rÀrÄr¼rÆr½r*r*r*r+rµ9s    rµcCst|ƒr iStƒSdS)N)Úshould_bypass_proxiesr)rHr*r*r+rrsrrc Cs6ytt|ƒjƒrdSWnttjfk r0YnXdS)z: Returns whether we should bypass proxies or not. TF)rr r5rÖÚsocketÚgaierror)rHr*r*r+rΤs rÎú ISO-8859-1cCsF| d¡}|sdSt |¡\}}d|kr6|d d¡Sd|krB|SdS)z®Returns encodings from given HTTP Header Dict. :param headers: dictionary to extract encoding from. :param default: default encoding if the content-type is text z content-typeNÚcharsetz'"r†)r2ÚcgiÚ parse_headerrÃ)ryÚdefaultÚ content_typer~r*r*r+Úget_encoding_from_headers¹s r×cKs0t|ttfƒrt|ƒ}nt|ƒ}t |¡ d¡S)Nrö)r&ÚbytesÚ bytearrayÚ_calculate_md5_from_bytesÚ_calculate_md5_from_fileÚbase64Ú b64encoderú)rêr/Z binary_md5r*r*r+Ú calculate_md5Îs rÞcCst|ƒ}| ¡S)N)r rò)Z body_bytesÚmd5r*r*r+rÚÖsrÚcsFˆ ¡}tƒ}x$t‡fdd„dƒD]}| |¡q"Wˆ |¡| ¡S)Ncs ˆ d¡S)Ni)r¹r*)Úfileobjr*r+rëÞrìz*_calculate_md5_from_file..rì)Útellr rïrðÚseekrò)ràZstart_positionrßrór*)ràr+rÛÛs  rÛcKs<|d}|d}tr8|r8d|kr8t|f|Ž}||dd<dS)z1Only add a Content-MD5 if the system supports it.ryrêz Content-MD5N)r rÞ)r~r/ryrêZ md5_digestr*r*r+Úconditionally_calculate_md5äs  rãc@s eZdZefdd„Zdd„ZdS)ÚFileWebIdentityTokenLoadercCs||_||_dS)N)Ú_web_identity_token_pathr½)raZweb_identity_token_pathr½r*r*r+rbîsz#FileWebIdentityTokenLoader.__init__c Cs | |j¡ }| ¡SQRXdS)N)r½rår¹)raZ token_filer*r*r+Ú__call__òsz#FileWebIdentityTokenLoader.__call__N)r[r\r]Úopenrbrær*r*r*r+räís räc@s&eZdZddd„Zdd„Zdd„ZdS) ÚSSOTokenLoaderNcCs|dkr i}||_dS)N)r^)rarcr*r*r+rbøszSSOTokenLoader.__init__cCst | d¡¡ ¡S)Nzutf-8)ríÚsha1rÐrñ)raÚ start_urlr*r*r+Ú_generate_cache_keyýsz"SSOTokenLoader._generate_cache_keycCsR| |¡}y|j|}|dStk rLtjdddd}t|d‚YnXdS)NZ accessTokenzFailed to load SSO token:T)r{z@The SSO access token has either expired or is otherwise invalid.)rË)rër^ÚKeyErrorrˆr‰r)rarêr?r“rËr*r*r+ræs  zSSOTokenLoader.__call__)N)r[r\r]rbrërær*r*r*r+rè÷s rè)T)F)N)F)N)N)T)T)rÑ)vrÜr:rÍÚloggingrÔrírørDr_rrjrÏrÓZdateutil.parserr×Z dateutil.tzrroZbotocore.awsrequestZbotocore.httpsessionZbotocore.compatrrrrrrr r r r r Z*botocore.vendored.six.moves.urllib.requestrrZbotocore.exceptionsrrrrrrrrrrrrrÚ getLoggerr[rˆršr›Z SAFE_CHARSrr(r‡rGZ EVENT_ALIASESr,r5r=rAr?rQrTÚ ExceptionrZr_Úobjectrcrœr³r¸rçrÀrºrÍrÈrÛrÝrßrérôrýr÷rÿrr#r%r,r2r.r4rFrOrSrMrTrVr[r\r®r€rrŒršrµrrrÎr×rÞrÚrÛrãrärèr*r*r*r+Ú s: 4<    !~V   $ -  !`   >   !=Gd