B ㊇cv@s|dZddlmZddlmZmZddlmZddlm Z m Z ddl m Z m Z mZeZGdddeZGd d d eZGd d d eZGd ddeZGdddeZGdddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZGd!d"d"Z Gd#d$d$Z!Gd%d&d&Z"Gd'd(d(Z#Gd)d*d*Z$Gd+d,d,Z%d-S).z-Abstractions to interact with service models.) defaultdict) NamedTupleUnion) OrderedDict)MissingServiceIdErrorUndefinedModelAttributeError)CachedPropertyhyphenize_service_idinstance_cachec@s eZdZdS)NoShapeFoundErrorN)__name__ __module__ __qualname__rri/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/botocore/model.pyr sr c@s eZdZdS)InvalidShapeErrorN)r r rrrrrrsrc@s eZdZdS)OperationNotFoundErrorN)r r rrrrrr#src@s eZdZdS)InvalidShapeReferenceErrorN)r r rrrrrr'src@seZdZddZdS) ServiceIdcCst|S)N)r )selfrrr hyphenize,szServiceId.hyphenizeN)r r rrrrrrr+src@seZdZdZdddddddd d d d d dddddgZddddddddddddddd gZeZd0d"d#Ze d$d%Z e d&d'Z e d(d)Z d*d+Z d,d-Zed.d/Zd!S)1Shapez3Object representing a shape from the service model. locationNameZ queryNameZ flattenedlocationpayloadZ streamingZtimestampFormatZ xmlNamespaceZ resultWrapperZ xmlAttribute eventstreameventZ eventheaderZ eventpayloadZ jsonvalueZ hostLabelrequiredminmaxpatternZ sensitiveenumidempotencyTokenerror exceptionZendpointdiscoveryidZ retryabledocumentunion contextParamclientContextParamsNcCsB||_|d|_|dd|_||_|dkr2t}||_i|_dS)a  :type shape_name: string :param shape_name: The name of the shape. :type shape_model: dict :param shape_model: The shape model. This would be the value associated with the key in the "shapes" dict of the service model (i.e ``model['shapes'][shape_name]``) :type shape_resolver: botocore.model.ShapeResolver :param shape_resolver: A shape resolver object. This is used to resolve references to other shapes. For scalar shape types (string, integer, boolean, etc.), this argument is not required. If a shape_resolver is not provided for a complex type, then a ``ValueError`` will be raised when an attempt to resolve a shape is made. type documentationN)name type_namegetr* _shape_modelUnresolvableShapeMap_shape_resolver_cache)r shape_name shape_modelshape_resolverrrr__init__]s zShape.__init__cCsJ|j}i}x$|jD]}||jkr||||<qWd|krF|d|d<|S)aSerialization information about the shape. This contains information that may be needed for input serialization or response parsing. This can include: * name * queryName * flattened * location * payload * streaming * xmlNamespace * resultWrapper * xmlAttribute * jsonvalue * timestampFormat :rtype: dict :return: Serialization information about the shape. rr,)r/SERIALIZED_ATTRSpop)rmodel serializationattrrrrr:s  zShape.serializationcCs4|j}i}x$|jD]}||jkr||||<qW|S)asMetadata about the shape. This requires optional information about the shape, including: * min * max * pattern * enum * sensitive * required * idempotencyToken * document * union :rtype: dict :return: Metadata about the shape. )r/METADATA_ATTRS)rr9metadatar;rrrr=s   zShape.metadatacCs|jdgS)zA list of members that are required. A structure shape can define members that are required. This value will return a list of required members. If there are no required members an empty list is returned. r)r=r.)rrrrrequired_memberss zShape.required_memberscCs |j|S)N)r1resolve_shape_ref)r shape_refrrr_resolve_shape_refszShape._resolve_shape_refcCsd|jjd|jdS)N<(z)>) __class__r r,)rrrr__repr__szShape.__repr__cCsdS)Nr)rrrrevent_stream_nameszShape.event_stream_name)N)r r r__doc__r7r<rMAP_TYPEr6rr:r=r>rArEpropertyrFrrrrr0sR " !  rc@sHeZdZeddZeddZeddZeddZed d Zd S) StructureShapecCsB|jd|}|}x"|D]\}}||||<q$W|S)Nmembers)r/r.rHitemsrA)rrKZ shape_membersr,r@rrrrKs zStructureShape.memberscCs,x&|jD]\}}|jdr |Sq WdS)Nr)rKrLr:r.)r member_namememberrrrrFs z StructureShape.event_stream_namecCs8|jddsdS|jdi}|d}|r2|S|jS)Nr$Fr#code)r=r.r,)rZerror_metadatarOrrr error_codes zStructureShape.error_codecCs|jddS)Nr%F)r=r.)rrrris_document_typeszStructureShape.is_document_typecCs|jddS)Nr&F)r=r.)rrrris_tagged_unionszStructureShape.is_tagged_unionN) r r rrrKrFrPrQrRrrrrrJs    rJc@seZdZeddZdS) ListShapecCs||jdS)NrN)rAr/)rrrrrNszListShape.memberN)r r rrrNrrrrrSsrSc@s$eZdZeddZeddZdS)MapShapecCs||jdS)Nkey)rAr/)rrrrrUsz MapShape.keycCs||jdS)Nvalue)rAr/)rrrrrVszMapShape.valueN)r r rrrUrVrrrrrTs rTc@seZdZeddZdS) StringShapecCs|jdgS)Nr!)r=r.)rrrrr! szStringShape.enumN)r r rrr!rrrrrW srWc@s&eZdZUeed<eeefed<dS)StaticContextParameterr,rVN)r r rstr__annotations__rboolrrrrrXs rXc@seZdZUeed<eed<dS)ContextParameterr,rMN)r r rrYrZrrrrr\s r\c@s&eZdZUeed<eed<eed<dS)ClientContextParameterr,r)r*N)r r rrYrZrrrrr]s r]c@seZdZdZd0ddZd1ddZddZed d Zd d Z ed dZ eddZ e ddZ eddZeddZeddZeddZeddZeddZedd Zed!d"Zed#d$Zed%d&Zed'd(Zd)d*Zed+d,Zejd-d,Zd.d/ZdS)2 ServiceModelzQ :ivar service_description: The parsed service description dictionary. NcCs<||_|di|_t|di|_t|_||_i|_dS)a :type service_description: dict :param service_description: The service description model. This value is obtained from a botocore.loader.Loader, or from directly loading the file yourself:: service_description = json.load( open('/path/to/service-description-model.json')) model = ServiceModel(service_description) :type service_name: str :param service_name: The name of the service. Normally this is the endpoint prefix defined in the service_description. However, you can override this value to provide a more convenient name. This is done in a few places in botocore (ses instead of email, emr instead of elasticmapreduce). If this value is not provided, it will default to the endpointPrefix defined in the model. r=shapesN) _service_descriptionr.r= ShapeResolverr1NOT_SET_signature_version _service_nameZ_instance_cache)rZservice_description service_namerrrr6(szServiceModel.__init__cCs|j||S)N)r1get_shape_by_name)rr3 member_traitsrrr shape_forGszServiceModel.shape_forcCs|j|dS)N)_error_code_cacher.)rrPrrrshape_for_error_codeLsz!ServiceModel.shape_for_error_codecCs&i}x|jD]}|j}|||<q W|S)N) error_shapesrP)rZerror_code_cache error_shaperOrrrriOs   zServiceModel._error_code_cachecCs |j|S)N)r1r?)rr@rrrr?WszServiceModel.resolve_shape_refcCst|jdiS)Nr_)listr`r.)rrrr shape_namesZszServiceModel.shape_namescCs:g}x0|jD]&}||}|jddr ||q W|S)Nr$F)rnrhr=r.append)rrkr3rlrrrrk^s   zServiceModel.error_shapescCs<y|jd|}Wntk r.t|YnXt|||S)N operations)r`KeyErrorrOperationModel)rZoperation_namer9rrroperation_modelgs zServiceModel.operation_modelcCs|jddS)Nr*r+)r`r.)rrrrr*oszServiceModel.documentationcCst|jdgS)Nrp)rmr`r.)rrrroperation_namessszServiceModel.operation_namescCs|jdk r|jS|jSdS)aThe name of the service. This defaults to the endpointPrefix defined in the service model. However, this value can be overriden when a ``ServiceModel`` is created. If a service_name was not provided when the ``ServiceModel`` was created and if there is no endpointPrefix defined in the service model, then an ``UndefinedModelAttributeError`` exception will be raised. N)rdendpoint_prefix)rrrrrews zServiceModel.service_namecCs4yt|dStk r.t|jdYnXdS)NZ serviceId)re)r_get_metadata_propertyrrrd)rrrr service_idszServiceModel.service_idcCs|jd}|dkr|j}|S)zThe name to use when computing signatures. If the model does not define a signing name, this value will be the endpoint prefix defined in the model. Z signingNameN)r=r.ru)r signing_namerrrrxs zServiceModel.signing_namecCs |dS)NZ apiVersion)rv)rrrr api_versionszServiceModel.api_versioncCs |dS)Nprotocol)rv)rrrrrzszServiceModel.protocolcCs |dS)NZendpointPrefix)rv)rrrrruszServiceModel.endpoint_prefixcCs(x"|jD]}||}|jr|SqWdS)N)rtrsis_endpoint_discovery_operation)r operationr9rrrendpoint_discovery_operations  z)ServiceModel.endpoint_discovery_operationcCs8x2|jD](}||}|jdk r|jdrdSqWdS)NrTF)rtrsendpoint_discoveryr.)rr|r9rrrendpoint_discovery_requireds     z(ServiceModel.endpoint_discovery_requiredcCs |jdi}dd|DS)Nr(cSs&g|]\}}t||d|ddqS)r)r*)r,r)r*)r]).0 param_nameZ param_valrrr sz:ServiceModel.client_context_parameters..)r`r.rL)rparamsrrrclient_context_parameterssz&ServiceModel.client_context_parameterscCs8y |j|Stk r2td|d|YnXdS)N"z," not defined in the metadata of the model: )r=rqr)rr,rrrrvs  z#ServiceModel._get_metadata_propertycCs"|jtkr|jd}||_|jS)NZsignatureVersion)rcrbr=r.)rsignature_versionrrrrs  zServiceModel.signature_versioncCs ||_dS)N)rc)rrVrrrrscCs|jjd|jdS)NrC))rDr re)rrrrrEszServiceModel.__repr__)N)N)r r rrGr6rhrjrrir?rnrkr rsr*rtrerwrxryrzrur}rrrvrIrsetterrErrrrr^!s0               r^c@sJeZdZd.)rrKrL)rrrrridempotent_membersEs z!OperationModel.idempotent_memberscCs |jdi}dd|DS)NZstaticContextParamscSs"g|]\}}t||ddqS)rV)r,rV)rXr.)rr,propsrrrrVsz.)rr.rL)rrrrrstatic_context_parametersRsz(OperationModel.static_context_parameterscCs |js gSdd|jjDS)NcSs>g|]6\}}d|jkrd|jdkrt|jdd|dqS)r'r,)r,rM)r=r\)rr,rrrrr`s z5OperationModel.context_parameters..)rrKrL)rrrrcontext_parametersZsz!OperationModel.context_parameterscCs |jdS)NZauthtype)rr.)rrrr auth_typeiszOperationModel.auth_typecs$jdg}tfdd|DS)Nerrorsc3s|]}j|VqdS)N)rr?)rs)rrr psz.OperationModel.error_shapes..)rr.rm)rr_r)rrrkmszOperationModel.error_shapescCs |jdS)Nendpoint)rr.)rrrrrrszOperationModel.endpointcCs|jddS)NZhttpChecksumRequiredF)rr.)rrrrhttp_checksum_requiredvsz%OperationModel.http_checksum_requiredcCs|jdiS)NZ httpChecksum)rr.)rrrr http_checksumzszOperationModel.http_checksumcCs |dk S)N)get_event_stream_input)rrrrhas_event_stream_input~sz%OperationModel.has_event_stream_inputcCs |dk S)N)get_event_stream_output)rrrrhas_event_stream_outputsz&OperationModel.has_event_stream_outputcCs ||jS)N)_get_event_streamr)rrrrrsz%OperationModel.get_event_stream_inputcCs ||jS)N)rr)rrrrrsz&OperationModel.get_event_stream_outputcCs$|dkr dS|j}|r |j|SdS)zAReturns the event stream member's shape if any or None otherwise.N)rFrK)rrZ event_namerrrrs  z OperationModel._get_event_streamcCs |dk S)N)get_streaming_input)rrrrhas_streaming_inputsz"OperationModel.has_streaming_inputcCs |dk S)N)get_streaming_output)rrrrhas_streaming_outputsz#OperationModel.has_streaming_outputcCs ||jS)N)_get_streaming_bodyr)rrrrrsz"OperationModel.get_streaming_inputcCs ||jS)N)rr)rrrrrsz#OperationModel.get_streaming_outputcCs<|dkr dS|jd}|dk r8|j|}|jdkr8|SdS)z?Returns the streaming member's shape if any; or None otherwise.Nrblob)r:r.rKr-)rrrZ payload_shaperrrrs   z"OperationModel._get_streaming_bodycCs|jjd|jdS)Nz(name=r)rDr r,)rrrrrEszOperationModel.__repr__)N)"r r rr6rr,rIrrr*rr~r{rrrrrrrkrrrrrrrrrrrrrrErrrrrrs: %                   rrc@s8eZdZdZeeeedZddZ d ddZ dd Z dS) razResolves shape references.) structurermmapstringcCs||_i|_dS)N) _shape_mapZ _shape_cache)r shape_maprrrr6szShapeResolver.__init__NcCsy|j|}Wntk r*t|YnXy|j|dt}Wn"tk rdtd|YnX|r||}||||||}|S)Nr)z&Shape is missing required key 'type': ) rrqr SHAPE_CLASSESr.rrcopyupdate)rr3rgr4Z shape_clsresultrrrrfs  zShapeResolver.get_shape_by_namecCslt|dkr"d|kr"||dS|}y|d}Wn"tk rZtd|YnX|||SdS)Nrz(Invalid model, missing shape reference: )lenrfrr8rqr)rr@rgr3rrrr?szShapeResolver.resolve_shape_ref)N) r r rrGrJrSrTrWrr6rfr?rrrrras rac@s"eZdZdZdddZddZdS)r0zEA ShapeResolver that will throw ValueErrors when shapes are resolved.NcCstd|ddS)NzAttempted to lookup shape 'z!', but no shape map was provided.) ValueError)rr3rgrrrrfsz&UnresolvableShapeMap.get_shape_by_namecCstd|ddS)NzAttempted to resolve shape 'z!', but no shape map was provided.)r)rr@rrrr?sz&UnresolvableShapeMap.resolve_shape_ref)N)r r rrGrfr?rrrrr0s r0c@sfeZdZdZdZdddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)DenormalizedStructureBuilderaBuild a StructureShape from a denormalized model. This is a convenience builder class that makes it easy to construct ``StructureShape``s based on a denormalized model. It will handle the details of creating unique shape names and creating the appropriate shape map needed by the ``StructureShape`` class. Example usage:: builder = DenormalizedStructureBuilder() shape = builder.with_members({ 'A': { 'type': 'structure', 'members': { 'B': { 'type': 'structure', 'members': { 'C': { 'type': 'string', } } } } } }).build_model() # ``shape`` is now an instance of botocore.model.StructureShape :type dict_type: class :param dict_type: The dictionary type to use, allowing you to opt-in to using OrderedDict or another dict type. This can be particularly useful for testing when order matters, such as for documentation. ) rintegerbooleanrfloat timestamplongdoublecharNcCs*t|_t|_|dkr&|jd|_dS)Nr)rrKShapeNameGenerator_name_generatornew_shape_namer,)rr,rrrr6(sz%DenormalizedStructureBuilder.__init__cCs ||_|S)zp :type members: dict :param members: The denormalized members. :return: self )_members)rrKrrr with_members.s z)DenormalizedStructureBuilder.with_memberscCsBt}d|jd}||||jt|d}t|j||j|dS)zBuild the model based on the provided members. :rtype: botocore.model.StructureShape :return: The built StructureShape object. r)r)rK)r)r3r4r5)rr _build_modelr,rarJ)rr_Z denormalizedresolverrrr build_model:s  z(DenormalizedStructureBuilder.build_modelcCs|ddkr|||||<nl|ddkr<|||||<nN|ddkrZ|||||<n0|d|jkrx||||<ntd|ddS)Nr)rrmrzUnknown shape type: )_build_structure _build_list _build_map SCALAR_TYPES _build_scalarr)rr9r_r3rrrrNs   z)DenormalizedStructureBuilder._build_modelcCs`t}||}||d<xB|dtD],\}}||}d|i||<||||q,W|S)NrKr)r_build_initial_shaper.rL_get_shape_namer)rr9r_rKrr,Z member_modelmember_shape_namerrrrZs   z-DenormalizedStructureBuilder._build_structurecCs6||}||}d|i|d<||d|||S)NrrN)rrr)rr9r_rrrrrres    z(DenormalizedStructureBuilder._build_listcCsf||d}||d}||}d|i|d<d|i|d<||d||||d|||S)NrUrVr)rrr)rr9r_Zkey_shape_nameZvalue_shape_namerrrrrls   z'DenormalizedStructureBuilder._build_mapcCsHd|di}d|kr |d|d<x"tjD]}||kr(||||<q(W|S)Nr)r*)rr<)rr9rr;rrrrvs   z1DenormalizedStructureBuilder._build_initial_shapecCs ||S)N)r)rr9rrrrsz*DenormalizedStructureBuilder._build_scalarcCs$d|kr|dS|j|dSdS)Nr3r))rr)rr9rrrrsz,DenormalizedStructureBuilder._get_shape_name)N)r r rrGrr6rrrrrrrrrrrrrrs#      rc@s eZdZdZddZddZdS)rzGenerate unique shape names for a type. This class can be used in conjunction with the DenormalizedStructureBuilder to generate unique shape names for a given type. cCstt|_dS)N)rint _name_cache)rrrrr6szShapeNameGenerator.__init__cCs.|j|d7<|j|}|d|S)aGenerate a unique shape name. This method will guarantee a unique shape name each time it is called with the same type. :: >>> s = ShapeNameGenerator() >>> s.new_shape_name('structure') 'StructureType1' >>> s.new_shape_name('structure') 'StructureType2' >>> s.new_shape_name('list') 'ListType1' >>> s.new_shape_name('list') 'ListType2' :type type_name: string :param type_name: The type name (structure, list, map, string, etc.) :rtype: string :return: A unique shape name for the given type rType)r capitalize)rr-Z current_indexrrrrs z!ShapeNameGenerator.new_shape_nameN)r r rrGr6rrrrrrsrN)&rG collectionsrtypingrrZbotocore.compatrZbotocore.exceptionsrrZbotocore.utilsrr r objectrb Exceptionr rrrrYrrrJrSrTrWrXr\r]r^rrrar0rrrrrr s:  "* ?T6