o
    <&ßa¦2  ã                   @   s˜   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl mZ d d	lmZ d
d„ ZG dd„ deƒZG dd„ deƒZdS )é    )Úget_official_service_name©Údocument_custom_method)Údocument_model_driven_method)Úget_instance_public_methods)Údocument_shared_examples)ÚResponseExampleDocumenter)ÚResponseParamsDocumenter)ÚDocumentedShape)ÚOrderedDictc                 K   s   | dkrd S |dv S )NÚgenerate_presigned_url)Ús3© )Úmethod_nameÚservice_nameÚkwargsr   r   ú6/usr/lib/python3/dist-packages/botocore/docs/client.pyÚ!_allowlist_generate_presigned_url   s   r   c                   @   sŒ   e Zd Zeg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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )!ÚClientDocumenterNc                 C   s.   || _ || _| jd u ri | _| j jjj| _d S ©N)Ú_clientÚ_shared_examplesÚmetaÚservice_modelr   Ú_service_name)ÚselfÚclientÚshared_examplesr   r   r   Ú__init__#   s
   
zClientDocumenter.__init__c                 C   s8   |   |¡ |  |¡ |  ¡ }|  ||¡ |  ||¡ dS )z]Documents a client and its methods

        :param section: The section to write to.
        N)Ú
_add_titleÚ_add_class_signatureÚ_get_client_methodsÚ_add_client_introÚ_add_client_methods)r   ÚsectionÚclient_methodsr   r   r   Údocument_client*   s
   

z ClientDocumenter.document_clientc                 C   s   t | jƒ}|  |¡S r   )r   r   Ú_filter_client_methods)r   r%   r   r   r   r!   5   s   

z$ClientDocumenter._get_client_methodsc                 C   s8   i }|  ¡ D ]\}}| j||| jd�}|r|||< q|S )N)Úmethodr   r   )ÚitemsÚ_filter_client_methodr   )r   r%   Úfiltered_methodsr   r(   Úincluder   r   r   r'   9   s   ý€z'ClientDocumenter._filter_client_methodsc                 K   s.   | j D ]}|di |¤Ž}|d ur|  S qdS )NTr   )Ú_CLIENT_METHODS_FILTERS)r   r   ÚfilterÚfilter_includer   r   r   r*   E   s   
ÿz&ClientDocumenter._filter_client_methodc                 C   ó   |j  d¡ d S )NÚClient©ÚstyleÚh2©r   r$   r   r   r   r   O   ó   zClientDocumenter._add_titlec                 C   sš   |  d¡}t| jjjƒ}| d| ¡ |j ¡  | | jjjj	¡ |  
|¡ |j ¡  | d¡ |j ¡  | jjj}t|ƒD ]}|j d||f ¡ q>d S )NÚintroz"A low-level client representing %sz These are the available methods:z:py:meth:`~%s.Client.%s`)Úadd_new_sectionr   r   r   r   Úwriter3   Únew_lineÚinclude_doc_stringÚdocumentationÚ_add_client_creation_exampleÚ	__class__Ú__name__ÚsortedÚli)r   r$   r%   Úofficial_service_nameÚ
class_namer   r   r   r   r"   R   s&   
ÿÿ






ÿÿz"ClientDocumenter._add_client_introc                 C   s   |j jd| jjj d� d S )Nz	%s.Client©rC   )r3   Ústart_sphinx_py_classr   r>   r?   r5   r   r   r   r    h   s   
ÿz%ClientDocumenter._add_class_signaturec                 C   s6   |j  ¡  |j  ¡  | dj| jd�¡ |j  ¡  d S )Nz+client = session.create_client('{service}'))Úservice)r3   Ústart_codeblockr:   r9   Úformatr   Úend_codeblockr5   r   r   r   r=   l   s   

ÿÿz-ClientDocumenter._add_client_creation_examplec                 C   s.   |  d¡}t|ƒD ]}|  |||| ¡ q	d S )NÚmethods)r8   r@   Ú_add_client_method)r   r$   r%   r   r   r   r   r#   u   s   

ÿÿz$ClientDocumenter._add_client_methodsc                 C   s6   |  |¡}|  |¡r|  |||¡ d S |  ||¡ d S r   )r8   Ú_is_custom_methodÚ_add_custom_methodÚ_add_model_driven_method©r   r$   r   r(   r   r   r   rK   {   s   

z#ClientDocumenter._add_client_methodc                 C   s   || j jjvS r   )r   r   Úmethod_to_api_mapping)r   r   r   r   r   rL   ‚   s   z"ClientDocumenter._is_custom_methodc                 C   s   t |||ƒ d S r   r   rO   r   r   r   rM   …   r6   z#ClientDocumenter._add_custom_methodc                 C   sb   |  d¡}|j ¡  |j d¡ |j ¡  | jjj}|jD ]}d||jf }|j 	d| ¡ qd S )NÚ
exceptionsÚ
Exceptionsú%s.Client.exceptions.%sú:py:class:`%s`)
r8   r3   r:   Úboldr   r>   r?   Úerror_shapesÚnamerA   )r   r$   Úoperation_modelÚerror_sectionÚclient_nameÚerrorrC   r   r   r   Ú_add_method_exceptions_listˆ   s   




þz,ClientDocumenter._add_method_exceptions_listc                 C   s~   | j jj}| j jj| }| |¡}d| }t|||| j jj|j|d� |jr,|  	||¡ | j
 |¡}|r=t||||ƒ d S d S )Nzresponse = client.%s)Úevent_emitterÚmethod_descriptionÚexample_prefix)r   r   r   rP   rX   r   Úeventsr<   rV   r\   r   Úgetr   )r   r$   r   r   Úoperation_namerX   r_   r   r   r   r   rN   ’   s$   

üÿÿz)ClientDocumenter._add_model_driven_methodr   )r?   Ú
__module__Ú__qualname__r   r-   r   r&   r!   r'   r*   r   r"   r    r=   r#   rK   rL   rM   r\   rN   r   r   r   r   r      s$    ÿ

	
r   c                   @   s´   e Zd ZdZedddededddd�fd	ed	dd
d�fgƒ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d(S ))ÚClientExceptionsDocumenterzQhttps://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.htmlÚErrorÚ	structurez1Normalized access to common exception attributes.ÚCodeÚstringz,An identifier specifying the exception type.)rW   Ú	type_namer<   ÚMessagez;A descriptive message explaining why the exception occured.)rW   rj   r<   Úmembersc                 C   s   || _ | j jjj| _d S r   )r   r   r   r   r   )r   r   r   r   r   r   È   s   z#ClientExceptionsDocumenter.__init__c                 C   s,   |   |¡ |  |¡ |  |¡ |  |¡ d S r   )r   Ú_add_overviewÚ_add_exceptions_listÚ_add_exception_classesr5   r   r   r   Údocument_exceptionsÌ   s   


z.ClientExceptionsDocumenter.document_exceptionsc                 C   r0   )NzClient Exceptionsr2   r5   r   r   r   r   Ò   r6   z%ClientExceptionsDocumenter._add_titlec                 C   s>   |j  ¡  | d¡ |j jd| jd� | d¡ |j  ¡  d S )NzÂClient exceptions are available on a client instance via the ``exceptions`` property. For more detailed instructions and examples on the exact usage of client exceptions, see the error handling z
user guide)ÚtitleÚlinkÚ.)r3   r:   r9   Úexternal_linkÚ_USER_GUIDE_LINKr5   r   r   r   rm   Õ   s   
ÿþ
z(ClientExceptionsDocumenter._add_overviewc                 C   s   | j jj}d||jf S )NrS   )r   r>   r?   rW   )r   ÚshapeÚcls_namer   r   r   Ú_exception_class_nameä   s   
z0ClientExceptionsDocumenter._exception_class_namec                 C   sx   | j jjj}|s|j ¡  | d¡ |j ¡  d S |j ¡  | d¡ |j ¡  |D ]}|  |¡}|j d| ¡ q*d S )Nz-This client has no modeled exception classes.z$The available client exceptions are:rT   )	r   r   r   rV   r3   r:   r9   rx   rA   )r   r$   rV   rv   rC   r   r   r   rn   è   s   






þz/ClientExceptionsDocumenter._add_exceptions_listc                 C   s"   | j jjjD ]}|  ||¡ qd S r   )r   r   r   rV   Ú_add_exception_class©r   r$   rv   r   r   r   ro   ö   s   ÿz1ClientExceptionsDocumenter._add_exception_classesc                 C   sV   |  |j¡}|  |¡}|jj|d� |  ||¡ |  ||¡ |  ||¡ |j ¡  d S )NrD   )	r8   rW   rx   r3   rE   Ú_add_top_level_documentationÚ_add_exception_catch_exampleÚ_add_response_attrÚend_sphinx_py_class)r   r$   rv   Úclass_sectionrC   r   r   r   ry   ú   s   
z/ClientExceptionsDocumenter._add_exception_classc                 C   s.   |j r|j ¡  | |j ¡ |j ¡  d S d S r   )r<   r3   r:   r;   rz   r   r   r   r{     s
   
ýz7ClientExceptionsDocumenter._add_top_level_documentationc                 C   s¢   |j  ¡  |j  d¡ |j  ¡  | d¡ |j  ¡  |j  ¡  | d¡ |j  ¡  |j  ¡  | d|j ¡ |j  ¡  |j  ¡  | d¡ |j  ¡  |j  ¡  d S )NÚExampleztry:z...z!except client.exceptions.%s as e:zprint(e.response))	r3   r:   rU   rG   r9   ÚindentÚdedentrW   rI   rz   r   r   r   r|   	  s   











z7ClientExceptionsDocumenter._add_exception_catch_examplec                 C   sF   |  d¡}|j d¡ |  |¡ |  ||¡ |  ||¡ |j ¡  d S )NÚresponse)r8   r3   Ústart_sphinx_py_attrÚ_add_response_attr_descriptionÚ_add_response_exampleÚ_add_response_paramsÚend_sphinx_py_attr)r   r$   rv   Úresponse_sectionr   r   r   r}     s   

z-ClientExceptionsDocumenter._add_response_attrc                 C   s"   |j  ¡  | d¡ |j  ¡  d S )NzÈThe parsed error response. All exceptions have a top level ``Error`` key that provides normalized access to common exception atrributes. All other keys are specific to this service or exception class.)r3   r:   r;   r5   r   r   r   r…   "  s
   
ÿz9ClientExceptionsDocumenter._add_response_attr_descriptionc                 C   sX   |  d¡}|j ¡  |j d¡ |j ¡  t| jd | jjj	d�}|j
||| jgd� d S )NÚsyntaxÚSyntax©r   rb   r]   ©r,   )r8   r3   r:   rU   Únew_paragraphr   r   r   r   r`   Údocument_exampleÚ_GENERIC_ERROR_SHAPE)r   r$   rv   Úexample_sectionÚ
documenterr   r   r   r†   ,  ó   


ý

ÿz0ClientExceptionsDocumenter._add_response_examplec                 C   sX   |  d¡}|j ¡  |j d¡ |j ¡  t| jd | jjj	d�}|j
||| jgd� d S )NÚ	StructurerŒ   r�   )r8   r3   r:   rU   rŽ   r	   r   r   r   r`   Údocument_paramsr�   )r   r$   rv   Úparams_sectionr’   r   r   r   r‡   :  r“   z/ClientExceptionsDocumenter._add_response_paramsN)r?   rc   rd   ru   r
   r   r�   r   rp   r   rm   rx   rn   ro   ry   r{   r|   r}   r…   r†   r‡   r   r   r   r   re   ª   sD    ÿüüøú	
re   N)Úbotocore.docs.utilsr   Úbotocore.docs.methodr   r   r   Úbotocore.docs.sharedexampler   Úbotocore.docs.exampler   Úbotocore.docs.paramsr	   r
   Úbotocore.compatr   r   Úobjectr   re   r   r   r   r   Ú<module>   s    