o
    jO                     @  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]Zadd_pz
List[CT_P]Zp_lstzList[CT_Tbl]Ztbl_lstzCallable[[CT_Tbl], CT_Tbl]Z_insert_tblzw:p 
successorszw:tblreturnList[CT_P | CT_Tbl]c                 C  s
   |  dS )zGenerate 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   R/var/www/html/Deteccion_Ine/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   pZ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   r1   r,   r   r3   r   r   r   r&   r/   3   s   
 r/   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   r6   r,   r   r7   r8   r9   r:   r;   r<   r   r   r   r&   r4   <   s.   
 r4   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:wr5   wzw:hhzw:orient)defaultr   orientN)r(   r)   r*   r+   r   r   r>   r,   r?   r   PORTRAITrA   r   r   r   r&   r=   V   s   
 r=   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:endnotePrr0   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:footerReferencer0      NzCT_SectType | NonetyperL      zCT_PageSz | NonepgSzrM      zCT_PageMar | NonepgMarrN      zCT_OnOff | NonetitlePgr1   r   r3   r2   r!   r/   c                 C     |   }||_||_|S )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:footerReference`.
        )rH   r1   r3   )r%   r1   r3   footerReferencer   r   r&   add_footerReference      zCT_SectPr.add_footerReferencec                 C  rW   )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:headerReference`.
        )rI   r1   r3   )r%   r1   r3   headerReferencer   r   r&   add_headerReference   rZ   zCT_SectPr.add_headerReferencer5   c                 C     | j }|du r	dS |jS )zValue of the `w:bottom` attr of `<w:pgMar>` child element, as |Length|.

        |None| when either the element or the attribute is not present.
        N)rT   r8   r%   rT   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)rD   
isinstancer   r8   r%   ra   rT   r   r   r&   r_         *c                 C  s   t | }|j  |S )zReturn 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   Zattribclear)r%   Zcloned_sectPrr   r   r&   clone   s   
zCT_SectPr.clonec                 C  r]   )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)rT   r;   r^   r   r   r&   r;      s   zCT_SectPr.footerc                 C  rc   rd   )rD   re   r   r;   rf   r   r   r&   r;      rg   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%   r1   pathZ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   rk   len)r%   r1   Zmatching_headerReferencesr   r   r&   get_headerReference   s   zCT_SectPr.get_headerReferencec                 C  r]   )zThe 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)rT   r<   r^   r   r   r&   r<         zCT_SectPr.gutterc                 C  rc   rd   )rD   re   r   r<   rf   r   r   r&   r<      rg   c                 C  r]   )zDistance 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)rT   r:   r^   r   r   r&   r:      s   zCT_SectPr.headerc                 C  rc   rd   )rD   re   r   r:   rf   r   r   r&   r:     rg   Iterator[CT_P | CT_Tbl]c                 C  s
   t | S )zGenerate 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  r]   )zThe 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)rT   r9   r^   r   r   r&   left_margin  rp   zCT_SectPr.left_marginc                 C  rc   rd   )rD   re   r   r9   rf   r   r   r&   ru     rg   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)rR   r   rB   rA   r%   rR   r   r   r&   orientation  s   zCT_SectPr.orientationWD_ORIENTATION | Nonec                 C  s"   |   }|r||_d S tj|_d S rd   )rE   r   rB   rA   r%   ra   rR   r   r   r&   rw   *  s   c                 C  r]   )ziValue in EMU of the `h` attribute of the `w:pgSz` child element.

        |None| if not present.
        N)rR   r?   rv   r   r   r&   page_height/  r`   zCT_SectPr.page_heightc                 C     |   }||_d S rd   )rE   r?   ry   r   r   r&   rz   :     
c                 C  r]   )zoValue in EMU of the ``w`` attribute of the ``<w:pgSz>`` child element.

        |None| if not present.
        N)rR   r>   rv   r   r   r&   
page_width?  r`   zCT_SectPr.page_widthc                 C  r{   rd   )rE   r>   ry   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#   rn   )r%   Z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)rm   
ValueErrorr3   remove)r%   r1   rX   r3   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)ro   r   r3   r   )r%   r1   r[   r3   r   r   r&   remove_headerReference`  r   z CT_SectPr.remove_headerReferencec                 C  r]   )zThe 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)rT   r7   r^   r   r   r&   right_marginj  rp   zCT_SectPr.right_marginc                 C  r{   rd   )rD   r7   rf   r   r   r&   r   t  r|   r   c                 C  s$   | j }|du s|jdu rtjS |jS )zThe 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)rP   valr   NEW_PAGE)r%   rP   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 rd   )r   r   rK   rG   r   )r%   ra   rP   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)rV   r   )r%   rV   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)rJ   rF   r   )r%   ra   r   r   r&   r     s   c                 C  r]   )zThe 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)rT   r6   r^   r   r   r&   
top_margin  rp   zCT_SectPr.top_marginc                 C  r{   rd   )rD   r6   rf   r   r   r&   r     r|   )r1   r   r3   r2   r!   r/   )r!   r5   )ra   rb   )r!   rC   )r1   r   r!   rj   )r!   rq   )r!   r   )ra   rx   )ra   r5   )r!   r~   )r1   r   r!   r2   )r1   r   )r!   r   )ra   r   )r!   r   )ra   r   )%r(   r)   r*   r+   r,   Z_tag_seqr   r[   rX   r   rP   rR   rT   rV   rY   r\   r.   r_   setterri   r;   rm   ro   r<   r:   rt   ru   rw   rz   r}   r   r   r   r   r   r   r   r   r   r   r&   rC   d   s   
 


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


			rC   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   r,   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 )#rr   zGenerates 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sectPrrC   c                 C  s
   || _ d S rd   )_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&   rs     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   ZsectPrsZ
sectPr_idxZ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_sectionr2   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%   Zp_sect_term_blockZbody_sect_termZ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   rC   )r   rC   r!   r   )r!   r   )r   rC   r!   r   )r!   r2   )r   rC   r!   r   )r!   r   )r(   r)   r*   r+   r   r,   r   r   classmethodrs   r   r   r   r   r   r   r   r   r   r&   rr     s   
 



rr   N)1r+   
__future__r   copyr   typingr   r   r   r   r   Zlxmlr	   Ztyping_extensionsr
   Zdocx.enum.sectionr   r   r   Zdocx.oxml.nsr   Zdocx.oxml.sharedr   Zdocx.oxml.simpletypesr   r   r   Zdocx.oxml.tabler   Zdocx.oxml.text.paragraphr   Zdocx.oxml.xmlchemyr   r   r   r   r   Zdocx.sharedr   r   r   r,   r   r/   r4   r=   rC   r   rr   r   r   r   r&   <module>   s0    	  H