mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 09:01:39 -05:00
Fix editor and rcfile encoding errors
This commit is contained in:
parent
be119b3d4e
commit
0507bd4bbf
1 changed files with 7 additions and 7 deletions
|
@ -88,7 +88,7 @@ def findUserConfigFile():
|
|||
"""
|
||||
home = os.path.expanduser("~")
|
||||
config_dir = getenv(
|
||||
"XDG_CONFIG_HOME", os.path.expanduser("~/.config")
|
||||
"XDG_CONFIG_HOME", os.path.join(home, ".config")
|
||||
)
|
||||
|
||||
# Will search for files in this order
|
||||
|
@ -120,7 +120,7 @@ def getUserConfig():
|
|||
|
||||
# for now, this is a simple file read, but if the files can
|
||||
# include other files, that will need more work
|
||||
return open(cfg_file, "r").read()
|
||||
return open(cfg_file, "r", encoding="utf-8").read()
|
||||
|
||||
|
||||
def sanitizeFilename(fn):
|
||||
|
@ -440,7 +440,7 @@ def handleMessage(message):
|
|||
os.path.expandvars(
|
||||
os.path.expanduser(message["file"])
|
||||
),
|
||||
"r",
|
||||
"r", encoding="utf-8"
|
||||
) as file:
|
||||
reply["content"] = file.read()
|
||||
reply["code"] = 0
|
||||
|
@ -468,14 +468,14 @@ def handleMessage(message):
|
|||
reply["code"] = 2
|
||||
|
||||
elif cmd == "write":
|
||||
with open(message["file"], "w") as file:
|
||||
with open(message["file"], "w", encoding="utf-8") as file:
|
||||
file.write(message["content"])
|
||||
|
||||
elif cmd == "writerc":
|
||||
path = os.path.expanduser(message["file"])
|
||||
if not os.path.isfile(path) or message["force"]:
|
||||
if not os.path.isfile(path) or message["force"]:
|
||||
try:
|
||||
with open(path, "w") as file:
|
||||
with open(path, "w", encoding="utf-8") as file:
|
||||
file.write(message["content"])
|
||||
reply["code"] = 0 # Success.
|
||||
except EnvironmentError:
|
||||
|
@ -490,7 +490,7 @@ def handleMessage(message):
|
|||
prefix = "tmp_{}_".format(sanitizeFilename(prefix))
|
||||
|
||||
(handle, filepath) = tempfile.mkstemp(prefix=prefix, suffix=".txt")
|
||||
with os.fdopen(handle, "w") as file:
|
||||
with os.fdopen(handle, "w", encoding="utf-8") as file:
|
||||
file.write(message["content"])
|
||||
reply["content"] = filepath
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue