
    hi!i                    :   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 ddlmZ ddlmZmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZ  G d de          Zd1d2dZd3d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"          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!0          Z,dS )4zPBase and meta classes enabling declarative definition of custom element classes.    )annotationsN)AnyCallableIterableProtocolSequenceTypecast)etree)ElementBase_Element)InvalidXmlError)oxml_parser)NamespacePrefixedTag_nsmapqn)lazypropertyc                  B    e Zd ZdZed
d            Zedd            Zd	S )AttributeTypezInterface for an object that can act as an attribute type.

    An attribute-type specifies how values are transformed to and from the XML "string" value of the
    attribute.
    	xml_valuestrreturnr   c                    dS )z/Transform an attribute value to a Python value.N )clsr   s     j/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pptx/oxml/xmlchemy.pyfrom_xmlzAttributeType.from_xml   	     	    valuec                    dS )zGTransform a Python value to a str value suitable to this XML attribute.Nr   )r   r    s     r   to_xmlzAttributeType.to_xml   r   r   N)r   r   r   r   )r    r   r   r   )__name__
__module____qualname____doc__classmethodr   r"   r   r   r   r   r      s^             [    [  r   r   
nsptag_strr   nsmapdict[str, str] | Noner   BaseOxmlElementc                l    t          |           }||n|j        }t          j        |j        |          S )a  Return a "loose" lxml element having the tag specified by `nsptag_str`.

    `nsptag_str` must contain the standard namespace prefix, e.g. 'a:tbl'. The resulting element is
    an instance of the custom element class for this tag name if one is defined.
    N)r)   )r   r)   r   makeelement
clark_name)r(   r)   nsptags      r   OxmlElementr0   #   s:     "*--F&EEFLE"6#4EBBBBr   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)r1   xmls     r   serialize_for_readingr9   .   s&    
 .94
H
H
HCS>>r   c                  Z    e Zd ZdZ ej        d          ZddZddZddZ	ddZ
ddZdS )r7   zRProvides string comparison override suitable for serialized XML; useful for tests.z(( *</?[\w:]+)(.*?)(/?>)([^<]*</[\w:]+>)?otherobjectr   boolc                &   t          |t                    sdS |                                 }|                                }t          |          t          |          k    rdS t	          ||          D ]\  }}|                     ||          s dS dS )NFT)
isinstancer   
splitlineslenzip_eq_elm_strs)selfr;   lineslines_otherline
line_others         r   __eq__zXmlString.__eq__B   s    %%% 	5!!&&((u::[))))5 #E; 7 7 	 	D*$$T:66 uutr   c                .    |                      |           S N)rI   )rD   r;   s     r   __ne__zXmlString.__ne__N   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)rD   rM   attr_lsts      r   	_attr_seqzXmlString._attr_seqQ   s,    
 ;;==hr   rG   line_2c                    |                      |          \  }}}}|                      |          \  }}}	}
||k    rdS |                     |          |                     |          k    rdS ||	k    rdS ||
k    rdS dS )zTrue if the element in `line_2` is XML-equivalent to the element in `line`.

        In particular, the order of attributes in XML is not significant.
        FT)_parse_linerT   )rD   rG   rU   frontrM   closetextfront_2attrs_2close_2text_2s              r   rC   zXmlString._eq_elm_strsZ   s    
 %)$4$4T$:$:!ueT,0,<,<V,D,D)'6G5>>%  DNN7$;$;;;5G56>>5tr   c                    | j                             |          t          d          fdt          dd          D             \  }}}}||||fS )zUReturn front, attrs, close, text 4-tuple result of parsing XML element string `line`.Nz0`line` does not match pattern for an XML elementc                :    g | ]}                     |          S r   )group).0nmatchs     r   
<listcomp>z)XmlString._parse_line.<locals>.<listcomp>p   s#    $I$I$IU[[^^$I$I$Ir         )_xml_elm_line_pattrd   
ValueErrorrange)rD   rG   rX   rM   rY   rZ   rd   s         @r   rW   zXmlString._parse_linek   sf    '--d33=OPPP$I$I$I$IU1a[[$I$I$I!ueTeUD((r   N)r;   r<   r   r=   )rM   r   r   rN   )rG   r   rU   r   r   r=   )rG   r   )r#   r$   r%   r&   recompilerh   rI   rL   rT   rC   rW   r   r   r   r7   r7   7   s        \\ $$OPP
 
 
 
& & & &          ") ) ) ) ) )r   r7   c                      e Zd ZdZd
dZd	S )MetaOxmlElementzMetaclass for BaseOxmlElement.clsnamer   basestuple[type, ...]clsdictdict[str, Any]c                    t           t          t          t          t          t
          t          f}|                                D ]+\  }}t          ||          r|	                    | |           ,d S rK   )
OneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOneZeroOrOneChoiceitemsr?   populate_class_members)r   ro   rp   rr   dispatchablekeyr    s          r   __init__zMetaOxmlElement.__init__w   sn    
 "--// 	7 	7JC%.. 7,,S#666	7 	7r   N)ro   r   rp   rq   rr   rs   )r#   r$   r%   r&   r   r   r   r   rn   rn   t   s.        ((7 7 7 7 7 7r   rn   c                  n    e Zd ZdZddZdd
Zd Zed             Zedd            Z	edd            Z
dS )BaseAttributezQBase class for OptionalAttribute and RequiredAttribute, providing common methods.	attr_namer   simple_typetype[AttributeType]c                "    || _         || _        d S rK   )
_attr_name_simple_type)rD   r   r   s      r   r   zBaseAttribute.__init__   s    #'r   element_clsType[BaseOxmlElement]	prop_namec                J    || _         || _        |                                  dS z?
        Add the appropriate methods to *element_cls*.
        N)_element_cls
_prop_name_add_attr_propertyrD   r   r   s      r   r}   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   rD   	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   rD   s    r   _clark_namezBaseAttribute._clark_name   s'    $/!!do&&&r   r    Callable[[BaseOxmlElement], Any]c                     t          d          )JCallable suitable for the "get" side of the attribute property descriptor.$must be implemented by each subclassNotImplementedErrorr   s    r   r   zBaseAttribute._getter        ""HIIIr   &Callable[[BaseOxmlElement, Any], None]c                     t          d          )JCallable suitable for the "set" side of the attribute property descriptor.r   r   r   s    r   r   zBaseAttribute._setter   r   r   N)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   r      s        [[( ( ( (" " " "? ? ?   X
 J J J XJ J J J XJ J Jr   r   c                  l     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 )rw   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.
    Nr   r   r   r   defaultr   c                h    t          t          |                               ||           || _        d S rK   )superrw   r   _default)rD   r   r   r   	__class__s       r   r   zOptionalAttribute.__init__   s/    &&//	;GGGr   c                0    | j         j        d| j        dS )s
        Return the string to use as the ``__doc__`` attribute of the property
        for this attribute.
         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   r#   r   r   s    r   
_docstringzOptionalAttribute._docstring   s%      )))4???<	
r   r   r   c                ,     d fd} j         |_        |S )r   objr+   r   r   c                ~    |                      j                  }|j        S j                            |          S rK   )getr   r   r   r   r   attr_str_valuerD   s     r   get_attr_valuez1OptionalAttribute._getter.<locals>.get_attr_value   s<     WWT%566N%}$$--n===r   r   r+   r   r   r   r&   rD   r   s   ` r   r   zOptionalAttribute._getter   s3    	> 	> 	> 	> 	> 	> "&r   r   c                     d fd}|S )	r   r   r+   r    r   r   Nonec                    |j         k    rj        | j        v r| j        j        = d S j                            |          }|                     j        |           d S rK   )r   r   attribr   r"   setr   r    	str_valuerD   s      r   set_attr_valuez1OptionalAttribute._setter.<locals>.set_attr_value   sg     %%#sz11
4#34)0077IGGD$i00000r   r   r+   r    r   r   r   r   rD   r   s   ` r   r   zOptionalAttribute._setter   s)    	1 	1 	1 	1 	1 	1 r   rK   )r   r   r   r   r   r   r   r   )
r#   r$   r%   r&   r   r   r   r   r   __classcell__r   s   @r   rw   rw      s                       

 

 X

 
 
 
 X
    X    r   rw   c                  X    e Zd ZdZed	d            Zed             Zed
d            ZdS )rx   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.
    r   r   c                ,     d fd} j         |_        |S )r   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%%oKO???\_\c\cd   $--n===r   r   r   r   s   ` r   r   zRequiredAttribute._getter   s3    	> 	> 	> 	> 	> 	> "&r   c                0    | j         j        d| j        dS )r   r   z`` attribute.r   r   s    r   r   zRequiredAttribute._docstring   s&     &&&OOO
 	
r   r   c                     d fd}|S )	r   r   r+   r    r   r   r   c                r    j                             |          }|                     j        |           d S rK   )r   r"   r   r   r   s      r   r   z1RequiredAttribute._setter.<locals>.set_attr_value  s6    )0077IGGD$i00000r   r   r   r   s   ` r   r   zRequiredAttribute._setter
  s)    	1 	1 	1 	1 	1 	1 r   Nr   r   )r#   r$   r%   r&   r   r   r   r   r   r   r   rx   rx      sy             X 
 
 X
    X  r   rx   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#dZed$d            Zed%d            Zed             Zed&d            Zed             Zed             Z xZS )'_BaseChildElementzBase class for the child element classes corresponding to varying cardinalities.

    Subclasses include ZeroOrOne and ZeroOrMore.
    r   
nsptagnamer   
successorsSequence[str]c                r    t          t          |                                            || _        || _        d S rK   )r   r   r   _nsptagname_successors)rD   r   r   r   s      r   r   z_BaseChildElement.__init__  s6    &&//111%%r   r   r   r   c                "    || _         || _        dS )zFBaseline behavior for adding the appropriate methods to `element_cls`.N)r   r   r   s      r   r}   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+   rM   r   c                    t          | j                  } |            }|                                D ]\  }}t          |||           t          | j                  } ||           |S rK   )getattr_new_method_namer|   r   _insert_method_name)r   rM   
new_methodchildr   r    insert_methodrD   s          r   
_add_childz0_BaseChildElement._add_adder.<locals>._add_child(  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+   rM   r   )r   r&   _add_to_class_add_method_name)rD   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.

        This method 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   )rD   creators     r   _add_creatorz_BaseChildElement._add_creator7  sC    
 -(*.*:; 	 	40':::::r   c                h    t          | j        dd          }t          | j        | j        |           dS )zAdd a read-only `{prop_name}` property to the parent element class.

        The property locates and returns this child element or `None` if not present.
        N)r   r   r   r   r   r   s     r   _add_getterz_BaseChildElement._add_getterC  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 rK   )insert_element_beforer   r   r   rD   s     r   _insert_childz6_BaseChildElement._add_inserter.<locals>._insert_childO  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   )rD   r   s   ` r   _add_inserterz_BaseChildElement._add_inserterL  sZ    	 	 	 	 	 	
)+/+;< 	 	43]CCCCCr   c                r    | j          d}t          | j        dd          }t          | j        ||           dS )z
        Add a read-only ``{prop_name}_lst`` property to the element class to
        retrieve a list of child elements matching this type.
        _lstN)r   r   _list_getterr   r   )rD   r   r   s      r   _add_list_getterz"_BaseChildElement._add_list_getterY  sC    
 ,,,	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_nameb      4?**r   namemethodCallable[..., Any]c                `    t          | j        |          rdS t          | j        ||           dS )zSAdd `method` to the target class as `name`, unless `name` is already defined there.N)hasattrr   r   )rD   r   r   s      r   r   z_BaseChildElement._add_to_classf  s7    4$d++ 	F!400000r   r   ,Callable[[BaseOxmlElement], BaseOxmlElement]c                     d fd}|S )zSCallable that creates a new, empty element of the child type, having no attributes.r   r+   c                ,    t          j                  S rK   )r0   r   r   rD   s    r   new_child_elementz5_BaseChildElement._creator.<locals>.new_child_elementp  s    t/000r   r   r+   r   )rD   r  s   ` r   r   z_BaseChildElement._creatorl  s)    	1 	1 	1 	1 	1 	1 ! r   3Callable[[BaseOxmlElement], BaseOxmlElement | None]c                2     d fd}d j         z  |_        |S )zCallable 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+   r   BaseOxmlElement | Nonec                R    |                      t          j                            S rK   )findr   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   r&   rD   r  s   ` r   r   z_BaseChildElement._getteru  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   2Callable[[BaseOxmlElement], list[BaseOxmlElement]]c                2     d fd}d j         z  |_        |S )zCCallable suitable for the "get" side of a list property descriptor.r   r+   r   list[BaseOxmlElement]c                n    t          d|                     t          j                                      S )Nr  )r
   findallr   r   r  s    r   get_child_element_listz>_BaseChildElement._list_getter.<locals>.get_child_element_list  s+    /R@P=Q=Q1R1RSSSr   zPA list containing each of the ``<%s>`` child elements, in the order they appear.)r   r+   r   r  r  )rD   r  s   ` r   r   z_BaseChildElement._list_getter  sG    	T 	T 	T 	T 	T 	T "&"23 	& &%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   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   r   r   r   r   r   r   r   r   r  r   r   r   s   @r   r   r     s        
& & & & & & &
$ $ $ $
> > >$
; 
; 
;? ? ?D D D9 9 9 + + \+1 1 1 1 ! ! ! X! ! ! ! X! . . \. 
& 
& 
& X
& . . \. + + \+ + + + +r   r   c                  z    e Zd ZdZed             Zdd	ZddZed             Ze	d             Z
e	d             ZdS )ChoicezVDefines a child element belonging to a group, only one of which may appear as a child.c                    | j         S rK   )r   r   s    r   r   zChoice.nsptagname  s    r   r   r   group_prop_namer   r   r   c                    || _         || _        || _        |                                  |                                  |                                  |                                  |                                  dS z-Add the appropriate methods to `element_cls`.N)r   _group_prop_namer   r   r   r   r   _add_get_or_change_to_method)rD   r   r   r   s       r   r}   zChoice.populate_class_members  sz     ( /%))+++++r   r   r   c                h     d fd}d j         z  |_                              j        |           dS )zPAdd 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 rK   )r   r   _remove_group_method_namer   )r   r   remove_group_method
add_methodrD   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)rD   r*  s   ` r   r$  z#Choice._add_get_or_change_to_method  sZ    	 	 	 	 	 	 X*& 	4=?UVVVVVr   c                r    d| j         v r| j                             d          dz   }nd}| j         |d         S )zW
        Calculate property name from tag name, e.g. a:schemeClr -> schemeClr.
        r   rf   r   N)r   index)rD   starts     r   r   zChoice._prop_name  sF    
 $"""$**3//!3EEE''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   r   r   r   r   r   r   r   )r#   r$   r%   r&   r   r   r}   r$  r   r   r+  r'  r   r   r   r  r    s        ``    X , , , ,W W W W$ ( ( X( 7 7 \7 4 4 \4 4 4r   r  c                  H     e Zd ZdZd fdZd fdZedd            Z xZS )ru   z5Defines a required child element for MetaOxmlElement.r   r   c                Z    t          t          |                               |d           d S )Nr   )r   ru   r   )rD   r   r   s     r   r   zOneAndOnlyOne.__init__  s)    mT""++J;;;;;r   r   r   r   c                    t          t          |                               ||           |                                  dS r   )r   ru   r}   r   rD   r   r   r   s      r   r}   z$OneAndOnlyOne.populate_class_members  s=     	mT""99+yQQQr   r   r   c                2     d fd}d j         z  |_        |S )z@Callable suitable for the "get" side of the property descriptor.r   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   r+   r  r  s   ` r   r   zOneAndOnlyOne._getter  s;    	 	 	 	 	 	 %GIY$Y!  r   )r   r   r   r  )	r#   r$   r%   r&   r   r}   r   r   r   r   s   @r   ru   ru     s        ??< < < < < <      ! ! ! X! ! ! ! !r   ru   c                  B     e Zd ZdZd fdZdd	Zed
             Z xZS )rv   zUDefines a repeating child element for MetaOxmlElement that must appear at least once.r   r   r   r   c                B   t          t          |                               ||           |                                  |                                  |                                  |                                  |                                  t          ||           dS )z-Add the appropriate methods to *element_cls*.N)	r   rv   r}   r   r   r   r   _add_public_adderdelattrr5  s      r   r}   z OneOrMore.populate_class_members  s    i55k9MMM   Y'''''r   r   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+   r   c                F    t          | j                  } |            }|S rK   )r   r   )r   private_add_methodr   rD   s      r   	add_childz.OneOrMore._add_public_adder.<locals>.add_child  s)    !(d.C!D!D&&((ELr   r   Nr8  )r   r&   r   _public_add_method_name)rD   r@  s   ` r   r;  zOneOrMore._add_public_adder  sZ    	 	 	 	 	 	#%)%56 	 	47CCCCCr   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   rA  z!OneOrMore._public_add_method_name  s     $/))r   r   r1  )	r#   r$   r%   r&   r}   r;  r   rA  r   r   s   @r   rv   rv     sv        __( ( ( ( ( (D D D D * * \* * * * *r   rv   c                  $     e Zd ZdZd fdZ xZS )ry   zJ
    Defines an optional repeating child element for MetaOxmlElement.
    r   r   r   r   c                   t          t          |                               ||           |                                  |                                  |                                  |                                  t          ||           dS r   )r   ry   r}   r   r   r   r   r<  r5  s      r   r}   z!ZeroOrMore.populate_class_members"  s     	j$66{INNNY'''''r   r   )r#   r$   r%   r&   r}   r   r   s   @r   ry   ry     sG         	( 	( 	( 	( 	( 	( 	( 	( 	( 	(r   ry   c                  F     e Zd ZdZd
 fdZd Zd Zed	             Z xZ	S )rz   z6Defines an optional child element for MetaOxmlElement.r   r   r   r   c                J   t          t          |                               ||           |                                  |                                  |                                  |                                  |                                  |                                  dS r"  )	r   rz   r}   r   r   r   r   _add_get_or_adder_add_removerr5  s      r   r}   z ZeroOrOne.populate_class_members1  s    i55k9MMM   r   c                h     d fd}d j         z  |_                              j        |           dS )zKAdd a `.get_or_add_x()` method to the element class for this child element.r   r+   r   c                t    t          | j                  }|t          | j                  } |            }|S rK   )r   r   r   )r   r   r)  rD   s      r   get_or_add_childz5ZeroOrOne._add_get_or_adder.<locals>.get_or_add_child>  s;    C11E}$S$*?@@
"
Lr   z>Return the ``<%s>`` child element, newly added if not present.Nr8  )r   r&   r   _get_or_add_method_name)rD   rK  s   ` r   rG  zZeroOrOne._add_get_or_adder;  sZ    	 	 	 	 	 	 M$  	479IJJJJJr   c                j     d	 fd}d j          d|_                              j        |           dS )
zHAdd a `._remove_x()` method to the element class for this child element.r   r+   r   r   c                <    |                      j                   d S rK   )
remove_allr   r  s    r   _remove_childz-ZeroOrOne._add_remover.<locals>._remove_childM  s    NN4+,,,,,r   zRemove all `z` child elements.Nr   r+   r   r   )r   r&   r   r  )rD   rP  s   ` r   rH  zZeroOrOne._add_removerJ  sY    	- 	- 	- 	- 	- 	- !St/? R R R43]CCCCCr   c                    d| j         z  S )Nzget_or_add_%sr   r   s    r   rL  z!ZeroOrOne._get_or_add_method_nameS  s    00r   r   )
r#   r$   r%   r&   r}   rG  rH  r   rL  r   r   s   @r   rz   rz   .  s        @@     K K KD D D 1 1 \1 1 1 1 1r   rz   c                  ~     e Zd ZdZdddZd fdZd Zd Zed             Z	e
dd            Ze
d             Z xZS )r{   zOAn `EG_*` element group where at most one of its members may appear as a child.r   choicesIterable[Choice]r   Iterable[str]c                V    t          |          | _        t          |          | _        d S rK   )tuple_choicesr   )rD   rT  r   s      r   r   zZeroOrOneChoice.__init__[  s%    g ,,r   r   r   r   r   c                    t          t          |                               ||           |                                  | j        D ]#}|                    || j        | j                   $|                                  dS r"  )r   r{   r}   _add_choice_getterrY  r   r   _add_group_remover)rD   r   r   choicer   s       r   r}   z&ZeroOrOneChoice.populate_class_members_  s    ot$$;;KSSS!!!m 	Z 	ZF))+tHXYYYY!!!!!r   c                h    t          | j        dd          }t          | j        | j        |           dS )zAdd a read-only `.{prop_name}` property to the element class.

        The property returns the present member of this group, or |None| if none are present.
        N)r   _choice_getterr   r   r   r   s     r   r[  z"ZeroOrOneChoice._add_choice_getterg  s5    
 T0$==	!4?I>>>>>r   c                X     d fd}d|_                               j        |           dS )	zJAdd a `._remove_eg_x()` method to the element class for this choice group.r   r+   r   r   c                F    j         D ]}|                     |           d S rK   )_member_nsptagnamesrO  )r   tagnamerD   s     r   _remove_choice_groupz@ZeroOrOneChoice._add_group_remover.<locals>._remove_choice_groups  s4    3 ( (w''''( (r   z9Remove the current choice group child element if present.NrQ  )r&   r    _remove_choice_group_method_name)rD   rd  s   ` r   r\  z"ZeroOrOneChoice._add_group_removerp  sM    	( 	( 	( 	( 	( 	( (c$4@BVWWWWWr   c                "     d fd}d|_         |S )zj
        Return a function object suitable for the "get" side of the property
        descriptor.
        r   r+   r   r  c                >    t          d | j        j                   S )Nr  )r
   first_child_found_inrb  r  s    r   get_group_member_elementz@ZeroOrOneChoice._choice_getter.<locals>.get_group_member_element  s(    (*B#*BDD\*]  r   zbReturn the child element belonging to this element group, or |None| if no member child is present.r  )r&   )rD   ri  s   ` r   r_  zZeroOrOneChoice._choice_getterz  s6    	 	 	 	 	 	4 	!( ('r   r   rN   c                $    d | j         D             S )zUSequence of namespace-prefixed tagnames, one for each member element of choice group.c                    g | ]	}|j         
S r   )r   )rb   r]  s     r   re   z7ZeroOrOneChoice._member_nsptagnames.<locals>.<listcomp>  s    >>>f!>>>r   )rY  r   s    r   rb  z#ZeroOrOneChoice._member_nsptagnames  s     ?>>>>>r   c                    d| j          S )z!Function-name for choice remover._remove_r   r   s    r   re  z0ZeroOrOneChoice._remove_choice_group_method_name  s     ,$/+++r   r  )rT  rU  r   rV  r   )r   rN   )r#   r$   r%   r&   r   r}   r[  r\  r   r_  r   rb  re  r   r   s   @r   r{   r{   X  s        YY- - - - -" " " " " "? ? ?X X X ( ( X(" ? ? ? \? , , \, , , , ,r   r{   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   r#   _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   )rD   rs  rc  r   s       r   rh  z$BaseOxmlElement.first_child_found_in  sA     	 	GIIbkk**E  !tr   elmr   c                t     | j         | }||                    |           n|                     |           |S rK   )rh  addpreviousappend)rD   rv  rs  	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)rD   rs  rc  matchingr   s        r   rO  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.
        )r9   r   s    r   r8   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   )rD   r  r   s     r   r  zBaseOxmlElement.xpath  s    
 ww}}Y6}:::r   c                4    t          j        | j                  S rK   )r   from_clark_namer   r   s    r   rp  zBaseOxmlElement._nsptag  s    #3DH===r   )rs  r   r   rt  )rv  r   rs  r   )rs  r   r   r   )r   r   )r  r   r   r   )r#   r$   r%   r&   rr  rh  r   rO  r   r8   r  rp  r   r   s   @r   r+   r+     s         

 
 
      # # # # + + + X+; ; ; ; ; ; > > > X> > > > >r   )	metaclassrK   )r(   r   r)   r*   r   r+   )r1   r   )-r&   
__future__r   rk   typingr   r   r   r   r   r	   r
   lxmlr   
lxml.etreer   r   pptx.excr   	pptx.oxmlr   pptx.oxml.nsr   r   r   	pptx.utilr   r   r0   r9   r   r7   typern   r   rw   rx   r   r  ru   rv   ry   rz   r{   r+   r   r   r   <module>r     s   V V " " " " " " 				 J J J J J J J J J J J J J J J J J J       , , , , , , , , $ $ $ $ $ $ ! ! ! ! ! ! 9 9 9 9 9 9 9 9 9 9 " " " " " "    H   $C C C C C   :) :) :) :) :) :) :) :)z7 7 7 7 7d 7 7 7$(J (J (J (J (J (J (J (JV3 3 3 3 3 3 3 3l+ + + + + + + +\G+ G+ G+ G+ G+ G+ G+ G+T84 84 84 84 84 84 84 84v! ! ! ! !% ! ! !:#* #* #* #* #*! #* #* #*L( ( ( ( (" ( ( ("'1 '1 '1 '1 '1! '1 '1 '1T<, <, <, <, <,' <, <, <,@5> 5> 5> 5> 5>e'? 5> 5> 5> 5> 5> 5>r   