U
    O8ÚcU+  ã                   @   s¤   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZmZmZ d d	lmZ G d
d„ deƒZG dd„ deƒZdS )é    )Ú
xform_name)Úget_official_service_name)ÚActionDocumenter)Údocument_attributeÚdocument_identifierÚdocument_reference)ÚBaseDocumenter)ÚCollectionDocumenter)ÚSubResourceDocumenter)Úadd_resource_type_overviewÚ!get_identifier_args_for_signatureÚget_identifier_descriptionÚ!get_identifier_values_for_example)ÚWaiterResourceDocumenterc                       sŒ   e Z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
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚResourceDocumenterc                    s   t ƒ  |¡ || _d S ©N)ÚsuperÚ__init__Ú_botocore_session)ÚselfÚresourceZbotocore_session©Ú	__class__© ú7/tmp/pip-unpacked-wheel-hml_76kf/boto3/docs/resource.pyr   #   s    zResourceDocumenter.__init__c                 C   sr   |   |¡ |  |¡ | d¡}|  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  	|¡ |  
|¡ d S )Nzmember-overview)Ú
_add_titleÚ
_add_introÚadd_new_sectionÚ_add_identifiersÚ_add_attributesÚ_add_referencesÚ_add_actionsÚ_add_sub_resourcesÚ_add_collectionsÚ_add_waitersÚ_add_overview_of_members)r   ÚsectionZoverview_sectionr   r   r   Údocument_resource'   s    









z$ResourceDocumenter.document_resourcec                 C   s   |j  | j¡ d S r   )ÚstyleÚh2Ú_resource_name©r   r&   r   r   r   r   4   s    zResourceDocumenter._add_titlec                 C   sŽ   g }| j jr&| j jD ]}| |j¡ qt|ƒ}|jj| j› d|› dd | d¡}|  	|¡ | d¡}|  
||¡ | d¡}|  ||¡ d S )Nú(ú))Ú
class_nameÚdescriptionZexampleÚparams)Z_resource_modelÚidentifiersÚappendÚnamer   r(   Zstart_sphinx_py_classr.   r   Ú_add_descriptionÚ_add_exampleÚ_add_params_description)r   r&   Úidentifier_namesÚ
identifierZ
class_argsZdescription_sectionZexample_sectionZparam_sectionr   r   r   r   7   s    ÿ



zResourceDocumenter._add_introc                 C   s"   t | jƒ}| d || j¡¡ d S )Nz A resource representing an {} {})r   Ú_service_modelÚwriteÚformatr*   ©r   r&   Zofficial_service_namer   r   r   r4   P   s    
 ÿÿz#ResourceDocumenter._add_descriptionc                 C   sˆ   |j  ¡  |j  ¡  | d¡ |j  ¡  |j  ¡  | d | j| j¡¡ |j  ¡  t|ƒ}| d t| jƒ| j| j|¡¡ |j  	¡  d S )Núimport boto3z{} = boto3.resource('{}')z{} = {}.{}({}))
r(   Ústart_codeblockÚnew_liner:   r;   Ú_service_namer   r   r*   Úend_codeblock)r   r&   r7   Zexample_valuesr   r   r   r5   X   s,    




 ÿÿ
üÿzResourceDocumenter._add_examplec                 C   sV   |D ]L}t | j|ƒ}| d|› d¡ |j ¡  | d|› d|› ¡ |j ¡  qd S )Nz:type z: stringz:param z: )r   r*   r:   r(   r?   )r   r&   r7   Zidentifier_namer/   r   r   r   r6   o   s     ÿ
z*ResourceDocumenter._add_params_descriptionc                 C   sx   | j D ]l}|j ¡  | d|› d¡ |j ¡  | j | D ]6}|dkr\|j d|› d¡ q:|j d|› d¡ q:qd S )Nz#These are the resource's available ú:)Ú
attributesÚcollectionsr1   Ú
referencesz
:py:attr:`ú`z
:py:meth:`z()`)Ú
member_mapr(   r?   r:   Úli)r   r&   Zresource_member_typeÚmemberr   r   r   r%   y   s    


ÿ
z+ResourceDocumenter._add_overview_of_membersc                 C   sn   | j jjj}| d¡}g }|r8|| jd< t|dddd |D ],}| |j¡}| |j¡ t	|| j
|d q<d S )Nr1   ZIdentifierszYIdentifiers are properties of a resource that are set upon instantiation of the resource.Úidentifiers_attributes_intro©r&   Zresource_typer/   Z
intro_link)r&   Úresource_nameZidentifier_model)Ú	_resourceÚmetaÚresource_modelr1   r   rG   r   r3   r2   r   r*   )r   r&   r1   Zmember_listr8   Zidentifier_sectionr   r   r   r   ‹   s&    

ù	ýz#ResourceDocumenter._add_identifiersc           
   	   C   sÀ   | j jjjj}i }| j jjjr@| | j jjj¡}| j jj |¡}| d¡}g }|rlt	|dddd || j
d< t|ƒD ]F}|| \}}| |¡}	| |¡ t|	| j| j|| j jjjj|d qtd S )NrC   Z
Attributesz”Attributes provide access to the properties of a resource. Attributes are lazy-loaded the first time one is accessed via the :py:meth:`load` method.rJ   rK   )r&   Zservice_namerL   Ú	attr_nameZevent_emitterZ
attr_model)rM   rN   ÚclientÚservice_modelrO   ÚshapeZ	shape_forZget_attributesr   r   rG   Úsortedr2   r   r@   r*   Úevents)
r   r&   rR   rC   rS   Zattribute_listrP   Ú_Z
attr_shapeZattribute_sectionr   r   r   r   £   s>    
ÿ
ÿ
÷


úz"ResourceDocumenter._add_attributesc                 C   sj   |  d¡}| jjjj}g }|r8t|dddd || jd< |D ](}|  |j¡}| |j¡ t	||d q<d S )NrE   Z
ReferenceszNReferences are related resource instances that have a belongs-to relationship.Zreferences_introrK   )r&   Zreference_model)
r   rM   rN   rO   rE   r   rG   r3   r2   r   )r   r&   rE   Zreference_listÚ	referenceZreference_sectionr   r   r   r    É   s$    
ù	
 ÿz"ResourceDocumenter._add_referencesc                 C   s:   |  d¡}| jjjj}|r6t| jƒ}| j|_| |¡ d S )NÚactions)r   rM   rN   rO   rX   r   rG   Zdocument_actions)r   r&   rX   Ú
documenterr   r   r   r!   ß   s    

zResourceDocumenter._add_actionsc                 C   s:   |  d¡}| jjjj}|r6t| jƒ}| j|_| |¡ d S )Nzsub-resources)r   rM   rN   rO   Zsubresourcesr
   rG   Zdocument_sub_resources)r   r&   Zsub_resourcesrY   r   r   r   r"   ç   s    

z%ResourceDocumenter._add_sub_resourcesc                 C   s:   |  d¡}| jjjj}|r6t| jƒ}| j|_| |¡ d S )NrD   )r   rM   rN   rO   rD   r	   rG   Zdocument_collections)r   r&   rD   rY   r   r   r   r#   ï   s    

z#ResourceDocumenter._add_collectionsc                 C   sJ   |  d¡}| jjjj}|rF| j | j¡}t| j|ƒ}| j	|_	| 
|¡ d S )NÚwaiters)r   rM   rN   rO   rZ   r   Zget_waiter_modelr@   r   rG   Zdocument_resource_waiters)r   r&   rZ   Zservice_waiter_modelrY   r   r   r   r$   ÷   s    
ÿ ÿzResourceDocumenter._add_waiters)Ú__name__Ú
__module__Ú__qualname__r   r'   r   r   r4   r5   r6   r%   r   r   r    r!   r"   r#   r$   Ú__classcell__r   r   r   r   r   "   s   
&r   c                   @   s0   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	S )
ÚServiceResourceDocumenterc                 C   s   | j › dS )Nz.ServiceResource)Z_service_docs_name)r   r   r   r   r.     s    z$ServiceResourceDocumenter.class_namec                 C   s   |j  d¡ d S )NzService Resource)r(   r)   r+   r   r   r   r   
  s    z$ServiceResourceDocumenter._add_titlec                 C   s   t | jƒ}| d|› ¡ d S )NzA resource representing )r   r9   r:   r<   r   r   r   r4     s    
z*ServiceResourceDocumenter._add_descriptionc                 C   sZ   |j  ¡  |j  ¡  | d¡ |j  ¡  |j  ¡  | | j› d| j› d¡ |j  ¡  d S )Nr=   z = boto3.resource('z'))r(   r>   r?   r:   r@   rA   )r   r&   r7   r   r   r   r5     s    




ÿz&ServiceResourceDocumenter._add_exampleN)r[   r\   r]   Úpropertyr.   r   r4   r5   r   r   r   r   r_     s
   
r_   N)Zbotocorer   Zbotocore.docs.utilsr   Zboto3.docs.actionr   Zboto3.docs.attrr   r   r   Zboto3.docs.baser   Zboto3.docs.collectionr	   Zboto3.docs.subresourcer
   Zboto3.docs.utilsr   r   r   r   Zboto3.docs.waiterr   r   r_   r   r   r   r   Ú<module>   s    d