enumerific 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
enumerific/__init__.py CHANGED
@@ -1,87 +1,23 @@
1
- from __future__ import annotations
2
-
3
1
  from enum import *
4
2
 
5
- import logging
6
-
7
-
8
- class EnumValueError(ValueError):
9
- pass
10
-
11
-
12
- logger = logging.getLogger(__name__)
13
-
14
-
15
- class Enum(Enum):
16
- """An extended Enum class that provides support for validating an Enum value and
17
- accepting either enumeration class properties as enumeration values or their string
18
- names or values, and providing straightforward access to the enumeration values an
19
- Enum class holds."""
20
-
21
- @classmethod
22
- def validate(cls, value: Enum | str | int | object) -> bool:
23
- """Determine if an enum value name or enum value is valid or not"""
24
-
25
- try:
26
- return cls.reconcile(value=value, default=None) is not None
27
- except EnumValueError as exception:
28
- return False
29
-
30
- @classmethod
31
- def reconcile(
32
- cls,
33
- value: Enum | str | int | object,
34
- default: Enum = None,
35
- raises: bool = False,
36
- ) -> Enum | None:
37
- """Reconcile enum values and enum names to their corresponding enum option, as
38
- well as allowing valid enum options to be returned unmodified; if the provided
39
- enum option, enum value or enum name cannot be reconciled and if a default value
40
- has been provided, the default value will be returned instead and a warning
41
- message will be logged, otherwise an EnumValueError exception will be raised."""
42
-
43
- if isinstance(value, str):
44
- for prop, enumeration in cls.__members__.items():
45
- if enumeration.name.casefold() == value.casefold():
46
- return enumeration
47
- elif (
48
- isinstance(enumeration.value, str)
49
- and enumeration.value.casefold() == value.casefold()
50
- ):
51
- return enumeration
52
- elif isinstance(value, int) and not isinstance(value, bool):
53
- for prop, enumeration in cls.__members__.items():
54
- if isinstance(enumeration.value, int) and enumeration.value == value:
55
- return enumeration
56
- elif isinstance(value, bool):
57
- for prop, enumeration in cls.__members__.items():
58
- if enumeration.value is value:
59
- return enumeration
60
- elif isinstance(value, cls):
61
- if value in cls:
62
- return value
63
- elif not value is None:
64
- for prop, enumeration in cls.__members__.items():
65
- if enumeration.value == value:
66
- return enumeration
67
-
68
- if value is not None:
69
- if raises is True:
70
- raise EnumValueError(
71
- "The provided value, %r, is invalid and does not correspond with this enumeration's options!"
72
- % (value)
73
- )
74
- else:
75
- logger.warning(
76
- "The provided value, %r, is invalid, but a default, %r, has been provided, and will be returned instead!",
77
- value,
78
- default,
79
- )
80
-
81
- return default
82
-
83
- @classmethod
84
- def options(cls) -> list[Enum]:
85
- """Provide straightforward access to the list of enumeration options"""
86
-
87
- return cls.__members__.values()
3
+ from .logging import logger
4
+
5
+ from .exceptions import EnumValueError
6
+
7
+ from .extensible import (
8
+ Enumeration,
9
+ EnumerationType,
10
+ EnumerationInteger,
11
+ EnumerationString,
12
+ EnumerationFloat,
13
+ EnumerationComplex,
14
+ EnumerationBytes,
15
+ EnumerationTuple,
16
+ EnumerationSet,
17
+ EnumerationList,
18
+ EnumerationDictionary,
19
+ EnumerationFlag,
20
+ auto,
21
+ )
22
+
23
+ from .standard import Enum
@@ -0,0 +1,18 @@
1
+ class EnumValueError(ValueError):
2
+ pass
3
+
4
+
5
+ class EnumerationError(RuntimeError):
6
+ pass
7
+
8
+
9
+ class EnumerationOptionError(AttributeError, EnumerationError):
10
+ pass
11
+
12
+
13
+ class EnumerationSubclassingError(EnumerationError):
14
+ pass
15
+
16
+
17
+ class EnumerationNonUniqueError(EnumerationError):
18
+ pass