|
1 |
| -# /*########################################################################## |
2 |
| -# |
3 |
| -# Copyright (c) 2019 European Synchrotron Radiation Facility |
4 |
| -# |
5 |
| -# Permission is hereby granted, free of charge, to any person obtaining a copy |
6 |
| -# of this software and associated documentation files (the "Software"), to deal |
7 |
| -# in the Software without restriction, including without limitation the rights |
8 |
| -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9 |
| -# copies of the Software, and to permit persons to whom the Software is |
10 |
| -# furnished to do so, subject to the following conditions: |
11 |
| -# |
12 |
| -# The above copyright notice and this permission notice shall be included in |
13 |
| -# all copies or substantial portions of the Software. |
14 |
| -# |
15 |
| -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 |
| -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 |
| -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18 |
| -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 |
| -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20 |
| -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 |
| -# THE SOFTWARE. |
22 |
| -# |
23 |
| -# ###########################################################################*/ |
24 |
| -"""An :class:`.Enum` class with additional features.""" |
25 |
| - |
26 |
| -__authors__ = ["T. Vincent"] |
27 |
| -__license__ = "MIT" |
28 |
| -__date__ = "29/04/2019" |
29 |
| - |
30 |
| - |
31 |
| -import enum |
32 |
| - |
33 |
| - |
34 |
| -class Enum(enum.Enum): |
35 |
| - """Enum with additional class methods.""" |
36 |
| - |
37 |
| - @classmethod |
38 |
| - def from_value(cls, value): |
39 |
| - """Convert a value to corresponding Enum member |
40 |
| -
|
41 |
| - :param value: The value to compare to Enum members |
42 |
| - If it is already a member of Enum, it is returned directly. |
43 |
| - :return: The corresponding enum member |
44 |
| - :rtype: Enum |
45 |
| - :raise ValueError: In case the conversion is not possible |
46 |
| - """ |
47 |
| - if isinstance(value, cls): |
48 |
| - return value |
49 |
| - for member in cls: |
50 |
| - if value == member.value: |
51 |
| - return member |
52 |
| - raise ValueError("Cannot convert: %s" % value) |
53 |
| - |
54 |
| - @classmethod |
55 |
| - def members(cls): |
56 |
| - """Returns a tuple of all members. |
57 |
| -
|
58 |
| - :rtype: Tuple[Enum] |
59 |
| - """ |
60 |
| - return tuple(member for member in cls) |
61 |
| - |
62 |
| - @classmethod |
63 |
| - def names(cls): |
64 |
| - """Returns a tuple of all member names. |
65 |
| -
|
66 |
| - :rtype: Tuple[str] |
67 |
| - """ |
68 |
| - return tuple(member.name for member in cls) |
69 |
| - |
70 |
| - @classmethod |
71 |
| - def values(cls): |
72 |
| - """Returns a tuple of all member values. |
73 |
| -
|
74 |
| - :rtype: Tuple |
75 |
| - """ |
76 |
| - return tuple(member.value for member in cls) |
| 1 | +from ._enum import * |
| 2 | +from silx.utils.deprecation import deprecated_warning |
| 3 | + |
| 4 | +deprecated_warning( |
| 5 | + "Class", |
| 6 | + "silx.utils.enum.Enum", |
| 7 | + since_version="2.1.1", |
| 8 | + replacement="Python built-in Enum class", |
| 9 | +) |
0 commit comments