U
    M8cv                     @   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	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)OrderedDict)MissingServiceIdErrorUndefinedModelAttributeError)CachedPropertyhyphenize_service_idinstance_cachec                   @   s   e Zd ZdS )NoShapeFoundErrorN__name__
__module____qualname__ r   r   2/tmp/pip-unpacked-wheel-ozje0y8b/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 gZeZd0d"d#Ze	d$d% Z
e	d&d' Ze	d(d) Zd*d+ Zd,d- Zed.d/ Zd!S )1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clientContextParamsNc                 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   r/   )r2   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 )as  Metadata 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.

        )r2   METADATA_ATTRS)r   r<   metadatar>   r   r   r   r@      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    r@   r1   r   r   r   r   required_members   s    	zShape.required_membersc                 C   s   | j |S r   r4   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   r/   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_TYPEr9   r   r=   r@   rB   rG   rL   propertyrM   r   r   r   r   r   0   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)r2   r1   rO   itemsrG   )r   rR   Zshape_membersr/   rF   r   r   r   rR      s
    zStructureShape.membersc                 C   s,   | j  D ]\}}|jdr
|  S q
d S )Nr   )rR   rS   r=   r1   )r   member_namememberr   r   r   rM      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)r@   r1   r/   )r   Zerror_metadatarV   r   r   r   
error_code   s    
zStructureShape.error_codec                 C   s   | j ddS )Nr(   FrA   r   r   r   r   is_document_type   s    zStructureShape.is_document_typec                 C   s   | j ddS )Nr)   FrA   r   r   r   r   is_tagged_union   s    zStructureShape.is_tagged_unionN)	r   r   r   r   rR   rM   rW   rX   rY   r   r   r   r   rQ      s   




rQ   c                   @   s   e Zd Zedd ZdS )	ListShapec                 C   s   |  | jd S )NrU   rG   r2   r   r   r   r   rU      s    zListShape.memberN)r   r   r   r   rU   r   r   r   r   rZ      s   rZ   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$   rA   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 )StaticContextParameterr/   r^   N)r   r   r   str__annotations__r   boolr   r   r   r   r`     s   
r`   c                   @   s   e Zd ZU eed< eed< dS )ContextParameterr/   rT   Nr   r   r   ra   rb   r   r   r   r   rd     s   
rd   c                   @   s&   e Zd ZU eed< eed< eed< dS )ClientContextParameterr/   r,   r-   Nre   r   r   r   r   rf     s   
rf   c                   @   s  e Zd ZdZd0ddZd1d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d)d* Zed+d, Zejd-d, Zd.d/ ZdS )2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.

        r@   shapesN)	_service_descriptionr1   r@   ShapeResolverr4   NOT_SET_signature_version_service_nameZ_instance_cache)r   Zservice_descriptionservice_namer   r   r   r9   (  s    
zServiceModel.__init__c                 C   s   | j ||S r   )r4   get_shape_by_namer   r6   member_traitsr   r   r   	shape_forG  s     zServiceModel.shape_forc                 C   s   | j |d S r   )_error_code_cacher1   )r   rW   r   r   r   shape_for_error_codeL  s    z!ServiceModel.shape_for_error_codec                 C   s"   i }| j D ]}|j}|||< q
|S r   )error_shapesrW   )r   Zerror_code_cacheerror_shaperV   r   r   r   rs   O  s
    

zServiceModel._error_code_cachec                 C   s   | j |S r   rC   rE   r   r   r   rD   W  s    zServiceModel.resolve_shape_refc                 C   s   t | jdi S )Nrh   listri   r1   r   r   r   r   shape_namesZ  s    zServiceModel.shape_namesc                 C   s6   g }| j D ]&}| |}|jddr
|| q
|S )Nr'   F)ry   rr   r@   r1   append)r   ru   r6   rv   r   r   r   ru   ^  s    

zServiceModel.error_shapesc                 C   s<   z| j d | }W n tk
r.   t|Y nX t|| |S N
operations)ri   KeyErrorr   OperationModel)r   Zoperation_namer<   r   r   r   operation_modelg  s
    zServiceModel.operation_modelc                 C   s   | j ddS Nr-   r.   )ri   r1   r   r   r   r   r-   o  s    zServiceModel.documentationc                 C   s   t | jdg S r{   rw   r   r   r   r   operation_namess  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)rm   endpoint_prefixr   r   r   r   rn   w  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)rn   )r   _get_metadata_propertyr   r   rm   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)r@   r1   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 )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_discoveryr1   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-   )r/   r,   r-   )rf   ).0
param_nameZ	param_valr   r   r   
<listcomp>  s   z:ServiceModel.client_context_parameters.<locals>.<listcomp>)ri   r1   rS   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: )r@   r}   r   r   r/   r   r   r   r     s    z#ServiceModel._get_metadata_propertyc                 C   s"   | j tkr| jd}|| _ | j S )NZsignatureVersion)rl   rk   r@   r1   )r   signature_versionr   r   r   r     s    
zServiceModel.signature_versionc                 C   s
   || _ d S r   )rl   )r   r^   r   r   r   r     s    c                 C   s   | j j d| j dS )NrI   ))rK   r   rn   r   r   r   r   rL     s    zServiceModel.__repr__)N)N)r   r   r   rN   r9   rr   rt   r   rs   rD   ry   ru   r
   r   r-   r   rn   r   r   r   r   r   r   r   r   r   rP   r   setterrL   r   r   r   r   rg   !  sR   



















rg   c                   @   sJ  e Zd Zd<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d*d+ Zd,d- Zd.d/ Zed0d1 Zed2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!dS )=r~   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.

        r/   httpN)_operation_model_service_model	_api_namer1   Z
_wire_namer@   r   )r   r   service_modelr/   r   r   r   r9     s    zOperationModel.__init__c                 C   s   | j d k	r| j S | jS d S r   )r   	wire_namer   r   r   r   r/     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 operaiton name
        we send across the wire (e.g cloudfront).

        Any serialization code should use ``wire_name``.

        r/   r   r1   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   "  s    zOperationModel.deprecatedc                 C   s   | j dd S )NZendpointdiscoveryr   r   r   r   r   r   &  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   rD   r   r   r   r   input_shape0  s
    
zOperationModel.input_shapec                 C   s    d| j krd S | j| j d S )Noutputr   r   r   r   r   output_shape:  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   r/   shaper   r   r   r   K  s   

z5OperationModel.idempotent_members.<locals>.<listcomp>r   rR   rS   )r   r   r   r   r   idempotent_membersE  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^   )r/   r^   )r`   r1   )r   r/   propsr   r   r   r   U  s   z<OperationModel.static_context_parameters.<locals>.<listcomp>)r   r1   rS   r   r   r   r   static_context_parametersR  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*   r/   )r/   rT   )r@   rd   r   r   r   r   r   _  s   
z5OperationModel.context_parameters.<locals>.<listcomp>r   r   r   r   r   context_parametersZ  s
    
z!OperationModel.context_parametersc                 C   s   | j dS )NZauthtyper   r   r   r   r   	auth_typei  s    zOperationModel.auth_typec                    s$    j dg }t fdd|D S )Nerrorsc                 3   s   | ]} j |V  qd S r   )r   rD   )r   sr   r   r   	<genexpr>p  s     z.OperationModel.error_shapes.<locals>.<genexpr>)r   r1   rx   )r   rh   r   r   r   ru   m  s    zOperationModel.error_shapesc                 C   s   | j dS )Nendpointr   r   r   r   r   r   r  s    zOperationModel.endpointc                 C   s   | j ddS )NZhttpChecksumRequiredFr   r   r   r   r   http_checksum_requiredv  s    z%OperationModel.http_checksum_requiredc                 C   s   | j di S )NZhttpChecksumr   r   r   r   r   http_checksumz  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)rM   rR   )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=   r1   rR   r0   )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   rJ   r   r   r   r   rL     s    zOperationModel.__repr__)N)"r   r   r   r9   r   r/   rP   r   r   r-   r   r   r   r   r   r   r   r   r   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   r   r   r   r   r~     sd   
%







	











	

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 )rj   zResolves shape references.)	structurerx   mapstringc                 C   s   || _ i | _d S r   )
_shape_mapZ_shape_cache)r   	shape_mapr   r   r   r9     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_CLASSESr1   r   r   copyupdate)r   r6   rq   r7   Z	shape_clsresultr   r   r   ro     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: )lenro   r   r;   r}   r   )r   rF   rq   r6   r   r   r   rD     s    
zShapeResolver.resolve_shape_ref)N)r   r   r   rN   rQ   rZ   r\   r_   r   r9   ro   rD   r   r   r   r   rj     s   
rj   c                   @   s"   e Zd ZdZdddZdd ZdS )r3   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.
ValueErrorrp   r   r   r   ro     s    
z&UnresolvableShapeMap.get_shape_by_namec                 C   s   t d| dd S )NzAttempted to resolve shape 'r   r   rE   r   r   r   rD     s    
z&UnresolvableShapeMap.resolve_shape_ref)N)r   r   r   rN   ro   rD   r   r   r   r   r3     s   
r3   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   rR   ShapeNameGenerator_name_generatornew_shape_namer/   r   r   r   r   r9   (  s    z%DenormalizedStructureBuilder.__init__c                 C   s
   || _ | S )zp

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

        :return: self

        )_members)r   rR   r   r   r   with_members.  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,   rR   )r   )r6   r7   r8   )r   r   _build_modelr/   rj   rQ   )r   rh   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   rx   r   zUnknown shape type: )_build_structure_build_list
_build_mapSCALAR_TYPES_build_scalarr   )r   r<   rh   r6   r   r   r   r   N  s    z)DenormalizedStructureBuilder._build_modelc                 C   s\   t  }| |}||d< |dt   D ],\}}| |}d|i||< | ||| q*|S )NrR   r   )r   _build_initial_shaper1   rS   _get_shape_namer   )r   r<   rh   rR   r   r/   Zmember_modelmember_shape_namer   r   r   r   Z  s    

z-DenormalizedStructureBuilder._build_structurec                 C   s6   |  |}| |}d|i|d< | |d || |S )Nr   rU   r   r   r   )r   r<   rh   r   r   r   r   r   r   e  s
    

z(DenormalizedStructureBuilder._build_listc                 C   sf   |  |d }|  |d }| |}d|i|d< d|i|d< | |d || | |d || |S )Nr]   r^   r   r   )r   r<   rh   Zkey_shape_nameZvalue_shape_namer   r   r   r   r   l  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   v  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 )Nr6   r,   )r   r   r   r   r   r   r     s    z,DenormalizedStructureBuilder._get_shape_name)N)r   r   r   rN   r   r9   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   r9     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   r0   Zcurrent_indexr   r   r   r     s    
z!ShapeNameGenerator.new_shape_nameN)r   r   r   rN   r9   r   r   r   r   r   r     s   r   N)&rN   collectionsr   typingr   r   Zbotocore.compatr   Zbotocore.exceptionsr   r   Zbotocore.utilsr   r	   r
   objectrk   	Exceptionr   r   r   r   ra   r   r   rQ   rZ   r\   r_   r`   rd   rf   rg   r~   rj   r3   r   r   r   r   r   r   <module>   s:    "*
 ? T6 