o .&a,@sZddlZddlmZddlmZddlmZedZGddde Z Gdd d e Z dS) N) OrderedDict)DocStringParser) ReSTStylebcdocsc@sneZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZdS) ReSTDocumentmancCsBt||_||_t||_d|_d|_i|_i|_g|_ d|_ dS)NTF) rstyletargetrparser keep_datado_translationtranslation_maphrefs_writes_last_doc_string)selfr r6/usr/lib/python3/dist-packages/awscli/bcdoc/restdoc.py__init__s   zReSTDocument.__init__cCs&|jr|dur|j|dSdSdSN)r rappendrsrrr_write#szReSTDocument._writecCs||dS)z2 Write content into the document. N)rrcontentrrrwrite'szReSTDocument.writecCs|d|j|fdS)z- Write content on a newline. z%s%s N)rrspacesrrrrwriteln-szReSTDocument.writelncCs |jdS)zn Returns the last content written to the document without removing it from the stack. rrrrr peek_write3s zReSTDocument.peek_writecCs |jS)zL Removes and returns the last content written to the stack. )rpopr!rrr pop_write:s zReSTDocument.pop_writecCs|j|dS)z2 Places new content on the stack. N)rrrrrr push_write@szReSTDocument.push_writecCsD|jr|j|jD] \}}|j||q d|jdS)zJ Returns the current content of the document as a string. utf-8)rr new_paragraphitemslink_target_definitionjoinrencode)rrefnamelinkrrrgetvalueFs  zReSTDocument.getvaluecsfdd|DS)Ncsg|] }j||qSr)r get).0wr!rr Qsz0ReSTDocument.translate_words..r)rwordsrr!rtranslate_wordsPzReSTDocument.translate_wordscCs |r |jr||dSdSdSr)r r)rdatarrr handle_dataSs zReSTDocument.handle_datacCsp|r6zt|j}|j||jt|j}||f|_WdSty5tjdddt|YdSwdS)NzError parsing doc stringT)exc_info) lenrr feedcloser ExceptionLOGdebug)r doc_stringstartendrrrinclude_doc_stringWs     zReSTDocument.include_doc_stringcCs(|jdur|j\}}|j||=dSdSr)rr)rrArBrrrremove_last_doc_stringcs  z#ReSTDocument.remove_last_doc_stringN)r)__name__ __module__ __qualname__rrrrr"r$r%r/r5r8rCrDrrrrrs    rcseZdZdfdd ZeddZeddZejd dZed d Zed d Z ddZ dddZ ddZ ddZ ddZddZddZddZZS) DocumentStructureNrcsXtt|j|d||_t|_|jg|_i|_|dur||_|dur*||dSdS)a5Provides 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) superrHr_namer _structure_path_context_generate_structure)rname section_namesr context __class__rrrks  zDocumentStructure.__init__cC|jS)z"The name of the document structure)rJr!rrrrOszDocumentStructure.namecCrT)zv A list of where to find a particular document structure in the overlying document structure. rLr!rrrpathszDocumentStructure.pathcCs ||_dSrrU)rvaluerrrrV cCs t|jSr)listrKr!rrravailable_sectionsrXz$DocumentStructure.available_sectionscCrTr)rMr!rrrrQszDocumentStructure.contextcCs|D]}||qdSr)add_new_section)rrP section_namerrrrNs z%DocumentStructure._generate_structurecCsJ|j||j|d}|j|g|_|jj|j_|j|_|j|_||j|<|S)aAdds 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. )rOr rQ)rSr rVr indentationr rrK)rrOrQsectionrrrr[s   z!DocumentStructure.add_new_sectioncCs |j|S)zRetrieve a sectionrKrrOrrr get_sectionrXzDocumentStructure.get_sectioncCs |j|=dS)zDelete a sectionNr_r`rrrdelete_sections z DocumentStructure.delete_sectioncCslt|jdkr |jr |j|jD] \}}|j||q|}|jD] \}}|| 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:rVrrr(r)r*r/rKflush_structure)rr-r.rWrOr^rrrrds z!DocumentStructure.flush_structurecCsd|jdS)Nr&r')r+rr,r!rrrr/r6zDocumentStructure.getvaluecCs t|_dSr)rrKr!rrrremove_all_sectionss z%DocumentStructure.remove_all_sectionscCs g|_dSrr r!rrr clear_texts zDocumentStructure.clear_text)NrNr)rErFrGrpropertyrOrVsetterrZrQrNr[rarbrdr/rerf __classcell__rrrRrrHjs(      rH) loggingbotocore.compatrawscli.bcdoc.docstringparserrawscli.bcdoc.styler getLoggerr>objectrrHrrrrs    T