-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.py
41 lines (29 loc) · 1.1 KB
/
parser.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
from models import *
class Parser(object):
@staticmethod
def parse_element(elementElement):
if elementElement.tag != 'Element':
raise Exception('ElementElement', 'tag')
element = Element.create_element(elementElement.attrib)
return element
@staticmethod
def parse_page(pageElement):
if pageElement.tag != 'Page':
raise Exception('PageElement', 'tag')
page = Page()
for pageChild in pageElement:
if pageChild.tag == 'Element':
element = Parser.parse_element(pageChild)
page.elements.append(element)
else:
raise Exception('Page', 'child')
return page
@staticmethod
def parse_procedure(procedureElement):
if procedureElement.tag != 'Procedure':
raise Exception('ProcedureElement', 'tag')
procedure = Procedure.create_procedure(procedureElement.attrib)
for pageElement in procedureElement:
page = Parser.parse_page(pageElement)
procedure.pages.append(page)
return procedure