o
    .&ßa;p  ã                   @   sR  d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddl	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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 eƒZG d!d"„ d"eƒZG d#d$„ d$eƒZG d%d&„ d&eƒZd'S )(z-Abstractions to interact with service models.é    )Údefaultdict)ÚCachedPropertyÚinstance_cacheÚhyphenize_service_id)ÚOrderedDict)ÚMissingServiceIdError)ÚUndefinedModelAttributeErrorc                   @   ó   e Zd ZdS )ÚNoShapeFoundErrorN©Ú__name__Ú
__module__Ú__qualname__© r   r   ú0/usr/lib/python3/dist-packages/botocore/model.pyr
      ó    r
   c                   @   r	   )ÚInvalidShapeErrorNr   r   r   r   r   r      r   r   c                   @   r	   )ÚOperationNotFoundErrorNr   r   r   r   r   r   !   r   r   c                   @   r	   )ÚInvalidShapeReferenceErrorNr   r   r   r   r   r   %   r   r   c                   @   s   e Zd Zdd„ ZdS )Ú	ServiceIdc                 C   s   t | ƒS ©N)r   ©Úselfr   r   r   Ú	hyphenize*   ó   zServiceId.hyphenizeN)r   r   r   r   r   r   r   r   r   )   s    r   c                   @   sn   e Zd ZdZg d¢Zg d¢ZeZdd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 )ÚShapez3Object representing a shape from the service model.)ÚlocationNameÚ	queryNameÚ	flattenedÚlocationÚpayloadÚ	streamingÚtimestampFormatÚxmlNamespaceÚresultWrapperÚxmlAttributeÚeventstreamÚeventÚeventheaderÚeventpayloadÚ	jsonvaluer"   Ú	hostLabel)ÚrequiredÚminÚmaxÚ	sensitiveÚenumÚidempotencyTokenÚerrorÚ	exceptionÚendpointdiscoveryidÚ	retryableÚdocumentÚunionNc                 C   sB   || _ |d | _| dd¡| _|| _|du rtƒ }|| _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Úgetr9   Ú_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 v r|| ||< qd|v r!| 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;   )r>   ÚSERIALIZED_ATTRSÚpop)r   ÚmodelÚserializationÚattrr   r   r   rI   `   s   

€zShape.serializationc                 C   s0   | j }i }| jD ]}|| j v r|| ||< q|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)r   rH   ÚmetadatarJ   r   r   r   rL   �   s   

€zShape.metadatac                 C   ó   | j  dg ¡S )zïA 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,   ©rL   r=   r   r   r   r   Úrequired_members›   s   	zShape.required_membersc                 C   ó   | j  |¡S r   ©r@   Úresolve_shape_ref©r   Ú	shape_refr   r   r   Ú_resolve_shape_ref¦   ó   zShape._resolve_shape_refc                 C   ó   d| j j| jf S )Nz<%s(%s)>©Ú	__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_namer   )r   r   r   Ú__doc__rF   rK   r   ÚMAP_TYPErE   r   rI   rL   rO   rU   rZ   Úpropertyr[   r   r   r   r   r   .   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)r>   r=   r]   ÚitemsrU   )r   r`   Úshape_membersr;   rT   r   r   r   r`   ³   s
   zStructureShape.membersc                 C   s,   | j  ¡ D ]\}}|j d¡r|  S qd S )Nr&   )r`   ra   rI   r=   )r   Úmember_nameÚmemberr   r   r   r[   Á   s
   ÿz StructureShape.event_stream_namec                 C   s8   | j  dd¡s	d S | j  di ¡}| d¡}|r|S | jS )Nr3   Fr2   Úcode)rL   r=   r;   )r   Úerror_metadatare   r   r   r   Ú
error_codeÈ   s   
zStructureShape.error_codec                 C   ó   | j  dd¡S )Nr6   FrN   r   r   r   r   Úis_document_typeÓ   ó   zStructureShape.is_document_typec                 C   rh   )Nr7   FrN   r   r   r   r   Úis_tagged_union×   rj   zStructureShape.is_tagged_unionN)	r   r   r   r   r`   r[   rg   ri   rk   r   r   r   r   r_   ²   s    




r_   c                   @   ó   e Zd Zedd„ ƒZdS )Ú	ListShapec                 C   ó   |   | jd ¡S )Nrd   ©rU   r>   r   r   r   r   rd   Ý   ó   zListShape.memberN)r   r   r   r   rd   r   r   r   r   rm   Ü   ó    rm   c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚMapShapec                 C   rn   )NÚkeyro   r   r   r   r   rs   ã   rp   zMapShape.keyc                 C   rn   )NÚvaluero   r   r   r   r   rt   ç   rp   zMapShape.valueN)r   r   r   r   rs   rt   r   r   r   r   rr   â   s
    
rr   c                   @   rl   )ÚStringShapec                 C   rM   )Nr0   rN   r   r   r   r   r0   í   rj   zStringShape.enumN)r   r   r   r   r0   r   r   r   r   ru   ì   rq   ru   c                   @   s  e Zd ZdZd.dd„Zd.d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d'd(„ Zed)d*„ ƒZejd+d*„ ƒZd,d-„ ZdS )/Ú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.

        rL   ÚshapesN)	Ú_service_descriptionr=   rL   ÚShapeResolverr@   ÚNOT_SETÚ_signature_versionÚ_service_nameÚ_instance_cache)r   Úservice_descriptionÚservice_namer   r   r   rE   ù   s   
ÿ
zServiceModel.__init__c                 C   s   | j  ||¡S r   )r@   Úget_shape_by_name©r   rB   Úmember_traitsr   r   r   Ú	shape_for  s   ÿzServiceModel.shape_forc                 C   s   | j  |d ¡S r   )Ú_error_code_cacher=   )r   rg   r   r   r   Úshape_for_error_code  ó   z!ServiceModel.shape_for_error_codec                 C   s"   i }| j D ]	}|j}|||< q|S r   )Úerror_shapesrg   )r   Úerror_code_cacheÚerror_shapere   r   r   r   r„     s
   

zServiceModel._error_code_cachec                 C   rP   r   rQ   rS   r   r   r   rR   &  rV   zServiceModel.resolve_shape_refc                 C   s   t | j di ¡ƒS )Nrw   ©Úlistrx   r=   r   r   r   r   Úshape_names)  ó   zServiceModel.shape_namesc                 C   s6   g }| j D ]}|  |¡}|j dd¡r| |¡ q|S )Nr3   F)rŒ   rƒ   rL   r=   Úappend)r   r‡   rB   r‰   r   r   r   r‡   -  s   


€zServiceModel.error_shapesc                 C   s6   z	| j d | }W n ty   t|ƒ‚w t|| |ƒS ©NÚ
operations)rx   ÚKeyErrorr   ÚOperationModel)r   Úoperation_namerH   r   r   r   Úoperation_model6  s   ÿzServiceModel.operation_modelc                 C   rh   ©Nr9   r:   )rx   r=   r   r   r   r   r9   >  rj   zServiceModel.documentationc                 C   s   t | j dg ¡ƒS r�   rŠ   r   r   r   r   Úoperation_namesB  r�   zServiceModel.operation_namesc                 C   s   | j dur| j S | j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)r|   Úendpoint_prefixr   r   r   r   r   F  s   
zServiceModel.service_namec                 C   s,   zt |  d¡ƒW S  ty   t| jd�‚w )NÚ	serviceId)r   )r   Ú_get_metadata_propertyr   r   r|   r   r   r   r   Ú
service_idW  s   ÿÿzServiceModel.service_idc                 C   s   | j  d¡}|du r| j}|S )z®The 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)rL   r=   r—   )r   Úsigning_namer   r   r   rœ   `  s   zServiceModel.signing_namec                 C   ó
   |   d¡S )NÚ
apiVersion©r™   r   r   r   r   Úapi_versionl  ó   
zServiceModel.api_versionc                 C   r�   )NÚprotocolrŸ   r   r   r   r   r¢   p  r¡   zServiceModel.protocolc                 C   r�   )NÚendpointPrefixrŸ   r   r   r   r   r—   t  r¡   zServiceModel.endpoint_prefixc                 C   s(   | j D ]}|  |¡}|jr|  S qd S r   )r–   r”   Úis_endpoint_discovery_operation©r   Ú	operationrH   r   r   r   Úendpoint_discovery_operationx  s   

ÿþz)ServiceModel.endpoint_discovery_operationc                 C   s6   | j D ]}|  |¡}|jd ur|j d¡r dS qdS )Nr,   TF)r–   r”   Úendpoint_discoveryr=   r¥   r   r   r   Úendpoint_discovery_required  s   



ÿ€z(ServiceModel.endpoint_discovery_requiredc                 C   s,   z| j | W S  ty   td|| f ƒ‚w )Nz1"%s" not defined in the metadata of the model: %s)rL   r‘   r   ©r   r;   r   r   r   r™   Š  s   ÿÿÿz#ServiceModel._get_metadata_propertyc                 C   s"   | j tu r| j d¡}|| _ | j S )NÚsignatureVersion)r{   rz   rL   r=   )r   Úsignature_versionr   r   r   r¬   •  s   
zServiceModel.signature_versionc                 C   s
   || _ d S r   )r{   )r   rt   r   r   r   r¬   œ  r¡   c                 C   rW   )Nz%s(%s))rY   r   r   r   r   r   r   rZ      ó   zServiceModel.__repr__r   )r   r   r   r\   rE   rƒ   r…   r   r„   rR   rŒ   r‡   r   r”   r9   r–   r   rš   rœ   r    r¢   r—   r§   r©   r™   r^   r¬   ÚsetterrZ   r   r   r   r   rv   ò   sP    


















rv   c                   @   s&  e Zd Zd6d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d*d+„ ƒZed,d-„ ƒZd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ ZdS )7r’   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_namer=   Ú
_wire_namerL   r¯   )r   r”   Úservice_modelr;   r   r   r   rE   ¥  s   zOperationModel.__init__c                 C   s   | j d ur| j S | jS r   )r²   Ú	wire_namer   r   r   r   r;   Ê  s   
zOperationModel.namec                 C   ó   | 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°   r=   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   rh   r•   r·   r   r   r   r   r9   ã  rj   zOperationModel.documentationc                 C   rh   )NÚ
deprecatedFr·   r   r   r   r   r¸   ç  rj   zOperationModel.deprecatedc                 C   s   | j  dd ¡S )NÚendpointdiscoveryr·   r   r   r   r   r¨   ë  s   z!OperationModel.endpoint_discoveryc                 C   rh   )NÚendpointoperationFr·   r   r   r   r   r¤   ñ  rj   z.OperationModel.is_endpoint_discovery_operationc                 C   ó    d| j vrd S | j | j d ¡S )NÚinput©r°   r±   rR   r   r   r   r   Úinput_shapeõ  s
   
ÿzOperationModel.input_shapec                 C   r»   )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 v r|j d  r|‘qS )r1   )rL   )Ú.0r;   Úshaper   r   r   Ú
<listcomp>  s    
ÿÿz5OperationModel.idempotent_members.<locals>.<listcomp>)r¾   r`   ra   )r   r¾   r   r   r   Úidempotent_members  s   ÿz!OperationModel.idempotent_membersc                 C   r¶   )NÚauthtyper·   r   r   r   r   Ú	auth_type  ó   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±   rR   )rÁ   Úsr   r   r   Ú	<genexpr>  s   € z.OperationModel.error_shapes.<locals>.<genexpr>)r°   r=   r‹   )r   rw   r   r   r   r‡     s   zOperationModel.error_shapesc                 C   r¶   )NÚendpointr·   r   r   r   r   rË     rÇ   zOperationModel.endpointc                 C   rh   )NÚhttpChecksumRequiredFr·   r   r   r   r   Úhttp_checksum_required!  rj   z%OperationModel.http_checksum_requiredc                 C   ó   |   ¡ d uS r   )Úget_event_stream_inputr   r   r   r   Úhas_event_stream_input%  rÇ   z%OperationModel.has_event_stream_inputc                 C   rÎ   r   )Úget_event_stream_outputr   r   r   r   Úhas_event_stream_output)  rÇ   z&OperationModel.has_event_stream_outputc                 C   ó   |   | j¡S r   )Ú_get_event_streamr¾   r   r   r   r   rÏ   -  rV   z%OperationModel.get_event_stream_inputc                 C   rÓ   r   )rÔ   rÀ   r   r   r   r   rÑ   0  rV   z&OperationModel.get_event_stream_outputc                 C   s$   |du rdS |j }|r|j| S dS )zAReturns the event stream member's shape if any or None otherwise.N)r[   r`   )r   rÂ   Ú
event_namer   r   r   rÔ   3  s   
z OperationModel._get_event_streamc                 C   rÎ   r   )Úget_streaming_inputr   r   r   r   Úhas_streaming_input<  rÇ   z"OperationModel.has_streaming_inputc                 C   rÎ   r   )Úget_streaming_outputr   r   r   r   Úhas_streaming_output@  rÇ   z#OperationModel.has_streaming_outputc                 C   rÓ   r   )Ú_get_streaming_bodyr¾   r   r   r   r   rÖ   D  rV   z"OperationModel.get_streaming_inputc                 C   rÓ   r   )rÚ   rÀ   r   r   r   r   rØ   G  rV   z#OperationModel.get_streaming_outputc                 C   s<   |du rdS |j  d¡}|dur|j| }|jdkr|S dS )z?Returns the streaming member's shape if any; or None otherwise.Nr    Úblob)rI   r=   r`   r<   )r   rÂ   r    Úpayload_shaper   r   r   rÚ   J  s   

z"OperationModel._get_streaming_bodyc                 C   rW   )Nz%s(name=%s)rX   r   r   r   r   rZ   U  r­   zOperationModel.__repr__r   )r   r   r   rE   r   r;   r^   rµ   r´   r9   r¸   r¨   r¤   r¾   rÀ   rÄ   rÆ   r‡   rË   rÍ   rÐ   rÒ   rÏ   rÑ   rÔ   r×   rÙ   rÖ   rØ   rÚ   rZ   r   r   r   r   r’   ¤  sZ    
%








	






	

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 )ry   zResolves shape references.)Ú	structurer‹   ÚmapÚstringc                 C   s   || _ i | _d S r   )Ú
_shape_mapÚ_shape_cache)r   Ú	shape_mapr   r   r   rE   d  s   
zShapeResolver.__init__Nc                 C   s~   z| j | }W n ty   t|ƒ‚w z| j |d t¡}W n ty+   td| ƒ‚w |r7| ¡ }| |¡ |||| ƒ}|S )Nr8   z(Shape is missing required key 'type': %s)	rà   r‘   r
   ÚSHAPE_CLASSESr=   r   r   ÚcopyÚupdate)r   rB   r‚   rC   Ú	shape_clsÚresultr   r   r   r€   h  s"   ÿÿÿ
zShapeResolver.get_shape_by_namec                 C   s`   t |ƒdkrd|v r|  |d ¡S | ¡ }z| d¡}W n ty)   td| ƒ‚w |  ||¡S )Né   rÂ   z*Invalid model, missing shape reference: %s)Úlenr€   rä   rG   r‘   r   )r   rT   r‚   rB   r   r   r   rR   x  s   ÿÿzShapeResolver.resolve_shape_refr   )r   r   r   r\   r_   rm   rr   ru   rã   rE   r€   rR   r   r   r   r   ry   Y  s    ü
ry   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )r?   zJA ShapeResolver that will throw ValueErrors when shapes are resolved.
    Nc                 C   ó   t dƒ‚)Nz>Attempted to lookup shape '%s', but no shape map was provided.©Ú
ValueErrorr�   r   r   r   r€   �  r   z&UnresolvableShapeMap.get_shape_by_namec                 C   rê   )Nz?Attempted to resolve shape '%s', but no shape map was provided.rë   rS   r   r   r   rR   ”  r   z&UnresolvableShapeMap.resolve_shape_refr   )r   r   r   r\   r€   rR   r   r   r   r   r?   �  s    
r?   c                   @   sb   e 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.

    Nc                 C   s.   t ƒ | _tƒ | _|d u r| j d¡| _d S d S )NrÝ   )r   r`   ÚShapeNameGeneratorÚ_name_generatorÚnew_shape_namer;   rª   r   r   r   rE   ½  s
   ÿz%DenormalizedStructureBuilder.__init__c                 C   s
   || _ | S )zp

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

        :return: self

        )Ú_members)r   r`   r   r   r   Úwith_membersÃ  s   	z)DenormalizedStructureBuilder.with_membersc                 C   sB   t ƒ }d| jdœ}|  ||| j¡ t|d�}t| j|| j |d�S )z™Build the model based on the provided members.

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

        rÝ   )r8   r`   )râ   )rB   rC   rD   )r   rñ   Ú_build_modelr;   ry   r_   )r   rw   ÚdenormalizedÚresolverr   r   r   Úbuild_modelÏ  s   þ
þz(DenormalizedStructureBuilder.build_modelc                 C   sŽ   |d dkr|   ||¡||< d S |d dkr |  ||¡||< d S |d dkr0|  ||¡||< d S |d dv r?|  |¡||< d S td|d  ƒ‚)Nr8   rÝ   r‹   rÞ   )	rß   ÚintegerÚbooleanrÛ   ÚfloatÚ	timestampÚlongÚdoubleÚcharzUnknown shape type: %s)Ú_build_structureÚ_build_listÚ
_build_mapÚ_build_scalarr   )r   rH   rw   rB   r   r   r   ró   á  s   z)DenormalizedStructureBuilder._build_modelc                 C   s\   t ƒ }|  |¡}||d< | dt ƒ ¡ ¡ D ]\}}|  |¡}d|i||< |  |||¡ q|S )Nr`   rÂ   )r   Ú_build_initial_shaper=   ra   Ú_get_shape_nameró   )r   rH   rw   r`   rÂ   r;   Úmember_modelÚmember_shape_namer   r   r   rþ   î  s   

z-DenormalizedStructureBuilder._build_structurec                 C   s6   |   |¡}|  |¡}d|i|d< |  |d ||¡ |S )NrÂ   rd   ©r  r  ró   )r   rH   rw   r  rÂ   r   r   r   rÿ   ù  s
   

z(DenormalizedStructureBuilder._build_listc                 C   sf   |   |d ¡}|   |d ¡}|  |¡}d|i|d< d|i|d< |  |d ||¡ |  |d ||¡ |S )Nrs   rt   rÂ   r  )r   rH   rw   Úkey_shape_nameÚvalue_shape_namerÂ   r   r   r   r      s   
z'DenormalizedStructureBuilder._build_mapc                 C   sD   d|d i}d|v r|d |d< t jD ]}||v r|| ||< q|S )Nr8   r9   )r   rK   )r   rH   rÂ   rJ   r   r   r   r  
  s   ÿ
€z1DenormalizedStructureBuilder._build_initial_shapec                 C   s
   |   |¡S r   )r  ©r   rH   r   r   r   r    s   
z*DenormalizedStructureBuilder._build_scalarc                 C   s    d|v r|d S | j  |d ¡S )NrB   r8   )rï   rð   r	  r   r   r   r    s   z,DenormalizedStructureBuilder._get_shape_namer   )r   r   r   r\   rE   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î   z³Generate 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   rE   &  r†   zShapeNameGenerator.__init__c                 C   s,   | j |  d7  < | j | }d| ¡ |f 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è   z%sType%s)r  Ú
capitalize)r   r<   Úcurrent_indexr   r   r   rð   )  s
   
ÿz!ShapeNameGenerator.new_shape_nameN)r   r   r   r\   rE   rð   r   r   r   r   rî     s    rî   N) r\   Úcollectionsr   Úbotocore.utilsr   r   r   Úbotocore.compatr   Úbotocore.exceptionsr   r   Úobjectrz   Ú	Exceptionr
   r   r   r   Ústrr   r   r_   rm   rr   ru   rv   r’   ry   r?   rí   rî   r   r   r   r   Ú<module>   s6    *
 3 64 