-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
"""Provide the Flair class.""" | ||
from .base import RedditBase | ||
|
||
|
||
class RichFlairBase(RedditBase): | ||
"""A base class for rich flairs. | ||
Flairs of this type are obtained by either | ||
:meth:`.SubredditFlair.templates` | ||
or :meth:`.SubredditFlair.link_templates`. | ||
""" | ||
|
||
STR_FIELD = "text" | ||
|
||
def __eq__(self, other): | ||
"""Check that two instances of the class are equal.""" | ||
if isinstance(other, str): | ||
return str(self) == other | ||
return ( | ||
isinstance(other, self.__class__) | ||
and str(self) == str(other) | ||
and self.id == other.id | ||
and self.css_class == other.css_class | ||
) | ||
|
||
def __hash__(self): | ||
"""Get the hash of the instance.""" | ||
return ( | ||
hash(self.__class__.__name__) | ||
^ hash(str(self)) | ||
^ hash(self.id) | ||
^ hash(self.css_class) | ||
) | ||
|
||
def __init__(self, reddit, _data): | ||
"""Initialize the class.""" | ||
super().__init__(reddit, _data=_data) | ||
|
||
def change_css_class(self, css_class): | ||
"""Change the css class of the flair.""" | ||
self.css_class = css_class | ||
|
||
def change_text(self, text): | ||
"""Change the text of the flair.""" | ||
self.text = text | ||
|
||
|
||
class SubmissionFlair(RedditBase): | ||
"""An individual SubmissionFlair object. | ||
**Typical Attributes** | ||
This table describes attributes that typically belong to objects of this | ||
class. Since attributes are dynamically provided (see | ||
:ref:`determine-available-attributes-of-an-object`), there is not a | ||
guarantee that these attributes will always be present, nor is this list | ||
necessarily comprehensive. | ||
======================= =================================================== | ||
Attribute Description | ||
======================= =================================================== | ||
``flair_template_id`` The id of the flair template. | ||
``flair_text_editable`` Whether or not the flair text can be edited. | ||
``flair_text`` The text of the flair | ||
""" | ||
|
||
STR_FIELD = "flair_text" | ||
|
||
def __eq__(self, other): | ||
"""Check that two flairs are the same flair.""" | ||
if isinstance(other, str): | ||
return str(self) == other | ||
return ( | ||
isinstance(other, self.__class__) | ||
and str(self) == str(other) | ||
and self.flair_template_id == other.flair_template_id | ||
) | ||
|
||
def __hash__(self): | ||
"""Return the hash of the flair.""" | ||
return ( | ||
hash(self.__class__.__name__) | ||
^ hash(str(self)) | ||
^ hash(self.flair_template_id) | ||
) | ||
|
||
def __init__(self, reddit, _data): | ||
"""Instantizes the flair object.""" | ||
super().__init__(reddit, _data=_data) | ||
|
||
def change_text(self, text): | ||
"""Allow the submission author to give a custom text to the flair. | ||
Please verify that the flair is editable before editing the text of the | ||
flair. | ||
""" | ||
self.flair_text = text | ||
|
||
|
||
class SubmissionModerationFlair(RichFlairBase): | ||
"""A special flair that is returned to moderators. | ||
**Typical Attributes** | ||
This table describes attributes that typically belong to objects of this | ||
class. Since attributes are dynamically provided (see | ||
:ref:`determine-available-attributes-of-an-object`), there is not a | ||
guarantee that these attributes will always be present, nor is this list | ||
necessarily comprehensive. | ||
======================= =================================================== | ||
Attribute Description | ||
======================= =================================================== | ||
``allowable_content`` The type of content allowed in the flair ( | ||
acceptable values are ``all``, ``emoji`` or | ||
``text``). | ||
``background_color`` The background color of the flair. Values can be a | ||
color name (``dark`` or a 6-digit RGB code | ||
``#ffffff``.) | ||
``css_class`` The css class of the flair. | ||
``id`` The flair template id. | ||
``max_emojis`` The amount of :class:`.Emoji` that can go in the | ||
flair. | ||
``mod_only`` Whether or not the flair is mod only or not. | ||
``richtext`` A list containing data about any richtext elements, | ||
including any emojis, present in the flair. | ||
``text`` The text of the flair. | ||
``text_color`` The color of the text | ||
``text_editable`` Whether or not the flair text can be edited. | ||
``type`` The type of the flair (``text`` or ``richtext``.) | ||
""" | ||
|
||
|
||
class RedditorFlair(RichFlairBase): | ||
"""An individual RedditorFlair object. | ||
**Typical Attributes** | ||
This table describes attributes that typically belong to objects of this | ||
class. Since attributes are dynamically provided (see | ||
:ref:`determine-available-attributes-of-an-object`), there is not a | ||
guarantee that these attributes will always be present, nor is this list | ||
necessarily comprehensive. | ||
======================= =================================================== | ||
Attribute Description | ||
======================= =================================================== | ||
``allowable_content`` The type of content allowed in the flair ( | ||
acceptable values are ``all``, ``emoji`` or | ||
``text``). | ||
``background_color`` The background color of the flair. Values can be a | ||
color name (``dark`` or a 6-digit RGB code | ||
``#ffffff``.) | ||
``css_class`` The css class of the flair. | ||
``id`` The flair template id. | ||
``max_emojis`` The amount of :class:`.Emoji` that can go in the | ||
flair. | ||
``mod_only`` Whether or not the flair is mod only or not. | ||
``richtext`` A list containing data about any richtext elements, | ||
including any emojis, present in the flair. | ||
``text`` The text of the flair. | ||
``text_color`` The color of the text | ||
``text_editable`` Whether or not the flair text can be edited. | ||
``type`` The type of the flair (``text`` or ``richtext``.) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.