
    4 f1                         d Z dZddlZddlZddlmZmZ ddlmZ ddl	m
Z
  G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)a  
Transforms needed by most or all documents:

- `Decorations`: Generate a document's header & footer.
- `ExposeInternals`: Expose internal attributes.
- `Messages`: Placement of system messages generated after parsing.
- `FilterMessages`: Remove system messages below verbosity threshold.
- `TestMessages`: Like `Messages`, used on test runs.
- `StripComments`: Remove comment elements from the document tree.
- `StripClassesAndElements`: Remove elements with classes
  in `self.document.settings.strip_elements_with_classes`
  and class values in `self.document.settings.strip_classes`.
- `SmartQuotes`: Replace ASCII quotation marks with typographic form.
reStructuredText    N)nodesutils)	Transform)smartquotesc                   &    e Zd ZdZdZd Zd Zd Zy)DecorationszD
    Populate a document's decoration element (header, footer).
    i4  c                 :   | j                         }|r;| j                  j                         }|j                         }|j	                  |       | j                         }|r<| j                  j                         }|j                         }|j	                  |       y y N)generate_headerdocumentget_decoration
get_headerextendgenerate_footer
get_footer)selfheader_nodes
decorationheaderfooter_nodesfooters         S/var/www/equiseq/venv/lib/python3.11/site-packages/docutils/transforms/universal.pyapplyzDecorations.apply&   s    ++-557J**,FMM,'++-557J**,FMM,'     c                      y r    )r   s    r   r   zDecorations.generate_header2   s    r   c           
         | j                   j                  }|j                  s%|j                  s|j                  s|j
                  rg }|j                  r|j                  s|j
                  r|j
                  r|j
                  }n*t        j                  |j                  |j                        }|j                  t        j                  dd|      t        j                  d      g       |j                  r\t        j                  |j                  t        j                                }|j#                  t        j                  d|z   dz                |j                  r{|j                  t        j                  d      t        j                  ddd      t        j                  d	      t        j                  dd
d      t        j                  d      g       t        j$                  ddg| gS y )N zView document source)refuriz.
zGenerated on: zGenerated by Docutilsz https://docutils.sourceforge.io/z from r   z(https://docutils.sourceforge.io/rst.htmlz	 source.
)r   settings	generator	datestampsource_link
source_url_sourcer   relative_path_destinationr   r   	referenceTexttimestrftimegmtimeappend	paragraph)r   r"   textsourcer$   s        r   r   zDecorations.generate_footer5   s    ==))("4"4##x':':D$$)9)9&&&&%00F"001F1F191A1ACFOOB(>+13JJu%' ( !! MM(*<*<dkkmL	EJJ'7)'Ce'KLM!!JJ/OOB
+MOJJx(OOB(:,/0 JJ|,. / OOB2T233r   N)__name__
__module____qualname____doc__default_priorityr   r   r   r   r   r   r	   r	      s     
(%r   r	   c                        e Zd ZdZdZd Zd Zy)ExposeInternalszL
    Expose internal attributes if ``expose_internals`` setting is set.
    iH  c                 8    t        |t        j                         S r   )
isinstancer   r+   r   nodes     r   not_TextzExposeInternals.not_Texte   s    dEJJ///r   c                    | j                   j                  j                  rh| j                   j                  | j                        D ]?  }| j                   j                  j                  D ]  }t        ||d       }|||d|z   <    A y y )Nz	internal:)r   r"   expose_internalsfindallr>   getattr)r   r=   attvalues       r   r   zExposeInternals.applyh   s~    ==!!22--dmm< 8==11BB 8C#D#t4E(27[3./88 3r   N)r3   r4   r5   r6   r7   r>   r   r   r   r   r9   r9   ]   s     08r   r9   c                       e Zd ZdZdZd Zy)Messageszi
    Place any system messages generated after parsing into a dedicated section
    of the document.
    i\  c                 >   | j                   j                  }|D cg c]  }|j                  r| }}|rdt        j                  dg      }|t        j
                  dd      z  }||z  }g | j                   j                  d d  | xj                   |z  c_         y y c c}w )Nsystem-messages)classesr   zDocutils System Messages)r   transform_messagesparentr   sectiontitle)r   messagesmsgloose_messagesrL   s        r   r   zMessages.applyz   s    ==33)1D##DDmm->,?@Gu{{2'ABBG~%G24DMM,,Q/MMW$M  Es
   BBNr3   r4   r5   r6   r7   r   r   r   r   rF   rF   q   s    
 	%r   rF   c                       e Zd ZdZdZd Zy)FilterMessagesz
    Remove system messages below verbosity threshold.

    Convert <problematic> nodes referencing removed messages to <Text>.
    Remove "System Messages" section if empty.
    if  c                 2   t        | j                  j                  t        j                              D ]b  }|d   | j                  j
                  j                  k  s*|j                  j                  |       	 | j                  j                  |d   d   = d t        | j                  j                  t        j                              D ][  }|d   | j                  j                  vs|j                  j                  |t        j                  |j                                      ] | j                  j                  t        j                        D ]4  }d|d   v st!        |      dk(  s|j                  j                  |       6 y # t        $ r Y bw xY w)Nlevelidsr   refidrH   rI      )tupler   rA   r   system_messagereporterreport_levelrK   removerV   
IndexErrorproblematicreplacer+   astextrL   lenr<   s     r   r   zFilterMessages.apply   s>   $--//0D0DEF 	DG}t}}55BBB""4())$u+a.9		 $--//0A0ABC 	EDG}DMM$5$55##D%**T[[]*CD	E MM))%--8 	)D DO3D	Q""4(	) # s   9F			FFNrQ   r   r   r   rS   rS      s     )r   rS   c                       e Zd ZdZdZdZd Zy)TestMessageszk
    Append all post-parse system messages to the end of the document.

    Used for testing purposes.
    Fip  c                 ~    | j                   j                  D ]$  }|j                  r| xj                   |z  c_         & y r   )r   rJ   rK   )r   rO   s     r   r   zTestMessages.apply   s0    ==33 	%C::$	%r   N)r3   r4   r5   r6   __test__r7   r   r   r   r   rd   rd      s     H%r   rd   c                       e Zd ZdZdZd Zy)StripCommentszq
    Remove comment elements from the document tree (only if the
    ``strip_comments`` setting is enabled).
    i  c                     | j                   j                  j                  rSt        | j                   j	                  t
        j                              D ]  }|j                  j                  |        y y r   )	r   r"   strip_commentsrY   rA   r   commentrK   r]   r<   s     r   r   zStripComments.apply   sS    ==!!00dmm33EMMBC )""4() 1r   NrQ   r   r   r   rh   rh      s    
 )r   rh   c                        e Zd ZdZdZd Zd Zy)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  c                 b   | j                   j                  j                  ruh | j                   j                  j                  | _        t	        | j                   j                  | j                              D ]  }|j                  j                  |        | j                   j                  j                  sy | j                   j                  j                  }| j                   j                  t        j                        D ]  }|D ]  }	 |d   j                  |          y # t        $ r Y (w xY w)NrI   )r   r"   strip_elements_with_classesstrip_elementsrY   rA   check_classesrK   r]   strip_classesr   Element
ValueError)r   r=   rr   class_values       r   r   zStripClassesAndElements.apply   s    ==!!==#ADMM$:$:$?$?#AD dmm33D4F4FGH )""4() }}%%33..<<MM))%--8 	D, O**;7	 " s   	D""	D.-D.c                 t    t        |t        j                        sy|d   d d  D ]  }|| j                  v s y y)NFrI   T)r;   r   rs   rp   )r   r=   ru   s      r   rq   z%StripClassesAndElements.check_classes   sA    $.	?1- 	Kd111	 r   N)r3   r4   r5   r6   r7   r   rq   r   r   r   rm   rm      s     &r   rm   c                       e Zd ZdZdZej                  ej                  fZ	 ej                  ej                  ej                  ej                  ej                  ej                  ej                  fZ	 dZ	 d Zd Zd Zy)SmartQuotesz
    Replace ASCII quotation marks with typographic form.

    Also replace multiple dashes with em-dash/en-dash characters.
    iW  qDec                 R    t        j                  | ||       t               | _        y )N)	startnode)r   __init__setunsupported_languages)r   r   r{   s      r   r|   zSmartQuotes.__init__  s    4Y?%(U"r   c              #     K   |D ]  }t        |j                  | j                        s*t        |j                  j                  | j                        rdt        |      f ]t	        j
                  ddt        |            }d|f  y w)Nliteralz(?<= )([-\'".`])z\\\1plain)r;   rK   literal_nodesstrresub)r   txtnodesr=   txts       r   
get_tokenszSmartQuotes.get_tokens  sw       	#D4;;(:(:;dkk00$2D2DET** ff4gs4yIsl"	#s   B	Bc                    | j                   j                  j                  dd      }|sy 	 |j                  d      }| j                   j                  j
                  }| j                   j                  j                  }|r2t        j                  j                  j                  t        |             | j                   j                  t        j                        D ]  }t        || j                         rt        |j"                  t        j                        r@|j                  t        j$                        D cg c](  }t        |j"                  t        j&                        s|* }}|j)                  |      }|rd|v r|j+                  dd      }n|dz  }t-        j.                  |      D ]"  }	|	t        j                  j                  v s |	} nV || j0                  vr*| j                   j2                  j5                  d|z  |       | j0                  j7                  |       d}t        j8                  | j;                  |      | j<                  |      }
t?        ||
      D ]4  \  }}|j"                  j+                  |t        j$                  |             6  | j0                  jA                          y # t        $ r d}Y w xY wc c}w )	Nsmart_quotesFaltz
-x-altquotr   z*No smart quotes defined for language "%s".)	base_node)attrlanguage)!r   r"   
setdefault
startswithAttributeErrorlanguage_codesmartquotes_localesr   
smartcharsquotesupdatedictrA   r   TextElementr;   nodes_to_skiprK   r+   option_stringget_language_coder`   r   normalize_language_tagr~   r[   warningaddeducate_tokensr   smartquotes_actionzipclear)r   r   alternativedocument_languagelc_smartquotesr=   txtnoder   langtagteachernewtexts               r   r   zSmartQuotes.apply  s{   }}--889>@	 &11%8K !MM22@@//CC""))00n1EF MM))%*;*;< )	ED$ 2 23$++u'8'89 04||EJJ/G @G)'..*/*=*= ?   @H @
 ))*;<D4'<<b9DL(D33D9 
+00777D

 t999MM**22DtK"& 3 ( **..t4 "00),,t=G %('$: E &&w

70CDEQ)	EV 	""((*k  	 K	 &@s   J9 :-K9KKN)r3   r4   r5   r6   r7   r   FixedTextElementSpecialr   imager   mathrawr_   r   r   r|   r   r   r   r   r   rx   rx      s~     ++U]];MM++U]][[%--YY 1 13M G+#<+r   rx   )r6   __docformat__r   r,   docutilsr   r   docutils.transformsr   docutils.utilsr   r	   r9   rF   rS   rd   rh   rm   rx   r   r   r   <module>r      s    # 	  ! ) &<) <~8i 8(%y %6)Y )6%9 %&)I )#i #Lf+) f+r   