a
    ]j                     @  s   d Z ddlmZ ddlZddlmZmZ ddlm	Z	 erlddl
mZmZ ddlmZ ddlmZ dd	lmZ G d
d dZG dd de	ZdS )z?Collection providing access to comments added to this document.    )annotationsN)TYPE_CHECKINGIterator)BlockItemContainer)
CT_CommentCT_Comments)CommentsPart)ParagraphStyle)	Paragraphc                   @  sb   e Zd ZdZdddddZddd	d
ZddddZddddddddZdddddZdS )Commentsz:Collection containing the comments added to this document.r   r   )comments_elmcomments_partc                 C  s   || _ || _d S N)_comments_elm_comments_part)selfr   r    r   I/var/www/html/assistant/venv/lib/python3.9/site-packages/docx/comments.py__init__   s    zComments.__init__zIterator[Comment]returnc                   s    fdd j jD S )z.Iterator over the comments in this collection.c                 3  s   | ]}t | jV  qd S r   )Commentr   ).0comment_elmr   r   r   	<genexpr>   s   z$Comments.__iter__.<locals>.<genexpr>)r   comment_lstr   r   r   r   __iter__   s    
zComments.__iter__intc                 C  s   t | jjS )z*The number of comments in this collection.)lenr   r   r   r   r   r   __len__   s    zComments.__len__ str
str | Noner   )textauthorinitialsr   c           
      C  s   | j  }||_||_tjtjj|_	t
|| j}|dkr@|S t|d}t|}|jd }|| |D ]}	|j|	d qn|S )a  Add a new comment to the document and return it.

        The comment is added to the end of the comments collection and is assigned a unique
        comment-id.

        If `text` is provided, it is added to the comment. This option provides for the common
        case where a comment contains a modest passage of plain text. Multiple paragraphs can be
        added using the `text` argument by separating their text with newlines (`"\\n"`).
        Between newlines, text is interpreted as it is in `Document.add_paragraph(text=...)`.

        The default is to place a single empty paragraph in the comment, which is the same
        behavior as the Word UI when you add a comment. New runs can be added to the first
        paragraph in the empty comment with `comments.paragraphs[0].add_run()` to adding more
        complex text with emphasis or images. Additional paragraphs can be added using
        `.add_paragraph()`.

        `author` is a required attribute, set to the empty string by default.

        `initials` is an optional attribute, set to the empty string by default. Passing |None|
        for the `initials` parameter causes that attribute to be omitted from the XML.
        r!   
r   r$   )r   add_commentr%   r&   dtdatetimenowtimezoneutcdater   r   itersplitnext
paragraphsZadd_runadd_paragraph)
r   r$   r%   r&   r   commentZpara_text_iterZfirst_para_textZ
first_parasr   r   r   r)   #   s    


zComments.add_commentzComment | None)
comment_idr   c                 C  s$   | j |}|dur t|| jS dS )zFReturn the comment identified by `comment_id`, or |None| if not found.N)r   Zget_comment_by_idr   r   )r   r7   r   r   r   r   getM   s    zComments.getN)r!   r!   r!   )	__name__
__module____qualname____doc__r   r   r    r)   r8   r   r   r   r   r      s   *r   c                      s   e Zd ZdZddd fddZd d	d
dd fddZed	dddZejd	dddZeddddZ	eddddZ
e
jddddZ
ed	dddZeddddZ  ZS )!r   as  Proxy for a single comment in the document.

    Provides methods to access comment metadata such as author, initials, and date.

    A comment is also a block-item container, similar to a table cell, so it can contain both
    paragraphs and tables and its paragraphs can contain rich text, hyperlinks and images,
    although the common case is that a comment contains a single paragraph of plain text like a
    sentence or phrase.

    Note that certain content like tables may not be displayed in the Word comment sidebar due to
    space limitations. Such "over-sized" content can still be viewed in the review pane.
    r   r   )r   r   c                   s   t  || || _d S r   )superr   _comment_elm)r   r   r   	__class__r   r   r   a   s    zComment.__init__r!   Nr"   zstr | ParagraphStyle | Noner
   )r$   styler   c                   s"   t  ||}|du rd|j_|S )aA  Return paragraph newly added to the end of the content in this container.

        The paragraph has `text` in a single run if present, and is given paragraph style `style`.
        When `style` is |None| or ommitted, the "CommentText" paragraph style is applied, which is
        the default style for comments.
        NZCommentText)r=   r4   _prA   )r   r$   rA   Z	paragraphr?   r   r   r4   e   s    zComment.add_paragraphr   c                 C  s   | j jS )z}Read/write. The recorded author of this comment.

        This field is required but can be set to the empty string.
        r>   r%   r   r   r   r   r%   u   s    zComment.author)valuec                 C  s   || j _d S r   rC   r   rD   r   r   r   r%   }   s    r   c                 C  s   | j jS )z&The unique identifier of this comment.)r>   idr   r   r   r   r7      s    zComment.comment_idr#   c                 C  s   | j jS )zRead/write. The recorded initials of the comment author.

        This attribute is optional in the XML, returns |None| if not set. Assigning |None| removes
        any existing initials from the XML.
        r>   r&   r   r   r   r   r&      s    zComment.initialsc                 C  s   || j _d S r   rG   rE   r   r   r   r&      s    c                 C  s   d dd | jD S )zThe text content of this comment as a string.

        Only content in paragraphs is included and of course all emphasis and styling is stripped.

        Paragraph boundaries are indicated with a newline (`"\\n"`)
        r'   c                 s  s   | ]}|j V  qd S r   r(   )r   pr   r   r   r          zComment.text.<locals>.<genexpr>)joinr3   r   r   r   r   r$      s    zComment.textzdt.datetime | Nonec                 C  s   | j jS )zThe date and time this comment was authored.

        This attribute is optional in the XML, returns |None| if not set.
        )r>   r/   r   r   r   r   	timestamp   s    zComment.timestamp)r!   N)r9   r:   r;   r<   r   r4   propertyr%   setterr7   r&   r$   rK   __classcell__r   r   r?   r   r   S   s"   	r   )r<   
__future__r   r+   r*   typingr   r   Zdocx.blkcntnrr   Zdocx.oxml.commentsr   r   Zdocx.parts.commentsr   Zdocx.styles.styler	   Zdocx.text.paragraphr
   r   r   r   r   r   r   <module>   s   B