3 changed files with 31 additions and 16 deletions
@ -0,0 +1,20 @@ |
|||||
|
import six |
||||
|
|
||||
|
|
||||
|
def get_enum_members(enum): |
||||
|
for k, v in six.iteritems(enum.__dict__): |
||||
|
if not isinstance(k, six.string_types): |
||||
|
continue |
||||
|
|
||||
|
if k.startswith('_') or not k.isupper(): |
||||
|
continue |
||||
|
|
||||
|
yield k, v |
||||
|
|
||||
|
|
||||
|
def get_enum_value_by_name(enum, name): |
||||
|
name = name.lower() |
||||
|
|
||||
|
for k, v in get_enum_members(enum): |
||||
|
if k.lower() == name: |
||||
|
return v |
Loading…
Reference in new issue