Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from federation.entities.mixins import (
PublicMixin, TargetIDMixin, ParticipationMixin, CreatedAtMixin, RawContentMixin, OptionalRawContentMixin,
EntityTypeMixin, ProviderDisplayNameMixin, RootTargetIDMixin, BaseEntity)
from federation.utils.network import fetch_content_type
class Accept(CreatedAtMixin, TargetIDMixin, BaseEntity):
"""An acceptance message for some target."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# ID not required for accept
self._required.remove('id')
class Image(OptionalRawContentMixin, CreatedAtMixin, BaseEntity):
"""Reflects a single image, possibly linked to another object."""
url: str = ""
name: str = ""
height: int = 0
width: int = 0
inline: bool = False
media_type: str = ""
_default_activity = ActivityType.CREATE
_valid_media_types: Tuple[str] = (
"image/jpeg",
"image/png",
"image/gif",
)
def __init__(self, *args, **kwargs):
_relationship_valid_values = ["sharing", "following", "ignoring", "blocking"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._required += ["relationship"]
def validate_relationship(self):
"""Ensure relationship is of a certain type."""
if self.relationship not in self._relationship_valid_values:
raise ValueError("relationship should be one of: {valid}".format(
valid=", ".join(self._relationship_valid_values)
))
class Profile(CreatedAtMixin, OptionalRawContentMixin, PublicMixin, BaseEntity):
"""Represents a profile for a user."""
atom_url = ""
email = ""
gender = ""
image_urls = None
location = ""
name = ""
nsfw = False
public_key = ""
tag_list = None
url = ""
username = ""
inboxes: Dict = None
_allowed_children = (Image,)
super().__init__(*args, **kwargs)
self._required += ["following"]
# ID not required for follow
self._required.remove('id')
class Post(RawContentMixin, PublicMixin, CreatedAtMixin, ProviderDisplayNameMixin, BaseEntity):
"""Reflects a post, status message, etc, which will be composed from the message or to the message."""
location = ""
url = ""
_allowed_children = (Image,)
_default_activity = ActivityType.CREATE
class Reaction(ParticipationMixin, CreatedAtMixin, BaseEntity):
"""Represents a reaction to another object, for example a like."""
participation = "reaction"
reaction = ""
_default_activity = ActivityType.CREATE
_reaction_valid_values = ["like"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._required += ["reaction"]
def validate_reaction(self):
"""Ensure reaction is of a certain type.
Mainly for future expansion.
"""