
    j
e                    B   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZ ddlmZ ddlmZmZmZ dd	lmZ erdd
lmZ ddlmZ d+dZ G d de           Z! ed          Z" G d de#          Z$ G d d          Z% G d de%          Z& G d de%          Z' G d d          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j        e$*          Z/dS ),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)BaseSimpleTypeelementr   c                N    t          j        | dd          }t          |          S )z[Serialize `element` to human-readable XML suitable for tests.

    No XML declaration.
    unicodeT)encodingpretty_print)r   tostring	XmlString)r   xmls     \/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/docx/oxml/xmlchemy.pyserialize_for_readingr        s&    
 .94
H
H
HCS>>    c                  j    e Zd ZdZ ej        d          ZddZddZddZ	ddZ
edd            ZdS )r   z]Provides string comparison override suitable for serialized XML that is useful
    for tests.z)( *</?[\w:]+)(.*?)(/?>)([^<]*</[\w:]+>)?$otherobjectreturnboolc                &   t          |t                    sdS |                                 }|                                }t          |          t          |          k    rdS t	          ||          D ]\  }}|                     ||          s dS dS )NFT)
isinstancestr
splitlineslenzip_eq_elm_strs)selfr#   lineslines_otherline
line_others         r   __eq__zXmlString.__eq__5   s    %%% 	5!!&&((u::[))))5 #E; 7 7 	 	D*$$T:66 uutr!   c                .    |                      |           S N)r3   )r.   r#   s     r   __ne__zXmlString.__ne__A   s    ;;u%%%%r!   attrsr)   	List[str]c                p    |                                 }|                                }t          |          S )zReturn a sequence of attribute strings parsed from `attrs`.

        Each attribute string is stripped of whitespace on both ends.
        )stripsplitsorted)r.   r7   attr_lsts      r   	_attr_seqzXmlString._attr_seqD   s,    
 ;;==hr!   r1   line_2c                    |                      |          \  }}}}|                      |          \  }}}	}
||k    rdS |                     |          |                     |          k    rdS ||	k    rdS ||
k    rdS dS )zZReturn True if the element in `line_2` is XML equivalent to the element in
        `line`.FT)_parse_liner>   )r.   r1   r?   frontr7   closetextfront_2attrs_2close_2text_2s              r   r-   zXmlString._eq_elm_strsM   s     %)$4$4T$:$:!ueT,0,<,<V,D,D)'6G5>>%  DNN7$;$;;;5G56>>5tr!   Tuple[str, str, str, str]c                    | j                             |          dS fdt          dd          D             \  }}}}||||fS )zI(front, attrs, close, text) 4-tuple result of parsing XML element `line`.N) rK   rK   rK   c                :    g | ]}                     |          S  )group).0nmatchs     r   
<listcomp>z)XmlString._parse_line.<locals>.<listcomp>b   s#    $I$I$IU[[^^$I$I$Ir!         )_xml_elm_line_pattrQ   range)clsr1   rB   r7   rC   rD   rQ   s         @r   rA   zXmlString._parse_line\   s^     &,,T22=!>$I$I$I$IU1a[[$I$I$I!ueTeUD((r!   N)r#   r$   r%   r&   )r7   r)   r%   r8   )r1   r)   r?   r)   )r1   r)   r%   rI   )__name__
__module____qualname____doc__recompilerU   r3   r6   r>   r-   classmethodrA   rM   r!   r   r   r   )   s          $$PQQ
 
 
 
& & & &           ) ) ) [) ) )r!   r   _Tc                      e Zd ZdZd
dZd	S )MetaOxmlElementzMetaclass for BaseOxmlElement.clsnamer)   basesTuple[type, ...]	namespaceDict[str, Any]c                    t           t          t          t          t          t
          t          f}|                                D ]+\  }}t          ||          r|	                    | |           ,d S r5   )
OneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOneZeroOrOneChoiceitemsr(   populate_class_members)rW   rb   rc   re   dispatchablekeyvalues          r   __init__zMetaOxmlElement.__init__l   sp    
 $//++ 	7 	7JC%.. 7,,S#666	7 	7r!   N)rb   r)   rc   rd   re   rf   )rX   rY   rZ   r[   rt   rM   r!   r   ra   ra   i   s.        ((7 7 7 7 7 7r!   ra   c                  x     e Zd ZdZd fdZddZd Zed             Zedd            Z	edd            Z
 xZS )BaseAttributezZBase class for OptionalAttribute and RequiredAttribute.

    Provides common methods.
    	attr_namer)   simple_type(Type[BaseXmlEnum] | Type[BaseSimpleType]c                r    t          t          |                                            || _        || _        d S r5   )superrv   rt   
_attr_name_simple_type)r.   rw   rx   	__class__s      r   rt   zBaseAttribute.__init__   s6     	mT""++---#'r!   element_clsra   	prop_namer%   Nonec                J    || _         || _        |                                  dS z-Add the appropriate methods to `element_cls`.N)_element_cls
_prop_name_add_attr_propertyr.   r   r   s      r   rp   z$BaseAttribute.populate_class_members   s+     (#!!!!!r!   c                r    t          | j        | j        d          }t          | j        | j        |           dS )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   z BaseAttribute._add_attr_property   s6     T\4<>>	!4?I>>>>>r!   c                J    d| j         v rt          | j                   S | j         S )N:)r|   r   r.   s    r   _clark_namezBaseAttribute._clark_name   s'    $/!!do&&&r!   'Callable[[BaseOxmlElement], Any | None]c                    d S r5   rM   r   s    r   r   zBaseAttribute._getter   s    r!   -Callable[[BaseOxmlElement, Any | None], None]c                    d S r5   rM   r   s    r   r   zBaseAttribute._setter   s	     	r!   )rw   r)   rx   ry   r   ra   r   r)   r%   r   r%   r   )r%   r   )rX   rY   rZ   r[   rt   rp   r   r   r   r   r   __classcell__r~   s   @r   rv   rv   {   s         
( ( ( ( ( (" " " "? ? ?   X
    X    X    r!   rv   c                  n     e Zd ZdZ	 dd fd	Zed
             Zedd            Zedd            Z xZ	S )rj   a  Defines 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.
    Nrw   r)   rx   ry   default#BaseXmlEnum | BaseSimpleType | Nonec                h    t          t          |                               ||           || _        d S r5   )r{   rj   rt   _default)r.   rw   rx   r   r~   s       r   rt   zOptionalAttribute.__init__   s1     	&&//	;GGGr!   c                0    | j         j         d| j         dS )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}   rX   r|   r   s    r   
_docstringzOptionalAttribute._docstring   s0      ) : :/: : :	
r!   r%   r   c                ,     d fd} j         |_        |S )zJFunction suitable for `__get__()` method on attribute property descriptor.objBaseOxmlElementr%   
Any | Nonec                ~    |                      j                  }|j        S j                            |          S r5   )getr   r   r}   from_xmlr   attr_str_valuer.   s     r   get_attr_valuez1OptionalAttribute._getter.<locals>.get_attr_value   s>     !WWT%566N%}$$--n===r!   r   r   r%   r   r   r[   r.   r   s   ` r   r   zOptionalAttribute._getter   s3    	> 	> 	> 	> 	> 	> "&r!   &Callable[[BaseOxmlElement, Any], None]c                     d fd}|S )zJFunction suitable for `__set__()` method on attribute property descriptor.r   r   rs   r   c                   ||j         k    rj        | j        v r| j        j        = d S j                            |          }|j        | j        v r| j        j        = d S |                     j        |           d S r5   )r   r   attribr}   to_xmlsetr   rs   	str_valuer.   s      r   set_attr_valuez1OptionalAttribute._setter.<locals>.set_attr_value   s    } 6 6#sz11
4#34)0077I #sz11
4#34GGD$i00000r!   )r   r   rs   r   rM   r.   r   s   ` r   r   zOptionalAttribute._setter   s)    
	1 
	1 
	1 
	1 
	1 
	1 r!   r5   )rw   r)   rx   ry   r   r   r   r%   r   )
rX   rY   rZ   r[   rt   r   r   r   r   r   r   s   @r   rj   rj      s          8<	              
 
 X
    X     X    r!   rj   c                  X    e Zd ZdZed             Zed	d            Zed
d            ZdS )rk   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                0    | j         j        d| j        dS )zaReturn the string to use as the ``__doc__`` attribute of the property for
        this attribute.r   z`` attribute.r   r   s    r   r   zRequiredAttribute._docstring   s&    
 &&&OOO
 	
r!   r%    Callable[[BaseOxmlElement], Any]c                ,     d fd} j         |_        |S )zDfunction object suitable for "get" side of attr property descriptor.r   r   r%   r   c                    |                      j                  }|t          dj        d| j                  j                            |          S )Nz
required 'z#' attribute not present on element )r   r   r   r|   tagr}   r   r   s     r   r   z1RequiredAttribute._getter.<locals>.get_attr_value  s^     WWT%566N%%o1   $--n===r!   r   r   r   s   ` r   r   zRequiredAttribute._getter   s3    	> 	> 	> 	> 	> 	> "&r!   r   c                     d fd}|S )zIfunction object suitable for "set" side of attribute property descriptor.r   r   rs   r   c                    j                             |          }|t          d| d          |                     j        |           d S )Nzcannot assign z to this required attribute)r}   r   
ValueErrorr   r   r   s      r   r   z1RequiredAttribute._setter.<locals>.set_attr_value  sV    )0077I  !T%!T!T!TUUUGGD$i00000r!   )r   r   rs   r   rM   r   s   ` r   r   zRequiredAttribute._setter  s)    	1 	1 	1 	1 	1 	1 r!   N)r%   r   r   )rX   rY   rZ   r[   r   r   r   r   rM   r!   r   rk   rk      sy          
 
 X
    X 	 	 	 X	 	 	r!   rk   c                      e Zd ZdZd!d" fdZd#dZd Zd Zd Zd Z	d Z
ed             Zd Zd$dZed%d            Zed             Zed             Zed             Zed             Zed             Zed              Z xZS )&_BaseChildElementzBase class for the child-element classes.

    The child-element sub-classes correspond to varying cardinalities, such as ZeroOrOne
    and ZeroOrMore.
    rM   
nsptagnamer)   
successorsTuple[str, ...]c                r    t          t          |                                            || _        || _        d S r5   )r{   r   rt   _nsptagname_successors)r.   r   r   r~   s      r   rt   z_BaseChildElement.__init__"  s6    &&//111%%r!   r   ra   r   r%   r   c                "    || _         || _        dS )zFBaseline behavior for adding the appropriate methods to `element_cls`.N)r   r   r   s      r   rp   z(_BaseChildElement.populate_class_members'  s     (#r!   c                h     d fd}d j         z  |_                              j        |           dS )	zGAdd an ``_add_x()`` method to the element class for this child element.r   r   r7   r   c                    t          | j                  } |            }|                                D ]\  }}t          |||           t          | j                  } ||           |S r5   )getattr_new_method_namero   r   _insert_method_name)r   r7   
new_methodchildrr   rs   insert_methodr.   s          r   
_add_childz0_BaseChildElement._add_adder.<locals>._add_child1  sw     d&;<<JJLLE#kkmm + +
UsE****#C)ABBMM%   Lr!   SAdd a new ``<%s>`` child element unconditionally, inserted in the correct sequence.N)r   r   r7   r   )r   r[   _add_to_class_add_method_name)r.   r   s   ` r   
_add_adderz_BaseChildElement._add_adder.  sZ    	 	 	 	 	 	#%)%56 	 	40*=====r!   c                h    | j         }d| j        z  |_        |                     | j        |           dS )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_creatorz_BaseChildElement._add_creator@  sC     -(*.*:; 	 	40':::::r!   c                h    t          | j        dd          }t          | j        | j        |           dS )z]Add a read-only ``{prop_name}`` property to the element class for this child
        element.N)r   r   r   r   r   r   s     r   _add_getterz_BaseChildElement._add_getterJ  s4     T\466	!4?I>>>>>r!   c                h     d fd}d j         z  |_                              j        |           dS )zJAdd an ``_insert_x()`` method to the element class for this child element.r   r   r   c                .     | j         |gj        R   |S r5   )insert_element_beforer   r   r   r.   s     r   _insert_childz6_BaseChildElement._add_inserter.<locals>._insert_childT  s&    %C%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_inserterz_BaseChildElement._add_inserterQ  sZ    	 	 	 	 	 	
)+/+;< 	 	43]CCCCCr!   c                r    d| j         z  }t          | j        dd          }t          | j        ||           dS )zAdd 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_getterz"_BaseChildElement._add_list_getter^  s?     t.	T.d;;	!9i88888r!   c                    d| j         z  S )Nz_add_%sr   r   s    r   r   z"_BaseChildElement._add_method_namee      4?**r!   c                h     d fd}d j         z  |_                              j        |           dS )z<Add a public ``add_x()`` method to the parent element class.r   r   c                F    t          | j                  } |            }|S r5   )r   r   )r   private_add_methodr   r.   s      r   	add_childz6_BaseChildElement._add_public_adder.<locals>.add_childl  s)    !(d.C!D!D&&((ELr!   r   Nr   r   )r   r[   r   _public_add_method_name)r.   r   s   ` r   _add_public_adderz#_BaseChildElement._add_public_adderi  sZ    	 	 	 	 	 	#%)%56 	 	47CCCCCr!   namemethodCallable[..., Any]c                `    t          | j        |          rdS t          | j        ||           dS )zbAdd `method` to the target class as `name`, unless `name` is already defined
        on the class.N)hasattrr   r   )r.   r   r   s      r   r   z_BaseChildElement._add_to_classw  s9     4$d++ 	F!400000r!   ,Callable[[BaseOxmlElement], BaseOxmlElement]c                $     ddl m d fd}|S )zHCallable that creates an empty element of the right type, with no attrs.r   )OxmlElementr   r   c                $     j                   S r5   r   )r   r   r.   s    r   new_child_elementz5_BaseChildElement._creator.<locals>.new_child_element  s    ;t/000r!   r   )docx.oxml.parserr   )r.   r   r   s   ` @r   r   z_BaseChildElement._creator~  sC     	100000	1 	1 	1 	1 	1 	1 	1 ! r!   c                2     d fd}d j         z  |_        |S )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.
        r   r   c                R    |                      t          j                            S r5   )findr   r   r   r.   s    r   get_child_elementz4_BaseChildElement._getter.<locals>.get_child_element  s     88Bt/00111r!   z0``<%s>`` child element or |None| if not present.r   r   r[   r.   r  s   ` r   r   z_BaseChildElement._getter  s>    	2 	2 	2 	2 	2 	2 ?AQQ 	! ! r!   c                    d| j         z  S )Nz
_insert_%sr   r   s    r   r   z%_BaseChildElement._insert_method_name      do--r!   c                2     d fd}d j         z  |_        |S )z[Return a function object suitable for the "get" side of a list property
        descriptor.r   r   c                R    |                      t          j                            S r5   )findallr   r   r  s    r   get_child_element_listz>_BaseChildElement._list_getter.<locals>.get_child_element_list  s     ;;r$"233444r!   zPA list containing each of the ``<%s>`` child elements, in the order they appear.r   r  )r.   r  s   ` r   r   z_BaseChildElement._list_getter  sA    
	5 	5 	5 	5 	5 	5 "&"23 	& &%r!   c                    d| j         z  S )a
  add_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   z)_BaseChildElement._public_add_method_name  s     $/))r!   c                    d| j         z  S Nz
_remove_%sr   r   s    r   _remove_method_namez%_BaseChildElement._remove_method_name  r  r!   c                    d| j         z  S )Nz_new_%sr   r   s    r   r   z"_BaseChildElement._new_method_name  r   r!   rM   )r   r)   r   r   r   )r   r)   r   r   )r%   r   )rX   rY   rZ   r[   rt   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   s   @r   r   r     s        & & & & & & &
$ $ $ $> > >$; ; ;? ? ?D D D9 9 9 + + \+D D D1 1 1 1 ! ! ! X! ! ! X!  . . \. & & X& * * \* . . \. + + \+ + + + +r!   r   c                  x    e Zd ZdZed             ZddZd Zed             Ze	d             Z
e	d             ZdS )ChoicezZDefines a child element belonging to a group, only one of which may appear as a
    child.c                    | j         S r5   r   r   s    r   r   zChoice.nsptagname  s    r!   r   ra   group_prop_namer)   r   r   r%   r   c                    || _         || _        || _        |                                  |                                  |                                  |                                  |                                  dS r   )r   _group_prop_namer   r   r   r   r   _add_get_or_change_to_method)r.   r   r  r   s       r   rp   zChoice.populate_class_members  sz     ( /%))+++++r!   c                h     d fd}d j         z  |_                              j        |           dS )zZAdd a ``get_or_change_to_x()`` method to the element class for this child
        element.r   r   c                    t          | j                  }||S t          | j                  } |             t          | j                  } |            }|S r5   )r   r   _remove_group_method_namer   )r   r   remove_group_method
add_methodr.   s       r   get_or_change_to_childzCChoice._add_get_or_change_to_method.<locals>.get_or_change_to_child  sc    C11E ")#t/M"N"N!!! d&;<<JJLLELr!   zFReturn the ``<%s>`` child, replacing any other group element if found.Nr   )r   r[   r   _get_or_change_to_method_name)r.   r  s   ` r   r  z#Choice._add_get_or_change_to_method  sZ    	 	 	 	 	 	 X*& 	4=?UVVVVVr!   c                p    d| j         v r| j                             d          dz   nd}| j         |d         S )zDProperty name computed from tag name, e.g. a:schemeClr -> schemeClr.r   rS   r   N)r   index)r.   starts     r   r   zChoice._prop_name  sD     47$:J3J3J &&s++a//PQ''r!   c                    d| j         z  S )Nzget_or_change_to_%sr   r   s    r   r   z$Choice._get_or_change_to_method_name  s    $t66r!   c                    d| j         z  S r  )r  r   s    r   r  z Choice._remove_group_method_name  s    d333r!   N)r   ra   r  r)   r   r   r%   r   )rX   rY   rZ   r[   r   r   rp   r  r   r   r   r  rM   r!   r   r  r    s              X , , , ,"W W W& ( ( X(
 7 7 \7 4 4 \4 4 4r!   r  c                  F     e Zd ZdZd fdZd fd
Zed             Z xZS )rh   z5Defines a required child element for MetaOxmlElement.r   r)   c                Z    t          t          |                               |d           d S )NrM   )r{   rh   rt   )r.   r   r~   s     r   rt   zOneAndOnlyOne.__init__  s)    mT""++J;;;;;r!   r   ra   r   r%   r   c                    t          t          |                               ||           |                                  dS r   )r{   rh   rp   r   r.   r   r   r~   s      r   rp   z$OneAndOnlyOne.populate_class_members  s=     	mT""99+yQQQr!   c                2     d fd}d j         z  |_        |S )XReturn a function object suitable for the "get" side of the property
        descriptor.r   r   c                    |                      t          j                            }|t          dj        z            |S )Nz+required ``<%s>`` child element not present)r  r   r   r   r   s     r   r  z0OneAndOnlyOne._getter.<locals>.get_child_element  sH    HHR 01122E}%ADDTT   Lr!   z Required ``<%s>`` child element.r   r  r  s   ` r   r   zOneAndOnlyOne._getter  s>    
	 	 	 	 	 	 /1AA 	! ! r!   )r   r)   r   )	rX   rY   rZ   r[   rt   rp   r   r   r   r   s   @r   rh   rh     s|        ??< < < < < <      ! ! X! ! ! ! !r!   rh   c                  $     e Zd ZdZd	 fdZ xZS )
ri   zYDefines a repeating child element for MetaOxmlElement that must appear at least
    once.r   ra   r   r)   r%   r   c                B   t          t          |                               ||           |                                  |                                  |                                  |                                  |                                  t          ||           dS r   )	r{   ri   rp   r   r   r   r   r   delattrr)  s      r   rp   z OneOrMore.populate_class_members  s     	i55k9MMM   Y'''''r!   r   rX   rY   rZ   r[   rp   r   r   s   @r   ri   ri     sG         
( 
( 
( 
( 
( 
( 
( 
( 
( 
(r!   ri   c                  $     e Zd ZdZd	 fdZ xZS )
rl   z@Defines an optional repeating child element for MetaOxmlElement.r   ra   r   r)   r%   r   c                B   t          t          |                               ||           |                                  |                                  |                                  |                                  |                                  t          ||           dS r   )	r{   rl   rp   r   r   r   r   r   r/  r)  s      r   rp   z!ZeroOrMore.populate_class_members-  s     	j$66{INNN   Y'''''r!   r   r0  r   s   @r   rl   rl   *  sC        JJ
( 
( 
( 
( 
( 
( 
( 
( 
( 
(r!   rl   c                  F     e Zd ZdZd fdZd	 Zd
 Zed             Z xZ	S )rm   z6Defines an optional child element for MetaOxmlElement.r   ra   r   r)   r%   r   c                J   t          t          |                               ||           |                                  |                                  |                                  |                                  |                                  |                                  dS r   )	r{   rm   rp   r   r   r   r   _add_get_or_adder_add_removerr)  s      r   rp   z ZeroOrOne.populate_class_members=  s     	i55k9MMM   r!   c                h     d fd}d j         z  |_                              j        |           dS )zTAdd a ``get_or_add_x()`` method to the element class for this child
        element.r   r   c                t    t          | j                  }|t          | j                  } |            }|S r5   )r   r   r   )r   r   r  r.   s      r   get_or_add_childz5ZeroOrOne._add_get_or_adder.<locals>.get_or_add_childM  s;    C11E}$S$*?@@
"
Lr!   z>Return the ``<%s>`` child element, newly added if not present.Nr   )r   r[   r   _get_or_add_method_name)r.   r9  s   ` r   r5  zZeroOrOne._add_get_or_adderI  sZ    	 	 	 	 	 	 M$  	479IJJJJJr!   c                h     d fd}d j         z  |_                              j        |           dS )zIAdd a ``_remove_x()`` method to the element class for this child element.r   r   c                <    |                      j                   d S r5   )
remove_allr   r  s    r   _remove_childz-ZeroOrOne._add_remover.<locals>._remove_child\  s    NN4+,,,,,r!   z#Remove all ``<%s>`` child elements.Nr   )r   r[   r   r  )r.   r>  s   ` r   r6  zZeroOrOne._add_removerY  sW    	- 	- 	- 	- 	- 	- 2! 	43]CCCCCr!   c                    d| j         z  S )Nzget_or_add_%sr   r   s    r   r:  z!ZeroOrOne._get_or_add_method_named  s    00r!   r   )
rX   rY   rZ   r[   rp   r5  r6  r   r:  r   r   s   @r   rm   rm   :  s        @@
 
 
 
 
 
K K K 	D 	D 	D 1 1 \1 1 1 1 1r!   rm   c                  |     e Zd ZdZdddZd fdZd Zd Zed             Z	e
d             Ze
d             Z xZS )rn   zeCorrespondes to an ``EG_*`` element group where at most one of its members may
    appear as a child.rM   choicesSequence[Choice]r   r   c                "    || _         || _        d S r5   )_choicesr   )r.   rA  r   s      r   rt   zZeroOrOneChoice.__init__m  s    %r!   r   ra   r   r)   r%   r   c                    t          t          |                               ||           |                                  | j        D ]#}|                    || j        | j                   $|                                  dS r   )r{   rn   rp   _add_choice_getterrD  r   r   _add_group_remover)r.   r   r   choicer~   s       r   rp   z&ZeroOrOneChoice.populate_class_membersq  s     	ot$$;;KSSS!!!m 	 	F))T_d.>    	!!!!!r!   c                h    t          | j        dd          }t          | j        | j        |           dS )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   rF  z"ZeroOrOneChoice._add_choice_getter}  s5     T0$==	!4?I>>>>>r!   c                X     d fd}d|_                               j        |           dS )zSAdd a ``_remove_eg_x()`` method to the element class for this choice
        group.r   r   c                F    j         D ]}|                     |           d S r5   )_member_nsptagnamesr=  )r   tagnamer.   s     r   _remove_choice_groupz@ZeroOrOneChoice._add_group_remover.<locals>._remove_choice_group  s4    3 ( (w''''( (r!   z9Remove the current choice group child element if present.Nr   )r[   r    _remove_choice_group_method_name)r.   rO  s   ` r   rG  z"ZeroOrOneChoice._add_group_remover  sQ    	( 	( 	( 	( 	( 	(
 H 	$ 	4@BVWWWWWr!   c                "     d fd}d|_         |S )r+  r   r   c                "     | j         j         S r5   )first_child_found_inrM  r  s    r   get_group_member_elementz@ZeroOrOneChoice._choice_getter.<locals>.get_group_member_element  s    +3+T-EFFr!   zbReturn the child element belonging to this element group, or |None| if no member child is present.r   )r[   )r.   rT  s   ` r   rJ  zZeroOrOneChoice._choice_getter  s<    
	G 	G 	G 	G 	G 	G4 	!( ('r!   c                $    d | j         D             S )zjSequence of namespace-prefixed tagnames, one for each of the member elements
        of this choice group.c                    g | ]	}|j         
S rM   )r   )rO   rH  s     r   rR   z7ZeroOrOneChoice._member_nsptagnames.<locals>.<listcomp>  s    >>>f!>>>r!   )rD  r   s    r   rM  z#ZeroOrOneChoice._member_nsptagnames  s     ?>>>>>r!   c                    d| j         z  S r  r   r   s    r   rP  z0ZeroOrOneChoice._remove_choice_group_method_name  r  r!   r  )rA  rB  r   r   r   )rX   rY   rZ   r[   rt   rp   rF  rG  r   rJ  r   rM  rP  r   r   s   @r   rn   rn   i  s         & & & & &
" 
" 
" 
" 
" 
"? ? ?X X X ( ( X( ? ? \?
 . . \. . . . .r!   rn   c                  r     e Zd ZdZd ZddZdd
ZddZedd            Z	d fdZ
edd            Z xZS )r   zvEffective base class for all custom element classes.

    Adds standardized behavior to all classes in one place.
    c                J    d| j         j        | j        t          |           fz  S )Nz<%s '<%s>' at 0x%0x>)r~   rX   _nsptagidr   s    r   __repr__zBaseOxmlElement.__repr__  s*    %N#LtHH)
 
 	
r!   tagnamesr)   r%   _Element | Nonec                `    |D ]*}|                      t          |                    }||c S +dS )z9First child with tag in `tagnames`, or None if not found.N)r  r   )r.   r]  rN  r   s       r   rS  z$BaseOxmlElement.first_child_found_in  sA     	 	GIIbkk**E  !tr!   elmr   c                t     | j         | }||                    |           n|                     |           |S r5   )rS  addpreviousappend)r.   r`  r]  	successors       r   r   z%BaseOxmlElement.insert_element_before  sE    -D-x8	 !!#&&&&KK
r!   r   c                    |D ]>}|                      t          |                    }|D ]}|                     |           ?dS )z>Remove child elements with tagname (e.g. "a:p") in `tagnames`.N)r  r   remove)r.   r]  rN  matchingr   s        r   r=  zBaseOxmlElement.remove_all  s[     	# 	#G||BwKK00H! # #E""""#	# 	#r!   c                     t          |           S )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   zBaseOxmlElement.xml  s     %T***r!   	xpath_strr   c                T    t                                          |t                    S )zOverride of `lxml` _Element.xpath() method.

        Provides standard Open XML namespace mapping (`nsmap`) in centralized location.
        )
namespaces)r{   xpathr   )r.   ri  r~   s     r   rl  zBaseOxmlElement.xpath  s     ww}}Y5}999r!   c                4    t          j        | j                  S r5   )r   from_clark_namer   r   s    r   rZ  zBaseOxmlElement._nsptag  s    #3DH===r!   )r]  r)   r%   r^  )r`  r   r]  r)   )r]  r)   r%   r   )r%   r)   )ri  r)   r%   r   )rX   rY   rZ   r[   r\  rS  r   r=  r   r   rl  rZ  r   r   s   @r   r   r     s         

 
 
      # # # # + + + X+: : : : : : > > > X> > > > >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   r_   typera   rv   rj   rk   r   r  rh   ri   rl   rm   rn   r   rM   r!   r   <module>rz     s   F E " " " " " " 				
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       , , , , , , , , 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 $ $ $ $ $ $ 5******444444   :) :) :) :) :) :) :) :)z WT]]7 7 7 7 7d 7 7 7$. . . . . . . .b< < < < < < < <~- - - - - - - -``+ `+ `+ `+ `+ `+ `+ `+F84 84 84 84 84 84 84 84v! ! ! ! !% ! ! !@( ( ( ( (! ( ( ("( ( ( ( (" ( ( ( ,1 ,1 ,1 ,1 ,1! ,1 ,1 ,1^>. >. >. >. >.' >. >. >.D9> 9> 9> 9> 9>	9> 9> 9> 9> 9> 9>r!   