forked from MicrochipTech/cryptoauthlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatcaenum.py
More file actions
40 lines (31 loc) · 1.04 KB
/
Copy pathatcaenum.py
File metadata and controls
40 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Enum Extension for improved comparisons
"""
from enum import Enum
# This is because @DynamicClassAttribue isn't exactly @property and pylint doesn't really understand it as the same
# pylint: disable-msg=comparison-with-callable
class AtcaEnum(Enum):
"""
Overload of standard python enum for some additional convenience features. Assumes closer alignment to C style enums
where the value is always an integer
"""
def __str__(self):
return self.name
def __eq__(self, other):
if isinstance(other, str):
answer = (self.name == other)
else:
answer = (self.value == int(other))
return answer
def __ne__(self, other):
if isinstance(other, str):
answer = (self.name != other)
else:
answer = (self.value != int(other))
return answer
def __int__(self):
return int(self.value)
def __hash__(self):
return hash(int(self.value))
# Make module import * safe - keep at the end of the file
__all__ = ['AtcaEnum']