o
    2g.                     @  s   d Z ddlmZ ddlmZ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 d
dlmZ er>ddlZG dd dZG dd deZdS )zProvide the WikiPage class.    )annotations)TYPE_CHECKINGAny	GeneratorIterator   )API_PATH)_deprecate_args)cachedproperty   )ListingGenerator   )
RedditBase)RedditorNc                   @  sT   e Zd ZdZdddZddd	Zdd
dZdd ZdddZe	dddddZ
dS )WikiPageModerationzProvides 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")

    wikipageWikiPagec                 C  s
   || _ dS )zqInitialize a :class:`.WikiPageModeration` instance.

        :param wikipage: The wikipage to moderate.

        N)r   )selfr    r   S/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/wikipage.py__init__   s   
zWikiPageModeration.__init__redditorpraw.models.Redditorc                 C  >   | j jt|d}td j| j jdd}| j jj||d dS )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")

        pageusernamewiki_page_editoradd	subredditmethoddataNr   namestrr   formatr    _redditpostr   r   r#   urlr   r   r   r   %   
   zWikiPageModeration.addc                 C  r   )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   r   delr   r"   Nr$   r*   r   r   r   remove7   r,   zWikiPageModeration.removec                 C  s4   | j jjtd j| j jd| j j| j jdd dS )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_revertr    )r   revisionr"   N)r   r(   r)   r   r'   r    r%   	_revisionr   r   r   r   revertI   s   '
zWikiPageModeration.revertreturndict[str, Any]c                 C  s,   t d j| jj| jjd}| jj|d S )z0Return the settings for this :class:`.WikiPage`.wiki_page_settingsr    r   r#   )r   r'   r   r    r%   r(   get)r   r+   r   r   r   settingsx   s   zWikiPageModeration.settingslisted	permlevelboolintother_settingsr   c                K  s@   | ||d td j| jj| jjd}| jjj||d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)

        )r;   r<   r7   r8   r"   r#   )updater   r'   r   r    r%   r(   r)   )r   r;   r<   r?   r+   r   r   r   r@      s
   zWikiPageModeration.updateN)r   r   )r   r   )r5   r6   )r;   r=   r<   r>   r?   r   r5   r6   )__name__
__module____qualname____doc__r   r   r.   r4   r:   r	   r@   r   r   r   r   r      s    




/r   c                      s   e Zd ZdZejZed1d
dZed2ddZ			d3d4 fddZ
d5ddZd5ddZ fddZdd  Zd6d#d$Zed%d&dd'd7d)d*Zd8d+d,Zd9d/d0Z  ZS ):r   a  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

    generator_kwargsr6   r    praw.models.Subredditr+   r&   r5   OGenerator[dict[str, Redditor | WikiPage | str | int | bool | None], None, None]c                 c  sh    t |j|fi | D ]&}|d d ur t|j|d d d|d< t|j||d |d |d< |V  qd S )Nauthorr#   _datar   id)r   r(   r   r   )rE   r    r+   r1   r   r   r   _revision_generator   s   	
zWikiPage._revision_generatorr   c                 C  s   t | S )zProvide 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")

        )r   r3   r   r   r   mod   s   zWikiPage.modNredditpraw.Redditr%   r1   
str | NonerJ   dict[str, Any] | Nonec                   s(   || _ || _|| _t j||dd dS )zInitialize a :class:`.WikiPage` instance.

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

        F)rJ   
_str_fieldN)r%   r2   r    superr   )r   rN   r    r%   r1   rJ   	__class__r   r   r      s   zWikiPage.__init__c                 C  s   | j j d| jd| jdS )z?Return an object initialization representation of the instance.z(subreddit=z, name=))rU   rA   r    r%   r3   r   r   r   __repr__   s   zWikiPage.__repr__c                 C  s   | j  d| j S )z/Return a string representation of the instance./)r    r%   r3   r   r   r   __str__   s   zWikiPage.__str__c                   sP   |   }|d }|d d urt| j|d d d|d< | j| t   d S )Nr#   revision_byrI   )_fetch_datar   r(   __dict__r@   rS   _fetch)r   r#   rT   r   r   r]      s   
zWikiPage._fetchc                 C  s&   d| j | jd| jrd| jifS d fS )N	wiki_pager8   v)r    r%   r2   r3   r   r   r   _fetch_info   s   zWikiPage._fetch_infor    Iterator[praw.models.Submission]c                 K  s&   t | jtd j| j| jd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_discussionsr8   )r   r(   r   r'   r    r%   )r   rE   r   r   r   discussions  s   zWikiPage.discussionscontentreason)re   r?   c                K  s6   | || j|d | jjtd j| jd|d dS )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")

        )rd   r   re   	wiki_editr0   r"   N)r@   r%   r(   r)   r   r'   r    )r   rd   re   r?   r   r   r   edit  s   
zWikiPage.editc                 C  s   t | jj| j| j|S )zReturn 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   r1   r   r   r   r1   2  s   
zWikiPage.revisionstr | int | dict[str, str]Generator[WikiPage, None, None]c                 K  s(   t d j| j| jd}| j|| j|d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_revisionsr8   )rE   r    r+   )r   r'   r    r%   rL   )r   rE   r+   r   r   r   	revisions>  s   zWikiPage.revisions)rE   r6   r    rF   r+   r&   r5   rG   )r5   r   )NN)
rN   rO   r    rF   r%   r&   r1   rP   rJ   rQ   )r5   r&   )rE   r   r5   ra   )rd   r&   re   rP   r?   r   )r1   r&   r5   r   )rE   rh   r5   ri   )rA   rB   rC   rD   r   __hash__staticmethodrL   r
   rM   r   rW   rY   r]   r`   rc   r	   rg   r1   rk   __classcell__r   r   rT   r   r      s&    




r   )rD   
__future__r   typingr   r   r   r   constr   utilr	   
util.cacher
   listing.generatorr   baser   r   r   praw.modelsprawr   r   r   r   r   r   <module>   s     