U
    EZhz                     @   s  d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZ e ZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZG dd dZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ G d d! d!eZ!G d"d# d#Z"G d$d% d%Z#G d&d' d'Z$G d(d) d)Z%G d*d+ d+Z&G d,d- d-Z'd.S )/z-Abstractions to interact with service models.    )defaultdict)
NamedTupleUnion)resolve_auth_type)OrderedDict)MissingServiceIdErrorUndefinedModelAttributeError)CachedPropertyhyphenize_service_idinstance_cachec                   @   s   e Zd ZdS )NoShapeFoundErrorN__name__
__module____qualname__ r   r   U/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/botocore/model.pyr      s   r   c                   @   s   e Zd ZdS )InvalidShapeErrorNr   r   r   r   r   r   !   s   r   c                   @   s   e Zd ZdS )OperationNotFoundErrorNr   r   r   r   r   r   %   s   r   c                   @   s   e Zd ZdS )InvalidShapeReferenceErrorNr   r   r   r   r   r   )   s   r   c                   @   s   e Zd Zdd ZdS )	ServiceIdc                 C   s   t | S N)r
   selfr   r   r   	hyphenize.   s    zServiceId.hyphenizeN)r   r   r   r   r   r   r   r   r   -   s   r   c                   @   s   e Zd ZdZdddddddd	d
ddddddddgZddddddddddddddd d!gZeZd1d#d$Ze	d%d& Z
e	d'd( Ze	d)d* Zd+d, Zd-d. Zed/d0 Zd"S )2Shapez3Object representing a shape from the service model.locationNameZ	queryNameZ	flattenedlocationpayloadZ	streamingZtimestampFormatZxmlNamespaceZresultWrapperZxmlAttributeeventstreameventZeventheaderZeventpayloadZ	jsonvalueZ	hostLabelrequiredminmaxpatternZ	sensitiveenumidempotencyTokenerror	exceptionZendpointdiscoveryidZ	retryabledocumentunioncontextParamclientContextParamsZrequiresLengthNc                 C   sB   || _ |d | _|dd| _|| _|dkr2t }|| _i | _dS )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documentation N)name	type_namegetr.   _shape_modelUnresolvableShapeMap_shape_resolver_cache)r   
shape_nameshape_modelshape_resolverr   r   r   __init__`   s    
zShape.__init__c                 C   sF   | j }i }| jD ]}|| j kr|| ||< qd|krB|d|d< |S )a  Serialization 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.

        r   r0   )r3   SERIALIZED_ATTRSpop)r   modelserializationattrr   r   r   r>      s    

zShape.serializationc                 C   s0   | j }i }| jD ]}|| j kr|| ||< q|S )a  Metadata about the shape.

        This requires optional information about the shape, including:

            * min
            * max
            * pattern
            * enum
            * sensitive
            * required
            * idempotencyToken
            * document
            * union
            * contextParam
            * clientContextParams
            * requiresLength

        :rtype: dict
        :return: Metadata about the shape.

        )r3   METADATA_ATTRS)r   r=   metadatar?   r   r   r   rA      s    

zShape.metadatac                 C   s   | j dg S )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!   rA   r2   r   r   r   r   required_members   s    	zShape.required_membersc                 C   s   | j |S r   r5   resolve_shape_refr   	shape_refr   r   r   _resolve_shape_ref   s    zShape._resolve_shape_refc                 C   s   d| j j d| j dS )N<(z)>	__class__r   r0   r   r   r   r   __repr__   s    zShape.__repr__c                 C   s   d S r   r   r   r   r   r   event_stream_name   s    zShape.event_stream_name)N)r   r   r   __doc__r;   r@   r   MAP_TYPEr:   r	   r>   rA   rC   rH   rM   propertyrN   r   r   r   r   r   2   s`   
"
 


r   c                   @   sH   e Zd Zedd Zedd Zedd Zedd Zed	d
 ZdS )StructureShapec                 C   s>   | j d|  }|  }| D ]\}}| |||< q"|S )Nmembers)r3   r2   rP   itemsrH   )r   rS   Zshape_membersr0   rG   r   r   r   rS      s
    zStructureShape.membersc                 C   s,   | j  D ]\}}|jdr
|  S q
d S )Nr   )rS   rT   r>   r2   )r   member_namememberr   r   r   rN      s    
z StructureShape.event_stream_namec                 C   s8   | j ddsd S | j di }|d}|r2|S | jS )Nr(   Fr'   code)rA   r2   r0   )r   Zerror_metadatarW   r   r   r   
error_code   s    
zStructureShape.error_codec                 C   s   | j ddS )Nr)   FrB   r   r   r   r   is_document_type   s    zStructureShape.is_document_typec                 C   s   | j ddS )Nr*   FrB   r   r   r   r   is_tagged_union   s    zStructureShape.is_tagged_unionN)	r   r   r   r	   rS   rN   rX   rY   rZ   r   r   r   r   rR      s   




rR   c                   @   s   e Zd Zedd ZdS )	ListShapec                 C   s   |  | jd S )NrV   rH   r3   r   r   r   r   rV     s    zListShape.memberN)r   r   r   r	   rV   r   r   r   r   r[     s   r[   c                   @   s$   e Zd Zedd Zedd ZdS )MapShapec                 C   s   |  | jd S )Nkeyr\   r   r   r   r   r^     s    zMapShape.keyc                 C   s   |  | jd S )Nvaluer\   r   r   r   r   r_     s    zMapShape.valueN)r   r   r   r	   r^   r_   r   r   r   r   r]     s   
r]   c                   @   s   e Zd Zedd ZdS )StringShapec                 C   s   | j dg S )Nr%   rB   r   r   r   r   r%     s    zStringShape.enumN)r   r   r   r	   r%   r   r   r   r   r`     s   r`   c                   @   s&   e Zd ZU eed< eeef ed< dS )StaticContextParameterr0   r_   N)r   r   r   str__annotations__r   boolr   r   r   r   ra     s   
ra   c                   @   s   e Zd ZU eed< eed< dS )ContextParameterr0   rU   Nr   r   r   rb   rc   r   r   r   r   re     s   
re   c                   @   s&   e Zd ZU eed< eed< eed< dS )ClientContextParameterr0   r-   r.   Nrf   r   r   r   r   rg   !  s   
rg   c                   @   s*  e Zd ZdZd4ddZd5ddZdd Zed	d
 Zdd Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zd+d, Zed-d. Zejd/d. Zed0d1 Zd2d3 ZdS )6ServiceModelzQ

    :ivar service_description: The parsed service description dictionary.

    Nc                 C   s<   || _ |di | _t|di | _t| _|| _i | _dS )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.

        rA   shapesN)	_service_descriptionr2   rA   ShapeResolverr5   NOT_SET_signature_version_service_nameZ_instance_cache)r   Zservice_descriptionservice_namer   r   r   r:   .  s    
zServiceModel.__init__c                 C   s   | j ||S r   )r5   get_shape_by_namer   r7   member_traitsr   r   r   	shape_forM  s     zServiceModel.shape_forc                 C   s   | j |d S r   )_error_code_cacher2   )r   rX   r   r   r   shape_for_error_codeR  s    z!ServiceModel.shape_for_error_codec                 C   s"   i }| j D ]}|j}|||< q
|S r   )error_shapesrX   )r   Zerror_code_cacheerror_shaperW   r   r   r   rt   U  s
    

zServiceModel._error_code_cachec                 C   s   | j |S r   rD   rF   r   r   r   rE   ]  s    zServiceModel.resolve_shape_refc                 C   s   t | jdi S )Nri   listrj   r2   r   r   r   r   shape_names`  s    zServiceModel.shape_namesc                 C   s6   g }| j D ]&}| |}|jddr
|| q
|S )Nr(   F)rz   rs   rA   r2   append)r   rv   r7   rw   r   r   r   rv   d  s    

zServiceModel.error_shapesc                 C   s<   z| j d | }W n tk
r.   t|Y nX t|| |S N
operations)rj   KeyErrorr   OperationModel)r   Zoperation_namer=   r   r   r   operation_modelm  s
    zServiceModel.operation_modelc                 C   s   | j ddS Nr.   r/   )rj   r2   r   r   r   r   r.   u  s    zServiceModel.documentationc                 C   s   t | jdg S r|   rx   r   r   r   r   operation_namesy  s    zServiceModel.operation_namesc                 C   s   | j dk	r| j S | jS dS )a  The 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)rn   endpoint_prefixr   r   r   r   ro   }  s    
zServiceModel.service_namec                 C   s6   zt | dW S  tk
r0   t| jdY nX d S )NZ	serviceId)ro   )r   _get_metadata_propertyr   r   rn   r   r   r   r   
service_id  s    zServiceModel.service_idc                 C   s   | j d}|dkr| 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)rA   r2   r   )r   signing_namer   r   r   r     s    zServiceModel.signing_namec                 C   s
   |  dS )NZ
apiVersionr   r   r   r   r   api_version  s    zServiceModel.api_versionc                 C   s
   |  dS )Nprotocolr   r   r   r   r   r     s    zServiceModel.protocolc                 C   s
   |  dS )N	protocolsr   r   r   r   r   r     s    zServiceModel.protocolsc                 C   s
   |  dS )NZendpointPrefixr   r   r   r   r   r     s    zServiceModel.endpoint_prefixc                 C   s(   | j D ]}| |}|jr|  S qd S r   )r   r   is_endpoint_discovery_operationr   Z	operationr=   r   r   r   endpoint_discovery_operation  s    

z)ServiceModel.endpoint_discovery_operationc                 C   s6   | j D ]*}| |}|jd k	r|jdr dS qdS )Nr!   TF)r   r   endpoint_discoveryr2   r   r   r   r   endpoint_discovery_required  s    


z(ServiceModel.endpoint_discovery_requiredc                 C   s    | j di }dd | D S )Nr,   c                 S   s&   g | ]\}}t ||d  |d dqS )r-   r.   )r0   r-   r.   )rg   ).0
param_nameZ	param_valr   r   r   
<listcomp>  s   z:ServiceModel.client_context_parameters.<locals>.<listcomp>)rj   r2   rT   r   paramsr   r   r   client_context_parameters  s    z&ServiceModel.client_context_parametersc                 C   s:   z| j | W S  tk
r4   td| d|  Y nX d S )N"z," not defined in the metadata of the model: )rA   r~   r   r   r0   r   r   r   r     s    z#ServiceModel._get_metadata_propertyc                 C   s"   | j tkr| jd}|| _ | j S )NZsignatureVersion)rm   rl   rA   r2   )r   signature_versionr   r   r   r     s    
zServiceModel.signature_versionc                 C   s
   || _ d S r   )rm   )r   r_   r   r   r   r     s    c                 C   s
   d| j kS )NZawsQueryCompatiblerA   r   r   r   r   is_query_compatible  s    z ServiceModel.is_query_compatiblec                 C   s   | j j d| j dS )NrJ   ))rL   r   ro   r   r   r   r   rM     s    zServiceModel.__repr__)N)N) r   r   r   rO   r:   rs   ru   r	   rt   rE   rz   rv   r   r   r.   r   ro   r   r   r   r   r   r   r   r   r   r   rQ   r   setterr   rM   r   r   r   r   rh   '  sZ   





















rh   c                   @   s  e Zd ZdFddZedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zd4d5 Zd6d7 Zd8d9 Z ed:d; Z!ed<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dS )Gr   Nc                 C   s8   || _ || _|| _|d| _|j| _|di | _dS )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.

        r0   httpN)_operation_model_service_model	_api_namer2   Z
_wire_namerA   r   )r   r   service_modelr0   r   r   r   r:     s    zOperationModel.__init__c                 C   s   | j d k	r| j S | jS d S r   )r   	wire_namer   r   r   r   r0     s    
zOperationModel.namec                 C   s   | j dS )aR  The 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 operation name
        we send across the wire (e.g cloudfront).

        Any serialization code should use ``wire_name``.

        r0   r   r2   r   r   r   r   r     s    zOperationModel.wire_namec                 C   s   | j S r   )r   r   r   r   r   r   (  s    zOperationModel.service_modelc                 C   s   | j ddS r   r   r   r   r   r   r.   ,  s    zOperationModel.documentationc                 C   s   | j ddS )N
deprecatedFr   r   r   r   r   r   0  s    zOperationModel.deprecatedc                 C   s   | j dd S )NZendpointdiscoveryr   r   r   r   r   r   4  s    z!OperationModel.endpoint_discoveryc                 C   s   | j ddS )NZendpointoperationFr   r   r   r   r   r   :  s    z.OperationModel.is_endpoint_discovery_operationc                 C   s    d| j krd S | j| j d S )Ninputr   r   rE   r   r   r   r   input_shape>  s
    
zOperationModel.input_shapec                 C   s    d| j krd S | j| j d S )Noutputr   r   r   r   r   output_shapeH  s
    
zOperationModel.output_shapec                 C   s"   | j }|sg S dd |j D S )Nc                 S   s(   g | ] \}}d |j kr|j d  r|qS )r&   r   r   r0   shaper   r   r   r   Y  s   

z5OperationModel.idempotent_members.<locals>.<listcomp>r   rS   rT   )r   r   r   r   r   idempotent_membersS  s    z!OperationModel.idempotent_membersc                 C   s    | j di }dd | D S )NZstaticContextParamsc                 S   s"   g | ]\}}t ||d dqS )r_   )r0   r_   )ra   r2   )r   r0   propsr   r   r   r   c  s   z<OperationModel.static_context_parameters.<locals>.<listcomp>)r   r2   rT   r   r   r   r   static_context_parameters`  s    z(OperationModel.static_context_parametersc                 C   s    | j s
g S dd | j j D S )Nc                 S   s>   g | ]6\}}d |j krd|j d  krt|j d  d |dqS )r+   r0   )r0   rU   )rA   re   r   r   r   r   r   m  s   
z5OperationModel.context_parameters.<locals>.<listcomp>r   r   r   r   r   context_parametersh  s
    
z!OperationModel.context_parametersc                 C   s   | j dg S )NZoperationContextParamsr   r   r   r   r   operation_context_parametersw  s    z+OperationModel.operation_context_parametersc                 C   s   | j dS )NZrequestcompressionr   r   r   r   r   request_compression{  s    z"OperationModel.request_compressionc                 C   s   | j dS )Nauthr   r   r   r   r   r     s    zOperationModel.authc                 C   s   | j dS )NZauthtyper   r   r   r   r   	auth_type  s    zOperationModel.auth_typec                 C   s   | j rt| j S | jS r   )r   r   r   r   r   r   r   resolved_auth_type  s    
z!OperationModel.resolved_auth_typec                 C   s   | j dS )NZunsignedPayloadr   r   r   r   r   unsigned_payload  s    zOperationModel.unsigned_payloadc                    s$    j dg }t fdd|D S )Nerrorsc                 3   s   | ]} j |V  qd S r   )r   rE   )r   sr   r   r   	<genexpr>  s     z.OperationModel.error_shapes.<locals>.<genexpr>)r   r2   ry   )r   ri   r   r   r   rv     s    zOperationModel.error_shapesc                 C   s   | j dS )Nendpointr   r   r   r   r   r     s    zOperationModel.endpointc                 C   s   | j ddS )NZhttpChecksumRequiredFr   r   r   r   r   http_checksum_required  s    z%OperationModel.http_checksum_requiredc                 C   s   | j di S )NZhttpChecksumr   r   r   r   r   http_checksum  s    zOperationModel.http_checksumc                 C   s   |   d k	S r   )get_event_stream_inputr   r   r   r   has_event_stream_input  s    z%OperationModel.has_event_stream_inputc                 C   s   |   d k	S r   )get_event_stream_outputr   r   r   r   has_event_stream_output  s    z&OperationModel.has_event_stream_outputc                 C   s   |  | jS r   )_get_event_streamr   r   r   r   r   r     s    z%OperationModel.get_event_stream_inputc                 C   s   |  | jS r   )r   r   r   r   r   r   r     s    z&OperationModel.get_event_stream_outputc                 C   s$   |dkrdS |j }|r |j| S dS )zAReturns the event stream member's shape if any or None otherwise.N)rN   rS   )r   r   Z
event_namer   r   r   r     s    
z OperationModel._get_event_streamc                 C   s   |   d k	S r   )get_streaming_inputr   r   r   r   has_streaming_input  s    z"OperationModel.has_streaming_inputc                 C   s   |   d k	S r   )get_streaming_outputr   r   r   r   has_streaming_output  s    z#OperationModel.has_streaming_outputc                 C   s   |  | jS r   )_get_streaming_bodyr   r   r   r   r   r     s    z"OperationModel.get_streaming_inputc                 C   s   |  | jS r   )r   r   r   r   r   r   r     s    z#OperationModel.get_streaming_outputc                 C   s<   |dkrdS |j d}|dk	r8|j| }|jdkr8|S dS )z?Returns the streaming member's shape if any; or None otherwise.Nr   blob)r>   r2   rS   r1   )r   r   r   Zpayload_shaper   r   r   r     s    

z"OperationModel._get_streaming_bodyc                 C   s   | j j d| j dS )Nz(name=r   rK   r   r   r   r   rM     s    zOperationModel.__repr__)N)'r   r   r   r:   r	   r0   rQ   r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r     sx   
%







	
















	

r   c                   @   s8   e Zd ZdZeeeedZdd Z	d
ddZ
dd	 ZdS )rk   zResolves shape references.)	structurery   mapstringc                 C   s   || _ i | _d S r   )
_shape_mapZ_shape_cache)r   	shape_mapr   r   r   r:     s    zShapeResolver.__init__Nc                 C   s   z| j | }W n tk
r*   t|Y nX z| j|d t}W n" tk
rd   td| Y nX |r|| }|| |||| }|S )Nr-   z&Shape is missing required key 'type': )	r   r~   r   SHAPE_CLASSESr2   r   r   copyupdate)r   r7   rr   r8   Z	shape_clsresultr   r   r   rp     s    

zShapeResolver.get_shape_by_namec                 C   sl   t |dkr"d|kr"| |d S | }z|d}W n" tk
rZ   td| Y nX | ||S d S )N   r   z(Invalid model, missing shape reference: )lenrp   r   r<   r~   r   )r   rG   rr   r7   r   r   r   rE     s    
zShapeResolver.resolve_shape_ref)N)r   r   r   rO   rR   r[   r]   r`   r   r:   rp   rE   r   r   r   r   rk     s   
rk   c                   @   s"   e Zd ZdZdddZdd ZdS )r4   zEA ShapeResolver that will throw ValueErrors when shapes are resolved.Nc                 C   s   t d| dd S )NzAttempted to lookup shape '!', but no shape map was provided.
ValueErrorrq   r   r   r   rp     s    
z&UnresolvableShapeMap.get_shape_by_namec                 C   s   t d| dd S )NzAttempted to resolve shape 'r   r   rF   r   r   r   rE     s    
z&UnresolvableShapeMap.resolve_shape_ref)N)r   r   r   rO   rp   rE   r   r   r   r   r4     s   
r4   c                   @   sf   e Zd ZdZdZdddZdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )DenormalizedStructureBuildera  Build 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.

    )	r   integerbooleanr   float	timestamplongdoublecharNc                 C   s*   t  | _t | _|d kr&| jd| _d S )Nr   )r   rS   ShapeNameGenerator_name_generatornew_shape_namer0   r   r   r   r   r:   L  s    z%DenormalizedStructureBuilder.__init__c                 C   s
   || _ | S )zp

        :type members: dict
        :param members: The denormalized members.

        :return: self

        )_members)r   rS   r   r   r   with_membersR  s    	z)DenormalizedStructureBuilder.with_membersc                 C   sB   t  }d| jd}| ||| j t|d}t| j|| j |dS )zBuild the model based on the provided members.

        :rtype: botocore.model.StructureShape
        :return: The built StructureShape object.

        r   )r-   rS   )r   )r7   r8   r9   )r   r   _build_modelr0   rk   rR   )r   ri   Zdenormalizedresolverr   r   r   build_model^  s    
z(DenormalizedStructureBuilder.build_modelc                 C   s   |d dkr|  ||||< nl|d dkr<| ||||< nN|d dkrZ| ||||< n0|d | jkrx| |||< ntd|d  d S )Nr-   r   ry   r   zUnknown shape type: )_build_structure_build_list
_build_mapSCALAR_TYPES_build_scalarr   )r   r=   ri   r7   r   r   r   r   r  s    z)DenormalizedStructureBuilder._build_modelc                 C   s\   t  }| |}||d< |dt   D ],\}}| |}d|i||< | ||| q*|S )NrS   r   )r   _build_initial_shaper2   rT   _get_shape_namer   )r   r=   ri   rS   r   r0   Zmember_modelmember_shape_namer   r   r   r   ~  s    

z-DenormalizedStructureBuilder._build_structurec                 C   s6   |  |}| |}d|i|d< | |d || |S )Nr   rV   r   r   r   )r   r=   ri   r   r   r   r   r   r     s
    

z(DenormalizedStructureBuilder._build_listc                 C   sf   |  |d }|  |d }| |}d|i|d< d|i|d< | |d || | |d || |S )Nr^   r_   r   r   )r   r=   ri   Zkey_shape_nameZvalue_shape_namer   r   r   r   r     s    
z'DenormalizedStructureBuilder._build_mapc                 C   sD   d|d i}d|kr |d |d< t jD ]}||kr&|| ||< q&|S )Nr-   r.   )r   r@   )r   r=   r   r?   r   r   r   r     s     
z1DenormalizedStructureBuilder._build_initial_shapec                 C   s
   |  |S r   )r   r   r=   r   r   r   r     s    z*DenormalizedStructureBuilder._build_scalarc                 C   s$   d|kr|d S | j |d S d S )Nr7   r-   )r   r   r   r   r   r   r     s    z,DenormalizedStructureBuilder._get_shape_name)N)r   r   r   rO   r   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   $

r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   zGenerate 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.

    c                 C   s   t t| _d S r   )r   int_name_cacher   r   r   r   r:     s    zShapeNameGenerator.__init__c                 C   s.   | j |  d7  < | j | }|  d| S )a  Generate 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

        r   Type)r   
capitalize)r   r1   Zcurrent_indexr   r   r   r     s    
z!ShapeNameGenerator.new_shape_nameN)r   r   r   rO   r:   r   r   r   r   r   r     s   r   N)(rO   collectionsr   typingr   r   Zbotocore.authr   Zbotocore.compatr   Zbotocore.exceptionsr   r   Zbotocore.utilsr	   r
   r   objectrl   	Exceptionr   r   r   r   rb   r   r   rR   r[   r]   r`   ra   re   rg   rh   r   rk   r4   r   r   r   r   r   r   <module>   s<    &*
 G j6 