Exemple #1
0
def parse_icon(d, path):
    check_allowed_properties(d, path, ("type", "name", "color"))
    check_required_properties(d, path, ("type", "name"))
    check_text(d['name'], path + ".name")

    if 'color' in d:
        check_color(d['color'], path + ".color")
Exemple #2
0
def parse_document(d):
    check_allowed_properties(d, "#", ("version", "title", "elements"))
    check_required_properties(d, "#", ("version", "title", "elements"))

    check_version(d['version'], "#version")
    check_text(d['title'], "#title")
    parse_elements(d['elements'], "#elements")
Exemple #3
0
def parse_table(d, path):
    check_allowed_properties(d, path, ("type", "rows", "headers"))
    check_required_properties(d, path, ("type", "rows"))

    if 'headers' in d:
        if not isinstance(d['headers'], list):
            raise ValidationError(path + ".headers", "must be an array")

        col_count = len(d['headers'])
        if col_count == 0:
            raise ValidationError(path + ".headers", "must not be empty")

        for i in range(0, col_count):
            h = d['headers'][i]
            parse_text(h, "%s.headers[%s]" % (path, i))

    if not isinstance(d['rows'], list):
        raise ValidationError(path + ".rows", "must be an array")

    if not d['rows']:
        raise ValidationError(path + ".rows", "must not be empty")

    for i in range(0, len(d['rows'])):
        r = d['rows'][i]
        p = "%s.rows[%s]" % (path, i)

        if 'headers' in d:
            if len(r) != col_count:
                raise ValidationError(
                    p, "does not have the correct number of columns")

        parse_elements(r, p)
Exemple #4
0
def parse_text(d, path):
    check_allowed_properties(d, path, ("type", "text", "emphasis", "color"))
    check_required_properties(d, path, ("type", "text"))

    check_text(d['text'], path + ".text")

    if 'emphasis' in d:
        if d['emphasis'] not in ("bold", "italic"):
            raise ValidationError(path + ".emphasis", "not a valid value")

    if 'color' in d:
        check_color(d['color'], path + ".color")
Exemple #5
0
def parse_grid(d, path):
    check_allowed_properties(d, path, ("type", "rows"))
    check_required_properties(d, path, ("type", "rows"))

    if not isinstance(d['rows'], list):
        raise ValidationError(path + ".rows", "must be an array")

    if not d['rows']:
        raise ValidationError(path + ".rows", "must not be empty")

    for i in range(0, len(d['rows'])):
        r = d['rows'][i]
        parse_elements(r, "%s.rows[%s]" % (path, i))
Exemple #6
0
def parse_pie(d, path):
    check_allowed_properties(d, path, ("type", "data", "name"))
    check_required_properties(d, path, ("type", "data", "name"))
    check_text(d['name'], path + ".name")

    for i in range(0, len(d['data'])):
        elem = d['data'][i]
        p = "%s.data[%s]" % (path, i)

        check_allowed_properties(elem, p, ("label", "value", "color"))
        check_required_properties(elem, p, ("label", "value", "color"))

        check_text(elem['label'], p + ".label")
        check_number(elem['value'], p + ".value")
        check_color(elem['color'], p + ".color")
Exemple #7
0
def parse_paragraph(d, path):
    check_allowed_properties(d, path, ("type", "elements"))
    check_required_properties(d, path, ("type", "elements"))
    parse_elements(d['elements'], path + ".elements")
Exemple #8
0
def parse_unordered_list(d, path):
    check_allowed_properties(d, path, ("type", "elements"))
    check_required_properties(d, path, ("type", "elements"))
    parse_elements(d['elements'], path + ".elements")
Exemple #9
0
def parse_hline(d, path):
    check_allowed_properties(d, path, ("type", ))
    check_required_properties(d, path, ("type", ))
Exemple #10
0
def parse_heading(d, path):
    check_allowed_properties(d, path, ("type", "text"))
    check_required_properties(d, path, ("type", "text"))
    check_text(d['text'], path + ".text")