Skip to content

Commit bac52ca

Browse files
author
SuslikV
committed
Get json in raw format
Fixes an issue when application fails to load files from the saved project with non-English characters in the path to the clips. Also removing json.loads strict=False key as obsolete in 3.x Python.
1 parent e247a9b commit bac52ca

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/classes/json_data.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ def merge_settings(self, default, user):
127127
def read_from_file(self, file_path, path_mode="ignore"):
128128
""" Load JSON settings from a file """
129129
try:
130-
with open(file_path, 'r') as f:
130+
with open(file_path, 'r', encoding='utf-8') as f:
131131
contents = f.read()
132132
if contents:
133133
if path_mode == "absolute":
134134
# Convert any paths to absolute
135135
contents = self.convert_paths_to_absolute(file_path, contents)
136-
return json.loads(contents, strict=False)
136+
return json.loads(contents)
137137
except Exception as ex:
138138
msg = ("Couldn't load {} file: {}".format(self.data_type, ex))
139139
log.error(msg)
@@ -145,11 +145,11 @@ def read_from_file(self, file_path, path_mode="ignore"):
145145
def write_to_file(self, file_path, data, path_mode="ignore", previous_path=None):
146146
""" Save JSON settings to a file """
147147
try:
148-
contents = json.dumps(data, indent=1)
148+
contents = json.dumps(data, ensure_ascii=False, indent=1)
149149
if path_mode == "relative":
150150
# Convert any paths to relative
151151
contents = self.convert_paths_to_relative(file_path, previous_path, contents)
152-
with open(file_path, 'w') as f:
152+
with open(file_path, 'w', encoding='utf-8') as f:
153153
f.write(contents)
154154
except Exception as ex:
155155
msg = ("Couldn't save {} file:\n{}\n{}".format(self.data_type, file_path, ex))
@@ -164,18 +164,18 @@ def replace_string_to_absolute(self, match):
164164
# Find absolute path of file (if needed)
165165
if "@transitions" in path:
166166
new_path = path.replace("@transitions", os.path.join(info.PATH, "transitions"))
167-
new_path = json.dumps(new_path) # Escape backslashes
167+
new_path = json.dumps(new_path, ensure_ascii=False)
168168
return '"%s": %s' % (key, new_path)
169169

170170
elif "@assets" in path:
171171
new_path = path.replace("@assets", path_context["new_project_assets"])
172-
new_path = json.dumps(new_path) # Escape backslashes
172+
new_path = json.dumps(new_path, ensure_ascii=False)
173173
return '"%s": %s' % (key, new_path)
174174

175175
else:
176176
# Convert path to the correct relative path
177177
new_path = os.path.abspath(os.path.join(path_context.get("new_project_folder", ""), path))
178-
new_path = json.dumps(new_path) # Escape backslashes
178+
new_path = json.dumps(new_path, ensure_ascii=False)
179179
return '"%s": %s' % (key, new_path)
180180

181181
def convert_paths_to_absolute(self, file_path, data):
@@ -205,7 +205,7 @@ def replace_string_to_relative(self, match):
205205
if info.THUMBNAIL_PATH in folder_path:
206206
# Convert path to relative thumbnail path
207207
new_path = os.path.join("thumbnail", file_path).replace("\\", "/")
208-
new_path = json.dumps(new_path) # Escape backslashes
208+
new_path = json.dumps(new_path, ensure_ascii=False)
209209
return '"%s": %s' % (key, new_path)
210210

211211
# Determine if @transitions path is found
@@ -215,7 +215,7 @@ def replace_string_to_relative(self, match):
215215

216216
# Convert path to @transitions/ path
217217
new_path = os.path.join("@transitions", category_path, file_path).replace("\\", "/")
218-
new_path = json.dumps(new_path) # Escape backslashes
218+
new_path = json.dumps(new_path, ensure_ascii=False)
219219
return '"%s": %s' % (key, new_path)
220220

221221
# Determine if @assets path is found
@@ -225,7 +225,7 @@ def replace_string_to_relative(self, match):
225225

226226
# Convert path to @transitions/ path
227227
new_path = os.path.join(folder_path, file_path).replace("\\", "/")
228-
new_path = json.dumps(new_path) # Escape backslashes
228+
new_path = json.dumps(new_path, ensure_ascii=False)
229229
return '"%s": %s' % (key, new_path)
230230

231231
# Find absolute path of file (if needed)
@@ -239,7 +239,7 @@ def replace_string_to_relative(self, match):
239239
# Calculate new relateive path
240240
new_rel_path_folder = os.path.relpath(orig_abs_folder, path_context.get("new_project_folder", ""))
241241
new_rel_path = os.path.join(new_rel_path_folder, file_path).replace("\\", "/")
242-
new_rel_path = json.dumps(new_rel_path) # Escape backslashes
242+
new_rel_path = json.dumps(new_rel_path, ensure_ascii=False)
243243
return '"%s": %s' % (key, new_rel_path)
244244

245245
def convert_paths_to_relative(self, file_path, previous_path, data):

0 commit comments

Comments
 (0)