o
    	Jh+&                     @   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.

    {}
    bcdocszResponse Syntaxi  )name
line_limitzResponse Structurei  zRequest Syntax
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_datado_translationtranslation_maphrefs_writes_last_doc_string)selfr    r   {/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/botocore/docs/bcdoc/restdoc.py__init__3   s   


zReSTDocument.__init__c                 C   s&   | j r|d ur| j| d S d S 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 r| 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      zReSTDocument.translate_wordsc                 C   s    |r| j r| | d S d S d S r   )r   r   )r   datar   r   r   handle_datan   s   
zReSTDocument.handle_datac                 C   sp   |r6zt | j}| j| | j  t | j}||f| _W d S  ty5   tjddd t| Y d S w d S )NzError parsing doc stringT)exc_info)	r*   r   r   feedcloser   	ExceptionLOGdebug)r   
doc_stringstartendr   r   r   include_doc_stringr   s   


zReSTDocument.include_doc_stringc                 C   s(   | j d ur| j \}}| j||= d S d S r   )r   r   )r   rH   rI   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-   r7   r=   r@   rJ   rK   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 Zd%ddZdd Zdd Zdd Zd d! Zd"d# Z  ZS )&DocumentStructureNr   c                    sT   t  j|d || _t | _| jg| _i | _|dur|| _|dur(| | dS 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      | j S )z"The name of the document structure)rQ   r(   r   r   r   r      s   zDocumentStructure.namec                 C   rZ   )zv
        A list of where to find a particular document structure in the
        overlying document structure.
        rS   r(   r   r   r   path   s   zDocumentStructure.pathc                 C   s
   || _ d S r   r[   )r   valuer   r   r   r\         
c                 C   s
   t | jS r   )listrR   r(   r   r   r   available_sections   r^   z$DocumentStructure.available_sectionsc                 C   rZ   r   )rT   r(   r   r   r   rW      s   zDocumentStructure.contextc                 C   s   |D ]}|  | qd S r   )add_new_section)r   rV   section_namer   r   r   rU      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   rW   )rY   r   r\   r   indentationr   r   rR   )r   r   rW   sectionr   r   r   ra      s   
z!DocumentStructure.add_new_sectionc                 C   s
   | j | S )zRetrieve a sectionrR   r   r   r   r   r   get_section   r^   zDocumentStructure.get_sectionc                 C   s
   || j v S r   re   rf   r   r   r   has_section      
zDocumentStructure.has_sectionc                 C   s   | j |= dS )zDelete a sectionNre   rf   r   r   r   delete_section   s   z DocumentStructure.delete_sectionc                 C   s  t | j}|dkr#| jr"| j  | j D ]\}}| j|| qn|t| jd kr/d}| 	 }| j
 D ] \}}t| }|rO|d d n|}|||7 }q8t | }	t| j}
|durm| nt}|
r|	|
d krt|
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*   r\   r   r   r0   r1   r2   SECTION_METHOD_PATH_DEPTHr8   r7   rR   DOCUMENTATION_LINK_REGEXsearchdecodegroupr4   flush_structure
splitlinesSECTION_LINE_LIMIT_CONFIGr   DEFAULT_AWS_DOCS_LINKLARGE_SECTION_MESSAGEformat)r   	docs_linkpath_lengthr5   r6   r]   r   rd   match
line_countsection_configaws_docs_linkr   r   r   rq      s8   

z!DocumentStructure.flush_structurec                 C   s   d | jdS )Nr.   r/   )r3   r   r4   r(   r   r   r   r7   
  r>   zDocumentStructure.getvaluec                 C   s   t  | _d S r   )r   rR   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  ri   zDocumentStructure.clear_textc                 C   s   |  d}|j| |S )Ntitle)ra   r   h1)r   r   title_sectionr   r   r   add_title_section  s   
z#DocumentStructure.add_title_sectionc                 C   sh   t j|st | t j|| d}t|d}||   W d    d S 1 s-w   Y  d S )Nz.rstwb)osr\   existsmakedirsr3   openr"   rq   )r   	full_path	file_namesub_resource_file_pathfr   r   r   write_to_file  s   
"zDocumentStructure.write_to_file)Nr   Nr   )rL   rM   rN   r   propertyr   r\   setterr`   rW   rU   ra   rg   rh   rj   rq   r7   r}   r~   r   r   __classcell__r   r   rX   r   rO      s.    






*rO   )loggingr   rebotocore.compatr   #botocore.docs.bcdoc.docstringparserr   botocore.docs.bcdoc.styler   rt   compilerm   ru   	getLoggerrE   rs   rl   r   rO   r   r   r   r   <module>   s.   

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