o
    ýÞhJƒ  ã                   @  sè  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„ deƒZ/G dd„ deƒZ0G dd„ deƒZ1G dd„ deƒZ2G dd„ deƒZ3G dd„ deƒZ4G dd„ deƒZ5G dd „ d eƒZ6G d!d"„ d"eƒZ7G d#d$„ d$eƒZ8G d%d&„ d&eƒZ9G d'd(„ d(eƒZ:G d)d*„ d*eƒZ;G d+d,„ d,eƒZ<d-S ).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                   @  s6   e Zd ZU dZedeƒZded< edeƒZ	ded< dS )	Ú	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(   © r.   r.   úO/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/oxml/table.pyr#   &   s   
 ÿÿr#   c                   @  sä   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d„ƒZe
d.dd„ƒZd/dd„Ze
d.dd„ƒZe
d0dd„ƒZejd1d d„ƒZe
d!d"„ ƒZejd2d$d"„ƒZd3d&d'„Zd4d)d*„Zd+d,„ Zd-S )5Ú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:tcÚreturnÚintc                 C  ó   | j }|du r	dS |jS ©zCThe number of unpopulated layout-grid cells at the end of this row.Nr   )r6   Ú
grid_after©Úselfr6   r.   r.   r/   r;   ?   ó   zCT_Row.grid_afterc                 C  r9   ©zEThe number of unpopulated layout-grid cells at the start of this row.Nr   )r6   Úgrid_beforer<   r.   r.   r/   r@   G   r>   zCT_Row.grid_beforeÚgrid_offsetÚCT_Tcc                 C  sJ   || j  }| jD ]}|dk r n|dkr|  S ||j8 }qtd|› �ƒ‚)zžThe `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=)r@   r4   Ú	grid_spanÚ
ValueError)r=   rA   Úremaining_offsetÚtcr.   r.   r/   Útc_at_grid_offsetO   s   

zCT_Row.tc_at_grid_offsetc                 C  ó   t t|  ¡ ƒ}|j | ¡S )z?Index of this `w:tr` element within its parent `w:tbl` element.)r   ÚCT_TblÚ	getparentÚtr_lstÚindex)r=   Útblr.   r.   r/   Útr_idxd   ó   zCT_Row.tr_idxr'   c                 C  ó   | j }|du r	dS |jS )zFThe value of `./w:trPr/w:trHeight/@w:hRule`, or |None| if not present.N)r6   ÚtrHeight_hRuler<   r.   r.   r/   rQ   j   r>   zCT_Row.trHeight_hRuleÚvaluec                 C  ó   |   ¡ }||_d S ©N)r2   rQ   ©r=   rR   r6   r.   r.   r/   rQ   r   ó   
c                 C  rP   )zHReturn the value of `w:trPr/w:trHeight@w:val`, or |None| if not present.N)r6   ÚtrHeight_valr<   r.   r.   r/   rW   w   r>   zCT_Row.trHeight_valr%   c                 C  rS   rT   )r2   rW   rU   r.   r.   r/   rW      rV   Ú
CT_TblPrExc                 C  s   |   d|¡ d S ©Nr   ©Úinsert)r=   r5   r.   r.   r/   Ú_insert_tblPrEx„   s   zCT_Row._insert_tblPrExÚCT_TrPrc                 C  s,   | j }|d ur| |¡ d S |  d|¡ d S rY   )r5   Úaddnextr[   )r=   r6   r5   r.   r.   r/   Ú_insert_trPr‡   s   zCT_Row._insert_trPrc                 C  s   t  ¡ S rT   )rB   Únew©r=   r.   r.   r/   Ú_new_tcŽ   s   zCT_Row._new_tcN©r7   r8   )rA   r8   r7   rB   ©r7   r'   ©rR   r'   ©rR   r%   )r5   rX   )r6   r]   )r)   r*   r+   r,   r-   r   r5   r6   r   rF   Úpropertyr;   r@   rG   rN   rQ   ÚsetterrW   r\   r_   rb   r.   r.   r.   r/   r0   1   s6   
 



r0   c                   @  sà   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
d2dd„ƒZejd3dd„ƒZe
dd„ ƒZdd„ Zed4dd„ƒZe
d5d d!„ƒZejd6d$d!„ƒZed7d&d'„ƒZed8d*d+„ƒZed9d-d.„ƒZed8d/d0„ƒZd1S ):rI   z``<w:tbl>`` element.zCallable[[], CT_Row]Úadd_trzlist[CT_Row]rK   zw:tblPrÚCT_TblPrÚtblPrz	w:tblGridÚ
CT_TblGridÚtblGridzw:trr7   úbool | Nonec                 C  ó   | j j}|du r
dS |jS )zŸValue 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)rk   Ú
bidiVisualr&   )r=   rp   r.   r.   r/   ÚbidiVisual_valœ   s   zCT_Tbl.bidiVisual_valrR   úWD_TABLE_DIRECTION | Nonec                 C  s,   | j }|d u r| ¡  d S t|ƒ| ¡ _d S rT   )rk   Ú_remove_bidiVisualÚboolÚget_or_add_bidiVisualr&   )r=   rR   rk   r.   r.   r/   rq   §   s   c                 C  s   t | jjƒS )z)The number of grid columns in this table.)Úlenrm   ÚgridCol_lstra   r.   r.   r/   Ú	col_count¯   s   zCT_Tbl.col_countc                 c  s$   � | j D ]}|jD ]}|V  q	qdS )zÍGenerate 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)rK   r4   )r=   ÚtrrF   r.   r.   r/   Úiter_tcs´   s   €

ÿÿzCT_Tbl.iter_tcsÚrowsr8   ÚcolsÚwidthr   c                 C  s   t tt|  |||¡ƒƒS )zˆReturn a new `w:tbl` element having `rows` rows and `cols` columns.

        `width` is distributed evenly between the columns.
        )r   rI   r   Ú_tbl_xml)Úclsr{   r|   r}   r.   r.   r/   Únew_tbl¿   s   zCT_Tbl.new_tblú
str | Nonec                 C  ro   )zH`w:tblPr/w:tblStyle/@w:val` (a table style id) or |None| if not present.N)rk   ÚtblStyler&   ©r=   r‚   r.   r.   r/   ÚtblStyle_valÇ   s   zCT_Tbl.tblStyle_valÚstyleIdÚNonec                 C  s(   | j }| ¡  |du rdS || ¡ _dS )z–Set 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)rk   Ú_remove_tblStyleÚ_add_tblStyler&   )r=   r…   rk   r.   r.   r/   r„   Ï   s
   Ústrc              	   C  sH   |dkr
t || ƒnt dƒ}dtdƒ› d|  ||¡› |  |||¡› 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_widthr.   r.   r/   r~   Û   s   
ùøÿzCT_Tbl._tbl_xmlrx   r�   c                 C  s,   d}t |ƒD ]	}|d|j 7 }q|d7 }|S )Nz  <w:tblGrid>
z    <w:gridCol w:w="%d"/>
z  </w:tblGrid>
)ÚrangeÚtwips)r   rx   r�   ÚxmlÚ_r.   r.   r/   r‹   ë   s
   zCT_Tbl._tblGrid_xmlÚ	row_countc                 C  s   d|   ||¡› d�| S )Nz	  <w:tr>
z
  </w:tr>
)Ú_tcs_xml)r   r’   rx   r�   r.   r.   r/   rŒ   ó   s   zCT_Tbl._trs_xmlc                 C  s   d|j › d�| S )Nz;    <w:tc>
      <w:tcPr>
        <w:tcW w:type="dxa" w:w="z-"/>
      </w:tcPr>
      <w:p/>
    </w:tc>
)r�   )r   rx   r�   r.   r.   r/   r“   ÷   s
   þùzCT_Tbl._tcs_xmlN)r7   rn   )rR   rr   )r{   r8   r|   r8   r}   r   r7   rI   ©r7   r�   )r…   r�   r7   r†   )r{   r8   r|   r8   r}   r   r7   r‰   )rx   r8   r�   r   r7   r‰   )r’   r8   rx   r8   r�   r   r7   r‰   )r)   r*   r+   r,   r-   r   rk   rm   r   ry   rg   rq   rh   rx   rz   Úclassmethodr€   r„   r~   r‹   rŒ   r“   r.   r.   r.   r/   rI   ’   s8   
 

rI   c                   @  s.   e Zd ZU dZded< ded< eddd�Zd	S )
rl   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]rw   z	w:gridCol)zw:tblGridChange©Ú
successorsN)r)   r*   r+   r,   r-   r   ÚgridColr.   r.   r.   r/   rl     s
   
 rl   c                   @  s2   e Zd ZU dZedeƒZded< ed
dd„ƒZ	d	S )ÚCT_TblGridColzB`w:gridCol` element, child of `w:tblGrid`, defines a table column.úw:wr%   rŠ   r7   r8   c                 C  rH   )zHIndex of this `w:gridCol` element within its parent `w:tblGrid` element.)r   rl   rJ   rw   rL   )r=   rm   r.   r.   r/   ÚgridCol_idx  rO   zCT_TblGridCol.gridCol_idxNrc   )
r)   r*   r+   r,   r   r   rŠ   r-   rg   rœ   r.   r.   r.   r/   rš     s   
 ÿrš   c                   @  ó$   e Zd ZU dZedeƒZded< dS )Ú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-   r.   r.   r.   r/   rž     s
   
 ÿrž   c                   @  s  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… d�Zded< ededd… d�Zded< ededd… d�Z	ded< ededd… d�Z
ded < [ed/d#d$„ƒZejd0d&d$„ƒZed1d(d)„ƒZejd2d*d)„ƒZed+d,„ ƒZejd3d.d,„ƒZdS )4rj   z}``<w:tblPr>`` element, child of ``<w:tbl>``, holds child elements that define
    table properties such as style and borders.zCallable[[], CT_OnOff]ru   zCallable[[], CT_Jc]Úget_or_add_jczCallable[[], CT_TblLayoutType]Úget_or_add_tblLayoutzCallable[[], CT_String]rˆ   úCallable[[], None]rs   Ú
_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 | Nonerp   r§   é   zCT_Jc | NoneÚjcrª   é   zCT_TblLayoutType | NoneÚ	tblLayoutr7   úWD_TABLE_ALIGNMENT | Nonec                 C  s   | j }|du r	dS td|jƒS )zAHorizontal alignment of table, |None| if `./w:jc` is not present.Nr±   )r®   r   r&   )r=   r®   r.   r.   r/   Ú	alignmentW  ó   zCT_TblPr.alignmentrR   c                 C  s,   |   ¡  |d u r
d S |  ¡ }td|ƒ|_d S )Nr   )r¤   r¡   r   r&   )r=   rR   r®   r.   r.   r/   r²   _  s
   rt   c                 C  s   | j }|du r	dS |jdkS )zg|False| when there is a `w:tblLayout` child with `@w:type="fixed"`.

        Otherwise |True|.
        NTÚfixed)r°   r    )r=   r°   r.   r.   r/   Úautofitg  s   zCT_TblPr.autofitc                 C  s    |   ¡ }|rd|_d S d|_d S )Nrµ   r´   )r¢   r    )r=   rR   r°   r.   r.   r/   rµ   p  s   c                 C  rP   )ziReturn the value of the ``val`` attribute of the ``<w:tblStyle>`` child or
        |None| if not present.N)r‚   r&   rƒ   r.   r.   r/   Ústyleu  ó   zCT_TblPr.styler�   c                 C  s"   |   ¡  |d u r
d S ||  ¡ _d S rT   )r‡   rˆ   r&   ©r=   rR   r.   r.   r/   r¶   ~  ó   )r7   r±   )rR   r±   ©r7   rt   )rR   rt   ©rR   r�   )r)   r*   r+   r,   r-   Ú_tag_seqr   r‚   rp   r®   r°   rg   r²   rh   rµ   r¶   r.   r.   r.   r/   rj   )  sF   
 ÿÿÿÿ
rj   c                   @  s   e Zd ZdZdS )rX   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,   r.   r.   r.   r/   rX   †  s    rX   c                   @  sL   e Zd ZU dZedeƒZded< edeƒZ	e
ddd	„ƒZejddd	„ƒZdS )ÚCT_TblWidthzJUsed for `w:tblW` and `w:tcW` and others, specifies a table-related width.r›   r8   rŠ   rŸ   r7   r%   c                 C  s   | j dkrdS t| jƒS )z>EMU length indicated by the combined `w:w` and `w:type` attrs.ÚdxaN)r    r   rŠ   ra   r.   r.   r/   r}   ˜  s   

zCT_TblWidth.widthrR   r   c                 C  s   d| _ t|ƒj| _d S )Nr¾   )r    r   r�   rŠ   r¸   r.   r.   r/   r}   Ÿ  s   N©r7   r%   ©rR   r   )r)   r*   r+   r,   r   r   rŠ   r-   r   r    rg   r}   rh   r.   r.   r.   r/   r½   �  s   
 
r½   c                   @  s  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
dkdd„ƒZdd„ Ze
dkdd„ƒZe
dkdd„ƒZejdldd„ƒZe
dmdd „ƒZd!d"„ Ze
dkd#d$„ƒZdnd&d'„Zedod(d)„ƒZe
dkd*d+„ƒZe
dkd,d-„ƒZe
dpd/d0„ƒZejdqd1d0„ƒZe
drd3d4„ƒZejdsd6d4„ƒZdtd7d8„Zdudvd>d?„ZdwdAdB„Ze
dxdDdE„ƒZdtdFdG„ZdydIdJ„Ze
dzdKdL„ƒZ dMdN„ Z!dOdP„ Z"d{dRdS„Z#d|dVdW„Z$d}dXdY„Z%e
d~d[d\„ƒZ&e
dod]d^„ƒZ'e
dzd_d`„ƒZ(e
ddbdc„ƒZ)e
dddde„ƒZ*e
d€dgdh„ƒZ+e
dkdidj„ƒZ,d9S )�rB   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:tblr7   r8   c                 C  s4   | j dur| j}|dur|j tjkr|jS | jd S )zìThe 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.
        Nr«   )ÚvMergeÚ	_tc_belowr   ÚCONTINUEÚbottomÚ_tr_idx)r=   Útc_belowr.   r.   r/   rÍ   ´  s
   

zCT_Tc.bottomc                 C  s   |   d¡D ]}|  |¡ qdS )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=   Úer.   r.   r/   Úclear_contentÁ  s   ÿzCT_Tc.clear_contentc                 C  s(   | j j}tdd„ |  d¡D ƒƒ}|| S )zƒStarting offset of `tc` in the layout-grid columns of its table.

        A cell in the leftmost grid-column has offset 0.
        c                 s  s   � | ]}|j V  qd S rT   )rC   )Ú.0rF   r.   r.   r/   Ú	<genexpr>Ó  s   € 
ÿz$CT_Tc.grid_offset.<locals>.<genexpr>z./preceding-sibling::w:tc)Ú_trr@   ÚsumrÐ   )r=   r@   Úpreceding_tc_grid_spansr.   r.   r/   rA   Ì  s
   ÿzCT_Tc.grid_offsetc                 C  r9   )zzThe integer number of columns this cell spans.

        Determined by ./w:tcPr/w:gridSpan/@val, it defaults to 1.
        Nr«   )rÇ   rC   ©r=   rÇ   r.   r.   r/   rC   Ø  ó   zCT_Tc.grid_spanrR   c                 C  rS   rT   )rÂ   rC   ©r=   rR   rÇ   r.   r.   r/   rC   á  rV   úlist[CT_P | CT_Tbl]c                 C  s
   |   d¡S )zÔGenerate 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Ð   ra   r.   r.   r/   Úinner_content_elementsæ  s   
zCT_Tc.inner_content_elementsc                 c  s6   � t dƒt dƒt dƒf}| D ]
}|j|v r|V  qdS )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Úchildr.   r.   r/   Úiter_block_itemsï  s   €
€þzCT_Tc.iter_block_itemsc                 C  s   | j S )z?The grid column index at which this ``<w:tc>`` element appears.)rA   ra   r.   r.   r/   Úleft÷  s   z
CT_Tc.leftÚother_tcc                 C  s4   |   |¡\}}}}| jj|  |¡}| ||¡ |S )z½Return 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Ú_tblrK   rG   Ú_grow_to)r=   rä   Útoprã   Úheightr}   Útop_tcr.   r.   r/   Úmergeü  s   zCT_Tc.mergec                 C  s   t ttdtdƒ ƒƒ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   rB   r   r
   )r   r.   r.   r/   r`     s   z	CT_Tc.newc                 C  s   | j | j 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.
        )rA   rC   ra   r.   r.   r/   Úright  s   zCT_Tc.rightc                 C  s$   | j du s| j tjkr| jS | jjS )z9The top-most row index in the vertical span of this cell.N)rÊ   r   ÚRESTARTrÎ   Ú	_tc_aboverè   ra   r.   r.   r/   rè     s   z	CT_Tc.topr�   c                 C  rP   )zCValue of ./w:tcPr/w:vMerge/@val, |None| if w:vMerge is not present.N)rÇ   Ú
vMerge_valrÙ   r.   r.   r/   rÊ     r>   zCT_Tc.vMergec                 C  rS   rT   )rÂ   rï   rÛ   r.   r.   r/   rÊ   %  rV   r%   c                 C  rP   )zDEMU length represented in `./w:tcPr/w:tcW` or |None| if not present.N)rÇ   r}   rÙ   r.   r.   r/   r}   *  r>   zCT_Tc.widthr   c                 C  rS   rT   )rÂ   r}   rÛ   r.   r.   r/   r}   2  rV   c                 C  s*   | j r|j rt| j |j  ƒ| _ dS dS dS )z‰Add 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ä   r.   r.   r/   Ú_add_width_of7  s   ÿzCT_Tc._add_width_ofNr}   ré   rê   úCT_Tc | Nonec                   sf   d‡ ‡fdd„}|du rˆn|}ˆ  ||||ƒ¡ ˆ dkr1ˆj}|dus&J ‚| |ˆ d |¡ dS dS )z¾Grow this cell to `width` grid columns and `height` rows.

        This is accomplished by expanding horizontal spans and creating continuation
        cells to form vertical spans.
        rê   rB   c                   s    | ˆurt jS ˆ dkrd S t jS ©Nr«   )r   rÌ   rí   )rê   ©ré   r=   r.   r/   rï   F  s   ÿÿÿýûz"CT_Tc._grow_to.<locals>.vMerge_valNr«   )rê   rB   )Ú_span_to_widthrË   rç   )r=   r}   ré   rê   rï   rÏ   r.   ró   r/   rç   ?  s   	ýzCT_Tc._grow_toÚCT_TcPrc                 C  s   |   d|¡ |S )z#Override default `._insert_tcPr()`.r   rZ   rÙ   r.   r.   r/   Ú_insert_tcPrV  s   zCT_Tc._insert_tcPrrt   c                 C  s<   t |  ¡ ƒ}t|ƒdkrdS |d }t|tƒot|jƒdkS )z=True if this cell contains only a single empty `w:p` element.r«   Fr   )Úlistrâ   rv   Ú
isinstancer   Úr_lst)r=   Úblock_itemsÚ	only_itemr.   r.   r/   Ú	_is_empty]  s
   zCT_Tc._is_emptyc                 C  sH   || u rdS | j rdS | ¡  |  ¡ D ]}| |¡ q|  |  ¡ ¡ dS )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_elementr.   r.   r/   Ú_move_content_toh  s   zCT_Tc._move_content_tor†   c                 C  s   t dƒ‚)NzDuse CT_Tbl.new_tbl() to add a new table, specifying rows and columns)ÚNotImplementedErrorra   r.   r.   r/   Ú_new_tblx  s   ÿzCT_Tc._new_tblc                 C  s   |   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_tcsr.   r.   r/   Ú_next_tc}  s   
zCT_Tc._next_tcc                 C  s"   |   ¡ }|dus
J ‚| | ¡ dS )z-Remove this `w:tc` element from the XML tree.N)rJ   rÑ   )r=   Úparent_elementr.   r.   r/   Ú_remove„  s   zCT_Tc._removec                 C  sF   t |  ¡ ƒ}|d }t|tƒsdS |}t|jƒdkrdS |  |¡ dS )zJRemove last content element from this cell if it's an empty `w:p` element.éÿÿÿÿNr   )r÷   râ   rø   r   rv   rù   rÑ   )r=   rú   Úlast_content_elmÚpr.   r.   r/   rý   Š  s   
zCT_Tc._remove_trailing_empty_pútuple[int, int, int, int]c                 C  st   d	dd„}d	dd„}|| |ƒ || |ƒ t | j|jƒ}t | j|jƒ}t| j|jƒ}t| j|jƒ}|||| || fS )
z¨Return 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.ÚarB   Úbc                 S  sH   | j |j kr| j|jkrtdƒ‚| j|jkr | j|jkr"tdƒ‚d S d S ©Nzrequested span not rectangular©rè   rÍ   r	   rã   rì   )r  r  r.   r.   r/   Úraise_on_inverted_Lš  s
   ÿz3CT_Tc._span_dimensions.<locals>.raise_on_inverted_Lc                 S  sˆ   | j |j k r
| |fn|| f\}}|j |j k r |j|jkr tdƒ‚| j|jk r*| |fn|| f\}}|j|jk r@|j|jkrBtdƒ‚d S d S r  r  )r  r  Útop_mostÚotherÚ	left_mostr.   r.   r/   Úraise_on_tee_shaped   s     ÿz3CT_Tc._span_dimensions.<locals>.raise_on_tee_shapedN)r  rB   r  rB   )Úminrè   rã   ÚmaxrÍ   rì   )r=   rä   r  r  rè   rã   rÍ   rì   r.   r.   r/   rå   •  s   


	
zCT_Tc._span_dimensionsÚ
grid_widthrÊ   c                 C  s4   |   |¡ | j|k r|  ||¡ | j|k s
|| _dS )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   rC   Ú_swallow_next_tcrÊ   )r=   r  rê   rÊ   r.   r.   r/   rô   ³  s
   


ÿ
zCT_Tc._span_to_widthc                   sZ   d‡ ‡fdd„}ˆj }||ƒ |dusJ ‚| |¡ ˆ |¡ ˆ j|j7  _| ¡  dS )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.
        Únext_tcrñ   c                   s,   | d u rt dƒ‚ˆj| j ˆ krt dƒ‚d S )Nznot enough grid columnszspan is not rectangular)r	   rC   )r  ©r  r=   r.   r/   Úraise_on_invalid_swallowÏ  s
   ÿz8CT_Tc._swallow_next_tc.<locals>.raise_on_invalid_swallowN)r  rñ   )r  r   rð   rC   r  )r=   r  rê   r  r  r.   r  r/   r  Ä  s   

zCT_Tc._swallow_next_tcrI   c                 C  ó   t t|  d¡d ƒS )z+The tbl element this tc element appears in.z./ancestor::w:tbl[position()=1]r   )r   rI   rÐ   ra   r.   r.   r/   ræ   Ý  ó   z
CT_Tc._tblc                 C  s   | j  | j¡S )zAThe `w:tc` element immediately above this one in its grid column.)Ú	_tr_aboverG   rA   ra   r.   r.   r/   rî   â  s   zCT_Tc._tc_abovec                 C  s   | j }|du r	dS | | j¡S )z=The tc element immediately below this one in its grid column.N)Ú	_tr_belowrG   rA   )r=   Útr_belowr.   r.   r/   rË   ç  r³   zCT_Tc._tc_belowr0   c                 C  r  )z*The tr element this tc element appears in.z./ancestor::w:tr[position()=1]r   )r   r0   rÐ   ra   r.   r.   r/   rÖ   ï  r  z	CT_Tc._trc                 C  s   |   d¡}|stdƒ‚|d 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Ð   rD   )r=   Ú	tr_abovesr.   r.   r/   r  ô  s   
zCT_Tc._tr_aboveúCT_Row | Nonec                 C  s8   | j j}| | j¡}z||d  W S  ty   Y dS 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æ   rK   rL   rÖ   Ú
IndexError)r=   rK   rN   r.   r.   r/   r  ÿ  s   ÿzCT_Tc._tr_belowc                 C  s   | j j | j¡S )z;The row index of the tr element this tc element appears in.)ræ   rK   rL   rÖ   ra   r.   r.   r/   rÎ   
  s   zCT_Tc._tr_idxrc   ©rR   r8   )r7   rÜ   )rä   rB   r7   rB   )r7   rB   r”   r»   r¿   rÀ   )rä   rB   rT   )r}   r8   ré   r8   rê   rñ   )rÇ   rõ   r7   rõ   rº   )r7   r†   )r7   rñ   )rä   rB   r7   r
  )r  r8   rê   rB   rÊ   r�   )r  r8   rê   rB   )r7   rI   )r7   r0   )r7   r!  )-r)   r*   r+   r,   r-   r   rÇ   r   r	  rM   rg   rÍ   rÓ   rA   rC   rh   rÞ   râ   rã   rë   r•   r`   rì   rè   rÊ   r}   rð   rç   rö   rü   r   r  r  r  rý   rå   rô   r  ræ   rî   rË   rÖ   r  r  rÎ   r.   r.   r.   r/   rB   ¥  sˆ   
 
	









rB   c                   @  s4  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… d�Zded< ededd… d�Zded< ededd… d�Z	ded< ededd… d�Z
ded < [ed4d#d$„ƒZejd5d&d$„ƒZed'd(„ ƒZejd6d*d(„ƒZed+d,„ ƒZejd7d.d,„ƒZed8d0d1„ƒZejd9d3d1„ƒZdS ):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:tcPrChanger,  é   Nr—   zCT_TblWidth | NoneÚtcWr-  é   úCT_DecimalNumber | NoneÚgridSpanr.  é   zCT_VMerge | NonerÊ   r/  é   zCT_VerticalJc | NoneÚvAlignr7   r8   c                 C  r9   )zsThe integer number of columns this cell spans.

        Determined by ./w:gridSpan/@val, it defaults to 1.
        Nr«   )r4  r&   )r=   r4  r.   r.   r/   rC   =  rÚ   zCT_TcPr.grid_spanrR   c                 C  s"   |   ¡  |dkr||  ¡ _d S d S rò   )r(  r$  r&   r¸   r.   r.   r/   rC   F  ó   ÿc                 C  rP   )z¯Value 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)r7  r&   )r=   r7  r.   r.   r/   Ú
vAlign_valL  s   zCT_TcPr.vAlign_valú!WD_CELL_VERTICAL_ALIGNMENT | Nonec                 C  s"   |d u r
|   ¡  d S ||  ¡ _d S rT   )r)  r&  r&   r¸   r.   r.   r/   r9  X  r¹   c                 C  rP   )zeThe value of the ./w:vMerge/@val attribute, or |None| if the w:vMerge element
        is not present.N)rÊ   r&   )r=   rÊ   r.   r.   r/   rï   _  r·   zCT_TcPr.vMerge_valr�   c                 C  s"   |   ¡  |d ur||  ¡ _d S d S rT   )r*  r'  r&   r¸   r.   r.   r/   rï   h  r8  r%   c                 C  rP   )zJEMU length in `./w:tcW` or |None| if not present or its type is not 'dxa'.N)r1  r}   )r=   r1  r.   r.   r/   r}   n  r>   zCT_TcPr.widthr   c                 C  rS   rT   )r%  r}   )r=   rR   r1  r.   r.   r/   r}   v  rV   rc   r#  )rR   r:  r»   r¿   rÀ   )r)   r*   r+   r,   r-   r¼   r   r1  r4  rÊ   r7  rg   rC   rh   r9  rï   r}   r.   r.   r.   r/   rõ     sN   
 ÿÿÿÿ

rõ   c                   @  sÊ   e Zd ZU dZded< dZededd… d�Zd	ed
< ededd… d�Zd	ed< ededd… d�Z	ded< [e
d!dd„ƒZe
d!dd„ƒZe
d"dd„ƒZejd#dd„ƒZe
dd„ ƒZejd$d d„ƒZdS )%r]   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—   r3  Ú	gridAfterr<  r2  Ú
gridBeforer>  r­   zCT_Height | NoneÚtrHeightr7   r8   c                 C  r9   r:   )r?  r&   )r=   r?  r.   r.   r/   r;   �  ó   zCT_TrPr.grid_afterc                 C  r9   r?   )r@  r&   )r=   r@  r.   r.   r/   r@   £  rB  zCT_TrPr.grid_beforer'   c                 C  rP   )zCReturn the value of `w:trHeight@w:hRule`, or |None| if not present.N)rA  r(   ©r=   rA  r.   r.   r/   rQ   ©  rB  zCT_TrPr.trHeight_hRulerR   c                 C  ó(   |d u r| j d u rd S |  ¡ }||_d S rT   )rA  r;  r(   ©r=   rR   rA  r.   r.   r/   rQ   ¯  ó   
c                 C  rP   )zAReturn the value of `w:trHeight@w:val`, or |None| if not present.N)rA  r&   rC  r.   r.   r/   rW   ¶  rB  zCT_TrPr.trHeight_valr%   c                 C  rD  rT   )rA  r;  r&   rE  r.   r.   r/   rW   ¼  rF  rc   rd   re   rf   )r)   r*   r+   r,   r-   r¼   r   r?  r@  rA  rg   r;   r@   rQ   rh   rW   r.   r.   r.   r/   r]   |  s4   
 ÿÿÿ
r]   c                   @  r�   )ÚCT_VerticalJcz:`w:vAlign` element, specifying vertical alignment of cell.r$   r   r&   N)r)   r*   r+   r,   r   r   r&   r-   r.   r.   r.   r/   rG  Ä  s
   
 ÿrG  c                   @  s*   e Zd ZU dZedeejd�Zded< dS )Ú	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-   r.   r.   r.   r/   rH  Ì  s
   
 ÿrH  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#   r0   rI   rl   rš   rž   rj   rX   r½   rB   rõ   r]   rG  rH  r.   r.   r.   r/   Ú<module>   sB    $	aq]	  mlH