
    Pe#                     F    d dl Z d dlZd dlmZ d dlmZ  G d d      Zd Zy)    N)escape_controls)parse_timestampc                   ^    e Zd Zd Zd Zd Zd Z	 ddZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)SharedExampleDocumenterc                 "   |j                   j                          |j                  |j                  d             |j                   j	                          | j                  ||||j                         | j                  |||j                         y)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_models        =/usr/lib/python3/dist-packages/botocore/docs/sharedexample.pydocument_shared_examplez/SharedExampleDocumenter.document_shared_example   sp     	##%gkk-01 Wfo&A&A	
 	Wg/K/KL    c                    |j                  d      }|j                  j                          ||j                  |       |j	                  di       }|j	                  d      }|r|j	                  d      }|j                  d      }| j                  |||g |       |j                  d      }	|	j                  j                          |	j                  j                          |	j                  d       |	j                  j                          y )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_sections
             r   r   z&SharedExampleDocumenter.document_input*   s    //8++-'Wb);;z*||G,H%55lCmVXr5I'77F&&(&&(/0++-r   c                    |j                  d      }|j                  j                          |j                  d       |j                  j                          |j                  j	                          |j                  di       }ddi|d<   |j                  d      }|r|j                  d      }| j                  |||g |d       |j                  d      }|j                  j                          y )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&   s           r   r   z'SharedExampleDocumenter.document_output;   s     00:%%'/0%%',,.Xr* ',U^!";;z*||H-HNFHb%N(88H++-r   c                 h   t        |t              r| j                  |||||       yt        |t              r| j	                  |||||       yt        |t
        j                        r| j                  |||       y|r#|j                  dk(  r| j                  |||       y| j                  |||       y)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"   s         r   	_documentz!SharedExampleDocumenter._documentL   s     eT"$Ft$$Fw~~.!!'5$7u+5##GUD9wt4r   c                    |j                  d      }| j                  |d       |j                         D ]  \  }}	|j                  d|z         |j                  |      }
|
j                  j                          | j                  ||      }|r+|
j                  |       |
j                  j                          |
j                  d|z         d }|rF|j                  dk(  r|j                  j                  |      }n|j                  dk(  r|j                  }| j                  |
|	|||       |j                          
 |j                  d      }| j                  |d       |s|j                  d	       y y )
Nz
dict-value{.%sz'%s': 	structuremapzending-brace},)r   _start_nested_valueitemsappendr	   r   _get_commentr   r5   membersr   r8   r:   pop_end_nested_value)r   r   r8   r   r9   r"   	top_leveldict_sectionkeyvalitem_sectionitem_comment
item_shapedict_section_ends                 r   r*   z&SharedExampleDocumenter._document_dicte   sL    ..|<  s3 	HCKK$'77<L''),,T8<L""<0""++-x#~. J??k1!&!2!23!7J__-!&JNN<hjIHHJ%	& (77G/5""3' r   c                 l   |j                  d      }| j                  |d       |j                         D ]  \  }}|j                  d|z         |j                  |      }	|	j                  j                          | j                  ||      }
|
r+|	j                  |
       |	j                  j                          |	j                  |dz          d }|r|j                  j                  |      }| j                  |	||||       |j                           |j                  d      }| j                  |d       y )Nzparam-values(r=   =zending-parenthesis))r   rB   rC   rD   r	   r   rE   r   rF   r   r:   rG   rH   )r   r   r8   r   r9   r"   r%   rK   rL   rM   rN   rO   param_section_ends                r   r    z(SharedExampleDocumenter._document_params   s   //?  4 	HCKK$(88=L''),,T8<L""<0""++-sSy) J"]]..s3
NN<hjIHHJ	  *99:NO0#6r   c                    |j                  d      }| j                  |d       |j                  }t        |      D ]  \  }}	|j                  |      }
|
j                  j                          |j                  d|z         | j                  ||      }|r+|
j                  |       |
j                  j                          | j                  |
|	|||       |j                           |j                  d      }| j                  |d       y )Nzlist-section[z[%s]zending-bracketz],)r   rB   member	enumerater	   r   rD   rE   r   r:   rG   rH   )r   r   r8   r   r9   r"   list_sectionrO   indexrL   rM   rN   list_section_ends                r   r1   z&SharedExampleDocumenter._document_list   s    ..~>  s3\\
#E* 		JE3'77>L'')KK',,T8<L""<0""++-NN<hjIHHJ		 (778HI/6r   c                 D    t        |      }|j                  d| d       y )N'z',)r   r   )r   r   r8   r9   
safe_values        r   r7   z%SharedExampleDocumenter._document_str   s#     %U+
*R()r   c                 >    |j                  dt        |      z         y )Nz%s,)r   str)r   r   r8   r9   s       r   r4   z(SharedExampleDocumenter._document_number   s    ec%j()r   c                     t        |      j                         }t        |d         }t        dt	        |            D ]  }|dt        ||         z   z  } |j                  d|z         y )Nr      z, zdatetime(%s),)r   	timetuplera   rangelenr   )r   r   r8   r9   datetime_tupledatetime_stris          r   r6   z*SharedExampleDocumenter._document_datetime   si    (/99;>!,-q#n-. 	:AD3~a'8#999L	:o45r   c                 l    t        j                  dddj                  |            }|r||v rd||   z   S y)Nz^\. z# )resubjoin)r   r9   r   rK   s       r   rE   z$SharedExampleDocumenter._get_comment   s7    ffVR/x(3-''r   c                     |j                  |       |j                  j                          |j                  j                          y N)r   r	   indent)r   r   starts      r   rB   z+SharedExampleDocumenter._start_nested_value   s.    er   c                     |j                   j                          |j                   j                          |j                   j                          |j                  |       y rp   )r	   dedentr   r   )r   r   ends      r   rH   z)SharedExampleDocumenter._end_nested_value   s>     cr   N)F)__name__
__module____qualname__r   r   r   r:   r*   r    r1   r7   r4   r6   rE   rB   rH    r   r   r   r      sK    M*."."54 @E(:7,7"**6
r   r   c                     | j                  d      }|j                  j                          |j                  j                  d       t	               }|D ])  }|j                  ||j                  |d         ||       + y)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   s          r   document_shared_examplesr      s      //0AB))+  ,(*J" 
**%55gdmD!+	 	+ 	

r   )r2   rl   botocore.docs.utilsr   botocore.utilsr   r   r   ry   r   r   <module>r      s%     	 / *u up
r   