U
    N8Úcþ#  ã                   @   sB   d dl Z d dlZd dlmZ d dlmZ G dd„ dƒZdd„ ZdS )é    N)Úescape_controls)Úparse_timestampc                   @   sv   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_inputZinput_shapeÚdocument_outputZoutput_shape)ÚselfÚexampleÚprefixÚsectionÚoperation_model© r   ú?/tmp/pip-unpacked-wheel-ozje0y8b/botocore/docs/sharedexample.pyÚdocument_shared_example   s    

   ÿz/SharedExampleDocumenter.document_shared_examplec           
      C   sœ   |  d¡}|j ¡  |d k	r&| |¡ | di ¡}| d¡}|rJ| 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   ÚshapeZ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¡}|rb| d¡}|  |||g |d¡ |  d¡}|j ¡  d S )NÚoutputzExpected Output:z...ZResponseMetadatar   Tzoutput-close)r   r   r
   r   r   r	   Ú_document_dictr   )r   r   r   r   Zoutput_sectionr   r   r   r   r   r   r   ;   s    







z'SharedExampleDocumenter.document_outputc                 C   sˆ   t |tƒr|  |||||¡ nft |tƒr<|  |||||¡ nHt |tjƒrX|  |||¡ n,|rv|jdkrv|  	|||¡ n|  
|||¡ 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   Ú	_documentL   s    

z!SharedExampleDocumenter._documentFc                 C   sî   |  d¡}|  |d¡ | ¡ D ]¦\}}	| d| ¡ |  |¡}
|
j ¡  |  ||¡}|rl|
 |¡ |
j ¡  |
 d| ¡ d }|rª|jdkrš|j	 
|¡}n|jdkrª|j}|  |
|	|||¡ | ¡  q|  d¡}|  |d¡ |sê| d	¡ d S )
Nz
dict-valueÚ{ú.%sz'%s': Z	structureÚmapzending-braceÚ}ú,)r   Ú_start_nested_valueÚitemsÚappendr   r
   Ú_get_commentr   r*   Úmembersr	   r-   r/   ÚpopÚ_end_nested_value)r   r   r-   r   r.   r   Z	top_levelZdict_sectionÚkeyÚvalÚitem_sectionÚitem_commentÚ
item_shapeZdict_section_endr   r   r   r!   e   s.    








z&SharedExampleDocumenter._document_dictc                 C   sÄ   |  d¡}|  |d¡ | ¡ D ]Š\}}| d| ¡ |  |¡}	|	j ¡  |  ||¡}
|
rl|	 |
¡ |	j ¡  |	 |d ¡ d }|rŽ|j 	|¡}|  
|	||||¡ | ¡  q|  d¡}|  |d¡ d S )Nzparam-valuesú(r1   ú=zending-parenthesisú))r   r5   r6   r7   r   r
   r8   r   r9   r	   r/   r:   r;   )r   r   r-   r   r.   r   r   r<   r=   r>   r?   r@   Zparam_section_endr   r   r   r   ‚   s$    






z(SharedExampleDocumenter._document_paramsc                 C   s¨   |  d¡}|  |d¡ |j}t|ƒD ]h\}}	|  |¡}
|
j ¡  | d| ¡ |  ||¡}|rr|
 |¡ |
j ¡  |  	|
|	|||¡ | 
¡  q$|  d¡}|  |d¡ d S )Nzlist-sectionú[z[%s]zending-bracketz],)r   r5   ÚmemberÚ	enumerater   r
   r7   r8   r   r/   r:   r;   )r   r   r-   r   r.   r   Zlist_sectionr@   Úindexr=   r>   r?   Zlist_section_endr   r   r   r&   ˜   s    






z&SharedExampleDocumenter._document_listc                 C   s   t |ƒ}| d|› d¡ d S )Nú'z',)r   r   )r   r   r-   r.   Z
safe_valuer   r   r   r,   ©   s    z%SharedExampleDocumenter._document_strc                 C   s   |  dt|ƒ ¡ d S )Nz%s,)r   Ústr)r   r   r-   r.   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   Ú	timetuplerI   ÚrangeÚlenr   )r   r   r-   r.   Zdatetime_tupleZdatetime_strÚir   r   r   r+   ²   s
    z*SharedExampleDocumenter._document_datetimec                 C   s4   t  ddd |¡¡}|r,||kr,d||  S dS d S )Nz^\.Ú z# )ÚreÚsubÚjoin)r   r.   r   r<   r   r   r   r8   ¹   s    z$SharedExampleDocumenter._get_commentc                 C   s"   |  |¡ |j ¡  |j ¡  d S ©N)r   r   Úindent)r   r   Ústartr   r   r   r5   À   s    

z+SharedExampleDocumenter._start_nested_valuec                 C   s,   |j  ¡  |j  ¡  |j  ¡  | |¡ d S rS   )r   Údedentr
   r   )r   r   Úendr   r   r   r;   Å   s    


z)SharedExampleDocumenter._end_nested_valueN)F)Ú__name__Ú
__module__Ú__qualname__r   r   r   r/   r!   r   r&   r,   r)   r+   r8   r5   r;   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-examplesZExamplesÚid)r   r   r   r   N)r   r   r   Zboldr   r   )r   r   Zexample_prefixZshared_examplesZcontainer_sectionZ
documenterr   r   r   r   Údocument_shared_examplesÌ   s    

ür\   )r'   rP   Zbotocore.docs.utilsr   Zbotocore.utilsr   r   r\   r   r   r   r   Ú<module>   s    9