Set encoding for all text reads and writes to utf8, as windows defaults to latin1

This commit is contained in:
Veronica K. B. Olsen
2019-10-28 13:44:13 +01:00
parent 3a8b7846ab
commit f760eeb544
14 changed files with 24 additions and 24 deletions
+2 -2
View File
@@ -193,7 +193,7 @@ class Config:
logger.debug("Loading config file")
cnfParse = configparser.ConfigParser()
try:
cnfParse.read_file(open(path.join(self.confPath,self.confFile)))
cnfParse.read_file(open(path.join(self.confPath,self.confFile),mode="r",encoding="utf8"))
except Exception as e:
logger.error("Could not load config file")
return False
@@ -315,7 +315,7 @@ class Config:
# Write config file
try:
cnfParse.write(open(path.join(self.confPath,self.confFile),"w"))
cnfParse.write(open(path.join(self.confPath,self.confFile),mode="w",encoding="utf8"))
self.confChanged = False
except Exception as e:
logger.error("Could not save config file")
+1 -1
View File
@@ -63,7 +63,7 @@ class ConcatFile(TextFile):
def _doOpenFile(self, filePath):
try:
self.outFile = open(filePath,mode="wt+")
self.outFile = open(filePath,mode="wt+",encoding="utf8")
except Exception as e:
self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR)
return False
+1 -1
View File
@@ -34,7 +34,7 @@ class HtmlFile(TextFile):
def _doOpenFile(self, filePath):
try:
self.outFile = open(filePath,mode="wt+")
self.outFile = open(filePath,mode="wt+",encoding="utf8")
self.outFile.write("<!DOCTYPE html>\n")
self.outFile.write("<html>\n")
self.outFile.write("<head>\n")
+1 -1
View File
@@ -34,7 +34,7 @@ class LaTeXFile(TextFile):
def _doOpenFile(self, filePath):
try:
self.outFile = open(filePath,mode="wt+")
self.outFile = open(filePath,mode="wt+",encoding="utf8")
self.outFile.write("\\documentclass[12pt]{report}\n")
self.outFile.write("\\usepackage[utf8]{inputenc}\n")
self.outFile.write("\n")
+1 -1
View File
@@ -34,7 +34,7 @@ class MarkdownFile(TextFile):
def _doOpenFile(self, filePath):
try:
self.outFile = open(filePath,mode="wt+")
self.outFile = open(filePath,mode="wt+",encoding="utf8")
except Exception as e:
self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR)
return False
+1 -1
View File
@@ -153,7 +153,7 @@ class TextFile():
that uses a different file format that requires a different approach.
"""
try:
self.outFile = open(filePath,mode="wt+")
self.outFile = open(filePath,mode="wt+",encoding="utf8")
self.outFile.write("\n\n")
except Exception as e:
self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR)
+1 -1
View File
@@ -147,7 +147,7 @@ class GuiSessionLogView(QDialog):
logger.debug("Loading session log file")
try:
with open(logFile,mode="r") as inFile:
with open(logFile,mode="r",encoding="utf8") as inFile:
for inLine in inFile:
inData = inLine.split()
if len(inData) != 8:
+1 -1
View File
@@ -390,7 +390,7 @@ class GuiMain(QMainWindow):
theText = None
try:
with open(loadFile,mode="rt") as inFile:
with open(loadFile,mode="rt",encoding="utf8") as inFile:
theText = inFile.read()
except Exception as e:
self.makeAlert(["Could not read file. The file cannot be a binary file.",str(e)], nwAlert.ERROR)
+2 -2
View File
@@ -53,7 +53,7 @@ class NWDoc():
if path.isfile(docPath):
try:
with open(docPath,mode="r") as inFile:
with open(docPath,mode="r",encoding="utf8") as inFile:
theDoc = inFile.read()
except Exception as e:
self.makeAlert(["Failed to open document file.",str(e)], nwAlert.ERROR)
@@ -89,7 +89,7 @@ class NWDoc():
if path.isfile(docPath): rename(docPath,docBack)
try:
with open(docPath,mode="w") as outFile:
with open(docPath,mode="w",encoding="utf8") as outFile:
outFile.write(docText)
except Exception as e:
self.makeAlert(["Could not save document.",str(e)], nwAlert.ERROR)
+2 -2
View File
@@ -91,7 +91,7 @@ class NWIndex():
if path.isfile(indexFile):
logger.debug("Loading index file")
try:
with open(indexFile,mode="r") as inFile:
with open(indexFile,mode="r",encoding="utf8") as inFile:
theJson = inFile.read()
theData = json.loads(theJson)
except Exception as e:
@@ -119,7 +119,7 @@ class NWIndex():
else:
nIndent = None
try:
with open(indexFile,mode="w+") as outFile:
with open(indexFile,mode="w+",encoding="utf8") as outFile:
outFile.write(json.dumps({
"tagIndex" : self.tagIndex,
"refIndex" : self.refIndex,
+2 -2
View File
@@ -328,7 +328,7 @@ class NWProject():
# Write the xml tree to file
saveFile = path.join(self.projPath,self.projFile)
try:
with open(saveFile,"wb") as outFile:
with open(saveFile,mode="wb") as outFile:
outFile.write(etree.tostring(
nwXML,
pretty_print = True,
@@ -657,7 +657,7 @@ class NWProject():
if self.projMeta is None:
return False
with open(path.join(self.projMeta, nwFiles.SESS_INFO), mode="a+") as outFile:
with open(path.join(self.projMeta, nwFiles.SESS_INFO),mode="a+",encoding="utf8") as outFile:
print((
"Start: {opened:s} "
"End: {closed:s} "
+5 -5
View File
@@ -137,7 +137,7 @@ class Theme:
cssData = ""
try:
if path.isfile(self.cssFile):
with open(self.cssFile,mode="r") as inFile:
with open(self.cssFile,mode="r",encoding="utf8") as inFile:
cssData = inFile.read()
except Exception as e:
logger.error("Could not load theme css file")
@@ -154,7 +154,7 @@ class Theme:
# Config File
confParser = configparser.ConfigParser()
try:
confParser.read_file(open(self.confFile))
confParser.read_file(open(self.confFile,mode="r",encoding="utf8"))
except Exception as e:
logger.error("Could not load theme settings from: %s" % self.confFile)
return False
@@ -205,7 +205,7 @@ class Theme:
confParser = configparser.ConfigParser()
try:
confParser.read_file(open(self.syntaxFile))
confParser.read_file(open(self.syntaxFile,mode="r",encoding="utf8"))
except Exception as e:
logger.error("Could not load syntax colours from: %s" % self.syntaxFile)
return False
@@ -251,7 +251,7 @@ class Theme:
themeConf = path.join(self.mainConf.themeRoot, self.guiPath, themeDir, self.confName)
logger.verbose("Checking theme config for '%s'" % themeDir)
try:
confParser.read_file(open(themeConf))
confParser.read_file(open(themeConf,mode="r",encoding="utf8"))
except Exception as e:
self.theParent.makeAlert(["Could not load theme config file",str(e)],nwAlert.ERROR)
continue
@@ -279,7 +279,7 @@ class Theme:
continue
logger.verbose("Checking theme syntax for '%s'" % syntaxFile)
try:
confParser.read_file(open(syntaxPath))
confParser.read_file(open(syntaxPath,moe="r",encoding="utf8"))
except Exception as e:
self.theParent.makeAlert(["Could not load syntax file",str(e)],nwAlert.ERROR)
return []
+2 -2
View File
@@ -37,7 +37,7 @@ class OptLastState():
if path.isfile(stateFile):
logger.debug("Loading options file")
try:
with open(stateFile,mode="r") as inFile:
with open(stateFile,mode="r",encoding="utf8") as inFile:
theJson = inFile.read()
theState = json.loads(theJson)
except Exception as e:
@@ -52,7 +52,7 @@ class OptLastState():
stateFile = path.join(self.theProject.projMeta,self.theFile)
logger.debug("Saving options file")
try:
with open(stateFile,mode="w+") as outFile:
with open(stateFile,mode="w+",encoding="utf8") as outFile:
outFile.write(json.dumps(self.theState, indent=2))
except Exception as e:
logger.error("Failed to save options file")
+2 -2
View File
@@ -13,13 +13,13 @@ def ensureDir(theDir):
def cmpFiles(fileOne, fileTwo, ignoreLines=[]):
try:
foOne = open(fileOne,mode="r")
foOne = open(fileOne,mode="r",encoding="utf8")
except Exception as e:
print(str(e))
return False
try:
foTwo = open(fileTwo,mode="r")
foTwo = open(fileTwo,mode="r",encoding="utf8")
except Exception as e:
print(str(e))
return False