
    Pqh1l                       d Z ddlmZ ddlmZmZmZ ddl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mZmZmZ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! erddl"m#Z# ddlm$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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$e      Z0 G d% d&e      Z1y')(z"Custom element classes for tables.    )annotations)TYPE_CHECKINGCallableList)WD_CELL_VERTICAL_ALIGNMENTWD_ROW_HEIGHT_RULE)InvalidSpanError)nsdeclsqn)	parse_xml)ST_MergeST_TblLayoutTypeST_TblWidthST_TwipsMeasureXsdInt)BaseOxmlElementOneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOne)EmuTwips)CT_P)Lengthc                  4    e Zd ZdZ ede      Z ede      Zy)	CT_HeightzFUsed for ``<w:trHeight>`` to specify a row height and row height rule.w:valzw:hRuleN)	__name__
__module____qualname____doc__r   r   valr   hRule     P/srv/www/ollama/chat-ollama/venv/lib/python3.12/site-packages/docx/oxml/table.pyr   r   "   s    P
G_
5Ci);<Er'   r   c                      e Zd ZdZ ed      Z ed      Z ed      Zd Z	e
d        Ze
d        Zej                  d        Ze
d	        Zej                  d
        Zd Zd Zd Zy)CT_Rowz``<w:tr>`` element.z	w:tblPrExzw:trPrzw:tcc                    d}| j                   D ]-  }||k(  r|c S ||j                  z  }||kD  s!t        d|z         t        d      )zThe ``<w:tc>`` element appearing at grid column `idx`.

        Raises |ValueError| if no ``w:tc`` element begins at that grid column.
        r   zno cell on grid column %dzindex out of bounds)tc_lst	grid_span
ValueError)selfidxgrid_coltcs       r(   tc_at_grid_colzCT_Row.tc_at_grid_col0   s^    
 ++ 	DB3	$H#~ !<s!BCC	D .//r'   c                T    | j                         j                  j                  |       S )zSThe index of this ``<w:tr>`` element within its parent ``<w:tbl>``
        element.)	getparenttr_lstindexr/   s    r(   tr_idxzCT_Row.tr_idx>   s"     ~~&&,,T22r'   c                8    | j                   }|y|j                  S )zJReturn the value of `w:trPr/w:trHeight@w:hRule`, or |None| if not present.N)trPrtrHeight_hRuler/   r;   s     r(   r<   zCT_Row.trHeight_hRuleD   s!     yy<"""r'   c                2    | j                         }||_        y N)get_or_add_trPrr<   r/   valuer;   s      r(   r<   zCT_Row.trHeight_hRuleL   s    ##%#r'   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     r(   rD   zCT_Row.trHeight_valQ   s!     yy<   r'   c                2    | j                         }||_        y r?   )r@   rD   rA   s      r(   rD   zCT_Row.trHeight_valY   s    ##%!r'   c                (    | j                  d|       y Nr   insert)r/   tblPrExs     r(   _insert_tblPrExzCT_Row._insert_tblPrEx^   s    Awr'   c                h    | j                   }||j                  |       y | j                  d|       y rG   )rJ   addnextrI   )r/   r;   rJ   s      r(   _insert_trPrzCT_Row._insert_trPra   s+    ,,OOD!KK4 r'   c                *    t         j                         S r?   )CT_Tcnewr8   s    r(   _new_tczCT_Row._new_tch   s    yy{r'   N)r    r!   r"   r#   r   rJ   r;   r   r2   r3   propertyr9   r<   setterrD   rK   rN   rR   r&   r'   r(   r*   r*   )   s    $GXD	F	B0 3 3
 # # $ $ ! ! " " !r'   r*   c                     e Zd ZdZ ed      Z ed      Z ed      Ze	d        Z
e
j                  d        Z
e	d        Zd Zedd	       Ze	d
        Zej                  d        Zedd       Zed        Zed        Zed        Zy)CT_Tblz``<w:tbl>`` element.zw:tblPrz	w: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)tblPr
bidiVisualr$   )r/   rY   s     r(   bidiVisual_valzCT_Tbl.bidiVisual_vals   s&     ZZ**
~~r'   c                l    | j                   }||j                          y ||j                         _        y r?   )rX   _remove_bidiVisualget_or_add_bidiVisualr$   )r/   rB   rX   s      r(   rZ   zCT_Tbl.bidiVisual_val~   s-    

=$$&05E'')-r'   c                @    t        | j                  j                        S )z)The number of grid columns in this table.)lentblGridgridCol_lstr8   s    r(   	col_countzCT_Tbl.col_count   s     4<<++,,r'   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)r6   r,   )r/   trr2   s      r(   iter_tcszCT_Tbl.iter_tcs   s3      ++ 	Bii 	s   (*c                :    t        | j                  |||            S )zReturn a new `w:tbl` element having `rows` rows and `cols` columns.

        `width` is distributed evenly between the columns.
        )r   _tbl_xml)clsrowscolswidths       r(   new_tblzCT_Tbl.new_tbl   s     dD%899r'   c                L    | j                   j                  }|y|j                  S )zYValue of `w:tblPr/w:tblStyle/@w:val` (a table style id) or |None| if not
        present.N)rX   tblStyler$   r/   rn   s     r(   tblStyle_valzCT_Tbl.tblStyle_val   s&     ::&&||r'   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)rX   _remove_tblStyle_add_tblStyler$   )r/   styleIdrX   s      r(   rp   zCT_Tbl.tblStyle_val   s2     

 ?$+!r'   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)rh   ri   rj   rk   	col_widths        r(   rg   zCT_Tbl._tbl_xml   sO    )-C%s1v	 CLT9-LLtY/
 	
r'   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rh   rb   ry   xmlis        r(   rw   zCT_Tbl._tblGrid_xml   sA    y! 	CA09??BBC	C!!
r'   c                Z    d}t        |      D ]  }|d| j                  ||      z  z  } |S )N z  <w:tr>
%s  </w:tr>
)r|   _tcs_xml)rh   	row_countrb   ry   r   r   s         r(   rx   zCT_Tbl._trs_xml   sD    y! 	A3s||98  C	 
r'   c                N    d}t        |      D ]  }|d|j                  z  z  } |S )Nr   zj    <w:tc>
      <w:tcPr>
        <w:tcW w:type="dxa" w:w="%d"/>
      </w:tcPr>
      <w:p/>
    </w:tc>
r{   r~   s        r(   r   zCT_Tbl._tcs_xml   s?    y! 	 A     C	  
r'   N)ri   intrj   r   rk   r   returnrV   )ri   r   rj   r   rk   r   r   str)r    r!   r"   r#   r   rX   r`   r   rd   rS   rZ   rT   rb   re   classmethodrl   rp   rg   rw   rx   r   r&   r'   r(   rV   rV   l   s    )$EK(G	F	B  6 6 - -	 : :   	, 	, 
 
&      r'   rV   c                  $    e Zd ZdZ edd      Zy)
CT_TblGridzw``<w:tblGrid>`` element, child of ``<w:tbl>``, holds ``<w:gridCol>`` elements
    that define column count, width, etc.z	w:gridCol)zw:tblGridChange
successorsN)r    r!   r"   r#   r   gridColr&   r'   r(   r   r      s    - 1EFGr'   r   c                  2    e Zd ZdZ ede      Zed        Zy)CT_TblGridColzJ``<w:gridCol>`` element, child of ``<w:tblGrid>``, defines a table column.w:wc                T    | j                         j                  j                  |       S )z\The index of this ``<w:gridCol>`` element within its parent ``<w:tblGrid>``
        element.)r5   ra   r7   r8   s    r(   gridCol_idxzCT_TblGridCol.gridCol_idx   s"     ~~++11$77r'   N)	r    r!   r"   r#   r   r   rv   rS   r   r&   r'   r(   r   r      s#    T%1A8 8r'   r   c                  "    e Zd ZdZ ede      Zy)CT_TblLayoutTypez|``<w:tblLayout>`` element, specifying whether column widths are fixed or can be
    automatically adjusted based on content.w:typeN)r    r!   r"   r#   r   r   typer&   r'   r(   r   r      s    0 X'78Dr'   r   c                     e Zd ZdZdZ ededd       Z ededd       Z ed	ed
d       Z ededd       Z	[e
d        Zej                  d        Ze
dd       Zej                  dd       Ze
d        Zej                  d        Zy)CT_TblPrz}``<w:tblPr>`` element, child of ``<w:tbl>``, holds child elements that define
    table properties such as style and borders.)
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   r      r      r      c                8    | j                   }|y|j                  S )zMember of :ref:`WdRowAlignment` enumeration or |None|, based on the contents
        of the `w:val` attribute of `./w:jc`.

        |None| if no `w:jc` element is present.
        N)jcr$   )r/   r   s     r(   	alignmentzCT_TblPr.alignment  s     WW:vvr'   c                X    | j                          |y | j                         }||_        y r?   )
_remove_jcget_or_add_jcr$   )r/   rB   r   s      r(   r   zCT_TblPr.alignment+  s)    =!r'   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)	tblLayoutr   )r/   r   s     r(   autofitzCT_TblPr.autofit3  s&     NN	 (tGinn.GGr'   c                F    | j                         }|rd|_        y d|_        y )Nr   r   )get_or_add_tblLayoutr   )r/   rB   r   s      r(   r   zCT_TblPr.autofit<  s    --/	&+		r'   c                8    | j                   }|y|j                  S )ziReturn the value of the ``val`` attribute of the ``<w:tblStyle>`` child or
        |None| if not present.N)rn   r$   ro   s     r(   stylezCT_TblPr.styleA  s      ==||r'   c                N    | j                          |y | j                  |       y )N)r$   )rr   rs   r/   rB   s     r(   r   zCT_TblPr.styleJ  s'    =u%r'   )r   bool)rB   r   )r    r!   r"   r#   _tag_seqr   rn   rY   r   r   rS   r   rT   r   r   r&   r'   r(   r   r     s    3H( (12,?H>hqrlCJ	6hqrl	3B-HRSMBI	 	   H H ^^9 9   \\& &r'   r   c                  h    e Zd ZdZ ede      Z ede      Ze	d        Z
e
j                  d        Z
y)CT_TblWidthzeUsed for ``<w:tblW>`` and ``<w:tcW>`` elements and many others, to specify a
    table-related width.r   r   c                L    | j                   dk7  ryt        | j                        S )zbReturn the EMU length value represented by the combined ``w:w`` and
        ``w:type`` attributes.dxaN)r   r   rv   r8   s    r(   rk   zCT_TblWidth.width\  s!     99TVV}r'   c                F    d| _         t        |      j                  | _        y )Nr   )r   r   r}   rv   r   s     r(   rk   zCT_TblWidth.widthd  s    	U!!r'   N)r    r!   r"   r#   r   r   rv   r   r   rS   rk   rT   r&   r'   r(   r   r   R  sK     	%(AX{3D  \\" "r'   r   c                  X   e Zd ZU dZded<   ded<   ded<   ded	<    ed
      Z ed      Z ed      Z	e
d        Zd Ze
d        Zej                  d        Ze
d1d       Zd Ze
d        Zd Zed        Ze
d        Ze
d        Ze
d        Zej                  d        Ze
d        Zej                  d        Zd Ze
d        Zd2dZd  Ze
d!        Zd" Zd# Ze
d$        Z d% Z!d& Z"d' Z#d( Z$d) Z%e
d*        Z&e
d+        Z'e
d,        Z(e
d-        Z)e
d.        Z*e
d/        Z+e
d0        Z,y)3rP   z`w:tc` table cell element.zCallable[[], CT_P]add_pz
List[CT_P]p_lstzList[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl]_insert_tblzw: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     r(   r   zCT_Tc.bottomw  sG     ;;"~~H#8;L;L(L&||ar'   c                P    g }| j                   }||j                  |       || dd y)aM  Remove all content child elements, preserving the ``<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.
        N)tcPrappend)r/   new_childrenr   s      r(   clear_contentzCT_Tc.clear_content  s/     yy%Qr'   c                8    | j                   }|y|j                  S )zzThe integer number of columns this cell spans.

        Determined by ./w:tcPr/w:gridSpan/@val, it defaults to 1.
        r   )r   r-   r/   r   s     r(   r-   zCT_Tc.grid_span  s     yy<~~r'   c                2    | j                         }||_        y r?   )get_or_add_tcPrr-   r/   rB   r   s      r(   r-   zCT_Tc.grid_span  s    ##%r'   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xpathr8   s    r(   inner_content_elementszCT_Tc.inner_content_elements  s     zz+,,r'   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      r(   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.)	_grid_colr8   s    r(   leftz
CT_Tc.left  s     ~~r'   c                    | j                  |      \  }}}}| j                  j                  |   j                  |      }|j	                  ||       |S )zReturn the top-left ``<w:tc>`` element of a new span formed by merging the
        rectangular region defined by using this tc element and `other_tc` as diagonal
        corners.)_span_dimensions_tblr6   r3   _grow_to)r/   other_tctopr   heightrk   top_tcs          r(   mergezCT_Tc.merge  sO     $(#8#8#B T65!!#&55d;v&r'   c                0    t        dt        d      z        S )zhReturn a new ``<w:tc>`` element, containing an empty paragraph as the
        required EG_BlockLevelElt.z<w:tc %s>
  <w:p/>
</w:tc>rv   )r   r
   )rh   s    r(   rQ   z	CT_Tc.new  s     =LMMr'   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.
        )r   r-   r8   s    r(   rightzCT_Tc.right  s     ~~..r'   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   r8   s    r(   r   z	CT_Tc.top  s9     ;;$++1A1A"A<<~~!!!r'   c                8    | j                   }|y|j                  S )zlThe value of the ./w:tcPr/w:vMerge/@val attribute, or |None| if the w:vMerge
        element is not present.N)r   
vMerge_valr   s     r(   r   zCT_Tc.vMerge  s     yy<r'   c                2    | j                         }||_        y r?   )r   r   r   s      r(   r   zCT_Tc.vMerge  s    ##%r'   c                8    | j                   }|y|j                  S )zqReturn the EMU length value represented in the ``./w:tcPr/w:tcW`` child
        element or |None| if not present.N)r   rk   r   s     r(   rk   zCT_Tc.width  s     yy<zzr'   c                2    | j                         }||_        y r?   )r   rk   r   s      r(   rk   zCT_Tc.width  s    ##%
r'   c                v    | j                   r-|j                   r | xj                   |j                   z  c_         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)rk   )r/   r   s     r(   _add_width_ofzCT_Tc._add_width_of  s*    
 ::(..JJ(..(J ):r'   c                    | j                   }|j                  j                  |       }|j                  d| }t        d |D              S )z*The grid column at which this cell begins.Nc              3  4   K   | ]  }|j                     y wr?   )r-   ).0r2   s     r(   	<genexpr>z"CT_Tc._grid_col.<locals>.<genexpr>  s     8B2<<8s   )_trr,   r7   sum)r/   rd   r0   preceding_tcss       r(   r   zCT_Tc._grid_col  s?     XXiiood#		$38-888r'   Nc                      fd}| n|} j                  || ||             dkD  r! j                  j                  |dz
  |       yy)zGrow this cell to `width` grid columns and `height` rows by expanding
        horizontal spans and creating continuation cells to form vertical spans.c                X    | urt         j                  S dk(  ry t         j                  S Nr   )r   r   r   )r   r   r/   s    r(   r   z"CT_Tc._grow_to.<locals>.vMerge_val  s-    T!((({###r'   Nr   )_span_to_widthr   r   )r/   rk   r   r   r   s   ` `  r(   r   zCT_Tc._grow_to  sR    	$  VE6:f+=>A:NN##E6A:v> r'   c                *    | j                  d|       |S )z``tcPr`` has a bunch of successors, but it comes first if it appears, so just
        overriding and using insert(0, ...) rather than spelling out successors.r   rH   r   s     r(   _insert_tcPrzCT_Tc._insert_tcPr  s     	Atr'   c                    t        | j                               }t        |      dkD  ry|d   }t        |j                        dk(  ryy)zATrue if this cell contains only a single empty ``<w:p>`` element.r   Fr   T)listr   r_   r_lst)r/   block_itemsps      r(   	_is_emptyzCT_Tc._is_empty  sF     40023{aNqww<1r'   c                    || u ry| j                   ry|j                          | j                         D ]  }|j                  |        | j                  | j	                                y)zoAppend the content of this cell to `other_tc`, leaving this cell with a
        single empty ``<w:p>`` element.N)r  _remove_trailing_empty_pr   r   _new_p)r/   r   block_elements      r(   _move_content_tozCT_Tc._move_content_to%  s]     t>>))+!224 	+MOOM*	+ 	DKKM"r'   c                *    t         j                         S r?   )rV   rQ   r8   s    r(   _new_tblzCT_Tc._new_tbl3  s    zz|r'   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     r(   _next_tczCT_Tc._next_tc6  s%     

#>?#0}Q:d:r'   c                B    | j                         j                  |        y)z-Remove this `w:tc` element from the XML tree.N)r5   remover8   s    r(   _removezCT_Tc._remove=  s    %r'   c                    t        | j                               }|d   }|j                  t        d      k7  ry|}t	        |j
                        dkD  ry| j                  |       y)z[Remove the last content element from this cell if it is an empty ``<w:p>``
        element.r   Nr   )r  r   r   r   r_   r  r  )r/   r  last_content_elmr  s       r(   r	  zCT_Tc._remove_trailing_empty_pA  sY     40023&r?2e9,qww<!Ar'   c                J   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     r(   raise_on_inverted_Lz3CT_Tc._span_dimensions.<locals>.raise_on_inverted_LR  s_    uu~!((ahh"6&'GHHvvAGGqww$6&'GHH %7r'   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  )r  r  top_mostother	left_mosts        r(   raise_on_tee_shapedz3CT_Tc._span_dimensions.<locals>.raise_on_tee_shapedX  s    ()q!fAq6OHe||eii'HOOell,J&'GHH)*!&&1vq!fIu~~

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

        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  r-   _swallow_next_tcr   )r/   
grid_widthr   r   s       r(   r   zCT_Tc._span_to_widthk  sC     	f%nnz)!!*f5 nnz)r'   c                      fd} 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	   r-   )next_tcr(  r/   s    r(   raise_on_invalid_swallowz8CT_Tc._swallow_next_tc.<locals>.raise_on_invalid_swallow  s<    &'@AA~~ 1 11J>&'@AA ?r'   N)r  r  r   r-   r  )r/   r(  r   r,  r+  s   ``   r(   r'  zCT_Tc._swallow_next_tc{  sV    	B -- )  (7#'+++r'   c                *    | j                  d      d   S )z+The tbl element this tc element appears in.z./ancestor::w:tbl[position()=1]r   r   r8   s    r(   r   z
CT_Tc._tbl  s     zz;<Q??r'   c                L    | j                   j                  | j                        S )zAThe `w:tc` element immediately above this one in its grid column.)	_tr_abover3   r   r8   s    r(   r   zCT_Tc._tc_above  s     ~~,,T^^<<r'   c                V    | j                   }|y|j                  | j                        S )z=The tc element immediately below this one in its grid column.N)	_tr_belowr3   r   )r/   tr_belows     r(   r   zCT_Tc._tc_below  s+     >>&&t~~66r'   c                *    | j                  d      d   S )z*The tr element this tc element appears in.z./ancestor::w:tr[position()=1]r   r   r8   s    r(   r   z	CT_Tc._tr  s     zz:;A>>r'   c                    | j                   j                  }|j                  | j                        }|dk(  rt	        d      ||dz
     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.
        r   zno tr above topmost trr   )r   r6   r7   r   r.   r/   r6   r9   s      r(   r/  zCT_Tc._tr_above  sG     !!dhh'Q;566fqj!!r'   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   r6   r7   r   
IndexErrorr5  s      r(   r1  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   r6   r7   r   r8   s    r(   r   zCT_Tc._tr_idx  s#     yy%%dhh//r'   )r   zList[CT_P | CT_Tbl]r?   )-r    r!   r"   r#   __annotations__r   r   r   r  tblrS   r   r   r-   rT   r   r   r   r   r   rQ   r   r   r   rk   r   r   r   r  r  r  r  r  r  r	  r   r   r'  r   r   r   r   r/  r1  r   r&   r'   r(   rP   rP   j  sD   $++XD%A
G
C
  
      - -   N N
 / / " "   ]]      \\ ) 9 9?   # ; ;&
5< 0 @ @ = = 7 7 ? ? 	" 	"   0 0r'   rP   c                  N   e Zd ZdZdZ ededd       Z ededd       Z ed	ed
d       Z ededd       Z	[e
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Ze
d        Zej                  d        Zy)CT_TcPrz5``<w:tcPr>`` element, defining table cell properties.)
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:tcPrChanger>     Nr   r?     r@     rA     c                8    | j                   }|y|j                  S )zsThe integer number of columns this cell spans.

        Determined by ./w:gridSpan/@val, it defaults to 1.
        r   )gridSpanr$   )r/   rG  s     r(   r-   zCT_TcPr.grid_span  s      ==||r'   c                Z    | j                          |dkD  r|| j                         _        y y r   )_remove_gridSpanget_or_add_gridSpanr$   r   s     r(   r-   zCT_TcPr.grid_span  s+    19-2D$$&* r'   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)vAlignr$   )r/   rL  s     r(   
vAlign_valzCT_TcPr.vAlign_val  s     >zzr'   c                T    || j                          y || j                         _        y r?   )_remove_vAlignget_or_add_vAlignr$   r   s     r(   rM  zCT_TcPr.vAlign_val  s'    =!', $r'   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     r(   r   zCT_TcPr.vMerge_val  s     >zzr'   c                T    | j                          ||| j                         _        y y r?   )_remove_vMerge_add_vMerger$   r   s     r(   r   zCT_TcPr.vMerge_val  s*    %*D" r'   c                8    | j                   }|y|j                  S )zReturn the EMU length value represented in the ``<w:tcW>`` child element or
        |None| if not present or its type is not 'dxa'.N)tcWrk   )r/   rV  s     r(   rk   zCT_TcPr.width  s     hh;yyr'   c                2    | j                         }||_        y r?   )get_or_add_tcWrk   )r/   rB   rV  s      r(   rk   zCT_TcPr.width   s    !!#	r'   )r    r!   r"   r#   r   r   rV  rG  r   rL  rS   r-   rT   rM  r   rk   r&   r'   r(   r<  r<    s   ?H( G
5C(12,?Hzhqrl;Fzhrsm<F  3 3
 	 	 - -   + +
   \\ r'   r<  c                      e Zd ZdZdZ ededd       Z[ed        Zej                  d        Zed	        Z
e
j                  d
        Z
y)CT_TrPrz4``<w:trPr>`` element, defining table row properties.)r=  zw:divIdzw:gridBeforezw:gridAfterz	w:wBeforezw:wAfterzw:cantSplit
w:trHeightzw:tblHeaderr   r   zw:hiddenzw:inszw:delzw:trPrChanger[  r   Nr   c                8    | j                   }|y|j                  S )zCReturn the value of `w:trHeight@w:hRule`, or |None| if not present.N)trHeightr%   r/   r]  s     r(   r<   zCT_TrPr.trHeight_hRule=  s      ==~~r'   c                P    || j                   y | j                         }||_        y r?   )r]  get_or_add_trHeightr%   r/   rB   r]  s      r(   r<   zCT_TrPr.trHeight_hRuleE  s(    =T]]2++-r'   c                8    | j                   }|y|j                  S )zAReturn the value of `w:trHeight@w:val`, or |None| if not present.N)r]  r$   r^  s     r(   rD   zCT_TrPr.trHeight_valL  s      ==||r'   c                P    || j                   y | j                         }||_        y r?   )r]  r`  r$   ra  s      r(   rD   zCT_TrPr.trHeight_valT  s(    =T]]2++-r'   )r    r!   r"   r#   r   r   r]  rS   r<   rT   rD   r&   r'   r(   rZ  rZ  &  s}    >H" (12,?H       r'   rZ  c                  "    e Zd ZdZ ede      Zy)CT_VerticalJcz:`w:vAlign` element, specifying vertical alignment of cell.r   N)r    r!   r"   r#   r   r   r$   r&   r'   r(   re  re  \  s    D
G%?
@Cr'   re  c                  :    e Zd ZdZ edeej                        Zy)	CT_VMergezG``<w:vMerge>`` element, specifying vertical merging behavior of a cell.r   )defaultN)r    r!   r"   r#   r   r   r   r$   r&   r'   r(   rg  rg  b  s    Q
GXx7H7H
ICr'   rg  N)2r#   
__future__r   typingr   r   r   docx.enum.tabler   r   docx.exceptionsr	   docx.oxml.nsr
   r   docx.oxml.parserr   docx.oxml.simpletypesr   r   r   r   r   docx.oxml.xmlchemyr   r   r   r   r   r   r   docx.sharedr   r   docx.oxml.text.paragraphr   r   r   r*   rV   r   r   r   r   r   rP   r<  rZ  re  rg  r&   r'   r(   <module>rs     s    ( " 0 0 J , $ &    #-"= =@_ @Fx_ xvG G	8O 	89 9N& N&b"/ "0Z0O Z0z
\o \~3o 3lAO AJ Jr'   