From 6f57f36620354011c708edc00a7cc220ef97b1dc Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:15:20 +0100 Subject: [PATCH 1/4] [Start] Fix Python 3.11 Unicode Errors Example Error : File "/home/john/freecad-daily-build/Mod/Start/StartPage/StartPage.py", line 422, in handle ALTCSS = f.read() ^^^^^^^^ File "/usr/lib/python3.11/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 421: ordinal not in range(128) --- src/Mod/Start/StartPage/StartPage.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index 4951d960bf..a48ea7354e 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -32,6 +32,7 @@ import zipfile import re import FreeCAD import FreeCADGui +import codecs import urllib.parse from . import TranslationTexts from PySide import QtCore, QtGui @@ -424,7 +425,7 @@ def handle(): "", '" ) else: - with open(path, "r") as f: + with codecs.open(path, encoding='utf-8') as f: ALTCSS = f.read() HTML = HTML.replace( "", '" @@ -789,9 +790,13 @@ def exportTestFile(): "Allow to check if everything is Ok" - f = open(os.path.expanduser("~") + os.sep + "freecad-startpage.html", "w") - f.write(handle()) - f.close() + with codecs.open( + os.path.expanduser("~") + os.sep + "freecad-startpage.html", + encoding="utf-8", + mode="w", + ) as f: + f.write(handle()) + f.close() def postStart(switch_wb=True): From 82abb33555845945f13bf9d9a42b0fdb9c1c37df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:31:59 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Mod/Start/StartPage/StartPage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index a48ea7354e..09e0506269 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -425,7 +425,7 @@ def handle(): "", '" ) else: - with codecs.open(path, encoding='utf-8') as f: + with codecs.open(path, encoding="utf-8") as f: ALTCSS = f.read() HTML = HTML.replace( "", '" From 00f97981560ecce2b32d55f83560560ba2998004 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:04:35 +0100 Subject: [PATCH 3/4] [App] PropertyPythonObject Python 3.11 fix --- src/App/PropertyPythonObject.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index c519dfb6a4..e71d061f7c 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -87,6 +87,7 @@ std::string PropertyPythonObject::toString() const throw Py::Exception(); Py::Callable method(pickle.getAttr(std::string("dumps"))); Py::Object dump; +#if PY_VERSION_HEX < 0x03b0000 if (this->object.hasAttr("__getstate__")) { Py::Tuple args; Py::Callable state(this->object.getAttr("__getstate__")); @@ -98,6 +99,9 @@ std::string PropertyPythonObject::toString() const else { dump = this->object; } +#else + dump = this->object; +#endif Py::Tuple args(1); args.setItem(0, dump); From d20b0d9dae343f26df2ecf4d985f03dd64bf4b21 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:18:46 +0100 Subject: [PATCH 4/4] [App] Remove mistaken commit --- src/App/PropertyPythonObject.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index e71d061f7c..c519dfb6a4 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -87,7 +87,6 @@ std::string PropertyPythonObject::toString() const throw Py::Exception(); Py::Callable method(pickle.getAttr(std::string("dumps"))); Py::Object dump; -#if PY_VERSION_HEX < 0x03b0000 if (this->object.hasAttr("__getstate__")) { Py::Tuple args; Py::Callable state(this->object.getAttr("__getstate__")); @@ -99,9 +98,6 @@ std::string PropertyPythonObject::toString() const else { dump = this->object; } -#else - dump = this->object; -#endif Py::Tuple args(1); args.setItem(0, dump);