o
    ýÞhrc  ã                   @  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
 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rNdd
lmZ ddlmZ d,dd„ZG dd„ deƒZe
dƒ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'd(„ d(e%ƒZ+G d)d*„ d*eje!d+�Z,dS )-z?Enabling declarative definition of lxml custom element classes.é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚCallableÚSequenceÚTypeÚTypeVar)Úetree)ÚElementBaseÚ_Element)ÚInvalidXmlError)ÚNamespacePrefixedTagÚnsmapÚqn)Úlazyproperty)ÚBaseXmlEnum)ÚBaseSimpleTypeÚ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   Úxml© r   úR/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/oxml/xmlchemy.pyÚserialize_for_reading   s   r   c                   @  sP   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
ed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                 C  s\   t |tƒsdS |  ¡ }| ¡ }t|ƒt|ƒkrdS t||ƒD ]\}}|  ||¡s+ dS qdS )NFT)Ú
isinstanceÚstrÚ
splitlinesÚlenÚzipÚ_eq_elm_strs)Úselfr   ÚlinesÚlines_otherÚlineÚ
line_otherr   r   r   Ú__eq__+   s   
ÿzXmlString.__eq__c                 C  s   |   |¡ S ©N)r,   )r'   r   r   r   r   Ú__ne__7   ó   zXmlString.__ne__Úattrsr"   ú	list[str]c                 C  s   |  ¡ }| ¡ }t|ƒS )z‹Return a sequence of attribute strings parsed from `attrs`.

        Each attribute string is stripped of whitespace on both ends.
        )ÚstripÚsplitÚsorted)r'   r0   Úattr_lstr   r   r   Ú	_attr_seq:   s   zXmlString._attr_seqr*   Úline_2c                 C  s\   |   |¡\}}}}|   |¡\}}}	}
||krdS |  |¡|  |¡kr$dS ||	kr*dS ||
kS )zZReturn True if the element in `line_2` is XML equivalent to the element in
        `line`.F)Ú_parse_liner6   )r'   r*   r7   Úfrontr0   ÚcloseÚtextÚfront_2Úattrs_2Úclose_2Útext_2r   r   r   r&   C   s   zXmlString._eq_elm_strsútuple[str, str, str, str]c                   sD   | j  |¡‰ ˆ du rdS ‡ fdd„tddƒD ƒ\}}}}||||fS )zI(front, attrs, close, text) 4-tuple result of parsing XML element `line`.N)Ú rA   rA   rA   c                   s   g | ]}ˆ   |¡‘qS r   )Úgroup)Ú.0Ún©Úmatchr   r   Ú
<listcomp>V   s    z)XmlString._parse_line.<locals>.<listcomp>é   é   )Ú_xml_elm_line_pattrF   Úrange)Úclsr*   r9   r0   r:   r;   r   rE   r   r8   P   s
    zXmlString._parse_lineN)r   r   r   r    )r0   r"   r   r1   )r*   r"   r7   r"   )r*   r"   r   r@   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚreÚcompilerJ   r,   r.   r6   r&   Úclassmethodr8   r   r   r   r   r      s    
	



	r   Ú_Tc                   @  s   e Zd ZdZddd	„Zd
S )ÚMetaOxmlElementzMetaclass for BaseOxmlElement.Úclsnamer"   Úbasesútuple[type, ...]Ú	namespaceú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Úitemsr!   Úpopulate_class_members)rL   rV   rW   rY   ÚdispatchableÚkeyÚvaluer   r   r   Ú__init__`   s   ù	
€þzMetaOxmlElement.__init__N)rV   r"   rW   rX   rY   rZ   )rM   rN   rO   rP   rg   r   r   r   r   rU   ]   s    rU   c                      s\   e Zd ZdZd‡ fdd„Zddd„Zdd„ Zedd„ ƒZeddd„ƒZ	eddd„ƒZ
‡  ZS )ÚBaseAttributezZBase class for OptionalAttribute and RequiredAttribute.

    Provides common methods.
    Ú	attr_namer"   Úsimple_typeú(Type[BaseXmlEnum] | Type[BaseSimpleType]c                   ó   t t| ƒ ¡  || _|| _d S r-   )Úsuperrh   rg   Ú
_attr_nameÚ_simple_type)r'   ri   rj   ©Ú	__class__r   r   rg   u   ó   
zBaseAttribute.__init__Úelement_clsrU   Ú	prop_namer   ÚNonec                 C  s   || _ || _|  ¡  dS ©z-Add the appropriate methods to `element_cls`.N)Ú_element_clsÚ
_prop_nameÚ_add_attr_property©r'   rs   rt   r   r   r   rc   z   s   z$BaseAttribute.populate_class_membersc                 C  s$   t | j| jdƒ}t| j| j|ƒ dS )zæAdd 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Úsetattrrw   rx   ©r'   Ú	property_r   r   r   ry   �   s   z BaseAttribute._add_attr_propertyc                 C  s   d| j v r
t| j ƒS | j S )Nú:)rn   r   ©r'   r   r   r   Ú_clark_name‹   s   

zBaseAttribute._clark_nameú'Callable[[BaseOxmlElement], Any | None]c                 C  ó   d S r-   r   r‚   r   r   r   r|   ‘   s   zBaseAttribute._getterú-Callable[[BaseOxmlElement, Any | None], None]c                 C  r…   r-   r   r‚   r   r   r   r}   ”   s   zBaseAttribute._setter)ri   r"   rj   rk   ©rs   rU   rt   r"   r   ru   ©r   r„   )r   r†   )rM   rN   rO   rP   rg   rc   ry   r{   rƒ   r|   r}   Ú__classcell__r   r   rp   r   rh   o   s    


rh   c                      sN   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 )r]   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.
    Nri   r"   rj   rk   Údefaultú0BaseXmlEnum | BaseSimpleType | str | bool | Nonec                   s   t t| ƒ ||¡ || _d S r-   )rm   r]   rg   Ú_default)r'   ri   rj   rŠ   rp   r   r   rg   ¢   s   
zOptionalAttribute.__init__c                 C  s   | j j› d| j› d�S )z;String to use as `__doc__` attribute of attribute property.z 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.©ro   rM   rn   r‚   r   r   r   Ú
_docstring«   s   
ÿÿzOptionalAttribute._docstringr   r„   c                   ó   d‡ fdd„}ˆ j |_|S )	zJFunction suitable for `__get__()` method on attribute property descriptor.ÚobjÚBaseOxmlElementr   ú
Any | Nonec                   s&   |   ˆ j¡}|d u rˆ jS ˆ j |¡S r-   )Úgetrƒ   rŒ   ro   Úfrom_xml©r�   Úattr_str_valuer‚   r   r   Úget_attr_value»   s   z1OptionalAttribute._getter.<locals>.get_attr_valueN©r�   r‘   r   r’   ©rŽ   rP   ©r'   r—   r   r‚   r   r|   µ   s   zOptionalAttribute._getterú&Callable[[BaseOxmlElement, Any], None]c                   ó   d‡ fdd„}|S )	zJFunction suitable for `__set__()` method on attribute property descriptor.r�   r‘   rf   r’   c                   sl   |d u s	|ˆ j krˆ j| jv r| jˆ j= d S ˆ j |¡}|d u r-ˆ j| jv r+| jˆ j= d S |  ˆ j|¡ d S r-   )rŒ   rƒ   Úattribro   Úto_xmlÚset©r�   rf   Ú	str_valuer‚   r   r   Úset_attr_valueÊ   s   

z1OptionalAttribute._setter.<locals>.set_attr_valueN)r�   r‘   rf   r’   r   ©r'   r¢   r   r‚   r   r}   Æ   s   zOptionalAttribute._setterr-   )ri   r"   rj   rk   rŠ   r‹   rˆ   ©r   r›   )
rM   rN   rO   rP   rg   r{   rŽ   r|   r}   r‰   r   r   rp   r   r]   š   s    ü	
	r]   c                   @  s8   e Zd ZdZedd„ ƒZeddd„ƒZedd	d
„ƒZdS )r^   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                 C  s   d| j j| jf S )zaReturn the string to use as the ``__doc__`` attribute of the property for
        this attribute.z,%s type-converted value of ``%s`` attribute.r�   r‚   r   r   r   rŽ   ã   s   þzRequiredAttribute._docstringr   ú Callable[[BaseOxmlElement], Any]c                   r�   )	zDfunction object suitable for "get" side of attr property descriptor.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   rn   Útagro   r”   r•   r‚   r   r   r—   ð   s   ÿz1RequiredAttribute._getter.<locals>.get_attr_valueNr˜   r™   rš   r   r‚   r   r|   ì   s   zRequiredAttribute._getterr›   c                   rœ   )	zIfunction object suitable for "set" side of attribute property descriptor.r�   r‘   rf   r   c                   s6   ˆ j  |¡}|d u rtd|› d�ƒ‚|  ˆ j|¡ d S )Nzcannot assign z to this required attribute)ro   rž   Ú
ValueErrorrŸ   rƒ   r    r‚   r   r   r¢   ÿ   s   z1RequiredAttribute._setter.<locals>.set_attr_valueN)r�   r‘   rf   r   r   r£   r   r‚   r   r}   û   s   zRequiredAttribute._setterN)r   r¥   r¤   )rM   rN   rO   rP   r{   rŽ   r|   r}   r   r   r   r   r^   Ù   s    	
r^   c                      sÊ   e Zd ZdZd2d3‡ fdd„Zd4dd„Zdd„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
edd„ ƒZdd„ Zd5d!d"„Zed6d$d%„ƒZed&d'„ ƒZed(d)„ ƒZed*d+„ ƒZed,d-„ ƒZed.d/„ ƒZed0d1„ ƒZ‡  ZS )7Ú_BaseChildElementzœBase class for the child-element classes.

    The child-element sub-classes correspond to varying cardinalities, such as ZeroOrOne
    and ZeroOrMore.
    r   Ú
nsptagnamer"   Ú
successorsútuple[str, ...]c                   rl   r-   )rm   r¨   rg   Ú_nsptagnameÚ_successors)r'   r©   rª   rp   r   r   rg     rr   z_BaseChildElement.__init__rs   rU   rt   r   ru   c                 C  s   || _ || _dS )zFBaseline behavior for adding the appropriate methods to `element_cls`.N)rw   rx   rz   r   r   r   rc     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‘   r0   r   c                   sH   t | ˆ jƒ}|ƒ }| ¡ D ]
\}}t|||ƒ qt | ˆ jƒ}||ƒ |S r-   )ÚgetattrÚ_new_method_namerb   r~   Ú_insert_method_name)r�   r0   Ú
new_methodÚchildre   rf   Úinsert_methodr‚   r   r   Ú
_add_child  s   z0_BaseChildElement._add_adder.<locals>._add_childúSAdd a new ``<%s>`` child element unconditionally, inserted in the correct sequence.N)r�   r‘   r0   r   )r¬   rP   Ú_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 )z�Add 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¬   rP   r¶   r¯   )r'   Úcreatorr   r   r   Ú_add_creator+  s   ÿÿz_BaseChildElement._add_creatorc                 C  ó"   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~   rw   rx   r   r   r   r   Ú_add_getter5  ó   z_BaseChildElement._add_getterc                   s,   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_child?  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¬   rP   r¶   r°   )r'   rÁ   r   r‚   r   Ú_add_inserter<  s   ÿÿz_BaseChildElement._add_inserterc                 C  s*   d| j  }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%s_lstN)rx   r{   Ú_list_getterr~   rw   )r'   rt   r€   r   r   r   Ú_add_list_getterI  s   
z"_BaseChildElement._add_list_getterc                 C  ó
   d| j  S )Nz_add_%s©rx   r‚   r   r   r   r·   P  ó   
z"_BaseChildElement._add_method_namec                   ó,   d‡ fdd„}dˆ j  |_ˆ  ˆ j|¡ dS )z<Add a public ``add_x()`` method to the parent element class.r�   r‘   c                   s   t | ˆ jƒ}|ƒ }|S r-   )r®   r·   )r�   Úprivate_add_methodr²   r‚   r   r   Ú	add_childW  s   z6_BaseChildElement._add_public_adder.<locals>.add_childrµ   N©r�   r‘   )r¬   rP   r¶   Ú_public_add_method_name)r'   rÊ   r   r‚   r   Ú_add_public_adderT  s   ÿÿz#_BaseChildElement._add_public_adderÚnameÚmethodúCallable[..., Any]c                 C  s"   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)Úhasattrrw   r~   )r'   rÎ   rÏ   r   r   r   r¶   b  s   z_BaseChildElement._add_to_classú,Callable[[BaseOxmlElement], BaseOxmlElement]c                   s    ddl m‰  d‡ ‡fdd„}|S )	zHCallable that creates an empty element of the right type, with no attrs.r   )ÚOxmlElementr�   r‘   c                   s
   ˆ ˆj ƒS r-   ©r¬   ©r�   ©rÓ   r'   r   r   Únew_child_elementn  s   
z5_BaseChildElement._creator.<locals>.new_child_elementNrË   )Údocx.oxml.parserrÓ   )r'   r×   r   rÖ   r   r¹   i  s   z_BaseChildElement._creatorc                   ó   d‡ fdd„}dˆ j  |_|S )zÑReturn 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                   ó   |   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.NrË   ©r¬   rP   ©r'   rÜ   r   r‚   r   r|   s  s   	ÿz_BaseChildElement._getterc                 C  rÅ   )Nz
_insert_%srÆ   r‚   r   r   r   r°   „  rÇ   z%_BaseChildElement._insert_method_namec                   rÙ   )z[Return a function object suitable for the "get" side of a list property
        descriptor.r�   r‘   c                   rÚ   r-   )Úfindallr   r¬   rÕ   r‚   r   r   Úget_child_element_list�  rÝ   z>_BaseChildElement._list_getter.<locals>.get_child_element_listzPA list containing each of the ``<%s>`` child elements, in the order they appear.NrË   rÞ   )r'   rá   r   r‚   r   rÃ   ˆ  s   ÿÿz_BaseChildElement._list_getterc                 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)_BaseChildElement._public_add_method_namec                 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Ò   )rM   rN   rO   rP   rg   rc   r¸   r»   r½   rÂ   rÄ   r   r·   rÍ   r¶   r{   r¹   r|   r°   rÃ   rÌ   rã   r¯   r‰   r   r   rp   r   r¨     s6    



	



	
r¨   c                   @  sR   e Zd ZdZedd„ ƒZddd„Z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.nsptagnamers   rU   Úgroup_prop_namer"   rª   r«   r   ru   c                 C  s>   || _ || _|| _|  ¡  |  ¡  |  ¡  |  ¡  |  ¡  dS rv   )rw   Ú_group_prop_namer­   r½   r»   rÂ   r¸   Ú_add_get_or_change_to_method)r'   rs   ræ   rª   r   r   r   rc   °  s   zChoice.populate_class_membersc                   rÈ   )zZAdd 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®   rx   Ú_remove_group_method_namer·   )r�   r²   Ú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¬   rP   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 )zDProperty name computed from tag name, e.g. a:schemeClr -> schemeClr.r�   rH   r   N)r¬   Úindex)r'   Ústartr   r   r   rx   Ô  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)rs   rU   ræ   r"   rª   r«   r   ru   )rM   rN   rO   rP   r{   r©   rc   rè   rx   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„ ƒZ‡  ZS )r[   z5Defines a required child element for MetaOxmlElement.r©   r"   c                   s   t t| ƒ |d¡ d S )Nr   )rm   r[   rg   )r'   r©   rp   r   r   rg   æ  s   zOneAndOnlyOne.__init__rs   rU   rt   r   ru   c                   s   t t| ƒ ||¡ |  ¡  dS rv   )rm   r[   rc   r½   rz   rp   r   r   rc   é  s   z$OneAndOnlyOne.populate_class_membersc                   rÙ   )úXReturn a function object suitable for the "get" side of the property
        descriptor.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.NrË   rÞ   rß   r   r‚   r   r|   î  s   zOneAndOnlyOne._getter)r©   r"   r‡   )	rM   rN   rO   rP   rg   rc   r{   r|   r‰   r   r   rp   r   r[   ã  s    r[   c                      ó"   e Zd ZdZd
‡ fdd	„Z‡  ZS )r\   zYDefines a repeating child element for MetaOxmlElement that must appear at least
    once.rs   rU   rt   r"   r   ru   c                   óH   t t| ƒ ||¡ |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  t||ƒ dS rv   )	rm   r\   rc   rÄ   r»   rÂ   r¸   rÍ   Údelattrrz   rp   r   r   rc     ó   z OneOrMore.populate_class_membersr‡   ©rM   rN   rO   rP   rc   r‰   r   r   rp   r   r\   ÿ  s    r\   c                      rñ   )r_   z@Defines an optional repeating child element for MetaOxmlElement.rs   rU   rt   r"   r   ru   c                   rò   rv   )	rm   r_   rc   rÄ   r»   rÂ   r¸   rÍ   ró   rz   rp   r   r   rc     rô   z!ZeroOrMore.populate_class_membersr‡   rõ   r   r   rp   r   r_     s    r_   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 )r`   z6Defines an optional child element for MetaOxmlElement.rs   rU   rt   r"   r   ru   c                   sF   t t| ƒ ||¡ |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  dS rv   )	rm   r`   rc   r½   r»   rÂ   r¸   Ú_add_get_or_adderÚ_add_removerrz   rp   r   r   rc     s   z ZeroOrOne.populate_class_membersc                   rÈ   )zTAdd a ``get_or_add_x()`` method to the element class for this child
        element.r�   r‘   c                   s*   t | ˆ jƒ}|d u rt | ˆ jƒ}|ƒ }|S r-   )r®   rx   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¬   rP   r¶   Ú_get_or_add_method_name)r'   rø   r   r‚   r   rö   )  s
   þzZeroOrOne._add_get_or_adderc                   rÈ   )zIAdd a ``_remove_x()`` method to the element class for this child element.r�   r‘   c                   s   |   ˆ j¡ d S r-   )Ú
remove_allr¬   rÕ   r‚   r   r   Ú_remove_child<  rÝ   z-ZeroOrOne._add_remover.<locals>._remove_childz#Remove all ``<%s>`` child elements.NrË   )r¬   rP   r¶   rã   )r'   rû   r   r‚   r   r÷   9  s   zZeroOrOne._add_removerc                 C  rÅ   )Nzget_or_add_%srÆ   r‚   r   r   r   rù   B  rÇ   z!ZeroOrOne._get_or_add_method_namer‡   )
rM   rN   rO   rP   rc   rö   r÷   r   rù   r‰   r   r   rp   r   r`     s    
	r`   c                      sb   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„ ƒZe
dd„ ƒZ‡  ZS )ra   zeCorrespondes to an ``EG_*`` element group where at most one of its members may
    appear as a child.r   ÚchoicesúSequence[Choice]rª   r«   c                 C  s   || _ || _d S r-   )Ú_choicesr­   )r'   rü   rª   r   r   r   rg   K  s   
zZeroOrOneChoice.__init__rs   rU   rt   r"   r   ru   c                   sD   t t| ƒ ||¡ |  ¡  | jD ]}| || j| j¡ q|  ¡  dS rv   )rm   ra   rc   Ú_add_choice_getterrþ   rx   r­   Ú_add_group_remover)r'   rs   rt   Úchoicerp   r   r   rc   O  s
   
z&ZeroOrOneChoice.populate_class_membersc                 C  r¼   )z“Add 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~   rw   rx   r   r   r   r   rÿ   W  r¾   z"ZeroOrOneChoice._add_choice_getterc                   s&   d‡ fdd„}d|_ ˆ  ˆ j|¡ dS )zSAdd a ``_remove_eg_x()`` method to the element class for this choice
        group.r�   r‘   c                   s   ˆ j D ]}|  |¡ qd S r-   )Ú_member_nsptagnamesrú   )r�   Útagnamer‚   r   r   Ú_remove_choice_groupb  s   
ÿz@ZeroOrOneChoice._add_group_remover.<locals>._remove_choice_groupz9Remove the current choice group child element if present.NrË   )rP   r¶   Ú _remove_choice_group_method_name)r'   r  r   r‚   r   r   ^  s   z"ZeroOrOneChoice._add_group_removerc                   s   d‡ fdd„}d|_ |S )rð   r�   r‘   c                   s   | j ˆ jŽ S r-   )Úfirst_child_found_inr  rÕ   r‚   r   r   Úget_group_member_elementn  r/   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Ë   )rP   )r'   r  r   r‚   r   r  i  s   ÿzZeroOrOneChoice._choice_getterc                 C  s   dd„ | j D ƒS )zjSequence of namespace-prefixed tagnames, one for each of the member elements
        of this choice group.c                 S  s   g | ]}|j ‘qS r   )r©   )rC   r  r   r   r   rG   {  s    z7ZeroOrOneChoice._member_nsptagnames.<locals>.<listcomp>)rþ   r‚   r   r   r   r  w  s   z#ZeroOrOneChoice._member_nsptagnamesc                 C  rÅ   râ   rÆ   r‚   r   r   r   r  }  rÇ   z0ZeroOrOneChoice._remove_choice_group_method_namerä   )rü   rý   rª   r«   r‡   )rM   rN   rO   rP   rg   rc   rÿ   r   r{   r  r   r  r  r‰   r   r   rp   r   ra   G  s    

ra   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>)rq   rM   Ú_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_beforeru   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  Úmatchingr²   r   r   r   rú      s   ÿþzBaseOxmlElement.remove_allc                 C  s   t | ƒS )z—XML string for this element, suitable for testing purposes.

        Pretty printed for readability and without an XML declaration at the top.
        )r   r‚   r   r   r   r   §  s   zBaseOxmlElement.xmlÚ	xpath_strr   c                   s   t ƒ j|td�S )z�Override of `lxml` _Element.xpath() method.

        Provides standard Open XML namespace mapping (`nsmap`) in centralized location.
        )Ú
namespaces)rm   Úxpathr   )r'   r  rp   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   ru   )r   r"   )r  r"   r   r   )rM   rN   rO   rP   r  r  r¿   rú   r{   r   r  r	  r‰   r   r   rp   r   r‘   ƒ  s    


r‘   )Ú	metaclass)r   r
   )-rP   Ú
__future__r   rQ   Útypingr   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   rT   ÚtyperU   rh   r]   r^   r¨   rå   r[   r\   r_   r`   ra   r‘   r   r   r   r   Ú<module>   s8    
	;+?/ ":+<