
    {i;                        S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJrJr  S
SKJr  \(       a  SSKr " S S\5      r " S S5      r " S S5      r " S S5      rg)zProvide the Rule class.    )annotations)TYPE_CHECKINGAnyIterator)quote)warn   )API_PATH)ClientException)_deprecate_argscachedproperty   )
RedditBaseNc                  |   ^  \ rS rSrSrSr\S	S j5       rS
U 4S jjr   S       SU 4S jjjr	U 4S jr
SrU =r$ )Rule   a  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                    [        U 5      $ )w  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    R/home/james-whalen/.local/lib/python3.13/site-packages/praw/models/reddit/rules.pymodRule.mod,   s    & d##    c                R   > [         TU ]  U5      nUS:X  a  Uc  Sn[        U5      eU$ )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    Rule.__getattribute__A   s2    (3#OCS/!r   c                   > X44R                  S5      S:w  a  Sn[        U5      eU(       a  X0l        X l        [        TU ]  XS9  g)z%Initialize a :class:`.Rule` instance.Nr   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*   Rule.__init__I   sI     $$T*a/ACS/!(O #-r   c                *  > U R                   R                   HR  nUR                  U R                  :X  d  M  U R                  R	                  UR                  5        [
        TU ]  5           g    SU R                    SU R                   3n[        U5      e)Nz
Subreddit z does not have the rule )r   rulesr   __dict__updater   _fetchr   )r   ruler$   r%   s      r   r1   Rule._fetch\   st    NN((D$//1$$T]]3 	 )
 4>>**B4??BSTc""r   )r   r   )returnz'praw.models.reddit.rules.RuleModeration)r"   strr4   r   )NNN)r+   zpraw.Redditr   zpraw.models.Subreddit | Noner   
str | Noner(   zdict[str, str] | None)__name__
__module____qualname____firstlineno____doc__	STR_FIELDr   r   r    r*   r1   __static_attributes____classcell__)r%   s   @r   r   r      sk    . I$ $( 37!%'+.. 0. 	.
 %. .&# #r   r   c                  n    \ rS rSrSrSS jrS r\" SSSS5      S	S	S	S	S
.         SS jj5       rSr	g	)r   f   r   c                    Xl         g)z/Initialize a :class:`.RuleModeration` instance.Nr2   )r   r2   s     r   r*   RuleModeration.__init__y   s    	r   c                    [        U R                  R                  5      U R                  R                  S.nU R                  R                  R                  [        S   US9  g)zDelete 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)r5   r2   r   r   _redditpostr
   )r   rH   s     r   deleteRuleModeration.delete}   sO     TYY(()))..
 			x(?@tLr   descriptionkindr   violation_reasonNrM   rN   r   rO   c               z   [        U R                  R                  5      U R                  R                  S.nUUUUS.R	                  5        H"  u  pgUc  [        U R                  U5      OUXV'   M$     U R                  R                  R                  [        S   US9S   nU R                  R                  Ul        U$ )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"
    )

)rE   old_short_namerP   update_subreddit_rulerG   r   )	r5   r2   r   r   itemsgetattrrI   rJ   r
   )	r   rM   rN   r   rO   rH   namer#   updated_rules	            r   r0   RuleModeration.update   s    B TYY(()"ii22

 '$ 0	

 %'KD 6;]D1DJ yy((--,-D . 

 "&!4!4r   rB   )r2   praw.models.Rule)
rM   r6   rN   r6   r   r6   rO   r6   r4   rY   )
r7   r8   r9   r:   r;   r*   rK   r   r0   r=    r   r   r   r   f   ss    $M  ]FL:LM #'!%'+.  . 	.
 . %. 
. N.r   r   c                  h    \ rS rSrSr\SS j5       r\SS j5       rSS jrSS jr	SS jr
SS jrS	rg
)SubredditRules   a  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                    U R                   R                  [        S   R                  U R                  S95      nU H  nU R                  Ul        M     U$ )zYGet a list of :class:`.Rule` objects.

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

r.   r   )rI   getr
   formatr   )r   	rule_listr2   s      r   
_rule_listSubredditRules._rule_list   sJ     LL$$Xg%6%=%=%=%WX	D!^^DN r   c                    [        U 5      $ )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   SubredditRules.mod   s    0 (--r   c                    [        S[        SS9  U R                  R                  S[        S   R                  U R                  S9S9$ )aY  Return a list of :class:`.Rule`\ s (Deprecated).

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

.. deprecated:: 7.1

    Use the iterator by removing the call to :class:`.SubredditRules`. For
    example, in order to use the iterator:

    .. code-block:: python

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

a=  Calling SubredditRules to get a list of rules is deprecated. Remove the parentheses to use the iterator. View the PRAW documentation on how to change the code in order to use the iterator (https://praw.readthedocs.io/en/latest/code_overview/other/subredditrules.html#praw.models.reddit.rules.SubredditRules.__call__).   )category
stacklevelGETr.   r_   )methodpath)r   DeprecationWarningrI   requestr
   ra   r   r   s    r   __call__SubredditRules.__call__   sT      	Q (	
 ||##x077$..7Q $ 
 	
r   c                    [        U[        5      (       d  U R                  U   $ [        U R                  U R
                  US9$ )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]

)r   r   )
isinstancer5   rc   r   rI   r   )r   r   s     r   __getitem__SubredditRules.__getitem__  s8    L *c**??:..DLLDNNzRRr   c                2    Xl         UR                  U l        g)zlInitialize a :class:`.SubredditRules` instance.

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

N)r   rI   )r   r   s     r   r*   SubredditRules.__init__@  s     # ((r   c                ,    [        U R                  5      $ )a1  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)

)iterrc   r   s    r   __iter__SubredditRules.__iter__I  s     DOO$$r   )rI   r   N)r4   z
list[Rule])r4   rf   )r4   list[praw.models.Rule])r   zstr | int | slicer4   rY   )r   zpraw.models.Subreddit)r4   zIterator[praw.models.Rule])r7   r8   r9   r:   r;   r   rc   r   rq   ru   r*   r{   r=   rZ   r   r   r\   r\      sE    ( 	 	 . .2
8(ST)%r   r\   c                  n    \ rS rSrSrSS jr\" SSSS5      SS	S
.         SS jj5       rSS jrSr	g	)rf   i[  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                    Xl         g)z9Initialize a :class:`.SubredditRulesModeration` instance.Nsubreddit_rules)r   r   s     r   r*   !SubredditRulesModeration.__init__s  s    .r   r   rN   rM   rO    N)rM   rO   c                   [        U R                  R                  5      UUUUc  UOUS.nU R                  R                  R	                  [
        S   US9S   nU R                  R                  Ul        U$ )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"
    )

)rE   rM   rN   r   rO   add_subreddit_rulerG   r   )r5   r   r   rI   rJ   r
   )r   rM   rN   r   rO   rH   new_rules          r   addSubredditRulesModeration.addw  s    > T))334&$.6
<L
 ''//44)* 5 

 "11;;r   c                X   [        SR                  U Vs/ s H  o"R                  PM     sn5      SS9n[        U R                  R
                  5      US.nU R                  R                  R                  [        S   US9nU H  nU R                  R
                  Ul        M      U$ s  snf )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)rE   new_rule_orderreorder_subreddit_rulesrG   )	r   joinr   r5   r   r   rI   rJ   r
   )r   rb   r2   order_stringrH   responses         r   reorder SubredditRulesModeration.reorder  s    ( HH)<)$oo)<=C
 T))334*
 ''//44./d 5 
 D!11;;DN  =s   B'r   )r   r\   )
rM   r5   rN   r5   r   r5   rO   r6   r4   rY   )rb   r}   r4   r}   )
r7   r8   r9   r:   r;   r*   r   r   r   r=   rZ   r   r   rf   rf   [  so    ./ \6=:LM  (,* * 	*
 * %* 
* N*X r   rf   )r;   
__future__r   typingr   r   r   urllib.parser   warningsr   constr
   
exceptionsr   utilr   r   baser   praw.modelsprawr   r   r\   rf   rZ   r   r   <module>r      s^     " / /    ) 3 Q#: Q#hV VrY% Y%xi ir   