-
Notifications
You must be signed in to change notification settings - Fork 24
/
schema.py
62 lines (45 loc) · 1.72 KB
/
schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
#
# Copyright 2016 Red Hat, Inc.
#
# Authors:
# Fam Zheng <famz@redhat.com>
#
# This work is licensed under the MIT License. Please see the LICENSE file or
# http://opensource.org/licenses/MIT.
"""Data schema classes"""
class Schema:
def __init__(self, name, title=None, desc=None, required=False):
self.name = name
self.title = title or name
self.desc = desc
self.required = required
class StringSchema(Schema):
def __init__(
self, name, title=None, desc=None, required=False, default="", multiline=False
):
super().__init__(name, title, desc, required)
self.multiline = multiline
self.default = default
class IntegerSchema(Schema):
def __init__(self, name, title=None, desc=None, required=False, default=0):
super().__init__(name, title, desc, required)
self.default = default
class EnumSchema(Schema):
def __init__(self, name, title=None, desc=None, required=False, enums=lambda: []):
super().__init__(name, title, desc, required)
self.enums = enums
class BooleanSchema(Schema):
def __init__(self, name, title=None, desc=None, required=False, default=0):
super().__init__(name, title, desc, required)
self.default = default
class MapSchema(Schema):
"""Homogeneous map from string to items"""
def __init__(self, name, title=None, desc=None, required=False, item=None):
super().__init__(name, title, desc, required)
self.item = item
class ArraySchema(Schema):
"""A fixed array of items"""
def __init__(self, name, title=None, desc=None, required=False, members=[]):
super().__init__(name, title, desc, required)
self.members = members