o
    Ü!d}  ã                   @   s>  d dl Z d dlZd dl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mZmZmZmZ e  e¡Zej ej ej e¡¡d
¡Zej ed¡Z ej ed¡Z!G dd„ de"ƒZ#G dd„ de#ƒZ$G dd„ de#ƒZ%G dd„ de#ƒZ&G dd„ de#ƒZ'G dd„ de'ƒZ(G dd„ dƒZ)dS )é    N)Ú
xform_name)ÚStringShape)Úis_json_value_header)ÚSCALAR_TYPES)ÚParamShorthandDocGen)Ú
DOC_EVENTS)Ú
TopicTagDB)Ú%find_service_and_method_in_event_nameÚis_document_typeÚoperation_uses_document_typesÚis_streaming_blob_typeÚis_tagged_union_typeÚexampleszglobal_options.rstzglobal_synopsis.rstc                   @   sÄ   e Z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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 )0ÚCLIDocumentEventHandlerc                 C   s,   || _ |  |j|j¡ |  |¡| _g | _d S ©N)Úhelp_commandÚregisterÚsessionÚevent_classÚ_build_arg_table_groupsÚ_arg_groupsÚ_documented_arg_groups©Úselfr   © r   ú2usr/lib/python3.10/site-packages/awscli/clidocs.pyÚ__init__(   s   
z CLIDocumentEventHandler.__init__c                 C   s6   i }|j  ¡ D ]}|jd ur| |jg ¡ |¡ q|S r   )Ú	arg_tableÚvaluesÚ
group_nameÚ
setdefaultÚappend)r   r   Z
arg_groupsÚargr   r   r   r   .   s   
€z/CLIDocumentEventHandler._build_arg_table_groupsc                 C   s4   t |ƒrdS t|ƒrdS t|ƒrdS t|ƒrdS |S )NZJSONZdocumentzstreaming blobztagged union structure)r   r
   r   r   )r   ÚshapeÚdefaultr   r   r   Ú_get_argument_type_name5   s   z/CLIDocumentEventHandler._get_argument_type_namec                 C   sv   t D ]6}| dd¡}t| |ƒr8t| |ƒ}t | }t| d¡ƒd }|fd|  }	|||	  }
|| }||
||ƒ qd S )Nú-Ú_Ú.é   )Ú*)r   ÚreplaceÚhasattrÚgetattrÚlenÚsplit)r   r   r   ZmapfnÚeventZevent_handler_nameZevent_handlerÚformat_stringÚnum_argsZformat_argsZevent_stringZ	unique_idr   r   r   Ú_map_handlers@   s   

€÷z%CLIDocumentEventHandler._map_handlersc                 C   s   |   |||j¡ dS )a:  
        The default register iterates through all of the
        available document events and looks for a corresponding
        handler method defined in the object.  If it's there, that
        handler method will be registered for the all events of
        that type for the specified ``event_class``.
        N)r3   r   )r   r   r   r   r   r   r   L   s   z CLIDocumentEventHandler.registerc                 C   s    |   | jj| jj| jjj¡ dS )a>  
        The default unregister iterates through all of the
        available document events and looks for a corresponding
        handler method defined in the object.  If it's there, that
        handler method will be unregistered for the all events of
        that type for the specified ``event_class``.
        N)r3   r   r   r   Ú
unregister)r   r   r   r   r4   V   s   
þz"CLIDocumentEventHandler.unregisterc                 K   sŠ   |j }|jdkrC|j d¡}| d¡ | d¡ dg}|d d… D ]}| d¡ | |¡ d |¡}| d	||f ¡ q!| d
¡ d S d S )NÚmanr(   ú[ z:ref:`aws <cli:aws>`Úawséÿÿÿÿú . ú z:ref:`%s <cli:%s>`ú ])ÚdocÚtargetr   r/   Úwriter!   Újoin)r   r   Úkwargsr<   Z	cmd_namesZfull_cmd_listÚcmdZfull_cmd_namer   r   r   Údoc_breadcrumbsd   s   





öz'CLIDocumentEventHandler.doc_breadcrumbsc                 K   sN   |j }|j ¡  |j dd¡}|dkrd| }| d| ¡ |j |j¡ d S )Nr(   r:   r7   zaws z.. _cli:%s:)r<   ÚstyleÚnew_paragraphr   r+   ÚwritelnÚh1Úname)r   r   r@   r<   Ú	referencer   r   r   Ú	doc_titler   s   
z!CLIDocumentEventHandler.doc_titlec                 K   s,   |j }|j d¡ | |j¡ |j ¡  d S ©NÚDescription)r<   rC   Úh2Úinclude_doc_stringÚdescriptionrD   ©r   r   r@   r<   r   r   r   Údoc_description{   ó   z'CLIDocumentEventHandler.doc_descriptionc                 K   s6   g | _ |j}|j d¡ |j ¡  | d|j ¡ d S )NÚSynopsisú%s)r   r<   rC   rL   Ústart_codeblockrE   rG   rO   r   r   r   Údoc_synopsis_start   s
   
z*CLIDocumentEventHandler.doc_synopsis_startc                 K   s¦   |j }|j| }|j| jv r,|j| jv rd S d dd„ | j|j D ƒ¡}| j |j¡ n|j d¡r8d|j }nd|j }|j	sJt
|ddƒsJd	| }| d
| ¡ d S )Nú | c                 S   s   g | ]}|j ‘qS r   ©Úcli_name©Ú.0Úar   r   r   Ú
<listcomp>   s    z?CLIDocumentEventHandler.doc_synopsis_option.<locals>.<listcomp>z--z
%s <value>z<%s>Z_DOCUMENT_AS_REQUIREDFz[%s]rS   )r<   r   r   r   r   r?   r!   rX   Ú
startswithÚrequiredr-   rE   )r   Úarg_namer   r@   r<   ÚargumentZ
option_strr   r   r   Údoc_synopsis_optionˆ   s&   

ÿÿ

ÿz+CLIDocumentEventHandler.doc_synopsis_optionc                 K   s$   |j }| t¡ |j ¡  g | _d S r   )r<   Úwrite_from_fileÚGLOBAL_OPTIONS_SYNOPSIS_FILErC   Úend_codeblockr   rO   r   r   r   Údoc_synopsis_endœ   s   


z(CLIDocumentEventHandler.doc_synopsis_endc                 K   s*   |j }|j d¡ |js| d¡ d S d S )NZOptionsz*None*
)r<   rC   rL   r   r>   rO   r   r   r   Údoc_options_start¦   s
   ÿz)CLIDocumentEventHandler.doc_options_startc                 K   s   |j }|j| }|j| jv r,|j| jv rd S d dd„ | j|j D ƒ¡}| j |j¡ nd|j }| d||  	|j
|j¡f ¡ |j ¡  | |j¡ t|j
ƒrU|  |¡ t|j
ƒra|  |j
|¡ t|dƒrt|  |j
|¡ |  |j
|¡ |j ¡  |j ¡  d S )NrV   c                 S   s   g | ]}d |j  ‘qS )ú``%s``rW   rY   r   r   r   r\   ´   s    z6CLIDocumentEventHandler.doc_option.<locals>.<listcomp>rg   z%s (%s)
Úargument_model)r<   r   r   r   r   r?   r!   rX   r>   r%   rh   Úcli_type_namerC   ÚindentrM   Údocumentationr   Ú_add_streaming_blob_noter   Ú_add_tagged_union_noter,   Ú_document_enumsÚ_document_nested_structureÚdedentrD   )r   r_   r   r@   r<   r`   rG   r   r   r   Ú
doc_option¬   s4   

ÿÿ

ÿ





z"CLIDocumentEventHandler.doc_optionc                 K   s    |j }|j d¡ | t¡ d S )NzGlobal Options)r<   rC   rL   rb   ÚGLOBAL_OPTIONS_FILErO   r   r   r   Údoc_global_optionÇ   ó   z)CLIDocumentEventHandler.doc_global_optionc                 K   s    |j r|j}|j d¡ d S d S )NzSee Also)Zrelated_itemsr<   rC   rL   rO   r   r   r   Údoc_relateditems_startÌ   s   þz.CLIDocumentEventHandler.doc_relateditems_startc                 K   s2   |j }| d¡ |jjd| |d | d¡ d S )Nú* zcli:%s©ÚlabelÚtextÚ
)r<   r>   rC   Úsphinx_reference_label)r   r   Zrelated_itemr@   r<   r   r   r   Údoc_relateditemÑ   s   
þz'CLIDocumentEventHandler.doc_relateditemc                 C   s`   t |tƒr,|jr.|j ¡  | d¡ |j ¡  |jD ]
}|j d| ¡ q|j ¡  dS dS dS )z#Documents top-level parameter enumszPossible values:rg   N)	Ú
isinstancer   ÚenumrC   rD   r>   Ústart_ulÚliÚend_ul)r   Úmodelr<   r~   r   r   r   rn   Ú   s   




ùz'CLIDocumentEventHandler._document_enumsc           
      C   sÊ   t |ddƒ}|dkr!|j ¡ D ]\}}| j||||jgd qdS |dkr3| j|d|j|jgd dS |dkrc|j}|j dd	¡}| j||||jgd |j	}|j dd
¡}	| j||	||jgd dS dS )z5Recursively documents parameters in nested structuresÚ	type_nameNÚ	structure©ÚstackÚlistÚ ÚmaprG   ÚkeyÚvalue)
r-   ÚmembersÚitemsÚ_doc_memberrG   ÚmemberrŠ   ÚserializationÚgetr‹   )
r   r‚   r<   Úmember_type_nameÚmember_nameÚmember_shapeÚ	key_shapeÚkey_nameÚvalue_shapeÚ
value_namer   r   r   ro   å   s"   
ÿÿúz2CLIDocumentEventHandler._document_nested_structurec                 C   sh   |j |v r| |j ¡dkr|jdkr| d¡ d S | |j ¡ z|  ||||¡ W | ¡  d S | ¡  w )Né   r„   z( ... recursive ... ))rG   Úcountrƒ   r>   r!   Ú_do_doc_memberÚpop)r   r<   r“   r”   r†   r   r   r   rŽ   ö   s   


ÿz#CLIDocumentEventHandler._doc_memberc                 C   s.  |j }|  ||j¡}|r| d||f ¡ n| d| ¡ |j ¡  |j ¡  | |¡ t|ƒr6|  	||¡ |j ¡  |j}|dkrU|j
 ¡ D ]\}}	|  |||	|¡ qGn6|dkr~|j}
|
j dd¡}|  |||
|¡ |j}|j dd¡}|  ||||¡ n|dkr‹|  |d	|j|¡ |j ¡  |j ¡  d S )
Nz
%s -> (%s)z(%s)r„   r‰   rG   rŠ   r‹   r‡   rˆ   )rk   r%   rƒ   r>   rC   rj   rD   rM   r   rm   rŒ   r   rŽ   rŠ   r   r‘   r‹   r   rp   )r   r<   r“   r”   r†   Údocsrƒ   r’   Zsub_nameZ	sub_shaper•   r–   r—   r˜   r   r   r   r›     s:   ÿ



ÿ
z&CLIDocumentEventHandler._do_doc_memberc                 C   s&   |j  ¡  d}| |¡ |j  ¡  d S )Nz¤This argument is of type: streaming blob. Its value must be the path to a file (e.g. ``path/to/file``) and must **not** be prefixed with ``file://`` or ``fileb://``)rC   Ú
start_noterE   Úend_note)r   r<   Úmsgr   r   r   rl   #  s   

z0CLIDocumentEventHandler._add_streaming_blob_notec                 C   sH   |j  ¡  d dd„ |j ¡ D ƒ¡}d|› d}| |¡ |j  ¡  d S )Nz, c                 S   s   g | ]}d |› d ‘qS )ú``r   )rZ   rŠ   r   r   r   r\   /  s    zBCLIDocumentEventHandler._add_tagged_union_note.<locals>.<listcomp>zWThis is a Tagged Union structure. Only one of the following top level keys can be set: r(   )rC   rž   r?   rŒ   ÚkeysrE   rŸ   )r   r#   r<   Zmembers_strr    r   r   r   rm   ,  s   
ÿÿ
z.CLIDocumentEventHandler._add_tagged_union_noteN)Ú__name__Ú
__module__Ú__qualname__r   r   r%   r3   r   r4   rB   rI   rP   rU   ra   re   rf   rq   rs   ru   r|   rn   ro   rŽ   r›   rl   rm   r   r   r   r   r   &   s0    
	
		r   c                   @   sL   e Z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 )ÚProviderDocumentEventHandlerc                 K   ó   d S r   r   )r   r   Ú
event_namer@   r   r   r   rB   9  ó   z,ProviderDocumentEventHandler.doc_breadcrumbsc                 K   s0   |j }|j d¡ |j |j¡ | |j¡ d S )NrR   )r<   rC   rL   Z	codeblockZsynopsisrM   Z
help_usagerO   r   r   r   rU   <  s   z/ProviderDocumentEventHandler.doc_synopsis_startc                 K   r§   r   r   ©r   r_   r   r@   r   r   r   ra   B  r©   z0ProviderDocumentEventHandler.doc_synopsis_optionc                 K   s   |j }|j ¡  d S r   )r<   rC   rD   rO   r   r   r   re   E  s   z-ProviderDocumentEventHandler.doc_synopsis_endc                 K   r§   r   r   ©r   r   r@   r   r   r   rf   I  r©   z.ProviderDocumentEventHandler.doc_options_startc                 K   r§   r   r   rª   r   r   r   rq   L  r©   z'ProviderDocumentEventHandler.doc_optionc                 K   ó    |j }|j d¡ |j ¡  d S )NzAvailable Services©r<   rC   rL   ZtoctreerO   r   r   r   Údoc_subitems_startO  rt   z/ProviderDocumentEventHandler.doc_subitems_startc                 K   s"   |j }d| }|jj||d d S )Nú%s/index©Ú	file_name)r<   rC   Útocitem)r   Úcommand_namer   r@   r<   r±   r   r   r   Údoc_subitemT  s   z(ProviderDocumentEventHandler.doc_subitemN)r£   r¤   r¥   rB   rU   ra   re   rf   rq   r®   r´   r   r   r   r   r¦   7  s    r¦   c                   @   sd   e Z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 )ÚServiceDocumentEventHandlerc                 K   r§   r   r   r«   r   r   r   rU   ]  r©   z.ServiceDocumentEventHandler.doc_synopsis_startc                 K   r§   r   r   rª   r   r   r   ra   `  r©   z/ServiceDocumentEventHandler.doc_synopsis_optionc                 K   r§   r   r   r«   r   r   r   re   c  r©   z,ServiceDocumentEventHandler.doc_synopsis_endc                 K   r§   r   r   r«   r   r   r   rf   g  r©   z-ServiceDocumentEventHandler.doc_options_startc                 K   r§   r   r   rª   r   r   r   rq   j  r©   z&ServiceDocumentEventHandler.doc_optionc                 K   r§   r   r   rª   r   r   r   Údoc_option_examplem  r©   z.ServiceDocumentEventHandler.doc_option_examplec                 K   r§   r   r   r«   r   r   r   Údoc_options_endp  r©   z+ServiceDocumentEventHandler.doc_options_endc                 K   r§   r   r   r«   r   r   r   rs   s  r©   z-ServiceDocumentEventHandler.doc_global_optionc                 K   s(   |j }|j}|j d¡ | |j¡ d S rJ   )r<   ÚobjrC   rL   rM   rk   )r   r   r@   r<   Úservice_modelr   r   r   rP   v  s   z+ServiceDocumentEventHandler.doc_descriptionc                 K   r¬   )NzAvailable Commandsr­   rO   r   r   r   r®   }  rt   z.ServiceDocumentEventHandler.doc_subitems_startc                 K   sT   |j }|j| }t|di ƒ}t|ƒdkr"d| }|jj||d d S |j |¡ d S )NÚsubcommand_tabler   r¯   r°   )r<   Zcommand_tabler-   r.   rC   r²   )r   r³   r   r@   r<   Z
subcommandrº   r±   r   r   r   r´   ‚  s   
z'ServiceDocumentEventHandler.doc_subitemN)r£   r¤   r¥   rU   ra   re   rf   rq   r¶   r·   rs   rP   r®   r´   r   r   r   r   rµ   Z  s    rµ   c                   @   sj   e Zd ZdZdd„ Zdd„ Zdd„ 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S )ÚOperationDocumentEventHandlerz'https://docs.aws.amazon.com/goto/WebAPIc                 K   s<   |j }|j}|j d¡ | |j¡ |  |¡ |  |¡ d S rJ   )r<   r¸   rC   rL   rM   rk   Ú_add_webapi_crosslinkÚ$_add_note_for_document_types_if_used)r   r   r@   r<   Úoperation_modelr   r   r   rP   ”  s   
z-OperationDocumentEventHandler.doc_descriptionc                 C   sn   |j }|j}|j}|j d¡}|d u rd S |j ¡  | d¡ d| j||j	f }|jj
d|d | d¡ d S )NÚuidz
See also: z%s/%s/%szAWS API Documentation)ÚtitleÚlinkrˆ   )r<   r¸   r¹   Úmetadatar‘   rC   rD   r>   ÚAWS_DOC_BASErG   Zexternal_linkrE   )r   r   r<   r¾   r¹   Zservice_uidrÁ   r   r   r   r¼     s   

ÿz3OperationDocumentEventHandler._add_webapi_crosslinkc                 C   s0   t |jƒr|jj ¡  |j d|j ¡ d S d S )NaC  ``%s`` uses document type values. Document types follow the JSON data model where valid values are: strings, numbers, booleans, null, arrays, and objects. For command input, options and nested parameters that are labeled with the type ``document`` must be provided as JSON. Shorthand syntax does not support document types.)r   r¸   r<   rC   rD   rE   rG   r   r   r   r   r½   ®  s   
ûÿþzBOperationDocumentEventHandler._add_note_for_document_types_if_usedTc                 C   sJ   t |tƒr|jr|r|j}d dd„ |D ƒ¡S dS |jdkr dS d|j S )Nú|c                 S   s   g | ]}d | ‘qS )z"%s"r   )rZ   Úcr   r   r   r\   À  s    zJOperationDocumentEventHandler._json_example_value_name.<locals>.<listcomp>z"string"Úbooleanz
true|falserS   )r}   r   r~   r?   rƒ   )r   rh   Úinclude_enum_valuesÚchoicesr   r   r   Ú_json_example_value_nameº  s   



z6OperationDocumentEventHandler._json_example_value_namec                 C   sf   |j |v r| |j ¡dkr|jdkr| d¡ d S | |j ¡ z|  |||¡ W | ¡  d S | ¡  w )Nr™   r„   z{ ... recursive ... })rG   rš   rƒ   r>   r!   Ú_do_json_examplerœ   )r   r<   rh   r†   r   r   r   Ú_json_exampleÈ  s   


z+OperationDocumentEventHandler._json_examplec                 C   sn  |j dkrI| d¡ |jj tv r| d|  |j¡ ¡ n&|j ¡  |j ¡  |  ||j|¡ |j ¡  | d¡ |j 	¡  |j ¡  | d¡ d S |j dkr| d¡ |j ¡  |  |j
¡}| d| ¡ |jj tv ru| |  |j¡¡ n|j ¡  |  ||j|¡ |j 	¡  |j ¡  | d¡ |j 	¡  | d	¡ d S |j d
krµ|jr¬|  |¡ d S |  |||¡ d S d S )Nr‡   ú[z%s, ...z...ú]r‰   Ú{z%s: Ú}r„   )rƒ   r>   r   r   rÉ   rC   rj   Únew_linerË   rp   rŠ   r‹   r
   Ú_doc_document_memberÚ_doc_input_structure_members)r   r<   rh   r†   Z
key_stringr   r   r   rÊ   Ö  s>   
















üz.OperationDocumentEventHandler._do_json_examplec                 C   s   |  d¡ d S )Nz{...})r>   )r   r<   r   r   r   rÑ   ù  ó   z2OperationDocumentEventHandler._doc_document_memberc           	      C   s  |  d¡ |j ¡  |j ¡  |j}t|ƒD ]f\}}|| }|j}|tv r2|  d||  |¡f ¡ n8|dkrE|  d| ¡ |  	|||¡ n%|dkrX|  d| ¡ |  	|||¡ n|dkrj|  d| ¡ |  	|||¡ |t
|ƒd k r||  d¡ |j ¡  q|j ¡  |j ¡  |  d	¡ d S )
NrÎ   z"%s": %sr„   z"%s": r‰   r‡   r™   ú,rÏ   )r>   rC   rj   rÐ   rŒ   Ú	enumeraterƒ   r   rÉ   rË   r.   rp   )	r   r<   rh   r†   rŒ   Úir“   Zmember_modelr’   r   r   r   rÒ   ü  s6   



ÿ

€

z:OperationDocumentEventHandler._doc_input_structure_membersc                 K   sš  t |ƒ\}}|j}|j| }|j| jv r|j| jv rd S |j}	tƒ }
|
 |j¡rW|
 	|||¡}|d u r5d S |rW|j
 ¡  | d¡ |j
 ¡  | ¡ D ]}| |¡ qJ|j
 ¡  |	d ur£|	jdkr£|	jjtv r£|	j}|j
 ¡  | d¡ |j
 ¡  | j|dd}| d||f ¡ t|tƒr—|jr—|  ||j¡ |j
 ¡  |j
 ¡  d S |jtvrË|j
 ¡  | d¡ |j
 ¡  | j||	g d |j
 ¡  |j
 ¡  d S d S )	NzShorthand Syntaxr‡   ZSyntaxF)rÇ   z	%s %s ...zJSON Syntaxr…   )r	   r<   r   r   r   r   rh   r   Zsupports_shorthandZgenerate_shorthand_examplerC   rD   r>   rT   Ú
splitlinesrE   rd   rƒ   r   r   rÉ   r}   r   r~   Ú_write_valid_enumsri   rË   )r   r_   r   r¨   r@   Z
service_idZoperation_namer<   Zcli_argumentrh   ZdocgenZexample_shorthand_syntaxZexample_liner   Zexample_typer   r   r   r¶     sX   ÿ
ÿ






ÿ





úz0OperationDocumentEventHandler.doc_option_examplec                 C   s:   |j  ¡  | d¡ |D ]	}| d| ¡ q| d¡ d S )NzWhere valid values are:
z    %s
rz   )rC   rD   r>   )r   r<   Zenum_valuesr‹   r   r   r   rØ   O  s
   

z0OperationDocumentEventHandler._write_valid_enumsc           	      K   sd   |j }|j d¡ |j}|j}|d u s|js| d¡ d S |j ¡ D ]\}}| j|||g d q"d S )NÚOutputÚNoner…   )	r<   rC   rL   r¸   Úoutput_shaperŒ   r>   r   rŽ   )	r   r   r¨   r@   r<   r¾   rÛ   r“   r”   r   r   r   Ú
doc_outputV  s   ÿz(OperationDocumentEventHandler.doc_outputN)T)r£   r¤   r¥   rÃ   rP   r¼   r½   rÉ   rË   rÊ   rÑ   rÒ   r¶   rØ   rÜ   r   r   r   r   r»     s    	
#8r»   c                   @   s`   e Zd Z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 )ÚTopicListerDocumentEventHandleras  This is the AWS CLI Topic Guide. It gives access to a set of topics that provide a deeper understanding of the CLI. To access the list of topics from the command line, run ``aws help topics``. To access a specific topic from the command line, run ``aws help [topicname]``, where ``topicname`` is the name of the topic as it appears in the output from ``aws help topics``.c                 C   s,   || _ |  |j|j¡ tƒ | _| j ¡  d S r   )r   r   r   r   r   Ú_topic_tag_dbZload_json_indexr   r   r   r   r   k  s   z(TopicListerDocumentEventHandler.__init__c                 K   s<   |j }|jdkr| d¡ |jjddd | d¡ d S d S )Nr5   r6   úcli:awsr7   rw   r;   ©r<   r=   r>   rC   r{   rO   r   r   r   rB   q  s   

ýz/TopicListerDocumentEventHandler.doc_breadcrumbsc                 K   s8   |j }|j ¡  |jjd| jj dd |j d¡ d S )Núcli:aws help %srˆ   ©ZrefnamerÁ   zAWS CLI Topic Guide)r<   rC   rD   Úlink_target_definitionr   rG   rF   rO   r   r   r   rI   x  s   

þz)TopicListerDocumentEventHandler.doc_titlec                 K   s,   |j }|j d¡ | | j¡ |j ¡  d S rJ   )r<   rC   rL   rM   ÚDESCRIPTIONrD   rO   r   r   r   rP   €  rQ   z/TopicListerDocumentEventHandler.doc_descriptionc                 K   r§   r   r   r«   r   r   r   rU   †  r©   z2TopicListerDocumentEventHandler.doc_synopsis_startc                 K   r§   r   r   r«   r   r   r   re   ‰  r©   z0TopicListerDocumentEventHandler.doc_synopsis_endc                 K   r§   r   r   r«   r   r   r   rf   Œ  r©   z1TopicListerDocumentEventHandler.doc_options_startc                 K   r§   r   r   r«   r   r   r   r·     r©   z/TopicListerDocumentEventHandler.doc_options_endc                 K   r§   r   r   r«   r   r   r   rs   ’  r©   z1TopicListerDocumentEventHandler.doc_global_optionc           
      K   sÄ   |j }|j d¡ | j d¡}| j ¡ }t| ¡ ƒ}|D ]3}|j |¡ |j 	¡  t|| ƒD ]}| j 
|d¡}	| d¡ |jjd| |d | d|	 ¡ q/q|j ¡  |D ]}|j |¡ qWd S )NzAvailable TopicsÚcategoryrN   rv   rá   rw   z: %s
)r<   rC   rL   rÞ   ÚqueryZget_all_topic_namesÚsortedr¢   Zh3rD   Úget_tag_single_valuer>   r{   Zhidden_toctreeZhidden_tocitem)
r   r   r@   r<   Ú
categoriesZtopic_namesZcategory_namesZcategory_nameZ
topic_namerN   r   r   r   r®   •  s.   

ÿ
þø
ÿz2TopicListerDocumentEventHandler.doc_subitems_startN)r£   r¤   r¥   rä   r   rB   rI   rP   rU   re   rf   r·   rs   r®   r   r   r   r   rÝ   b  s    ÿrÝ   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTopicDocumentEventHandlerc                 K   sV   |j }|jdkr)| d¡ |jjddd | d¡ |jjddd | d	¡ d S d S )
Nr5   r6   rß   r7   rw   r9   zcli:aws help topicsZtopicsr;   rà   rO   r   r   r   rB   µ  s   


þøz)TopicDocumentEventHandler.doc_breadcrumbsc                 K   sH   |j }|j ¡  |jjd| jj dd | j |jd¡}|j |¡ d S )Nrá   rˆ   râ   rÀ   )	r<   rC   rD   rã   r   rG   rÞ   rè   rF   )r   r   r@   r<   rÀ   r   r   r   rI   Á  s   

þÿz#TopicDocumentEventHandler.doc_titlec                 K   s@   |j }tj | jj|jd ¡}|  |¡}| |¡ |j	 
¡  d S )Nz.rst)r<   ÚosÚpathr?   rÞ   Z	topic_dirrG   Ú_remove_tags_from_contentrE   rC   rD   )r   r   r@   r<   Ztopic_filenameÚcontentsr   r   r   rP   Ë  s   ÿ

z)TopicDocumentEventHandler.doc_descriptionc                 C   sl   t |dƒ}| ¡ }W d   ƒ n1 sw   Y  d}t|ƒD ]\}}|  |¡s,|} nqd ||d … ¡S )NÚrr   rˆ   )ÚopenÚ	readlinesrÕ   Ú_line_has_tagr?   )r   ÚfilenameÚfÚlinesZcontent_begin_indexrÖ   Úliner   r   r   rí   Ó  s   
ÿ
þz3TopicDocumentEventHandler._remove_tags_from_contentc                 C   s*   | j jD ]}| d| d ¡r dS qdS )Nú:TF)rÞ   Z
valid_tagsr]   )r   rö   Útagr   r   r   rò   â  s
   ÿz'TopicDocumentEventHandler._line_has_tagc                 K   r§   r   r   r«   r   r   r   r®   è  r©   z,TopicDocumentEventHandler.doc_subitems_startN)	r£   r¤   r¥   rB   rI   rP   rí   rò   r®   r   r   r   r   rê   ³  s    
rê   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚGlobalOptionsDocumenterz4Documenter used to pre-generate global options docs.c                 C   s
   || _ d S r   )Ú_help_commandr   r   r   r   r   ï  s   
z GlobalOptionsDocumenter.__init__c                 C   s   t  dd|¡S )Nz\n+rz   )ÚreÚsub)r   Úsr   r   r   Ú_remove_multilinesò  rÓ   z*GlobalOptionsDocumenter._remove_multilinesc                 C   sÌ   | j }|jD ]R}|j |¡}|j d|j› d|j› d¡ |jj ¡  |jj 	¡  |j 
|j¡ |jrL|jj ¡  |jD ]	}|jj |¡ q<|jj ¡  |jj ¡  |jj 	¡  q|j ¡  d¡}|  |¡S )Nr¡   z`` (ú)úutf-8)rú   r   r‘   r<   rE   rX   ri   rC   rj   rD   rM   rk   rÈ   r   r€   r   rp   ÚgetvalueÚdecoderþ   )r   r   r"   r`   ÚchoiceÚglobal_optionsr   r   r   Údoc_global_optionsõ  s$   
ÿ

z*GlobalOptionsDocumenter.doc_global_optionsc                 C   sl   | j }|jD ]"}|j |¡}|jdkrd|j› d}nd|j› d}|j |¡ q|j ¡  d¡}|  	|¡S )NrÆ   rÌ   rÍ   z	 <value>]r   )
rú   r   r‘   ri   rX   r<   rE   r  r  rþ   )r   r   r"   r`   Zarg_synopsisZglobal_synopsisr   r   r   Údoc_global_synopsis  s   


z+GlobalOptionsDocumenter.doc_global_synopsisN)r£   r¤   r¥   Ú__doc__r   rþ   r  r  r   r   r   r   rù   ì  s    rù   )*Úloggingrë   rû   Zbotocorer   Zbotocore.modelr   Zbotocore.utilsr   Úawsclir   Zawscli.argprocessr   Zawscli.bcdoc.doceventsr   Zawscli.topictagsr   Zawscli.utilsr	   r
   r   r   r   Ú	getLoggerr£   ZLOGrì   r?   ÚdirnameÚabspathÚ__file__ZEXAMPLES_DIRrr   rc   Úobjectr   r¦   rµ   r»   rÝ   rê   rù   r   r   r   r   Ú<module>   s:   
ÿÿ  #6 SQ9