o ?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@ eZdZdS)NoShapeFoundErrorN__name__ __module__ __qualname__rri/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/model.pyr r c@r )InvalidShapeErrorNr rrrrrrrc@r )OperationNotFoundErrorNr rrrrr#rrc@r )InvalidShapeReferenceErrorNr rrrrr'rrc@seZdZddZdS) ServiceIdcCst|SN)r selfrrr hyphenize,szServiceId.hyphenizeN)rrrrrrrrr+s rc@sneZdZdZgdZgdZeZdddZe ddZ e d d Z e d d Z d dZ ddZeddZdS)Shapez3Object representing a shape from the service model.) locationNameZ queryNameZ flattenedlocationpayloadZ streamingtimestampFormatZ xmlNamespaceZ resultWrapperZ xmlAttribute eventstreameventZ eventheaderZ eventpayloadZ jsonvaluer Z hostLabel)requiredminmaxpatternZ sensitiveenumidempotencyTokenerror exceptionZendpointdiscoveryidZ retryabledocumentunion contextParamclientContextParamsNcCsB||_|d|_|dd|_||_|durt}||_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_namegetr0 _shape_modelUnresolvableShapeMap_shape_resolver_cache)r shape_name shape_modelshape_resolverrrr__init__]s  zShape.__init__cCsF|j}i}|jD] }||jvr||||<qd|vr!|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. rr2)r5SERIALIZED_ATTRSpop)rmodel serializationattrrrrr@s   zShape.serializationcCs0|j}i}|jD] }||jvr||||<q|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. )r5METADATA_ATTRS)rr?metadatarArrrrCs   zShape.metadatacC|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#rCr4rrrrrequired_memberss zShape.required_memberscC |j|Srr7resolve_shape_refr shape_refrrr_resolve_shape_ref zShape._resolve_shape_refcCsd|jjd|jdS)N<(z)> __class__rr2rrrr__repr__szShape.__repr__cCsdSrrrrrrevent_stream_nameszShape.event_stream_namer)rrr__doc__r=rBrMAP_TYPEr<rr@rCrFrLrRpropertyrSrrrrr0s  "    rc@sHeZdZeddZeddZeddZeddZed d Zd S) StructureShapecCs>|jd|}|}|D] \}}||||<q|S)Nmembers)r5r4rUitemsrL)rrXZ shape_membersr2rKrrrrXs zStructureShape.memberscCs,|jD]\}}|jdr|SqdS)Nr!)rXrYr@r4)r member_namememberrrrrSs  z StructureShape.event_stream_namecCs8|jdds dS|jdi}|d}|r|S|jS)Nr*Fr)code)rCr4r2)rZerror_metadatar\rrr error_codes zStructureShape.error_codecC|jddS)Nr+FrErrrris_document_typezStructureShape.is_document_typecCr^)Nr,FrErrrris_tagged_unionr`zStructureShape.is_tagged_unionN) rrrrrXrSr]r_rarrrrrWs    rWc@eZdZeddZdS) ListShapecC||jdS)Nr[rLr5rrrrr[zListShape.memberN)rrrrr[rrrrrcrcc@s$eZdZeddZeddZdS)MapShapecCrd)Nkeyrerrrrrirfz MapShape.keycCrd)NvaluererrrrrjrfzMapShape.valueN)rrrrrirjrrrrrhs  rhc@rb) StringShapecCrD)Nr'rErrrrr' r`zStringShape.enumN)rrrrr'rrrrrk rgrkc@s&eZdZUeed<eeefed<dS)StaticContextParameterr2rjN)rrrstr__annotations__rboolrrrrrls rlc@seZdZUeed<eed<dS)ContextParameterr2rZNrrrrmrnrrrrrps  rpc@s&eZdZUeed<eed<eed<dS)ClientContextParameterr2r/r0Nrqrrrrrrs  rrc@seZdZdZd0ddZd0ddZddZed 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)1 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. rCshapesN) _service_descriptionr4rC ShapeResolverr7NOT_SET_signature_version _service_nameZ_instance_cache)rZservice_description service_namerrrr<(s  zServiceModel.__init__cCs|j||Sr)r7get_shape_by_namerr9 member_traitsrrr shape_forGszServiceModel.shape_forcCs|j|dSr)_error_code_cacher4)rr]rrrshape_for_error_codeLz!ServiceModel.shape_for_error_codecCs"i}|jD] }|j}|||<q|Sr) error_shapesr])rZerror_code_cache error_shaper\rrrrOs   zServiceModel._error_code_cachecCrGrrHrJrrrrIWrMzServiceModel.resolve_shape_refcCst|jdiS)Nrtlistrur4rrrr shape_namesZzServiceModel.shape_namescCs6g}|jD]}||}|jddr||q|S)Nr*F)rr~rCr4append)rrr9rrrrr^s   zServiceModel.error_shapescCs6z |jd|}Wn tyt|wt|||SN operations)ruKeyErrorrOperationModel)rZoperation_namer?rrroperation_modelgs   zServiceModel.operation_modelcCr^Nr0r1)rur4rrrrr0or`zServiceModel.documentationcCst|jdgSrrrrrroperation_namessrzServiceModel.operation_namescCs|jdur|jS|jS)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)ryendpoint_prefixrrrrrzws zServiceModel.service_namecCs,zt|dWStyt|jdw)NZ serviceId)rz)r_get_metadata_propertyrrryrrrr service_ids   zServiceModel.service_idcCs|jd}|dur |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)rCr4r)r signing_namerrrrs zServiceModel.signing_namecC |dS)NZ apiVersionrrrrr api_version zServiceModel.api_versioncCr)NprotocolrrrrrrrzServiceModel.protocolcCr)NZendpointPrefixrrrrrrrzServiceModel.endpoint_prefixcCs(|jD]}||}|jr|SqdSr)rris_endpoint_discovery_operationrZ operationr?rrrendpoint_discovery_operations  z)ServiceModel.endpoint_discovery_operationcCs6|jD]}||}|jdur|jdrdSqdS)Nr#TF)rrendpoint_discoveryr4rrrrendpoint_discovery_requireds   z(ServiceModel.endpoint_discovery_requiredcC |jdi}dd|DS)Nr.cSs&g|]\}}t||d|ddqS)r/r0)r2r/r0)rr).0 param_nameZ param_valrrr sz:ServiceModel.client_context_parameters..)rur4rYrparamsrrrclient_context_parameterssz&ServiceModel.client_context_parameterscCs0z|j|WStytd|d|w)N"z," not defined in the metadata of the model: )rCrrrr2rrrrs  z#ServiceModel._get_metadata_propertycCs"|jtur|jd}||_|jS)NZsignatureVersion)rxrwrCr4)rsignature_versionrrrrs  zServiceModel.signature_versioncCs ||_dSr)rx)rrjrrrrrcC|jjd|jdS)NrO))rQrrzrrrrrRzServiceModel.__repr__r)rrrrTr<r~rrrrIrrr rr0rrzrrrrrrrrrrVrsetterrRrrrrrs!sT                     rsc@sJeZdZd.rrXrY)rrrrridempotent_membersEs z!OperationModel.idempotent_memberscCr)NZstaticContextParamscSs"g|] \}}t||ddqS)rj)r2rj)rlr4)rr2propsrrrrUsz.)rr4rYrrrrstatic_context_parametersRsz(OperationModel.static_context_parameterscCs |jsgSdd|jjDS)NcSs>g|]\}}d|jvrd|jdvrt|jdd|dqS)r-r2)r2rZ)rCrprrrrr_s  z5OperationModel.context_parameters..rrrrrcontext_parametersZs  z!OperationModel.context_parameterscCr)NZauthtyperrrrr auth_typei zOperationModel.auth_typecs$jdg}tfdd|DS)Nerrorsc3s|] }j|VqdSr)rrI)rsrrr psz.OperationModel.error_shapes..)rr4r)rrtrrrrmszOperationModel.error_shapescCr)NendpointrrrrrrrrzOperationModel.endpointcCr^)NZhttpChecksumRequiredFrrrrrhttp_checksum_requiredvr`z%OperationModel.http_checksum_requiredcCs|jdiS)NZ httpChecksumrrrrr http_checksumzr`zOperationModel.http_checksumcC |duSr)get_event_stream_inputrrrrhas_event_stream_input~rz%OperationModel.has_event_stream_inputcCrr)get_event_stream_outputrrrrhas_event_stream_outputrz&OperationModel.has_event_stream_outputcC ||jSr)_get_event_streamrrrrrrrMz%OperationModel.get_event_stream_inputcCrr)rrrrrrrrMz&OperationModel.get_event_stream_outputcCs$|durdS|j}|r|j|SdS)zAReturns the event stream member's shape if any or None otherwise.N)rSrX)rrZ event_namerrrrs  z OperationModel._get_event_streamcCrr)get_streaming_inputrrrrhas_streaming_inputrz"OperationModel.has_streaming_inputcCrr)get_streaming_outputrrrrhas_streaming_outputrz#OperationModel.has_streaming_outputcCrr)_get_streaming_bodyrrrrrrrMz"OperationModel.get_streaming_inputcCrr)rrrrrrrrMz#OperationModel.get_streaming_outputcCs<|durdS|jd}|dur|j|}|jdkr|SdS)z?Returns the streaming member's shape if any; or None otherwise.Nrblob)r@r4rXr3)rrrZ payload_shaperrrrs   z"OperationModel._get_streaming_bodycCr)Nz(name=rrPrrrrrRrzOperationModel.__repr__r)"rrrr<rr2rVrrr0rrrrrrrrrrrrrrrrrrrrrrrrRrrrrrsf %                      rc@s8eZdZdZeeeedZddZ d ddZ dd Z dS) rvzResolves shape references.) structurermapstringcCs||_i|_dSr) _shape_mapZ _shape_cache)r shape_maprrrr<s zShapeResolver.__init__NcCsz|j|}Wn tyt|wz |j|dt}Wnty,td|w|r8|}||||||}|S)Nr/z&Shape is missing required key 'type': ) rrr SHAPE_CLASSESr4rrcopyupdate)rr9r}r:Z shape_clsresultrrrr{s"    zShapeResolver.get_shape_by_namecCsbt|dkrd|vr||dS|}z|d}Wnty*td|w|||S)Nrz(Invalid model, missing shape reference: )lenr{rr>rr)rrKr}r9rrrrIs  zShapeResolver.resolve_shape_refr) rrrrTrWrcrhrkrr<r{rIrrrrrvs  rvc@s"eZdZdZdddZddZdS)r6zEA ShapeResolver that will throw ValueErrors when shapes are resolved.NcCtd|d)NzAttempted to lookup shape '!', but no shape map was provided. ValueErrorr|rrrr{ z&UnresolvableShapeMap.get_shape_by_namecCr)NzAttempted to resolve shape 'rrrJrrrrIrz&UnresolvableShapeMap.resolve_shape_refr)rrrrTr{rIrrrrr6s  r6c@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|_|dur|jd|_dSdS)Nr)rrXShapeNameGenerator_name_generatornew_shape_namer2rrrrr<(s z%DenormalizedStructureBuilder.__init__cCs ||_|S)zp :type members: dict :param members: The denormalized members. :return: self )_members)rrXrrr 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/rX)r)r9r:r;)rr _build_modelr2rvrW)rrtZ denormalizedresolverrrr build_model:s z(DenormalizedStructureBuilder.build_modelcCs|ddkr|||||<dS|ddkr |||||<dS|ddkr0|||||<dS|d|jvr@||||<dStd|d)Nr/rrrzUnknown shape type: )_build_structure _build_list _build_map SCALAR_TYPES _build_scalarr)rr?rtr9rrrrNs   z)DenormalizedStructureBuilder._build_modelcCs\t}||}||d<|dtD]\}}||}d|i||<||||q|S)NrXr)r_build_initial_shaper4rY_get_shape_namer)rr?rtrXrr2Z member_modelmember_shape_namerrrrZs   z-DenormalizedStructureBuilder._build_structurecCs6||}||}d|i|d<||d|||S)Nrr[rrr)rr?rtrrrrrres   z(DenormalizedStructureBuilder._build_listcCsf||d}||d}||}d|i|d<d|i|d<||d||||d|||S)Nrirjrr)rr?rtZkey_shape_nameZvalue_shape_namerrrrrls   z'DenormalizedStructureBuilder._build_mapcCsDd|di}d|vr|d|d<tjD] }||vr||||<q|S)Nr/r0)rrB)rr?rrArrrrvs   z1DenormalizedStructureBuilder._build_initial_shapecCs ||Sr)rrr?rrrrs z*DenormalizedStructureBuilder._build_scalarcCs d|vr|dS|j|dS)Nr9r/)rrrrrrrsz,DenormalizedStructureBuilder._get_shape_namer)rrrrTrr<rrrrrrrrrrrrrrs$      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|_dSr)rint _name_cacherrrrr<rzShapeNameGenerator.__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)rr3Z current_indexrrrrs z!ShapeNameGenerator.new_shape_nameN)rrrrTr<rrrrrrs rN)&rT collectionsrtypingrrZbotocore.compatrZbotocore.exceptionsrrZbotocore.utilsrr r objectrw Exceptionr rrrrmrrrWrcrhrkrlrprrrsrrvr6rrrrrrs<  "* ?T6