
    hiO                       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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          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                      e Zd ZU dZded<   ded<   ded<   ded	<    ed
d          Z edd          Ze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                ,    |                      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selfs    i/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/docx/oxml/section.pyinner_content_elementsz CT_HdrFtr.inner_content_elements)   s     zz+,,,    N)r'   r(   )
__name__
__module____qualname____doc____annotations__r   ptblpropertyr.   r$   r/   r-   r   r      s         XX++++
5R(((A
*W
,
,
,C- - - X- - -r/   r   c                  X    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)
r0   r1   r2   r3   r   r   r;   r4   r   r=   r$   r/   r-   r9   r9   3   sd         ??//" E     ! 33C333333r/   r9   c                     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)r0   r1   r2   r3   r   r   rA   r4   r   rB   rC   rD   rE   rF   rG   r$   r/   r-   r?   r?   <   sW        77**& C     -,? E     .-) F     ,+/ D     .-O F     .-O F     .-O F      r/   r?   c                      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
                  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)r0   r1   r2   r3   r   r   rJ   r4   rK   r   PORTRAITrM   r$   r/   r-   rI   rI   V   s         II(( A     )( A     /.NN,C  F      r/   rI   c                  ~   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          Z ede          Z e	dedd                   Z
ded<    e	dedd                   Zded<    e	dedd                   Zded <    e	d!ed"d                   Zd#ed$<   [dXd+ZdXd,ZedYd.            Zej        dZd1            Zd[d2ZedYd3            Zej        dZd4            Zd\d6Zd\d7ZedYd8            Zej        dZd9            ZedYd:            Zej        dZd;            Zd]d=ZedYd>            Zej        dZd?            Zed^dA            Zej        d_dC            ZedYdD            Zej        d`dE            ZedYdF            Zej        d`dG            ZedadI            ZdbdJZdcdKZ edYdL            Z!e!j        d`dM            Z!edddO            Z"e"j        dedQ            Z"edfdS            Z#e#j        dgdU            Z#edYdV            Z$e$j        d`dW            Z$dS )h	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:endnotePrr:   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:footerReferencer:      NzCT_SectType | NonetyperY      zCT_PageSz | NonepgSzrZ      zCT_PageMar | NonepgMarr[      zCT_OnOff | NonetitlePgr;   r   r=   r<   r'   r9   c                J    |                                  }||_        ||_        |S )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:footerReference`.
        )rU   r;   r=   )r,   r;   r=   footerReferences       r-   add_footerReferencezCT_SectPr.add_footerReference   +    
 3355 %!r/   c                J    |                                  }||_        ||_        |S )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:headerReference`.
        )rV   r;   r=   )r,   r;   r=   headerReferences       r-   add_headerReferencezCT_SectPr.add_headerReference   rg   r/   r@   c                &    | j         }|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)ra   rC   r,   ra   s     r-   bottom_marginzCT_SectPr.bottom_margin   s     
=4|r/   valueint | Length | Nonec                    |                                  }|t          |t                    r|nt          |          |_        d S N)rQ   
isinstancer   rC   r,   rn   ra   s      r-   rm   zCT_SectPr.bottom_margin   >    %%'' %E61J1JuuPVW\P]P]r/   c                V    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   attribclear)r,   cloned_sectPrs     r-   clonezCT_SectPr.clone   s*     !""$$$r/   c                &    | j         }|dS |j        S )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)ra   rF   rl   s     r-   rF   zCT_SectPr.footer   s     
=4|r/   c                    |                                  }|t          |t                    r|nt          |          |_        d S rq   )rQ   rr   r   rF   rs   s      r-   rF   zCT_SectPr.footer   rt   r/   CT_HdrFtrRef | Nonec                r    dt          j        |          z  }|                     |          }|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,   r;   pathfooterReferencess       r-   get_footerReferencezCT_SectPr.get_footerReference   sB    25E5LU5S5SS::d++ 	4""r/   c                    |                      dt          j        |          z            }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   r~   len)r,   r;   matching_headerReferencess      r-   get_headerReferencezCT_SectPr.get_headerReference   sP    $(JJ/2B2I%2P2PP%
 %
! ())Q..4(++r/   c                &    | j         }|dS |j        S )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)ra   rG   rl   s     r-   rG   zCT_SectPr.gutter   s    
 
=4|r/   c                    |                                  }|t          |t                    r|nt          |          |_        d S rq   )rQ   rr   r   rG   rs   s      r-   rG   zCT_SectPr.gutter   rt   r/   c                &    | j         }|dS |j        S )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)ra   rE   rl   s     r-   rE   zCT_SectPr.header   s     
=4|r/   c                    |                                  }|t          |t                    r|nt          |          |_        d S rq   )rQ   rr   r   rE   rs   s      r-   rE   zCT_SectPr.header  rt   r/   Iterator[CT_P | CT_Tbl]c                6    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+   s    r-   iter_inner_contentzCT_SectPr.iter_inner_content  s     )AA$GGGr/   c                &    | j         }|dS |j        S )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)ra   rD   rl   s     r-   left_marginzCT_SectPr.left_margin  s    
 
=4zr/   c                    |                                  }|t          |t                    r|nt          |          |_        d S rq   )rQ   rr   r   rD   rs   s      r-   r   zCT_SectPr.left_margin  s;    %%''#mz%/H/HmUUfUZmm


r/   r   c                :    | j         }|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.
        )r_   r   rN   rM   r,   r_   s     r-   orientationzCT_SectPr.orientation  s!     y<!**{r/   WD_ORIENTATION | Nonec                X    |                                  }|r|nt          j        |_        d S rq   )rR   r   rN   rM   r,   rn   r_   s      r-   r   zCT_SectPr.orientation*  s*    ##%%$Aee.*Ar/   c                &    | j         }|dS |j        S )ziValue in EMU of the `h` attribute of the `w:pgSz` child element.

        |None| if not present.
        N)r_   rK   r   s     r-   page_heightzCT_SectPr.page_height/       y<4vr/   c                <    |                                  }||_        d S rq   )rR   rK   r   s      r-   r   zCT_SectPr.page_height:      ##%%r/   c                &    | j         }|dS |j        S )zoValue in EMU of the ``w`` attribute of the ``<w:pgSz>`` child element.

        |None| if not present.
        N)r_   rJ   r   s     r-   
page_widthzCT_SectPr.page_width?  r   r/   c                <    |                                  }||_        d S rq   )rR   rJ   r   s      r-   r   zCT_SectPr.page_widthJ  r   r/   CT_SectPr | Nonec                f    |                      d          }t          |          dk    r|d         ndS )zCSectPr immediately preceding this one or None if this is the first.z./preceding::w:sectPr[1]r   N)r*   r   )r,   preceding_sectPrss     r-   preceding_sectPrzCT_SectPr.preceding_sectPrO  s;     !JJ'ABB'*+<'='='A'A ##tKr/   c                    |                      |          }|t          d          |j        }|                     |           |S )zCReturn rId of w:footerReference child of `type_` after removing it.Nz!CT_SectPr has no footer reference)r   
ValueErrorr=   remove)r,   r;   re   r=   s       r-   remove_footerReferencez CT_SectPr.remove_footerReferenceV  I    22599"@AAA!O$$$
r/   c                    |                      |          }|t          d          |j        }|                     |           |S )zCReturn rId of w:headerReference child of `type_` after removing it.Nz!CT_SectPr has no header reference)r   r   r=   r   )r,   r;   ri   r=   s       r-   remove_headerReferencez CT_SectPr.remove_headerReference`  r   r/   c                &    | j         }|dS |j        S )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)ra   rB   rl   s     r-   right_marginzCT_SectPr.right_marginj  s    
 
=4{r/   c                <    |                                  }||_        d S rq   )rQ   rB   rs   s      r-   r   zCT_SectPr.right_margint  s    %%''r/   r   c                H    | j         }||j        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.)r]   valr   NEW_PAGE)r,   r]   s     r-   
start_typezCT_SectPr.start_typey  s'    
 y<48+#,,xr/   WD_SECTION_START | Nonec                    ||t           j        u r|                                  d S |                                 }||_        d S rq   )r   r   rX   rT   r   )r,   rn   r]   s      r-   r   zCT_SectPr.start_type  sH    =E%5%>>>F##%%r/   boolc                &    | j         }|dS |j        S )zEValue of `w:titlePg/@val` or |False| if `./w:titlePg` is not present.NF)rc   r   )r,   rc   s     r-   titlePg_valzCT_SectPr.titlePg_val  s     ,?5{r/   bool | Nonec                l    |dv r|                                   d S d|                                 _        d S )N)NFT)rW   rS   r   )r,   rn   s     r-   r   zCT_SectPr.titlePg_val  s?    M!!  """"",0D##%%)))r/   c                &    | j         }|dS |j        S )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)ra   rA   rl   s     r-   
top_marginzCT_SectPr.top_margin  s    
 
=4yr/   c                <    |                                  }||_        d S rq   )rQ   rA   rs   s      r-   r   zCT_SectPr.top_margin  s    %%''			r/   )r;   r   r=   r<   r'   r9   )r'   r@   )rn   ro   )r'   rP   )r;   r   r'   r|   )r'   r   )r'   r   )rn   r   )rn   r@   )r'   r   )r;   r   r'   r<   )r;   r   )r'   r   )rn   r   )r'   r   )rn   r   )%r0   r1   r2   r3   r4   _tag_seqr   ri   re   r   r]   r_   ra   rc   rf   rj   r7   rm   setterry   rF   r   r   rG   rE   r   r   r   r   r   r   r   r   r   r   r   r   r$   r/   r-   rP   rP   d   s        KK....,,,,........44444444''''$$$$H, !j!4JJJO j!4JJJO(yXabb\     D     'YXabb\  D      )yhqrrl     E      )y     G     	          X ^ ^ ^ ^    
 
 
 X
 ]^ ^ ^ ]^# # # #, , , ,    X ]^ ^ ^ ]^ 	 	 	 X	 ]^ ^ ^ ]^H H H H    X \ \ \ \ 	 	 	 X	 B B B B    X        X     L L L XL          X        X        X 1 1 1 1    X      r/   rP   c                  6    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)r0   r1   r2   r3   r   r   r   r4   r$   r/   r-   r   r     sH         DD#4#4!$ $C      r/   r   c                      e Zd ZU dZdZded<   dZded<   ddZedd            Z	ddZ
ddZedd            ZddZedd            ZdS )r   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sectPrrP   c                    || _         d S rq   )_sectPr)r,   r   s     r-   __init__z"_SectBlockElementIterator.__init__  s    r/   r'   Iterator[BlockElement]c                <     | |                                           S )zIGenerate each CT_P or CT_Tbl element within extents governed by `sectPr`.)_iter_sect_block_elements)clsr   s     r-   r   z2_SectBlockElementIterator.iter_sect_block_elements  s     s6{{44666r/   c              #     K   | j         | j        }}|                    |          }|dk    rdn|                     ||dz
                     }|                     |          |d         D ]}|V  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elements         r-   r   z3_SectBlockElementIterator._iter_sect_block_elements  s       ,]]6**

 Q A;;GJQRN<STT 	 88@@Q 	 	GMMMM	 	r/   Sequence[BlockElement]c                    | j         &t          j        | j        t          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*   s      r-   r   z6_SectBlockElementIterator._blocks_in_and_above_section  sW    &.*/+7 + + +D'
 +H\*EE&MM:::r/   r<   c           	     .    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_tblss       r-   r   z<_SectBlockElementIterator._blocks_in_and_above_section_xpath  sa     :9J ! 6 6#6 6&66 6 !	6 6 $4	6 6	
r/   intc                    | j         *t          j        d| j         dt          d          | _         | j         }t          t          t           ||                              S )r   Nzcount()Fr   )r   r
   r   r   r   r   r	   floatr   s      r-   r   z?_SectBlockElementIterator._count_of_blocks_in_and_above_section  se    %-).C@CCC * * *D&
 *4uuV}}--...r/   Sequence[CT_SectPr]c                6    | 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+   s    r-   r   z"_SectBlockElementIterator._sectPrs  s!     |!!Q
 
 	
r/   )r   rP   )r   rP   r'   r   )r'   r   )r   rP   r'   r   )r'   r<   )r   rP   r'   r   )r'   r   )r0   r1   r2   r3   r   r4   r   r   classmethodr   r   r   r   r   r   r   r$   r/   r-   r   r     s          
 265555044444    7 7 7 [7   4
; 
; 
; 
; 
 
 
 \
6
/ 
/ 
/ 
/ 
 
 
 \
 
 
r/   r   N)1r3   
__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   r4   r   r9   r?   rI   rP   r   r   r$   r/   r-   <module>r      s   - - - " " " " " "       ; ; ; ; ; ; ; ; ; ; ; ; ; ;       ' ' ' ' ' ' P P P P P P P P P P       % % % % % % S S S S S S S S S S " " " " " " ) ) ) ) ) )              - , , , , , , ,) ) ) ) )- - - - - - - -,4 4 4 4 4? 4 4 4       4       C C C C C C C CL
    /   d
 d
 d
 d
 d
 d
 d
 d
 d
 d
r/   