U 3_tm@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__rri/private/var/folders/2d/2jcwkxfx4hj39rq32sgz27wh9m_5lk/T/pip-target-wqqlibfd/lib/python/botocore/model.pyr sr c@s eZdZdS)InvalidShapeErrorNr rrrrrsrc@s eZdZdS)OperationNotFoundErrorNr rrrrr src@s eZdZdS)InvalidShapeReferenceErrorNr rrrrr$src@seZdZddZdS) ServiceIdcCst|SN)rselfrrr hyphenize)szServiceId.hyphenizeN)r r r rrrrrr(src@seZdZdZdddddddd d d d d dddddgZddddddddddg ZeZd+ddZe dd 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 retryableNcCsB||_|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__cCsF|j}i}|jD]}||jkr||||<qd|krB|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 serializationattrrrrr6_s  zShape.serializationcCs0|j}i}|jD]}||jkr||||<q|S)a2Metadata about the shape. This requires optional information about the shape, including: * min * max * enum * sensitive * required * idempotencyToken :rtype: dict :return: Metadata about the shape. )r+METADATA_ATTRS)rr5metadatar7rrrr9s   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. rr9r*rrrrrequired_memberss zShape.required_memberscCs |j|Srr-resolve_shape_refr shape_refrrr_resolve_shape_refszShape._resolve_shape_refcCsd|jj|jfS)Nz<%s(%s)> __class__r r(rrrr__repr__szShape.__repr__cCsdSrrrrrrevent_stream_nameszShape.event_stream_name)N)r r r __doc__r3r8rMAP_TYPEr2rr6r9r;r@rCpropertyrDrrrrr-sF  "   rc@s0eZdZeddZeddZeddZdS)StructureShapecCs6|jd}|}|D]\}}||||<q|S)Nmembers)r+rFitemsr@)rrIZ shape_membersr(r?rrrrIs  zStructureShape.memberscCs,|jD]\}}|jdr |Sq dS)Nr)rIrJr6r*)r member_namememberrrrrDs  z StructureShape.event_stream_namecCs8|jddsdS|jdi}|d}|r2|S|jS)Nr$Fr#code)r9r*r()rZerror_metadatarMrrr error_codes zStructureShape.error_codeN)r r r rrIrDrNrrrrrHs   rHc@seZdZeddZdS) ListShapecCs||jdS)NrLr@r+rrrrrLszListShape.memberN)r r r rrLrrrrrOsrOc@s$eZdZeddZeddZdS)MapShapecCs||jdS)NkeyrPrrrrrRsz MapShape.keycCs||jdS)NvaluerPrrrrrSszMapShape.valueN)r r r rrRrSrrrrrQs rQc@seZdZeddZdS) StringShapecCs|jdgS)Nr!r:rrrrr!szStringShape.enumN)r r r rr!rrrrrTsrTc@seZdZdZd,ddZd-ddZddZed d Zd d Z ed dZ eddZ e ddZ eddZeddZeddZeddZeddZeddZedd Zed!d"Zed#d$Zd%d&Zed'd(Zejd)d(Zd*d+ZdS). 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. r9shapesN) _service_descriptionr*r9 ShapeResolverr-NOT_SET_signature_version _service_nameZ_instance_cache)rZservice_description service_namerrrr2s zServiceModel.__init__cCs|j||Sr)r-get_shape_by_namerr/ member_traitsrrr shape_for szServiceModel.shape_forcCs|j|dSr)_error_code_cacher*)rrNrrrshape_for_error_codesz!ServiceModel.shape_for_error_codecCs"i}|jD]}|j}|||<q |Sr) error_shapesrN)rZerror_code_cache error_shaperMrrrras   zServiceModel._error_code_cachecCs |j|Srr<r>rrrr=szServiceModel.resolve_shape_refcCst|jdiS)NrVlistrWr*rrrr shape_namesszServiceModel.shape_namescCs6g}|jD]&}||}|jddr ||q |S)Nr$F)rgr`r9r*append)rrcr/rdrrrrc"s    zServiceModel.error_shapescCs<z|jd|}Wntk r.t|YnXt|||SN operations)rWKeyErrorrOperationModel)rZoperation_namer5rrroperation_model+s zServiceModel.operation_modelcCs|jddSNr&r')rWr*rrrrr&3szServiceModel.documentationcCst|jdgSrirerrrroperation_names7szServiceModel.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)r[endpoint_prefixrrrrr\;s zServiceModel.service_namecCs6zt|dWStk r0t|jdYnXdS)NZ serviceId)r\)r_get_metadata_propertyrrr[rrrr service_idLs 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)r9r*rp)r signing_namerrrrsUs zServiceModel.signing_namecCs |dS)NZ apiVersionrqrrrr api_versionaszServiceModel.api_versioncCs |dS)NprotocolrtrrrrrveszServiceModel.protocolcCs |dS)NZendpointPrefixrtrrrrrpiszServiceModel.endpoint_prefixcCs(|jD]}||}|jr|SqdSr)rormis_endpoint_discovery_operation)rZ operationr5rrrendpoint_discovery_operationms  z)ServiceModel.endpoint_discovery_operationcCs6z |j|WStk r0td||fYnXdS)Nz1"%s" not defined in the metadata of the model: %s)r9rkrrr(rrrrqts z#ServiceModel._get_metadata_propertycCs"|jtkr|jd}||_|jS)NZsignatureVersion)rZrYr9r*)rsignature_versionrrrrzs  zServiceModel.signature_versioncCs ||_dSr)rZ)rrSrrrrzscCsd|jj|jfS)Nz%s(%s))rBr r\rrrrrCszServiceModel.__repr__)N)N)r r r rEr2r`rbrrar=rgrcrrmr&ror\rrrsrurvrprxrqrGrzsetterrCrrrrrUsJ                  rUc@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)7rlNcCs8||_||_||_|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_namer9r|)rrm service_modelr(rrrr2s  zOperationModel.__init__cCs|jdk r|jS|jSdSr)r wire_namerrrrr(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(r}r*rrrrrs zOperationModel.wire_namecCs|jSr)r~rrrrrszOperationModel.service_modelcCs|jddSrnrrrrrr&szOperationModel.documentationcCs|jddS)N deprecatedFrrrrrrszOperationModel.deprecatedcCs|jddS)NZendpointdiscoveryrrrrrendpoint_discoverysz!OperationModel.endpoint_discoverycCs|jddS)NZendpointoperationFrrrrrrwsz.OperationModel.is_endpoint_discovery_operationcCs d|jkrdS|j|jdS)Ninputr}r~r=rrrr input_shapes  zOperationModel.input_shapecCs d|jkrdS|j|jdS)Noutputrrrrr output_shapes  zOperationModel.output_shapecCs"|j}|sgSdd|jDS)NcSs(g|] \}}d|jkr|jdr|qS)r")r9).0r(shaperrr s  z5OperationModel.idempotent_members..)rrIrJ)rrrrridempotent_memberssz!OperationModel.idempotent_memberscCs |jdS)NZauthtyperrrrr auth_typeszOperationModel.auth_typecs$jdg}tfdd|DS)Nerrorsc3s|]}j|VqdSr)r~r=)rsrrr sz.OperationModel.error_shapes..)r}r*rf)rrVrrrrcszOperationModel.error_shapescCs |jdS)NendpointrrrrrrszOperationModel.endpointcCs|jddS)NZhttpChecksumRequiredFrrrrrhttp_checksum_required sz%OperationModel.http_checksum_requiredcCs |dk Sr)get_event_stream_inputrrrrhas_event_stream_inputsz%OperationModel.has_event_stream_inputcCs |dk Sr)get_event_stream_outputrrrrhas_event_stream_outputsz&OperationModel.has_event_stream_outputcCs ||jSr)_get_event_streamrrrrrrsz%OperationModel.get_event_stream_inputcCs ||jSr)rrrrrrrsz&OperationModel.get_event_stream_outputcCs$|dkr dS|j}|r |j|SdS)zAReturns the event stream member's shape if any or None otherwise.N)rDrI)rrZ event_namerrrrs  z OperationModel._get_event_streamcCs |dk Sr)get_streaming_inputrrrrhas_streaming_input%sz"OperationModel.has_streaming_inputcCs |dk Sr)get_streaming_outputrrrrhas_streaming_output)sz#OperationModel.has_streaming_outputcCs ||jSr)_get_streaming_bodyrrrrrr-sz"OperationModel.get_streaming_inputcCs ||jSr)rrrrrrr0sz#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)r6r*rIr))rrrZ payload_shaperrrr3s   z"OperationModel._get_streaming_bodycCsd|jj|jfS)Nz %s(name=%s)rArrrrrC>szOperationModel.__repr__)N)r r r r2rr(rGrrr&rrrwrrrrrcrrrrrrrrrrrrrCrrrrrlsX %                    rlc@s8eZdZdZeeeedZddZ d ddZ dd Z dS) rXzResolves shape references.) structurerfmapstringcCs||_i|_dSr) _shape_mapZ _shape_cache)r shape_maprrrr2MszShapeResolver.__init__NcCsz|j|}Wntk r*t|YnXz|j|dt}Wn tk rbtd|YnX|rz|}||||||}|S)Nr%z(Shape is missing required key 'type': %s) rrkr SHAPE_CLASSESr*rrcopyupdate)rr/r_r0Z shape_clsresultrrrr]Qs   zShapeResolver.get_shape_by_namecCsjt|dkr"d|kr"||dS|}z|d}Wn tk rXtd|YnX|||SdS)Nrz*Invalid model, missing shape reference: %s)lenr]rr4rkr)rr?r_r/rrrr=as zShapeResolver.resolve_shape_ref)N) r r r rErHrOrQrTrr2r]r=rrrrrXBs rXc@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. ValueErrorr^rrrr]ysz&UnresolvableShapeMap.get_shape_by_namecCs tddS)Nz?Attempted to resolve shape '%s', but no shape map was provided.rr>rrrr=}sz&UnresolvableShapeMap.resolve_shape_ref)N)r r r rEr]r=rrrrr,vs 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)rrIShapeNameGenerator_name_generatornew_shape_namer(ryrrrr2sz%DenormalizedStructureBuilder.__init__cCs ||_|S)zp :type members: dict :param members: The denormalized members. :return: self )_members)rrIrrr 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%rI)r)r/r0r1)rr _build_modelr(rXrH)rrVZ denormalizedresolverrrr build_models z(DenormalizedStructureBuilder.build_modelcCs|ddkr|||||<nh|ddkr<|||||<nJ|ddkrZ|||||<n,|ddkrv||||<ntd|ddS)Nr%rrfr) rintegerbooleanrfloat timestamplongdoublecharzUnknown shape type: %s)_build_structure _build_list _build_map _build_scalarr)rr5rVr/rrrrs    z)DenormalizedStructureBuilder._build_modelcCsVt}||}||d<|dD],\}}||}d|i||<||||q$|S)NrIr)r_build_initial_shaperJ_get_shape_namer)rr5rVrIrr(Z member_modelmember_shape_namerrrrs   z-DenormalizedStructureBuilder._build_structurecCs6||}||}d|i|d<||d|||S)NrrLrrr)rr5rVrrrrrrs    z(DenormalizedStructureBuilder._build_listcCsf||d}||d}||}d|i|d<d|i|d<||d||||d|||S)NrRrSrr)rr5rVZkey_shape_nameZvalue_shape_namerrrrrs   z'DenormalizedStructureBuilder._build_mapcCsDd|di}d|kr |d|d<tjD]}||kr&||||<q&|S)Nr%r&)rr8)rr5rr7rrrrs  z1DenormalizedStructureBuilder._build_initial_shapecCs ||Sr)rrr5rrrrsz*DenormalizedStructureBuilder._build_scalarcCs$d|kr|dS|j|dSdS)Nr/r%)rrrrrrrsz,DenormalizedStructureBuilder._get_shape_name)N)r r r rEr2rrrrrrrrrrrrrrs#      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_cacherrrrr2szShapeNameGenerator.__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_indexrrrrs  z!ShapeNameGenerator.new_shape_nameN)r r r rEr2rrrrrrsrN) rE collectionsrZbotocore.utilsrrrZbotocore.compatrZbotocore.exceptionsrrobjectrY Exceptionr rrrstrrrrHrOrQrTrUrlrXr,rrrrrr s4    " )44