Пример #1
0
class Person(Object):

    first = Attribute(type=str)

    last = Attribute(type=str)

    full = Attribute(type=str)
Пример #2
0
class Animal(Object):
    name = Attribute(type=str)
    age = Attribute(type=int)

    def __init__(self, name, age):
        Object.__init__(self)
        self.name = name
        self.age = age
Пример #3
0
class PositivePoint(Object):

    x = Attribute(type=float)

    @x.validator
    def x(self, x):
        if x < 0.0:
            raise ValueError('Cannot set PositivePoint.x to {}'.format(x))

    y = Attribute(type=float, validator=lambda self, y: y > 0)
Пример #4
0
        class PositivePoint2(Object):
            x = Attribute(type=float)
            y = Attribute(type=float)

            @classmethod
            def from_yaml(cls, loader, node, round_trip_data=None):
                # from_yaml.__func__ is the unbound class method
                self = Object.from_yaml.__func__(PositivePoint2, loader, node,
                                                 round_trip_data)

                if self.x < 0.0 or self.y < 0.0:
                    raise YamlizingError(
                        'Point x and y values must be positive', node)

                return self
Пример #5
0
        class DailyMenu(KeyedList):
            key_attr = MenuItem.name
            item_type = MenuItem
            day = Attribute(type=str)

            def __init__(self, day):
                self.day = day
Пример #6
0
class ConfigRoot(Object):
    my_int = Attribute(type=int)
    my_float = Attribute(type=float)
    my_str = Attribute(type=str)
    description = Attribute(type=str)

    required_defaults = Attribute(type=RequiredDefaults,
                                  default=RequiredDefaults())

    job_batch = Attribute(type=JobBatch, default=None)
    job_streaming = Attribute(type=JobStreaming, default=None)

    elastic = Attribute(type=Elastic)
Пример #7
0
class AnimalWithFriends(Object):

    name = Attribute(type=str)
Пример #8
0
 class ClassWithLists(Object):
     ints = Attribute(type=IntList, default=None)
Пример #9
0
 class ClassWithLists(Object):
     ints = Attribute(type=IntList)
     strs = Attribute(type=StrList)
Пример #10
0
        del cwl.ints
        self.assertEqual('{}\n', ClassWithLists.dump(cwl))


class AnimalWithFriends(Object):

    name = Attribute(type=str)


class AnimalSequence(Sequence):

    item_type = AnimalWithFriends


AnimalWithFriends.friends = Attribute(name='friends',
                                      type=AnimalSequence,
                                      default=None)


class Test_two_way(unittest.TestCase):
    def test_IntList(self):
        self.assertEqual([1, 2, 3], IntList.load(IntList.dump([1, 2, 3])))
        il = IntList((1, 2, 3))
        self.assertEqual([1, 2, 3], il)
        with self.assertRaises(TypeError):
            IntList(123)

    def test_StrList(self):
        abc = 'a b c'.split()
        self.assertEqual(abc, StrList.load(StrList.dump(abc)))
        self.assertEqual(3, len(abc))
Пример #11
0
 class MenuItem(Map):
     key_type = Typed(str)
     value_type = Dynamic
     name = Attribute(type=str)
Пример #12
0
 class DailyMenu(KeyedList):
     key_attr = MenuItem.name
     item_type = MenuItem
     day = Attribute(type=str)
Пример #13
0
 class NamedMap(Map):
     key_type = Typed(str)
     value_type = Dynamic
     name = Attribute(type=str)
Пример #14
0
 class Owner(Object):
     name = Attribute(type=str)
     pets = Attribute(type=NamedKennel)
Пример #15
0
class Node(Object):
    host = Attribute(type=str, default=DEFAULT_ELASTIC_HOST)
    port = Attribute(type=int, default=DEFAULT_ELASTIC_PORT)
Пример #16
0
class JobStreaming(Object):
    kafka_broker = Attribute(type=str, default=DEFAULT_KAFKA_HOST)
Пример #17
0
class JobBatch(Object):
    redis_host = Attribute(type=str, default=DEFAULT_REDIS_HOST)
Пример #18
0
class RequiredDefaults(Object):
    x = Attribute(type=str, default="val-x")
    y = Attribute(type=str, default="val-y")
Пример #19
0
class Elastic(Object):
    nodes = Attribute(type=Nodes)