ee[c@s ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z mZddlZddlmZmZddlmZmZddlmZddlmZmZmZmZmZddlmZddlmZmZej e!Z"d Z#d Z$d Z%ej&d Z'ej(ej)fZ*d gZ+de,fdYZ-dZ.dZ/dZ0dZ1dZ2e3dZ4de5fdYZ6e7dZ8e9dZ:dZ;e%dZ<e%dZ=dZ>dZ?ddZAe7d ZBd!ZCd"ZDd#e5fd$YZEd%e5fd&YZFd'ZGd(ZHdd)ZIdd*ZJd+ZKd,ZLd-ZMd.ZNe3d/ZOe3d0ZPd1ZQd2e5fd3YZRd4e5fd5YZSdS(6iN(ttzlocalttzutc(tInvalidExpressionErrortConfigNotFound(tInvalidDNSNameErrort ClientError(tMetadataRetrievalError(tjsontquotet zip_longestturlsplitt urlunsplit(trequests(t OrderedDicttsixisAhttp://169.254.169.254/latest/meta-data/iam/security-credentials/s-._~s-z0-9][a-z0-9\-]*[a-z0-9]t dualstackt_RetriesExceededErrorcBseZdZRS(s@Internal exception used when the number of retries are exceeded.(t__name__t __module__t__doc__(((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR1scCsIt|doH|jjdtoH|jjddkoH|jdkS(sDetermines 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 t serializationt jsonvaluetlocationtheadertstring(thasattrRtgettFalset type_name(tshape((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytis_json_value_header6s cCsd|jjd|jjd|j}|jdd}|jdd}tjdd|}|S(svReturns the module name for a service This is the value used in both the documentation and client class name tserviceAbbreviationtserviceFullNametAmazonttAWSs\W+(tmetadataRt service_nametreplacetretsub(t service_modeltname((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytget_service_module_nameEs  cCs|s dSt|S(Nt/(tremove_dot_segments(tpath((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytnormalize_url_pathTscCs|s dS|jd}g}xR|D]J}|r&|dkr&|dkr`|rm|jqmqp|j|q&q&W|ddkrd}nd}|ddkr|rd}nd}|dj||S(NR"R,t.s..ii(tsplittpoptappendtjoin(turlt input_urlt output_listtxtfirsttlast((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR-Zs"    cCsa| s|dkr%td|nx5dddgD]$}||kr5td|q5q5WdS(NR0t expressiont[t]t*(R(R;tinvalid((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytvalidate_jmespath_for_setus  cCs|rt|n|jdd}|dt|dkrH|dnd}}|sjtd|n|r||kri||t j d |nXi} x]t|D]O} i| d 6|| d d 6|| dd6|| dd6|| dd6} qRW| S(Nsutf-8s R,iiRXRYt{sQMetadata service returned non 200 status code of %s for url: %s, content body: %ss\Max number of attempts exceeded (%s) when attempting to retrieve data from metadata service.t role_namet AccessKeyIdt access_keytSecretAccessKeyt secret_keytTokenttokent Expirationt expiry_time(RORMRNRhtcontenttdecodeR1tendswithtretrieve_iam_role_credentialsRtloadsR_R`RdRtsorted( RWtdataR5RXRYtrtfieldstfieldtvalt final_dataRj((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRvsD     !       N(RRt DEFAULT_METADATA_SERVICE_TIMEOUTt!METADATA_SECURITY_CREDENTIALS_URLRPR\RhRv(((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRIs  cCsx|D]}t||tra||krP||krPt||||q||||sR"N(thashlibtsha256titertupdatet hexdigesttdigest(Rtas_hextchecksumtchunk((Rs2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytcalculate_sha256s   csg}dtj}x<tfddD]}|j||jq1W|sj|djSxxt|dkrg}xSt|D]E\}}|dk r|j|||jq|j|qW|}qmWt j |dj dS( s\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 jS(N(R((Rtrequired_chunk_size(s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRsR"iitasciiiN( RRRR3RRRBt _in_pairsRPtbinasciithexlifyRt(RtchunksRRt new_chunksR9tsecond((RRs2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytcalculate_tree_hashs "   cCst|}t||S(N(RR (titerablet shared_iter((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRs tCachedPropertycBs eZdZdZdZRS(sA 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(t_fget(RWtfget((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR\scCs:|dkr|S|j|}||j|jj<|SdS(N(RPRt__dict__R(RWtobjtclstcomputed_value((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyt__get__s  (RRRR\R(((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRs tArgumentGeneratorcBsJeZdZedZdZddZdZdZdZ RS(sGenerate 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) cCs ||_dS(N(t_use_member_names(RWtuse_member_names((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR\6scCsg}|j||S(sGenerate a sample input. :type shape: ``botocore.model.Shape`` :param shape: The input shape. :return: The generated skeleton input corresponding to the provided input shape. (t_generate_skeleton(RWRtstack((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytgenerate_skeleton9s R"cCs |j|jz|jdkr2|j||S|jdkrQ|j||S|jdkrp|j||S|jdkr|jr|S|jrtj |jSdS|jdkrdS|jd krd S|jd krt S|jd kr t j d dddddSWd|j XdS(Nt structureRtmapRR"tintegertlongiRgtbooleant timestampii(sintegerslong( R3R*Rt_generate_type_structuret_generate_type_listt_generate_type_mapRtenumtrandomtchoiceRcRR2(RWRRR*((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRFs.   cCse|j|jdkriSt}x9|jjD](\}}|j||d|||ms   M ! tContainerMetadataFetchercBseZdZdZdZdZeddgZdej dZ ddZ dZ d Z d Zdd Zd Zd ZRS(iiis 169.254.170.2t localhosts 127.0.0.1cCsC|dkr-tj}t|_i|_n||_||_dS(N(RPR tSessionRt trust_envtproxiest_sessiont_sleep(RWtsessiontsleep((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR\s      cCs|j||j||S(sRetrieve 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" (t_validate_allowed_urlt_retrieve_credentials(RWtfull_urlR]((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pytretrieve_full_uris cCsVtjj|}|j|j}|sRtd|jdj|jfndS(NsGUnsupported host '%s'. Can only retrieve metadata from these hosts: %ss, (tbotocoretcompatturlparset_check_if_whitelisted_hostRRR4t_ALLOWED_HOSTS(RWR~tparsedtis_whitelisted_host((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR|s cCs||jkrtStS(N(RRcR(RWR((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR%scCs|j|}|j|S(sRetrieve 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}(RWt relative_uriR~((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyt retrieve_uri*s cCsidd6}|dk r)|j|nd}xtry|j|||jSWq2tk r}tjd|dt|j|j |d7}||j krqq2Xq2WdS(Nsapplication/jsontAcceptisAReceived error when attempting to retrieve container metadata: %sR^i( RPRRct _get_responsetTIMEOUT_SECONDSRR_R`Ryt SLEEP_TIMEtRETRY_ATTEMPTS(RWR~t extra_headersR]tattemptsRg((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR}6s      cCsy|jj|d|d|}|jdkrRtdd|j|jfnytj|jSWn'tk rtdd|jnXWn,tk r}d|}td|nXdS(NR]RXit error_msgs4Received non 200 response (%s) from ECS metadata: %ss3Unable to parse JSON returned from ECS metadata: %ss;Received error when attempting to retrieve ECS metadata: %s( RxRRdRttextRRwRRb(RWR~R]RXRfRgR((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRFs"  cCsd|j|fS(Ns http://%s%s(t IP_ADDRESS(RWR((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyR~YsN(RRRRRRRRPttimeR{R\RR|RRR}RR~(((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyRss   (TR'RtloggingRRRR$RARRQtdateutil.parserRt dateutil.tzRRRtbotocore.exceptionsRRRRRtbotocore.compatRRR R R tbotocore.vendoredR R Rt getLoggerRR_RRt SAFE_CHARSRRtTimeouttConnectionErrorRbR+t ExceptionRRR+R/R-R@RcRCtobjectRIRRtopenRRRRRRRPRRRRRRRRRR RR&R0R4R,R5R;R>Rs(((s2/tmp/pip-install-xdEqop/botocore/botocore/utils.pyt sv            (      !M   $   -   ! `    >