o
    ýÞhñ  ã                   @  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r6d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                   @  sD   e Zd ZdZddd„Zdd
d„Zddd„Zd d!dd„Zd"dd„ZdS )#ÚCommentsz:Collection containing the comments added to this document.Úcomments_elmr   Úcomments_partr   c                 C  s   || _ || _d S ©N)Ú_comments_elmÚ_comments_part)Úselfr   r   © r   úM/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/comments.pyÚ__init__   s   
zComments.__init__ÚreturnúIterator[Comment]c                   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__   ó   zComments.__len__Ú ÚtextÚstrÚauthorÚinitialsú
str | Noner   c           
      C  s„   | j  ¡ }||_||_tj tjj¡|_	t
|| jƒ}|dkr |S t| d¡ƒ}t|ƒ}|jd }| |¡ |D ]}	|j|	d� q7|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Ú
paragraphsÚadd_runÚadd_paragraph)
r   r#   r%   r&   r   ÚcommentÚpara_text_iterÚfirst_para_textÚ
first_paraÚsr   r   r   r*   #   s   


zComments.add_commentÚ
comment_idúComment | Nonec                 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   Úget_comment_by_idr   r   )r   r<   r   r   r   r   ÚgetM   s   zComments.getN)r   r   r   r   )r   r   ©r   r   )r"   r"   r"   )r#   r$   r%   r$   r&   r'   r   r   )r<   r   r   r=   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r*   r?   r   r   r   r   r      s    


*r   c                      s˜   e Zd ZdZd"‡ fdd„Zd#d$‡ fdd„Zed%dd„ƒZejd&dd„ƒZed'dd„ƒZ	ed(dd„ƒZ
e
jd)dd„ƒZ
ed%dd„ƒZe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#   r$   Ústyleústr | ParagraphStyle | Noner   r
   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.
        NÚCommentText)rE   r6   Ú_prI   )r   r#   rI   Ú	paragraphrG   r   r   r6   e   s   zComment.add_paragraphc                 C  ó   | j jS )z}Read/write. The recorded author of this comment.

        This field is required but can be set to the empty string.
        ©rF   r%   r   r   r   r   r%   u   ó   zComment.authorÚvaluec                 C  ó   || j _d S r   rO   ©r   rQ   r   r   r   r%   }   r!   r   c                 C  rN   )z&The unique identifier of this comment.)rF   Úidr   r   r   r   r<   �   s   zComment.comment_idr'   c                 C  rN   )zÑRead/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.
        ©rF   r&   r   r   r   r   r&   †   s   zComment.initialsc                 C  rR   r   rU   rS   r   r   r   r&   �   r!   c                 C  s   d  dd„ | jD ƒ¡S )zßThe 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   ›   s   € zComment.text.<locals>.<genexpr>)Újoinr4   r   r   r   r   r#   “   s   zComment.textúdt.datetime | Nonec                 C  rN   )z€The date and time this comment was authored.

        This attribute is optional in the XML, returns |None| if not set.
        )rF   r0   r   r   r   r   Ú	timestamp�   rP   zComment.timestamp)r   r   r   r   )r"   N)r#   r$   rI   rJ   r   r
   )r   r$   )rQ   r$   r@   )r   r'   )rQ   r'   )r   rX   )rA   rB   rC   rD   r   r6   Úpropertyr%   Úsetterr<   r&   r#   rY   Ú__classcell__r   r   rG   r   r   S   s$    	r   )rD   Ú
__future__r   r,   r+   Útypingr   r   Údocx.blkcntnrr   Údocx.oxml.commentsr   r   Údocx.parts.commentsr   Údocx.styles.styler	   Údocx.text.paragraphr
   r   r   r   r   r   r   Ú<module>   s    B