Skip to content

Commit 38cc5b4

Browse files
committed
[fix] change function
1 parent 5b5aba5 commit 38cc5b4

File tree

5 files changed

+24
-253
lines changed

5 files changed

+24
-253
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
index.js
2-
2+
__pycache__

main.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def parseFile(pathToFile="", schema=None, optionsUser={}):
77
def checkOptions(optionsUser, attr, defaultValue):
8-
if hasattr(optionsUser, attr) or (attr == "lineCallBack" and callable(optionsUser[attr])):
8+
if attr in optionsUser or (attr == "lineCallBack" and callable(optionsUser[attr])):
99
return optionsUser[attr]
1010
else:
1111
return defaultValue
@@ -46,13 +46,17 @@ def checkOptions(optionsUser, attr, defaultValue):
4646
def createFieldsBinding(schemaObject, startPath=""):
4747
global firstLine
4848
bindings = []
49-
for oneElement in schemaObject:
49+
for index, value in enumerate(schemaObject):
50+
if isinstance(schemaObject, list):
51+
oneElement = index
52+
elif isinstance(schemaObject, dict):
53+
oneElement = value
5054
if startPath == "":
5155
path = '{}'.format(oneElement)
5256
else:
5357
path = '{}{}{}'.format(
5458
startPath, options["privateSeparator"], oneElement)
55-
if isinstance(schemaObject[oneElement], dict) or isinstance(schemaObject[oneElement], list):
59+
if isinstance(schemaObject, dict) and (isinstance(schemaObject[oneElement], dict) or isinstance(schemaObject[oneElement], list)):
5660
if isinstance(schemaObject[oneElement], list):
5761
bindings.append({
5862
"name": oneElement,
@@ -62,7 +66,7 @@ def createFieldsBinding(schemaObject, startPath=""):
6266
bindings = [
6367
*bindings, *createFieldsBinding(schemaObject[oneElement], path)]
6468
else:
65-
if isinstance(schemaObject, list) and options.arrayParse and schemaObject[oneElement] in firstLine:
69+
if isinstance(schemaObject, list) and options["arrayParse"] and schemaObject[oneElement] in firstLine:
6670
bindings.append({
6771
"name": schemaObject[oneElement],
6872
"path": path,
@@ -97,7 +101,7 @@ def parseLine(line):
97101
onePathName = oneRow["name"]
98102
allPath = onePathRow.split(options["privateSeparator"])
99103
currentValue = None
100-
if (not hasattr(oneRow, 'type')) or (hasattr(oneRow, 'type') and oneRow["type"] == None):
104+
if ('type' not in oneRow) or ('type' in oneRow and oneRow["type"] == None):
101105
schemaValue = oneRow["value"]
102106
index = firstLine.index(oneRow["name"])
103107
if index == -1:
@@ -117,9 +121,9 @@ def parseLine(line):
117121
currentValue = schemaValue(allValues)
118122
else:
119123
currentValue = schemaValue(currentValue)
120-
elif (hasattr(oneRow, 'type') and oneRow["type"] == "helper-array"):
124+
elif ('type' in oneRow and oneRow["type"] == "helper-array"):
121125
currentValue = []
122-
elif (hasattr(oneRow, 'type') and oneRow["type"] == "static"):
126+
elif ('type' in oneRow and oneRow["type"] == "static"):
123127
currentValue = oneRow["value"]
124128
goodPlace = None
125129
if len(allPath) > 1:
@@ -131,14 +135,13 @@ def parseLine(line):
131135
if not isinstance(goodPlace, list):
132136
goodPlace[nextPath] = ""
133137
else:
134-
if not hasattr(goodPlace, nextPath):
138+
if nextPath not in goodPlace:
135139
goodPlace[nextPath] = {}
136140
goodPlace = goodPlace[nextPath]
137-
if goodPlace:
138-
if isinstance(goodPlace, list):
139-
goodPlace.append(currentValue)
140-
elif isinstance(goodPlace, dict):
141-
goodPlace[onePathName] = currentValue
141+
if isinstance(goodPlace, list):
142+
goodPlace.append(currentValue)
143+
elif isinstance(goodPlace, dict):
144+
goodPlace[onePathName] = currentValue
142145
else:
143146
goodPlace = currentValue
144147
else:

main.py.save

Lines changed: 0 additions & 211 deletions
This file was deleted.

py.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from main import parseFile
22

33
schema = {
4+
"test1": [
5+
"test3"
6+
],
7+
"test2": "string"
8+
}
9+
10+
schema2 = {
411
"test1": {
512
"test3": "string",
613
},

0 commit comments

Comments
 (0)