Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Package providing models that act like a list."""
|
||||
52
backend/venv/Lib/site-packages/praw/models/list/base.py
Normal file
52
backend/venv/Lib/site-packages/praw/models/list/base.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Provide the BaseList class."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Iterator
|
||||
|
||||
from ..base import PRAWBase
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
import praw
|
||||
|
||||
|
||||
class BaseList(PRAWBase):
|
||||
"""An abstract class to coerce a list into a :class:`.PRAWBase`."""
|
||||
|
||||
CHILD_ATTRIBUTE = None
|
||||
|
||||
def __contains__(self, item: Any) -> bool:
|
||||
"""Test if item exists in the list."""
|
||||
return item in getattr(self, self.CHILD_ATTRIBUTE)
|
||||
|
||||
def __getitem__(self, index: int) -> Any:
|
||||
"""Return the item at position index in the list."""
|
||||
return getattr(self, self.CHILD_ATTRIBUTE)[index]
|
||||
|
||||
def __init__(self, reddit: praw.Reddit, _data: dict[str, Any]):
|
||||
"""Initialize a :class:`.BaseList` instance.
|
||||
|
||||
:param reddit: An instance of :class:`.Reddit`.
|
||||
|
||||
"""
|
||||
super().__init__(reddit, _data=_data)
|
||||
|
||||
if self.CHILD_ATTRIBUTE is None:
|
||||
msg = "BaseList must be extended."
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
child_list = getattr(self, self.CHILD_ATTRIBUTE)
|
||||
for index, item in enumerate(child_list):
|
||||
child_list[index] = reddit._objector.objectify(item)
|
||||
|
||||
def __iter__(self) -> Iterator[Any]:
|
||||
"""Return an iterator to the list."""
|
||||
return getattr(self, self.CHILD_ATTRIBUTE).__iter__()
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""Return the number of items in the list."""
|
||||
return len(getattr(self, self.CHILD_ATTRIBUTE))
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return a string representation of the list."""
|
||||
return str(getattr(self, self.CHILD_ATTRIBUTE))
|
||||
9
backend/venv/Lib/site-packages/praw/models/list/draft.py
Normal file
9
backend/venv/Lib/site-packages/praw/models/list/draft.py
Normal file
@@ -0,0 +1,9 @@
|
||||
"""Provide the DraftList class."""
|
||||
|
||||
from .base import BaseList
|
||||
|
||||
|
||||
class DraftList(BaseList):
|
||||
"""A list of :class:`.Draft` objects. Works just like a regular list."""
|
||||
|
||||
CHILD_ATTRIBUTE = "drafts"
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Provide the ModeratedList class."""
|
||||
|
||||
from .base import BaseList
|
||||
|
||||
|
||||
class ModeratedList(BaseList):
|
||||
"""A list of moderated :class:`.Subreddit` objects. Works just like a regular list."""
|
||||
|
||||
CHILD_ATTRIBUTE = "data"
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Provide the RedditorList class."""
|
||||
|
||||
from .base import BaseList
|
||||
|
||||
|
||||
class RedditorList(BaseList):
|
||||
"""A list of :class:`.Redditor` objects. Works just like a regular list."""
|
||||
|
||||
CHILD_ATTRIBUTE = "children"
|
||||
14
backend/venv/Lib/site-packages/praw/models/list/trophy.py
Normal file
14
backend/venv/Lib/site-packages/praw/models/list/trophy.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""Provide the TrophyList class."""
|
||||
|
||||
from .base import BaseList
|
||||
|
||||
|
||||
class TrophyList(BaseList):
|
||||
"""A list of :class:`.Trophy` objects. Works just like a regular list.
|
||||
|
||||
This class is solely used to parse responses from Reddit, so end users should not
|
||||
use this class directly.
|
||||
|
||||
"""
|
||||
|
||||
CHILD_ATTRIBUTE = "trophies"
|
||||
Reference in New Issue
Block a user