Ë
    Fü´j×2  ã            	      óØ   — d Z ddlmZ ddlmZmZ ddl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mZmZmZ dd	lmZ dd
lmZ er
ddlZddlmZ  G d„ deeeee«      Z G d„ de«      Zy)zProvide the Comment class.é    )Úannotations)ÚTYPE_CHECKINGÚAny)ÚAPI_PATH)ÚClientExceptionÚ
InvalidURL)ÚCommentForest)Ú
RedditBase)ÚCreatedMixinÚFullnameMixinÚInboxableMixinÚThingModerationMixinÚUserContentMixin)ÚRedditor)ÚcachedpropertyN)Úmodelsc                  ó   ‡ — e Zd ZdZdZdZedd„«       Zedd„«       Z	e
dd„«       Ze
dd„«       Ze
dd„«       Ze
dd	„«       Zej                  dd
„«       Z	 	 	 d	 	 	 	 	 	 	 	 	 dˆ fd„Z	 	 	 	 	 	 dˆ fd„Zdd„Zdˆ fd„Zdd„Z	 	 dd„Zdd„Zˆ xZS ) ÚCommentaº  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.
    ``likes``         The user's current vote status on the comment: ``True`` if
                      upvoted, ``False`` if downvoted, and ``None`` if not voted or not
                      logged in.
    ``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                óÄ   — t        j                  | «      }	 |j                  d«      }t        |«      dz
  |k7  rt	        | «      ‚|d   S # t        $ r t	        | «      d‚w xY w)z*Get the ID of a comment from the full URL.ÚcommentsNé   éÿÿÿÿ)r
   Ú
_url_partsÚindexÚ
ValueErrorr   Úlen)ÚurlÚpartsÚcomment_indexs      úX/root/workspace/ytshorts/venv/lib/python3.12/site-packages/praw/models/reddit/comment.pyÚid_from_urlzComment.id_from_urlF   sj   € ô ×%Ñ% cÓ*ˆð	,Ø!ŸK™K¨
Ó3ˆMô ˆu‹:˜‰>˜]Ò*Ü˜S“/Ð!Ø�R‰yÐøô ò 	,Ü˜S“/ tÐ+ð	,ús   —A	 Á	Ac                ó   — t        | «      S )zÈProvide an instance of :class:`.CommentModeration`.

        Example usage:

        .. code-block:: python

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

        )ÚCommentModeration©Úselfs    r!   ÚmodzComment.modS   s   € ô ! Ó&Ð&ó    c                óH   — | j                   j                  j                  d   S )zThe class's kind.Úcomment)Ú_redditÚconfigÚkindsr%   s    r!   Ú_kindzComment._kinda   s   € ð �|‰|×"Ñ"×(Ñ(¨Ñ3Ð3r(   c                óŒ   — | j                   j                  dd«      d   }|| j                  j                  j                  d   k(  S )z1``True`` when the comment is a top-level comment.Ú_é   r   Ú
submission)Ú	parent_idÚsplitr+   r,   r-   )r&   Úparent_types     r!   Úis_rootzComment.is_rootf   s?   € ð —n‘n×*Ñ*¨3°Ó2°1Ñ5ˆØ˜dŸl™l×1Ñ1×7Ñ7¸ÑEÑEÐEr(   c                ó˜   — t        | j                  t        «      r%t        | j                  | j                  «      | _        | j                  S )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	   r2   r%   s    r!   ÚreplieszComment.repliesl   s2   € ô. �d—m‘m¤TÔ*Ü)¨$¯/©/¸4¿=¹=ÓIˆDŒMØ�}‰}Ðr(   c                óŽ   — | j                   s.| j                  j                  | j                  «       «      | _         | j                   S )z8The :class:`.Submission` object this comment belongs to.)Ú_submissionr+   r2   Ú_extract_submission_idr%   s    r!   r2   zComment.submission‡   s9   € ð ×ÒØ#Ÿ|™|×6Ñ6°t×7RÑ7RÓ7TÓUˆDÔØ×ÑÐr(   c                óv   — | |j                   | j                  <   || _        t        | dg «      D ]	  }||_        Œ y)zFUpdate the :class:`.Submission` associated with the :class:`.Comment`.r;   N)Ú_comments_by_idÚfullnamer=   Úgetattrr2   )r&   r2   Úreplys      r!   r2   zComment.submissionŽ   s@   € ð 59ˆ
×"Ñ" 4§=¡=Ñ1Ø%ˆÔÜ˜T 9¨bÓ1ò 	*ˆEØ)ˆEÕñ	*r(   c                óÞ   •— t        d„ |||fD «       «      dk7  rd}t        |«      ‚d}g | _        d| _        |r|| _        n|r| j                  |«      | _        nd}t        ‰| �  |||¬«       y)z(Initialize a :class:`.Comment` instance.c              3  ó&   K  — | ]	  }|€Œd–— Œ y ­w)Nr1   © )Ú.0Úvalues     r!   ú	<genexpr>z#Comment.__init__.<locals>.<genexpr>ž   s   è ø€ ÒD�U°%Ñ2CŒqÑDùs   ‚Šr1   z8Exactly one of 'id', 'url', or '_data' must be provided.FNT)Ú_dataÚ_fetched)ÚsumÚ	TypeErrorr9   r=   r   r"   ÚsuperÚ__init__)r&   Úredditr   r   rJ   ÚmsgÚfetchedÚ	__class__s          €r!   rO   zComment.__init__–   sz   ø€ ô ÑD˜r 3¨Ð.ÔDÓDÈÒIØLˆCÜ˜C“.Ð ØˆØˆŒØˆÔÙØˆD�GÙØ×&Ñ& sÓ+ˆD�GàˆGÜ‰Ñ˜ u°wÐÕ?r(   c                ó<  •— |dk(  r!t        j                  | j                  |«      }ne|dk(  r@|dk(  rdn%| j                  j                  j	                  |¬«      }|€g n|j
                  }d}n |dk(  r| j                  j                  |«      }t        ‰| �!  ||«       y)z)Objectify author, replies, and subreddit.Úauthorr;   Ú N©Údatar9   Ú	subreddit)	r   Ú	from_datar+   Ú	_objectorÚ	objectifyÚchildrenrY   rN   Ú__setattr__)r&   Ú	attributerH   ÚlistingrS   s       €r!   r^   zComment.__setattr__¬   s’   ø€ ð ˜Ò Ü×&Ñ& t§|¡|°UÓ;‰EØ˜)Ò#Ø#(¨B¢;™4°D·L±L×4JÑ4J×4TÑ4TÐZ_Ð4TÓ4`ˆGØ!˜/‘B¨w×/?Ñ/?ˆEØ"‰IØ˜+Ò%Ø—L‘L×*Ñ*¨5Ó1ˆEÜ‰Ñ˜I uÕ-r(   c                óš   — d| j                   v r| j                  j                  dd«      d   S | j                  j	                  dd«      d   S )NÚcontextú/r   r1   r0   )Ú__dict__rb   ÚrsplitÚlink_idr4   r%   s    r!   r>   zComment._extract_submission_id¼   sF   € Ø˜Ÿ™Ñ%Ø—<‘<×&Ñ& s¨AÓ.¨qÑ1Ð1Ø�|‰|×!Ñ! # qÓ)¨!Ñ,Ð,r(   c                ó$  •— | j                  «       }|d   }|d   sd| j                  › �}t        |«      ‚|d   d   d   } t        | «      | j                  |¬«      }| j
                  j                  |j
                  «       t        ‰| �!  «        y )NrX   r]   zNo data returned for comment r   )rJ   )	Ú_fetch_datarA   r   Útyper+   rd   ÚupdaterN   Ú_fetch)r&   rX   rQ   Úcomment_dataÚotherrS   s        €r!   rk   zComment._fetchÁ   s‡   ø€ Ø×ÑÓ!ˆØ�F‰|ˆà�JÒØ1°$·-±-°ÐAˆCÜ! #Ó&Ð&à˜JÑ'¨Ñ*¨6Ñ2ˆØ”�T“
˜4Ÿ<™<¨|Ô<ˆØ�‰×Ñ˜UŸ^™^Ô,Ü‰‰Õr(   c                ó$   — di d| j                   ifS )NÚinfor   )rA   r%   s    r!   Ú_fetch_infozComment._fetch_infoÎ   s   € Ø�r˜D $§-¡-Ð0Ð0Ð0r(   c                óv  — | j                   | j                  j                  k(  r| j                  S | j                   | j                  j                  v r#| j                  j                  | j                      S t	        | j
                  | j                   j                  dd«      d   «      }| j                  |_        |S )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

            ancestor = reddit.comment("dkk4qjd")
            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.

        r0   r1   )r3   r2   rA   r@   r   r+   r4   r=   )r&   Úparents     r!   rr   zComment.parentÑ   s‹   € ðf �>‰>˜TŸ_™_×5Ñ5Ò5Ø—?‘?Ð"à�>‰>˜TŸ_™_×<Ñ<Ñ<à—?‘?×2Ñ2°4·>±>ÑBÐBä˜Ÿ™ t§~¡~×';Ñ';¸CÀÓ'CÀAÑ'FÓGˆØ!Ÿ_™_ˆÔØˆr(   c                óä  — d| j                   v r | j                  j                  dd«      d   }n>t        d   j	                  | j
                  j                  ¬«      }|› d| j                  › �}ddi}d	| j                   v r| j                  |d
<   d| j                   v r| j                  |d<   | j                  j                  ||¬«      d   j                  }|st        | j                  «      ‚d}|dd }|ru|�|j                  | j                  k7  rZ|j                  «       }t        |t         «      r|j#                  |j$                  «       |r|€Œ@|j                  | j                  k7  rŒZ|�|j                  | j                  k7  rt        | j                  «      ‚| j&                  �|j                   d= | j                   j)                  |j                   «       |D ]  }| j
                  |_        Œ | S )a)  Refresh 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()

        rb   ú?r1   r   r2   )r   z_/éd   Úreply_limitÚlimitÚ
reply_sortÚsort)ÚparamsNr=   )rd   rb   r4   r   Úformatr2   r   rv   rx   r+   Úgetr]   r   ÚMISSING_COMMENT_MESSAGEÚpopr8   r   Úextendr9   r=   rj   )r&   Úcomment_pathÚpathrz   Úcomment_listr*   ÚqueuerC   s           r!   ÚrefreshzComment.refresh  s·  € ð ˜Ÿ™Ñ%ØŸ<™<×-Ñ-¨c°1Ó5°aÑ8‰Lä˜LÑ)×0Ñ0°D·O±O×4FÑ4FÐ0ÓGˆDØ"˜V 2 d§g¡g YÐ/ˆLð )2°3Ð'7ˆØ˜DŸM™MÑ)Ø"×.Ñ.ˆF�7‰OØ˜4Ÿ=™=Ñ(Ø!Ÿ_™_ˆF�6‰NØ—|‘|×'Ñ'¨¸VÐ'ÓDÀQÑG×PÑPˆÙÜ! $×">Ñ">Ó?Ð?ð ˆØ™Q�ˆÙ˜˜¨G¯J©J¸$¿'¹'Ò,AØ—i‘i“kˆGÜ˜'¤7Ô+Ø—‘˜W×-Ñ-Ô.ñ ˜™¨G¯J©J¸$¿'¹'Ó,Að
 ˆ?˜gŸj™j¨D¯G©GÒ3Ü! $×">Ñ">Ó?Ð?à×ÑÐ'Ø× Ñ  Ð/Ø�‰×Ñ˜W×-Ñ-Ô.à!ò 	/ˆEØ#Ÿ™ˆEÕð	/àˆr(   )r   ÚstrÚreturnr…   )r†   r$   )r†   r…   )r†   Úbool)r†   r	   )r†   úmodels.Submission)r2   rˆ   r†   ÚNone)NNN)
rP   zpraw.Redditr   ú
str | Noner   rŠ   rJ   zdict[str, Any] | Noner†   r‰   )r_   r…   rH   r   r†   r‰   ©r†   r‰   )r†   z tuple[str, dict, dict[str, str]])r†   zComment | models.Submission)r†   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r}   Ú	STR_FIELDÚstaticmethodr"   r   r'   Úpropertyr.   r6   r;   r2   ÚsetterrO   r^   r>   rk   rp   rr   r„   Ú__classcell__)rS   s   @r!   r   r      s2  ø„ ñ&ðP WÐØ€Iàò
ó ð
ð ò'ó ð'ð ò4ó ð4ð òFó ðFð
 òó ðð4 ò ó ð ð ×Ñò*ó ð*ð ØØ'+ð@àð@ð ð@ð ð	@ð
 %ð@ð 
õ@ð,.àð.ð ð.ð 
õ	.ó -õ
ó1ð<à	$ó<÷|/r(   r   c                  ó$   — e Zd ZdZdZdd„Zdd„Zy)r$   zÇProvide a set of functions pertaining to :class:`.Comment` moderation.

    Example usage:

    .. code-block:: python

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

    Úremoval_comment_messagec                ó   — || _         y)znInitialize a :class:`.CommentModeration` instance.

        :param comment: The comment to moderate.

        N)Úthing)r&   r*   s     r!   rO   zCommentModeration.__init__O  s   € ð ˆ�
r(   c                ó�   — t         d   }| j                  j                  j                  |d| j                  j                  i¬«       y)zþUncollapse 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   rW   N)r   r˜   r+   ÚpostrA   )r&   r   s     r!   ÚshowzCommentModeration.showW  s:   € ô �~Ñ&ˆà�
‰
×Ñ×Ñ ¨4°·±×1DÑ1DÐ*EÐÕFr(   N)r*   zmodels.Commentr†   r‰   r‹   )rŒ   r�   rŽ   r�   ÚREMOVAL_MESSAGE_APIrO   rœ   rF   r(   r!   r$   r$   A  s   „ ñ	ð 4ÐóôGr(   r$   )r�   Ú
__future__r   Útypingr   r   Ú
praw.constr   Úpraw.exceptionsr   r   Úpraw.models.comment_forestr	   Úpraw.models.reddit.baser
   Úpraw.models.reddit.mixinsr   r   r   r   r   Úpraw.models.reddit.redditorr   Úpraw.util.cacher   Úprawr   r   r$   rF   r(   r!   ú<module>r¨      s\   ðÙ  å "ç %å ß 7Ý 4Ý .÷õ õ 1Ý *áÛÝôdˆnÐ.°¸|ÈZô dôN	$GÐ,õ $Gr(   