
    ,h`                    <   d Z ddlmZ ddlmZmZmZ ddl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 dd	lmZmZmZmZmZ dd
lmZ ddlmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z' erddlm(Z( ddl)m*Z* ddlm+Z+m,Z, ddl-m.Z.  G d de      Z/ G d de      Z0 G d de      Z1 G d de      Z2 G d de      Z3 G d de      Z4 G d de      Z5 G d d e      Z6 G d! d"e      Z7 G d# d$e      Z8 G d% d&e      Z9 G d' d(e      Z: G d) d*e      Z; G d+ d,e      Z<y-).z"Custom element classes for tables.    )annotations)TYPE_CHECKINGCallablecast)WD_CELL_VERTICAL_ALIGNMENTWD_ROW_HEIGHT_RULEWD_TABLE_DIRECTION)InvalidSpanError)nsdeclsqn)	parse_xml)CT_DecimalNumber)ST_MergeST_TblLayoutTypeST_TblWidthST_TwipsMeasureXsdInt)CT_P)BaseOxmlElementOneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOne)EmuLengthTwips)WD_TABLE_ALIGNMENT)WD_ALIGN_PARAGRAPH)CT_OnOff	CT_String)CT_Jcc                  J    e Zd ZU dZ ede      Zded<    ede      Z	ded<   y)		CT_HeightzBUsed for `w:trHeight` to specify a row height and row height rule.w:valLength | Nonevalzw:hRuleWD_ROW_HEIGHT_RULE | NonehRuleN)
__name__
__module____qualname____doc__r   r   r(   __annotations__r   r*        Q/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/oxml/table.pyr%   r%   &   s5    L*C  (9%(E$ r1   r%   c                  @   e Zd ZU dZded<   ded<   ded<   ded<    ed	      Zd
ed<    ed      Zded<    ed      Z	e
dd       Ze
dd       ZddZe
dd       Ze
dd       Zej                   dd       Ze
d        Zej                   d d       Zd!dZd"dZd Zy)#CT_Rowz``<w:tr>`` element.zCallable[[], CT_Tc]add_tczCallable[[], CT_TrPr]get_or_add_trPr	_add_trPrzlist[CT_Tc]tc_lstz	w:tblPrExzCT_TblPrEx | NonetblPrExzw:trPrzCT_TrPr | NonetrPrzw:tcc                8    | j                   }|y|j                  S zCThe number of unpopulated layout-grid cells at the end of this row.r   )r:   
grid_afterselfr:   s     r2   r=   zCT_Row.grid_after?   s     yy<r1   c                8    | j                   }|y|j                  S zEThe number of unpopulated layout-grid cells at the start of this row.r   )r:   grid_beforer>   s     r2   rB   zCT_Row.grid_beforeG   s!     yy<r1   c                    || j                   z
  }| j                  D ]!  }|dk  r n|dk(  r|c S ||j                  z  }# t        d|       )zThe `tc` element in this tr at exact `grid offset`.

        Raises ValueError when this `w:tr` contains no `w:tc` with exact starting `grid_offset`.
        r   zno `tc` element at grid_offset=)rB   r8   	grid_span
ValueError)r?   grid_offsetremaining_offsettcs       r2   tc_at_grid_offsetzCT_Row.tc_at_grid_offsetO   sf     ')9)99++ 		-B!#1$	 ,		- :;-HIIr1   c                t    t        t        | j                               }|j                  j	                  |       S )z?Index of this `w:tr` element within its parent `w:tbl` element.)r   CT_Tbl	getparenttr_lstindex)r?   tbls     r2   tr_idxzCT_Row.tr_idxd   s,     64>>+,zz%%r1   c                8    | j                   }|y|j                  S )zFThe value of `./w:trPr/w:trHeight/@w:hRule`, or |None| if not present.N)r:   trHeight_hRuler>   s     r2   rR   zCT_Row.trHeight_hRulej   s!     yy<"""r1   c                2    | j                         }||_        y N)r6   rR   r?   valuer:   s      r2   rR   zCT_Row.trHeight_hRuler   s    ##%#r1   c                8    | j                   }|y|j                  S )zHReturn the value of `w:trPr/w:trHeight@w:val`, or |None| if not present.N)r:   trHeight_valr>   s     r2   rX   zCT_Row.trHeight_valw   s!     yy<   r1   c                2    | j                         }||_        y rT   )r6   rX   rU   s      r2   rX   zCT_Row.trHeight_val   s    ##%!r1   c                (    | j                  d|       y Nr   insert)r?   r9   s     r2   _insert_tblPrExzCT_Row._insert_tblPrEx   s    Awr1   c                h    | j                   }||j                  |       y | j                  d|       y r[   )r9   addnextr]   )r?   r:   r9   s      r2   _insert_trPrzCT_Row._insert_trPr   s+    ,,OOD!KK4 r1   c                *    t         j                         S rT   )CT_Tcnewr?   s    r2   _new_tczCT_Row._new_tc   s    yy{r1   Nreturnint)rF   ri   rh   rc   rh   r)   rV   r)   rV   r'   )r9   
CT_TblPrEx)r:   CT_TrPr)r+   r,   r-   r.   r/   r   r9   r:   r   rH   propertyr=   rB   rI   rP   rR   setterrX   r^   ra   rf   r0   r1   r2   r4   r4   1   s    **$$!*;!7G7$X.D..	F	B     J* & &
 # # $ $ ! ! " " !r1   r4   c                  J   e Zd ZU dZded<   ded<    ed      Zded<    ed	      Zd
ed<    ed      Z	e
dd       Zej                  dd       Ze
d        Zd Zedd       Ze
dd       Zej                  dd       Zedd       Zedd       Zed d       Zedd       Zy)!rK   z``<w:tbl>`` element.zCallable[[], CT_Row]add_trzlist[CT_Row]rM   zw:tblPrCT_TblPrtblPrz	w:tblGrid
CT_TblGridtblGridzw:trc                L    | j                   j                  }|y|j                  S )zValue of `./w:tblPr/w:bidiVisual/@w:val` or |None| if not present.

        Controls whether table cells are displayed right-to-left or left-to-right.
        N)rt   
bidiVisualr(   )r?   rx   s     r2   bidiVisual_valzCT_Tbl.bidiVisual_val   s&     ZZ**
~~r1   c                ~    | j                   }||j                          y t        |      |j                         _        y rT   )rt   _remove_bidiVisualboolget_or_add_bidiVisualr(   )r?   rV   rt   s      r2   ry   zCT_Tbl.bidiVisual_val   s1    

=$$&04UE'')-r1   c                @    t        | j                  j                        S )z)The number of grid columns in this table.)lenrv   gridCol_lstre   s    r2   	col_countzCT_Tbl.col_count   s     4<<++,,r1   c              #  X   K   | j                   D ]  }|j                  D ]  }|   yw)zGenerate each of the `w:tc` elements in this table, left to right and top to
        bottom.

        Each cell in the first row is generated, followed by each cell in the second
        row, etc.
        N)rM   r8   )r?   trrH   s      r2   iter_tcszCT_Tbl.iter_tcs   s3      ++ 	Bii 	s   (*c           
     V    t        t        t        | j                  |||                  S )zReturn a new `w:tbl` element having `rows` rows and `cols` columns.

        `width` is distributed evenly between the columns.
        )r   rK   r   _tbl_xml)clsrowscolswidths       r2   new_tblzCT_Tbl.new_tbl   s#     FIcll4u&EFGGr1   c                L    | j                   j                  }|y|j                  S )zH`w:tblPr/w:tblStyle/@w:val` (a table style id) or |None| if not present.N)rt   tblStyler(   r?   r   s     r2   tblStyle_valzCT_Tbl.tblStyle_val   s&     ::&&||r1   c                l    | j                   }|j                          |y||j                         _        y)zSet the value of `w:tblPr/w:tblStyle/@w:val` (a table style id) to `styleId`.

        If `styleId` is None, remove the `w:tblStyle` element.
        N)rt   _remove_tblStyle_add_tblStyler(   )r?   styleIdrt   s      r2   r   zCT_Tbl.tblStyle_val   s2     

 ?$+!r1   c           	         |dkD  rt        ||z        n
t        d      }dt        d       d| j                  ||       | j                  |||       dS )Nr   z<w:tbl wz>
  <w:tblPr>
    <w:tblW w:type="auto" w:w="0"/>
    <w:tblLook w:firstColumn="1" w:firstRow="1"
               w:lastColumn="0" w:lastRow="0" w:noHBand="0"
               w:noVBand="1" w:val="04A0"/>
  </w:tblPr>
z	</w:tbl>
)r   r   _tblGrid_xml_trs_xml)r   r   r   r   	col_widths        r2   r   zCT_Tbl._tbl_xml   sa    *.(C&A	gcl^ $ i01||D$	23		
r1   c                X    d}t        |      D ]  }|d|j                  z  z  } |dz  }|S )Nz  <w:tblGrid>
z    <w:gridCol w:w="%d"/>
z  </w:tblGrid>
)rangetwips)r   r   r   xml_s        r2   r   zCT_Tbl._tblGrid_xml   sA    y! 	CA09??BBC	C!!
r1   c                4    d| j                  ||       d|z  S )Nz	  <w:tr>
z
  </w:tr>
)_tcs_xml)r   	row_countr   r   s       r2   r   zCT_Tbl._trs_xml   s"    CLLI>?{KiWWr1   c                (    d|j                    d|z  S )Nz;    <w:tc>
      <w:tcPr>
        <w:tcW w:type="dxa" w:w="z-"/>
      </w:tcPr>
      <w:p/>
    </w:tc>
)r   )r   r   r   s      r2   r   zCT_Tbl._tcs_xml   s+    009/@ A  	r1   N)rh   zbool | None)rV   zWD_TABLE_DIRECTION | None)r   ri   r   ri   r   r   rh   rK   rh   
str | None)r   r   rh   None)r   ri   r   ri   r   r   rh   str)r   ri   r   r   rh   r   )r   ri   r   ri   r   r   rh   r   )r+   r,   r-   r.   r/   r   rt   rv   r   r   ro   ry   rp   r   r   classmethodr   r   r   r   r   r   r0   r1   r2   rK   rK      s     #I.E8.'4GZ4	F	B  < < - -	 H H   	, 	, 
 
   X X  r1   rK   c                  :    e Zd ZU dZded<   ded<    edd      Zy	)
ru   zq`w:tblGrid` element.

    Child of `w:tbl`, holds `w:gridCol> elements that define column count, width, etc.
    zCallable[[], CT_TblGridCol]add_gridColzlist[CT_TblGridCol]r   z	w:gridCol)zw:tblGridChange
successorsN)r+   r,   r-   r.   r/   r   gridColr0   r1   r2   ru   ru     s"    
 -,$$1EFGr1   ru   c                  @    e Zd ZU dZ ede      Zded<   edd       Z	y)CT_TblGridColzB`w:gridCol` element, child of `w:tblGrid`, defines a table column.w:wr'   r   c                t    t        t        | j                               }|j                  j	                  |       S )zHIndex of this `w:gridCol` element within its parent `w:tblGrid` element.)r   ru   rL   r   rN   )r?   rv   s     r2   gridCol_idxzCT_TblGridCol.gridCol_idx  s.     z4>>#34""((..r1   Nrg   )
r+   r,   r-   r.   r   r   r   r/   ro   r   r0   r1   r2   r   r     s/    L(A}  / /r1   r   c                  .    e Zd ZU dZ ede      Zded<   y)CT_TblLayoutTypez`w:tblLayout` element.

    Specifies whether column widths are fixed or can be automatically adjusted based on
    content.
    w:typer   typeN)r+   r,   r-   r.   r   r   r   r/   r0   r1   r2   r   r     s      )"D* r1   r   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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 <   [ed'd!       Zej                  d(d"       Zed)d#       Zej                  d*d$       Zed%        Zej                  d+d&       Zy),rs   z}``<w:tblPr>`` element, child of ``<w:tbl>``, holds child elements that define
    table properties such as style and borders.zCallable[[], CT_OnOff]r}   zCallable[[], CT_Jc]get_or_add_jczCallable[[], CT_TblLayoutType]get_or_add_tblLayoutzCallable[[], CT_String]r   Callable[[], None]r{   
_remove_jcr   )
w:tblStylezw:tblpPrzw:tblOverlapw:bidiVisualzw:tblStyleRowBandSizezw:tblStyleColBandSizezw:tblWw:jcw:tblCellSpacingzw:tblIndzw:tblBordersw:shdw:tblLayoutzw:tblCellMarz	w:tblLookzw:tblCaptionzw:tblDescriptionzw:tblPrChanger      Nr   zCT_String | Noner   r      zCT_OnOff | Nonerx   r      zCT_Jc | Nonejcr      zCT_TblLayoutType | None	tblLayoutc                L    | j                   }|yt        d|j                        S )zAHorizontal alignment of table, |None| if `./w:jc` is not present.NWD_TABLE_ALIGNMENT | None)r   r   r(   )r?   r   s     r2   	alignmentzCT_TblPr.alignmentW  s'     WW:/88r1   c                l    | j                          |y | j                         }t        d|      |_        y )Nr    )r   r   r   r(   )r?   rV   r   s      r2   r   zCT_TblPr.alignment_  s1    =!*E2r1   c                @    | j                   }|dS |j                  dk7  S )zg|False| when there is a `w:tblLayout` child with `@w:type="fixed"`.

        Otherwise |True|.
        Tfixed)r   r   )r?   r   s     r2   autofitzCT_TblPr.autofitg  s&     NN	 (tGinn.GGr1   c                F    | j                         }|rd|_        y d|_        y )Nr   r   )r   r   )r?   rV   r   s      r2   r   zCT_TblPr.autofitp  s    --/	&+		r1   c                8    | j                   }|y|j                  S )ziReturn the value of the ``val`` attribute of the ``<w:tblStyle>`` child or
        |None| if not present.N)r   r(   r   s     r2   stylezCT_TblPr.styleu  s      ==||r1   c                T    | j                          |y || j                         _        y rT   )r   r   r(   r?   rV   s     r2   r   zCT_TblPr.style~  s'    =#( r1   )rh   r   )rV   r   rh   r|   )rV   r|   rV   r   )r+   r,   r-   r.   r/   _tag_seqr   r   rx   r   r   ro   r   rp   r   r   r0   r1   r2   rs   rs   )  s?   3 21&&88****""((H( "+!""H  #,8AB<#J  !8AB<B  *3(23-*I&  	9 9 3 3 H H ^^9 9   \\) )r1   rs   c                      e Zd ZdZy)rm   z`w:tblPrEx` element, exceptions to table-properties.

    Applied at a lower level, like a `w:tr` to modify the appearance. Possibly used when
    two tables are merged. For more see:
    http://officeopenxml.com/WPtablePropertyExceptions.php
    N)r+   r,   r-   r.   r0   r1   r2   rm   rm     s    r1   rm   c                  x    e Zd ZU dZ ede      Zded<    ede      Z	e
d	d       Zej                  d
d       Zy)CT_TblWidthzJUsed for `w:tblW` and `w:tcW` and others, specifies a table-related width.r   ri   r   r   c                L    | j                   dk7  ryt        | j                        S )z>EMU length indicated by the combined `w:w` and `w:type` attrs.dxaN)r   r   r   re   s    r2   r   zCT_TblWidth.width  s!     99TVV}r1   c                F    d| _         t        |      j                  | _        y )Nr   )r   r   r   r   r   s     r2   r   zCT_TblWidth.width  s    	U!!r1   Nrh   r'   rV   r   )r+   r,   r-   r.   r   r   r   r/   r   r   ro   r   rp   r0   r1   r2   r   r     sN    T
 uf-As-X{3D  \\" "r1   r   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<    ed      Zded<    ed      Z ed      Z	e
d6d       Zd Ze
d6d       Ze
d6d       Zej                  d7d       Ze
d8d       Zd Ze
d6d       Zd9dZed:d       Ze
d6d       Ze
d6d       Ze
d;d       Zej                  d<d       Ze
d=d        Zej                  d>d!       Zd?d"Zd@dAd$ZdBd%Ze
dCd&       Zd?d'ZdDd(Ze
dEd)       Z d* Z!d+ Z"dFd,Z#dGd-Z$dHd.Z%e
dId/       Z&e
d:d0       Z'e
dEd1       Z(e
dJd2       Z)e
dJd3       Z*e
dKd4       Z+e
d6d5       Z,y#)Lrc   z`w:tc` table cell element.zCallable[[], CT_P]add_pzCallable[[], CT_TcPr]get_or_add_tcPrz
list[CT_P]p_lstzlist[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl]_insert_tbl_new_pzw:tcPrzCT_TcPr | NonetcPrw:pw:tblc                    | j                   7| j                  }|)|j                   t        j                  k(  r|j                  S | j
                  dz   S )zThe row index that marks the bottom extent of the vertical span of this cell.

        This is one greater than the index of the bottom-most row of the span, similar
        to how a slice of the cell's rows would be specified.
        r   )vMerge	_tc_belowr   CONTINUEbottom_tr_idx)r?   tc_belows     r2   r   zCT_Tc.bottom  sG     ;;"~~H#8;L;L(L&||ar1   c                R    | j                  d      D ]  }| j                  |        y)a/  Remove all content elements, preserving `w:tcPr` element if present.

        Note that this leaves the `w:tc` element in an invalid state because it doesn't
        contain at least one block-level element. It's up to the caller to add a
        `w:p`child element as the last content element.
        z./*[not(self::w:tcPr)]N)xpathremove)r?   es     r2   clear_contentzCT_Tc.clear_content  s(     45 	AKKN	r1   c                z    | j                   j                  }t        d | j                  d      D              }||z   S )zStarting offset of `tc` in the layout-grid columns of its table.

        A cell in the leftmost grid-column has offset 0.
        c              3  4   K   | ]  }|j                     y wrT   )rD   ).0rH   s     r2   	<genexpr>z$CT_Tc.grid_offset.<locals>.<genexpr>  s      &
BLL&
s   z./preceding-sibling::w:tc)_trrB   sumr   )r?   rB   preceding_tc_grid_spanss      r2   rF   zCT_Tc.grid_offset  sC     hh**"% &
#'::.I#J&
 #
 444r1   c                :    | j                   }|dS |j                  S )zzThe integer number of columns this cell spans.

        Determined by ./w:tcPr/w:gridSpan/@val, it defaults to 1.
        r   )r   rD   r?   r   s     r2   rD   zCT_Tc.grid_span  s      yyLq4dnn4r1   c                2    | j                         }||_        y rT   )r   rD   r?   rV   r   s      r2   rD   zCT_Tc.grid_span  s    ##%r1   c                $    | j                  d      S )zGenerate all `w:p` and `w:tbl` elements in this document-body.

        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r   re   s    r2   inner_content_elementszCT_Tc.inner_content_elements  s     zz+,,r1   c              #     K   t        d      t        d      t        d      f}| D ]  }|j                  |v s|  yw)zpGenerate a reference to each of the block-level content elements in this
        cell, in the order they appear.r   r   zw:sdtN)r   tag)r?   block_item_tagschilds      r2   iter_block_itemszCT_Tc.iter_block_items  s@      e9bk2g;? 	EyyO+	s   4>>c                    | j                   S )z?The grid column index at which this ``<w:tc>`` element appears.)rF   re   s    r2   leftz
CT_Tc.left  s     r1   c                    | j                  |      \  }}}}| j                  j                  |   j                  |      }|j	                  ||       |S )zReturn top-left `w:tc` element of a new span.

        Span is formed by merging the rectangular region defined by using this tc
        element and `other_tc` as diagonal corners.
        )_span_dimensions_tblrM   rI   _grow_to)r?   other_tctopr  heightr   top_tcs          r2   mergezCT_Tc.merge  sO     $(#8#8#B T65!!#&88>v&r1   c           	     L    t        t        t        dt        d      z              S )zUA new `w:tc` element, containing an empty paragraph as the required EG_BlockLevelElt.z<w:tc %s>
  <w:p/>
</w:tc>r   )r   rc   r   r   )r   s    r2   rd   z	CT_Tc.new  s!     E9%IGTWL%XYZZr1   c                4    | j                   | j                  z   S )a  The grid column index that marks the right-side extent of the horizontal span
        of this cell.

        This is one greater than the index of the right-most column of the span, similar
        to how a slice of the cell's columns would be specified.
        )rF   rD   re   s    r2   rightzCT_Tc.right  s     $..00r1   c                    | j                   | j                   t        j                  k(  r| j                  S | j                  j
                  S )z9The top-most row index in the vertical span of this cell.)r   r   RESTARTr   	_tc_abover  re   s    r2   r  z	CT_Tc.top  s9     ;;$++1A1A"A<<~~!!!r1   c                8    | j                   }|y|j                  S )zCValue of ./w:tcPr/w:vMerge/@val, |None| if w:vMerge is not present.N)r   
vMerge_valr   s     r2   r   zCT_Tc.vMerge  s     yy<r1   c                2    | j                         }||_        y rT   )r   r  r   s      r2   r   zCT_Tc.vMerge%  s    ##%r1   c                8    | j                   }|y|j                  S )zDEMU length represented in `./w:tcPr/w:tcW` or |None| if not present.N)r   r   r   s     r2   r   zCT_Tc.width*  s     yy<zzr1   c                2    | j                         }||_        y rT   )r   r   r   s      r2   r   zCT_Tc.width2  s    ##%
r1   c                    | j                   r5|j                   r(t        | j                   |j                   z         | _         yyy)zAdd the width of `other_tc` to this cell.

        Does nothing if either this tc or `other_tc` does not have a specified width.
        N)r   r   )r?   r  s     r2   _add_width_ofzCT_Tc._add_width_of7  s1    
 ::(..

X^^ ;<DJ ):r1   Nc                     d fd}| n|} j                  || ||             dkD  r' j                  }|J |j                  |dz
  |       yy)zGrow this cell to `width` grid columns and `height` rows.

        This is accomplished by expanding horizontal spans and creating continuation
        cells to form vertical spans.
        c                Z    | urt         j                  S dk(  rd S t         j                  S Nr   )r   r   r  )r  r  r?   s    r2   r  z"CT_Tc._grow_to.<locals>.vMerge_valF  s=     % !! $q[T /7.>.>r1   Nr   )r  rc   )_span_to_widthr   r  )r?   r   r  r  r  r   s   ` `   r2   r  zCT_Tc._grow_to?  s`    	  VE6:f+=>A:~~H''eVaZ8 r1   c                *    | j                  d|       |S )z#Override default `._insert_tcPr()`.r   r\   r   s     r2   _insert_tcPrzCT_Tc._insert_tcPrT  s     	Atr1   c                    t        | j                               }t        |      dkD  ry|d   }t        |t              rt        |j
                        dk(  ryy)z=True if this cell contains only a single empty `w:p` element.r   Fr   T)listr  r   
isinstancer   r_lst)r?   block_items	only_items      r2   	_is_emptyzCT_Tc._is_empty[  sR     40023{a  N	i&3y+?1+Dr1   c                    || u ry| j                   ry|j                          | j                         D ]  }|j                  |        | j                  | j	                                y)zxAppend the content of this cell to `other_tc`.

        Leaves this cell with a single empty ``<w:p>`` element.
        N)r*  _remove_trailing_empty_pr  appendr   )r?   r  block_elements      r2   _move_content_tozCT_Tc._move_content_toh  s]    
 t>>))+!224 	+MOOM*	+ 	DKKM"r1   c                    t        d      )NzDuse CT_Tbl.new_tbl() to add a new table, specifying rows and columns)NotImplementedErrorre   s    r2   _new_tblzCT_Tc._new_tblx  s    !R
 	
r1   c                6    | j                  d      }|r|d   S dS )zThe `w:tc` element immediately following this one in this row, or |None| if
        this is the last `w:tc` element in the row.z./following-sibling::w:tcr   Nr   )r?   following_tcss     r2   _next_tczCT_Tc._next_tc}  s%     

#>?#0}Q:d:r1   c                N    | j                         }|J |j                  |        y)z-Remove this `w:tc` element from the XML tree.N)rL   r   )r?   parent_elements     r2   _removezCT_Tc._remove  s%    )))d#r1   c                    t        | j                               }|d   }t        |t              sy|}t	        |j
                        dkD  ry| j                  |       y)zJRemove last content element from this cell if it's an empty `w:p` element.Nr   )r%  r  r&  r   r   r'  r   )r?   r(  last_content_elmps       r2   r,  zCT_Tc._remove_trailing_empty_p  sP    40023&r?*D1qww<!Ar1   c                N   dd}dd} || |        || |       t        | j                  |j                        }t        | j                  |j                        }t        | j                  |j                        }t        | j
                  |j
                        }||||z
  ||z
  fS )zReturn a (top, left, height, width) 4-tuple specifying the extents of the
        merged cell formed by using this tc and `other_tc` as opposite corner
        extents.c                    | j                   |j                   k(  r$| j                  |j                  k7  rt        d      | j                  |j                  k(  r%| j                  |j                  k7  rt        d      y y Nzrequested span not rectangularr  r   r
   r  r  )abs     r2   raise_on_inverted_Lz3CT_Tc._span_dimensions.<locals>.raise_on_inverted_L  s_    uu~!((ahh"6&'GHHvvAGGqww$6&'GHH %7r1   c                   | j                   |j                   k  r| |fn|| f\  }}|j                   |j                   k  r$|j                  |j                  kD  rt        d      | j                  |j                  k  r| |fn|| f\  }}|j                  |j                  k  r%|j                  |j                  kD  rt        d      y y r?  r@  )rA  rB  top_mostother	left_mosts        r2   raise_on_tee_shapedz3CT_Tc._span_dimensions.<locals>.raise_on_tee_shaped  s    ()q!fAq6OHe||eii'HOOell,J&'GHH)*!&&1vq!fIu~~

*y/L&'GHH 0M*r1   )rA  rc   rB  rc   )minr  r  maxr   r  )r?   r  rC  rH  r  r  r   r  s           r2   r	  zCT_Tc._span_dimensions  s    
	I	I 	D(+D(+$((HLL)499hmm,T[[(//2DJJ/D&3,44r1   c                    | j                  |       | j                  |k  r"| j                  ||       | j                  |k  r"|| _        y)a  Incorporate `w:tc` elements to the right until this cell spans `grid_width`.

        Incorporated `w:tc` elements are removed (replaced by gridSpan value).

        Raises |ValueError| if `grid_width` cannot be exactly achieved, such as when a
        merged cell would drive the span width greater than `grid_width` or if not
        enough grid columns are available to make this cell that wide. All content from
        incorporated cells is appended to `top_tc`. The val attribute of the vMerge
        element on the single remaining cell is set to `vMerge`. If `vMerge` is |None|,
        the vMerge element is removed if present.
        N)r/  rD   _swallow_next_tcr   )r?   
grid_widthr  r   s       r2   r!  zCT_Tc._span_to_width  sC     	f%nnz)!!*f5 nnz)r1   c                     d fd} j                   } ||       |J |j                  |        j                  |        xj                  |j                  z  c_        |j	                          y)a  Extend the horizontal span of this `w:tc` element to incorporate the
        following `w:tc` element in the row and then delete that following `w:tc`
        element.

        Any content in the following `w:tc` element is appended to the content of
        `top_tc`. The width of the following `w:tc` element is added to this one, if
        present. Raises |InvalidSpanError| if the width of the resulting cell is greater
        than `grid_width` or if there is no next `<w:tc>` element in the row.
        c                n    | t        d      j                  | j                  z   kD  rt        d      y )Nznot enough grid columnszspan is not rectangular)r
   rD   )next_tcrM  r?   s    r2   raise_on_invalid_swallowz8CT_Tc._swallow_next_tc.<locals>.raise_on_invalid_swallow  s<    &'@AA~~ 1 11J>&'@AA ?r1   N)rP  CT_Tc | None)r5  r/  r  rD   r8  )r?   rM  r  rQ  rP  s   ``   r2   rL  zCT_Tc._swallow_next_tc  s_    	B -- )""  (7#'+++r1   c                F    t        t        | j                  d      d         S )z+The tbl element this tc element appears in.z./ancestor::w:tbl[position()=1]r   )r   rK   r   re   s    r2   r
  z
CT_Tc._tbl  s      FDJJ'HI!LMMr1   c                L    | j                   j                  | j                        S )zAThe `w:tc` element immediately above this one in its grid column.)	_tr_aboverI   rF   re   s    r2   r  zCT_Tc._tc_above  s     ~~//0@0@AAr1   c                V    | j                   }|y|j                  | j                        S )z=The tc element immediately below this one in its grid column.N)	_tr_belowrI   rF   )r?   tr_belows     r2   r   zCT_Tc._tc_below  s-     >>))$*:*:;;r1   c                F    t        t        | j                  d      d         S )z*The tr element this tc element appears in.z./ancestor::w:tr[position()=1]r   )r   r4   r   re   s    r2   r   z	CT_Tc._tr  s      FDJJ'GHKLLr1   c                H    | j                  d      }|st        d      |d   S )zThe tr element prior in sequence to the tr this cell appears in.

        Raises |ValueError| if called on a cell in the top-most row.
        z9./ancestor::w:tr[position()=1]/preceding-sibling::w:tr[1]zno tr above topmost tr in w:tblr   )r   rE   )r?   	tr_abovess     r2   rU  zCT_Tc._tr_above  s,     JJZ[	>??|r1   c                    | j                   j                  }|j                  | j                        }	 ||dz      S # t        $ r Y yw xY w)zzThe tr element next in sequence after the tr this cell appears in, or |None|
        if this cell appears in the last row.r   N)r
  rM   rN   r   
IndexError)r?   rM   rP   s      r2   rW  zCT_Tc._tr_below  sK     !!dhh'	&1*%% 		s   ; 	AAc                `    | j                   j                  j                  | j                        S )z;The row index of the tr element this tc element appears in.)r
  rM   rN   r   re   s    r2   r   zCT_Tc._tr_idx
  s#     yy%%dhh//r1   rg   rV   ri   )rh   zlist[CT_P | CT_Tbl])r  rc   rh   rc   )rh   rc   r   r   r   r   )r  rc   rT   )r   ri   r  ri   r  rR  )r   CT_TcPrrh   r`  r   )rh   r   )rh   rR  )r  rc   rh   ztuple[int, int, int, int])rM  ri   r  rc   r   r   )rM  ri   r  rc   )rh   rK   )rh   r4   )rh   zCT_Row | None)-r+   r,   r-   r.   r/   r   r   r   r<  rO   ro   r   r   rF   rD   rp   r   r  r  r  r   rd   r  r  r   r   r  r  r#  r*  r/  r2  r5  r8  r,  r	  r!  rL  r
  r  r   r   rU  rW  r   r0   r1   r2   rc   rc     s[   $**++ %X.D..%A
G
C
  
 	 	5 	5 5 5   - -    	 [ [ 1 1 " "   ]]      \\ =9* 
 
# 

 ; ;$	5<"2 N N B B < < M M     0 0r1   rc   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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 <   [ed)d!       Zej                  d*d"       Zed#        Zej                  d+d$       Zed%        Zej                  d,d&       Zed-d'       Zej                  d.d(       Zy)/r`  z5``<w:tcPr>`` element, defining table cell properties.zCallable[[], CT_DecimalNumber]get_or_add_gridSpanzCallable[[], CT_TblWidth]get_or_add_tcWzCallable[[], CT_VerticalJc]get_or_add_vAlignzCallable[[], CT_VMerge]_add_vMerger   _remove_gridSpan_remove_vAlign_remove_vMerge)
w:cnfStylew:tcW
w:gridSpanzw:hMergew:vMergezw:tcBordersr   zw:noWrapzw:tcMarzw:textDirectionzw:tcFitTextw:vAlignz
w:hideMarkz	w:headersz	w:cellInsz	w:cellDelzw:cellMergezw:tcPrChangerj     Nr   zCT_TblWidth | NonetcWrk     CT_DecimalNumber | NonegridSpanrl     zCT_VMerge | Noner   rm     zCT_VerticalJc | NonevAlignc                :    | j                   }|dS |j                  S )zsThe integer number of columns this cell spans.

        Determined by ./w:gridSpan/@val, it defaults to 1.
        r   )rr  r(   )r?   rr  s     r2   rD   zCT_TcPr.grid_span=  s!     ==$q6(,,6r1   c                Z    | j                          |dkD  r|| j                         _        y y r   )rf  rb  r(   r   s     r2   rD   zCT_TcPr.grid_spanF  s+    19-2D$$&* r1   c                8    | j                   }|y|j                  S )zValue of `w:val` attribute on  `w:vAlign` child.

        Value is |None| if `w:vAlign` child is not present. The `w:val` attribute on
        `w:vAlign` is required.
        N)ru  r(   )r?   ru  s     r2   
vAlign_valzCT_TcPr.vAlign_valL  s     >zzr1   c                T    || j                          y || j                         _        y rT   )rg  rd  r(   r   s     r2   ry  zCT_TcPr.vAlign_valX  s'    =!', $r1   c                8    | j                   }|y|j                  S )zeThe value of the ./w:vMerge/@val attribute, or |None| if the w:vMerge element
        is not present.N)r   r(   )r?   r   s     r2   r  zCT_TcPr.vMerge_val_  s     >zzr1   c                T    | j                          ||| j                         _        y y rT   )rh  re  r(   r   s     r2   r  zCT_TcPr.vMerge_valh  s*    %*D" r1   c                8    | j                   }|y|j                  S )zJEMU length in `./w:tcW` or |None| if not present or its type is not 'dxa'.N)ro  r   )r?   ro  s     r2   r   zCT_TcPr.widthn  s     hh;yyr1   c                2    | j                         }||_        y rT   )rc  r   )r?   rV   ro  s      r2   r   zCT_TcPr.widthv  s    !!#	r1   rg   r_  )rV   z!WD_CELL_VERTICAL_ALIGNMENT | Noner   r   r   )r+   r,   r-   r.   r/   r   r   ro  rr  r   ru  ro   rD   rp   ry  r  r   r0   r1   r2   r`  r`    sk   ?77--22((((&&&&H( (HQRLC	  )2!")H%   )x| F  $-x}$F   	7 7 3 3
 	 	 - -   + +
   \\ r1   r`  c                      e Zd ZU dZded<   d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d       Ze
dd       Ze
dd       Zej                  dd       Ze
d        Zej                  dd       Zy)rn   z4``<w:trPr>`` element, defining table row properties.zCallable[[], CT_Height]get_or_add_trHeight)ri  zw:divIdw:gridBeforew:gridAfterz	w:wBeforezw:wAfterzw:cantSplit
w:trHeightzw:tblHeaderr   r   zw:hiddenzw:inszw:delzw:trPrChanger  r   Nr   rq  	gridAfterr  rp  
gridBeforer  r   zCT_Height | NonetrHeightc                :    | j                   }|dS |j                  S r<   )r  r(   )r?   r  s     r2   r=   zCT_TrPr.grid_after  s!     NN	%q89==8r1   c                :    | j                   }|dS |j                  S rA   )r  r(   )r?   r  s     r2   rB   zCT_TrPr.grid_before  s!     __
&q:JNN:r1   c                :    | j                   }|dS |j                  S )zCReturn the value of `w:trHeight@w:hRule`, or |None| if not present.N)r  r*   r?   r  s     r2   rR   zCT_TrPr.trHeight_hRule  s!     =='t;X^^;r1   c                P    || j                   y | j                         }||_        y rT   )r  r  r*   r?   rV   r  s      r2   rR   zCT_TrPr.trHeight_hRule  s(    =T]]2++-r1   c                :    | j                   }|dS |j                  S )zAReturn the value of `w:trHeight@w:val`, or |None| if not present.N)r  r(   r  s     r2   rX   zCT_TrPr.trHeight_val  s!     =='t9X\\9r1   c                P    || j                   y | j                         }||_        y rT   )r  r  r(   r  s      r2   rX   zCT_TrPr.trHeight_val  s(    =T]]2++-r1   rg   rj   rk   rl   )r+   r,   r-   r.   r/   r   r   r  r  r  ro   r=   rB   rR   rp   rX   r0   r1   r2   rn   rn   |  s    >00H" *3(12,*I&  +48AB<+J'  "+!""H  	9 9
 ; ;
 < <
   : :
  r1   rn   c                  .    e Zd ZU dZ ede      Zded<   y)CT_VerticalJcz:`w:vAlign` element, specifying vertical alignment of cell.r&   r   r(   N)r+   r,   r-   r.   r   r   r(   r/   r0   r1   r2   r  r    s    D&7+'C	# r1   r  c                  F    e Zd ZU dZ edeej                        Zded<   y)	CT_VMergezG``<w:vMerge>`` element, specifying vertical merging behavior of a cell.r&   )defaultr   r(   N)	r+   r,   r-   r.   r   r   r   r(   r/   r0   r1   r2   r  r    s#    Q'8#4#4C r1   r  N)=r.   
__future__r   typingr   r   r   docx.enum.tabler   r   r	   docx.exceptionsr
   docx.oxml.nsr   r   docx.oxml.parserr   docx.oxml.sharedr   docx.oxml.simpletypesr   r   r   r   r   docx.oxml.text.paragraphr   docx.oxml.xmlchemyr   r   r   r   r   r   r   docx.sharedr   r   r   r   docx.enum.textr    r!   r"   docx.oxml.text.parfmtr#   r%   r4   rK   ru   r   r   rs   rm   r   rc   r`  rn   r  r  r0   r1   r2   <module>r     s   ( " 0 0 ^ ^ , $ & -  *   + *214+ ^_ ^Bn_ nb	G 	G/O /	 	Z) Z)z "/ ",h0O h0Vio iXEo EPO  r1   