Skip to content

Commit 111d78b

Browse files
committed
Fix functions to use python naming conventions
1 parent d3af535 commit 111d78b

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def _prettify(elem):
1212
return reparsed.toprettyxml(indent=" ")
1313

1414
@staticmethod
15-
def generateProcedure(procedure):
15+
def generate_procedure(procedure):
1616
procedureElement = ElementTree.Element('Procedure')
17-
procedureElement.attrib = procedure.generatePropertiesDictionary()
17+
procedureElement.attrib = procedure.generate_properties_dict()
1818

1919
for page in procedure.pages:
2020
pageElement = ElementTree.SubElement(procedureElement, 'Page')
@@ -23,7 +23,7 @@ def generateProcedure(procedure):
2323
ElementTree.SubElement(
2424
pageElement,
2525
'Element',
26-
element.generatePropertiesDictionary()
26+
element.generate_properties_dict()
2727
)
2828

2929
return Generator._prettify(procedureElement)

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def main():
1414
try:
1515
tree = ElementTree.parse(args[1])
1616
procedureElement = tree.getroot()
17-
procedure = Parser.parseProcedure(procedureElement)
17+
procedure = Parser.parse_procedure(procedureElement)
1818

19-
generatedProc = Generator.generateProcedure(procedure)
19+
generatedProc = Generator.generate_procedure(procedure)
2020
with open('out.xml', 'w') as outfile:
2121
outfile.write(generatedProc)
2222

models.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def __init__(self, eleType, eleId, concept, question, answer):
66
self.question = question
77
self.answer = answer
88

9-
def generatePropertiesDictionary(self):
9+
def generate_properties_dict(self):
1010
return {
1111
'type': self.eleType,
1212
'id': self.eleId,
@@ -16,7 +16,7 @@ def generatePropertiesDictionary(self):
1616
}
1717

1818
@staticmethod
19-
def _validateAttributes(attrib):
19+
def _validate_attributes(attrib):
2020
if 'type' not in attrib:
2121
raise Exception('Element', 'type')
2222

@@ -33,17 +33,17 @@ def _validateAttributes(attrib):
3333
raise Exception('Element', 'answer')
3434

3535
@staticmethod
36-
def createElement(attrib):
37-
Element._validateAttributes(attrib)
36+
def create_element(attrib):
37+
Element._validate_attributes(attrib)
3838

3939
if attrib['type'] == 'MULTI_SELECT':
40-
return MultiSelectElement._createElement(attrib)
40+
return MultiSelectElement._create_element(attrib)
4141
if attrib['type'] == 'ENTRY':
42-
return EntryElement._createElement(attrib)
42+
return EntryElement._create_element(attrib)
4343
if attrib['type'] == 'PICTURE':
44-
return PictureElement._createElement(attrib)
44+
return PictureElement._create_element(attrib)
4545
if attrib['type'] == 'GPS':
46-
return GPSElement._createElement(attrib)
46+
return GPSElement._create_element(attrib)
4747

4848
raise Exception('Element', 'type')
4949

@@ -60,20 +60,20 @@ def __init__(self, eleId, concept, question, choices, answer):
6060

6161
self.choices = choices
6262

63-
def generatePropertiesDictionary(self):
64-
propDict = super(MultiSelectElement, self).generatePropertiesDictionary()
63+
def generate_properties_dict(self):
64+
propDict = super(MultiSelectElement, self).generate_properties_dict()
6565
propDict['choices'] = self.choices
6666

6767
return propDict
6868

6969
@staticmethod
70-
def _validateAttributes(attrib):
70+
def _validate_attributes(attrib):
7171
if 'choices' not in attrib:
7272
raise Exception('MultiSelectElement', 'choices')
7373

7474
@staticmethod
75-
def _createElement(attrib):
76-
MultiSelectElement._validateAttributes(attrib)
75+
def _create_element(attrib):
76+
MultiSelectElement._validate_attributes(attrib)
7777

7878
eleId = attrib['id']
7979
concept = attrib['concept']
@@ -101,15 +101,15 @@ def __init__(self, eleId, concept, question, answer, numeric=None):
101101
)
102102
self.numeric = numeric
103103

104-
def generatePropertiesDictionary(self):
105-
propDict = super(EntryElement, self).generatePropertiesDictionary()
104+
def generate_properties_dict(self):
105+
propDict = super(EntryElement, self).generate_properties_dict()
106106
if self.numeric is not None:
107107
propDict['numeric'] = self.numeric
108108

109109
return propDict
110110

111111
@staticmethod
112-
def _createElement(attrib):
112+
def _create_element(attrib):
113113
eleId = attrib['id']
114114
concept = attrib['concept']
115115
question = attrib['question']
@@ -136,7 +136,7 @@ def __init__(self, eleId, concept, question, answer):
136136
)
137137

138138
@staticmethod
139-
def _createElement(attrib):
139+
def _create_element(attrib):
140140
eleId = attrib['id']
141141
concept = attrib['concept']
142142
question = attrib['question']
@@ -161,7 +161,7 @@ def __init__(self, eleId, concept, question, answer):
161161
)
162162

163163
@staticmethod
164-
def _createElement(attrib):
164+
def _create_element(attrib):
165165
eleId = attrib['id']
166166
concept = attrib['concept']
167167
question = attrib['question']
@@ -189,14 +189,14 @@ def __init__(self, title, author):
189189
def __contains__(self, page):
190190
return page in self.pages
191191

192-
def generatePropertiesDictionary(self):
192+
def generate_properties_dict(self):
193193
return {
194194
'title': self.title,
195195
'author': self.author
196196
}
197197

198198
@staticmethod
199-
def createProcedure(attrib):
199+
def create_procedure(attrib):
200200
if 'title' not in attrib:
201201
raise Exception('Procedure', 'title')
202202

parser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@
33

44
class Parser(object):
55
@staticmethod
6-
def parseElement(elementElement):
6+
def parse_element(elementElement):
77
if elementElement.tag != 'Element':
88
raise Exception('ElementElement', 'tag')
99

10-
element = Element.createElement(elementElement.attrib)
10+
element = Element.create_element(elementElement.attrib)
1111

1212
return element
1313

1414
@staticmethod
15-
def parsePage(pageElement):
15+
def parse_page(pageElement):
1616
if pageElement.tag != 'Page':
1717
raise Exception('PageElement', 'tag')
1818

1919
page = Page()
2020

2121
for pageChild in pageElement:
2222
if pageChild.tag == 'Element':
23-
element = Parser.parseElement(pageChild)
23+
element = Parser.parse_element(pageChild)
2424
page.elements.append(element)
2525
else:
2626
raise Exception('Page', 'child')
2727

2828
return page
2929

3030
@staticmethod
31-
def parseProcedure(procedureElement):
31+
def parse_procedure(procedureElement):
3232
if procedureElement.tag != 'Procedure':
3333
raise Exception('ProcedureElement', 'tag')
3434

35-
procedure = Procedure.createProcedure(procedureElement.attrib)
35+
procedure = Procedure.create_procedure(procedureElement.attrib)
3636

3737
for pageElement in procedureElement:
38-
page = Parser.parsePage(pageElement)
38+
page = Parser.parse_page(pageElement)
3939
procedure.pages.append(page)
4040

4141
return procedure

0 commit comments

Comments
 (0)