o
    .&ßan$  ã                   @   sP   d dl Z d dlZd dlmZ d dlmZ d dlmZ G dd„ deƒZ	dd„ Z
dS )	é    N)Úparse_timestamp)Úescape_controls)Úsixc                   @   sx   e Zd Zdd„ Zdd„ Zdd„ Zd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S )ÚSharedExampleDocumenterc                 C   sJ   |j  ¡  | | d¡¡ |j  ¡  |  ||||j¡ |  |||j¡ dS )a8  Documents a single shared example based on its definition.

        :param example: The model of the example

        :param prefix: The prefix to use in the method example.

        :param section: The section to write to.

        :param operation_model: The model of the operation used in the example
        ÚdescriptionN)	ÚstyleÚnew_paragraphÚwriteÚgetÚnew_lineÚdocument_inputÚinput_shapeÚdocument_outputÚoutput_shape)ÚselfÚexampleÚprefixÚsectionÚoperation_model© r   ú=/usr/lib/python3/dist-packages/botocore/docs/sharedexample.pyÚdocument_shared_example   s   


ÿz/SharedExampleDocumenter.document_shared_examplec           
      C   sœ   |  d¡}|j ¡  |d ur| |¡ | di ¡}| d¡}|r%| d¡}|  d¡}|  |||g |¡ |  d¡}	|	j ¡  |	j ¡  |	 d¡ |	j ¡  d S )NÚinputÚcommentsÚ
parameterszinput-closezprint(response))Úadd_new_sectionr   Ústart_codeblockr	   r
   Ú_document_paramsr   Úend_codeblock)
r   r   r   r   ÚshapeÚinput_sectionÚparamsr   Úparam_sectionÚclosing_sectionr   r   r   r   (   s   









z&SharedExampleDocumenter.document_inputc                 C   sŽ   |  d¡}|j ¡  | d¡ |j ¡  |j ¡  | di ¡}ddi|d< | d¡}|r1| d¡}|  |||g |d¡ |  d¡}|j ¡  d S )NÚoutputzExpected Output:z...ÚResponseMetadatar   Tzoutput-close)r   r   r   r	   r   r
   Ú_document_dictr   )r   r   r   r   Úoutput_sectionr!   r   r#   r   r   r   r   9   s   







z'SharedExampleDocumenter.document_outputc                 C   s�   t |tƒr|  |||||¡ dS t |tƒr |  |||||¡ dS t |tjƒr/|  |||¡ dS |r?|jdkr?|  	|||¡ dS |  
|||¡ dS )a  
        :param section: The section to add the docs to.

        :param value: The input / output values representing the parameters that
                      are included in the example.

        :param comments: The dictionary containing all the comments to be
                         applied to the example.

        :param path: A list describing where the documenter is in traversing the
                     parameters. This is used to find the equivalent location
                     in the comments dictionary.
        Ú	timestampN)Ú
isinstanceÚdictr&   ÚlistÚ_document_listÚnumbersÚNumberÚ_document_numberÚ	type_nameÚ_document_datetimeÚ_document_str)r   r   Úvaluer   Úpathr   r   r   r   Ú	_documentJ   s   

z!SharedExampleDocumenter._documentFc                 C   sò   |  d¡}|  |d¡ | ¡ D ]S\}}	| d| ¡ |  |¡}
|
j ¡  |  ||¡}|r6|
 |¡ |
j ¡  |
 d| ¡ d }|rU|jdkrM|j	 
|¡}n|jdkrU|j}|  |
|	|||¡ | ¡  q|  d¡}|  |d¡ |sw| d	¡ d S d S )
Nz
dict-valueú{ú.%sz'%s': Ú	structureÚmapzending-braceú}ú,)r   Ú_start_nested_valueÚitemsÚappendr   r   Ú_get_commentr	   r0   Úmembersr
   r3   r5   ÚpopÚ_end_nested_value)r   r   r3   r   r4   r   Ú	top_levelÚdict_sectionÚkeyÚvalÚitem_sectionÚitem_commentÚ
item_shapeÚdict_section_endr   r   r   r&   c   s0   








ÿz&SharedExampleDocumenter._document_dictc                 C   sÄ   |  d¡}|  |d¡ | ¡ D ]E\}}| d| ¡ |  |¡}	|	j ¡  |  ||¡}
|
r6|	 |
¡ |	j ¡  |	 |d ¡ d }|rG|j 	|¡}|  
|	||||¡ | ¡  q|  d¡}|  |d¡ d S )Nzparam-valuesú(r7   ú=zending-parenthesisú))r   r<   r=   r>   r   r   r?   r	   r@   r
   r5   rA   rB   )r   r   r3   r   r4   r   r"   rE   rF   rG   rH   rI   Úparam_section_endr   r   r   r      s$   






z(SharedExampleDocumenter._document_paramsc                 C   s¨   |  d¡}|  |d¡ |j}t|ƒD ]4\}}	|  |¡}
|
j ¡  | d| ¡ |  ||¡}|r9|
 |¡ |
j ¡  |  	|
|	|||¡ | 
¡  q|  d¡}|  |d¡ d S )Nzlist-sectionú[z[%s]zending-bracketz],)r   r<   ÚmemberÚ	enumerater   r   r>   r?   r	   r5   rA   rB   )r   r   r3   r   r4   r   Úlist_sectionrI   ÚindexrF   rG   rH   Úlist_section_endr   r   r   r,   •   s   






z&SharedExampleDocumenter._document_listc                 C   s    t |ƒ}| dt |¡ ¡ d S )Nz'%s',)r   r	   r   Ú	text_type)r   r   r3   r4   Ú
safe_valuer   r   r   r2   ¦   s   z%SharedExampleDocumenter._document_strc                 C   s   |  dt|ƒ ¡ d S )Nz%s,)r	   Ústr)r   r   r3   r4   r   r   r   r/   ¬   s   z(SharedExampleDocumenter._document_numberc                 C   sR   t |ƒ ¡ }t|d ƒ}tdt|ƒƒD ]}|dt|| ƒ 7 }q| d| ¡ d S )Nr   é   z, zdatetime(%s),)r   Ú	timetuplerW   ÚrangeÚlenr	   )r   r   r3   r4   Údatetime_tupleÚdatetime_strÚir   r   r   r1   ¯   s
   z*SharedExampleDocumenter._document_datetimec                 C   s0   t  ddd |¡¡}|r||v rd||  S dS )Nz^\.Ú z# )ÚreÚsubÚjoin)r   r4   r   rE   r   r   r   r?   ¶   s   z$SharedExampleDocumenter._get_commentc                 C   s"   |  |¡ |j ¡  |j ¡  d S ©N)r	   r   Úindent)r   r   Ústartr   r   r   r<   ½   s   

z+SharedExampleDocumenter._start_nested_valuec                 C   s,   |j  ¡  |j  ¡  |j  ¡  | |¡ d S rc   )r   Údedentr   r	   )r   r   Úendr   r   r   rB   Â   s   


z)SharedExampleDocumenter._end_nested_valueN)F)Ú__name__Ú
__module__Ú__qualname__r   r   r   r5   r&   r   r,   r2   r/   r1   r?   r<   rB   r   r   r   r   r      s    
ÿr   c                 C   sP   |   d¡}|j ¡  |j d¡ tƒ }|D ]}|j||  |d ¡||d� qdS )a  Documents the shared examples

    :param section: The section to write to.

    :param operation_model: The model of the operation.

    :param example_prefix: The prefix to use in the method example.

    :param shared_examples: The shared JSON examples from the model.
    zshared-examplesÚExamplesÚid)r   r   r   r   N)r   r   r   Úboldr   r   )r   r   Úexample_prefixÚshared_examplesÚcontainer_sectionÚ
documenterr   r   r   r   Údocument_shared_examplesÉ   s   

üÿrr   )r`   r-   Úbotocore.utilsr   Úbotocore.docs.utilsr   Úbotocore.compatr   Úobjectr   rr   r   r   r   r   Ú<module>   s    6