U
    db  ã                   @   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                       sl   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dd„ Z‡  ZS )r   Úexamplesc                    sp   t ƒ j||j|d || _| j |¡| _d | _| j| j ¡ krL| j 	|¡| _dddddddg| _
|| _d	| _d S )
N)Úservice_nameÚsessionÚroot_docs_pathÚtitleútable-of-contentsÚclientÚ
paginatorsÚwaitersÚ	resourcesr	   zLhttps://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html)ÚsuperÚ__init__Ú_sessionÚ_boto3_sessionr   Ú_clientÚ_service_resourceÚ_service_nameZget_available_resourcesÚresourceÚsectionsÚ_root_docs_pathÚ_USER_GUIDE_LINK)Úselfr
   r   r   ©Ú	__class__© ú6/tmp/pip-unpacked-wheel-vyj7p4na/boto3/docs/service.pyr      s*    ûù	ÿzServiceDocumenter.__init__c                 C   s   t | j| jdd}|  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ |  | d¡¡ | j	rx|  
| 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   Zget_sectionZtable_of_contentsÚ
client_apiZpaginator_apiZ
waiter_apir   Úresource_sectionÚ_document_examplesZflush_structure)r   Zdoc_structurer!   r!   r"   Údocument_service9   s      ÿz"ServiceDocumenter.document_servicec                 C   sD   d }z|   | j¡}W n tk
r(   Y nX t| j| j|ƒ |¡ d S )N)Zget_examplesr   r   r   r   r   Zdocument_client)r   Úsectionr	   r!   r!   r"   r%   L   s      ÿþzServiceDocumenter.client_apic                 C   s†   |j  d¡ |j  ¡  | d¡ |j jd| jd | d¡ |j  ¡  |j  ¡  | d¡ |j  ¡  |j  ¡  |  |¡ |  |¡ d S )NZ	Resourcesz—Resources are available in boto3 via the ``resource`` method. For more detailed instructions and examples on the usage of resources, see the resources z
user guide)r   ÚlinkÚ.zThe available resources are:)	ÚstyleÚh2Únew_lineÚwriteZexternal_linkr   ZtoctreeÚ_document_service_resourceÚ_document_resources)r   r)   r!   r!   r"   r&   W   s"    
ÿþ






z"ServiceDocumenter.resource_sectionc                 C   s„   t ddd}t| j| j| jƒ |¡ | jjjj}|| j	kr>d}t
j | j| j	› | ¡ › ¡}| |d¡ |j | j	› d|› d¡ d S )Nzservice-resourcer#   ©r$   Úindexú/ú/index)r   r   r   r   r   Údocument_resourceÚmetaÚresource_modelÚnamer   ÚosÚpathÚjoinÚlowerÚwrite_to_filer,   Útocitem)r   r)   Zservice_resource_docÚresource_nameÚservice_resource_dir_pathr!   r!   r"   r0   m   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Ž}|jjj ¡ }t|dd	}t|| j | jƒ | |jjj¡¡ tj | j| j› |› ¡}| |d
¡ |j | j› d|› d¡ q4d S )NZfooZdata_loaderzresources-1r   )r
   Zresource_json_definitionsÚservice_modelZservice_waiter_model)r@   Zsingle_resource_json_definitionZservice_contextr   r#   r2   r3   r4   r5   )r   Zget_componentZload_service_modelr   r   r7   r   rB   r   Zresource_factoryZload_from_definitionr   r8   ÚidentifiersÚappendr   r9   r=   r   r   r   r6   Zadd_new_sectionr:   r;   r<   r>   r,   r?   )r   r)   Ztemp_identifier_valueÚloaderZjson_resource_modelrB   r@   r8   Zresource_clsrC   ÚargsÚ_r   Zresource_docrA   r!   r!   r"   r1   ‚   sZ     ÿÿúýÿ
  ÿýýÿz%ServiceDocumenter._document_resourcesc                 C   s   t j t j | j| jd ¡¡S )Nz.rst)r:   r;   Úrealpathr<   ÚEXAMPLE_PATHr   )r   r!   r!   r"   Ú_get_example_file²   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)
rJ   r:   r;   Úisfiler,   r-   r.   r/   ÚopenÚread)r   r)   Zexamples_fileÚfr!   r!   r"   r'   ·   s    




z$ServiceDocumenter._document_examples)Ú__name__Ú
__module__Ú__qualname__r:   r;   r<   ÚdirnameÚboto3Ú__file__rI   r   r(   r%   r&   r0   r1   rJ   r'   Ú__classcell__r!   r!   r   r"   r      s   0r   )r:   Zbotocore.docs.bcdoc.restdocr   Zbotocore.docs.servicer   ZBaseServiceDocumenterZbotocore.exceptionsr   rS   Zboto3.docs.clientr   Zboto3.docs.resourcer   r   Zboto3.utilsr   r!   r!   r!   r"   Ú<module>   s   