U
    m/e%                     @   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Z	e
dZdZe dZd	d
dddddd
dddddZddddZG dd dZG dd deZdS )    N)OrderedDict)DocStringParser)	ReSTStylez&https://docs.aws.amazon.com/index.htmlzX`AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/[a-z0-9-.]*/[a-zA-Z]*>`_z

    **{}**
    ::

        # This section is too large to render.
        # Please see the AWS API Documentation linked below.

    {}
    ZbcdocszResponse Syntaxi  )name
line_limitzResponse Structurei  zRequest SyntaxZ
Parameters)zresponse-exampledescriptionzrequest-examplezrequest-params      )z
client-apizpaginator-apiz
waiter-apic                   @   sn   e Z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d Zdd Zdd Zdd ZdS )ReSTDocumentmanc                 C   sB   t | | _|| _t| | _d| _d| _i | _i | _g | _	d | _
d S )NTF)r   styletargetr   parser	keep_dataZdo_translationtranslation_maphrefs_writes_last_doc_string)selfr    r   ?/tmp/pip-unpacked-wheel-3gylhwtm/botocore/docs/bcdoc/restdoc.py__init__3   s    

zReSTDocument.__init__c                 C   s   | j r|d k	r| j| d S N)r   r   appendr   sr   r   r   _write>   s    zReSTDocument._writec                 C   s   |  | dS )z2
        Write content into the document.
        N)r   r   contentr   r   r   writeB   s    zReSTDocument.writec                 C   s   |  | j  | d dS )z-
        Write content on a newline.
        
N)r   r   spacesr   r   r   r   writelnH   s    zReSTDocument.writelnc                 C   s
   | j d S )zn
        Returns the last content written to the document without
        removing it from the stack.
        r   r   r   r   r   
peek_writeN   s    zReSTDocument.peek_writec                 C   s   t | jdkr| j S dS )zL
        Removes and returns the last content written to the stack.
        r   N)lenr   popr%   r   r   r   	pop_writeU   s    zReSTDocument.pop_writec                 C   s   | j | dS )z2
        Places new content on the stack.
        N)r   r   r   r   r   r   
push_write[   s    zReSTDocument.push_writec                 C   sD   | j r2| j  | j  D ]\}}| j|| qd| jdS )zJ
        Returns the current content of the document as a string.
         utf-8)r   r   new_paragraphitemslink_target_definitionjoinr   encode)r   refnamelinkr   r   r   getvaluea   s
    
zReSTDocument.getvaluec                    s    fdd|D S )Nc                    s   g | ]} j ||qS r   )r   get).0wr%   r   r   
<listcomp>l   s     z0ReSTDocument.translate_words.<locals>.<listcomp>r   )r   wordsr   r%   r   translate_wordsk   s    zReSTDocument.translate_wordsc                 C   s   |r| j r| | d S r   )r   r   )r   datar   r   r   handle_datan   s    
zReSTDocument.handle_datac                 C   sn   |rjz8t | j}| j| | j  t | j}||f| _W n, tk
rh   tjddd t| Y nX d S )NzError parsing doc stringT)exc_info)	r'   r   r   feedcloser   	ExceptionLOGdebug)r   Z
doc_stringstartendr   r   r   include_doc_stringr   s    


zReSTDocument.include_doc_stringc                 C   s$   | j d k	r | j \}}| j||= d S r   )r   r   )r   rC   rD   r   r   r   remove_last_doc_string~   s    

z#ReSTDocument.remove_last_doc_stringN)r   )__name__
__module____qualname__r   r   r   r"   r&   r)   r*   r4   r:   r<   rE   rF   r   r   r   r   r
   2   s   

r
   c                       s   e Zd Zd" fdd	Zedd Zedd Zejd	d Zed
d Zedd Z	dd Z
d#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  ZS )%DocumentStructureNr   c                    sP   t  j|d || _t | _| jg| _i | _|dk	r:|| _|dk	rL| | dS )a5  Provides a Hierarichial structure to a ReSTDocument

        You can write to it similiar to as you can to a ReSTDocument but
        has an innate structure for more orginaztion and abstraction.

        :param name: The name of the document
        :param section_names: A list of sections to be included
            in the document.
        :param target: The target documentation of the Document structure
        :param context: A dictionary of data to store with the strucuture. These
            are only stored per section not the entire structure.
        )r   N)superr   _namer   
_structure_path_context_generate_structure)r   r   section_namesr   context	__class__r   r   r      s    
zDocumentStructure.__init__c                 C   s   | j S )z"The name of the document structure)rL   r%   r   r   r   r      s    zDocumentStructure.namec                 C   s   | j S )zv
        A list of where to find a particular document structure in the
        overlying document structure.
        rN   r%   r   r   r   path   s    zDocumentStructure.pathc                 C   s
   || _ d S r   rU   )r   valuer   r   r   rV      s    c                 C   s
   t | jS r   )listrM   r%   r   r   r   available_sections   s    z$DocumentStructure.available_sectionsc                 C   s   | j S r   )rO   r%   r   r   r   rR      s    zDocumentStructure.contextc                 C   s   |D ]}|  | qd S r   )add_new_section)r   rQ   section_namer   r   r   rP      s    z%DocumentStructure._generate_structurec                 C   sJ   | j || j|d}| j|g |_| jj|j_| j|_| j|_|| j|< |S )a  Adds a new section to the current document structure

        This document structure will be considered a section to the
        current document structure but will in itself be an entirely
        new document structure that can be written to and have sections
        as well

        :param name: The name of the section.
        :param context: A dictionary of data to store with the strucuture. These
            are only stored per section not the entire structure.
        :rtype: DocumentStructure
        :returns: A new document structure to add to but lives as a section
            to the document structure it was instantiated from.
        )r   r   rR   )rT   r   rV   r   indentationr   r   rM   )r   r   rR   sectionr   r   r   rZ      s      
z!DocumentStructure.add_new_sectionc                 C   s
   | j | S )zRetrieve a sectionrM   r   r   r   r   r   get_section   s    zDocumentStructure.get_sectionc                 C   s   | j |= dS )zDelete a sectionNr^   r_   r   r   r   delete_section   s    z DocumentStructure.delete_sectionc                 C   s
  t | j}|dkrF| jr^| j  | j D ]\}}| j|| q,n|t| jd kr^d}| 	 }| j
 D ]@\}}t| }|r|d d n|}|||7 }qpt | }	t| j}
|dk	r| nt}|
r|	|
d krt|
d | }|S )zFlushes a doc structure to a ReSTructed string

        The document is flushed out in a DFS style where sections and their
        subsections' values are added to the string as they are visited.
           Nr   z

r   r   )r'   rV   r   r   r-   r.   r/   SECTION_METHOD_PATH_DEPTHr5   r4   rM   DOCUMENTATION_LINK_REGEXsearchdecodegroupr1   flush_structure
splitlinesSECTION_LINE_LIMIT_CONFIGr   DEFAULT_AWS_DOCS_LINKLARGE_SECTION_MESSAGEformat)r   Z	docs_linkZpath_lengthr2   r3   rW   r   r]   match
line_countZsection_configZaws_docs_linkr   r   r   rh      s4    


 z!DocumentStructure.flush_structurec                 C   s   d | jdS )Nr+   r,   )r0   r   r1   r%   r   r   r   r4     s    zDocumentStructure.getvaluec                 C   s   t  | _d S r   )r   rM   r%   r   r   r   remove_all_sections
  s    z%DocumentStructure.remove_all_sectionsc                 C   s
   g | _ d S r   r$   r%   r   r   r   
clear_text  s    zDocumentStructure.clear_textc                 C   s   |  d}|j| |S )Ntitle)rZ   r   h1)r   rr   Ztitle_sectionr   r   r   add_title_section  s    
z#DocumentStructure.add_title_sectionc              	   C   sR   t j|st | t j|| d}t|d}||   W 5 Q R X d S )Nz.rstwb)osrV   existsmakedirsr0   openr   rh   )r   	full_path	file_nameZsub_resource_file_pathfr   r   r   write_to_file  s
    
zDocumentStructure.write_to_file)Nr   N)N)N)rG   rH   rI   r   propertyr   rV   setterrY   rR   rP   rZ   r`   ra   rh   r4   rp   rq   rt   r}   __classcell__r   r   rS   r   rJ      s*   






*rJ   )loggingrv   reZbotocore.compatr   Z#botocore.docs.bcdoc.docstringparserr   Zbotocore.docs.bcdoc.styler   rk   compilerd   rl   	getLoggerrA   rj   rc   r
   rJ   r   r   r   r   <module>   s,   

S