obspy.core.util.obspy_types.Enum

class Enum(enums, replace={})[source]

Bases: object

Enumerated type (enum) implementation for Python.

Parameters:

replace (dict, optional) – Dictionary of keys which are replaced by values.

Example

>>> from obspy.core.util import Enum
>>> units = Enum(["m", "s", "m/s", "m/(s*s)", "m*s", "other"])

There are different ways to access the correct enum values:

>>> print(units.get('m/s'))
m/s
>>> print(units['S'])
s
>>> print(units.OTHER)
other
>>> print(units[3])
m/(s*s)
>>> units.xxx  
Traceback (most recent call last):
...
AttributeError: 'xxx'

Changing enum values will not work:

>>> units.m = 5  
Traceback (most recent call last):
...
NotImplementedError
>>> units['m'] = 'xxx'  
Traceback (most recent call last):
...
NotImplementedError

Calling with a value will either return the mapped enum value or None:

>>> print(units("M*s"))
m*s
>>> units('xxx')
>>> print(units(5))
other

The following enum allows replacing certain entries:

>>> units2 = Enum(["m", "s", "m/s", "m/(s*s)", "m*s", "other"],
...               replace={'meter': 'm'})
>>> print(units2('m'))
m
>>> print(units2('meter'))
m

Public Methods

get

items

iteritems

keys

values

Private Methods

Warning

Private methods are mainly for internal/developer use and their API might change without notice.

Enum._repr_pretty_(p, cycle)[source]

Special Methods

Enum.__call__(enum)[source]
Enum.__contains__(value)[source]
Enum.__delattr__(name, /)

Implement delattr(self, name).

Enum.__dir__()

Default dir() implementation.

Enum.__eq__(value, /)

Return self==value.

Enum.__format__(format_spec, /)

Default object formatter.

Enum.__ge__(value, /)

Return self>=value.

Enum.__getattr__(name)[source]
Enum.__getattribute__(name, /)

Return getattr(self, name).

Enum.__getitem__(key)
Enum.__gt__(value, /)

Return self>value.

Enum.__hash__()

Return hash(self).

Enum.__init__(enums, replace={})[source]
Enum.__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

Enum.__le__(value, /)

Return self<=value.

Enum.__lt__(value, /)

Return self<value.

Enum.__ne__(value, /)

Return self!=value.

Enum.__new__(**kwargs)
Enum.__reduce__()

Helper for pickle.

Enum.__reduce_ex__(protocol, /)

Helper for pickle.

Enum.__repr__()[source]
>>> enum = Enum(["c", "a", "b"])
>>> print(repr(enum))
Enum(["c", "a", "b"])
>>> enum = Enum(["not existing",
...              "not reported",
...              "earthquake",
...              "controlled explosion",
...              "experimental explosion",
...              "industrial explosion"])
>>> print(repr(enum))  
Enum(["not existing", "not reported", ..., "experimental explosion",
      "industrial explosion"])
Enum.__setattr__(name, value)[source]
Enum.__setitem__(name, value)
Enum.__sizeof__()

Size of object in memory, in bytes.

Enum.__str__()[source]
>>> enum = Enum(["c", "a", "b"])
>>> print(enum)
Enum(["c", "a", "b"])
>>> enum = Enum(["not existing",
...              "not reported",
...              "earthquake",
...              "controlled explosion",
...              "experimental explosion",
...              "industrial explosion"])
>>> print(enum)  
Enum(["not existing", "not reported", ..., "experimental explosion",
      "industrial explosion"])
Enum.__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).