From a0de713ca2f3a2c6753a6633d1b4b3f790bec8d5 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 26 Nov 2020 00:48:28 +0100 Subject: [PATCH] Py2: do not open Init[Gui].py files with utf-8 encoding --- src/App/FreeCADInit.py | 10 ++++++---- src/Gui/FreeCADGuiInit.py | 9 ++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index 2edaa47436..c5f5a16670 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -172,9 +172,12 @@ def InitApplications(): if (os.path.exists(InstallFile)): try: # XXX: This looks scary securitywise... - - with codecs.open(filename=InstallFile, encoding="utf-8") as f: - exec(f.read()) + if sys.version_info.major < 3: + with open(InstallFile) as f: + exec(f.read()) + else: + with open(file=InstallFile, encoding="utf-8") as f: + exec(f.read()) except Exception as inst: Log('Init: Initializing ' + Dir + '... failed\n') Log('-'*100+'\n') @@ -630,7 +633,6 @@ FreeCAD.Logger = FCADLogger # init every application by importing Init.py try: import traceback - import codecs InitApplications() except Exception as e: Err('Error in InitApplications ' + str(e) + '\n') diff --git a/src/Gui/FreeCADGuiInit.py b/src/Gui/FreeCADGuiInit.py index 5899ae0287..5f0f619cf8 100644 --- a/src/Gui/FreeCADGuiInit.py +++ b/src/Gui/FreeCADGuiInit.py @@ -108,7 +108,6 @@ class NoneWorkbench ( Workbench ): def InitApplications(): import sys,os,traceback - import codecs try: # Python3 import io as cStringIO @@ -126,8 +125,12 @@ def InitApplications(): if (os.path.exists(InstallFile)): try: # XXX: This looks scary securitywise... - with codecs.open(filename=InstallFile, encoding="utf-8") as f: - exec(f.read()) + if sys.version_info.major < 3: + with open(InstallFile) as f: + exec(f.read()) + else: + with open(file=InstallFile, encoding="utf-8") as f: + exec(f.read()) except Exception as inst: Log('Init: Initializing ' + Dir + '... failed\n') Log('-'*100+'\n')