
    {i\1                        S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	J
r
  SSKJr  SS	KJr  S
SKJr  S
SKJrJrJrJr  S
SKJr  \(       a  SSKr " S S\\\\5      r " S S\5      rg)zProvide the Comment class.    )annotations)TYPE_CHECKINGAny   )API_PATH)ClientException
InvalidURL)cachedproperty   )CommentForest   )
RedditBase)FullnameMixinInboxableMixinThingModerationMixinUserContentMixin)RedditorNc                  4  ^  \ rS rSrSrSrSr\SS j5       r\	SS j5       r
\S 5       r\SS j5       r\SS	 j5       r\SS
 j5       r\R                   SS j5       r   S       SU 4S jjjr    SU 4S jjrS rU 4S jrS r  SS jrSS jrSrU =r$ )Comment   at  A class that represents a Reddit comment.

.. include:: ../../typical_attributes.rst

================= =================================================================
Attribute         Description
================= =================================================================
``author``        Provides an instance of :class:`.Redditor`.
``body``          The body of the comment, as Markdown.
``body_html``     The body of the comment, as HTML.
``created_utc``   Time the comment was created, represented in `Unix Time`_.
``distinguished`` Whether or not the comment is distinguished.
``edited``        Whether or not the comment has been edited.
``id``            The ID of the comment.
``is_submitter``  Whether or not the comment author is also the author of the
                  submission.
``link_id``       The submission ID that the comment belongs to.
``parent_id``     The ID of the parent comment (prefixed with ``t1_``). If it is a
                  top-level comment, this returns the submission ID instead
                  (prefixed with ``t3_``).
``permalink``     A permalink for the comment. :class:`.Comment` objects from the
                  inbox have a ``context`` attribute instead.
``replies``       Provides an instance of :class:`.CommentForest`.
``saved``         Whether or not the comment is saved.
``score``         The number of upvotes for the comment.
``stickied``      Whether or not the comment is stickied.
``submission``    Provides an instance of :class:`.Submission`. The submission that
                  the comment belongs to.
``subreddit``     Provides an instance of :class:`.Subreddit`. The subreddit that
                  the comment belongs to.
``subreddit_id``  The subreddit ID that the comment belongs to.
================= =================================================================

.. _unix time: https://en.wikipedia.org/wiki/Unix_time

z6This comment does not appear to be in the comment treeidc                    [         R                  " U 5      n UR                  S5      n[        U5      S-
  U:w  a  [	        U 5      eUS   $ ! [         a    [	        U 5      Sef = f)z*Get the ID of a comment from the full URL.commentsN   )r   
_url_partsindex
ValueErrorr	   len)urlpartscomment_indexs      T/home/james-whalen/.local/lib/python3.13/site-packages/praw/models/reddit/comment.pyid_from_urlComment.id_from_urlA   sj     %%c*	,!KK
3M u:>]*S/!Ry  	,S/t+	,s   A A"c                    [        U 5      $ )zProvide an instance of :class:`.CommentModeration`.

Example usage:

.. code-block:: python

    comment = reddit.comment("dkk4qjd")
    comment.mod.approve()

)CommentModerationselfs    r#   modComment.modN   s     !&&    c                H    U R                   R                  R                  S   $ )zReturn the class's kind.comment)_redditconfigkindsr(   s    r#   _kindComment._kind\   s     ||""((33r,   c                    U R                   R                  SS5      S   nXR                  R                  R                  S   :H  $ )z8Return ``True`` when the comment is a top-level comment._r   r   
submission)	parent_idsplitr/   r0   r1   )r)   parent_types     r#   is_rootComment.is_roota   s=     nn**3215ll1177EEEr,   c                    [        U R                  [        5      (       a%  [        U R                  U R                  5      U l        U R                  $ )a@  Provide an instance of :class:`.CommentForest`.

This property may return an empty list if the comment has not been refreshed
with :meth:`.refresh`

Sort order and reply limit can be set with the ``reply_sort`` and
``reply_limit`` attributes before replies are fetched, including any call to
:meth:`.refresh`:

.. code-block:: python

    comment.reply_sort = "new"
    comment.refresh()
    replies = comment.replies

.. note::

    The appropriate values for ``reply_sort`` include ``"confidence"``,
    ``"controversial"``, ``"new"``, ``"old"``, ``"q&a"``, and ``"top"``.

)
isinstance_replieslistr   r6   r(   s    r#   repliesComment.repliesg   s5    . dmmT**)$//4==IDM}}r,   c                    U R                   (       d.  U R                  R                  U R                  5       5      U l         U R                   $ )z?Return the :class:`.Submission` object this comment belongs to.)_submissionr/   r6   _extract_submission_idr(   s    r#   r6   Comment.submission   s9     #||66t7R7R7TUDr,   c                t    XR                   U R                  '   Xl        [        U S/ 5       H	  nXl        M     g)zFUpdate the :class:`.Submission` associated with the :class:`.Comment`.r@   N)_comments_by_idfullnamerC   getattrr6   )r)   r6   replys      r#   r6   rE      s5     59""4==1%T9b1E) 2r,   c                   > X#U4R                  S5      S:w  a  Sn[        U5      eSn/ U l        SU l        U(       a  X l        O U(       a  U R                  U5      U l        OSn[        TU ]  XUS9  g)z(Initialize a :class:`.Comment` instance.Nr   z8Exactly one of 'id', 'url', or '_data' must be provided.FT)_data_fetched)count	TypeErrorr>   rC   r   r$   super__init__)r)   redditr   r    rL   msgfetched	__class__s          r#   rQ   Comment.__init__   st     U!!$'1,LCC. G&&s+DGGw?r,   c                8  > US:X  a"  [         R                  " U R                  U5      nObUS:X  a;  US:X  a  / nO/U R                  R                  R	                  U5      R
                  nSnO!US:X  a  U R                  R                  U5      n[        TU ]!  X5        g)z)Objectify author, replies, and subreddit.authorr@    r>   	subredditN)	r   	from_datar/   	_objector	objectifychildrenrZ   rP   __setattr__)r)   	attributevaluerU   s      r#   r_   Comment.__setattr__   s      &&t||U;E)#{..88?HH"I+%LL**51EI-r,   c                    SU R                   ;   a  U R                  R                  SS5      S   $ U R                  R	                  SS5      S   $ )Ncontext/r   r   r5   )__dict__rd   rsplitlink_idr8   r(   s    r#   rD   Comment._extract_submission_id   sF    %<<&&sA.q11||!!#q)!,,r,   c                (  > U R                  5       nUS   nUS   (       d  SU R                   3n[        U5      eUS   S   S   n[        U 5      " U R                  US9nU R
                  R                  UR
                  5        [        TU ]!  5         g )Ndatar^   zNo data returned for comment r   )rL   )	_fetch_datarH   r   typer/   rf   updaterP   _fetch)r)   rk   rS   comment_dataotherrU   s        r#   ro   Comment._fetch   s    !F|J1$--AC!#&&J'*62T
4<<|<U^^,r,   c                $    S0 SU R                   04$ )Ninfor   )rH   r(   s    r#   _fetch_infoComment._fetch_info   s    rD$--000r,   c                |   U R                   U R                  R                  :X  a  U R                  $ U R                   U R                  R                  ;   a#  U R                  R                  U R                      $ [	        U R
                  U R                   R                  SS5      S   5      nU R                  Ul        U$ )a  Return the parent of the comment.

The returned parent will be an instance of either :class:`.Comment`, or
:class:`.Submission`.

If this comment was obtained through a :class:`.Submission`, then its entire
ancestry should be immediately available, requiring no extra network requests.
However, if this comment was obtained through other means, e.g.,
``reddit.comment("COMMENT_ID")``, or ``reddit.inbox.comment_replies``, then the
returned parent may be a lazy instance of either :class:`.Comment`, or
:class:`.Submission`.

Lazy comment example:

.. code-block:: python

    comment = reddit.comment("cklhv0f")
    parent = comment.parent()
    # 'replies' is empty until the comment is refreshed
    print(parent.replies)  # Output: []
    parent.refresh()
    print(parent.replies)  # Output is at least: [Comment(id="cklhv0f")]

.. warning::

    Successive calls to :meth:`.parent` may result in a network request per call
    when the comment is not obtained through a :class:`.Submission`. See below
    for an example of how to minimize requests.

If you have a deeply nested comment and wish to most efficiently discover its
top-most :class:`.Comment` ancestor you can chain successive calls to
:meth:`.parent` with calls to :meth:`.refresh` at every 9 levels. For example:

.. code-block:: python

    comment = reddit.comment("dkk4qjd")
    ancestor = comment
    refresh_counter = 0
    while not ancestor.is_root:
        ancestor = ancestor.parent()
        if refresh_counter % 9 == 0:
            ancestor.refresh()
        refresh_counter += 1
    print(f"Top-most Ancestor: {ancestor}")

The above code should result in 5 network requests to Reddit. Without the calls
to :meth:`.refresh` it would make at least 31 network requests.

r5   r   )r7   r6   rH   rG   r   r/   r8   rC   )r)   parents     r#   rx   Comment.parent   s    h >>T__555??">>T__<<<??224>>BBt~~';';C'CA'FG!__r,   c                   SU R                   ;   a   U R                  R                  SS5      S   nO;[        S   R	                  U R
                  R                  S9nU SU R                   3nSS0nS	U R                   ;   a  U R                  US
'   SU R                   ;   a  U R                  US'   U R                  R                  XS9S   R                  nU(       d  [        U R                  5      eSnUSS nU(       a  Ub  UR                  U R                  :w  ah  UR                  5       n[        U[         5      (       a  UR#                  UR$                  5        U(       a!  Uc  ML  UR                  U R                  :w  a  Mh  UR                  U R                  :w  a  [        U R                  5      eU R&                  b  UR                   S	 U R                   R)                  UR                   5        U H  nU R
                  Ul        M     U $ )zRefresh the comment's attributes.

If using :meth:`.Reddit.comment` this method must be called in order to obtain
the comment's replies.

Example usage:

.. code-block:: python

    comment = reddit.comment("dkk4qjd")
    comment.refresh()

rd   ?r   r   r6   )r   z_/d   reply_limitlimit
reply_sortsort)paramsNrC   )rf   rd   r8   r   formatr6   r   r}   r   r/   getr^   r   MISSING_COMMENT_MESSAGEpopr=   r   extendr>   rC   rn   )r)   comment_pathpathr   comment_listr.   queuerJ   s           r#   refreshComment.refresh  s    %<<--c15a8LL)00DOO4F4F0GD"V2dggY/L S!DMM)"..F7O4==(!__F6N||'''DQGPP!$">">?? QGJJ$'',AiikG'7++W--. GJJ$'',A
 :: !$">">??'  /W--.!E#E "r,   )r>   rC   r   )r    strreturnr   )r   z,praw.models.reddit.comment.CommentModeration)r   bool)r   r   )r   praw.models.Submission)r6   r   )NNN)rR   zpraw.Redditr   
str | Noner    r   rL   zdict[str, Any] | None)r`   r   ra   z6str | Redditor | CommentForest | praw.models.Subreddit)r   z Comment | praw.models.Submission)r   r   )__name__
__module____qualname____firstlineno____doc__r   	STR_FIELDstaticmethodr$   r
   r*   propertyr2   r:   r@   r6   setterrQ   r_   rD   ro   ru   rx   r   __static_attributes____classcell__)rU   s   @r#   r   r      s)   #J WI
 
 ' ' 4 4 F F
  4     * * '+@@ @ 	@
 %@ @,.. F.$-
1=	)=~/ /r,   r   c                  ,    \ rS rSrSrSrSS jrS rSrg)	r'   i?  zProvide a set of functions pertaining to :class:`.Comment` moderation.

Example usage:

.. code-block:: python

    comment = reddit.comment("dkk4qjd")
    comment.mod.approve()

removal_comment_messagec                    Xl         g)z^Initialize a :class:`.CommentModeration` instance.

:param comment: The comment to moderate.

Nthing)r)   r.   s     r#   rQ   CommentModeration.__init__M  s	     
r,   c                    [         S   nU R                  R                  R                  USU R                  R                  0S9  g)zUncollapse a :class:`.Comment` that has been collapsed by Crowd Control.

Example usage:

.. code-block:: python

    # Uncollapse a comment:
    comment = reddit.comment("dkk4qjd")
    comment.mod.show()

show_commentr   )rk   N)r   r   r/   postrH   )r)   r    s     r#   showCommentModeration.showU  s:     ~&

41D1D*EFr,   r   N)r.   zpraw.models.Comment)	r   r   r   r   r   REMOVAL_MESSAGE_APIrQ   r   r    r,   r#   r'   r'   ?  s    	 4Gr,   r'   )r   
__future__r   typingr   r   constr   
exceptionsr   r	   
util.cacher
   comment_forestr   baser   mixinsr   r   r   r   redditorr   praw.modelsprawr   r'   r   r,   r#   <module>r      sW      " %  5 ( *   dn.z dN	$G, $Gr,   