o ?c @sXddlZddlmZddlmZddlmZedZGdddZ Gdd d e Z dS) N) OrderedDict)DocStringParser) ReSTStyleZbcdocsc@sneZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZdS) ReSTDocumentmancCsBt||_||_t||_d|_d|_i|_i|_g|_ d|_ dS)NTF) rstyletargetrparser keep_dataZdo_translationtranslation_maphrefs_writes_last_doc_string)selfrrv/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/docs/bcdoc/restdoc.py__init__s   zReSTDocument.__init__cCs&|jr|dur|j|dSdSdSN)r r appendrsrrr_write"szReSTDocument._writecCs||dS)z2 Write content into the document. N)rrcontentrrrwrite&szReSTDocument.writecCs||j|ddS)z- Write content on a newline.  N)rrspacesrrrrwriteln,szReSTDocument.writelncCs |jdS)zn Returns the last content written to the document without removing it from the stack. r rrrr peek_write2s zReSTDocument.peek_writecCs |jS)zL Removes and returns the last content written to the stack. )r popr rrr pop_write9s zReSTDocument.pop_writecCs|j|dS)z2 Places new content on the stack. N)r rrrrr 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)r r new_paragraphitemslink_target_definitionjoinr encode)rrefnamelinkrrrgetvalueEs  zReSTDocument.getvaluecsfdd|DS)Ncsg|] }j||qSr)r get).0wr rr Psz0ReSTDocument.translate_words..r)rwordsrr rtranslate_wordsOzReSTDocument.translate_wordscCs |r |jr||dSdSdSr)r r)rdatarrr handle_dataRs zReSTDocument.handle_datacCsp|r6zt|j}|j||jt|j}||f|_WdSty5tjdddt|YdSwdS)NzError parsing doc stringT)exc_info) lenr r feedcloser ExceptionLOGdebug)rZ doc_stringstartendrrrinclude_doc_stringVs     zReSTDocument.include_doc_stringcCs(|jdur|j\}}|j||=dSdSr)rr )rr?r@rrrremove_last_doc_stringbs  z#ReSTDocument.remove_last_doc_stringN)r)__name__ __module__ __qualname__rrrrr!r#r$r.r4r7rArBrrrrrs    rcseZdZdfdd ZeddZeddZejd dZed d Zed d Z ddZ dddZ ddZ ddZ ddZddZddZddZZS) DocumentStructureNrcsTtj|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. )rN)superr_namer _structure_path_context_generate_structure)rname section_namesrcontext __class__rrrjs  zDocumentStructure.__init__cC|jS)z"The name of the document structure)rHr rrrrMszDocumentStructure.namecCrR)zv A list of where to find a particular document structure in the overlying document structure. rJr rrrpathszDocumentStructure.pathcCs ||_dSrrS)rvaluerrrrT cCs t|jSr)listrIr rrravailable_sectionsrVz$DocumentStructure.available_sectionscCrRr)rKr rrrrOszDocumentStructure.contextcCs|D]}||qdSr)add_new_section)rrN section_namerrrrLs 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. )rMrrO)rQrrTr indentationr r rI)rrMrOsectionrrrrYs  z!DocumentStructure.add_new_sectioncCs |j|S)zRetrieve a sectionrIrrMrrr get_sectionrVzDocumentStructure.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. ) r9rTr rr'r(r)r.rIflush_structure)rr,r-rUrMr\rrrrbs z!DocumentStructure.flush_structurecCsd|jdS)Nr%r&)r*r r+r rrrr.r5zDocumentStructure.getvaluecCs t|_dSr)rrIr rrrremove_all_sectionss z%DocumentStructure.remove_all_sectionscCs g|_dSrrr rrr clear_texts zDocumentStructure.clear_text)NrNr)rCrDrErpropertyrMrTsetterrXrOrLrYr_r`rbr.rcrd __classcell__rrrPrrFis(      rF) loggingZbotocore.compatrZ#botocore.docs.bcdoc.docstringparserrZbotocore.docs.bcdoc.styler getLoggerr=rrFrrrrs    S