Module PyEnum :: Class PyEnum
[hide private]
[frames] | no frames]

Class PyEnum

source code

object --+
         |
        PyEnum

Class that simulate the C enum type


Note: PyEnum does not allow general access to the class variables

Instance Methods [hide private]
 
__init__(self, *enum_ids)
Create the enum instance.
source code
int
__getattr__(self, enum_id)
Get the value for a specific enum id.
source code
int
__getitem__(self, enum_id)
Get the value for a specific enum id.
source code
 
__setattr__(self, attr_name, attr_val)
Set the value for a specific enum id.
source code
iter
__iter__(self)
Get an iterator object.
source code
iter
next(self)
Get the next iterator value.
source code
str
getID(self, enum_value)
Get the the id for a specific value.
source code
 
dump(self)
Dump all the enum identifier and values.
source code
 
toString(self)
Return all the enum identifier and values in a comma delimited string.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *enum_ids)
(Constructor)

source code 

Create the enum instance.

Parameters:
  • enum_ids (list) - List of the enum identifiers, an optional value can be associated with the key in the form of name=value
Overrides: object.__init__

__getattr__(self, enum_id)
(Qualification operator)

source code 

Get the value for a specific enum id.

Parameters:
  • enum_id (str) - Identifier of the enum value to retrieve.
Returns: int
The enum value.
Raises:
  • AttributeError - on failure

__getitem__(self, enum_id)
(Indexing operator)

source code 

Get the value for a specific enum id.

Parameters:
  • enum_id (str) - Identifier of the enum value to retrieve
Returns: int
The enum value.
Raises:
  • AttributeError - on failure

__setattr__(self, attr_name, attr_val)

source code 

Set the value for a specific enum id.

Parameters:
  • attr_name (str) - Identifier of the attribute to set
  • attr_val (object) - Object to assing to the attribute
Raises:
Overrides: object.__setattr__

Note: PyEnum does not allow updating the enums, it will raise EnumUpdateError.

__iter__(self)

source code 

Get an iterator object.

Returns: iter
Iterator object.

next(self)

source code 

Get the next iterator value.

Returns: iter
Next iterator object.

getID(self, enum_value)

source code 

Get the the id for a specific value.

Parameters:
  • enum_value (str) - Enum value to get the identifier for.
Returns: str
The enum identifier.
Raises:
  • AttributeError - on failure

Note: The ID of the first matching value will be returned.