Fixed platform specific behaviour in format.py

Previously this would've used CRLF on Windows and LF on Linux, now it's
using CRLF on all platforms, as it's the current format
This commit is contained in:
Fabian Wunsch 2022-04-09 23:24:33 +02:00
parent fa8c58164f
commit ebcd5ff847

View file

@ -263,11 +263,11 @@ def per_line_entries(entries: list):
"""
Returns a string of all the entries, with every entry in one line.
"""
out = "[\n"
out = "[\r\n"
for entry in entries:
if entry:
out += json.dumps(entry, ensure_ascii=False) + ",\n"
out = out[:-2] + "\n]"
out += json.dumps(entry, ensure_ascii=False) + ",\r\n"
out = out[:-2] + "\r\n]"
return out
def format_all(entry: dict, silent=False):
@ -326,8 +326,8 @@ def go(path):
print(f"{len(entries)} checked.")
with open(path, "w", encoding='UTF-8') as f2:
f2.write(per_line_entries(entries))
with open(path, "wb") as f2:
f2.write(per_line_entries(entries).encode(encoding='utf-8'))
print("Writing completed. All done.")