B ݁[c@sJdZddlmZddlmZmZmZddlmZe Z Gddde Z Gddde Z Gd d d e ZGd d d e ZGd dde ZGdddeZGddde 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) OrderedDictc@s eZdZdS)NoShapeFoundErrorN)__name__ __module__ __qualname__r r O/Users/kashii/Desktop/Projects/Workshops/worker-safety/lambda/botocore/model.pyrsrc@s eZdZdS)InvalidShapeErrorN)rr r r r r r r sr c@s eZdZdS)OperationNotFoundErrorN)rr r r r r r rsrc@s eZdZdS)InvalidShapeReferenceErrorN)rr r r r r r r#src@s eZdZdS)UndefinedModelAttributeErrorN)rr r r r r r r'src@seZdZddZdS) ServiceIdcCst|S)N)r)selfr r r hyphenize,szServiceId.hyphenizeN)rr r rr r r r r+src@seZdZdZdddddddd d d d d ddddgZddddddddgZeZd&ddZe ddZ e ddZ e d d!Z d"d#Z d$d%ZdS)'Shapez3Object representing a shape from the service model. locationNameZ queryNameZ flattenedlocationpayloadZ streamingZtimestampFormatZ xmlNamespaceZ resultWrapperZ xmlAttribute eventstreameventZ eventheaderZ eventpayload jsonvaluerequiredminmaxZ sensitiveenumidempotencyTokenerror exceptionNcCsB||_|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 r r3as  zShape.serializationcCs4|j}i}x$|jD]}||jkr||||<qW|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)rr2metadatar4r r r r6s   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)r6r')rr r r required_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__rr%)rr r r __repr__szShape.__repr__)N)rr r __doc__r0r5rMAP_TYPEr/rr3r6r7r:r<r r r r r0s   " !  rc@seZdZeddZdS)StructureShapecCs:|jd}|}x"|D]\}}||||<qW|S)Nmembers)r(r>itemsr:)rr@Z shape_membersr%r9r r r r@s  zStructureShape.membersN)rr r rr@r r r r r?sr?c@seZdZeddZdS) ListShapecCs||jdS)Nmember)r:r()rr r r rCszListShape.memberN)rr r rrCr r r r rBsrBc@s$eZdZeddZeddZdS)MapShapecCs||jdS)Nkey)r:r()rr r r rEsz MapShape.keycCs||jdS)Nvalue)r:r()rr r r rFszMapShape.valueN)rr r rrErFr r r r rDs rDc@seZdZeddZdS) StringShapecCs|jdgS)Nr)r6r')rr r r rszStringShape.enumN)rr r rrr r r r rGsrGc@seZdZdZd$ddZd%ddZddZed d Ze d d Z ed dZ eddZ eddZ eddZeddZeddZeddZeddZddZedd 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. r6shapesN) _service_descriptionr'r6 ShapeResolverr*NOT_SET_signature_version _service_name_instance_cache)rservice_description service_namer r r r/szServiceModel.__init__cCs|j||S)N)r*get_shape_by_name)rr, member_traitsr r r shape_forszServiceModel.shape_forcCs |j|S)N)r*r8)rr9r r r r8szServiceModel.resolve_shape_refcCst|jdiS)NrI)listrJr')rr r r shape_namesszServiceModel.shape_namescCs<y|jd|}Wntk r.t|YnXt|||S)N operations)rJKeyErrorrOperationModel)roperation_namer2r r r operation_models zServiceModel.operation_modelcCs|jddS)Nr#r$)rJr')rr r r r# szServiceModel.documentationcCst|jdgS)NrW)rUrJr')rr r r operation_namesszServiceModel.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)rNendpoint_prefix)rr r r rQs zServiceModel.service_namecCst|dS)NZ serviceId)r_get_metadata_property)rr r r service_id$szServiceModel.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. signingNameN)r6r'r])r signing_namer r r ra(s zServiceModel.signing_namecCs |dS)NZ apiVersion)r^)rr r r api_version4szServiceModel.api_versioncCs |dS)Nprotocol)r^)rr r r rc8szServiceModel.protocolcCs |dS)NendpointPrefix)r^)rr r r r]<szServiceModel.endpoint_prefixcCs4y |j|Stk r.td||fYnXdS)Nz1"%s" not defined in the metadata of the model: %s)r6rXr)rr%r r r r^@s  z#ServiceModel._get_metadata_propertycCs"|jtkr|jd}||_|jS)NZsignatureVersion)rMrLr6r')rsignature_versionr r r reKs  zServiceModel.signature_versioncCs ||_dS)N)rM)rrFr r r reRscCsd|jj|jfS)Nz%s(%s))r;rrQ)rr r r r<VszServiceModel.__repr__)N)N)rr r r=r/rTr8rrVrr[r#r\rQr_rarbrcr]r^propertyresetterr<r r r r rHs$            rHc@seZdZd.ddZeddZeddZedd Zed d Z ed d Z eddZ eddZ eddZ eddZeddZeddZeddZddZddZd d!Zed"d#Zed$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS)/rYNcCs8||_||_||_|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_namer6rh)rr[ service_modelr%r r r r/\s  zOperationModel.__init__cCs|jdk r|jS|jSdS)N)rk wire_name)rr r r r%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%)rir')rr r r rms zOperationModel.wire_namecCs|jS)N)rj)rr r r rlszOperationModel.service_modelcCs|jddS)Nr#r$)rir')rr r r r#szOperationModel.documentationcCs|jddS)N deprecatedF)rir')rr r r rnszOperationModel.deprecatedcCs d|jkrdS|j|jdS)Ninput)rirjr8)rr r r input_shapes zOperationModel.input_shapecCs d|jkrdS|j|jdS)Noutput)rirjr8)rr r r output_shapes zOperationModel.output_shapecCs"|j}|sgSdd|jDS)NcSs(g|] \}}d|jkr|jdr|qS)r)r6).0r%shaper r r s z5OperationModel.idempotent_members..)rpr@rA)rrpr r r idempotent_memberssz!OperationModel.idempotent_memberscCs |jdS)NZauthtype)rir')rr r r auth_typeszOperationModel.auth_typecs$jdg}tfdd|DS)Nerrorsc3s|]}j|VqdS)N)rjr8)rss)rr r sz.OperationModel.error_shapes..)rir'rU)rrIr )rr error_shapesszOperationModel.error_shapescCs |dk S)N)get_event_stream_input)rr r r has_event_stream_inputsz%OperationModel.has_event_stream_inputcCs |dk S)N)get_event_stream_output)rr r r has_event_stream_outputsz&OperationModel.has_event_stream_outputcCs ||jS)N)_get_event_streamrp)rr r r r|sz%OperationModel.get_event_stream_inputcCs ||jS)N)rrr)rr r r r~sz&OperationModel.get_event_stream_outputcCs4|dkr dSx"|jD]}|jdr|SqWdS)zAReturns the event stream member's shape if any or None otherwise.Nr)r@valuesr3r')rrtrCr r r rs  z OperationModel._get_event_streamcCs |dk S)N)get_streaming_input)rr r r has_streaming_inputsz"OperationModel.has_streaming_inputcCs |dk S)N)get_streaming_output)rr r r has_streaming_outputsz#OperationModel.has_streaming_outputcCs ||jS)N)_get_streaming_bodyrp)rr r r rsz"OperationModel.get_streaming_inputcCs ||jS)N)rrr)rr r r rsz#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)r3r'r@r&)rrtrZ payload_shaper r r rs   z"OperationModel._get_streaming_bodycCsd|jj|jfS)Nz %s(name=%s))r;rr%)rr r r r<szOperationModel.__repr__)N)rr r r/rr%rfrmrlr#rnrprrrvrwr{r}rr|r~rrrrrrr<r r r r rY[s, %            rYc@s8eZdZdZeeeedZddZ d ddZ dd Z dS) rKzResolves shape references.) structurerUmapstringcCs||_i|_dS)N) _shape_mapZ _shape_cache)r shape_mapr r r r/szShapeResolver.__init__NcCsy|j|}Wntk r*t|YnXy|j|dt}Wn tk rbtd|YnX|rz|}||||||}|S)Nr"z(Shape is missing required key 'type': %s) rrXr SHAPE_CLASSESr'rr copyupdate)rr,rSr-Z shape_clsresultr r r rR s  zShapeResolver.get_shape_by_namecCsjt|dkr"d|kr"||dS|}y|d}Wn tk rXtd|YnX|||SdS)Nrtz*Invalid model, missing shape reference: %s)lenrRrr1rXr)rr9rSr,r r r r8szShapeResolver.resolve_shape_ref)N) rr r r=r?rBrDrGrr/rRr8r r r r rKs rKc@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,rSr r r rR3sz&UnresolvableShapeMap.get_shape_by_namecCs tddS)Nz?Attempted to resolve shape '%s', but no shape map was provided.)r)rr9r r r r87sz&UnresolvableShapeMap.resolve_shape_ref)N)rr r r=rRr8r r r r r)0s 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)rr@ShapeNameGenerator_name_generatornew_shape_namer%)rr%r r r r/`sz%DenormalizedStructureBuilder.__init__cCs ||_|S)zp :type members: dict :param members: The denormalized members. :return: self )_members)rr@r r r with_membersfs 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"r@)r)r,r-r.)rr _build_modelr%rKr?)rrIZ denormalizedresolverr r r build_modelrs  z(DenormalizedStructureBuilder.build_modelcCs|ddkr|||||<nh|ddkr<|||||<nJ|ddkrZ|||||<n,|ddkrv||||<ntd|ddS)Nr"rrUr) rintegerbooleanrfloat timestamplongdoublecharzUnknown shape type: %s)_build_structure _build_list _build_map _build_scalarr )rr2rIr,r r r rs    z)DenormalizedStructureBuilder._build_modelcCsZt}||}||d<x<|dD],\}}||}d|i||<||||q&W|S)Nr@rt)r_build_initial_shaperA_get_shape_namer)rr2rIr@rtr%Z member_modelmember_shape_namer r r rs   z-DenormalizedStructureBuilder._build_structurecCs6||}||}d|i|d<||d|||S)NrtrC)rrr)rr2rIrrtr r r rs    z(DenormalizedStructureBuilder._build_listcCsf||d}||d}||}d|i|d<d|i|d<||d||||d|||S)NrErFrt)rrr)rr2rIZkey_shape_nameZvalue_shape_namertr r r rs   z'DenormalizedStructureBuilder._build_mapcCs8d|di}d|kr |d|d<d|kr4|d|d<|S)Nr"r#rr )rr2rtr r r rs    z1DenormalizedStructureBuilder._build_initial_shapecCs ||S)N)r)rr2r r r rsz*DenormalizedStructureBuilder._build_scalarcCs$d|kr|dS|j|dSdS)Nr,r")rr)rr2r r r rsz,DenormalizedStructureBuilder._get_shape_name)N)rr r r=r/rrrrrrrrrr r r r r<s#      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 r r/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 r rs z!ShapeNameGenerator.new_shape_nameN)rr r r=r/rr r r r rsrN)r= collectionsrbotocore.utilsrrrbotocore.compatrobjectrL Exceptionrr rrrstrrrr?rBrDrGrHrYrKr)rrr r r r  s0  }  "4