
    h`                    F   S r SSKJr  SSKJrJrJr  SSKJrJ	r	J
r
  SSKJr  SSKJrJr  SSKJr  SSKJr  SS	KJrJrJrJrJr  SS
KJr  SSKJrJrJrJ r J!r!J"r"J#r#  SSK$J%r%J&r&J'r'  \(       a  SSKJ(r(  SSK)J*r*  SSKJ+r+J,r,  SSK-J.r.   " S S\5      r/ " S S\5      r0 " S S\5      r1 " S S\5      r2 " S S\5      r3 " S S\5      r4 " S S\5      r5 " S S \5      r6 " S! S"\5      r7 " S# S$\5      r8 " S% S&\5      r9 " S' S(\5      r: " S) S*\5      r; " S+ S,\5      r<g-).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                  R    \ rS rSr% Sr\" S\5      rS\S'   \" S\	5      r
S\S'   S	rg
)	CT_Height&   zBUsed for `w:trHeight` to specify a row height and row height rule.w:valLength | Nonevalzw:hRuleWD_ROW_HEIGHT_RULE | NonehRule N)__name__
__module____qualname____firstlineno____doc__r   r   r)   __annotations__r   r+   __static_attributes__r,       A/var/www/html/env/lib/python3.13/site-packages/docx/oxml/table.pyr%   r%   &   s5    L*C  (9%(E$ r4   r%   c                  Z   \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   \" S
5      rS\S'   \" S5      rS\S'   \	" S5      r
\SS j5       r\SS j5       rSS jr\SS j5       r\S S j5       r\R"                  S!S j5       r\S 5       r\R"                  S"S j5       rS#S jrS$S jrS rSrg)%CT_Row1   z``<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                :    U R                   nUc  gUR                  $ zCThe number of unpopulated layout-grid cells at the end of this row.r   )r>   
grid_afterselfr>   s     r5   rA   CT_Row.grid_after?   s     yy<r4   c                :    U R                   nUc  gUR                  $ zEThe number of unpopulated layout-grid cells at the start of this row.r   )r>   grid_beforerB   s     r5   rG   CT_Row.grid_beforeG   s!     yy<r4   c                    XR                   -
  nU R                   H#  nUS:  a    OUS:X  a  Us  $ X#R                  -  nM%     [        SU 35      e)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=)rG   r<   	grid_span
ValueError)rC   grid_offsetremaining_offsettcs       r5   tc_at_grid_offsetCT_Row.tc_at_grid_offsetO   s]     ')9)99++B!#1$	 ,  :;-HIIr4   c                t    [        [        U R                  5       5      nUR                  R	                  U 5      $ )z?Index of this `w:tr` element within its parent `w:tbl` element.)r   CT_Tbl	getparenttr_lstindex)rC   tbls     r5   tr_idxCT_Row.tr_idxd   s,     64>>+,zz%%r4   c                :    U R                   nUc  gUR                  $ )zFThe value of `./w:trPr/w:trHeight/@w:hRule`, or |None| if not present.N)r>   trHeight_hRulerB   s     r5   rZ   CT_Row.trHeight_hRulej   s!     yy<"""r4   c                0    U R                  5       nXl        g N)r:   rZ   rC   valuer>   s      r5   rZ   r[   r   s    ##%#r4   c                :    U R                   nUc  gUR                  $ )zHReturn the value of `w:trPr/w:trHeight@w:val`, or |None| if not present.N)r>   trHeight_valrB   s     r5   ra   CT_Row.trHeight_valw   s!     yy<   r4   c                0    U R                  5       nXl        g r]   )r:   ra   r^   s      r5   ra   rb      s    ##%!r4   c                (    U R                  SU5        g Nr   insert)rC   r=   s     r5   _insert_tblPrExCT_Row._insert_tblPrEx   s    Awr4   c                j    U R                   nUb  UR                  U5        g U R                  SU5        g re   )r=   addnextrg   )rC   r>   r=   s      r5   _insert_trPrCT_Row._insert_trPr   s+    ,,OOD!KK4 r4   c                *    [         R                  5       $ r]   )CT_TcnewrC   s    r5   _new_tcCT_Row._new_tc   s    yy{r4   r,   Nreturnint)rL   rv   ru   ro   ru   r*   r_   r*   r_   r(   )r=   
CT_TblPrEx)r>   CT_TrPr)r-   r.   r/   r0   r1   r2   r   r=   r>   r   rN   propertyrA   rG   rO   rW   rZ   setterra   rh   rl   rr   r3   r,   r4   r5   r7   r7   1   s    **$$!*;!7G7$X.D..	F	B     J* & &
 # # $ $ ! ! " " !r4   r7   c                  d   \ rS rSr% SrS\S'   S\S'   \" S5      rS\S	'   \" S
5      rS\S'   \	" S5      r
\SS j5       r\R                  SS j5       r\S 5       rS r\SS j5       r\SS j5       r\R                  SS j5       r\S S j5       r\S!S j5       r\S"S j5       r\S!S j5       rSrg)#rR      z``<w:tbl>`` element.zCallable[[], CT_Row]add_trzlist[CT_Row]rT   zw:tblPrCT_TblPrtblPrz	w:tblGrid
CT_TblGridtblGridzw:trc                N    U R                   R                  nUc  gUR                  $ )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)r   
bidiVisualr)   )rC   r   s     r5   bidiVisual_valCT_Tbl.bidiVisual_val   s&     ZZ**
~~r4   c                    U R                   nUc  UR                  5         g [        U5      UR                  5       l        g r]   )r   _remove_bidiVisualboolget_or_add_bidiVisualr)   )rC   r_   r   s      r5   r   r      s1    

=$$&04UE'')-r4   c                @    [        U R                  R                  5      $ )z)The number of grid columns in this table.)lenr   gridCol_lstrq   s    r5   	col_countCT_Tbl.col_count   s     4<<++,,r4   c              #  `   #    U R                    H  nUR                   H  nUv   M	     M     g7f)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)rT   r<   )rC   trrN   s      r5   iter_tcsCT_Tbl.iter_tcs   s(      ++Bii   s   ,.c           
     T    [        [        [        U R                  XU5      5      5      $ )zxReturn a new `w:tbl` element having `rows` rows and `cols` columns.

`width` is distributed evenly between the columns.
)r   rR   r   _tbl_xml)clsrowscolswidths       r5   new_tblCT_Tbl.new_tbl   s!     FIcll4u&EFGGr4   c                N    U R                   R                  nUc  gUR                  $ )zH`w:tblPr/w:tblStyle/@w:val` (a table style id) or |None| if not present.N)r   tblStyler)   rC   r   s     r5   tblStyle_valCT_Tbl.tblStyle_val   s&     ::&&||r4   c                l    U R                   nUR                  5         Uc  gXR                  5       l        g)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)r   _remove_tblStyle_add_tblStyler)   )rC   styleIdr   s      r5   r   r      s0     

 ?$+!r4   c           	         US:  a  [        X2-  5      O
[        S5      nS[        S5       SU R                  X$5       U R                  XU5       S3$ )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        r5   r   CT_Tbl._tbl_xml   s[    *.(C&A	gcl^ $ 01||D	23		
r4   c                \    Sn[        U5       H  nUSUR                  -  -  nM     US-  nU$ )Nz  <w:tblGrid>
z    <w:gridCol w:w="%d"/>
z  </w:tblGrid>
)rangetwips)r   r   r   xml_s        r5   r   CT_Tbl._tblGrid_xml   s:    y!A09??BBC "!!
r4   c                2    SU R                  X#5       S3U-  $ )Nz	  <w:tr>
z
  </w:tr>
)_tcs_xml)r   	row_countr   r   s       r5   r   CT_Tbl._trs_xml   s     CLL>?{KiWWr4   c                (    SUR                    S3U-  $ )Nz;    <w:tc>
      <w:tcPr>
        <w:tcW w:type="dxa" w:w="z-"/>
      </w:tcPr>
      <w:p/>
    </w:tc>
)r   )r   r   r   s      r5   r   CT_Tbl._tcs_xml   s+    009/@ A  	r4   r,   N)ru   zbool | None)r_   zWD_TABLE_DIRECTION | None)r   rv   r   rv   r   r   ru   rR   ru   
str | None)r   r   ru   None)r   rv   r   rv   r   r   ru   str)r   rv   r   r   ru   r   )r   rv   r   rv   r   r   ru   r   )r-   r.   r/   r0   r1   r2   r   r   r   r   r   r|   r   r}   r   r   classmethodr   r   r   r   r   r   r3   r,   r4   r5   rR   rR      s     #I.E8.'4GZ4	F	B  < < - -	 H H   	, 	, 
 
   X X  r4   rR   c                  <    \ rS rSr% SrS\S'   S\S'   \" SSS	9rS
rg)r   i  zi`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
successorsr,   N)	r-   r.   r/   r0   r1   r2   r   gridColr3   r,   r4   r5   r   r     s"    
 -,$$1EFGr4   r   c                  J    \ rS rSr% Sr\" S\5      rS\S'   \	S	S j5       r
Srg)
CT_TblGridColi  zB`w:gridCol` element, child of `w:tblGrid`, defines a table column.w:wr(   r   c                t    [        [        U R                  5       5      nUR                  R	                  U 5      $ )zHIndex of this `w:gridCol` element within its parent `w:tblGrid` element.)r   r   rS   r   rU   )rC   r   s     r5   gridCol_idxCT_TblGridCol.gridCol_idx  s.     z4>>#34""((..r4   r,   Nrt   )r-   r.   r/   r0   r1   r   r   r   r2   r|   r   r3   r,   r4   r5   r   r     s/    L(A}  / /r4   r   c                  6    \ rS rSr% Sr\" S\5      rS\S'   Sr	g)CT_TblLayoutTypei  zu`w:tblLayout` element.

Specifies whether column widths are fixed or can be automatically adjusted based on
content.
w:typer   typer,   N)
r-   r.   r/   r0   r1   r   r   r   r2   r3   r,   r4   r5   r   r     s      )"D* r4   r   c                     \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   Sr\" S\SS S9rS\S'   \" S\SS S9r	S\S'   \" S\SS S9r
S\S'   \" S\SS S9rS \S!'   C\S)S" j5       r\R                  S*S# j5       r\S+S$ j5       r\R                  S,S% j5       r\S& 5       r\R                  S-S' j5       rS(rg).r   i)  zy``<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 | Noner   r      zCT_Jc | Nonejcr      zCT_TblLayoutType | None	tblLayoutc                N    U R                   nUc  g[        SUR                  5      $ )zAHorizontal alignment of table, |None| if `./w:jc` is not present.NWD_TABLE_ALIGNMENT | None)r   r   r)   )rC   r   s     r5   	alignmentCT_TblPr.alignmentW  s'     WW:/88r4   c                n    U R                  5         Uc  g U R                  5       n[        SU5      Ul        g )Nr    )r   r   r   r)   )rC   r_   r   s      r5   r   r   _  s1    =!*E2r4   c                B    U R                   nUc  S$ UR                  S:g  $ )zW|False| when there is a `w:tblLayout` child with `@w:type="fixed"`.

Otherwise |True|.
Tfixed)r   r   )rC   r   s     r5   autofitCT_TblPr.autofitg  s&     NN	 (tGinn.GGr4   c                P    U R                  5       nU(       a  SUl        g SUl        g )Nr   r   )r   r   )rC   r_   r   s      r5   r   r   p  s    --/	&+		r4   c                :    U R                   nUc  gUR                  $ )zaReturn the value of the ``val`` attribute of the ``<w:tblStyle>`` child or
|None| if not present.N)r   r)   r   s     r5   styleCT_TblPr.styleu  s      ==||r4   c                T    U R                  5         Uc  g XR                  5       l        g r]   )r   r   r)   rC   r_   s     r5   r   r   ~  s%    =#( r4   r,   )ru   r   )r_   r   ru   r   )r_   r   r_   r   )r-   r.   r/   r0   r1   r2   _tag_seqr   r   r   r   r   r|   r   r}   r   r   r3   r,   r4   r5   r   r   )  s?   3 21&&88****""((H( "+!""H  #,8AB<#J  !8AB<B  *3(23-*I&  	9 9 3 3 H H ^^9 9   \\) )r4   r   c                      \ rS rSrSrSrg)rz   i  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
r,   N)r-   r.   r/   r0   r1   r3   r,   r4   r5   rz   rz     s    r4   rz   c                      \ rS rSr% Sr\" S\5      rS\S'   \" S\	5      r
\SS j5       r\R                  SS j5       rS	rg
)CT_TblWidthi  zJUsed for `w:tblW` and `w:tcW` and others, specifies a table-related width.r   rv   r   r   c                N    U R                   S:w  a  g[        U R                  5      $ )z>EMU length indicated by the combined `w:w` and `w:type` attrs.dxaN)r   r   r   rq   s    r5   r   CT_TblWidth.width  s!     99TVV}r4   c                F    SU l         [        U5      R                  U l        g )Nr   )r   r   r   r   r   s     r5   r   r     s    	U!!r4   )r   r   Nru   r(   r_   r   )r-   r.   r/   r0   r1   r   r   r   r2   r   r   r|   r   r}   r3   r,   r4   r5   r   r     sN    T
 uf-As-X{3D  \\" "r4   r   c                     \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   \" S5      rS\S'   \" S5      r	\" S5      r
\S8S j5       rS r\S8S j5       r\S8S j5       r\R                   S9S j5       r\S:S j5       rS r\S8S j5       rS;S jr\S<S j5       r\S8S j5       r\S8S j5       r\S=S j5       r\R                   S>S  j5       r\S?S! j5       r\R                   S@S" j5       rSAS# jrSBSCS% jjrSDS& jr\SES' j5       rSAS( jrSFS) jr \SGS* j5       r!S+ r"S, r#SHS- jr$SIS. jr%SJS/ jr&\SKS0 j5       r'\S<S1 j5       r(\SGS2 j5       r)\SLS3 j5       r*\SLS4 j5       r+\SMS5 j5       r,\S8S6 j5       r-S7r.g$)Nro   i  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                    U R                   b9  U R                  nUb*  UR                   [        R                  :X  a  UR                  $ U R
                  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)rC   tc_belows     r5   r  CT_Tc.bottom  sG     ;;"~~H#8;L;L(L&||ar4   c                V    U R                  S5       H  nU R                  U5        M     g)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)rC   es     r5   clear_contentCT_Tc.clear_content  s#     45AKKN 6r4   c                x    U R                   R                  n[        S U R                  S5       5       5      nX-   $ )zsStarting offset of `tc` in the layout-grid columns of its table.

A cell in the leftmost grid-column has offset 0.
c              3  8   #    U  H  oR                   v   M     g 7fr]   )rJ   ).0rN   s     r5   	<genexpr>$CT_Tc.grid_offset.<locals>.<genexpr>  s      &
#JRLL#Js   z./preceding-sibling::w:tc)_trrG   sumr  )rC   rG   preceding_tc_grid_spanss      r5   rL   CT_Tc.grid_offset  s@     hh**"% &
#'::.I#J&
 #
 44r4   c                <    U R                   nUc  S$ UR                  $ )zjThe integer number of columns this cell spans.

Determined by ./w:tcPr/w:gridSpan/@val, it defaults to 1.
r   )r   rJ   rC   r   s     r5   rJ   CT_Tc.grid_span  s      yyLq4dnn4r4   c                0    U R                  5       nXl        g r]   )r   rJ   rC   r_   r   s      r5   rJ   r    s    ##%r4   c                $    U R                  S5      $ )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  rq   s    r5   inner_content_elementsCT_Tc.inner_content_elements  s     zz+,,r4   c              #     #    [        S5      [        S5      [        S5      4nU  H  nUR                  U;   d  M  Uv   M     g7f)zhGenerate 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)rC   block_item_tagschilds      r5   iter_block_itemsCT_Tc.iter_block_items  s:      e9bk2g;?EyyO+ s
   4A	Ac                    U R                   $ )z?The grid column index at which this ``<w:tc>`` element appears.)rL   rq   s    r5   left
CT_Tc.left  s     r4   c                    U R                  U5      u  p#pEU R                  R                  U   R                  U5      nUR	                  XT5        U$ )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_tblrT   rO   _grow_to)rC   other_tctopr*  heightr   top_tcs          r5   mergeCT_Tc.merge  sI     $(#8#8#B 6!!#&88>&r4   c           	     L    [        [        [        S[        S5      -  5      5      $ )zUA new `w:tc` element, containing an empty paragraph as the required EG_BlockLevelElt.z<w:tc %s>
  <w:p/>
</w:tc>r   )r   ro   r   r   )r   s    r5   rp   	CT_Tc.new  s!     E9%IGTWL%XYZZr4   c                4    U R                   U R                  -   $ )zThe 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.
)rL   rJ   rq   s    r5   rightCT_Tc.right  s     $..00r4   c                    U R                   b  U R                   [        R                  :X  a  U R                  $ U R                  R
                  $ )z9The top-most row index in the vertical span of this cell.)r  r   RESTARTr  	_tc_abover1  rq   s    r5   r1  	CT_Tc.top  s9     ;;$++1A1A"A<<~~!!!r4   c                :    U R                   nUc  gUR                  $ )zCValue of ./w:tcPr/w:vMerge/@val, |None| if w:vMerge is not present.N)r   
vMerge_valr  s     r5   r  CT_Tc.vMerge  s     yy<r4   c                0    U R                  5       nXl        g r]   )r   r@  r  s      r5   r  rA  %  s    ##%r4   c                :    U R                   nUc  gUR                  $ )zDEMU length represented in `./w:tcPr/w:tcW` or |None| if not present.N)r   r   r  s     r5   r   CT_Tc.width*  s     yy<zzr4   c                0    U R                  5       nXl        g r]   )r   r   r  s      r5   r   rD  2  s    ##%
r4   c                    U R                   (       a:  UR                   (       a(  [        U R                   UR                   -   5      U l         ggg)zyAdd 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   )rC   r0  s     r5   _add_width_ofCT_Tc._add_width_of7  s1    
 ::(..

X^^ ;<DJ ):r4   Nc                   ^ ^ SUU 4S jjnUc  T OUnT R                  XU" U5      5        TS:  a(  T R                  nUc   eUR                  UTS-
  U5        gg)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                ^   > U TLa  [         R                  $ TS:X  a  S $ [         R                  $ Nr   )r   r  r<  )r3  r2  rC   s    r5   r@  "CT_Tc._grow_to.<locals>.vMerge_valF  s=     % !! $q[T /7.>.>r4   Nr   )r3  ro   )_span_to_widthr  r/  )rC   r   r2  r3  r@  r	  s   ` `   r5   r/  CT_Tc._grow_to?  sf    	 	  VE:f+=>A:~~H'''eVaZ8 r4   c                *    U R                  SU5        U$ )z#Override default `._insert_tcPr()`.r   rf   r  s     r5   _insert_tcPrCT_Tc._insert_tcPrT  s     	Atr4   c                    [        U R                  5       5      n[        U5      S:  a  gUS   n[        U[        5      (       a  [        UR
                  5      S:X  a  gg)z=True if this cell contains only a single empty `w:p` element.r   Fr   T)listr'  r   
isinstancer   r_lst)rC   block_items	only_items      r5   	_is_emptyCT_Tc._is_empty[  sU     40023{a  N	i&&3y+?1+Dr4   c                    XL a  gU R                   (       a  gUR                  5         U R                  5        H  nUR                  U5        M     U R                  U R	                  5       5        g)zhAppend the content of this cell to `other_tc`.

Leaves this cell with a single empty ``<w:p>`` element.
N)rX  _remove_trailing_empty_pr'  appendr   )rC   r0  block_elements      r5   _move_content_toCT_Tc._move_content_toh  sV    
 >>))+!224MOOM* 5 	DKKM"r4   c                    [        S5      e)NzDuse CT_Tbl.new_tbl() to add a new table, specifying rows and columns)NotImplementedErrorrq   s    r5   _new_tblCT_Tc._new_tblx  s    !R
 	
r4   c                @    U R                  S5      nU(       a  US   $ S$ )zwThe `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   )rC   following_tcss     r5   _next_tcCT_Tc._next_tc}  s%     

#>?#0}Q:d:r4   c                P    U R                  5       nUc   eUR                  U 5        g)z-Remove this `w:tc` element from the XML tree.N)rS   r  )rC   parent_elements     r5   _removeCT_Tc._remove  s(    ))))d#r4   c                    [        U R                  5       5      nUS   n[        U[        5      (       d  gUn[	        UR
                  5      S:  a  gU R                  U5        g)zJRemove last content element from this cell if it's an empty `w:p` element.Nr   )rS  r'  rT  r   r   rU  r  )rC   rV  last_content_elmps       r5   r[  CT_Tc._remove_trailing_empty_p  sS    40023&r?*D11qww<!Ar4   c                H   SS jnSS jnU" X5        U" X5        [        U R                  UR                  5      n[        U R                  UR                  5      n[        U R                  UR                  5      n[        U R
                  UR
                  5      nXEXd-
  Xu-
  4$ )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                   U R                   UR                   :X  a%  U R                  UR                  :w  a  [        S5      eU R                  UR                  :X  a&  U R                  UR                  :w  a  [        S5      eg g Nzrequested span not rectangularr1  r  r
   r*  r9  )abs     r5   raise_on_inverted_L3CT_Tc._span_dimensions.<locals>.raise_on_inverted_L  s_    uu~!((ahh"6&'GHHvvAGGqww$6&'GHH %7r4   c                   U R                   UR                   :  a  X4OX4u  p#UR                   UR                   :  a%  UR                  UR                  :  a  [        S5      eU R                  UR                  :  a  X4OX4u  pCUR                  UR                  :  a&  UR                  UR                  :  a  [        S5      eg g rs  rt  )ru  rv  top_mostother	left_mosts        r5   raise_on_tee_shaped3CT_Tc._span_dimensions.<locals>.raise_on_tee_shaped  s    ()qfA6OH||eii'HOOell,J&'GHH)*!&&vqfI~~

*y/L&'GHH 0M*r4   )ru  ro   rv  ro   )minr1  r*  maxr  r9  )rC   r0  rw  r}  r1  r*  r  r9  s           r5   r-  CT_Tc._span_dimensions  s    
	I	I 	D+D+$((HLL)499hmm,T[[(//2DJJ/&,44r4   c                    U R                  U5        U R                  U:  a#  U R                  X5        U R                  U:  a  M#  X0l        g)aF  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^  rJ   _swallow_next_tcr  )rC   
grid_widthr3  r  s       r5   rM  CT_Tc._span_to_width  s?     	f%nnz)!!*5 nnz)r4   c                   ^ ^ SUU 4S jjnT R                   nU" U5        Uc   eUR                  U5        T R                  U5        T =R                  UR                  -  sl        UR	                  5         g)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                r   > U c  [        S5      eTR                  U R                  -   T:  a  [        S5      eg )Nznot enough grid columnszspan is not rectangular)r
   rJ   )next_tcr  rC   s    r5   raise_on_invalid_swallow8CT_Tc._swallow_next_tc.<locals>.raise_on_invalid_swallow  s<    &'@AA~~ 1 11J>&'@AA ?r4   N)r  CT_Tc | None)rf  r^  rG  rJ   rj  )rC   r  r3  r  r  s   ``   r5   r  CT_Tc._swallow_next_tc  sh    	B 	B -- )"""  (7#'+++r4   c                F    [        [        U R                  S5      S   5      $ )z+The tbl element this tc element appears in.z./ancestor::w:tbl[position()=1]r   )r   rR   r  rq   s    r5   r.  
CT_Tc._tbl  s      FDJJ'HI!LMMr4   c                L    U R                   R                  U R                  5      $ )zAThe `w:tc` element immediately above this one in its grid column.)	_tr_aboverO   rL   rq   s    r5   r=  CT_Tc._tc_above  s     ~~//0@0@AAr4   c                X    U R                   nUc  gUR                  U R                  5      $ )z=The tc element immediately below this one in its grid column.N)	_tr_belowrO   rL   )rC   tr_belows     r5   r  CT_Tc._tc_below  s-     >>))$*:*:;;r4   c                F    [        [        U R                  S5      S   5      $ )z*The tr element this tc element appears in.z./ancestor::w:tr[position()=1]r   )r   r7   r  rq   s    r5   r  	CT_Tc._tr  s      FDJJ'GHKLLr4   c                R    U R                  S5      nU(       d  [        S5      eUS   $ )zThe 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  rK   )rC   	tr_abovess     r5   r  CT_Tc._tr_above  s,     JJZ[	>??|r4   c                    U R                   R                  nUR                  U R                  5      n XS-      $ ! [         a     gf = f)zrThe 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.  rT   rU   r  
IndexError)rC   rT   rW   s      r5   r  CT_Tc._tr_below  sI     !!dhh'	1*%% 		s   : 
AAc                `    U R                   R                  R                  U R                  5      $ )z;The row index of the tr element this tc element appears in.)r.  rT   rU   r  rq   s    r5   r  CT_Tc._tr_idx
  s#     yy%%dhh//r4   )r  r   rt   r_   rv   )ru   zlist[CT_P | CT_Tbl])r0  ro   ru   ro   )ru   ro   r   r   r   r   )r0  ro   r]   )r   rv   r2  rv   r3  r  )r   CT_TcPrru   r  r   )ru   r   )ru   r  )r0  ro   ru   ztuple[int, int, int, int])r  rv   r3  ro   r  r   )r  rv   r3  ro   )ru   rR   )ru   r7   )ru   zCT_Row | None)/r-   r.   r/   r0   r1   r2   r   r   r   ro  rV   r|   r  r  rL   rJ   r}   r!  r'  r*  r4  r   rp   r9  r1  r  r   rG  r/  rP  rX  r^  rb  rf  rj  r[  r-  rM  r  r.  r=  r  r  r  r  r  r3   r,   r4   r5   ro   ro     s[   $**++ %X.D..%A
G
C
  
 	 	5 	5 5 5   - -    	 [ [ 1 1 " "   ]]      \\ =9* 
 
# 

 ; ;$	5<"2 N N B B < < M M     0 0r4   ro   c                     \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   Sr\" S\SS S9rS\S'   \" S\SS S9r	S\S'   \" S\SS S9r
S\S'   \" S\SS S9rS \S!'   C\S+S" j5       r\R                  S,S# j5       r\S$ 5       r\R                  S-S% j5       r\S& 5       r\R                  S.S' j5       r\S/S( j5       r\R                  S0S) j5       rS*rg)1r  i  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:tcPrChanger     Nr   zCT_TblWidth | NonetcWr     CT_DecimalNumber | NonegridSpanr     zCT_VMerge | Noner  r     zCT_VerticalJc | NonevAlignc                <    U R                   nUc  S$ UR                  $ )zcThe integer number of columns this cell spans.

Determined by ./w:gridSpan/@val, it defaults to 1.
r   )r  r)   )rC   r  s     r5   rJ   CT_TcPr.grid_span=  s!     ==$q6(,,6r4   c                Z    U R                  5         US:  a  XR                  5       l        g g rK  )r  r  r)   r   s     r5   rJ   r  F  s)    19-2$$&* r4   c                :    U R                   nUc  gUR                  $ )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)r  r)   )rC   r  s     r5   
vAlign_valCT_TcPr.vAlign_valL  s     >zzr4   c                T    Uc  U R                  5         g XR                  5       l        g r]   )r  r  r)   r   s     r5   r  r  X  s%    =!', $r4   c                :    U R                   nUc  gUR                  $ )z]The value of the ./w:vMerge/@val attribute, or |None| if the w:vMerge element
is not present.N)r  r)   )rC   r  s     r5   r@  CT_TcPr.vMerge_val_  s     >zzr4   c                T    U R                  5         Ub  XR                  5       l        g g r]   )r  r  r)   r   s     r5   r@  r  h  s(    %*" r4   c                :    U R                   nUc  gUR                  $ )zJEMU length in `./w:tcW` or |None| if not present or its type is not 'dxa'.N)r  r   )rC   r  s     r5   r   CT_TcPr.widthn  s     hh;yyr4   c                0    U R                  5       nXl        g r]   )r  r   )rC   r_   r  s      r5   r   r  v  s    !!#	r4   r,   rt   r  )r_   z!WD_CELL_VERTICAL_ALIGNMENT | Noner   r   r   )r-   r.   r/   r0   r1   r2   r   r   r  r  r  r  r|   rJ   r}   r  r@  r   r3   r,   r4   r5   r  r    sk   ?77--22((((&&&&H( (HQRLC	  )2!")H%   )x| F  $-x}$F   	7 7 3 3
 	 	 - -   + +
   \\ r4   r  c                      \ rS rSr% SrS\S'   Sr\" S\SS S	9rS
\S'   \" S\SS S	9r	S
\S'   \" S\SS S	9r
S\S'   C\SS j5       r\SS j5       r\SS j5       r\R                  SS j5       r\S 5       r\R                  SS j5       rSrg)r{   i|  z4``<w:trPr>`` element, defining table row properties.zCallable[[], CT_Height]get_or_add_trHeight)r  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   r  	gridAfterr  r  
gridBeforer  r   zCT_Height | NonetrHeightc                <    U R                   nUc  S$ UR                  $ r@   )r  r)   )rC   r  s     r5   rA   CT_TrPr.grid_after  s!     NN	%q89==8r4   c                <    U R                   nUc  S$ UR                  $ rF   )r  r)   )rC   r  s     r5   rG   CT_TrPr.grid_before  s!     __
&q:JNN:r4   c                <    U R                   nUc  S$ UR                  $ )zCReturn the value of `w:trHeight@w:hRule`, or |None| if not present.N)r  r+   rC   r  s     r5   rZ   CT_TrPr.trHeight_hRule  s!     =='t;X^^;r4   c                R    Uc  U R                   c  g U R                  5       nXl        g r]   )r  r  r+   rC   r_   r  s      r5   rZ   r    s&    =T]]2++-r4   c                <    U R                   nUc  S$ UR                  $ )zAReturn the value of `w:trHeight@w:val`, or |None| if not present.N)r  r)   r  s     r5   ra   CT_TrPr.trHeight_val  s!     =='t9X\\9r4   c                R    Uc  U R                   c  g U R                  5       nXl        g r]   )r  r  r)   r  s      r5   ra   r    s&    =T]]2++-r4   r,   rt   rw   rx   ry   )r-   r.   r/   r0   r1   r2   r   r   r  r  r  r|   rA   rG   rZ   r}   ra   r3   r,   r4   r5   r{   r{   |  s    >00H" *3(12,*I&  +48AB<+J'  "+!""H  	9 9
 ; ;
 < <
   : :
  r4   r{   c                  6    \ rS rSr% Sr\" S\5      rS\S'   Sr	g)CT_VerticalJci  z:`w:vAlign` element, specifying vertical alignment of cell.r'   r   r)   r,   N)
r-   r.   r/   r0   r1   r   r   r)   r2   r3   r,   r4   r5   r  r    s    D&7+'C	# r4   r  c                  H    \ rS rSr% Sr\" S\\R                  S9rS\	S'   Sr
g)		CT_VMergei  zG``<w:vMerge>`` element, specifying vertical merging behavior of a cell.r'   )defaultr   r)   r,   N)r-   r.   r/   r0   r1   r   r   r  r)   r2   r3   r,   r4   r5   r  r    s#    Q'8#4#4C r4   r  N)=r1   
__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%   r7   rR   r   r   r   r   rz   r   ro   r  r{   r  r  r,   r4   r5   <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  r4   