Remove _core.Enum and aenum dependency
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import attr
|
import attr
|
||||||
import logging
|
import logging
|
||||||
import aenum
|
|
||||||
|
|
||||||
log = logging.getLogger("fbchat")
|
log = logging.getLogger("fbchat")
|
||||||
|
|
||||||
@@ -12,25 +11,6 @@ kw_only = sys.version_info[:2] > (3, 5)
|
|||||||
attrs_default = attr.s(slots=True, kw_only=kw_only)
|
attrs_default = attr.s(slots=True, kw_only=kw_only)
|
||||||
|
|
||||||
|
|
||||||
class Enum(aenum.Enum):
|
|
||||||
"""Used internally to support enumerations"""
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
# For documentation:
|
|
||||||
return "{}.{}".format(type(self).__name__, self.name)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _extend_if_invalid(cls, value):
|
|
||||||
try:
|
|
||||||
return cls(value)
|
|
||||||
except ValueError:
|
|
||||||
log.warning(
|
|
||||||
"Failed parsing {.__name__}({!r}). Extending enum.".format(cls, value)
|
|
||||||
)
|
|
||||||
aenum.extend_enum(cls, "UNKNOWN_{}".format(value).upper(), value)
|
|
||||||
return cls(value)
|
|
||||||
|
|
||||||
|
|
||||||
# Frozen, so that it can be used in sets
|
# Frozen, so that it can be used in sets
|
||||||
@attr.s(frozen=True, slots=True, kw_only=kw_only)
|
@attr.s(frozen=True, slots=True, kw_only=kw_only)
|
||||||
class Image:
|
class Image:
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
import attr
|
import attr
|
||||||
|
import enum
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
from ._core import log, attrs_default, Enum
|
from ._core import log, attrs_default
|
||||||
from . import _util, _session, _attachment, _location, _file, _quick_reply, _sticker
|
from . import _util, _session, _attachment, _location, _file, _quick_reply, _sticker
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class EmojiSize(Enum):
|
class EmojiSize(enum.Enum):
|
||||||
"""Used to specify the size of a sent emoji."""
|
"""Used to specify the size of a sent emoji."""
|
||||||
|
|
||||||
LARGE = "369239383222810"
|
LARGE = "369239383222810"
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import attr
|
import attr
|
||||||
import datetime
|
import datetime
|
||||||
from ._core import attrs_default, Enum
|
import enum
|
||||||
|
from ._core import attrs_default
|
||||||
from . import _exception, _util, _session
|
from . import _exception, _util, _session
|
||||||
|
|
||||||
|
|
||||||
class GuestStatus(Enum):
|
class GuestStatus(enum.Enum):
|
||||||
INVITED = 1
|
INVITED = 1
|
||||||
GOING = 2
|
GOING = 2
|
||||||
DECLINED = 3
|
DECLINED = 3
|
||||||
|
@@ -2,12 +2,13 @@ import abc
|
|||||||
import attr
|
import attr
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
from ._core import attrs_default, Enum, Image
|
import enum
|
||||||
|
from ._core import attrs_default, Image
|
||||||
from . import _util, _exception, _session, _graphql, _attachment, _file, _plan
|
from . import _util, _exception, _session, _graphql, _attachment, _file, _plan
|
||||||
from typing import MutableMapping, Any, Iterable, Tuple, Optional
|
from typing import MutableMapping, Any, Iterable, Tuple, Optional
|
||||||
|
|
||||||
|
|
||||||
class ThreadLocation(Enum):
|
class ThreadLocation(enum.Enum):
|
||||||
"""Used to specify where a thread is located (inbox, pending, archived, other)."""
|
"""Used to specify where a thread is located (inbox, pending, archived, other)."""
|
||||||
|
|
||||||
INBOX = "INBOX"
|
INBOX = "INBOX"
|
||||||
|
@@ -14,7 +14,6 @@ maintainer = "Mads Marquart"
|
|||||||
maintainer-email = "madsmtm@gmail.com"
|
maintainer-email = "madsmtm@gmail.com"
|
||||||
home-page = "https://github.com/carpedm20/fbchat/"
|
home-page = "https://github.com/carpedm20/fbchat/"
|
||||||
requires = [
|
requires = [
|
||||||
"aenum~=2.0",
|
|
||||||
"attrs>=19.1",
|
"attrs>=19.1",
|
||||||
"requests~=2.19",
|
"requests~=2.19",
|
||||||
"beautifulsoup4~=4.0",
|
"beautifulsoup4~=4.0",
|
||||||
|
@@ -1,14 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from fbchat._core import Enum
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
|
|
||||||
def test_enum_extend_if_invalid():
|
|
||||||
class TestEnum(Enum):
|
|
||||||
A = 1
|
|
||||||
B = 2
|
|
||||||
|
|
||||||
assert TestEnum._extend_if_invalid(1) == TestEnum.A
|
|
||||||
assert TestEnum._extend_if_invalid(3) == TestEnum.UNKNOWN_3
|
|
||||||
assert TestEnum._extend_if_invalid(3) == TestEnum.UNKNOWN_3
|
|
||||||
assert TestEnum(3) == TestEnum.UNKNOWN_3
|
|
Reference in New Issue
Block a user