
    <i{9                    T   d Z ddlmZ dZddlZddlmc mZ dZ		  G d dej
                  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 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 G d( d)e          Z G d* d+e          Z G d, d-e          Z G d. d/e          Z G d0 d1e          Z  G d2 d3e          Z! G d4 d5e          Z" G d6 d7e           Z# G d8 d9e          Z$ G d: d;e          Z% G d< d=e          Z&dS )>ah  MathML element classes based on `xml.etree`.

The module is intended for programmatic generation of MathML
and covers the part of `MathML Core`_ that is required by
Docutil's *TeX math to MathML* converter.

This module is PROVISIONAL:
the API is not settled and may change with any minor Docutils version.

.. _MathML Core: https://www.w3.org/TR/mathml-core/
    )annotationsreStructuredTextN)classdirdisplaystyleidnoncescriptlevelstyletabindexc                       e Zd ZdZdZ	 dZ	 d fdZed             ZddZ	dd	Z
d fd
Zd fdZd Zd Z fdZd ZddZd ZdddZddZddZ xZS )MathElementzBase class for MathML elements.NreturnNonec                      fd|                                 D             } t                      j         j        j        fi |                      |           dS )a  Set up node with `children` and `attributes`.

        Attribute names are normalised to lowercase.
        You may use "CLASS" to set a "class" attribute.
        Attribute values are converted to strings
        (with True -> "true" and False -> "false").

        >>> math(CLASS='test', level=3, split=True)
        math(class='test', level='3', split='true')
        >>> math(CLASS='test', level=3, split=True).toxml()
        '<math class="test" level="3" split="true"></math>'

        c                f    i | ]-\  }}|                                                     |          .S  )lowera_str).0kvselfs      /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/docutils/utils/math/mathml_elements.py
<dictcomp>z(MathElement.__init__.<locals>.<dictcomp>S   s1    JJJtq!!''))TZZ]]JJJ    N)itemssuper__init__	__class____name__extend)r   children
attributesattribr    s   `   r   r   zMathElement.__init__E   sh     KJJJz7G7G7I7IJJJ0;;F;;;Hr   c                    t          | t                    r!t          |                                           S t          |           S N)
isinstanceboolstrr   )r   s    r   r   zMathElement.a_strW   s5     a 	"q66<<>>!1vvr   r*   c                   d | D             }| j         r'|                    t          | j                              | j        | j        j        k    r|                    d| j                    t          | dd          r|                    d           |d |                                 D             z  }| j         dd                    |           d	S )
z"Return full string representation.c                ,    g | ]}t          |          S r   )reprr   childs     r   
<listcomp>z(MathElement.__repr__.<locals>.<listcomp>`   s    ...U...r   z
nchildren=switchNzswitch=Truec                &    g | ]\  }}|| d|S )N=r   )r   r   r   s      r   r0   z(MathElement.__repr__.<locals>.<listcomp>g   s'    HHH$!Q!-A---r   (, ))	textappendr-   	nchildrenr    getattrr   tagjoinr   argss     r   __repr__zMathElement.__repr__^   s    .....9 	)KKTY(((>T^555KK5T^5566644(( 	'KK&&&HH$**,,HHHH(//TYYt__////r   c                    | j         rt          | j                   }nd                    d | D                       }| j         d| dS )z/Return concise, informal string representation.r5   c              3     K   | ]}| V  d S r'   r   r.   s     r   	<genexpr>z&MathElement.__str__.<locals>.<genexpr>o   s$      ::EZ::::::r   r4   r6   )r7   r-   r<   r;   r=   s     r   __str__zMathElement.__str__j   sT    9 	;	??DD99::T:::::D($$T$$$$r   c                r    t                                          ||                     |                     d S r'   )r   setr   )r   keyvaluer    s      r   rE   zMathElement.setr   s-    CE**+++++r   c                n   | j         dk    rt          d|  d          t          |t                    r| |_        nV| j         rCt          |           t          |          z   | j         k    rt          d|  d| j          d          |D ]	}| |_        
t                                          ||           d S )Nr   	Element "z" does not take children.z" takes only 	 children)r9   	TypeErrorr(   r   parentlenr   __setitem__)r   rF   rG   er    s       r   rN   zMathElement.__setitem__u   s    >QGGGGHHHe[)) 	 ELL~ -#d))c%jj"84>"I"I !,D !, !,t~ !, !, !, - - -    C'''''r   c                D    | j         duot          |           | j         k    S )z;Return boolean indicating whether children may be appended.N)r9   rM   r   s    r   is_fullzMathElement.is_full   s!    ~T)Ic$ii4>.IIr   c                    t          |           | _        | j        }|1|                                r|j        }||                                |S )z:Close element and return first non-full anchestor or None.)rM   r9   rL   rR   )r   rL   s     r   closezMathElement.close   sN    T V^^%5%5 ]F  V^^%5%5 r   c                &   |                                  r+| j        rd| j         d}nd}t          d|  d| d          t                                          |           | |_        |                                  r|                                 S | S )aL  Append `element` and return new "current node" (insertion point).

        Append as child element and set the internal `parent` attribute.

        If self is already full, raise TypeError.

        If self is full after appending, call `self.close()`
        (returns first non-full anchestor or None) else return `self`.
        ztakes only rJ   zdoes not take childrenrI   z" .)rR   r9   rK   r   r8   rL   rT   )r   elementstatusr    s      r   r8   zMathElement.append   s     <<>> 	;~ 2@t~@@@1999999:::w<<>> 	 ::<<r   c                >    | }|D ]}|                      |          }|S )ziSequentially append `elements`. Return new "current node".

        Raise TypeError if overfull.
        )r8   )r   elementscurrent_noderW   s       r   r"   zMathElement.extend   s1    
  	0 	0G;;w//LLr   c                    | |         }| |= |S r'   r   )r   indexrW   s      r   popzMathElement.pop   s    u+Kr   c                    |                      d          +	 | j                                        S # t          $ r Y dS w xY w|                      d          dk    S )zReturn True, if `self` or an ancestor has ``display='block'``.

        Used to find out whether we are in inline vs. displayed maths.
        displayNFblock)getrL   in_blockAttributeErrorrQ   s    r   rd   zMathElement.in_block   sh    
 88I&{++---!   uuxx	""g--s   0 
>>  r   c                2    t          j        | ||           dS )zFormat XML output with indents.

        Use with care:
          Formatting whitespace is permanently added to the
          `text` and `tail` attributes of `self` and anchestors!
        N)ETindent)r   spacelevels      r   
indent_xmlzMathElement.indent_xml   s     		$u%%%%%r   c                    |                                  D ]a}t          |t                    s%|j        r|j                                        |_        |j        r|j                                        |_        bdS )zStrip whitespace at the end of `text` and `tail` attributes...

        to revert changes made by the `indent_xml()` method.
        Use with care, trailing whitespace from the original may be lost.
        N)iterr(   	MathTokenr7   rstriptail)r   rO   s     r   unindent_xmlzMathElement.unindent_xml   sm      	) 	)Aa++ ) )v )		) 	)r   c                    t          j        | |pdd          }	 |                    dd          }n9# t          $ r, |                    d                    |          d          }Y nw xY w|S )a  Return an XML representation of the element.

        By default, the return value is a `str` instance. With an explicit
        `encoding` argument, the result is a `bytes` instance in the
        specified encoding. The XML default encoding is UTF-8, any other
        encoding must be specified in an XML document header.

        Name and encoding handling match `xml.dom.minidom.Node.toxml()`
        while `etree.Element.tostring()` returns `bytes` by default.
        unicodeF)short_empty_elementsu   ⁡z&ApplyFunction;s   &ApplyFunction;)rh   tostringreplacerK   encode)r   encodingxmls      r   toxmlzMathElement.toxml   s     k$ 5I/46 6 6	M++h(9::CC 	M 	M 	M++hooh779KLLCCC	M
s   2 3A('A(r   r   )r   r*   )r\   )rf   r   r'   )r!   
__module____qualname____doc__r9   rL   r   staticmethodr   r?   rC   rE   rN   rR   rT   r8   r"   r_   rd   rl   rr   r{   __classcell__r    s   @r   r   r   <   s       ))I-F-     $   \
0 
0 
0 
0% % % %, , , , , ,( ( ( ( ( (J J J      ,     

. 
. 
.& & & & &
) 
) 
) 
)       r   r   c                      e Zd ZdZdS )MathRowz:Base class for elements treating content as a single mrow.Nr!   r}   r~   r   r   r   r   r   r      s        DDDDr   r   c                  2     e Zd ZdZdZd fdZ fdZ xZS )
MathSchemazBase class for schemata expecting 2 or more children.

    The special attribute `switch` indicates that the last two child
    elements are in reversed order and must be switched before XML-export.
    See `msub` for an example.
       r   r   c                p    |                     dd          | _         t                      j        |i | d S )Nr1   F)r_   r1   r   r   )r   r#   kwargsr    s      r   r   zMathSchema.__init__  s:    jj511(-f-----r   c                    t                                          |          }| j        r2|                                 r| d         | d         c| d<   | d<   d| _        |S )z2Append element. Normalize order and close if full.r\   F)r   r8   r1   rR   )r   rW   r[   r    s      r   r8   zMathSchema.append  sZ    ww~~g..; 	 4<<>> 	 !%b48DHd2hDKr   r|   )r!   r}   r~   r   r9   r   r8   r   r   s   @r   r   r      sg          I. . . . . .        r   r   c                  (     e Zd ZdZdZd fdZ xZS )ro   zgToken Element: contains textual data instead of children.

    Expect text data on initialisation.
    r   r   r   c                     t                      j        di | t          |t          t          j        f          st          d| d          t          |          | _        d S )Nz0MathToken element expects `str` or number, not "z".r   )r   r   r(   r*   numbersNumber
ValueErrorr7   )r   r7   r$   r    s      r   r   zMathToken.__init__  ss    &&:&&&$gn 566 	0 /&*/ / / 0 0 0II			r   r|   )r!   r}   r~   r   r9   r   r   r   s   @r   ro   ro     sN          I         r   ro   c                      e Zd ZdZdS )mathz8Top-level MathML element, a single mathematical formula.Nr   r   r   r   r   r   %  s        BBBBr   r   c                      e Zd ZdZdS )mtextz*Arbitrary text with no notational meaning.Nr   r   r   r   r   r   ,  s        4444r   r   c                      e Zd ZdZdS )mizCIdentifier, such as a function name, variable or symbolic constant.Nr   r   r   r   r   r   0  s        MMMMr   r   c                      e Zd ZdZdS )mnzNumeric literal.

    >>> mn(3.41).toxml()
    '<mn>3.41</mn>'

    Normally a sequence of digits with a possible separator (a dot or a comma).
    (Values with comma must be specified as `str`.)
    Nr   r   r   r   r   r   4  s           r   r   c                      e Zd ZdZdS )moa  Operator, Fence, Separator, or Accent.

    >>> mo('<').toxml()
    '<mo>&lt;</mo>'

    Besides operators in strict mathematical meaning, this element also
    includes "operators" like parentheses, separators like comma and
    semicolon, or "absolute value" bars.
    Nr   r   r   r   r   r   ?  s           r   r   c                      e Zd ZdZdZdS )mspacezBlank space, whose size is set by its attributes.

    Takes additional attributes `depth`, `height`, `width`.
    Takes no children and no text.

    See also `mphantom`.
    r   Nr!   r}   r~   r   r9   r   r   r   r   r   K  s          IIIr   r   c                  *     e Zd ZdZddZ fdZ xZS )mrowzyGeneric element to group children as a horizontal row.

    Removed on closing if not required (see `mrow.close()`).
    r   r   c                8   ddd}|                                  D ]\  }}|dv r`|r^|                    |          rI||                             |                    |                              ||                   |f          }|                    ||           dS )zTransfer attributes from self to other.

        "List values" (class, style) are appended to existing values,
        other values replace existing values.
         z; )r   r   N)r   rc   r<   rp   rE   )r   other
delimitersr   r   s        r   transfer_attributeszmrow.transfer_attributes_  s      #T22
JJLL 	 	DAq&&&1&99Q<< A"1**1,,Z];;Q?A AAIIaOOOO	 	r   c                B   | j         }|vt          |           dk    rc| d         }	 ||t          |                              |           <   ||_         n# t          t
          f$ r Y dS w xY w|                     |           t                                                      S )z|Close element and return first non-full anchestor or None.

        Remove <mrow> if it has only one child element.
        N   r   )	rL   rM   listr^   re   r   r   r   rT   )r   rL   r/   r    s      r   rT   z
mrow.closem  s    
 #d))q..GE38tF||))$//0%"J/   tt$$U+++ww}}s   ,A A)(A)r|   )r!   r}   r~   r   r   rT   r   r   s   @r   r   r   Y  sV         
           r   r   c                      e Zd ZdZdS )mfraczAFractions or fraction-like objects such as binomial coefficients.Nr   r   r   r   r   r     s        KKKKr   r   c                      e Zd ZdZdZdS )msqrtzSquare root. See also `mroot`.r   Nr   r   r   r   r   r     s        ((IIIr   r   c                      e Zd ZdZdS )mrootz/Roots with an explicit index. See also `msqrt`.Nr   r   r   r   r   r             9999r   r   c                      e Zd ZdZdS )mstylezStyle Change.

    In modern browsers, <mstyle> is equivalent to an <mrow> element.
    However, <mstyle> may still be relevant for compatibility with
    MathML implementations outside browsers.
    Nr   r   r   r   r   r     s           r   r   c                      e Zd ZdZdS )merrorz#Display contents as error messages.Nr   r   r   r   r   r     s        ----r   r   c                      e Zd ZdZdZdS )menclosezRenders content inside an enclosing notation...

    ... specified by the notation attribute.

    Non-standard but still required by Firefox for boxed expressions.
    r   Nr   r   r   r   r   r     s          IIIr   r   c                      e Zd ZdZdS )mpaddedzAdjust space around content.Nr   r   r   r   r   r     s        &&&&r   r   c                      e Zd ZdZdZdS )mphantomz8Placeholder: Rendered invisibly but dimensions are kept.r   Nr   r   r   r   r   r     s        BBIIIr   r   c                      e Zd ZdZdS )msubz$Attach a subscript to an expression.Nr   r   r   r   r   r     s        ....r   r   c                      e Zd ZdZdS )msupz&Attach a superscript to an expression.Nr   r   r   r   r   r     s        0000r   r   c                      e Zd ZdZdZdS )msubsupz;Attach both a subscript and a superscript to an expression.   Nr   r   r   r   r   r     s        EEIIIr   r   c                      e Zd ZdZdS )munderz0Attach an accent or a limit under an expression.Nr   r   r   r   r   r     s        ::::r   r   c                      e Zd ZdZdS )moverz/Attach an accent or a limit over an expression.Nr   r   r   r   r   r     r   r   r   c                      e Zd ZdZdS )
munderoverz;Attach accents or limits both under and over an expression.Nr   r   r   r   r   r     s        EEEEr   r   c                      e Zd ZdZdS )mtablezTable or matrix element.Nr   r   r   r   r   r     s        """"r   r   c                      e Zd ZdZdS )mtrzRow in a table or a matrix.Nr   r   r   r   r   r             %%%%r   r   c                      e Zd ZdZdS )mtdzCell in a table or a matrixNr   r   r   r   r   r     r   r   r   )'r   
__future__r   __docformat__r   xml.etree.ElementTreeetreeElementTreerh   GLOBAL_ATTRIBUTESElementr   r   r   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s1  
 
 # " " " " ""  " " " " " " " " " l l l l l"* l l lpE E E E Ek E E E       2       $C C C C C7 C C C5 5 5 5 5I 5 5 5N N N N N N N N       	 	 	 	 	 	 	 	    [   # # # # #7 # # #LL L L L LJ L L L    G   
: : : : :J : : :    W   . . . . .W . . .    w   ' ' ' ' 'g ' ' '
    w   / / / / /: / / /1 1 1 1 1: 1 1 1    j   $; ; ; ; ;T ; ; ;: : : : :D : : :F F F F F F F F# # # # #[ # # #& & & & &' & & && & & & &' & & & & &r   