ooici/pyon — pull request #11 by thomaslennan (2011-12-22 17:06:50+00:00)
Title: Obj gen and enums

Pretty hacky effort at providing object generation for data model objects defined in the yaml files. Objects are generated into the interface/data/data_model.py file. This pull request also provides a functional enum syntax. TBD, fix the object.py class to properly handle enums as ints, not a special enum type. Enum syntax in yaml looks like:

# Stand alone enum def
SampleEnum: !enum (values=(SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY), default=SUNDAY)

---

SampleObject:
name: ''
time: "2011-07-27T02:59:43.1Z"
_int: 0
_float: 0.0
_str: ''
none:
_dict: {}
_list: []
_enum: !SampleEnum
# inline enum def
_another_enum: !enum (name=AnEnum, values=(VALUE1, VALUE2), default=VALUE2)

Resulting python generated looks like:

def SampleEnum():
SUNDAY = 1
MONDAY = 2
TUESDAY = 3
WEDNESDAY = 4
THURSDAY = 5
FRIDAY = 6
SATURDAY = 7

def AnEnum():
VALUE1 = 1
VALUE2 = 2

class SampleObject(object):
def __init__(self):
self.name = ''
self.time = '2011-07-27T02:59:43.1Z'
self._int = 0
self._float = 0.0
self._str = ''
self.none = None
self._dict = {}
self._list = []
self._enum = SampleEnum.SUNDAY
self._another_enum = AnEnum.VALUE2