B =@Sap@sRdZddlmZddlmZmZmZddlmZddl m Z ddl m Z e Z GdddeZGd d d eZGd d d eZGd ddeZGdddeZGddde ZGdddeZGdddeZGdddeZGdddeZGddde ZGddde ZGdd d e ZGd!d"d"e ZGd#d$d$e ZGd%d&d&e Zd'S)(z-Abstractions to interact with service models.) defaultdict)CachedPropertyinstance_cachehyphenize_service_id) OrderedDict)MissingServiceIdError)UndefinedModelAttributeErrorc@s eZdZdS)NoShapeFoundErrorN)__name__ __module__ __qualname__r r f/private/var/folders/fg/1jzmct0d7d72tjkvm_1nhqc5sw67yj/T/pip-unpacked-wheel-ef76ia09/botocore/model.pyr sr c@s eZdZdS)InvalidShapeErrorN)r r r r r r rrsrc@s eZdZdS)OperationNotFoundErrorN)r r r r r r rr!src@s eZdZdS)InvalidShapeReferenceErrorN)r r r r r r rr%src@seZdZddZdS) ServiceIdcCst|S)N)r)selfr r r hyphenize*szServiceId.hyphenizeN)r r r rr r r rr)src@seZdZdZdddddddd d d d d dddddgZddddddddddddg ZeZd-dd Ze d!d"Z e d#d$Z e d%d&Z d'd(Z d)d*Zed+d,ZdS).Shapez3Object representing a shape from the service model. locationNameZ queryNameZ flattenedlocationpayloadZ streamingZtimestampFormatZ xmlNamespaceZ resultWrapperZ xmlAttribute eventstreameventZ eventheaderZ eventpayloadZ jsonvalueZ hostLabelrequiredminmaxZ sensitiveenumidempotencyTokenerror exceptionZendpointdiscoveryidZ retryabledocumentunionNcCsB||_|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_resolverr r r__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 serializationattrr r rr5`s  zShape.serializationcCs4|j}i}x$|jD]}||jkr||||<qW|S)a]Metadata about the shape. This requires optional information about the shape, including: * min * max * enum * sensitive * required * idempotencyToken * document * union :rtype: dict :return: Metadata about the shape. )r*METADATA_ATTRS)rr4metadatar6r r rr8s   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)r8r))rr r rrequired_memberss zShape.required_memberscCs |j|S)N)r,resolve_shape_ref)r shape_refr r r_resolve_shape_refszShape._resolve_shape_refcCsd|jj|jfS)Nz<%s(%s)>) __class__r r')rr r r__repr__szShape.__repr__cCsdS)Nr )rr r revent_stream_nameszShape.event_stream_name)N)r r r __doc__r2r7rMAP_TYPEr1rr5r8r9r<r>propertyr?r r r rr.s"    " !  rc@sHeZdZeddZeddZeddZeddZed d Zd S) StructureShapecCsB|jd|}|}x"|D]\}}||||<q$W|S)Nmembers)r*r)rAitemsr<)rrDZ shape_membersr'r;r r rrDs zStructureShape.memberscCs,x&|jD]\}}|jdr |Sq WdS)Nr)rDrEr5r))r member_namememberr r rr?s z StructureShape.event_stream_namecCs8|jddsdS|jdi}|d}|r2|S|jS)Nr!Fr code)r8r)r')rZerror_metadatarHr r r error_codes zStructureShape.error_codecCs|jddS)Nr"F)r8r))rr r ris_document_typeszStructureShape.is_document_typecCs|jddS)Nr#F)r8r))rr r ris_tagged_unionszStructureShape.is_tagged_unionN) r r r rrDr?rIrJrKr r r rrCs    rCc@seZdZeddZdS) ListShapecCs||jdS)NrG)r<r*)rr r rrGszListShape.memberN)r r r rrGr r r rrLsrLc@s$eZdZeddZeddZdS)MapShapecCs||jdS)Nkey)r<r*)rr r rrNsz MapShape.keycCs||jdS)Nvalue)r<r*)rr r rrOszMapShape.valueN)r r r rrNrOr r r rrMs rMc@seZdZeddZdS) StringShapecCs|jdgS)Nr)r8r))rr r rrszStringShape.enumN)r r r rrr r r rrPsrPc@seZdZdZd.ddZd/ddZddZed d Zd d Z ed dZ eddZ e ddZ eddZeddZeddZeddZeddZeddZedd Zed!d"Zed#d$Zed%d&Zd'd(Zed)d*Zejd+d*Zd,d-ZdS)0 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. r8shapesN) _service_descriptionr)r8 ShapeResolverr,NOT_SET_signature_version _service_nameZ_instance_cache)rZservice_description service_namer r rr1szServiceModel.__init__cCs|j||S)N)r,get_shape_by_name)rr. member_traitsr r r shape_forszServiceModel.shape_forcCs|j|dS)N)_error_code_cacher))rrIr r rshape_for_error_codesz!ServiceModel.shape_for_error_codecCs&i}x|jD]}|j}|||<q W|S)N) error_shapesrI)rZerror_code_cache error_shaperHr r rr\s   zServiceModel._error_code_cachecCs |j|S)N)r,r:)rr;r r rr:&szServiceModel.resolve_shape_refcCst|jdiS)NrR)listrSr))rr r r shape_names)szServiceModel.shape_namescCs:g}x0|jD]&}||}|jddr ||q W|S)Nr!F)rar[r8r)append)rr^r.r_r r rr^-s   zServiceModel.error_shapescCs<y|jd|}Wntk r.t|YnXt|||S)N operations)rSKeyErrorrOperationModel)rZoperation_namer4r r roperation_model6s zServiceModel.operation_modelcCs|jddS)Nr%r&)rSr))rr r rr%>szServiceModel.documentationcCst|jdgS)Nrc)r`rSr))rr r roperation_namesBszServiceModel.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)rWendpoint_prefix)rr r rrXFs zServiceModel.service_namecCs4yt|dStk r.t|jdYnXdS)NZ serviceId)rX)r_get_metadata_propertyrrrW)rr r r service_idWs zServiceModel.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)r8r)rh)r signing_namer r rrk`s zServiceModel.signing_namecCs |dS)NZ apiVersion)ri)rr r r api_versionlszServiceModel.api_versioncCs |dS)Nprotocol)ri)rr r rrmpszServiceModel.protocolcCs |dS)NZendpointPrefix)ri)rr r rrhtszServiceModel.endpoint_prefixcCs(x"|jD]}||}|jr|SqWdS)N)rgrfis_endpoint_discovery_operation)r operationr4r r rendpoint_discovery_operationxs  z)ServiceModel.endpoint_discovery_operationcCs8x2|jD](}||}|jdk r|jdrdSqWdS)NrTF)rgrfendpoint_discoveryr))rror4r r rendpoint_discovery_requireds     z(ServiceModel.endpoint_discovery_requiredcCs4y |j|Stk r.td||fYnXdS)Nz1"%s" not defined in the metadata of the model: %s)r8rdr)rr'r r rris  z#ServiceModel._get_metadata_propertycCs"|jtkr|jd}||_|jS)NZsignatureVersion)rVrUr8r))rsignature_versionr r rrss  zServiceModel.signature_versioncCs ||_dS)N)rV)rrOr r rrsscCsd|jj|jfS)Nz%s(%s))r=r rX)rr r rr>szServiceModel.__repr__)N)N)r r r r@r1r[r]rr\r:rar^rrfr%rgrXrjrkrlrmrhrprrrirBrssetterr>r r r rrQs.              rQc@s&eZdZd6ddZeddZeddZedd Zed d Z ed d Z eddZ eddZ eddZ eddZeddZeddZeddZeddZeddZed d!Zed"d#Zd$d%Zd&d'Zd(d)Zed*d+Zed,d-Zd.d/Zd0d1Zd2d3Zd4d5ZdS)7reNcCs8||_||_||_|d|_|j|_|di|_dS)a :type operation_model: dict :param operation_model: The operation model. This comes from the service model, and is the value associated with the operation name in the service model (i.e ``model['operations'][op_name]``). :type service_model: botocore.model.ServiceModel :param service_model: The service model associated with the operation. :type name: string :param name: The operation name. This is the operation name exposed to the users of this model. This can potentially be different from the "wire_name", which is the operation name that *must* by provided over the wire. For example, given:: "CreateCloudFrontOriginAccessIdentity":{ "name":"CreateCloudFrontOriginAccessIdentity2014_11_06", ... } The ``name`` would be ``CreateCloudFrontOriginAccessIdentity``, but the ``self.wire_name`` would be ``CreateCloudFrontOriginAccessIdentity2014_11_06``, which is the value we must send in the corresponding HTTP request. r'httpN)_operation_model_service_model _api_namer)Z _wire_namer8ru)rrf service_modelr'r r rr1s  zOperationModel.__init__cCs|jdk r|jS|jSdS)N)rx wire_name)rr r rr's zOperationModel.namecCs |jdS)aRThe wire name of the operation. In many situations this is the same value as the ``name``, value, but in some services, the operation name exposed to the user is different from the operaiton name we send across the wire (e.g cloudfront). Any serialization code should use ``wire_name``. r')rvr))rr r rrzs zOperationModel.wire_namecCs|jS)N)rw)rr r rryszOperationModel.service_modelcCs|jddS)Nr%r&)rvr))rr r rr%szOperationModel.documentationcCs|jddS)N deprecatedF)rvr))rr r rr{szOperationModel.deprecatedcCs|jddS)NZendpointdiscovery)rvr))rr r rrqsz!OperationModel.endpoint_discoverycCs|jddS)NZendpointoperationF)rvr))rr r rrnsz.OperationModel.is_endpoint_discovery_operationcCs d|jkrdS|j|jdS)Ninput)rvrwr:)rr r r input_shapes zOperationModel.input_shapecCs d|jkrdS|j|jdS)Noutput)rvrwr:)rr r r output_shapes zOperationModel.output_shapecCs"|j}|sgSdd|jDS)NcSs(g|] \}}d|jkr|jdr|qS)r)r8).0r'shaper r r s z5OperationModel.idempotent_members..)r}rDrE)rr}r r ridempotent_memberssz!OperationModel.idempotent_memberscCs |jdS)NZauthtype)rvr))rr r r auth_typeszOperationModel.auth_typecs$jdg}tfdd|DS)Nerrorsc3s|]}j|VqdS)N)rwr:)rs)rr r sz.OperationModel.error_shapes..)rvr)r`)rrRr )rrr^szOperationModel.error_shapescCs |jdS)Nendpoint)rvr))rr r rrszOperationModel.endpointcCs|jddS)NZhttpChecksumRequiredF)rvr))rr r rhttp_checksum_requiredsz%OperationModel.http_checksum_requiredcCs |dk S)N)get_event_stream_input)rr r rhas_event_stream_input"sz%OperationModel.has_event_stream_inputcCs |dk S)N)get_event_stream_output)rr r rhas_event_stream_output&sz&OperationModel.has_event_stream_outputcCs ||jS)N)_get_event_streamr})rr r rr*sz%OperationModel.get_event_stream_inputcCs ||jS)N)rr)rr r rr-sz&OperationModel.get_event_stream_outputcCs$|dkr dS|j}|r |j|SdS)zAReturns the event stream member's shape if any or None otherwise.N)r?rD)rrZ event_namer r rr0s  z OperationModel._get_event_streamcCs |dk S)N)get_streaming_input)rr r rhas_streaming_input9sz"OperationModel.has_streaming_inputcCs |dk S)N)get_streaming_output)rr r rhas_streaming_output=sz#OperationModel.has_streaming_outputcCs ||jS)N)_get_streaming_bodyr})rr r rrAsz"OperationModel.get_streaming_inputcCs ||jS)N)rr)rr r rrDsz#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)r5r)rDr()rrrZ payload_shaper r rrGs   z"OperationModel._get_streaming_bodycCsd|jj|jfS)Nz %s(name=%s))r=r r')rr r rr>RszOperationModel.__repr__)N)r r r r1rr'rBrzryr%r{rqrnr}rrrr^rrrrrrrrrrrrr>r r r rres4 %                rec@s8eZdZdZeeeedZddZ d ddZ dd Z dS) rTzResolves shape references.) structurer`mapstringcCs||_i|_dS)N) _shape_mapZ _shape_cache)r shape_mapr r rr1aszShapeResolver.__init__NcCsy|j|}Wntk r*t|YnXy|j|dt}Wn tk rbtd|YnX|rz|}||||||}|S)Nr$z(Shape is missing required key 'type': %s) rrdr SHAPE_CLASSESr)rrcopyupdate)rr.rZr/Z shape_clsresultr r rrYes  zShapeResolver.get_shape_by_namecCsjt|dkr"d|kr"||dS|}y|d}Wn tk rXtd|YnX|||SdS)Nrz*Invalid model, missing shape reference: %s)lenrYrr3rdr)rr;rZr.r r rr:uszShapeResolver.resolve_shape_ref)N) r r r r@rCrLrMrPrr1rYr:r r r rrTVs rTc@s"eZdZdZdddZddZdS)r+zJA ShapeResolver that will throw ValueErrors when shapes are resolved. NcCs tddS)Nz>Attempted to lookup shape '%s', but no shape map was provided.) ValueError)rr.rZr r rrYsz&UnresolvableShapeMap.get_shape_by_namecCs tddS)Nz?Attempted to resolve shape '%s', but no shape map was provided.)r)rr;r r rr:sz&UnresolvableShapeMap.resolve_shape_ref)N)r r r r@rYr:r r r rr+s r+c@sbeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dS)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. NcCs*t|_t|_|dkr&|jd|_dS)Nr)rrDShapeNameGenerator_name_generatornew_shape_namer')rr'r r rr1sz%DenormalizedStructureBuilder.__init__cCs ||_|S)zp :type members: dict :param members: The denormalized members. :return: self )_members)rrDr r r with_memberss 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$rD)r)r.r/r0)rr _build_modelr'rTrC)rrRZ denormalizedresolverr r r build_models  z(DenormalizedStructureBuilder.build_modelcCs|ddkr|||||<nh|ddkr<|||||<nJ|ddkrZ|||||<n,|ddkrv||||<ntd|ddS)Nr$rr`r) rintegerbooleanrfloat timestamplongdoublecharzUnknown shape type: %s)_build_structure _build_list _build_map _build_scalarr)rr4rRr.r r rrs    z)DenormalizedStructureBuilder._build_modelcCs`t}||}||d<xB|dtD],\}}||}d|i||<||||q,W|S)NrDr)r_build_initial_shaper)rE_get_shape_namer)rr4rRrDrr'Z member_modelmember_shape_namer r rrs   z-DenormalizedStructureBuilder._build_structurecCs6||}||}d|i|d<||d|||S)NrrG)rrr)rr4rRrrr r rrs    z(DenormalizedStructureBuilder._build_listcCsf||d}||d}||}d|i|d<d|i|d<||d||||d|||S)NrNrOr)rrr)rr4rRZkey_shape_nameZvalue_shape_namerr r rrs   z'DenormalizedStructureBuilder._build_mapcCsHd|di}d|kr |d|d<x"tjD]}||kr(||||<q(W|S)Nr$r%)rr7)rr4rr6r r rrs   z1DenormalizedStructureBuilder._build_initial_shapecCs ||S)N)r)rr4r r rrsz*DenormalizedStructureBuilder._build_scalarcCs$d|kr|dS|j|dSdS)Nr.r$)rr)rr4r r rrsz,DenormalizedStructureBuilder._get_shape_name)N)r r r r@r1rrrrrrrrrr r r rrs#      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)rr r rr1#szShapeNameGenerator.__init__cCs,|j|d7<|j|}d||fS)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 rz%sType%s)r capitalize)rr(Z current_indexr r rr&s z!ShapeNameGenerator.new_shape_nameN)r r r r@r1rr r r rrsrN) r@ collectionsrZbotocore.utilsrrrZbotocore.compatrZbotocore.exceptionsrrobjectrU Exceptionr rrrstrrrrCrLrMrPrQrerTr+rrr r r r s4    * 244