55
66def 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 :
0 commit comments