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")
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")
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)
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")
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))
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")
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")
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")
def parse_hline(d, path): check_allowed_properties(d, path, ("type", )) check_required_properties(d, path, ("type", ))
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")