From 91f44617a75cc9e6d197d5bc796c30ef12cf3bd9 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 13 Apr 2018 11:19:10 +0100 Subject: [PATCH 1/3] python/samba: Add some compatability PY2/PY3 functions I hope these changes are a short term interim solution for the absence of the 'six' module/library. I also hope that soon this module can be removed and be replaced by usage of six. Signed-off-by: Noel Power --- python/samba/compat.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/samba/compat.py b/python/samba/compat.py index 667a1a443b1..d17dc3c2ce9 100644 --- a/python/samba/compat.py +++ b/python/samba/compat.py @@ -22,8 +22,20 @@ PY3 = sys.version_info[0] == 3 if PY3: + # compat functions + from urllib.parse import quote as urllib_quote + from urllib.request import urlopen as urllib_urlopen + + # compat types integer_types = int, + string_types = str text_type = str else: + # compat functions + from urllib import quote as urllib_quote + from urllib import urlopen as urllib_urlopen + + # compat types integer_types = (int, long) + string_types = basestring text_type = unicode From c58999f1a92f66cb8720f0f1b2992dc0c30d63b1 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 13:52:58 +0100 Subject: [PATCH 2/3] Add aliases for StringIO.StringIO cStringIO doesn't handle unicode, StringIO does. With py2/py3 compatable code we can easily find ourselves getting passed unicode so we don't alias cStringIO Signed-off-by: Noel Power --- python/samba/compat.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/samba/compat.py b/python/samba/compat.py index d17dc3c2ce9..5662095fed5 100644 --- a/python/samba/compat.py +++ b/python/samba/compat.py @@ -30,6 +30,10 @@ integer_types = int, string_types = str text_type = str + + # alias + import io + StringIO = io.StringIO else: # compat functions from urllib import quote as urllib_quote @@ -39,3 +43,7 @@ integer_types = (int, long) string_types = basestring text_type = unicode + + # alias + import StringIO + StringIO = StringIO.StringIO From 61ff00d02654c549e0c3285d0d269e342f5b467b Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 16:28:41 +0100 Subject: [PATCH 3/3] python/samba: Add binary_type for p2/p3 testing. For helping test for binary types, binary_type evaluates to 'str' in py2, and 'bytes' in py3. Signed-off-by: Noel Power --- python/samba/compat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/samba/compat.py b/python/samba/compat.py index 5662095fed5..042fc86a440 100644 --- a/python/samba/compat.py +++ b/python/samba/compat.py @@ -30,6 +30,7 @@ integer_types = int, string_types = str text_type = str + binary_type = bytes # alias import io @@ -43,6 +44,7 @@ integer_types = (int, long) string_types = basestring text_type = unicode + binary_type = str # alias import StringIO