Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions API/Classes/Base/FileClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ class File:
@staticmethod
def readFile(path):
try:
f = open(path, mode="r")
data = json.loads(f.read())
with open(path, mode="r") as f:
data = json.loads(f.read())
#cirilica u json file
#data = json.load(open(path, encoding='utf-8-sig'))
f.close()
return data
except( IndexError):
raise IndexError
Expand All @@ -21,14 +20,13 @@ def readFile(path):
@staticmethod
def writeFile(data, path):
try:
f = open(path, mode="w")
#json
#f.write(json.dumps(data, ensure_ascii=False, separators=(',', ':')))
#f.write(json.dumps(data, ensure_ascii=True, indent=4, sort_keys=False))
#ascii false da zapisemo cirilicu u file
f.write(json.dumps(data, ensure_ascii=True, indent=4, sort_keys=False))
with open(path, mode="w") as f:
#json
#f.write(json.dumps(data, ensure_ascii=False, separators=(',', ':')))
#f.write(json.dumps(data, ensure_ascii=True, indent=4, sort_keys=False))
#ascii false da zapisemo cirilicu u file
f.write(json.dumps(data, ensure_ascii=True, indent=4, sort_keys=False))
#f.write(json.dumps(data))
f.close()
# except(IOError, IndexError):
# return('File not found or file is empty')
#ovako prosljedjujemo exception u prethodnom slucaju vracamo response u funkciju koja poziva writeFile
Expand All @@ -44,10 +42,9 @@ def writeFile(data, path):
@staticmethod
def writeFileUJson(data, path):
try:
f = open(path, mode="w")
#usjon
f.write(json.dumps(data))
f.close()
with open(path, mode="w") as f:
#usjon
f.write(json.dumps(data))
except(IOError, IndexError):
raise IndexError
except OSError:
Expand All @@ -56,9 +53,8 @@ def writeFileUJson(data, path):
@staticmethod
def readParamFile(path):
try:
f = open(path, mode="r")
data = json.loads(f.read())
f.close()
with open(path, mode="r") as f:
data = json.loads(f.read())
return data
except( IndexError):
raise IndexError
Expand Down