o
    ýÞh«O  ã                   @  sT  U d Z ddlmZ ddlmZ ddlmZmZmZ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 dd	lmZ dd
lmZmZmZ ddlmZ ddlmZ ddlm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z' dZ(de)d< 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ƒZ0d S )!z'Section-related custom element classes.é    )Úannotations)Údeepcopy)ÚCallableÚIteratorÚListÚSequenceÚcast)Úetree)Ú	TypeAlias)ÚWD_HEADER_FOOTERÚWD_ORIENTATIONÚWD_SECTION_START)Únsmap)ÚCT_OnOff)ÚST_SignedTwipsMeasureÚST_TwipsMeasureÚ	XsdString)ÚCT_Tbl)ÚCT_P)ÚBaseOxmlElementÚOptionalAttributeÚRequiredAttributeÚ
ZeroOrMoreÚ	ZeroOrOne)ÚLengthÚlazypropertyzCT_P | CT_Tblr
   ÚBlockElementc                   @  sX   e Zd ZU dZded< ded< ded< ded	< ed
dd�Zeddd�Zeddd„ƒZ	dS )Ú	CT_HdrFtrzN`w:hdr` and `w:ftr`, the root element for header and footer part respectively.zCallable[[], CT_P]Úadd_pz
List[CT_P]Úp_lstzList[CT_Tbl]Útbl_lstzCallable[[CT_Tbl], CT_Tbl]Ú_insert_tblzw:p© ©Ú
successorszw:tblÚreturnúList[CT_P | CT_Tbl]c                 C  s
   |   d¡S )z×Generate all `w:p` and `w:tbl` elements in this header or footer.

        Elements appear in document order. Elements shaded by nesting in a `w:ins` or
        other "wrapper" element will not be included.
        z./w:p | ./w:tbl)Úxpath©Úselfr"   r"   úQ/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/oxml/section.pyÚinner_content_elements)   s   
z CT_HdrFtr.inner_content_elementsN)r%   r&   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   ÚpÚtblÚpropertyr+   r"   r"   r"   r*   r      s   
 r   c                   @  s6   e Zd ZU dZedeƒZded< edeƒZ	ded< dS )	ÚCT_HdrFtrRefz5`w:headerReference` and `w:footerReference` elements.úw:typer   Útype_zr:idÚstrÚrIdN)
r,   r-   r.   r/   r   r   r6   r0   r   r8   r"   r"   r"   r*   r4   3   s   
 ÿr4   c                   @  s�   e Zd ZU dZedeƒZded< edeƒZ	ded< edeƒZ
ded< ed	eƒZded
< edeƒZded< edeƒZded< edeƒZded< dS )Ú
CT_PageMarz-``<w:pgMar>`` element, defining page margins.zw:topúLength | NoneÚtopzw:rightÚrightzw:bottomÚbottomzw:leftÚleftzw:headerÚheaderzw:footerÚfooterzw:gutterÚgutterN)r,   r-   r.   r/   r   r   r;   r0   r   r<   r=   r>   r?   r@   rA   r"   r"   r"   r*   r9   <   s.   
 ÿÿÿÿÿÿÿr9   c                   @  sN   e Zd ZU dZedeƒZded< edeƒZded< ede	e	j
d�Zd	ed
< dS )Ú	CT_PageSzz?``<w:pgSz>`` element, defining page dimensions and orientation.zw:wr:   Úwzw:hÚhzw:orient)Údefaultr   ÚorientN)r,   r-   r.   r/   r   r   rC   r0   rD   r   ÚPORTRAITrF   r"   r"   r"   r*   rB   V   s   
 ÿÿÿrB   c                   @  s¦  e Zd ZU dZded< ded< ded< ded	< d
ed< d
ed< ded< ded< dZeded�Zeded�Ze	dedd… d�Z
ded< e	dedd… d�Zded< e	dedd… d�Zded < e	d!ed"d… d�Zd#ed$< [dmd+d,„Zdmd-d.„Zednd0d1„ƒZejdod4d1„ƒZdpd5d6„Zednd7d8„ƒZejdod9d8„ƒZdqd;d<„Zdqd=d>„Zednd?d@„ƒZejdodAd@„ƒZedndBdC„ƒZejdodDdC„ƒZdrdFdG„ZedndHdI„ƒZejdodJdI„ƒZedsdLdM„ƒZejdtdOdM„ƒZedndPdQ„ƒZejdudRdQ„ƒZedndSdT„ƒZejdudUdT„ƒZedvdWdX„ƒZdwdYdZ„Zdxd[d\„Z ednd]d^„ƒZ!e!jdud_d^„ƒZ!edydadb„ƒZ"e"jdzdddb„ƒZ"ed{dfdg„ƒZ#e#jd|didg„ƒZ#edndjdk„ƒZ$e$jdudldk„ƒZ$dS )}Ú	CT_SectPrzA`w:sectPr` element, the container element for section properties.zCallable[[], CT_PageMar]Úget_or_add_pgMarzCallable[[], CT_PageSz]Úget_or_add_pgSzzCallable[[], CT_OnOff]Úget_or_add_titlePgzCallable[[], CT_SectType]Úget_or_add_typezCallable[[], CT_HdrFtrRef]Ú_add_footerReferenceÚ_add_headerReferencezCallable[[], None]Ú_remove_titlePgÚ_remove_type)zw:footnotePrzw:endnotePrr5   úw:pgSzúw:pgMarz
w:paperSrczw:pgBorderszw:lnNumTypezw:pgNumTypezw:colsz
w:formProtzw:vAlignzw:noEndnoteú	w:titlePgzw:textDirectionzw:bidizw:rtlGutterz	w:docGridzw:printerSettingszw:sectPrChangezw:headerReferencer#   zw:footerReferencer5   é   NzCT_SectType | NoneÚtyperQ   é   zCT_PageSz | NoneÚpgSzrR   é   zCT_PageMar | NoneÚpgMarrS   é   zCT_OnOff | NoneÚtitlePgr6   r   r8   r7   r%   r4   c                 C  ó   |   ¡ }||_||_|S )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:footerReference`.
        )rM   r6   r8   )r)   r6   r8   ÚfooterReferencer"   r"   r*   Úadd_footerReference–   ó   zCT_SectPr.add_footerReferencec                 C  r\   )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:headerReference`.
        )rN   r6   r8   )r)   r6   r8   ÚheaderReferencer"   r"   r*   Úadd_headerReference    r_   zCT_SectPr.add_headerReferencer:   c                 C  ó   | j }|du r	dS |jS )z™Value of the `w:bottom` attr of `<w:pgMar>` child element, as |Length|.

        |None| when either the element or the attribute is not present.
        N)rY   r=   ©r)   rY   r"   r"   r*   Úbottom_marginª   ó   zCT_SectPr.bottom_marginÚvalueúint | Length | Nonec                 C  ó2   |   ¡ }|d u st|tƒr||_d S t|ƒ|_d S ©N)rI   Ú
isinstancer   r=   ©r)   rf   rY   r"   r"   r*   rd   µ   ó   *c                 C  s   t | ƒ}|j ¡  |S )zÊReturn an exact duplicate of this ``<w:sectPr>`` element tree suitable for
        use in adding a section break.

        All rsid* attributes are removed from the root ``<w:sectPr>`` element.
        )r   ÚattribÚclear)r)   Úcloned_sectPrr"   r"   r*   Úcloneº   s   
zCT_SectPr.clonec                 C  rb   )a  Distance from bottom edge of page to bottom edge of the footer.

        This is the value of the `w:footer` attribute in the `w:pgMar` child element,
        as a |Length| object, or |None| if either the element or the attribute is not
        present.
        N)rY   r@   rc   r"   r"   r*   r@   Ä   s   zCT_SectPr.footerc                 C  rh   ri   )rI   rj   r   r@   rk   r"   r"   r*   r@   Ñ   rl   úCT_HdrFtrRef | Nonec                 C  s(   dt  |¡ }|  |¡}|sdS |d S )zAReturn footerReference element of `type_` or None if not present.z!./w:footerReference[@w:type='%s']Nr   )r   Úto_xmlr'   )r)   r6   ÚpathÚfooterReferencesr"   r"   r*   Úget_footerReferenceÖ   s
   
zCT_SectPr.get_footerReferencec                 C  s,   |   dt |¡ ¡}t|ƒdkrdS |d S )zAReturn headerReference element of `type_` or None if not present.z!./w:headerReference[@w:type='%s']r   N)r'   r   rr   Úlen)r)   r6   Úmatching_headerReferencesr"   r"   r*   Úget_headerReferenceÞ   s   ÿzCT_SectPr.get_headerReferencec                 C  rb   )z²The value of the ``w:gutter`` attribute in the ``<w:pgMar>`` child element,
        as a |Length| object, or |None| if either the element or the attribute is not
        present.N)rY   rA   rc   r"   r"   r*   rA   ç   ó   zCT_SectPr.gutterc                 C  rh   ri   )rI   rj   r   rA   rk   r"   r"   r*   rA   ñ   rl   c                 C  rb   )zÜDistance from top edge of page to top edge of header.

        This value comes from the `w:header` attribute on the `w:pgMar` child element.
        |None| if either the element or the attribute is not present.
        N)rY   r?   rc   r"   r"   r*   r?   ö   s   zCT_SectPr.headerc                 C  rh   ri   )rI   rj   r   r?   rk   r"   r"   r*   r?     rl   úIterator[CT_P | CT_Tbl]c                 C  s
   t  | ¡S )zÎGenerate all `w:p` and `w:tbl` elements in this section.

        Elements appear in document order. Elements shaded by nesting in a `w:ins` or
        other "wrapper" element will not be included.
        )Ú_SectBlockElementIteratorÚiter_sect_block_elementsr(   r"   r"   r*   Úiter_inner_content  s   
zCT_SectPr.iter_inner_contentc                 C  rb   )z°The value of the ``w:left`` attribute in the ``<w:pgMar>`` child element, as
        a |Length| object, or |None| if either the element or the attribute is not
        present.N)rY   r>   rc   r"   r"   r*   Úleft_margin  ry   zCT_SectPr.left_marginc                 C  rh   ri   )rI   rj   r   r>   rk   r"   r"   r*   r~     rl   r   c                 C  s   | j }|du r
tjS |jS )zÏ`WD_ORIENTATION` member indicating page-orientation for this section.

        This is the value of the `orient` attribute on the `w:pgSz` child, or
        `WD_ORIENTATION.PORTRAIT` if not present.
        N)rW   r   rG   rF   ©r)   rW   r"   r"   r*   Úorientation  s   zCT_SectPr.orientationúWD_ORIENTATION | Nonec                 C  s"   |   ¡ }|r||_d S tj|_d S ri   )rJ   r   rG   rF   ©r)   rf   rW   r"   r"   r*   r€   *  s   c                 C  rb   )ziValue in EMU of the `h` attribute of the `w:pgSz` child element.

        |None| if not present.
        N)rW   rD   r   r"   r"   r*   Úpage_height/  re   zCT_SectPr.page_heightc                 C  ó   |   ¡ }||_d S ri   )rJ   rD   r‚   r"   r"   r*   rƒ   :  ó   
c                 C  rb   )zoValue in EMU of the ``w`` attribute of the ``<w:pgSz>`` child element.

        |None| if not present.
        N)rW   rC   r   r"   r"   r*   Ú
page_width?  re   zCT_SectPr.page_widthc                 C  r„   ri   )rJ   rC   r‚   r"   r"   r*   r†   J  r…   úCT_SectPr | Nonec                 C  s"   |   d¡}t|ƒdkr|d S dS )zCSectPr immediately preceding this one or None if this is the first.z./preceding::w:sectPr[1]r   N)r'   rv   )r)   Úpreceding_sectPrsr"   r"   r*   Úpreceding_sectPrO  s   
zCT_SectPr.preceding_sectPrc                 C  ó.   |   |¡}|du rtdƒ‚|j}|  |¡ |S )zCReturn rId of w:footerReference child of `type_` after removing it.Nz!CT_SectPr has no footer reference)ru   Ú
ValueErrorr8   Úremove)r)   r6   r]   r8   r"   r"   r*   Úremove_footerReferenceV  ó   

z CT_SectPr.remove_footerReferencec                 C  rŠ   )zCReturn rId of w:headerReference child of `type_` after removing it.Nz!CT_SectPr has no header reference)rx   r‹   r8   rŒ   )r)   r6   r`   r8   r"   r"   r*   Úremove_headerReference`  rŽ   z CT_SectPr.remove_headerReferencec                 C  rb   )z±The value of the ``w:right`` attribute in the ``<w:pgMar>`` child element, as
        a |Length| object, or |None| if either the element or the attribute is not
        present.N)rY   r<   rc   r"   r"   r*   Úright_marginj  ry   zCT_SectPr.right_marginc                 C  r„   ri   )rI   r<   rk   r"   r"   r*   r�   t  r…   r   c                 C  s$   | j }|du s|jdu rtjS |jS )zÊThe member of the ``WD_SECTION_START`` enumeration corresponding to the value
        of the ``val`` attribute of the ``<w:type>`` child element, or
        ``WD_SECTION_START.NEW_PAGE`` if not present.N)rU   Úvalr   ÚNEW_PAGE)r)   rU   r"   r"   r*   Ú
start_typey  s   zCT_SectPr.start_typeúWD_SECTION_START | Nonec                 C  s0   |d u s	|t ju r|  ¡  d S |  ¡ }||_d S ri   )r   r’   rP   rL   r‘   )r)   rf   rU   r"   r"   r*   r“   ƒ  s
   
Úboolc                 C  s   | j }|du r	dS |jS )zEValue of `w:titlePg/@val` or |False| if `./w:titlePg` is not present.NF)r[   r‘   )r)   r[   r"   r"   r*   ÚtitlePg_val‹  s   zCT_SectPr.titlePg_valúbool | Nonec                 C  s"   |dv r
|   ¡  d S d|  ¡ _d S )N)NFT)rO   rK   r‘   )r)   rf   r"   r"   r*   r–   “  s   c                 C  rb   )z¯The value of the ``w:top`` attribute in the ``<w:pgMar>`` child element, as a
        |Length| object, or |None| if either the element or the attribute is not
        present.N)rY   r;   rc   r"   r"   r*   Ú
top_marginš  ry   zCT_SectPr.top_marginc                 C  r„   ri   )rI   r;   rk   r"   r"   r*   r˜   ¤  r…   )r6   r   r8   r7   r%   r4   )r%   r:   )rf   rg   )r%   rH   )r6   r   r%   rq   )r%   rz   )r%   r   )rf   r�   )rf   r:   )r%   r‡   )r6   r   r%   r7   )r6   r   )r%   r   )rf   r”   )r%   r•   )rf   r—   )%r,   r-   r.   r/   r0   Ú_tag_seqr   r`   r]   r   rU   rW   rY   r[   r^   ra   r3   rd   Úsetterrp   r@   ru   rx   rA   r?   r}   r~   r€   rƒ   r†   r‰   r�   r�   r�   r“   r–   r˜   r"   r"   r"   r*   rH   d   s¨   
 ÿÿÿÿ








		
	





			rH   c                   @  s$   e Zd ZU dZedeƒZded< dS )ÚCT_SectTypez:``<w:sectType>`` element, defining the section start type.zw:valr”   r‘   N)r,   r-   r.   r/   r   r   r‘   r0   r"   r"   r"   r*   r›   ª  s
   
 ÿr›   c                   @  s|   e Zd ZU dZdZded< dZded< ddd	„Zeddd„ƒZ	ddd„Z
ddd„Zed dd„ƒZd!dd„Zed"dd„ƒZdS )#r{   z�Generates the block-item XML elements in a section.

    A block-item element is a `CT_P` (paragraph) or a `CT_Tbl` (table).
    Nzetree.XPath | NoneÚ_compiled_blocks_xpathÚ_compiled_count_xpathÚsectPrrH   c                 C  s
   || _ d S ri   )Ú_sectPr)r)   rž   r"   r"   r*   Ú__init__¾  s   
z"_SectBlockElementIterator.__init__r%   úIterator[BlockElement]c                 C  s   | |ƒ  ¡ S )zIGenerate each CT_P or CT_Tbl element within extents governed by `sectPr`.)Ú_iter_sect_block_elements)Úclsrž   r"   r"   r*   r|   Á  s   z2_SectBlockElementIterator.iter_sect_block_elementsc                 c  sZ   � | j | j}}| |¡}|dkrdn|  ||d  ¡}|  |¡|d… D ]}|V  q%dS )z0Generate each CT_P or CT_Tbl element in section.r   é   N)rŸ   Ú_sectPrsÚindexÚ%_count_of_blocks_in_and_above_sectionÚ_blocks_in_and_above_section)r)   rž   ÚsectPrsÚ
sectPr_idxÚn_blks_to_skipÚelementr"   r"   r*   r¢   Æ  s   €
ÿýÿz3_SectBlockElementIterator._iter_sect_block_elementsúSequence[BlockElement]c                 C  s6   | j du rtj| jtdd�| _ | j }ttt ||ƒƒS )úFAll ps and tbls in section defined by `sectPr` and all prior sections.NF©Ú
namespacesÚregexp)rœ   r	   ÚXPathÚ"_blocks_in_and_above_section_xpathr   r   r   r   ©r)   rž   r'   r"   r"   r*   r¨   à  s   
ýz6_SectBlockElementIterator._blocks_in_and_above_sectionr7   c              	   C  s,   d}d}d}|› d|› d|› d|› d|› �	S )zHXPath expr for ps and tbls in context of a sectPr and all prior sectPrs.z./parent::w:pPr/parent::w:pzself::w:sectPr[parent::w:body]z-preceding-sibling::*[self::w:p | self::w:tbl]z | ú/r"   )r)   Úp_sect_term_blockÚbody_sect_termÚpred_ps_and_tblsr"   r"   r*   r³   ì  s   
þþüüþz<_SectBlockElementIterator._blocks_in_and_above_section_xpathÚintc                 C  s>   | j du rtjd| j› d�tdd�| _ | j }ttt||ƒƒƒS )r®   Nzcount(ú)Fr¯   )r�   r	   r²   r³   r   r¹   r   Úfloatr´   r"   r"   r*   r§     s   
ýz?_SectBlockElementIterator._count_of_blocks_in_and_above_sectionúSequence[CT_SectPr]c                 C  s   | j  d¡S )z5All w:sectPr elements in document, in document-order.zC/w:document/w:body/w:p/w:pPr/w:sectPr | /w:document/w:body/w:sectPr)rŸ   r'   r(   r"   r"   r*   r¥     s   ÿz"_SectBlockElementIterator._sectPrs)rž   rH   )rž   rH   r%   r¡   )r%   r¡   )rž   rH   r%   r­   )r%   r7   )rž   rH   r%   r¹   )r%   r¼   )r,   r-   r.   r/   rœ   r0   r�   r    Úclassmethodr|   r¢   r¨   r   r³   r§   r¥   r"   r"   r"   r*   r{   µ  s   
 



r{   N)1r/   Ú
__future__r   Úcopyr   Útypingr   r   r   r   r   Úlxmlr	   Útyping_extensionsr
   Údocx.enum.sectionr   r   r   Údocx.oxml.nsr   Údocx.oxml.sharedr   Údocx.oxml.simpletypesr   r   r   Údocx.oxml.tabler   Údocx.oxml.text.paragraphr   Údocx.oxml.xmlchemyr   r   r   r   r   Údocx.sharedr   r   r   r0   r   r4   r9   rB   rH   r›   r{   r"   r"   r"   r*   Ú<module>   s0    	  H