B “äî\^+ã@sÐdZdZddlZddlZddlZddlmZmZddlm Z m Z ddl m Z Gdd„de ƒZ Gd d „d e ƒZGd d „d e ƒZGd d„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZdS)a+ Transforms needed by most or all documents: - `Decorations`: Generate a document's header & footer. - `Messages`: Placement of system messages stored in `nodes.document.transform_messages`. - `TestMessages`: Like `Messages`, used on test runs. - `FinalReferences`: Resolve remaining references. ÚreStructuredTextéN)ÚnodesÚutils)ÚTransformErrorÚ Transform)Ú smartquotesc@s,eZdZdZdZdd„Zdd„Zdd„Zd S) Ú DecorationszD Populate a document's decoration element (header, footer). i4cCsT| ¡}|r(|j ¡}| ¡}| |¡| ¡}|rP|j ¡}| ¡}| |¡dS)N)Úgenerate_headerÚdocumentZget_decorationÚ get_headerÚextendÚgenerate_footerZ get_footer)ÚselfZ header_nodesZ decorationÚheaderZ footer_nodesÚfooter©rúA/tmp/pip-build-uw_ogi45/docutils/docutils/transforms/universal.pyÚapply"s   zDecorations.applycCsdS)Nr)rrrrr .szDecorations.generate_headerc Cs|jj}|js |js |js |jrøg}|jr0|js6|jrt|jrD|j}nt |j |j¡}|  t j dd|dt   d¡g¡|jr¤t |jt ¡¡}| t   d|d¡¡|jrè|  t   d¡t j ddddt   d ¡t j dd d dt   d ¡g¡t jd |žŽgSdSdS)NÚzView document source)Zrefuriz. zGenerated on: z Generated by ZDocutilsz http://docutils.sourceforge.net/z from rz(http://docutils.sourceforge.net/rst.htmlz source. )rr)r ÚsettingsÚ generatorÚ datestampZ source_linkZ source_urlZ_sourcerZ relative_pathZ _destinationr rÚ referenceÚTextÚtimeÚstrftimeÚgmtimeÚappendZ paragraph)rrÚtextÚsourcerrrrr 1s6 zDecorations.generate_footerN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Údefault_priorityrr r rrrrrs  rc@s$eZdZdZdZdd„Zdd„ZdS)ÚExposeInternalszL Expose internal attributes if ``expose_internals`` setting is set. iHcCst|tjƒ S)N)Ú isinstancerr)rÚnoderrrÚnot_Text`szExposeInternals.not_TextcCsZ|jjjrVxJ|j |j¡D]8}x2|jjjD]$}t||dƒ}|dk r*||d|<q*WqWdS)Nz internal:)r rZexpose_internalsÚtraverser(Úgetattr)rr'ZattÚvaluerrrrcs   zExposeInternals.applyN)r r!r"r#r$r(rrrrrr%Xsr%c@seZdZdZdZdd„ZdS)ÚMessageszi Place any system messages generated after parsing into a dedicated section of the document. i\cCsŒ|jj}|jjj}g}x(|D] }|d|kr|js| |¡qW|rˆtjdgd}|t dd¡7}||7}g|jjdd…<|j|7_dS)NÚlevelzsystem-messages)ÚclassesrzDocutils System Messages) r Útransform_messagesÚreporterÚ report_levelÚparentrrÚsectionÚtitle)rZ unfilteredÚ thresholdÚmessagesÚmsgr3rrrrus  zMessages.applyN)r r!r"r#r$rrrrrr,lsr,c@seZdZdZdZdd„ZdS)ÚFilterMessagesz; Remove system messages below verbosity threshold. ifcCs:x4|j tj¡D]"}|d|jjjkr|j |¡qWdS)Nr-)r r)rZsystem_messager0r1r2Úremove)rr'rrrrszFilterMessages.applyN)r r!r"r#r$rrrrrr8…sr8c@seZdZdZdZdd„ZdS)Ú TestMessageszk Append all post-parse system messages to the end of the document. Used for testing purposes. ipcCs*x$|jjD]}|js |j|7_q WdS)N)r r/r2)rr7rrrrszTestMessages.applyN)r r!r"r#r$rrrrrr:“sr:c@seZdZdZdZdd„ZdS)Ú StripCommentszq Remove comment elements from the document tree (only if the ``strip_comments`` setting is enabled). iäcCs2|jjjr.x"|j tj¡D]}|j |¡qWdS)N)r rÚstrip_commentsr)rÚcommentr2r9)rr'rrrr¬s zStripComments.applyN)r r!r"r#r$rrrrrr;£sr;c@s$eZdZdZdZdd„Zdd„ZdS)ÚStripClassesAndElementszÏ Remove from the document tree all elements with classes in `self.document.settings.strip_elements_with_classes` and all "classes" attribute values in `self.document.settings.strip_classes`. i¤cCs||jjjs|jjjsdStdd„|jjjp,gDƒƒ|_tdd„|jjjpJgDƒƒ|_x"|j |j¡D]}|j  |¡qdWdS)NcSsg|] }|df‘qS)Nr)Ú.0Úkeyrrrú Âsz1StripClassesAndElements.apply..cSsg|] }|df‘qS)Nr)r?r@rrrrAÆs) r rZstrip_elements_with_classesÚ strip_classesÚdictÚstrip_elementsr)Ú check_classesr2r9)rr'rrrr¼s     zStripClassesAndElements.applycCsPt|tjƒrLx>|ddd…D]*}||jkr:|d |¡||jkrdSqWdS)Nr.é)r&rÚElementrBr9rD)rr'Z class_valuerrrrEËs    z%StripClassesAndElements.check_classesN)r r!r"r#r$rrErrrrr>²sr>c@sTeZdZdZdZejejfZej ej ej ej ej fZdZdd„Zdd„Zdd „Zd S) Ú SmartQuotesz Replace ASCII quotation marks with typographic form. Also replace multiple dashes with em-dash/en-dash characters. iRZqDecCstj|||dtƒ|_dS)N)Ú startnode)rÚ__init__ÚsetÚunsupported_languages)rr rIrrrrJìszSmartQuotes.__init__ccs<dddœ}x,|D]$}|t|j|jƒ}|| ¡fVqWdS)NÚliteralÚplain)TF)r&r2Ú literal_nodesZastext)rÚtxtnodesZtexttypeÚtxtnodeZnodetyperrrÚ get_tokensðs   zSmartQuotes.get_tokensc Cs|jjj}|sdSy| d¡}Wntk r8d}YnX|jjj}|jjj}|rdtjj   t |ƒ¡x|j  t j¡D]}t||jƒrŠqvt|jt jƒršqvdd„|  t j¡Dƒ}| |¡}|rÜd|krÔ| dd¡}n|d7}xVt |¡D]}|tjj krè|}PqèW||jkr$|jjjd||d|j |¡d}tj| |¡|j|d } x2t|| ƒD]$\} } | j | t j| | jd ¡qXWqvWt ƒ|_dS) NZaltFcSsg|]}t|jtjƒs|‘qSr)r&r2rZ option_string)r?rQrrrrAsz%SmartQuotes.apply..z -x-altquotrz*No smart quotes defined for language "%s".)Z base_node)ÚattrÚlanguage)Ú rawsource)!r rÚ smart_quotesÚ startswithÚAttributeErrorZ language_codeZsmartquotes_localesrZ smartcharsÚquotesÚupdaterCr)rZ TextElementr&Ú nodes_to_skipr2rZget_language_codeÚreplacerZnormalize_language_tagrLr0ÚwarningÚaddZeducate_tokensrRÚsmartquotes_actionÚziprUrK) rrVÚ alternativeZdocument_languageZlc_smartquotesr'rPÚlangÚtagZteacherrQZnewtextrrrrüsJ             zSmartQuotes.applyN)r r!r"r#r$rZFixedTextElementÚSpecialr[ÚimagerMÚmathÚrawZ problematicrOr_rJrRrrrrrrHÔs    rH)r#Z __docformat__ÚreÚsysrZdocutilsrrZdocutils.transformsrrZdocutils.utilsrrr%r,r8r:r;r>rHrrrrÚs >"