Package csb :: Package core :: Class Enum
[frames] | no frames]

Class Enum

source code

object --+
         |
        Enum

A collection of efficient static methods for working with enum classes.

Instance Methods

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
create(classname, **members)
Dynamically create a new enum from a list of key:value pairs.
source code
bool
ismember(item, enumclass)
Return True if item is a member of enumclass.
source code
frozenset
members(enumclass)
Return all member items of the enumclass.
source code
frozenset
names(enumclass)
Return the names of all items in the enumclass.
source code
EnumItem
parse(enumclass, value, ignore_case=True)
Parse value as an enumclass member value.
source code
EnumItem
parsename(enumclass, name, ignore_case=True)
Parse name as a member of enumclass.
source code
str
tostring(item)
Return a string representation of the enum item.
source code
frozenset
values(enumclass)
Return all values of the enumclass.
source code
Properties

Inherited from object: __class__

Method Details

create(classname, **members)
Static Method

source code 

Dynamically create a new enum from a list of key:value pairs. Note that each key must be a valid python identifier, and the values must be unique.

Parameters:
  • classname (str) - class name for the new enum

Note: The recommended way to create an enum is to define a public subclass of enum in the global namespace of your module. You should avoid creating enums dynamically if static construction is possible, because dynamically created enums cannot be pickled.

ismember(item, enumclass)
Static Method

source code 

Return True if item is a member of enumclass.

Parameters:
  • enumclass (type) - target enumeration type
  • item (EnumItem) - the enum item to be tested
Returns: bool

members(enumclass)
Static Method

source code 

Return all member items of the enumclass.

Parameters:
  • enumclass (type) - the enumeration class to traverse
Returns: frozenset
a set of all enumclass members

names(enumclass)
Static Method

source code 

Return the names of all items in the enumclass.

Parameters:
  • enumclass (type) - the enumeration class to traverse
Returns: frozenset
a set of all enumclass member names

parse(enumclass, value, ignore_case=True)
Static Method

source code 

Parse value as an enumclass member value.

Parameters:
  • enumclass (type) - target enum subclass
  • ignore_case (bool) - if set to True, triggers case insensitive parsing
  • value (str, int, float)
Returns: EnumItem
a member of enumclass, having such value
Raises:

parsename(enumclass, name, ignore_case=True)
Static Method

source code 

Parse name as a member of enumclass.

Parameters:
  • enumclass (type) - target enum subclass
  • name (str) - enumclass member name to parse
  • ignore_case (bool) - if set to True, triggers case insensitive parsing
Returns: EnumItem
a member of enumclass, having such name
Raises:

tostring(item)
Static Method

source code 

Return a string representation of the enum item.

Parameters:
  • item (EnumItem) - an enum item to be converted to a string
Returns: str
the value of the enum member

values(enumclass)
Static Method

source code 

Return all values of the enumclass.

Parameters:
  • enumclass (type) - the enumeration class to traverse
Returns: frozenset
a set of all enum values