summaryrefslogtreecommitdiff
path: root/python/samba/compat.py
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2016-12-13 11:26:53 +0100
committerAndrew Bartlett <abartlet@samba.org>2017-03-10 07:31:11 +0100
commit6fa125e121c1216d89d8bafd7da894d49c1d6527 (patch)
treea3b8b15f0ee4cae45ab9456f8f5b09ada53ef9aa /python/samba/compat.py
parent211df4a1e46977fc197c4a86e28faa0b46e1f73f (diff)
downloadsamba-6fa125e121c1216d89d8bafd7da894d49c1d6527.tar.gz
python: Make top-level samba modules Python 3 compatible
New file compat.py will help with porting to Python 3. For now, it contains only PY3 variable based on six.PY3 which simplifies condition mentioned below. The added `if not PY3` conditions enable us to bootstrap running tests with Python 3 even if most modules are not ported yet. The plan is to move modules outside this condition as they are ported. The `PY3` condition is currently used only in tests and for the samba._ldb module which is not ported yet and has a lot of dependencies. The other changes are related to differences between Python 2 and 3. Python 2.6 introduced the `0o` prefix for octal literals as an alternative to plain `0`. In Python 3, support for plain `0` is dropped and octal literals have to start with `0o` prefix. Python 2.6 introduced a clearer `except` syntax: `except ExceptionType as target:` instead of `except ExceptionType, target:`. In Python 3, the old syntax is no longer allowed. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'python/samba/compat.py')
-rw-r--r--python/samba/compat.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/python/samba/compat.py b/python/samba/compat.py
new file mode 100644
index 00000000000..c8215f3f6af
--- /dev/null
+++ b/python/samba/compat.py
@@ -0,0 +1,22 @@
+# module which helps with porting to Python 3
+#
+# Copyright (C) Lumir Balhar <lbalhar@redhat.com> 2017
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""module which helps with porting to Python 3"""
+
+import sys
+
+PY3 = sys.version_info[0] == 3