o
    ˷e	                     @   sX   d dl Z d dlmZ d dlmZ d dlmZ e dZG dd dZ	G dd	 d	e	Z
dS )
    N)OrderedDict)DocStringParser)	ReSTStylebcdocsc                   @   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   R/var/www/ideatree/venv/lib/python3.10/site-packages/botocore/docs/bcdoc/restdoc.py__init__   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   write&   s   zReSTDocument.writec                 C   s   |  | j  | d dS )z-
        Write content on a newline.
        
N)r   r   spacesr   r   r   r   writeln,   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_write2   s   
zReSTDocument.peek_writec                 C   s
   | j  S )zL
        Removes and returns the last content written to the stack.
        )r   popr"   r   r   r   	pop_write9   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   getvalueE   s
   
zReSTDocument.getvaluec                    s    fdd|D S )Nc                    s   g | ]	} j ||qS r   )r   get).0wr"   r   r   
<listcomp>P   s    z0ReSTDocument.translate_words.<locals>.<listcomp>r   )r   wordsr   r"   r   translate_wordsO      zReSTDocument.translate_wordsc                 C   s    |r| j r| | d S d S d S r   )r   r   )r   datar   r   r   handle_dataR   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)	lenr   r
   feedcloser   	ExceptionLOGdebug)r   
doc_stringstartendr   r   r   include_doc_stringV   s   


zReSTDocument.include_doc_stringc                 C   s(   | j d ur| j \}}| j||= d S d S r   )r   r   )r   rB   rC   r   r   r   remove_last_doc_stringb   s   

z#ReSTDocument.remove_last_doc_stringN)r   )__name__
__module____qualname__r   r   r   r   r#   r%   r&   r0   r6   r9   rD   rE   r   r   r   r   r      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 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   namesection_namesr	   context	__class__r   r   r   j   s   
zDocumentStructure.__init__c                 C      | j S )z"The name of the document structure)rK   r"   r   r   r   rP      s   zDocumentStructure.namec                 C   rU   )zv
        A list of where to find a particular document structure in the
        overlying document structure.
        rM   r"   r   r   r   path   s   zDocumentStructure.pathc                 C   s
   || _ d S r   rV   )r   valuer   r   r   rW         
c                 C   s
   t | jS r   )listrL   r"   r   r   r   available_sections   rY   z$DocumentStructure.available_sectionsc                 C   rU   r   )rN   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   rO      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.
        )rP   r	   rR   )rT   r	   rW   r   indentationr   r   rL   )r   rP   rR   sectionr   r   r   r\      s   
z!DocumentStructure.add_new_sectionc                 C   s
   | j | S )zRetrieve a sectionrL   r   rP   r   r   r   get_section   rY   zDocumentStructure.get_sectionc                 C   s   | j |= dS )zDelete a sectionNr`   ra   r   r   r   delete_section   s   z DocumentStructure.delete_sectionc                 C   sl   t | jdkr | jr | j  | j D ]\}}| j|| q|  }| j D ]
\}}||	 7 }q)|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.
           )
r;   rW   r   r   r)   r*   r+   r0   rL   flush_structure)r   r.   r/   rX   rP   r_   r   r   r   re      s   
z!DocumentStructure.flush_structurec                 C   s   d | jdS )Nr'   r(   )r,   r   r-   r"   r   r   r   r0      r7   zDocumentStructure.getvaluec                 C   s   t  | _d S r   )r   rL   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_text)Nr   Nr   )rF   rG   rH   r   propertyrP   rW   setterr[   rR   rO   r\   rb   rc   re   r0   rf   rg   __classcell__r   r   rS   r   rI   i   s(    





rI   )loggingbotocore.compatr   #botocore.docs.bcdoc.docstringparserr   botocore.docs.bcdoc.styler   	getLoggerr?   r   rI   r   r   r   r   <module>   s   
S