HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/docx/__pycache__/table.cpython-310.pyc
o

$we�7�@sdZddlmZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZerTddlmZdd	lmZmZdd
lmZmZddlmZddlmZGd
d�de�ZGdd�de	�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#dS)z-The |Table| object and related proxy classes.�)�annotations)�
TYPE_CHECKING�List�Tuple�overload)�BlockItemContainer)�
WD_STYLE_TYPE)�ST_Merge)�Inches�Parented�lazyproperty)�types)�WD_TABLE_ALIGNMENT�WD_TABLE_DIRECTION)�CT_Tbl�CT_TblPr)�Length)�_TableStylecseZdZdZd;�fdd�Zd<d
d�Zdd
�Zed=dd��Zej	d>dd��Zed?dd��Z
e
j	d@dd��Z
dAdd�ZdBd d!�Ze
d"d#��ZdCd$d%�Ze
dDd'd(��ZedEd*d+��Zej	dFd-d+��Zed.d/��ZedGd1d2��Zej	dHd3d2��ZedId4d5��Zed6d7��ZedJd9d:��Z�ZS)K�Tablez7Proxy class for a WordprocessingML ``<w:tbl>`` element.�tblr�parent�t.StoryChildc� tt|��|�||_|_dS�N)�superr�__init__�_element�_tbl��selfrr��	__class__��C/home/arjun/projects/env/lib/python3.10/site-packages/docx/table.pyr�zTable.__init__�widthrcCs<|jj}|��}||_|jjD]	}|��}||_qt||�S)zIReturn a |_Column| object of `width`, newly added rightmost to the table.)r�tblGrid�add_gridCol�w�tr_lst�add_tcr%�_Column)rr%r&�gridCol�tr�tcr"r"r#�
add_columns
zTable.add_columncCs6|j}|��}|jjD]
}|��}|j|_qt||�S)z?Return a |_Row| instance, newly added bottom-most to the table.)r�add_trr&�gridCol_lstr*r(r%�_Row)rrr-r,r.r"r"r#�add_row%s

z
Table.add_row�return�WD_TABLE_ALIGNMENT | NonecC�|jjS)aRead/write.

        A member of :ref:`WdRowAlignment` or None, specifying the positioning of this
        table between the page margins. |None| if no setting is specified, causing the
        effective value to be inherited from the style hierarchy.
        ��_tblPr�	alignment�rr"r"r#r9.�zTable.alignment�valuecC�||j_dSrr7�rr<r"r"r#r98��boolcCr6)a|True| if column widths can be automatically adjusted to improve the fit of
        cell contents.

        |False| if table layout is fixed. Column widths are adjusted in either case if
        total column width exceeds page width. Read/write boolean.
        �r8�autofitr:r"r"r#rB<r;z
Table.autofitcCr=rrAr>r"r"r#rBFr?�row_idx�int�col_idx�_CellcCs|||j}|j|S)zb|_Cell| at `row_idx`, `col_idx` intersection.

        (0, 0) is the top, left-most cell.
        ��
_column_count�_cells)rrCrE�cell_idxr"r"r#�cellJs
z
Table.cell�
column_idx�List[_Cell]cs*|j�t|t��|j�}�fdd�|D�S)z>Sequence of cells in the column at `column_idx` in this table.csg|]}�|�qSr"r")�.0�idx��cellsr"r#�
<listcomp>Vsz&Table.column_cells.<locals>.<listcomp>)rI�range�lenrH)rrL�idxsr"rPr#�column_cellsRszTable.column_cellscC�t|j|�S)zG|_Columns| instance representing the sequence of columns in this table.)�_Columnsrr:r"r"r#�columnsX�z
Table.columnscCs$|j}||}||}|j||�S)z8Sequence of cells in the row at `row_idx` in this table.rG)rrC�column_count�start�endr"r"r#�	row_cells]szTable.row_cells�_RowscCrW)z?|_Rows| instance containing the sequence of rows in this table.)r_rr:r"r"r#�rowsdrZz
Table.rows�_TableStyle | NonecCs|jj}|j�|tj�S)am|_TableStyle| object representing the style applied to this table.

        Read/write. The default table style for the document (often `Normal Table`) is
        returned if the table has no directly-applied style. Assigning |None| to this
        property removes any directly-applied table style causing it to inherit the
        default table style of the document.

        Note that the style name of a table style differs slightly from that displayed
        in the user interface; a hyphen, if it appears, must be removed. For example,
        `Light Shading - Accent 1` becomes `Light Shading Accent 1`.
        )r�tblStyle_val�part�	get_styler�TABLE)r�style_idr"r"r#�styleis
zTable.style�
style_or_namecCs|j�|tj�}||j_dSr)rc�get_style_idrrerrb)rrhrfr"r"r#rgyscCs|S)aProvide child objects with reference to the |Table| object they belong to,
        without them having to know their direct parent is a |Table| object.

        This is the terminus of a series of `parent._table` calls from an arbitrary
        child through its ancestors.
        r"r:r"r"r#�table~szTable.table�WD_TABLE_DIRECTION | NonecCr6)z�Member of :ref:`WdTableDirection` indicating cell-ordering direction.

        For example: `WD_TABLE_DIRECTION.LTR`. |None| indicates the value is inherited
        from the style hierarchy.
        �r�bidiVisual_valr:r"r"r#�table_direction�szTable.table_directioncCr=rrlr>r"r"r#rn�r?cCst|j}g}|j��D]-}t|j�D]%}|jtjkr"|�||�q|dkr.|�|d�q|�t	||��qq
|S)z�A sequence of |_Cell| objects, one for each cell of the layout grid.

        If the table contains a span, one or more |_Cell| object references are
        repeated.
        r���)
rHr�iter_tcsrS�	grid_span�vMerger	�CONTINUE�appendrF)r�	col_countrQr.�
grid_span_idxr"r"r#rI�s�zTable._cellscCr6)z)The number of grid columns in this table.)rrur:r"r"r#rH��zTable._column_countrcCr6r)r�tblPrr:r"r"r#r8�szTable._tblPr)rrrr)r%r)r4r5)r<r5)r4r@)r<r@)rCrDrErDr4rF)rLrDr4rM)rCrDr4rM)r4r_)r4ra)rhra)r4rk)r<rk)r4rM)r4r)�__name__�
__module__�__qualname__�__doc__rr/r3�propertyr9�setterrBrKrVrrYr^r`rgrjrnrIrHr8�
__classcell__r"r"r r#rsH

			




	
rcs�eZdZdZ�fdd�Zd�fdd�	Z�fdd	�Zd
d�Ze�fdd
��Z	e�fdd��Z
eddd��Zejdd��Zedd��Z
e
jdd��Z
edd��Zejdd��Z�ZS)rFzTable cell.cs"tt|��||�||_|_dSr)rrFr�_tcr)rr.rr r"r#r�sz_Cell.__init__�Ncstt|��||�S)a�Return a paragraph newly added to the end of the content in this cell.

        If present, `text` is added to the paragraph in a single run. If specified, the
        paragraph style `style` is applied. If `style` is not specified or is |None|,
        the result is as though the 'Normal' style was applied. Note that the formatting
        of text in a cell can be influenced by the table style. `text` can contain tab
        (``\t``) characters, which are converted to the appropriate XML form for a tab.
        `text` can also include newline (``\n``) or carriage return (``\r``)
        characters, each of which is converted to a line break.
        )rrF�
add_paragraph)r�textrgr r"r#r��sz_Cell.add_paragraphcs8|jdur|jntd�}tt|��|||�}|��|S)a
Return a table newly added to this cell after any existing cell content,
        having `rows` rows and `cols` columns.

        An empty paragraph is added after the table because Word requires a paragraph
        element as the last element in every cell.
        N�)r%r
rrF�	add_tabler�)rr`�colsr%rjr r"r#r��sz_Cell.add_tablecCs$|j|j}}|�|�}t||j�S)z�Return a merged cell created by spanning the rectangular region having this
        cell and `other_cell` as diagonal corners.

        Raises |InvalidSpanError| if the cells do not define a rectangular region.
        )r��mergerF�_parent)r�
other_cellr.�tc_2�	merged_tcr"r"r#r��s
z_Cell.mergec�tt|�jS)z�List of paragraphs in the cell.

        A table cell is required to contain at least one block-level element and end
        with a paragraph. By default, a new cell contains a single paragraph. Read-only
        )rrF�
paragraphsr:r r"r#r��sz_Cell.paragraphscr�)zRList of tables in the cell, in the order they appear.

        Read-only.
        )rrF�tablesr:r r"r#r��sz_Cell.tablesr4�strcCsd�dd�|jD��S)z�The entire contents of this cell as a string of text.

        Assigning a string to this property replaces all existing content with a single
        paragraph containing the assigned text in a single run.
        �
css�|]}|jVqdSr)r�)rN�pr"r"r#�	<genexpr>�s�z_Cell.text.<locals>.<genexpr>)�joinr�r:r"r"r#r��sz
_Cell.textcCs(|j}|��|��}|��}||_dS)z�Write-only.

        Set entire contents of cell to the string `text`. Any existing content or
        revisions are replaced.
        N)r��
clear_content�add_p�add_rr�)rr�r.r��rr"r"r#r��s

cCs|jj}|dur
dS|jS)aMember of :ref:`WdCellVerticalAlignment` or None.

        A value of |None| indicates vertical alignment for this cell is inherited.
        Assigning |None| causes any explicitly defined vertical alignment to be removed,
        restoring inheritance.
        N)r�tcPr�
vAlign_val)rr�r"r"r#�vertical_alignmentsz_Cell.vertical_alignmentcCs|j��}||_dSr)r�get_or_add_tcPrr�)rr<r�r"r"r#r�s

cCr6)zEThe width of this cell in EMU, or |None| if no explicit width is set.�r�r%r:r"r"r#r%rwz_Cell.widthcCr=rr�r>r"r"r#r%r?)r�N)r4r�)ryrzr{r|rr�r�r�r}r�r�r�r~r�r%rr"r"r r#rF�s,





rFcs^eZdZdZ�fdd�Zedd��Zedd��Zedd	��Zej	d
d	��Zedd��Z
�ZS)
r+z
Table column.c�tt|��|�||_dSr)rr+r�_gridCol)rr,rr r"r#r"�
z_Column.__init__cC�t|j�|j��S)zDSequence of |_Cell| instances corresponding to cells in this column.)�tuplerjrV�_indexr:r"r"r#rQ&�z
_Column.cellscCr6)z7Reference to the |Table| object this column belongs to.�r�rjr:r"r"r#rj+rwz
_Column.tablecCr6)zGThe width of this column in EMU, or |None| if no explicit width is set.�r�r(r:r"r"r#r%0rwz
_Column.widthcCr=rr�r>r"r"r#r%5r?cCr6)z6Index of this column in its table, starting from zero.)r��gridCol_idxr:r"r"r#r�9rwz_Column._index)ryrzr{r|rr}rQrjr%r~r�rr"r"r r#r+s



r+csPeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zed
d��Z	edd
��Z
�ZS)rXz�Sequence of |_Column| instances corresponding to the columns in a table.

    Supports ``len()``, iteration and indexed access.
    cr�r)rrXrrrr r"r#rEr�z_Columns.__init__cCs8z|j|}Wntyd|}t|��wt||�S)z*Provide indexed access, e.g. 'columns[0]'.z!column index [%d] is out of range)�_gridCol_lst�
IndexErrorr+)rrOr,�msgr"r"r#�__getitem__Is�
z_Columns.__getitem__ccs�|jD]}t||�VqdSr)r�r+)rr,r"r"r#�__iter__Rs�
�z_Columns.__iter__cCs
t|j�Sr)rTr�r:r"r"r#�__len__Vs
z_Columns.__len__cCr6)zBReference to the |Table| object this column collection belongs to.r�r:r"r"r#rjYrwz_Columns.tablecCs|jj}|jS)zfSequence containing ``<w:gridCol>`` elements for this table, each
        representing a table column.)rr&r1)rr&r"r"r#r�^sz_Columns._gridCol_lst)ryrzr{r|rr�r�r�r}rjr�rr"r"r r#rX?s	
rXcszeZdZdZ�fdd�Zeddd��Zedd	��Zejd
d	��Zedd��Z	e	jd
d��Z	edd��Z
edd��Z�ZS)r2z
Table row.crr)rr2r�_trr)rr-rr r"r#rir$z
_Row.__init__r4�Tuple[_Cell]cCr�)zASequence of |_Cell| instances corresponding to cells in this row.)r�rjr^r�r:r"r"r#rQmr�z
_Row.cellscCr6)znReturn a |Length| object representing the height of this cell, or |None| if
        no explicit height is set.�r��trHeight_valr:r"r"r#�heightr�z_Row.heightcCr=rr�r>r"r"r#r�xr?cCr6)z�Return the height rule of this cell as a member of the :ref:`WdRowHeightRule`
        enumeration, or |None| if no explicit height_rule is set.�r��trHeight_hRuler:r"r"r#�height_rule|r�z_Row.height_rulecCr=rr�r>r"r"r#r��r?cCr6)z4Reference to the |Table| object this row belongs to.r�r:r"r"r#rj�rwz
_Row.tablecCr6)z3Index of this row in its table, starting from zero.)r��tr_idxr:r"r"r#r��rwz_Row._index)r4r�)
ryrzr{r|rr}rQr�r~r�rjr�rr"r"r r#r2fs"




r2csbeZdZdZ�fdd�Zeddd	��Zeddd	��Zddd	�Zdd�Zdd�Ze	dd��Z
�ZS)r_z�Sequence of |_Row| objects corresponding to the rows in a table.

    Supports ``len()``, iteration, indexed access, and slicing.
    cr�r)rr_rrrr r"r#r�r�z_Rows.__init__rOrDr4r2cC�dSrr"�rrOr"r"r#r���z_Rows.__getitem__�slice�
List[_Row]cCr�rr"r�r"r"r#r��r��int | slice�_Row | List[_Row]cCst|�|S)z7Provide indexed access, (e.g. `rows[0]` or `rows[1:3]`))�listr�r"r"r#r��r?cs�fdd��jjD�S)Nc3s�|]}t|��VqdSr)r2)rNr-r:r"r#r��s�z!_Rows.__iter__.<locals>.<genexpr>)rr)r:r"r:r#r��sz_Rows.__iter__cCst|jj�Sr)rTrr)r:r"r"r#r��sz
_Rows.__len__cCr6)z?Reference to the |Table| object this row collection belongs to.r�r:r"r"r#rj�rwz_Rows.table)rOrDr4r2)rOr�r4r�)rOr�r4r�)ryrzr{r|rrr�r�r�r}rjrr"r"r r#r_�s
r_N)$r|�
__future__r�typingrrrr�
docx.blkcntnrr�docx.enum.styler�docx.oxml.simpletypesr	�docx.sharedr
rr�docxr
�t�docx.enum.tablerr�docx.oxml.tablerrr�docx.styles.stylerrrFr+rXr2r_r"r"r"r#�<module>s(m '+