
    hc                       S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
JrJrJr  SSKJr  SSKJrJr  SSKJr  SSKJrJrJr  SS	KJr  \(       a  SS
KJr  SSKJr  S)S jr " S S\ 5      r!\" S5      r" " S S\#5      r$ " S S5      r% " S S\%5      r& " S S\%5      r' " S S5      r( " S S\(5      r) " S S\(5      r* " S S\(5      r+ " S  S!\(5      r, " S" S#\(5      r- " S$ S%\(5      r. " S& S'\R"                  \$S(9r/g)*z?Enabling declarative definition of lxml custom element classes.    )annotationsN)	TYPE_CHECKINGAnyCallableDictListSequenceTupleTypeTypeVar)etree)ElementBase_Element)InvalidXmlError)NamespacePrefixedTagnsmapqn)lazyproperty)BaseXmlEnum)BaseSimpleTypec                D    [         R                  " U SSS9n[        U5      $ )zSSerialize `element` to human-readable XML suitable for tests.

No XML declaration.
unicodeT)encodingpretty_print)r   tostring	XmlString)elementxmls     D/var/www/html/env/lib/python3.13/site-packages/docx/oxml/xmlchemy.pyserialize_for_readingr        s     
 ..94
HCS>    c                  x    \ rS rSrSr\R                  " S5      rSS jrSS jr	SS jr
SS jr\SS j5       rS	rg
)r   )   zYProvides string comparison override suitable for serialized XML that is useful
for tests.z)( *</?[\w:]+)(.*?)(/?>)([^<]*</[\w:]+>)?$c                    [        U[        5      (       d  gU R                  5       nUR                  5       n[        U5      [        U5      :w  a  g[	        X#5       H  u  pEU R                  XE5      (       a  M    g   g)NFT)
isinstancestr
splitlineslenzip_eq_elm_strs)selfotherlineslines_otherline
line_others         r   __eq__XmlString.__eq__5   sk    %%%!&&(u:[)) #E 7D$$T66 !8 r!   c                .    U R                  U5      (       + $ N)r1   )r+   r,   s     r   __ne__XmlString.__ne__A   s    ;;u%%%r!   c                X    UR                  5       nUR                  5       n[        U5      $ )z{Return a sequence of attribute strings parsed from `attrs`.

Each attribute string is stripped of whitespace on both ends.
)stripsplitsorted)r+   attrsattr_lsts      r   	_attr_seqXmlString._attr_seqD   s%    
 ;;=hr!   c                    U R                  U5      u  p4pVU R                  U5      u  pxpX7:w  a  gU R                  U5      U R                  U5      :w  a  gXY:w  a  gXj:w  a  gg)zRReturn True if the element in `line_2` is XML equivalent to the element in
`line`.FT)_parse_liner=   )r+   r/   line_2frontr;   closetextfront_2attrs_2close_2text_2s              r   r*   XmlString._eq_elm_strsM   sh     %)$4$4T$:!e,0,<,<V,D)'>>% DNN7$;;>r!   c                    U R                   R                  U5      nUc  g[        SS5       Vs/ s H  o2R                  U5      PM     snu  pEpgXEXg4$ s  snf )zI(front, attrs, close, text) 4-tuple result of parsing XML element `line`.) rK   rK   rK         )_xml_elm_line_pattmatchrangegroup)clsr/   rO   nrB   r;   rC   rD   s           r   r@   XmlString._parse_line\   sX     &&,,T2=!=B1a[$I[[[^[$I!eU(( %Js   A N)r,   objectreturnbool)r;   r&   rW   z	List[str])r/   r&   rA   r&   )r/   r&   rW   zTuple[str, str, str, str])__name__
__module____qualname____firstlineno____doc__recompilerN   r1   r5   r=   r*   classmethodr@   __static_attributes__rU   r!   r   r   r   )   sA     $PQ
&  ) )r!   r   _Tc                  "    \ rS rSrSrSS jrSrg)MetaOxmlElementi   zMetaclass for BaseOxmlElement.c                    [         [        [        [        [        [
        [        4nUR                  5        H(  u  pV[        Xd5      (       d  M  UR                  X5        M*     g r4   )
OneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOneZeroOrOneChoiceitemsr%   populate_class_members)rR   clsnamebases	namespacedispatchablekeyvalues          r   __init__MetaOxmlElement.__init__l   sL    
 $//+JC%..,,S6 ,r!   rU   N)rp   r&   rq   zTuple[type, ...]rr   zDict[str, Any])rY   rZ   r[   r\   r]   rv   ra   rU   r!   r   rd   rd   i   s
    (7r!   rd   c                  |   ^  \ rS rSrSrS
U 4S jjrSS jrS r\S 5       r	\SS j5       r
\  SS j5       rS	rU =r$ )BaseAttribute{   zRBase class for OptionalAttribute and RequiredAttribute.

Provides common methods.
c                B   > [         [        U ]  5         Xl        X l        g r4   )superry   rv   
_attr_name_simple_type)r+   	attr_namesimple_type	__class__s      r   rv   BaseAttribute.__init__   s    mT+-#'r!   c                <    Xl         X l        U R                  5         gz-Add the appropriate methods to `element_cls`.N)_element_cls
_prop_name_add_attr_propertyr+   element_cls	prop_names      r   ro   $BaseAttribute.populate_class_members   s    '#!r!   c                    [        U R                  U R                  S5      n[        U R                  U R
                  U5        g)zAdd a read/write `.{prop_name}` property to the element class.

The property returns the interpreted value of this attribute on access and
changes the attribute value to its ST_* counterpart on assignment.
N)property_getter_settersetattrr   r   r+   	property_s     r   r    BaseAttribute._add_attr_property   s0     T\\4<<>	!!4??I>r!   c                d    SU R                   ;   a  [        U R                   5      $ U R                   $ )N:)r}   r   r+   s    r   _clark_nameBaseAttribute._clark_name   s'    $//!doo&&r!   c                    g r4   rU   r   s    r   r   BaseAttribute._getter   s    BEr!   c                    g r4   rU   r   s    r   r   BaseAttribute._setter   s     9<r!   )r}   r   r   r~   )r   r&   r   (Type[BaseXmlEnum] | Type[BaseSimpleType]r   rd   r   r&   rW   NonerW   z'Callable[[BaseOxmlElement], Any | None])rW   z-Callable[[BaseOxmlElement, Any | None], None])rY   rZ   r[   r\   r]   rv   ro   r   r   r   r   r   ra   __classcell__r   s   @r   ry   ry   {   sU    
(
"?  
 E E<	6< <r!   ry   c                  |   ^  \ rS rSrSr S     S	U 4S jjjr\S 5       r\  S
S j5       r\SS j5       r	Sr
U =r$ )ri      zDefines an optional attribute on a custom element class.

An optional attribute returns a default value when not present for reading. When
assigned |None|, the attribute is removed, but still returns the default value when
one is specified.
c                8   > [         [        U ]  X5        X0l        g r4   )r|   ri   rv   _default)r+   r   r   defaultr   s       r   rv   OptionalAttribute.__init__   s     	/	Gr!   c                N    U R                   R                   SU R                   S3$ )z;String to use as `__doc__` attribute of attribute property. type-converted value of ``z`` attribute, or |None| (or specified default value) if not present. Assigning the default value causes the attribute to be removed from the element.r~   rY   r}   r   s    r   
_docstringOptionalAttribute._docstring   s4       ))* +//" #9:	
r!   c                B   ^      SU 4S jjnT R                   Ul        U$ )zJFunction suitable for `__get__()` method on attribute property descriptor.c                   > U R                  TR                  5      nUc  TR                  $ TR                  R	                  U5      $ r4   )getr   r   r~   from_xmlobjattr_str_valuer+   s     r   get_attr_value1OptionalAttribute._getter.<locals>.get_attr_value   s@     !WWT%5%56N%}}$$$--n==r!   r   BaseOxmlElementrW   
Any | Noner   r]   r+   r   s   ` r   r   OptionalAttribute._getter   s,    	> 	>	> "&r!   c                   ^  SU 4S jjnU$ )zJFunction suitable for `__set__()` method on attribute property descriptor.c                h  > Ub  UTR                   :X  a2  TR                  U R                  ;   a  U R                  TR                  	 g TR                  R	                  U5      nUc2  TR                  U R                  ;   a  U R                  TR                  	 g U R                  TR                  U5        g r4   )r   r   attribr~   to_xmlsetr   ru   	str_valuer+   s      r   set_attr_value1OptionalAttribute._setter.<locals>.set_attr_value   s    } 6##szz1

4#3#34))007I ##szz1

4#3#34GGD$$i0r!   )r   r   ru   r   rU   r+   r   s   ` r   r   OptionalAttribute._setter   s    
	1 r!   )r   r4   )r   r&   r   r   r   z0BaseXmlEnum | BaseSimpleType | str | bool | Noner   rW   z&Callable[[BaseOxmlElement, Any], None])rY   rZ   r[   r\   r]   rv   r   r   r   r   ra   r   r   s   @r   ri   ri      sz     EI	   >  B	    
 
 	0    r!   ri   c                  P    \ rS rSrSr\S 5       r\SS j5       r\S	S j5       rSr	g)
rj      a  Defines a required attribute on a custom element class.

A required attribute is assumed to be present for reading, so does not have a
default value; its actual value is always used. If missing on read, an
|InvalidXmlError| is raised. It also does not remove the attribute if |None| is
assigned. Assigning |None| raises |TypeError| or |ValueError|, depending on the
simple type of the attribute.
c                R    U R                   R                  < SU R                  < S3$ )zYReturn the string to use as the ``__doc__`` attribute of the property for
this attribute.r   z`` attribute.r   r   s    r   r   RequiredAttribute._docstring   s$    
 &&OO
 	
r!   c                :   ^  SU 4S jjnT R                   Ul        U$ )zDfunction object suitable for "get" side of attr property descriptor.c                   > U R                  TR                  5      nUc'  [        STR                  < SU R                  < 35      eTR
                  R                  U5      $ )Nz
required 'z#' attribute not present on element )r   r   r   r}   tagr~   r   r   s     r   r   1RequiredAttribute._getter.<locals>.get_attr_value   sV     WWT%5%56N%%KO??\_\c\cd  $$--n==r!   r   r   r   s   ` r   r   RequiredAttribute._getter   s    	> "&r!   c                   ^  SU 4S jjnU$ )zIfunction object suitable for "set" side of attribute property descriptor.c                   > TR                   R                  U5      nUc  [        SU S35      eU R                  TR                  U5        g )Nzcannot assign z to this required attribute)r~   r   
ValueErrorr   r   r   s      r   r   1RequiredAttribute._setter.<locals>.set_attr_value  sH    ))007I  >%8S!TUUGGD$$i0r!   )r   r   ru   r   rU   r   s   ` r   r   RequiredAttribute._setter  s    	1 r!   rU   N)rW   z Callable[[BaseOxmlElement], Any]r   )
rY   rZ   r[   r\   r]   r   r   r   r   ra   rU   r!   r   rj   rj      sC     
 
   	 	r!   rj   c                     ^  \ rS rSrSrSSU 4S jjjrSS jrS rS rS r	S r
S	 r\S
 5       rS rSS jr\SS j5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrU =r$ )_BaseChildElementi  zBase class for the child-element classes.

The child-element sub-classes correspond to varying cardinalities, such as ZeroOrOne
and ZeroOrMore.
c                B   > [         [        U ]  5         Xl        X l        g r4   )r|   r   rv   _nsptagname_successors)r+   
nsptagname
successorsr   s      r   rv   _BaseChildElement.__init__  s    /1%%r!   c                    Xl         X l        g)zFBaseline behavior for adding the appropriate methods to `element_cls`.N)r   r   r   s      r   ro   (_BaseChildElement.populate_class_members   s    '#r!   c                v   ^  SU 4S jjnST R                   -  Ul        T R                  T R                  U5        g)zGAdd an ``_add_x()`` method to the element class for this child element.c                   > [        U TR                  5      nU" 5       nUR                  5        H  u  pE[        X4U5        M     [        U TR                  5      nU" U5        U$ r4   )getattr_new_method_namern   r   _insert_method_name)r   r;   
new_methodchildrt   ru   insert_methodr+   s          r   
_add_child0_BaseChildElement._add_adder.<locals>._add_child(  sW     d&;&;<JLE#kkm
E* ,#C)A)ABM% Lr!   SAdd a new ``<%s>`` child element unconditionally, inserted in the correct sequence.N)r   r   r;   r   )r   r]   _add_to_class_add_method_name)r+   r   s   ` r   
_add_adder_BaseChildElement._add_adder%  s;    	#%)%5%56 	 	400*=r!   c                |    U R                   nSU R                  -  Ul        U R                  U R                  U5        g)zAdd a ``_new_{prop_name}()`` method to the element class that creates a new,
empty element of the correct type, having no attributes.zYReturn a "loose", newly created ``<%s>`` element having no attributes, text, or children.N)_creatorr   r]   r   r   )r+   creators     r   _add_creator_BaseChildElement._add_creator7  s?     --(*.*:*:; 	 	400':r!   c                t    [        U R                  SS5      n[        U R                  U R                  U5        g)zUAdd a read-only ``{prop_name}`` property to the element class for this child
element.N)r   r   r   r   r   r   s     r   _add_getter_BaseChildElement._add_getterA  s,     T\\46	!!4??I>r!   c                v   ^  SU 4S jjnST R                   -  Ul        T R                  T R                  U5        g)zJAdd an ``_insert_x()`` method to the element class for this child element.c                B   > U R                   " U/TR                  Q76   U$ r4   )insert_element_beforer   r   r   r+   s     r   _insert_child6_BaseChildElement._add_inserter.<locals>._insert_childK  s!    %%e?d.>.>?Lr!   zYReturn the passed ``<%s>`` element after inserting it as a child in the correct sequence.N)r   r   r   r   )r   r]   r   r   )r+   r   s   ` r   _add_inserter_BaseChildElement._add_inserterH  s;    	
)+/+;+;< 	 	433]Cr!   c                |    SU R                   -  n[        U R                  SS5      n[        U R                  X5        g)zzAdd a read-only ``{prop_name}_lst`` property to the element class to retrieve
a list of child elements matching this type.z%s_lstN)r   r   _list_getterr   r   )r+   r   r   s      r   _add_list_getter"_BaseChildElement._add_list_getterU  s6     t.	T..d;	!!98r!   c                     SU R                   -  $ )Nz_add_%sr   r   s    r   r   "_BaseChildElement._add_method_name\      4??**r!   c                v   ^  SU 4S jjnST R                   -  Ul        T R                  T R                  U5        g)z<Add a public ``add_x()`` method to the parent element class.c                B   > [        U TR                  5      nU" 5       nU$ r4   )r   r   )r   private_add_methodr   r+   s      r   	add_child6_BaseChildElement._add_public_adder.<locals>.add_childc  s#    !(d.C.C!D&(ELr!   r   Nr   r   )r   r]   r   _public_add_method_name)r+   r  s   ` r   _add_public_adder#_BaseChildElement._add_public_adder`  s;    	#%)%5%56 	 	477Cr!   c                h    [        U R                  U5      (       a  g[        U R                  X5        g)zZAdd `method` to the target class as `name`, unless `name` is already defined
on the class.N)hasattrr   r   )r+   namemethods      r   r   _BaseChildElement._add_to_classn  s*     4$$d++!!40r!   c                (   ^ ^ SSK Jm  SUU 4S jjnU$ )zHCallable that creates an empty element of the right type, with no attrs.r   )OxmlElementc                (   > T" TR                   5      $ r4   r   )r   r  r+   s    r   new_child_element5_BaseChildElement._creator.<locals>.new_child_elementz  s    t//00r!   r  )docx.oxml.parserr  )r+   r  r  s   ` @r   r   _BaseChildElement._creatoru  s     	1	1 	1 ! r!   c                @   ^  SU 4S jjnST R                   -  Ul        U$ )zReturn a function object suitable for the "get" side of the property
descriptor.

This default getter returns the child element with matching tag name or |None|
if not present.
c                L   > U R                  [        TR                  5      5      $ r4   )findr   r   r   r+   s    r   get_child_element4_BaseChildElement._getter.<locals>.get_child_element  s    88Bt//011r!   z0``<%s>`` child element or |None| if not present.r  r   r]   r+   r"  s   ` r   r   _BaseChildElement._getter  s(    	2 ?AQAQQ 	! ! r!   c                     SU R                   -  $ )Nz
_insert_%sr  r   s    r   r   %_BaseChildElement._insert_method_name      doo--r!   c                @   ^  SU 4S jjnST R                   -  Ul        U$ )zSReturn a function object suitable for the "get" side of a list property
descriptor.c                L   > U R                  [        TR                  5      5      $ r4   )findallr   r   r!  s    r   get_child_element_list>_BaseChildElement._list_getter.<locals>.get_child_element_list  s    ;;r$"2"2344r!   zPA list containing each of the ``<%s>`` child elements, in the order they appear.r  r$  )r+   r-  s   ` r   r  _BaseChildElement._list_getter  s+    
	5 "&"2"23 	& &%r!   c                     SU R                   -  $ )zadd_childElement() is public API for a repeating element, allowing new
elements to be added to the sequence.

May be overridden to provide a friendlier API to clients having domain
appropriate parameter names for required attributes.
zadd_%sr  r   s    r   r  )_BaseChildElement._public_add_method_name  s     $//))r!   c                     SU R                   -  $ Nz
_remove_%sr  r   s    r   _remove_method_name%_BaseChildElement._remove_method_name  r)  r!   c                     SU R                   -  $ )Nz_new_%sr  r   s    r   r   "_BaseChildElement._new_method_name  r  r!   )r   r   r   r   rU   )r   r&   r   Tuple[str, ...]r   )r  r&   r  zCallable[..., Any])rW   z,Callable[[BaseOxmlElement], BaseOxmlElement])rY   rZ   r[   r\   r]   rv   ro   r   r   r   r   r  r   r   r  r   r   r   r   r   r  r  r4  r   ra   r   r   s   @r   r   r     s    & &
$
>$;?D9 + +D1 ! ! ! !  . . & & * * . . + +r!   r   c                  x    \ rS rSrSr\S 5       r        SS jrS r\S 5       r	\
S 5       r\
S 5       rS	rg
)Choicei  zVDefines a child element belonging to a group, only one of which may appear as a
child.c                    U R                   $ r4   r  r   s    r   r   Choice.nsptagname  s    r!   c                    Xl         X l        X0l        U R                  5         U R	                  5         U R                  5         U R                  5         U R                  5         gr   )r   _group_prop_namer   r   r   r   r   _add_get_or_change_to_method)r+   r   group_prop_namer   s       r   ro   Choice.populate_class_members  sP     ( /%))+r!   c                v   ^  SU 4S jjnST R                   -  Ul        T R                  T R                  U5        g)zRAdd a ``get_or_change_to_x()`` method to the element class for this child
element.c                   > [        U TR                  5      nUb  U$ [        U TR                  5      nU" 5         [        U TR                  5      nU" 5       nU$ r4   )r   r   _remove_group_method_namer   )r   r   remove_group_method
add_methodr+   s       r   get_or_change_to_childCChoice._add_get_or_change_to_method.<locals>.get_or_change_to_child  sU    C1E ")#t/M/M"N! d&;&;<JLELr!   zFReturn the ``<%s>`` child, replacing any other group element if found.Nr  )r   r]   r   _get_or_change_to_method_name)r+   rH  s   ` r   r@  #Choice._add_get_or_change_to_method  s;    	 X*& 	4==?UVr!   c                    SU R                   ;   a  U R                   R                  S5      S-   OSnU R                   US $ )zDProperty name computed from tag name, e.g. a:schemeClr -> schemeClr.r   rL   r   N)r   index)r+   starts     r   r   Choice._prop_name  sB     47$:J:J3J  &&s+a/PQ''r!   c                     SU R                   -  $ )Nzget_or_change_to_%sr  r   s    r   rJ  $Choice._get_or_change_to_method_name  s    $t66r!   c                     SU R                   -  $ r3  )r?  r   s    r   rE   Choice._remove_group_method_name  s    d3333r!   )r   r?  r   N)r   rd   rA  r&   r   r9  rW   r   )rY   rZ   r[   r\   r]   r   r   ro   r@  r   r   rJ  rE  ra   rU   r!   r   r;  r;    s        ,$, , $	,
 
,"W& ( (
 7 7 4 4r!   r;  c                  P   ^  \ rS rSrSrSU 4S jjrSU 4S jjr\S 5       rSr	U =r
$ )	rg   i  z5Defines a required child element for MetaOxmlElement.c                .   > [         [        U ]  US5        g )NrU   )r|   rg   rv   )r+   r   r   s     r   rv   OneAndOnlyOne.__init__  s    mT+J;r!   c                L   > [         [        U ]  X5        U R                  5         gr   )r|   rg   ro   r   r+   r   r   r   s      r   ro   $OneAndOnlyOne.populate_class_members  s    mT9+Qr!   c                @   ^  SU 4S jjnST R                   -  Ul        U$ )PReturn a function object suitable for the "get" side of the property
descriptor.c                   > U R                  [        TR                  5      5      nUc  [        STR                  -  5      eU$ )Nz+required ``<%s>`` child element not present)r   r   r   r   r   s     r   r"  0OneAndOnlyOne._getter.<locals>.get_child_element   sC    HHR 0 012E}%ADDTDTT  Lr!   z Required ``<%s>`` child element.r  r$  r%  s   ` r   r   OneAndOnlyOne._getter  s%    
	 %GIYIY$Y!  r!   rU   )r   r&   r   )rY   rZ   r[   r\   r]   rv   ro   r   r   ra   r   r   s   @r   rg   rg     s$    ?<
 ! !r!   rg   c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )rh   i  zUDefines a repeating child element for MetaOxmlElement that must appear at least
once.c                   > [         [        U ]  X5        U R                  5         U R	                  5         U R                  5         U R                  5         U R                  5         [        X5        gr   )	r|   rh   ro   r  r   r   r   r  delattrrX  s      r   ro    OneOrMore.populate_class_members  sT    i5kM 'r!   rU   r   rY   rZ   r[   r\   r]   ro   ra   r   r   s   @r   rh   rh     s    ( (r!   rh   c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )rk   i  z@Defines an optional repeating child element for MetaOxmlElement.c                   > [         [        U ]  X5        U R                  5         U R	                  5         U R                  5         U R                  5         U R                  5         [        X5        gr   )	r|   rk   ro   r  r   r   r   r  ra  rX  s      r   ro   !ZeroOrMore.populate_class_members  sT    j$6{N 'r!   rU   r   rc  r   s   @r   rk   rk     s    J( (r!   rk   c                  L   ^  \ rS rSrSrSU 4S jjrS rS r\S 5       r	Sr
U =r$ )	rl   i)  z6Defines an optional child element for MetaOxmlElement.c                   > [         [        U ]  X5        U R                  5         U R	                  5         U R                  5         U R                  5         U R                  5         U R                  5         gr   )	r|   rl   ro   r   r   r   r   _add_get_or_adder_add_removerrX  s      r   ro    ZeroOrOne.populate_class_members,  sX    i5kM r!   c                v   ^  SU 4S jjnST R                   -  Ul        T R                  T R                  U5        g)zLAdd a ``get_or_add_x()`` method to the element class for this child
element.c                t   > [        U TR                  5      nUc  [        U TR                  5      nU" 5       nU$ r4   )r   r   r   )r   r   rG  r+   s      r   get_or_add_child5ZeroOrOne._add_get_or_adder.<locals>.get_or_add_child:  s6    C1E}$S$*?*?@
"Lr!   z>Return the ``<%s>`` child element, newly added if not present.Nr  )r   r]   r   _get_or_add_method_name)r+   rn  s   ` r   ri  ZeroOrOne._add_get_or_adder6  s;    	 M$  	4779IJr!   c                v   ^  SU 4S jjnST R                   -  Ul        T R                  T R                  U5        g)zIAdd a ``_remove_x()`` method to the element class for this child element.c                <   > U R                  TR                  5        g r4   )
remove_allr   r!  s    r   _remove_child-ZeroOrOne._add_remover.<locals>._remove_childI  s    NN4++,r!   z#Remove all ``<%s>`` child elements.Nr  )r   r]   r   r4  )r+   ru  s   ` r   rj  ZeroOrOne._add_removerF  s4    	- "G$JZJZ Z433]Cr!   c                     SU R                   -  $ )Nzget_or_add_%sr  r   s    r   rp  !ZeroOrOne._get_or_add_method_nameO  s    00r!   rU   r   )rY   rZ   r[   r\   r]   ro   ri  rj  r   rp  ra   r   r   s   @r   rl   rl   )  s+    @K D 1 1r!   rl   c                  z   ^  \ rS rSrSrSSS jjrSU 4S jjrS rS r\	S 5       r
\S 5       r\S	 5       rS
rU =r$ )rm   iT  zaCorrespondes to an ``EG_*`` element group where at most one of its members may
appear as a child.c                    Xl         X l        g r4   _choicesr   )r+   choicesr   s      r   rv   ZeroOrOneChoice.__init__X  s    %r!   c                   > [         [        U ]  X5        U R                  5         U R                   H)  nUR                  XR
                  U R                  5        M+     U R                  5         gr   )r|   rm   ro   _add_choice_getterr}  r   r   _add_group_remover)r+   r   r   choicer   s       r   ro   &ZeroOrOneChoice.populate_class_members\  sR    ot;KS!mmF))+HXHXY $!r!   c                t    [        U R                  SS5      n[        U R                  U R                  U5        g)zAdd a read-only ``{prop_name}`` property to the element class that returns
the present member of this group, or |None| if none are present.N)r   _choice_getterr   r   r   r   s     r   r  "ZeroOrOneChoice._add_choice_getterd  s.     T00$=	!!4??I>r!   c                \   ^  SU 4S jjnSUl         T R                  T R                  U5        g)zKAdd a ``_remove_eg_x()`` method to the element class for this choice
group.c                N   > TR                    H  nU R                  U5        M     g r4   )_member_nsptagnamesrt  )r   tagnamer+   s     r   _remove_choice_group@ZeroOrOneChoice._add_group_remover.<locals>._remove_choice_groupo  s    33w' 4r!   z9Remove the current choice group child element if present.Nr  )r]   r    _remove_choice_group_method_name)r+   r  s   ` r   r  "ZeroOrOneChoice._add_group_removerk  s+    	( (c$4@@BVWr!   c                &   ^  SU 4S jjnSUl         U$ )r[  c                6   > U R                   " TR                  6 $ r4   )first_child_found_inr  r!  s    r   get_group_member_element@ZeroOrOneChoice._choice_getter.<locals>.get_group_member_element{  s    ++T-E-EFFr!   zbReturn the child element belonging to this element group, or |None| if no member child is present.r  )r]   )r+   r  s   ` r   r  ZeroOrOneChoice._choice_getterv  s    
	G4 	!( ('r!   c                X    U R                    Vs/ s H  oR                  PM     sn$ s  snf )zbSequence of namespace-prefixed tagnames, one for each of the member elements
of this choice group.)r}  r   )r+   r  s     r   r  #ZeroOrOneChoice._member_nsptagnames  s$     15>f!!>>>s   'c                     SU R                   -  $ r3  r  r   s    r   r  0ZeroOrOneChoice._remove_choice_group_method_name  r)  r!   r|  r8  )r~  zSequence[Choice]r   r9  r   )rY   rZ   r[   r\   r]   rv   ro   r  r  r   r  r   r  r  ra   r   r   s   @r   rm   rm   T  sY    &"?	X ( ( ? ?
 . .r!   rm   c                  |   ^  \ rS rSrSrS rSS jrSS jrSS jr\	SS j5       r
SU 4S jjr\	SS	 j5       rS
rU =r$ )r   i  znEffective base class for all custom element classes.

Adds standardized behavior to all classes in one place.
c                `    SU R                   R                  U R                  [        U 5      4-  $ )Nz<%s '<%s>' at 0x%0x>)r   rY   _nsptagidr   s    r   __repr__BaseOxmlElement.__repr__  s/    %NN##LLtH)
 
 	
r!   c                X    U H$  nU R                  [        U5      5      nUc  M"  Us  $    g)z9First child with tag in `tagnames`, or None if not found.N)r   r   )r+   tagnamesr  r   s       r   r  $BaseOxmlElement.first_child_found_in  s.    GIIbk*E    r!   c                r    U R                   " U6 nUb  UR                  U5        U$ U R                  U5        U$ r4   )r  addpreviousappend)r+   elmr  	successors       r   r   %BaseOxmlElement.insert_element_before  s@    --x8	 !!#& 
 KK
r!   c                ~    U H7  nU R                  [        U5      5      nU H  nU R                  U5        M     M9     g)z>Remove child elements with tagname (e.g. "a:p") in `tagnames`.N)r,  r   remove)r+   r  r  matchingr   s        r   rt  BaseOxmlElement.remove_all  s4    G||BwK0H!E" "  r!   c                    [        U 5      $ )zXML string for this element, suitable for testing purposes.

Pretty printed for readability and without an XML declaration at the top.
)r    r   s    r   r   BaseOxmlElement.xml  s     %T**r!   c                (   > [         TU ]  U[        S9$ )z}Override of `lxml` _Element.xpath() method.

Provides standard Open XML namespace mapping (`nsmap`) in centralized location.
)
namespaces)r|   xpathr   )r+   	xpath_strr   s     r   r  BaseOxmlElement.xpath  s    
 w}Y5}99r!   c                B    [         R                  " U R                  5      $ r4   )r   from_clark_namer   r   s    r   r  BaseOxmlElement._nsptag  s    #33DHH==r!   rU   )r  r&   rW   z_Element | None)r  r   r  r&   )r  r&   rW   r   )rW   r&   )r  r&   rW   r   )rY   rZ   r[   r\   r]   r  r  r   rt  r   r   r  r  ra   r   r   s   @r   r   r     sI    

# + +: > >r!   r   )	metaclass)r   r   )0r]   
__future__r   r^   typingr   r   r   r   r   r	   r
   r   r   lxmlr   
lxml.etreer   r   docx.oxml.exceptionsr   docx.oxml.nsr   r   r   docx.sharedr   docx.enum.baser   docx.oxml.simpletypesr   r    r&   r   rb   typerd   ry   ri   rj   r   r;  rg   rh   rk   rl   rm   r   rU   r!   r   <module>r     s    F " 	
 
 
  , 0 8 8 $*4:) :)z T]7d 7$(< (<V< <~, ,^^+ ^+B84 84v!% !8(! ((" ((1! (1V8.' 8.x5>e''? 5>r!   