a
    ݌xd#                     @   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   S/var/www/html/Ranjet/env/lib/python3.9/site-packages/botocore/docs/sharedexample.pydocument_shared_example   s    


z/SharedExampleDocumenter.document_shared_examplec           
      C   s   | d}|j  |d u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,||v 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   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