
    >h+                    $   d 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 ddlmZ ddlmZmZ ddlmZmZmZmZ dd	lmZ er6dd
lmZ ddlmZ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( ddl)m*Z* ddl+m,Z,  G d de      Z- G d de
      Z.y
)z'|Document| and closely related objects.    )annotations)IOTYPE_CHECKINGIteratorListSequence)BlockItemContainer)
WD_SECTION)WD_BREAK)SectionSections)ElementProxyEmuInchesLength)RunN)CommentComments)CT_BodyCT_Document)DocumentPart)Settings)ParagraphStyle_TableStyle)Table)	Paragraphc                  r    e Zd ZdZd fdZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZdddZd ZdddZ	 	 d	 	 	 	 	 ddZ	e
j                  fd dZd!d"d	Zed#d
       Zed        Zed        Zd$dZed%d       Zed&d       Zd'dZed(d       Zed)d       Zed        Zed*d       Zed+d       Zed,d       Z xZS )-DocumentzWordprocessingML (WML) document.

    Not intended to be constructed directly. Use :func:`docx.Document` to open or create
    a document.
    c                V    t         t        |   |       || _        || _        d | _        y N)superr   __init___element_part_Document__body)selfelementpart	__class__s      N/var/www/html/bid_assistant/venv/lib/python3.12/site-packages/docx/document.pyr"   zDocument.__init__#   s'    h&w/
    c                    t        |t              r|gn|}|d   }|d   }| j                  j                  |||      }|j	                  ||j
                         |S )a  Add a comment to the document, anchored to the specified runs.

        `runs` can be a single `Run` object or a non-empty sequence of `Run` objects. Only the
        first and last run of a sequence are used, it's just more convenient to pass a whole
        sequence when that's what you have handy, like `paragraph.runs` for example. When `runs`
        contains a single `Run` object, that run serves as both the first and last run.

        A comment can be anchored only on an even run boundary, meaning the text the comment
        "references" must be a non-zero integer number of consecutive runs. The runs need not be
        _contiguous_ per se, like the first can be in one paragraph and the last in the next
        paragraph, but all runs between the first and the last will be included in the reference.

        The comment reference range is delimited by placing a `w:commentRangeStart` element before
        the first run and a `w:commentRangeEnd` element after the last run. This is why only the
        first and last run are required and why a single run can serve as both first and last.
        Word works out which text to highlight in the UI based on these range markers.

        `text` allows the contents of a simple comment to be provided in the call, providing for
        the common case where a comment is a single phrase or sentence without special formatting
        such as bold or italics. More complex comments can be added using the returned `Comment`
        object in much the same way as a `Document` or (table) `Cell` object, using methods like
        `.add_paragraph()`, .add_run()`, etc.

        The `author` and `initials` parameters allow that metadata to be set for the comment.
        `author` is a required attribute on a comment and is the empty string by default.
        `initials` is optional on a comment and may be omitted by passing |None|, but Word adds an
        `initials` attribute by default and we follow that convention by using the empty string
        when no `initials` argument is provided.
        r   )textauthorinitials)
isinstancer   commentsadd_commentmark_comment_range
comment_id)r&   runsr.   r/   r0   	first_runlast_runcomments           r*   r3   zDocument.add_comment)   sc    J $D#.vDG	8 --++fx+X 	$$Xw/A/ABr+   c                t    d|cxk  rdk  sn t        d|z        |dk(  rdnd|z  }| j                  ||      S )a  Return a heading paragraph newly added to the end of the document.

        The heading paragraph will contain `text` and have its paragraph style
        determined by `level`. If `level` is 0, the style is set to `Title`. If `level`
        is 1 (or omitted), `Heading 1` is used. Otherwise the style is set to `Heading
        {level}`. Raises |ValueError| if `level` is outside the range 0-9.
        r   	   z"level must be in range 0-9, got %dTitlez
Heading %d)
ValueErroradd_paragraph)r&   r.   levelstyles       r*   add_headingzDocument.add_headingZ   sE     EQAEIJJ A:<%+?!!$..r+   c                    | j                         }|j                         j                  t        j                         |S )z=Return newly |Paragraph| object containing only a page break.)r>   add_run	add_breakr   PAGE)r&   	paragraphs     r*   add_page_breakzDocument.add_page_breakg   s1    &&(	%%hmm4r+   c                :    | j                   j                  ||      S )a  Return paragraph newly added to the end of the document.

        The paragraph is populated with `text` and having paragraph style `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.
        )_bodyr>   )r&   r.   r@   s      r*   r>   zDocument.add_paragraphm   s     zz''e44r+   c                d    | j                         j                         }|j                  |||      S )a  Return new picture shape added in its own paragraph at end of the document.

        The picture contains the image at `image_path_or_stream`, scaled based on
        `width` and `height`. If neither width nor height is specified, the picture
        appears at its native size. If only one is specified, it is used to compute a
        scaling factor that is then applied to the unspecified dimension, preserving the
        aspect ratio of the image. The native size of the picture is calculated using
        the dots-per-inch (dpi) value specified in the image file, defaulting to 72 dpi
        if no value is specified, as is often the case.
        )r>   rC   add_picture)r&   image_path_or_streamwidthheightruns        r*   rK   zDocument.add_picturey   s/        "**,3UFCCr+   c                    | j                   j                  j                         }||_        t	        || j
                        S )zReturn a |Section| object newly added at the end of the document.

        The optional `start_type` argument must be a member of the :ref:`WdSectionStart`
        enumeration, and defaults to ``WD_SECTION.NEW_PAGE`` if not provided.
        )r#   bodyadd_section_break
start_typer   r$   )r&   rS   
new_sectPrs      r*   add_sectionzDocument.add_section   s5     ]]''99;
 *
z4::..r+   c                b    | j                   j                  ||| j                        }||_        |S )zAdd a table having row and column counts of `rows` and `cols` respectively.

        `style` may be a table style object or a table style name. If `style` is |None|,
        the table inherits the default table style of the document.
        )rI   	add_table_block_widthr@   )r&   rowscolsr@   tables        r*   rW   zDocument.add_table   s.     

$$T41B1BCr+   c                .    | j                   j                  S )zGA |Comments| object providing access to comments added to the document.)r$   r2   r&   s    r*   r2   zDocument.comments        zz"""r+   c                .    | j                   j                  S )zGA |CoreProperties| object providing Dublin Core properties of document.)r$   core_propertiesr]   s    r*   r`   zDocument.core_properties   s     zz)))r+   c                .    | j                   j                  S )zThe |InlineShapes| collection for this document.

        An inline shape is a graphical object, such as a picture, contained in a run of
        text and behaving like a character glyph, being flowed like other text in a
        paragraph.
        )r$   inline_shapesr]   s    r*   rb   zDocument.inline_shapes   s     zz'''r+   c                6    | j                   j                         S )zHGenerate each `Paragraph` or `Table` in this document in document order.)rI   iter_inner_contentr]   s    r*   rd   zDocument.iter_inner_content   s    zz,,..r+   c                .    | j                   j                  S )zThe |Paragraph| instances in the document, in document order.

        Note that paragraphs within revision marks such as ``<w:ins>`` or ``<w:del>`` do
        not appear in this list.
        )rI   
paragraphsr]   s    r*   rf   zDocument.paragraphs   s     zz$$$r+   c                    | j                   S )z+The |DocumentPart| object of this document.)r$   r]   s    r*   r(   zDocument.part   s     zzr+   c                :    | j                   j                  |       y)zSave this document to `path_or_stream`.

        `path_or_stream` can be either a path to a filesystem location (a string) or a
        file-like object.
        N)r$   save)r&   path_or_streams     r*   ri   zDocument.save   s     	

'r+   c                B    t        | j                  | j                        S )zD|Sections| object providing access to each section in this document.)r   r#   r$   r]   s    r*   sectionszDocument.sections   s     tzz22r+   c                .    | j                   j                  S )zDA |Settings| object providing access to the document-level settings.)r$   settingsr]   s    r*   rn   zDocument.settings   r^   r+   c                .    | j                   j                  S )zBA |Styles| object providing access to the styles in this document.)r$   stylesr]   s    r*   rp   zDocument.styles   s     zz   r+   c                .    | j                   j                  S )aP  All |Table| instances in the document, in document order.

        Note that only tables appearing at the top level of the document appear in this
        list; a table nested inside a table cell does not appear. A table within
        revision marks such as ``<w:ins>`` or ``<w:del>`` will also not appear in the
        list.
        )rI   tablesr]   s    r*   rr   zDocument.tables   s     zz   r+   c                    | j                   d   }|j                  xs t        d      }|j                  xs t        d      }|j                  xs t        d      }t        ||z
  |z
        S )zGA |Length| object specifying the space between margins in last section.r-   g      !@   )rl   
page_widthr   left_marginright_marginr   )r&   sectionru   rv   rw   s        r*   rX   zDocument._block_width   sc     --#''66#;
))6VAY++8vay:+l:;;r+   c                |    | j                   %t        | j                  j                  |       | _         | j                   S )z>The |_Body| instance containing the content for this document.)r%   _Bodyr#   rQ   r]   s    r*   rI   zDocument._body   s0     ;; 2 2D9DK{{r+   )r'   r   r(   r   ) r{   r{   )
r6   zRun | Sequence[Run]r.   
str | Noner/   strr0   r|   returnr   )r{   rt   )r.   r}   r?   int)r{   N)r.   r}   r@   zstr | ParagraphStyle | Noner~   r   )NN)rL   str | IO[bytes]rM   int | Length | NonerN   r   )rS   r
   r    )rY   r   rZ   r   r@   zstr | _TableStyle | None)r~   r   )r~   zIterator[Paragraph | Table])r~   zList[Paragraph])r~   r   )rj   r   )r~   r   )r~   r   )r~   zList[Table])r~   r   r~   rz   )__name__
__module____qualname____doc__r"   r3   rA   rG   r>   rK   r
   NEW_PAGErU   rW   propertyr2   r`   rb   rd   rf   r(   ri   rl   rn   rp   rr   rX   rI   __classcell__r)   s   @r*   r   r      s    !/!/ / 	/
 / 
/b/
5 &*&*	D-D #D $	D& 4>3F3F / # # * * ( (/ % %  ( 3 3 # # ! ! ! ! < <  r+   r   c                  ,     e Zd ZdZd fdZddZ xZS )rz   zoProxy for `<w:body>` element in this document.

    It's primary role is a container for document content.
    c                <    t         t        |   ||       || _        y r    )r!   rz   r"   rI   )r&   body_elmparentr)   s      r*   r"   z_Body.__init__   s    eT#Hf5
r+   c                :    | j                   j                          | S )zReturn this |_Body| instance after clearing it of all content.

        Section properties for the main document story, if present, are preserved.
        )rI   clear_contentr]   s    r*   r   z_Body.clear_content  s    
 	

  "r+   )r   r   r   zt.ProvidesStoryPartr   )r   r   r   r   r"   r   r   r   s   @r*   rz   rz      s    
r+   rz   )/r   
__future__r   typingr   r   r   r   r   docx.blkcntnrr	   docx.enum.sectionr
   docx.enum.textr   docx.sectionr   r   docx.sharedr   r   r   r   docx.text.runr   
docx.typestypestdocx.commentsr   r   docx.oxml.documentr   r   docx.parts.documentr   docx.settingsr   docx.styles.styler   r   
docx.tabler   docx.text.paragraphr   r   rz    r+   r*   <module>r      s_    . " > > , ( # * 9 9 /70&= -Z| Zz r+   