diff --git a/fbchat/_attachment.py b/fbchat/_attachment.py index a10c027..847377e 100644 --- a/fbchat/_attachment.py +++ b/fbchat/_attachment.py @@ -1,9 +1,9 @@ import attr -from ._core import Image +from ._core import attrs_default, Image from . import _util -@attr.s +@attrs_default class Attachment: """Represents a Facebook attachment.""" @@ -11,12 +11,12 @@ class Attachment: uid = attr.ib(None) -@attr.s +@attrs_default class UnsentMessage(Attachment): """Represents an unsent message attachment.""" -@attr.s +@attrs_default class ShareAttachment(Attachment): """Represents a shared item (e.g. URL) attachment.""" diff --git a/fbchat/_core.py b/fbchat/_core.py index afc90bd..ae7ecb1 100644 --- a/fbchat/_core.py +++ b/fbchat/_core.py @@ -4,6 +4,9 @@ import aenum log = logging.getLogger("fbchat") +#: Default attrs settings for classes +attrs_default = attr.s(slots=True) # TODO: Add kw_only=True + class Enum(aenum.Enum): """Used internally by ``fbchat`` to support enumerations""" diff --git a/fbchat/_file.py b/fbchat/_file.py index ef0b8af..9d255cd 100644 --- a/fbchat/_file.py +++ b/fbchat/_file.py @@ -1,10 +1,10 @@ import attr -from ._core import Image +from ._core import attrs_default, Image from . import _util from ._attachment import Attachment -@attr.s +@attrs_default class FileAttachment(Attachment): """Represents a file that has been sent as a Facebook attachment.""" @@ -28,7 +28,7 @@ class FileAttachment(Attachment): ) -@attr.s +@attrs_default class AudioAttachment(Attachment): """Represents an audio file that has been sent as a Facebook attachment.""" @@ -51,7 +51,7 @@ class AudioAttachment(Attachment): ) -@attr.s +@attrs_default class ImageAttachment(Attachment): """Represents an image that has been sent as a Facebook attachment. @@ -108,7 +108,7 @@ class ImageAttachment(Attachment): ) -@attr.s +@attrs_default class VideoAttachment(Attachment): """Represents a video that has been sent as a Facebook attachment.""" diff --git a/fbchat/_group.py b/fbchat/_group.py index c0ef982..bb73b2c 100644 --- a/fbchat/_group.py +++ b/fbchat/_group.py @@ -1,10 +1,10 @@ import attr -from ._core import Image +from ._core import attrs_default, Image from . import _util, _plan from ._thread import ThreadType, Thread -@attr.s +@attrs_default class Group(Thread): """Represents a Facebook group. Inherits `Thread`.""" diff --git a/fbchat/_location.py b/fbchat/_location.py index 28f5be7..e94ddb6 100644 --- a/fbchat/_location.py +++ b/fbchat/_location.py @@ -1,10 +1,10 @@ import attr -from ._core import Image +from ._core import attrs_default, Image from ._attachment import Attachment from . import _util -@attr.s +@attrs_default class LocationAttachment(Attachment): """Represents a user location. @@ -44,7 +44,7 @@ class LocationAttachment(Attachment): ) -@attr.s +@attrs_default class LiveLocationAttachment(LocationAttachment): """Represents a live user location.""" diff --git a/fbchat/_message.py b/fbchat/_message.py index 8546d25..ef0c7c8 100644 --- a/fbchat/_message.py +++ b/fbchat/_message.py @@ -1,7 +1,7 @@ import attr import json from string import Formatter -from ._core import log, Enum +from ._core import log, attrs_default, Enum from . import _util, _attachment, _location, _file, _quick_reply, _sticker @@ -42,7 +42,7 @@ class MessageReaction(Enum): NO = "👎" -@attr.s +@attrs_default class Mention: """Represents a ``@mention``.""" @@ -54,7 +54,7 @@ class Mention: length = attr.ib(10) -@attr.s +@attrs_default class Message: """Represents a Facebook message.""" diff --git a/fbchat/_page.py b/fbchat/_page.py index 53edf6c..aceb88b 100644 --- a/fbchat/_page.py +++ b/fbchat/_page.py @@ -1,10 +1,10 @@ import attr -from ._core import Image +from ._core import attrs_default, Image from . import _plan from ._thread import ThreadType, Thread -@attr.s +@attrs_default class Page(Thread): """Represents a Facebook page. Inherits `Thread`.""" diff --git a/fbchat/_plan.py b/fbchat/_plan.py index cb0a0c7..59e3941 100644 --- a/fbchat/_plan.py +++ b/fbchat/_plan.py @@ -1,6 +1,6 @@ import attr import json -from ._core import Enum +from ._core import attrs_default, Enum from . import _util @@ -10,7 +10,7 @@ class GuestStatus(Enum): DECLINED = 3 -@attr.s +@attrs_default class Plan: """Represents a plan.""" diff --git a/fbchat/_poll.py b/fbchat/_poll.py index 86a7c14..3273484 100644 --- a/fbchat/_poll.py +++ b/fbchat/_poll.py @@ -1,7 +1,8 @@ import attr +from ._core import attrs_default -@attr.s +@attrs_default class Poll: """Represents a poll.""" @@ -24,7 +25,7 @@ class Poll: ) -@attr.s +@attrs_default class PollOption: """Represents a poll option.""" diff --git a/fbchat/_quick_reply.py b/fbchat/_quick_reply.py index 653f31e..eb5ae86 100644 --- a/fbchat/_quick_reply.py +++ b/fbchat/_quick_reply.py @@ -1,8 +1,9 @@ import attr +from ._core import attrs_default from ._attachment import Attachment -@attr.s +@attrs_default class QuickReply: """Represents a quick reply.""" @@ -16,7 +17,7 @@ class QuickReply: is_response = attr.ib(False) -@attr.s +@attrs_default class QuickReplyText(QuickReply): """Represents a text quick reply.""" @@ -28,7 +29,7 @@ class QuickReplyText(QuickReply): _type = "text" -@attr.s +@attrs_default class QuickReplyLocation(QuickReply): """Represents a location quick reply (Doesn't work on mobile).""" @@ -36,7 +37,7 @@ class QuickReplyLocation(QuickReply): _type = "location" -@attr.s +@attrs_default class QuickReplyPhoneNumber(QuickReply): """Represents a phone number quick reply (Doesn't work on mobile).""" @@ -46,7 +47,7 @@ class QuickReplyPhoneNumber(QuickReply): _type = "user_phone_number" -@attr.s +@attrs_default class QuickReplyEmail(QuickReply): """Represents an email quick reply (Doesn't work on mobile).""" diff --git a/fbchat/_state.py b/fbchat/_state.py index 38cf767..78092fd 100644 --- a/fbchat/_state.py +++ b/fbchat/_state.py @@ -5,7 +5,7 @@ import requests import random import urllib.parse -from ._core import log +from ._core import log, attrs_default from . import _graphql, _util, _exception FB_DTSG_REGEX = re.compile(r'name="fb_dtsg" value="(.*?)"') @@ -98,7 +98,7 @@ def _2fa_helper(session, code, r): return r -@attr.s(slots=True) # TODO i Python 3: Add kw_only=True +@attrs_default # TODO i Python 3: Add kw_only=True class State: """Stores and manages state required for most Facebook requests.""" diff --git a/fbchat/_sticker.py b/fbchat/_sticker.py index 312b759..7189232 100644 --- a/fbchat/_sticker.py +++ b/fbchat/_sticker.py @@ -1,9 +1,9 @@ import attr -from ._core import Image +from ._core import attrs_default, Image from ._attachment import Attachment -@attr.s +@attrs_default class Sticker(Attachment): """Represents a Facebook sticker that has been sent to a thread as an attachment.""" diff --git a/fbchat/_thread.py b/fbchat/_thread.py index 6540a24..b517d1b 100644 --- a/fbchat/_thread.py +++ b/fbchat/_thread.py @@ -1,5 +1,5 @@ import attr -from ._core import Enum, Image +from ._core import attrs_default, Enum, Image class ThreadType(Enum): @@ -67,7 +67,7 @@ class ThreadColor(Enum): return cls._extend_if_invalid(value) -@attr.s +@attrs_default class Thread: """Represents a Facebook thread.""" diff --git a/fbchat/_user.py b/fbchat/_user.py index 6e7e698..18dd773 100644 --- a/fbchat/_user.py +++ b/fbchat/_user.py @@ -1,5 +1,5 @@ import attr -from ._core import Enum, Image +from ._core import attrs_default, Enum, Image from . import _util, _plan from ._thread import ThreadType, Thread @@ -41,7 +41,7 @@ class TypingStatus(Enum): TYPING = 1 -@attr.s +@attrs_default class User(Thread): """Represents a Facebook user. Inherits `Thread`."""