From fda023f283cbd8744a0ef7d2ed34cfabbac92dee Mon Sep 17 00:00:00 2001 From: Justin Israel Date: Thu, 30 Sep 2021 06:11:09 +1300 Subject: [PATCH] Make utf-8 file open backwards compatible for py2 (#40) --- MayaSublime.py | 8 +++++++- messages.json | 3 ++- messages/3.1.2.md | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 messages/3.1.2.md diff --git a/MayaSublime.py b/MayaSublime.py index 871a3c4..5073e68 100644 --- a/MayaSublime.py +++ b/MayaSublime.py @@ -271,6 +271,12 @@ def _sync_settings(): import maya.cmds + def _open(f): + try: + return open(f, encoding='utf-8') + except TypeError: + return open(f) + namespace = __main__.__dict__.get('_sublime_SendToMaya_plugin') if not namespace: namespace = __main__.__dict__.copy() @@ -289,7 +295,7 @@ def _sync_settings(): exec({cmd!r}, namespace, namespace) else: - with open({fp!r}, encoding='utf-8') as _fp: + with _open({fp!r}) as _fp: _code = compile(_fp.read(), {fp!r}, 'exec') exec(_code, namespace, namespace) diff --git a/messages.json b/messages.json index 7662c4e..cce9039 100644 --- a/messages.json +++ b/messages.json @@ -10,5 +10,6 @@ "3.0.3": "messages/3.0.3.md", "3.0.4": "messages/3.0.4.md", "3.1.0": "messages/3.1.0.md", - "3.1.1": "messages/3.1.1.md" + "3.1.1": "messages/3.1.1.md", + "3.1.2": "messages/3.1.2.md" } diff --git a/messages/3.1.2.md b/messages/3.1.2.md new file mode 100644 index 0000000..9081b3b --- /dev/null +++ b/messages/3.1.2.md @@ -0,0 +1,3 @@ +MayaSublime 3.1.2 change log: + +- [#40]: Make utf-8 file open fix backwards compatible with python 2.x