U
    O8ÚcJ  ã                   @   sp   d dl Z d dlmZ d dlmZ d dlmZ d dlZd dl	m
Z
 d dlmZmZ d dlmZ G dd	„ d	eƒZdS )
é    N)ÚDocumentStructure)ÚServiceDocumenter)ÚDataNotFoundError)ÚBoto3ClientDocumenter)ÚResourceDocumenterÚServiceResourceDocumenter)ÚServiceContextc                       sd   e Zd Zej ej ej¡d¡Z	‡ fdd„Z
dd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z‡  ZS )r   Úexamplesc                    sd   t ƒ j||jd || _| j |¡| _d | _| j| j ¡ krJ| j 	|¡| _dddddddd	g| _
d S )
N)Úservice_nameÚsessionÚtitleútable-of-contentsÚclientÚ
paginatorsÚwaitersúservice-resourceÚ	resourcesr	   )ÚsuperÚ__init__Ú_sessionÚ_boto3_sessionr   Ú_clientÚ_service_resourceÚ_service_nameZget_available_resourcesÚresourceÚsections)Úselfr
   r   ©Ú	__class__© ú6/tmp/pip-unpacked-wheel-hml_76kf/boto3/docs/service.pyr      s$    üøzServiceDocumenter.__init__c                 C   s    t | j| jdd}|  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ | j	rˆ|  
| d¡¡ |  | d	¡¡ |  | d
¡¡ | ¡ S )ziDocuments an entire service.

        :returns: The reStructured text of the documented service.
        Úhtml)Zsection_namesÚtargetr   r   r   r   r   r   r   r	   )r   r   r   r   Zget_sectionZtable_of_contentsÚ
client_apiZpaginator_apiZ
waiter_apir   Ú_document_service_resourceÚ_document_resourcesÚ_document_examplesZflush_structure)r   Zdoc_structurer   r   r    Údocument_service4   s"      ÿÿz"ServiceDocumenter.document_servicec                 C   s@   d }z|   | j¡}W n tk
r(   Y nX t| j|ƒ |¡ d S ©N)Zget_examplesr   r   r   r   Zdocument_client)r   Úsectionr	   r   r   r    r#   J   s    zServiceDocumenter.client_apic                 C   s   t | j| jƒ |¡ d S r(   )r   r   r   Údocument_resource)r   r)   r   r   r    r$   S   s     ÿþz,ServiceDocumenter._document_service_resourcec              
   C   sÀ   d}| j  d¡}| | jd¡}| jjjjj}|d D ]†}|d | }| jj	j
||t| j|d |d dd}|jjj}	g }
|	D ]}|
 |¡ q|||
d| jiŽ}t|| j ƒ | |jjj¡¡ q4d S )NZfooZdata_loaderzresources-1r   )r
   Zresource_json_definitionsÚservice_modelZservice_waiter_model)Úresource_nameZsingle_resource_json_definitionZservice_contextr   )r   Zget_componentZload_service_modelr   r   Úmetar   r+   r   Zresource_factoryZload_from_definitionr   Úresource_modelÚidentifiersÚappendr   r   r*   Zadd_new_sectionÚname)r   r)   Ztemp_identifier_valueÚloaderZjson_resource_modelr+   r,   r.   Zresource_clsr/   ÚargsÚ_r   r   r   r    r%   X   s<     ÿÿúýÿ
ÿz%ServiceDocumenter._document_resourcesc                 C   s   t j t j | j| jd ¡¡S )Nz.rst)ÚosÚpathÚrealpathÚjoinÚEXAMPLE_PATHr   )r   r   r   r    Ú_get_example_filex   s    ÿz#ServiceDocumenter._get_example_filec              	   C   sn   |   ¡ }tj |¡rj|j d¡ |j ¡  | d¡ |j ¡  |j ¡  t|ƒ}| | 	¡ ¡ W 5 Q R X d S )NZExamplesz'.. contents::
    :local:
    :depth: 1)
r:   r5   r6   ÚisfileÚstyleÚh2Únew_lineÚwriteÚopenÚread)r   r)   Zexamples_fileÚfr   r   r    r&   }   s    




z$ServiceDocumenter._document_examples)Ú__name__Ú
__module__Ú__qualname__r5   r6   r8   ÚdirnameÚboto3Ú__file__r9   r   r'   r#   r$   r%   r:   r&   Ú__classcell__r   r   r   r    r      s   	 r   )r5   Zbotocore.docs.bcdoc.restdocr   Zbotocore.docs.servicer   ZBaseServiceDocumenterZbotocore.exceptionsr   rG   Zboto3.docs.clientr   Zboto3.docs.resourcer   r   Zboto3.utilsr   r   r   r   r    Ú<module>   s   