Ë
    Fü´jµ7  ã                  óè   — 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 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e«      Z G d„ d«      Z G d„ d«      Z G d„ d«      Zy)zProvide the Rule class.é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚSupportsIndex)Úquote)ÚAPI_PATH)ÚClientException)Ú
RedditBase)ÚCreatedMixin)Úcachedproperty)ÚIteratorN)Úmodelsc                  ól   ‡ — e Zd ZdZdZedd„«       Zdˆ fd„Z	 	 	 d		 	 	 	 	 	 	 	 	 d
ˆ fd„Zdˆ fd„Z	ˆ xZ
S )ÚRuleaR  An individual :class:`.Rule` object.

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

    ==================== =============================================================
    Attribute            Description
    ==================== =============================================================
    ``created_utc``      Time the rule was created, represented in `Unix Time`_.
    ``description``      The description of the rule, if provided, otherwise a blank
                         string.
    ``kind``             The kind of rule. Can be ``"link"``, ``comment"``, or
                         ``"all"``.
    ``priority``         Represents where the rule is ranked. For example, the first
                         rule is at priority ``0``. Serves as an index number on the
                         list of rules.
    ``short_name``       The name of the rule.
    ``violation_reason`` The reason that is displayed on the report menu for the rule.
    ==================== =============================================================

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

    Ú
short_namec                ó   — t        | «      S )a¿  Contain methods used to moderate rules.

        To delete ``"No spam"`` from r/test try:

        .. code-block:: python

            reddit.subreddit("test").rules["No spam"].mod.delete()

        To update ``"No spam"`` from r/test try:

        .. code-block:: python

            reddit.subreddit("test").removal_reasons["No spam"].mod.update(
                description="Don't do this!", violation_reason="Spam post"
            )

        )ÚRuleModeration©Úselfs    úV/root/workspace/ytshorts/venv/lib/python3.12/site-packages/praw/models/reddit/rules.pyÚmodzRule.mod/   s   € ô& ˜dÓ#Ð#ó    c                óN   •— t         ‰| �  |«      }|dk(  r|€d}t        |«      ‚|S )zGet the value of an attribute.Ú	subredditz;The Rule is missing a subreddit. File a bug report at PRAW.)ÚsuperÚ__getattribute__Ú
ValueError)r   Ú	attributeÚvalueÚmsgÚ	__class__s       €r   r   zRule.__getattribute__D   s2   ø€ ä‘Ñ(¨Ó3ˆØ˜Ò#¨¨ØOˆCÜ˜S“/Ð!Øˆr   c                óŽ   •— ||fj                  d«      dk7  rd}t        |«      ‚|r|| _        || _        t        ‰| �  ||¬«       y)z%Initialize a :class:`.Rule` instance.Né   z-Either short_name or _data needs to be given.)Ú_data)Úcountr   r   r   r   Ú__init__)r   Úredditr   r   r$   r    r!   s         €r   r&   zRule.__init__L   sQ   ø€ ð ˜Ð×$Ñ$ TÓ*¨aÒ/ØAˆCÜ˜S“/Ð!ÙØ(ˆDŒOð #ˆŒÜ‰Ñ˜ uÐÕ-r   c                ó@  •— | j                   €J ‚| j                   j                  D ]P  }|j                  | j                  k(  sŒ| j                  j	                  |j                  «       t
        ‰| �  «         y  d| j                   › d| j                  › �}t        |«      ‚)Nz
Subreddit z does not have the rule )r   Úrulesr   Ú__dict__Úupdater   Ú_fetchr	   )r   Úruler    r!   s      €r   r,   zRule._fetch_   s‰   ø€ Ø�~‰~Ð)Ð)Ð)Ø—N‘N×(Ñ(ò 	ˆDØ�‰ $§/¡/Ó1Ø—‘×$Ñ$ T§]¡]Ô3Ü‘‘Ô Ùð		ð
 ˜4Ÿ>™>Ð*Ð*BÀ4Ç?Á?ÐBSÐTˆÜ˜cÓ"Ð"r   )Úreturnr   )r   Ústrr.   r   )NNN)
r'   zpraw.Redditr   zmodels.Subreddit | Noner   ú
str | Noner$   zdict[str, str] | Noner.   ÚNone©r.   r1   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	STR_FIELDr   r   r   r&   r,   Ú__classcell__)r!   s   @r   r   r      sp   ø„ ñð. €Iàò$ó ð$õ(ð .2Ø!%Ø'+ð.àð.ð +ð.ð ð	.ð
 %ð.ð 
õ.÷&#ñ #r   r   c                  óF   — e Zd ZdZdd„Zdd„Zdddddœ	 	 	 	 	 	 	 	 	 d	d„Zy)
r   a›  Contain methods used to moderate rules.

    To delete ``"No spam"`` from r/test try:

    .. code-block:: python

        reddit.subreddit("test").rules["No spam"].mod.delete()

    To update ``"No spam"`` from r/test try:

    .. code-block:: python

        reddit.subreddit("test").removal_reasons["No spam"].mod.update(
            description="Don't do this!", violation_reason="Spam post"
        )

    c                ó   — || _         y)z/Initialize a :class:`.RuleModeration` instance.N)r-   )r   r-   s     r   r&   zRuleModeration.__init__}   s	   € àˆ�	r   c                óÌ   — t        | j                  j                  «      | j                  j                  dœ}| j                  j                  j                  t        d   |¬«       y)zÂDelete a rule from this subreddit.

        To delete ``"No spam"`` from r/test try:

        .. code-block:: python

            reddit.subreddit("test").rules["No spam"].mod.delete()

        )Úrr   Úremove_subreddit_rule©ÚdataN)r/   r-   r   r   Ú_redditÚpostr   )r   r?   s     r   ÚdeletezRuleModeration.delete�   sO   € ô �T—Y‘Y×(Ñ(Ó)ØŸ)™)×.Ñ.ñ
ˆð 	�	‰	×Ñ×ÑœxÐ(?Ñ@ÀtÐÕLr   N©ÚdescriptionÚkindr   Úviolation_reasonc               ó~  — | j                   j                  t        | j                   j                  «      dœ}||||dœj	                  «       D ]"  \  }}|€t        | j                   |«      n|||<   Œ$ | j                   j                  j                  t        d   |¬«      d   }| j                   j                  |_        |S )a
  Update the rule from this subreddit.

        .. note::

            Existing values will be used for any unspecified arguments.

        :param description: The new description for the rule. Can be empty.
        :param kind: The kind of item that the rule applies to. One of ``"link"``,
            ``"comment"``, or ``"all"``.
        :param short_name: The name of the rule.
        :param violation_reason: The reason that is shown on the report menu.

        :returns: A Rule object containing the updated values.

        To update ``"No spam"`` from r/test try:

        .. code-block:: python

            reddit.subreddit("test").removal_reasons["No spam"].mod.update(
                description="Don't do this!", violation_reason="Spam post"
            )

        )Úold_short_namer<   rC   Úupdate_subreddit_ruler>   r   )	r-   r   r/   r   ÚitemsÚgetattrr@   rA   r   )	r   rD   rE   r   rF   r?   Únamer   Úupdated_rules	            r   r+   zRuleModeration.update‘   s»   € ð@ #Ÿi™i×2Ñ2Ü�T—Y‘Y×(Ñ(Ó)ñ
ˆð
 'ØØ$Ø 0ñ	
÷
 ‰%‹'ò	N‰KˆD�%ð 6;°]œ §¡¨DÔ1ÈˆD�ŠJð	Nð —y‘y×(Ñ(×-Ñ-¬hÐ7NÑ.OÐVZÐ-Ó[Ð\]Ñ^ˆØ!%§¡×!4Ñ!4ˆÔØÐr   )r-   úmodels.Ruler.   r1   r2   )
rD   r0   rE   r0   r   r0   rF   r0   r.   rN   )r3   r4   r5   r6   r&   rB   r+   © r   r   r   r   j   sW   „ ñó$óMð& #'ØØ!%Ø'+ñ,ð  ð,ð ð	,ð
 ð,ð %ð,ð 
ô,r   r   c                  óL   — e Zd ZdZedd„«       Zed	d„«       Zd
d„Zdd„Zdd„Z	y)ÚSubredditRulesa	  Provide a set of functions to access a :class:`.Subreddit`'s rules.

    For example, to list all the rules for a subreddit:

    .. code-block:: python

        for rule in reddit.subreddit("test").rules:
            print(rule)

    Moderators can also add rules to the subreddit. For example, to make a rule called
    ``"No spam"`` in r/test:

    .. code-block:: python

        reddit.subreddit("test").rules.mod.add(
            short_name="No spam", kind="all", description="Do not spam. Spam bad"
        )

    c                ó®   — | j                   j                  t        d   j                  | j                  ¬«      «      }|D ]  }| j                  |_        Œ |S )ziGet a list of :class:`.Rule` objects.

        :returns: A list of instances of :class:`.Rule`.

        r)   )r   )r@   Úgetr   Úformatr   )r   Ú	rule_listr-   s      r   Ú
_rule_listzSubredditRules._rule_listÕ   sO   € ð —L‘L×$Ñ$¤X¨gÑ%6×%=Ñ%=ÈÏÉÐ%=Ó%WÓXˆ	Øò 	,ˆDØ!Ÿ^™^ˆD�Nð	,àÐr   c                ó   — t        | «      S )a  Contain methods to moderate subreddit rules as a whole.

        To add rule ``"No spam"`` to r/test try:

        .. code-block:: python

            reddit.subreddit("test").rules.mod.add(
                short_name="No spam", kind="all", description="Do not spam. Spam bad"
            )

        To move the fourth rule to the first position, and then to move the prior first
        rule to where the third rule originally was in r/test:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            rules = list(subreddit.rules)
            new_rules = rules[3:4] + rules[1:3] + rules[0:1] + rules[4:]
            # Alternate: [rules[3]] + rules[1:3] + [rules[0]] + rules[4:]
            new_rule_list = subreddit.rules.mod.reorder(new_rules)

        )ÚSubredditRulesModerationr   s    r   r   zSubredditRules.modá   s   € ô0 (¨Ó-Ð-r   c                ó„   — t        |t        «      s| j                  |   S t        | j                  || j
                  ¬«      S )a‰  Return the :class:`.Rule` for the subreddit with short_name ``short_name``.

        :param short_name: The short_name of the rule, or the rule number.

        .. note::

            Rules fetched using a specific rule name are lazily loaded, so you might
            have to access an attribute to get all the expected attributes.

        This method is to be used to fetch a specific rule, like so:

        .. code-block:: python

            rule_name = "No spam"
            rule = reddit.subreddit("test").rules[rule_name]
            print(rule)

        You can also fetch a numbered rule of a subreddit.

        Rule numbers start at ``0``, so the first rule is at index ``0``, and the second
        rule is at index ``1``, and so on.

        :raises: :py:class:`IndexError` if a rule of a specific number does not exist.

        .. note::

            You can use negative indexes, such as ``-1``, to get the last rule. You can
            also use slices, to get a subset of rules, such as the last three rules with
            ``rules[-3:]``.

        For example, to fetch the second rule of r/test:

        .. code-block:: python

            rule = reddit.subreddit("test").rules[1]

        To get the last three rules in a subreddit:

        .. code-block:: python

            reasons = reddit.subreddit("test").rules[-3:]
            for rule in rules:
                print(rule)

        )r   r   )Ú
isinstancer/   rV   r   r@   r   )r   r   s     r   Ú__getitem__zSubredditRules.__getitem__û   s5   € ô\ ˜*¤cÔ*Ø—?‘? :Ñ.Ð.Ü�D—L‘L¨ZÀ4Ç>Á>ÔRÐRr   c                ó4   — || _         |j                  | _        y)z|Initialize a :class:`.SubredditRules` instance.

        :param subreddit: The subreddit whose rules to work with.

        N)r   r@   )r   r   s     r   r&   zSubredditRules.__init__-  s   € ð #ˆŒØ ×(Ñ(ˆ�r   c                ó,   — t        | j                  «      S )ai  Iterate through the rules of the subreddit.

        :returns: An iterator containing all the rules of a subreddit.

        This method is used to discover all rules for a subreddit.

        For example, to get the rules for r/test:

        .. code-block:: python

            for rule in reddit.subreddit("test").rules:
                print(rule)

        )ÚiterrV   r   s    r   Ú__iter__zSubredditRules.__iter__6  s   € ô �D—O‘OÓ$Ð$r   N)r.   z
list[Rule])r.   rX   )r   r   r.   rN   )r   zmodels.Subredditr.   r1   )r.   zIterator[models.Rule])
r3   r4   r5   r6   r   rV   r   r[   r&   r_   rO   r   r   rQ   rQ   À   s@   „ ñð( ò	ó ð	ð ò.ó ð.ó20Sód)ô%r   rQ   c                  óB   — e Zd ZdZdd„Zdddœ	 	 	 	 	 	 	 	 	 d	d„Zd
d„Zy)rX   aÞ  Contain methods to moderate subreddit rules as a whole.

    To add rule ``"No spam"`` to r/test try:

    .. code-block:: python

        reddit.subreddit("test").rules.mod.add(
            short_name="No spam", kind="all", description="Do not spam. Spam bad"
        )

    To move the fourth rule to the first position, and then to move the prior first rule
    to where the third rule originally was in r/test:

    .. code-block:: python

        subreddit = reddit.subreddit("test")
        rules = list(subreddit.rules)
        new_rules = rules[3:4] + rules[1:3] + rules[0:1] + rules[4:]
        # Alternate: [rules[3]] + rules[1:3] + [rules[0]] + rules[4:]
        new_rule_list = subreddit.rules.mod.reorder(new_rules)

    c                ó   — || _         y)z9Initialize a :class:`.SubredditRulesModeration` instance.N)Úsubreddit_rules)r   rb   s     r   r&   z!SubredditRulesModeration.__init__`  s
   € à.ˆÕr   Ú N)rD   rF   c               óð   — ||t        | j                  j                  «      ||€|n|dœ}| j                  j                  j	                  t
        d   |¬«      d   }| j                  j                  |_        |S )aô  Add a removal reason to this subreddit.

        :param description: The description for the rule.
        :param kind: The kind of item that the rule applies to. One of ``"link"``,
            ``"comment"``, or ``"all"``.
        :param short_name: The name of the rule.
        :param violation_reason: The reason that is shown on the report menu. If a
            violation reason is not specified, the short name will be used as the
            violation reason.

        :returns: The added :class:`.Rule`.

        To add rule ``"No spam"`` to r/test try:

        .. code-block:: python

            reddit.subreddit("test").rules.mod.add(
                short_name="No spam", kind="all", description="Do not spam. Spam bad"
            )

        )rD   rE   r<   r   rF   Úadd_subreddit_ruler>   r   )r/   rb   r   r@   rA   r   )r   rD   rE   r   rF   r?   Únew_rules          r   ÚaddzSubredditRulesModeration.addd  s|   € ð< 'ØÜ�T×)Ñ)×3Ñ3Ó4Ø$Ø/?Ð/G¡ÐM]ñ
ˆð ×'Ñ'×/Ñ/×4Ñ4´XÐ>RÑ5SÐZ^Ð4Ó_Ð`aÑbˆØ!×1Ñ1×;Ñ;ˆÔØˆr   c                ó\  — t        dj                  |D �cg c]  }|j                  ‘Œ c}«      d¬«      }|t        | j                  j
                  «      dœ}| j                  j                  j                  t        d   |¬«      }|D ]  }| j                  j
                  |_        Œ |S c c}w )aó  Reorder the rules of a subreddit.

        :param rule_list: The list of rules, in the wanted order. Each index of the list
            indicates the position of the rule.

        :returns: A list containing the rules in the specified order.

        For example, to move the fourth rule to the first position, and then to move the
        prior first rule to where the third rule originally was in r/test:

        .. code-block:: python

            subreddit = reddit.subreddit("test")
            rules = list(subreddit.rules)
            new_rules = rules[3:4] + rules[1:3] + rules[0:1] + rules[4:]
            # Alternate: [rules[3]] + rules[1:3] + [rules[0]] + rules[4:]
            new_rule_list = subreddit.rules.mod.reorder(new_rules)

        ú,)Úsafe)Únew_rule_orderr<   Úreorder_subreddit_rulesr>   )	r   Újoinr   r/   rb   r   r@   rA   r   )r   rU   r-   Úorder_stringr?   Úresponses         r   Úreorderz SubredditRulesModeration.reorderŒ  sž   € ô( ˜SŸX™XÀ9Ö&M¸4 t§£Ò&MÓNÐUXÔYˆà*Ü�T×)Ñ)×3Ñ3Ó4ñ
ˆð ×'Ñ'×/Ñ/×4Ñ4´XÐ>WÑ5XÐ_cÐ4ÓdˆØò 	<ˆDØ!×1Ñ1×;Ñ;ˆD�Nð	<àˆùò 'Ns   •B))rb   rQ   r.   r1   )
rD   r/   rE   r/   r   r/   rF   r0   r.   rN   )rU   úlist[models.Rule]r.   rq   )r3   r4   r5   r6   r&   rg   rp   rO   r   r   rX   rX   H  sS   „ ñó./ð ð (,ñ&ð ð&ð ð	&ð
 ð&ð %ð&ð 
ó&ôPr   rX   )r6   Ú
__future__r   Útypingr   r   r   Úurllib.parser   Ú
praw.constr   Úpraw.exceptionsr	   Úpraw.models.reddit.baser
   Úpraw.models.reddit.mixinsr   Ú	praw.utilr   Úcollections.abcr   Úprawr   r   r   rQ   rX   rO   r   r   ú<module>r|      sf   ðÙ å "ç 4Ñ 4Ý å Ý +Ý .Ý 2Ý $áÝ(ãÝôR#ˆ<˜ô R#÷jSñ S÷lE%ñ E%÷P`ò `r   