Fixed json parsing of local files.
This commit is contained in:
parent
b1303a76d9
commit
985bf2f115
|
@ -11,15 +11,20 @@ class JsonParser(object):
|
||||||
if self.printStatus:
|
if self.printStatus:
|
||||||
print('Download', fileName.rsplit('/', 1)[1] , 'from URL:', fileName)
|
print('Download', fileName.rsplit('/', 1)[1] , 'from URL:', fileName)
|
||||||
resource = urllib.request.urlopen(fileName)
|
resource = urllib.request.urlopen(fileName)
|
||||||
else:
|
|
||||||
if self.printStatus:
|
|
||||||
print('Open', fileName.rsplit('/', 1)[1] , 'from file:', fileName)
|
|
||||||
resource = open(fileName)
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(resource.read().decode('utf-8'))
|
data = json.loads(resource.read().decode('utf-8'))
|
||||||
except:
|
except:
|
||||||
raise HieraException('Error while parsing a json file (perhapes misformed file): ' + fileName)
|
raise HieraException('Error while parsing a json file (perhapes misformed file): ' + fileName)
|
||||||
finally:
|
finally:
|
||||||
resource.close()
|
resource.close()
|
||||||
|
else:
|
||||||
|
if self.printStatus:
|
||||||
|
print('Open', fileName.rsplit('/', 1)[1] , 'from file:', fileName)
|
||||||
|
with open(fileName) as data_file:
|
||||||
|
try:
|
||||||
|
data = json.load(data_file)
|
||||||
|
except:
|
||||||
|
raise HieraException('Error while parsing a json file (perhapes misformed file): ' + fileName)
|
||||||
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in a new issue