Ë
    Fü´jå-  ã                  ó²   — d Z ddlmZ ddl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 ddlmZ erdd	lmZ dd
lZddlmZ  G d„ de«      Z G d„ d«      Zy
)zProvide the WikiPage class.é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚcast)ÚAPI_PATH)ÚListingGenerator)Ú
RedditBase)ÚRedditor)Úcachedproperty)ÚIteratorN)Úmodelsc                  óÆ   ‡ — e Zd ZdZe	 	 	 	 	 	 	 	 dd„«       Zedd„«       Z	 	 d	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Z	dd„Z
dˆ fd„Zdd	„Zdd
„Zddœdd„Zdd„Z	 	 	 	 dd„Zˆ xZS )ÚWikiPageaò  An individual :class:`.WikiPage` object.

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

    ================= =================================================================
    Attribute         Description
    ================= =================================================================
    ``content_html``  The contents of the wiki page, as HTML.
    ``content_md``    The contents of the wiki page, as Markdown.
    ``may_revise``    A ``bool`` representing whether or not the authenticated user may
                      edit the wiki page.
    ``name``          The name of the wiki page.
    ``revision_by``   The :class:`.Redditor` who authored this revision of the wiki
                      page.
    ``revision_date`` The time of this revision, in `Unix Time`_.
    ``subreddit``     The :class:`.Subreddit` this wiki page belongs to.
    ================= =================================================================

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

    c              #  óð   K  — t        |j                  |fi | ¤ŽD ]X  }t        d|«      }|d   � t        |j                  |d   d   ¬«      |d<   t	        |j                  ||d   |d   «      |d<   |–— ŒZ y ­w)Núdict[str, Any]ÚauthorÚdata©Ú_dataÚpageÚid)r   Ú_redditr   r
   r   )Úgenerator_kwargsÚ	subredditÚurlÚitemÚrevisions        úY/root/workspace/ytshorts/venv/lib/python3.12/site-packages/praw/models/reddit/wikipage.pyÚ_revision_generatorzWikiPage._revision_generator+   s‘   è ø€ ô % Y×%6Ñ%6¸ÑPÐ?OÑPò 	ˆDÜÐ,¨dÓ3ˆHØ˜Ñ!Ð-Ü%-¨i×.?Ñ.?ÀxÐPXÑGYÐZ`ÑGaÔ%b�˜Ñ"Ü'¨	×(9Ñ(9¸9ÀhÈvÑFVÐX`ÐaeÑXfÓgˆH�VÑØ‹Nñ	ùs   ‚A4A6c                ó   — t        | «      S )züProvide an instance of :class:`.WikiPageModeration`.

        For example, to add u/spez as an editor on the wikipage ``"praw_test"`` try:

        .. code-block:: python

            reddit.subreddit("test").wiki["praw_test"].mod.add("spez")

        )ÚWikiPageModeration©Úselfs    r   ÚmodzWikiPage.mod9   s   € ô " $Ó'Ð'ó    Nc                óT   •— || _         || _        || _        t        ‰| �  ||d¬«       y)z¨Initialize a :class:`.WikiPage` instance.

        :param revision: A specific revision ID to fetch. By default, fetches the most
            recent revision.

        F)r   Ú
_str_fieldN)ÚnameÚ	_revisionr   ÚsuperÚ__init__)r#   Úredditr   r(   r   r   Ú	__class__s         €r   r+   zWikiPage.__init__F   s.   ø€ ð ˆŒ	Ø!ˆŒØ"ˆŒÜ‰Ñ˜ u¸ÐÕ?r%   c                óh   — | j                   j                  › d| j                  ›d| j                  ›d�S )z?Return an object initialization representation of the instance.z(subreddit=z, name=ú))r-   Ú__name__r   r(   r"   s    r   Ú__repr__zWikiPage.__repr__Y   s0   € à—.‘.×)Ñ)Ð*¨+°d·n±nÐ5GÀwÈtÏyÉyÈmÐ[\Ð]Ð]r%   c                ó8   — | j                   › d| j                  › �S )z/Return a string representation of the instance.ú/)r   r(   r"   s    r   Ú__str__zWikiPage.__str__]   s   € à—.‘.Ð!  4§9¡9 +Ð.Ð.r%   c                óÌ   •— | j                  «       }|d   }|d   � t        | j                  |d   d   ¬«      |d<   | j                  j	                  |«       t
        ‰| �  «        y )Nr   Úrevision_byr   )Ú_fetch_datar
   r   Ú__dict__Úupdater*   Ú_fetch)r#   r   r-   s     €r   r:   zWikiPage._fetcha   sa   ø€ Ø×ÑÓ!ˆØ�F‰|ˆØ�ÑÐ*Ü"*¨4¯<©<¸tÀMÑ?RÐSYÑ?ZÔ"[ˆD�ÑØ�‰×Ñ˜TÔ"Ü‰‰Õr%   c                óp   — d| j                   | j                  dœ| j                  rd| j                  ifS d fS )NÚ	wiki_page©r   r   Úv)r(   r   r)   r"   s    r   Ú_fetch_infozWikiPage._fetch_infoi   s@   € àØ—Y‘Y¨T¯^©^Ñ<Ø%)§^¢^ˆS�$—.‘.Ð!ð
ð 	
ð :>ð
ð 	
r%   c                óˆ   — t        | j                  t        d   j                  | j                  | j
                  ¬«      fi |¤ŽS )aì  Return a :class:`.ListingGenerator` for discussions of a wiki page.

        Discussions are site-wide links to a wiki page.

        Additional keyword arguments are passed in the initialization of
        :class:`.ListingGenerator`.

        To view the titles of discussions of the page ``"praw_test"`` in r/test, try:

        .. code-block:: python

            for submission in reddit.subreddit("test").wiki["praw_test"].discussions():
                print(submission.title)

        Úwiki_discussionsr=   )r   r   r   Úformatr(   r   )r#   r   s     r   ÚdiscussionszWikiPage.discussionsp   sC   € ô   Ø�L‰LÜÐ'Ñ(×/Ñ/°T·Y±YÈ$Ï.É.Ð/ÓYñ
ð ñ
ð 	
r%   )Úreasonc               ó¾   — |j                  || j                  |dœ«       | j                  j                  t        d   j                  | j                  ¬«      |¬«       y)aà  Edit this wiki page's contents.

        :param content: The updated Markdown content of the page.
        :param reason: The reason for the revision.
        :param other_settings: Additional keyword arguments to pass.

        For example, to replace the first wiki page of r/test with the phrase ``"test
        wiki page"``:

        .. code-block:: python

            page = next(iter(reddit.subreddit("test").wiki))
            page.edit(content="test wiki page")

        )Úcontentr   rD   Ú	wiki_edit©r   ©r   N)r9   r(   r   Úpostr   rB   r   )r#   rF   rD   Úother_settingss       r   ÚeditzWikiPage.edit†   sM   € ð  	×Ñ¨'¸4¿9¹9ÐPVÑWÔXØ�‰×Ñœ( ;Ñ/×6Ñ6ÀÇÁÐ6ÓPÐWeÐÕfr%   c                ón   — t        | j                  j                  | j                  | j                  |«      S )zùReturn a specific version of this page by revision ID.

        To view revision ``"1234abc"`` of ``"praw_test"`` in r/test:

        .. code-block:: python

            page = reddit.subreddit("test").wiki["praw_test"].revision("1234abc")

        )r   r   r   r(   )r#   r   s     r   r   zWikiPage.revision™   s'   € ô ˜Ÿ™×.Ñ.°·±ÀÇ	Á	È8ÓTÐTr%   c                óš   — t         d   j                  | j                  | j                  ¬«      }| j	                  || j                  |¬«      S )aV  Return a :class:`.ListingGenerator` for page revisions.

        Additional keyword arguments are passed in the initialization of
        :class:`.ListingGenerator`.

        To view the wiki revisions for ``"praw_test"`` in r/test try:

        .. code-block:: python

            for item in reddit.subreddit("test").wiki["praw_test"].revisions():
                print(item)

        To get :class:`.WikiPage` objects for each revision:

        .. code-block:: python

            for item in reddit.subreddit("test").wiki["praw_test"].revisions():
                print(item["page"])

        Úwiki_page_revisionsr=   )r   r   r   )r   rB   r(   r   r   )r#   r   r   s      r   Ú	revisionszWikiPage.revisions¥   sH   € ô. Ð,Ñ-×4Ñ4¸$¿)¹)ÈtÏ~É~Ð4Ó^ˆØ×'Ñ'Ð9IÐUY×UcÑUcÐilÐ'ÓmÐmr%   )r   r   r   úmodels.Subredditr   ÚstrÚreturnzBIterator[dict[str, Redditor | WikiPage | str | int | bool | None]])rS   r!   )NN)r,   zpraw.Redditr   rQ   r(   rR   r   ú
str | Noner   zdict[str, Any] | NonerS   ÚNone)rS   rR   ©rS   rU   )rS   zDtuple[str, dict[str, str | models.Subreddit], dict[str, str] | None])r   r   rS   zIterator[models.Submission])rF   rR   rD   rT   rK   r   rS   rU   )r   rR   rS   r   )r   r   rS   zIIterator[dict[str, models.Redditor | WikiPage | str | int | bool | None]])r0   Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r$   r+   r1   r4   r:   r?   rC   rL   r   rP   Ú__classcell__)r-   s   @r   r   r      sè   ø„ ñð, ðà(ðð $ðð ð	ð
 
Lòó ðð ò
(ó ð
(ð"  $Ø'+ð@àð@ð $ð@ð ð	@ð
 ð@ð %ð@ð 
õ@ó&^ó/õó
ó
ð, :>õ gó&
UðnØ"%ðnà	R÷nr%   r   c                  ó@   — e Zd ZdZd	d„Zd
d„Zd
d„Zdd„Zdd„Zdd„Z	y)r!   zøProvides a set of moderation functions for a :class:`.WikiPage`.

    For example, to add u/spez as an editor on the wikipage ``"praw_test"`` try:

    .. code-block:: python

        reddit.subreddit("test").wiki["praw_test"].mod.add("spez")

    c                ó   — || _         y)zqInitialize a :class:`.WikiPageModeration` instance.

        :param wikipage: The wikipage to moderate.

        N)Úwikipage)r#   r^   s     r   r+   zWikiPageModeration.__init__Ë   s   € ð !ˆ�r%   c                óò   — | j                   j                  t        |«      dœ}t        d   j	                  d| j                   j
                  ¬«      }| j                   j                  j                  ||¬«       y)a.  Add an editor to this :class:`.WikiPage`.

        :param redditor: A redditor name or :class:`.Redditor` instance.

        To add u/spez as an editor on the wikipage ``"praw_test"`` try:

        .. code-block:: python

            reddit.subreddit("test").wiki["praw_test"].mod.add("spez")

        ©r   ÚusernameÚwiki_page_editorÚadd©Úmethodr   rI   N©r^   r(   rR   r   rB   r   r   rJ   ©r#   Úredditorr   r   s       r   rc   zWikiPageModeration.addÓ   ó^   € ð Ÿ™×*Ñ*¼¸H»ÑFˆÜÐ)Ñ*×1Ñ1¸È$Ï-É-×JaÑJaÐ1ÓbˆØ�‰×Ñ×"Ñ" 3¨TÐ"Õ2r%   c                óò   — | j                   j                  t        |«      dœ}t        d   j	                  d| j                   j
                  ¬«      }| j                   j                  j                  ||¬«       y)a9  Remove an editor from this :class:`.WikiPage`.

        :param redditor: A redditor name or :class:`.Redditor` instance.

        To remove u/spez as an editor on the wikipage ``"praw_test"`` try:

        .. code-block:: python

            reddit.subreddit("test").wiki["praw_test"].mod.remove("spez")

        r`   rb   Údelrd   rI   Nrf   rg   s       r   ÚremovezWikiPageModeration.removeã   ri   r%   c                óþ   — | j                   j                  j                  t        d   j	                  | j                   j
                  ¬«      | j                   j                  | j                   j                  dœ¬«       y)a·  Revert a wikipage back to a specific revision.

        To revert the page ``"praw_test"`` in r/test to revision ``"1234abc"``, try

        .. code-block:: python

            reddit.subreddit("test").wiki["praw_test"].revision("1234abc").mod.revert()

        .. note::

            When you attempt to revert the page ``config/stylesheet``, Reddit checks to
            see if the revision being reverted to passes the CSS filter. If the check
            fails, then the revision attempt will also fail, and a
            ``prawcore.Forbidden`` exception will be raised. For example, you can't
            revert to a revision that contains a link to ``url(%%PRAW%%)`` if there is
            no image named ``PRAW`` on the current stylesheet.

            Here is an example of how to look for this type of error:

            .. code-block:: python

                from prawcore.exceptions import Forbidden

                try:
                    reddit.subreddit("test").wiki["config/stylesheet"].revision("1234abc").mod.revert()
                except Forbidden as exception:
                    try:
                        exception.response.json()
                    except ValueError:
                        exception.response.text

            If the error occurs, the output will look something like

            .. code-block:: python

                {"reason": "INVALID_CSS", "message": "Forbidden", "explanation": "%(css_error)s"}

        Úwiki_revertrH   )r   r   rI   N)r^   r   rJ   r   rB   r   r(   r)   r"   s    r   ÚrevertzWikiPageModeration.revertó   sa   € ðN 	�‰×Ñ×"Ñ"Ü�]Ñ#×*Ñ*°T·]±]×5LÑ5LÐ*ÓMàŸ™×*Ñ*Ø ŸM™M×3Ñ3ñð 	#õ 	
r%   c                óÖ   — t         d   j                  | j                  j                  | j                  j                  ¬«      }| j                  j
                  j                  |«      d   S )z0Return the settings for this :class:`.WikiPage`.Úwiki_page_settingsr=   r   )r   rB   r^   r(   r   r   Úget)r#   r   s     r   ÚsettingszWikiPageModeration.settings"  sT   € äÐ+Ñ,×3Ñ3¸¿¹×9KÑ9KÐW[×WdÑWd×WnÑWnÐ3ÓoˆØ�}‰}×$Ñ$×(Ñ(¨Ó-¨fÑ5Ð5r%   c               ó  — |j                  ||dœ«       t        d   j                  | j                  j                  | j                  j
                  ¬«      }| j                  j                  j                  ||¬«      d   S )aÙ  Update the settings for this :class:`.WikiPage`.

        :param listed: Show this page on page list.
        :param permlevel: Who can edit this page? ``0`` use subreddit wiki permissions,
            ``1`` only approved wiki contributors for this page may edit (see
            :meth:`.WikiPageModeration.add`), ``2`` only mods may edit and view.
        :param other_settings: Additional keyword arguments to pass.

        :returns: The updated WikiPage settings.

        To set the wikipage ``"praw_test"`` in r/test to mod only and disable it from
        showing in the page list, try:

        .. code-block:: python

            reddit.subreddit("test").wiki["praw_test"].mod.update(listed=False, permlevel=2)

        )ÚlistedÚ	permlevelrq   r=   rI   r   )r9   r   rB   r^   r(   r   r   rJ   )r#   ru   rv   rK   r   s        r   r9   zWikiPageModeration.update'  sn   € ð& 	×Ñ¨¸iÑHÔIÜÐ+Ñ,×3Ñ3¸¿¹×9KÑ9KÐW[×WdÑWd×WnÑWnÐ3ÓoˆØ�}‰}×$Ñ$×)Ñ)¨#°NÐ)ÓCÀFÑKÐKr%   N)r^   r   rS   rU   )rh   zmodels.RedditorrS   rU   rV   )rS   r   )ru   Úboolrv   ÚintrK   r   rS   r   )
r0   rW   rX   rY   r+   rc   rl   ro   rs   r9   © r%   r   r!   r!   À   s'   „ ñó!ó3ó 3ó -
ó^6ô
Lr%   r!   )rY   Ú
__future__r   Útypingr   r   r   Ú
praw.constr   Úpraw.models.listing.generatorr   Úpraw.models.reddit.baser	   Úpraw.models.reddit.redditorr
   Úpraw.util.cacher   Úcollections.abcr   Úprawr   r   r!   ry   r%   r   ú<module>rƒ      sK   ðÙ !å "ç +Ñ +å Ý :Ý .Ý 0Ý *áÝ(ãÝôinˆzô in÷X|Lò |Lr%   