
    ,hO                       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      Z0y )!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                  t    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	y)	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:tblc                $    | j                  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    S/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/oxml/section.pyinner_content_elementsz CT_HdrFtr.inner_content_elements)   s     zz+,,    N)returnzList[CT_P | CT_Tbl])
__name__
__module____qualname____doc____annotations__r   ptblpropertyr,   r$   r-   r+   r   r      sG    X++5R(A
W
,C- -r-   r   c                  J    e Zd ZU dZ ede      Zded<    ede      Z	ded<   y)	CT_HdrFtrRefz5`w:headerReference` and `w:footerReference` elements.w:typer   type_zr:idstrrIdN)
r/   r0   r1   r2   r   r   r:   r3   r   r<   r$   r-   r+   r8   r8   3   s0    ?/"E  !3C3r-   r8   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<   y)
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/   r0   r1   r2   r   r   r@   r3   r   rA   rB   rC   rD   rE   rF   r$   r-   r+   r>   r>   <   s    7*&C  -?E=  .)FM  ,/D-  .OFM  .OFM  .OFM 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
<   y)	CT_PageSzz?``<w:pgSz>`` element, defining page dimensions and orientation.zw:wr?   wzw:hhzw:orient)defaultr   orientN)r/   r0   r1   r2   r   r   rI   r3   rJ   r   PORTRAITrL   r$   r-   r+   rH   rH   V   sS    I(A}  )A}  /NN,C,CFN r-   rH   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$<   [dFd%ZdFd&ZedGd'       Zej$                  dHd(       ZdId)ZedGd*       Zej$                  dHd+       ZdJd,ZdJd-ZedGd.       Zej$                  dHd/       ZedGd0       Zej$                  dHd1       ZdKd2ZedGd3       Zej$                  dHd4       ZedLd5       Zej$                  dMd6       ZedGd7       Zej$                  dNd8       ZedGd9       Zej$                  dNd:       ZedOd;       ZdPd<ZdQd=Z edGd>       Z!e!j$                  dNd?       Z!edRd@       Z"e"j$                  dSdA       Z"edTdB       Z#e#j$                  dUdC       Z#edGdD       Z$e$j$                  dNdE       Z$y)V	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:endnotePrr9   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:footerReferencer9      NzCT_SectType | NonetyperX      zCT_PageSz | NonepgSzrY      zCT_PageMar | NonepgMarrZ      zCT_OnOff | NonetitlePgc                B    | j                         }||_        ||_        |S )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:footerReference`.
        )rT   r:   r<   )r*   r:   r<   footerReferences       r+   add_footerReferencezCT_SectPr.add_footerReference   (    
 335 %!r-   c                B    | j                         }||_        ||_        |S )zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

        The element tag is `w:headerReference`.
        )rU   r:   r<   )r*   r:   r<   headerReferences       r+   add_headerReferencezCT_SectPr.add_headerReference   rf   r-   c                8    | j                   }|y|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)r`   rB   r*   r`   s     r+   bottom_marginzCT_SectPr.bottom_margin   s     

=||r-   c                x    | j                         }|t        |t              r||_        y t        |      |_        y N)rP   
isinstancer   rB   r*   valuer`   s      r+   rl   zCT_SectPr.bottom_margin   1    %%' %E61JuPVW\P]r-   c                P    t        |       }|j                  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                8    | j                   }|y|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)r`   rE   rk   s     r+   rE   zCT_SectPr.footer   s     

=||r-   c                x    | j                         }|t        |t              r||_        y t        |      |_        y rn   )rP   ro   r   rE   rp   s      r+   rE   zCT_SectPr.footer   rr   r-   c                d    dt        j                  |      z  }| j                  |      }|sy|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   s8    25E5L5LU5SS::d+""r-   c                x    | j                  dt        j                  |      z        }t        |      dk(  ry|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   sC    $(JJ/2B2I2I%2PP%
! ()Q.(++r-   c                8    | j                   }|y|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)r`   rF   rk   s     r+   rF   zCT_SectPr.gutter   s    
 

=||r-   c                x    | j                         }|t        |t              r||_        y t        |      |_        y rn   )rP   ro   r   rF   rp   s      r+   rF   zCT_SectPr.gutter   rr   r-   c                8    | j                   }|y|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)r`   rD   rk   s     r+   rD   zCT_SectPr.header   s     

=||r-   c                x    | j                         }|t        |t              r||_        y t        |      |_        y rn   )rP   ro   r   rD   rp   s      r+   rD   zCT_SectPr.header  rr   r-   c                ,    t         j                  |       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Gr-   c                8    | j                   }|y|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)r`   rC   rk   s     r+   left_marginzCT_SectPr.left_margin  s    
 

=zzr-   c                x    | j                         }|t        |t              r||_        y t        |      |_        y rn   )rP   ro   r   rC   rp   s      r+   r   zCT_SectPr.left_margin  s/    %%'#mz%/HU
fUZm
r-   c                V    | 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   rM   rL   r*   r^   s     r+   orientationzCT_SectPr.orientation  s(     yy<!***{{r-   c                b    | j                         }|r||_        y t        j                  |_        y rn   )rQ   r   rM   rL   r*   rq   r^   s      r+   r   zCT_SectPr.orientation*  s%    ##%$e.*A*Ar-   c                8    | j                   }|y|j                  S )ziValue in EMU of the `h` attribute of the `w:pgSz` child element.

        |None| if not present.
        N)r^   rJ   r   s     r+   page_heightzCT_SectPr.page_height/       yy<vvr-   c                2    | j                         }||_        y rn   )rQ   rJ   r   s      r+   r   zCT_SectPr.page_height:      ##%r-   c                8    | j                   }|y|j                  S )zoValue in EMU of the ``w`` attribute of the ``<w:pgSz>`` child element.

        |None| if not present.
        N)r^   rI   r   s     r+   
page_widthzCT_SectPr.page_width?  r   r-   c                2    | j                         }||_        y rn   )rQ   rI   r   s      r+   r   zCT_SectPr.page_widthJ  r   r-   c                N    | j                  d      }t        |      dkD  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(   r   )r*   preceding_sectPrss     r+   preceding_sectPrzCT_SectPr.preceding_sectPrO  s2     !JJ'AB'*+<'='A #KtKr-   c                |    | j                  |      }|t        d      |j                  }| j                  |       |S )zCReturn rId of w:footerReference child of `type_` after removing it.z!CT_SectPr has no footer reference)r~   
ValueErrorr<   remove)r*   r:   rd   r<   s       r+   remove_footerReferencez CT_SectPr.remove_footerReferenceV  @    2259"@AA!!O$
r-   c                |    | j                  |      }|t        d      |j                  }| j                  |       |S )zCReturn rId of w:headerReference child of `type_` after removing it.z!CT_SectPr has no header reference)r   r   r<   r   )r*   r:   rh   r<   s       r+   remove_headerReferencez CT_SectPr.remove_headerReference`  r   r-   c                8    | j                   }|y|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)r`   rA   rk   s     r+   right_marginzCT_SectPr.right_marginj  s    
 

={{r-   c                2    | j                         }||_        y rn   )rP   rA   rp   s      r+   r   zCT_SectPr.right_margint  s    %%'r-   c                n    | 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  s0    
 yy<488+#,,,xxr-   c                |    ||t         j                  u r| j                          y | j                         }||_        y rn   )r   r   rW   rS   r   )r*   rq   r\   s      r+   r   zCT_SectPr.start_type  s9    =E%5%>%>>##%r-   c                8    | j                   }|y|j                  S )zEValue of `w:titlePg/@val` or |False| if `./w:titlePg` is not present.F)rb   r   )r*   rb   s     r+   titlePg_valzCT_SectPr.titlePg_val  s     ,,?{{r-   c                X    |dv r| j                          y d| j                         _        y )N)NFT)rV   rR   r   )r*   rq   s     r+   r   zCT_SectPr.titlePg_val  s'    M!  ",0D##%)r-   c                8    | j                   }|y|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)r`   r@   rk   s     r+   
top_marginzCT_SectPr.top_margin  s    
 

=yyr-   c                2    | j                         }||_        y rn   )rP   r@   rp   s      r+   r   zCT_SectPr.top_margin  s    %%'	r-   )r:   r   r<   r;   r.   r8   )r.   r?   )rq   zint | Length | None)r.   rO   )r:   r   r.   zCT_HdrFtrRef | None)r.   zIterator[CT_P | CT_Tbl])r.   r   )rq   zWD_ORIENTATION | None)rq   r?   )r.   zCT_SectPr | None)r:   r   r.   r;   )r:   r   )r.   r   )rq   WD_SECTION_START | None)r.   bool)rq   zbool | None)%r/   r0   r1   r2   r3   _tag_seqr   rh   rd   r   r\   r^   r`   rb   re   ri   r6   rl   setterrw   rE   r~   r   rF   rD   r   r   r   r   r   r   r   r   r   r   r   r   r$   r-   r+   rO   rO   d   sC   K..,,....4444''$$H, !!4JO !4JO(Xab\ D
  'Xab\D
   )hqrl E   ) G_  	   ^ ^ 
 
 ]]^ ^#,   ]]^ ^ 	 	 ]]^ ^H   \ \ 	 	 B B         L L           1 1    r-   rO   c                  .    e Zd ZU dZ ede      Zded<   y)CT_SectTypez:``<w:sectType>`` element, defining the section start type.zw:valr   r   N)r/   r0   r1   r2   r   r   r   r3   r$   r-   r+   r   r     s    D#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y)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_xpathc                    || _         y rn   )_sectPr)r*   sectPrs     r+   __init__z"_SectBlockElementIterator.__init__  s	    r-   c                .     | |      j                         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     6{4466r-   c              #     K   | j                   | j                  }}|j                  |      }|dk(  rdn| j                  ||dz
           }| j	                  |      |d D ]  }|  yw)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  sz      ,,]]6*

 Q ;;GJQRN<ST 	 88@Q 	GM	s   A&A(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.F
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  sQ    &&.*/++77 +D'
 ++H\*E&M::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  sH     :9J !!#$A&6%7.!#3"4	6	
r-   c                    | j                   /t        j                  d| j                   dt        d      | _         | j                   }t        t        t         ||                  S )r   zcount()Fr   )r   r
   r   r   r   intr	   floatr   s      r+   r   z?_SectBlockElementIterator._count_of_blocks_in_and_above_section  s[    %%-).@@AC *D&
 **4uV}-..r-   c                8    | j                   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   rO   )r   rO   r.   Iterator[BlockElement])r.   r   )r   rO   r.   zSequence[BlockElement])r.   r;   )r   rO   r.   r   )r.   zSequence[CT_SectPr])r/   r0   r1   r2   r   r3   r   r   classmethodr   r   r   r   r   r   r   r$   r-   r+   r   r     sq    
 26.504-4 7 74
; 
 
6
/ 
 
r-   r   N)1r2   
__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   r3   r   r8   r>   rH   rO   r   r   r$   r-   r+   <module>r      s    - "  ; ;  ' P P  % S S " )  -)i )- -,4? 4 4 C CL
/ d
 d
r-   