Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Return the item at position index in the list.
Parameters
----------
index : int
The item's index.
Returns
-------
item: aPRAWBase
The searched item.
"""
item = getattr(self, self.CHILD_ATTRIBUTE)[index]
if isinstance(item, aPRAWBase):
return item
if "page" in item:
return WikipageRevision(self._reddit, item)
elif item["kind"] == self._reddit.link_kind:
return Submission(self._reddit, item["data"], subreddit=self._subreddit)
elif item["kind"] == self._reddit.subreddit_kind:
return Subreddit(self._reddit, item["data"])
elif item["kind"] == self._reddit.comment_kind:
if item["data"]["replies"] and item["data"]["replies"]["kind"] == self._reddit.listing_kind:
from ..helpers.comment_forrest import CommentForrest
replies = CommentForrest(self._reddit, item["data"]["replies"]["data"], item["data"]["link_id"])
else:
replies = []
return Comment(self._reddit, item["data"], subreddit=self._subreddit, replies=replies)
elif item["kind"] == self._reddit.modaction_kind:
from datetime import datetime
from typing import Dict, TYPE_CHECKING
from ..helpers.apraw_base import aPRAWBase
from ..helpers.streamable import streamable
from ..reddit.redditor import Redditor
from ...const import API_PATH
if TYPE_CHECKING:
from ...reddit import Reddit
from .subreddit import Subreddit
class SubredditModerator(aPRAWBase):
"""
The model representing subreddit moderators. Redditors can be retrieved via ``redditor()``.
**Typical Attributes**
This table describes attributes that typically belong to objects of this
class. Attributes are dynamically provided by the :class:`~apraw.models.aPRAWBase` class
and may vary depending on the status of the response and expected objects.
========================== ============================================================
Attribute Description
========================== ============================================================
``added`` The date on which the moderator was added.
``author_flair_css_class`` The moderator's flair CSS class in the respective subreddit.
``author_flair_text`` The moderator's flair text in the respective subreddit.
``id`` The Redditor's fullname (t2_ID).
if TYPE_CHECKING:
from ...reddit import Reddit
class SubmissionKind(Enum):
"""
An enum representing the valid submission kinds
"""
LINK = "link"
SELF = "self"
IMAGE = "image"
VIDEO = "video"
VIDEOGIF = "videogif"
class Submission(aPRAWBase, DeletableMixin, HideableMixin, ReplyableMixin, NSFWableMixin, SavableMixin, VotableMixin,
AuthorMixin, SubredditMixin, SpoilerableMixin):
"""
The model representing submissions.
Members
-------
reddit: Reddit
The :class:`~apraw.Reddit` instance with which requests are made.
data: Dict
The data obtained from the /about endpoint.
mod: SubmissionModeration
The :class:`~apraw.models.SubmissionModeration` instance to aid in moderating the submission.
kind: str
The item's kind / type.
**Typical Attributes**
----------
kwargs: \*\*Dict
:class:`~apraw.models.ListingGenerator` ``kwargs``.
Returns
-------
generator: ListingGenerator
A :class:`~apraw.models.ListingGenerator` mapped to grab mod actions in the subreddit log.
"""
from ..helpers.generator import ListingGenerator
return ListingGenerator(self.subreddit._reddit,
API_PATH["subreddit_log"].format(sub=self.subreddit.display_name),
subreddit=self.subreddit, *args, **kwargs)
class ModAction(aPRAWBase):
"""
A model representing mod actions taken on specific items.
Members
-------
reddit: Reddit
The :class:`~apraw.Reddit` instance with which requests are made.
data: Dict
The data obtained from the /about endpoint.
kind: str
The item's kind / type.
**Typical Attributes**
This table describes attributes that typically belong to objects of this
class. Attributes are dynamically provided by the :class:`~apraw.models.aPRAWBase` class
import asyncio
from functools import update_wrapper
from typing import AsyncIterator, Callable, Any, Union, AsyncGenerator, Generator, Iterator, Awaitable
from .apraw_base import aPRAWBase
# I know, I know, this code is cursed
SYNC_OR_ASYNC_ITERABLE = Union[
Callable[[Any, int, Any], Union[Awaitable[Union[AsyncIterator[aPRAWBase], Iterator[aPRAWBase]]], Union[
AsyncIterator[aPRAWBase], Iterator[aPRAWBase]]]], AsyncGenerator[aPRAWBase, None], Generator[
aPRAWBase, None, None]]
class Streamable:
"""
A decorator to make functions returning a generator streamable.
Members
-------
max_wait: int
The maximum amount of seconds to wait before repolling the function.
attribute_name: str
The attribute name to use as a unique identifier for returned objects.
"""
@classmethod
from typing import TYPE_CHECKING, Dict
from ..helpers.apraw_base import aPRAWBase
from ..helpers.streamable import Streamable
from ...const import API_PATH
if TYPE_CHECKING:
from ..subreddit.subreddit import Subreddit
from ...reddit import Reddit
class Redditor(aPRAWBase):
"""
The model representing Redditors.
Members
-------
reddit: Reddit
The :class:`~apraw.Reddit` instance with which requests are made.
data: Dict
The data obtained from the /about endpoint.
kind: str
The item's kind / type.
subreddit: Sureddit
An instance of :class:`~apraw.models.Subreddit` for the Redditor's profile subreddit.
**Typical Attributes**
async def __anext__(self) -> Awaitable[aPRAWBase]:
"""
Permit ListingGenerator to operate as a generator.
Returns the next item in the listing.
Returns
-------
subreddit: Subreddit
The subreddit found in the listing.
comment: Comment
The comment found in the listing.
submission: Submission
The submission found in the listing.
mod_action: ModAction
The mod action found in the listing.
wikipage_revision: WikipageRevision
if item["data"]["replies"] and item["data"]["replies"]["kind"] == self._reddit.listing_kind:
from ..helpers.comment_forrest import CommentForrest
replies = CommentForrest(self._reddit, item["data"]["replies"]["data"], item["data"]["link_id"])
else:
replies = []
return Comment(self._reddit, item["data"], subreddit=self._subreddit, replies=replies)
elif item["kind"] == self._reddit.modaction_kind:
return ModAction(self._reddit, item["data"], self._subreddit)
elif item["kind"] == self._reddit.message_kind:
return Message(self._reddit, item["data"])
elif item["kind"] == self._reddit.listing_kind:
return Listing(self._reddit, item["data"])
elif item["kind"] == self._reddit.more_kind:
return MoreComments(self._reddit, item["data"], self._link_id)
else:
return aPRAWBase(self._reddit, item["data"] if "data" in item else item)