o
    2g#                     @  s   d Z ddlmZ ddl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 ddlmZmZ erHddlZG dd deeZdS )zProvide the Multireddit class.    )annotationsN)dumps)TYPE_CHECKINGAny   )API_PATH)_deprecate_argscachedproperty   )SubredditListingMixin   )
RedditBase)Redditor)	SubredditSubredditStreamc                      s   e Zd ZdZdZedejZe	d)ddZ
ed*d
dZd+ fddZ fddZdd Zd,ddZedddd-dd Zd!d" Zd,d#d$Zd.d'd(Z  ZS )/Multireddita  A class for users' multireddits.

    This is referred to as a "Custom Feed" on the Reddit UI.

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

    ==================== ==============================================================
    Attribute            Description
    ==================== ==============================================================
    ``can_edit``         A ``bool`` representing whether or not the authenticated user
                         may edit the multireddit.
    ``copied_from``      The multireddit that the multireddit was copied from, if it
                         exists, otherwise ``None``.
    ``created_utc``      When the multireddit was created, in `Unix Time`_.
    ``description_html`` The description of the multireddit, as HTML.
    ``description_md``   The description of the multireddit, as Markdown.
    ``display_name``     The display name of the multireddit.
    ``name``             The name of the multireddit.
    ``over_18``          A ``bool`` representing whether or not the multireddit is
                         restricted for users over 18.
    ``subreddits``       A list of :class:`.Subreddit`\ s that make up the multireddit.
    ``visibility``       The visibility of the multireddit, either ``"private"``,
                         ``"public"``, or ``"hidden"``.
    ==================== ==============================================================

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

    pathz[\W_]+titlestrreturnc                 C  sV   t jd| d } t| dkr'| dd } | d}|dkr'| d| } | p*dS )zReturn a slug version of the title.

        :param title: The title to make a slug of.

        Adapted from Reddit's utils.py.

        _   Nr   )r   
RE_INVALIDsubstriplowerlenrfind)r   	last_word r   P/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/multi.pysluggify5   s   	
zMultireddit.sluggifyr   c                 C  s   t | S )a  Provide an instance of :class:`.SubredditStream`.

        Streams can be used to indefinitely retrieve new comments made to a multireddit,
        like:

        .. code-block:: python

            for comment in reddit.multireddit(redditor="spez", name="fun").stream.comments():
                print(comment)

        Additionally, new submissions can be retrieved via the stream. In the following
        example all new submissions to the multireddit are fetched:

        .. code-block:: python

            for submission in reddit.multireddit(
                redditor="bboe", name="games"
            ).stream.submissions():
                print(submission)

        )r   selfr   r   r    streamF   s   zMultireddit.streamredditpraw.Reddit_datadict[str, Any]c                   s   d| _ t j |d t | j ddd | _td j| j| jd| _	d| j	dd  | _ d	| j
v rA fd
d| jD | _dS dS )z,Initialize a :class:`.Multireddit` instance.Nr'   /r   r
   multiredditmultiuser
subredditsc                   s   g | ]	}t  |d  qS name)r   ).0xr%   r   r    
<listcomp>g   s    z(Multireddit.__init__.<locals>.<listcomp>)r   super__init__r   split_authorr   formatr2   _path__dict__r0   )r#   r%   r'   	__class__r5   r    r8   _   s   
zMultireddit.__init__c                   s>   |   }|d }t| | j|d}| j|j t   d S )Ndatar)   )_fetch_datatype_redditr=   updater7   _fetch)r#   r@   otherr>   r   r    rE   i   s
   zMultireddit._fetchc                 C  s   d| j | jj dd fS )Nmultireddit_apir,   )r2   r:   r"   r   r   r    _fetch_infop   s   zMultireddit._fetch_info	subredditpraw.models.Subredditc                 C  F   t d j| j| j|d}| jj|dtdt|iid | d dS )aM  Add a subreddit to this multireddit.

        :param subreddit: The subreddit to add to this multi.

        For example, to add r/test to multireddit ``bboe/test``:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            reddit.multireddit(redditor="bboe", name="test").add(subreddit)

        multireddit_updater-   r.   rI   modelr2   r@   r0   N)	r   r;   r2   r:   rC   putr   r   _reset_attributesr#   rI   urlr   r   r    addw   
   
 zMultireddit.adddisplay_nameN)rV   
str | Nonepraw.models.Multiredditc                C  sT   |r|  |}n| j}| j}|| jtd j|| jj dd}| jj	td |dS )a  Copy this multireddit and return the new multireddit.

        :param display_name: The display name for the copied multireddit. Reddit will
            generate the ``name`` field from this display name. When not provided the
            copy will use the same display name and name as this multireddit.

        To copy the multireddit ``bboe/test`` with a name of ``"testing"``:

        .. code-block:: python

            reddit.multireddit(redditor="bboe", name="test").copy(display_name="testing")

        r+   r,   )rV   fromtomultireddit_copyrO   )
r!   rV   r2   r   r   r;   rC   r.   mepost)r#   rV   r2   r@   r   r   r    copy   s   zMultireddit.copyc                 C  s(   t d j| j| jjd}| j| dS )zDelete this multireddit.

        For example, to delete multireddit ``bboe/test``:

        .. code-block:: python

            reddit.multireddit(redditor="bboe", name="test").delete()

        rG   r,   N)r   r;   r2   r:   rC   delete)r#   r   r   r   r    r_      s   

zMultireddit.deletec                 C  rK   )a_  Remove a subreddit from this multireddit.

        :param subreddit: The subreddit to remove from this multi.

        For example, to remove r/test from multireddit ``bboe/test``:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            reddit.multireddit(redditor="bboe", name="test").remove(subreddit)

        rL   rM   rN   r2   rO   r0   N)	r   r;   r2   r:   rC   r_   r   r   rQ   rR   r   r   r    remove   rU   zMultireddit.removeupdated_settings8str | list[str | praw.models.Subreddit | dict[str, str]]c                 K  s`   d|v rdd |d D |d< t d j| j| jjd}| jj|dt|id}| j|j dS )	a  Update this multireddit.

        Keyword arguments are passed for settings that should be updated. They can any
        of:

        :param display_name: The display name for this multireddit. Must be no longer
            than 50 characters.
        :param subreddits: Subreddits for this multireddit.
        :param description_md: Description for this multireddit, formatted in Markdown.
        :param icon_name: Can be one of: ``"art and design"``, ``"ask"``, ``"books"``,
            ``"business"``, ``"cars"``, ``"comics"``, ``"cute animals"``, ``"diy"``,
            ``"entertainment"``, ``"food and drink"``, ``"funny"``, ``"games"``,
            ``"grooming"``, ``"health"``, ``"life advice"``, ``"military"``, ``"models
            pinup"``, ``"music"``, ``"news"``, ``"philosophy"``, ``"pictures and
            gifs"``, ``"science"``, ``"shopping"``, ``"sports"``, ``"style"``,
            ``"tech"``, ``"travel"``, ``"unusual stories"``, ``"video"``, or ``None``.
        :param key_color: RGB hex color code of the form ``"#FFFFFF"``.
        :param visibility: Can be one of: ``"hidden"``, ``"private"``, or ``"public"``.
        :param weighting_scheme: Can be one of: ``"classic"`` or ``"fresh"``.

        For example, to rename multireddit ``"bboe/test"`` to ``"bboe/testing"``:

        .. code-block:: python

            reddit.multireddit(redditor="bboe", name="test").update(display_name="testing")

        r0   c                 S  s   g | ]}d t |iqS r1   )r   )r3   r   r   r   r    r6      s    z&Multireddit.update.<locals>.<listcomp>rG   r,   rN   rO   N)	r   r;   r2   r:   rC   rP   r   r=   rD   )r#   ra   r   newr   r   r    rD      s   

zMultireddit.update)r   r   r   r   )r   r   )r%   r&   r'   r(   )rI   rJ   )rV   rW   r   rX   )ra   rb   )__name__
__module____qualname____doc__	STR_FIELDrecompileUNICODEr   staticmethodr!   r	   r$   r8   rE   rH   rT   r   r^   r_   r`   rD   __classcell__r   r   r>   r    r      s"    


r   )rg   
__future__r   ri   jsonr   typingr   r   constr   utilr   r	   listing.mixinsr   baser   redditorr   rI   r   r   praw.modelsprawr   r   r   r   r    <module>   s    