o
    7 h!i                     @  s  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 deZd3d4ddZd5ddZG dd deZG dd de Z!G dd dZ"G dd  d e"Z#G d!d" d"e"Z$G d#d$ d$Z%G d%d& d&e%Z&G d'd( d(e%Z'G d)d* d*e%Z(G d+d, d,e%Z)G d-d. d.e%Z*G d/d0 d0e%Z+G d1d deje!d2Z,dS )6zPBase 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                   @  s,   e Zd ZdZedddZed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                 C     dS )z/Transform an attribute value to a Python value.N )clsr   r   r   Z/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/oxml/xmlchemy.pyfrom_xml      zAttributeType.from_xmlvaluec                 C  r   )zGTransform a Python value to a str value suitable to this XML attribute.Nr   )r   r   r   r   r   to_xml   r   zAttributeType.to_xmlN)r   r   r   r   )r   r   r   r   )__name__
__module____qualname____doc__classmethodr   r   r   r   r   r   r      s    r   
nsptag_strr   nsmapdict[str, str] | Noner   BaseOxmlElementc                 C  s*   t | }|dur
|n|j}tj|j|d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%   nsptagr   r   r   OxmlElement#   s   r+   elementr   c                 C  s   t j| d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,   xmlr   r   r   serialize_for_reading.   s   r3   c                   @  sL   e Zd ZdZedZdddZdd	d
ZdddZ	dddZ
dddZdS )r1   zRProvides string comparison override suitable for serialized XML; useful for tests.z(( *</?[\w:]+)(.*?)(/?>)([^<]*</[\w:]+>)?otherobjectr   boolc                 C  s\   t |tsdS |  }| }t|t|krdS t||D ]\}}| ||s+ dS qdS )NFT)
isinstancer   
splitlineslenzip_eq_elm_strs)selfr4   linesZlines_otherlineZ
line_otherr   r   r   __eq__B   s   
zXmlString.__eq__c                 C  s   |  | S N)r?   )r<   r4   r   r   r   __ne__N   s   zXmlString.__ne__attrsr   	list[str]c                 C  s   |  }| }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<   rB   Zattr_lstr   r   r   	_attr_seqQ   s   zXmlString._attr_seqr>   line_2c                 C  sd   |  |\}}}}|  |\}}}	}
||krdS | || |kr$dS ||	kr*dS ||
kr0d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_linerG   )r<   r>   rH   frontrB   closetextZfront_2Zattrs_2Zclose_2Ztext_2r   r   r   r;   Z   s   zXmlString._eq_elm_strsc                   sH   | j |  du rtd fd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                   s   g | ]}  |qS r   )group).0nmatchr   r   
<listcomp>p   s    z)XmlString._parse_line.<locals>.<listcomp>      )_xml_elm_line_pattrQ   
ValueErrorrange)r<   r>   rJ   rB   rK   rL   r   rP   r   rI   k   s
    zXmlString._parse_lineN)r4   r5   r   r6   )rB   r   r   rC   )r>   r   rH   r   r   r6   )r>   r   )r   r    r!   r"   recompilerU   r?   rA   rG   r;   rI   r   r   r   r   r1   7   s    




	r1   c                   @  s   e Zd ZdZddd	Zd
S )MetaOxmlElementzMetaclass for BaseOxmlElement.clsnamer   basestuple[type, ...]clsdictdict[str, Any]c                 C  s>   t ttttttf}| D ]\}}t||r|	| | qd S r@   )
OneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOneZeroOrOneChoiceitemsr7   populate_class_members)r   r[   r\   r^   Zdispatchablekeyr   r   r   r   __init__w   s   	
zMetaOxmlElement.__init__N)r[   r   r\   r]   r^   r_   )r   r    r!   r"   rj   r   r   r   r   rZ   t   s    rZ   c                   @  sT   e Zd ZdZdddZdddZdd Zedd ZedddZ	edddZ
dS )BaseAttributezQBase class for OptionalAttribute and RequiredAttribute, providing common methods.	attr_namer   simple_typetype[AttributeType]c                 C  s   || _ || _d S r@   )
_attr_name_simple_type)r<   rl   rm   r   r   r   rj      s   
zBaseAttribute.__init__element_clsType[BaseOxmlElement]	prop_namec                 C  s   || _ || _|   dS z?
        Add the appropriate methods to *element_cls*.
        N)_element_cls
_prop_name_add_attr_propertyr<   rq   rs   r   r   r   rh      s   z$BaseAttribute.populate_class_membersc                 C  s$   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setattrru   rv   r<   	property_r   r   r   rw      s   z BaseAttribute._add_attr_propertyc                 C  s   d| j v r
t| j S | j S )N:)ro   r   r<   r   r   r   _clark_name   s   

zBaseAttribute._clark_namer    Callable[[BaseOxmlElement], Any]c                 C     t d)JCallable suitable for the "get" side of the attribute property descriptor.$must be implemented by each subclassNotImplementedErrorr   r   r   r   rz         zBaseAttribute._getter&Callable[[BaseOxmlElement, Any], None]c                 C  r   )JCallable suitable for the "set" side of the attribute property descriptor.r   r   r   r   r   r   r{      r   zBaseAttribute._setterN)rl   r   rm   rn   rq   rr   rs   r   r   r   r   r   )r   r    r!   r"   rj   rh   rw   ry   r   rz   r{   r   r   r   r   rk      s    

	

rk   c                      sL   e Zd ZdZdd fd	d
Zedd ZedddZedddZ  Z	S )rb   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.
    Nrl   r   rm   rn   defaultr   c                   s   t t| || || _d S r@   )superrb   rj   _default)r<   rl   rm   r   	__class__r   r   rj      s   
zOptionalAttribute.__init__c                 C     d| j j| jf S )s
        Return the string to use as the ``__doc__`` attribute of the property
        for this attribute.
        z%s type-converted value of ``%s`` attribute, or |None| (or specified default value) if not present. Assigning the default value causes the attribute to be removed from the element.rp   r   ro   r   r   r   r   
_docstring   s   zOptionalAttribute._docstringr   r   c                      d fdd} j |_|S )	r   objr'   r   r   c                   s&   |   j}|d u r jS  j|S r@   )getr   r   rp   r   r   Zattr_str_valuer   r   r   get_attr_value   s   z1OptionalAttribute._getter.<locals>.get_attr_valueNr   r'   r   r   r   r"   r<   r   r   r   r   rz      s   zOptionalAttribute._getterr   c                      d
 fdd}|S )r   r   r'   r   r   r   Nonec                   sB   | j kr j| jv r| j j= d S  j|}|  j| d S r@   )r   r   attribrp   r   setr   r   	str_valuer   r   r   set_attr_value   s   

z1OptionalAttribute._setter.<locals>.set_attr_valueNr   r'   r   r   r   r   r   r<   r   r   r   r   r{      s   
zOptionalAttribute._setterr@   )rl   r   rm   rn   r   r   r   r   )
r   r    r!   r"   rj   ry   r   rz   r{   __classcell__r   r   r   r   rb      s    
rb   c                   @  s8   e Zd ZdZedddZedd Zedd	d
ZdS )rc   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                   r   )	r   r   r'   r   r   c                   s4   |   j}|d u rtd j| jf  j|S )Nz1required '%s' attribute not present on element %s)r   r   r   ro   tagrp   r   r   r   r   r   r      s   z1RequiredAttribute._getter.<locals>.get_attr_valueNr   r   r   r   r   r   rz      s   zRequiredAttribute._getterc                 C  r   )r   z,%s type-converted value of ``%s`` attribute.r   r   r   r   r   r      s   zRequiredAttribute._docstringr   c                   r   )r   r   r'   r   r   r   r   c                   s    j |}|  j| d S r@   )rp   r   r   r   r   r   r   r   r     s   z1RequiredAttribute._setter.<locals>.set_attr_valueNr   r   r   r   r   r   r{   
  s   zRequiredAttribute._setterNr   r   )r   r    r!   r"   ry   rz   r   r{   r   r   r   r   rc      s    

rc   c                      s   e Zd ZdZd/d0 fddZd1ddZdd Zdd Zdd Zdd Z	dd Z
edd Zd2ddZed3d!d"Zed4d$d%Zed&d' Zed5d)d*Zed+d, Zed-d. Z  ZS )6_BaseChildElementzBase class for the child element classes corresponding to varying cardinalities.

    Subclasses include ZeroOrOne and ZeroOrMore.
    r   
nsptagnamer   
successorsSequence[str]c                   s   t t|   || _|| _d S r@   )r   r   rj   _nsptagname_successors)r<   r   r   r   r   r   rj     s   
z_BaseChildElement.__init__rq   rr   rs   c                 C  s   || _ || _dS )zFBaseline behavior for adding the appropriate methods to `element_cls`.N)ru   rv   rx   r   r   r   rh      s   
z(_BaseChildElement.populate_class_membersc                   s,   d	 fdd}d j  |_  j| dS )
zGAdd an ``_add_x()`` method to the element class for this child element.r   r'   rB   r   c                   sH   t |  j}| }| D ]
\}}t||| qt |  j}|| |S r@   )getattr_new_method_namerg   r|   _insert_method_name)r   rB   Z
new_methodchildri   r   Zinsert_methodr   r   r   
_add_child(  s   z0_BaseChildElement._add_adder.<locals>._add_childSAdd a new ``<%s>`` child element unconditionally, inserted in the correct sequence.N)r   r'   rB   r   )r   r"   _add_to_class_add_method_name)r<   r   r   r   r   
_add_adder%  s   
z_BaseChildElement._add_adderc                 C  s$   | j }d| j |_| | 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   )r<   creatorr   r   r   _add_creator7  s   z_BaseChildElement._add_creatorc                 C  "   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)ry   rz   r|   ru   rv   r}   r   r   r   _add_getterC     z_BaseChildElement._add_getterc                   ,   d fdd}d j  |_  j| dS )	zJAdd an ``_insert_x()`` method to the element class for this child element.r   r'   r   c                   s   | j |g jR   |S r@   )insert_element_beforer   r   r   r   r   r   _insert_childO  s   z6_BaseChildElement._add_inserter.<locals>._insert_childzYReturn 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   r   r   r   _add_inserterL  s   z_BaseChildElement._add_inserterc                 C  s,   | 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.
        Z_lstN)rv   ry   _list_getterr|   ru   )r<   rs   r~   r   r   r   _add_list_getterY  s   z"_BaseChildElement._add_list_getterc                 C  
   d| j  S )Nz_add_%srv   r   r   r   r   r   b     
z"_BaseChildElement._add_method_namenamemethodCallable[..., Any]c                 C  s"   t | j|rdS t| j|| dS )zSAdd `method` to the target class as `name`, unless `name` is already defined there.N)hasattrru   r|   )r<   r   r   r   r   r   r   f  s   z_BaseChildElement._add_to_classr   ,Callable[[BaseOxmlElement], BaseOxmlElement]c                   s   d fdd}|S )zSCallable that creates a new, empty element of the child type, having no attributes.r   r'   c                   s
   t  jS r@   )r+   r   r   r   r   r   new_child_elementp  s   
z5_BaseChildElement._creator.<locals>.new_child_elementNr   r'   r   )r<   r   r   r   r   r   l  s   z_BaseChildElement._creator3Callable[[BaseOxmlElement], BaseOxmlElement | None]c                      d	 fdd}d j  |_|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                   s   |  t jS r@   )findr   r   r   r   r   r   get_child_element}     z4_BaseChildElement._getter.<locals>.get_child_elementz0``<%s>`` child element or |None| if not present.Nr   r'   r   r   r   r"   r<   r   r   r   r   rz   u  s   z_BaseChildElement._getterc                 C  r   )Nz
_insert_%sr   r   r   r   r   r     r   z%_BaseChildElement._insert_method_name2Callable[[BaseOxmlElement], list[BaseOxmlElement]]c                   r   )
zCCallable suitable for the "get" side of a list property descriptor.r   r'   r   list[BaseOxmlElement]c                   s   t d| t jS )Nr   )r	   findallr   r   r   r   r   r   get_child_element_list     z>_BaseChildElement._list_getter.<locals>.get_child_element_listzPA list containing each of the ``<%s>`` child elements, in the order they appear.N)r   r'   r   r   r   )r<   r   r   r   r   r     s   z_BaseChildElement._list_getterc                 C  r   Nz
_remove_%sr   r   r   r   r   _remove_method_name  r   z%_BaseChildElement._remove_method_namec                 C  r   )Nz_new_%sr   r   r   r   r   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"   rj   rh   r   r   r   r   r   r   r   r   ry   r   rz   r   r   r   r   r   r   r   r   r   r     s0    
		



r   c                   @  sT   e Zd ZdZedd Zdd
dZdddZedd Ze	dd Z
e	dd ZdS )ChoicezVDefines a child element belonging to a group, only one of which may appear as a child.c                 C  s   | j S r@   )r   r   r   r   r   r     s   zChoice.nsptagnamerq   rr   group_prop_namer   r   r   c                 C  s>   || _ || _|| _|   |   |   |   |   dS z-Add the appropriate methods to `element_cls`.N)ru   _group_prop_namer   r   r   r   r   _add_get_or_change_to_method)r<   rq   r   r   r   r   r   rh     s   zChoice.populate_class_membersr   r   c                   s,   d fdd}d j  |_  j| dS )zPAdd a `get_or_change_to_x()` method to the element class for this child element.r   r'   c                   s@   t |  j}|d ur|S t |  j}|  t |  j}| }|S r@   )r   rv   _remove_group_method_namer   )r   r   Zremove_group_method
add_methodr   r   r   get_or_change_to_child  s   zCChoice._add_get_or_change_to_method.<locals>.get_or_change_to_childzFReturn the ``<%s>`` child, replacing any other group element if found.Nr   )r   r"   r   _get_or_change_to_method_name)r<   r   r   r   r   r     s
   z#Choice._add_get_or_change_to_methodc                 C  s.   d| j v r| j dd }nd}| j |d S )zW
        Calculate property name from tag name, e.g. a:schemeClr -> schemeClr.
        r   rS   r   N)r   index)r<   startr   r   r   rv     s   
zChoice._prop_namec                 C  r   )Nzget_or_change_to_%sr   r   r   r   r   r     r   z$Choice._get_or_change_to_method_namec                 C  r   r   )r   r   r   r   r   r     r   z Choice._remove_group_method_nameN)rq   rr   r   r   r   r   r   r   )r   r    r!   r"   ry   r   rh   r   rv   r   r   r   r   r   r   r   r     s    





r   c                      s>   e Zd ZdZd fddZd fd	d
ZedddZ  ZS )r`   z5Defines a required child element for MetaOxmlElement.r   r   c                   s   t t| |d d S )Nr   )r   r`   rj   )r<   r   r   r   r   rj     r   zOneAndOnlyOne.__init__rq   rr   rs   c                   s   t t| || |   dS rt   )r   r`   rh   r   rx   r   r   r   rh     s   z$OneAndOnlyOne.populate_class_membersr   r   c                   s   d fdd}d j  |_|S )	z@Callable suitable for the "get" side of the property descriptor.r   r'   r   c                   s*   |  t j}|d u rtd j |S )Nz+required ``<%s>`` child element not present)r   r   r   r   r   r   r   r   r     s   z0OneAndOnlyOne._getter.<locals>.get_child_elementz Required ``<%s>`` child element.Nr   r'   r   r'   r   r   r   r   r   rz     s   zOneAndOnlyOne._getter)r   r   r   r   )	r   r    r!   r"   rj   rh   ry   rz   r   r   r   r   r   r`     s    r`   c                      s8   e Zd ZdZd fddZdd
dZedd Z  ZS )ra   zUDefines a repeating child element for MetaOxmlElement that must appear at least once.rq   rr   rs   r   c                   sH   t t| || |   |   |   |   |   t|| dS )z-Add the appropriate methods to *element_cls*.N)	r   ra   rh   r   r   r   r   _add_public_adderdelattrrx   r   r   r   rh     s   z OneOrMore.populate_class_membersr   r   c                   r   )	z;Add a public `.add_x()` method to the parent element class.r   r'   r   c                   s   t |  j}| }|S r@   )r   r   )r   Zprivate_add_methodr   r   r   r   	add_child  s   z.OneOrMore._add_public_adder.<locals>.add_childr   Nr   )r   r"   r   _public_add_method_name)r<   r   r   r   r   r     s   zOneOrMore._add_public_adderc                 C  r   )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   r   r   r   r     s   
z!OneOrMore._public_add_method_namer   r   )	r   r    r!   r"   rh   r   r   r   r   r   r   r   r   ra     s    

ra   c                      s"   e Zd ZdZd fddZ  ZS )	rd   zJ
    Defines an optional repeating child element for MetaOxmlElement.
    rq   rr   rs   r   c                   s@   t t| || |   |   |   |   t|| dS rt   )r   rd   rh   r   r   r   r   r   rx   r   r   r   rh   "  s   z!ZeroOrMore.populate_class_membersr   )r   r    r!   r"   rh   r   r   r   r   r   rd     s    rd   c                      s>   e Zd ZdZd fddZdd	 Zd
d Zedd Z  Z	S )re   z6Defines an optional child element for MetaOxmlElement.rq   rr   rs   r   c                   sF   t t| || |   |   |   |   |   |   dS r   )	r   re   rh   r   r   r   r   _add_get_or_adder_add_removerrx   r   r   r   rh   1  s   z ZeroOrOne.populate_class_membersc                   r   )	zKAdd a `.get_or_add_x()` method to the element class for this child element.r   r'   r   c                   s*   t |  j}|d u rt |  j}| }|S r@   )r   rv   r   )r   r   r   r   r   r   get_or_add_child>  s
   z5ZeroOrOne._add_get_or_adder.<locals>.get_or_add_childz>Return the ``<%s>`` child element, newly added if not present.Nr   )r   r"   r   _get_or_add_method_name)r<   r   r   r   r   r   ;  s
   zZeroOrOne._add_get_or_adderc                   s0   d
 fd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                   s   |   j d S r@   )
remove_allr   r   r   r   r   _remove_childM  r   z-ZeroOrOne._add_remover.<locals>._remove_childzRemove all `z` child elements.Nr   r'   r   r   )r   r"   r   r   )r<   r   r   r   r   r   J  s   zZeroOrOne._add_removerc                 C  r   )Nzget_or_add_%sr   r   r   r   r   r   S  r   z!ZeroOrOne._get_or_add_method_namer   )
r   r    r!   r"   rh   r   r   r   r   r   r   r   r   r   re   .  s    
	re   c                      sd   e Zd ZdZddddZd fddZdd Zdd Zedd Z	e
dddZe
dd Z  ZS )rf   zOAn `EG_*` element group where at most one of its members may appear as a child.r   choicesIterable[Choice]r   Iterable[str]c                 C  s   t || _t || _d S r@   )tuple_choicesr   )r<   r   r   r   r   r   rj   [  s   
zZeroOrOneChoice.__init__rq   rr   rs   r   c                   sD   t t| || |   | jD ]}||| j| j q|   dS r   )r   rf   rh   _add_choice_getterr   rv   r   _add_group_remover)r<   rq   rs   choicer   r   r   rh   _  s
   
z&ZeroOrOneChoice.populate_class_membersc                 C  r   )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)ry   _choice_getterr|   ru   rv   r}   r   r   r   r   g  r   z"ZeroOrOneChoice._add_choice_getterc                   s&   d	 fdd}d|_   j| dS )
zJAdd a `._remove_eg_x()` method to the element class for this choice group.r   r'   r   r   c                   s    j D ]}| | qd S r@   )_member_nsptagnamesr   )r   tagnamer   r   r   _remove_choice_groups  s   
z@ZeroOrOneChoice._add_group_remover.<locals>._remove_choice_groupz9Remove the current choice group child element if present.Nr   )r"   r    _remove_choice_group_method_name)r<   r  r   r   r   r  p  s   z"ZeroOrOneChoice._add_group_removerc                   s   d	 fdd}d|_ |S )
zj
        Return a function object suitable for the "get" side of the property
        descriptor.
        r   r'   r   r   c                   s   t d| j j S )Nr   )r	   first_child_found_inr  r   r   r   r   get_group_member_element  s   z@ZeroOrOneChoice._choice_getter.<locals>.get_group_member_elementzbReturn the child element belonging to this element group, or |None| if no member child is present.Nr   )r"   )r<   r	  r   r   r   r  z  s   zZeroOrOneChoice._choice_getterr   rC   c                 C  s   dd | j D S )zUSequence of namespace-prefixed tagnames, one for each member element of choice group.c                 S  s   g | ]}|j qS r   )r   )rN   r  r   r   r   rR     s    z7ZeroOrOneChoice._member_nsptagnames.<locals>.<listcomp>)r   r   r   r   r   r    s   z#ZeroOrOneChoice._member_nsptagnamesc                 C  s   d| j  S )z!Function-name for choice remover.Z_remove_r   r   r   r   r   r    s   z0ZeroOrOneChoice._remove_choice_group_method_namer   )r   r   r   r   r   )r   rC   )r   r    r!   r"   rj   rh   r   r  ry   r  r   r  r  r   r   r   r   r   rf   X  s    	

rf   c                      sd   e Zd ZdZdd Zddd	ZdddZdddZedddZ	d fddZ
edddZ  ZS )r'   zvEffective base class for all custom element classes.

    Adds standardized behavior to all classes in one place.
    c                 C  s   d| j j| jt| f S )Nz<%s '<%s>' at 0x%0x>)r   r   _nsptagidr   r   r   r   __repr__  s
   zBaseOxmlElement.__repr__tagnamesr   r   _Element | Nonec                 G  s,   |D ]}|  t|}|dur|  S qdS )z9First child with tag in `tagnames`, or None if not found.N)r   r   )r<   r  r  r   r   r   r   r    s   z$BaseOxmlElement.first_child_found_inelmr   c                 G  s.   | j | }|d ur|| |S | | |S r@   )r  addpreviousappend)r<   r  r  	successorr   r   r   r     s   


z%BaseOxmlElement.insert_element_beforer   c                 G  s0   |D ]}|  t|}|D ]}| | qqdS )z>Remove child elements with tagname (e.g. "a:p") in `tagnames`.N)r   r   remove)r<   r  r  Zmatchingr   r   r   r   r     s   zBaseOxmlElement.remove_allc                 C  s   t | S )zXML string for this element, suitable for testing purposes.

        Pretty printed for readability and without an XML declaration at the top.
        )r3   r   r   r   r   r2     s   zBaseOxmlElement.xml	xpath_strr   c                   s   t  j|tdS )zOverride of `lxml` _Element.xpath() method.

        Provides standard Open XML namespace mapping (`nsmap`) in centralized location.
        )
namespaces)r   xpathr   )r<   r  r   r   r   r    s   zBaseOxmlElement.xpathc                 C  s   t | jS r@   )r   from_clark_namer   r   r   r   r   r
    s   zBaseOxmlElement._nsptag)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   ry   r2   r  r
  r   r   r   r   r   r'     s    


)	metaclassr@   )r$   r   r%   r&   r   r'   )r,   r   )-r"   
__future__r   rX   typingr   r   r   r   r   r   r	   lxmlr
   
lxml.etreer   r   pptx.excr   	pptx.oxmlr   pptx.oxml.nsr   r   r   	pptx.utilr   r   r+   r3   r   r1   typerZ   rk   rb   rc   r   r   r`   ra   rd   re   rf   r'   r   r   r   r   <module>   s6    $
	=+6. ;&*@