
    ohe+2                         d Z dZddl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         ?/usr/lib/python3/dist-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_header3   s    r   c           
         | j                   j                  }|j                  s%|j                  s|j                  s|j
                  r
g }|j                  r|j                  s|j
                  r|j
                  r|j
                  }n*t        j                  |j                  |j                        }|j                  t        j                  dd|      t        j                  d      g       |j                  rt        j                  j!                  d      }|r=t#        j$                  |j                  t#        j&                  t)        |                  }n2t#        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.
SOURCE_DATE_EPOCHz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osenvirongettimestrftimegmtimeintappend	paragraph)r   r#   textsourcesource_date_epochr%   s         r   r   zDecorations.generate_footer6   s    ==))("4"4##x':':D$$)9)9&&&&%00F"001F1F191A1ACFOOB(>+13JJu%' ( !!$&JJNN3F$G!$ $h.@.@.2kk#>O:P.Q!SI !%h.@.@$++- PI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_Textk   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findallrD   getattr)r   rC   attvalues       r   r   zExposeInternals.applyn   s~    ==!!22--dmm< 8==11BB 8C#D#t4E(27[3./88 3r   N)r9   r:   r;   r<   r=   rD   r   r   r   r   r?   r?   c   s     08r   r?   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_messagesrR   s        r   r   zMessages.apply   s    ==33)1D##DDmm->,?@Gu{{2'ABBG~%G24DMM,,Q/MMW$M  Es
   BBNr9   r:   r;   r<   r=   r   r   r   r   rL   rL   w   s    
 	%r   rL   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   refidrN   rO      )tupler   rG   r   system_messagereporterreport_levelrQ   remover\   
IndexErrorproblematicreplacer,   astextrR   lenrB   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NrW   r   r   r   rY   rY      s     )r   rY   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   rP   rQ   )r   rU   s     r   r   zTestMessages.apply   s0    ==33 	%C::$	%r   N)r9   r:   r;   r<   __test__r=   r   r   r   r   rj   rj      s     H%r   rj   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_commentsr_   rG   r   commentrQ   rc   rB   s     r   r   zStripComments.apply   sS    ==!!00dmm33EMMBC )""4() 1r   NrW   r   r   r   rn   rn      s    
 )r   rn   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)NrO   )r   r#   strip_elements_with_classesstrip_elementsr_   rG   check_classesrQ   rc   strip_classesr   Element
ValueError)r   rC   rx   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)NFrO   T)rA   r   ry   rv   )r   rC   r{   s      r   rw   z%StripClassesAndElements.check_classes   sA    $.	?1- 	Kd111	 r   N)r9   r:   r;   r<   r=   r   rw   r   r   r   rs   rs      s     &r   rs   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)rA   rQ   literal_nodesstrresub)r   txtnodesrC   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dictrG   r   TextElementrA   nodes_to_skiprQ   r,   option_stringget_language_coderf   r   normalize_language_tagr   ra   warningaddeducate_tokensr   smartquotes_actionzipclear)r   r   alternativedocument_languagelc_smartquotesrC   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)r9   r:   r;   r<   r=   r   FixedTextElementSpecialr   imager   mathrawre   r   r   r   r   r   r   r   r   r~   r~      s~     ++U]];MM++U]][[%--YY 1 13M G+#<+r   r~   )r<   __docformat__r-   r   r0   docutilsr   r   docutils.transformsr   docutils.utilsr   r	   r?   rL   rY   rj   rn   rs   r~   r   r   r   <module>r      s    # 	 	  ! ) &A) AH8i 8(%y %6)Y )6%9 %&)I )#i #Lf+) f+r   