def __init__(self, name, default, enum, fmt="H"):
        """ Initializes enum fields.

        @param name:    name of this field
        @param default: default value of this field
        @param enum:    either a dict or a tuple of two callables. Dict keys are  # noqa: E501
                        the internal values, while the dict values are the
                        user-friendly representations. If the tuple is provided,  # noqa: E501
                        the first callable receives the internal value as
                        parameter and returns the user-friendly representation
                        and the second callable does the converse. The first
                        callable may return None to default to a literal string
                        (repr()) representation.
        @param fmt:     struct.pack format used to parse and serialize the
                        internal value from and to machine representation.
        """
        if isinstance(enum, ObservableDict):
            enum.observe(self)

        if isinstance(enum, tuple):
            self.i2s_cb = enum[0]
            self.s2i_cb = enum[1]
            self.i2s = None
            self.s2i = None
        else:
            i2s = self.i2s = {}
            s2i = self.s2i = {}
            self.i2s_cb = None
            self.s2i_cb = None
            if isinstance(enum, list):
                keys = list(range(len(enum)))
            elif isinstance(enum, DADict):
                keys = enum.keys()
            else:
                keys = list(enum)
            if any(isinstance(x, str) for x in keys):
                i2s, s2i = s2i, i2s
            for k in keys:
                i2s[k] = enum[k]
                s2i[enum[k]] = k
        Field.__init__(self, name, default, fmt)
def __init__ ( self , name , default , enum , fmt = "H" ) : if isinstance ( enum , ObservableDict ) : enum . observe ( self ) if isinstance ( enum , tuple ) : self . i2s_cb = enum [ 0 ] self . s2i_cb = enum [ 1 ] self . i2s = None self . s2i = None else : i2s = self . i2s = { } s2i = self . s2i = { } self . i2s_cb = None self . s2i_cb = None if isinstance ( enum , list ) : keys = list ( range ( len ( enum ) ) ) elif isinstance ( enum , DADict ) : keys = enum . keys ( ) else : keys = list ( enum ) if any ( isinstance ( x , str ) for x in keys ) : i2s , s2i = s2i , i2s for k in keys : i2s [ k ] = enum [ k ] s2i [ enum [ k ] ] = k Field . __init__ ( self , name , default , fmt )
Initializes enum fields.

        @param name:    name of this field
        @param default: default value of this field
        @param enum:    either a dict or a tuple of two callables. Dict keys are  # noqa: E501
                        the internal values, while the dict values are the
                        user-friendly representations. If the tuple is provided,  # noqa: E501
                        the first callable receives the internal value as
                        parameter and returns the user-friendly representation
                        and the second callable does the converse. The first
                        callable may return None to default to a literal string
                        (repr()) representation.
        @param fmt:     struct.pack format used to parse and serialize the
                        internal value from and to machine representation.