From bcaf076d30f38cea4465be57d5270e9431951161 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Sat, 4 Jul 2020 14:01:32 +1200 Subject: [PATCH] python compat: reduce use of 'if PY3:' Signed-off-by: Douglas Bagnall Reviewed-by: Noel Power --- python/samba/gp_parse/gp_csv.py | 1 - python/samba/tests/credentials.py | 18 +++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/python/samba/gp_parse/gp_csv.py b/python/samba/gp_parse/gp_csv.py index e436c1b5bd2..d56d7d67b99 100644 --- a/python/samba/gp_parse/gp_csv.py +++ b/python/samba/gp_parse/gp_csv.py @@ -23,7 +23,6 @@ import io from io import BytesIO from xml.etree.ElementTree import Element, SubElement -from samba.compat import PY3 from samba.gp_parse import GPParser from samba.compat import text_type # [MS-GPAC] Group Policy Audit Configuration diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py index d2a81506de3..3df99ee783f 100644 --- a/python/samba/tests/credentials.py +++ b/python/samba/tests/credentials.py @@ -25,7 +25,6 @@ from samba import credentials import samba.tests import os import binascii -from samba.compat import PY3 from samba.dcerpc import misc @@ -34,13 +33,6 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): def setUp(self): super(CredentialsTests, self).setUp() self.creds = credentials.Credentials() - if PY3: - # Because Python 2 does not support 'x' mode and Python 3 - # does not support 'wx' mode in open() function - # for exclusive creation - self.open_mode = 'x' - else: - self.open_mode = 'wx' def test_set_username(self): self.creds.set_username("somebody") @@ -203,7 +195,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): username = "user" passwd_file_name = os.path.join(self.tempdir, "parse_file") - passwd_file_fd = open(passwd_file_name, self.open_mode) + passwd_file_fd = open(passwd_file_name, 'x') passwd_file_fd.write("realm=%s\n" % realm) passwd_file_fd.write("domain=%s\n" % domain) passwd_file_fd.write("username=%s\n" % username) @@ -226,7 +218,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): username = "user" passwd_file_name = os.path.join(self.tempdir, "parse_file") - passwd_file_fd = open(passwd_file_name, self.open_mode) + passwd_file_fd = open(passwd_file_name, 'x') passwd_file_fd.write("realm=%s\n" % realm) passwd_file_fd.write("domain=%s\n" % domain) passwd_file_fd.write("username=%s\\%s\n" % (domain, username)) @@ -251,7 +243,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): userdom = "userdom" passwd_file_name = os.path.join(self.tempdir, "parse_file") - passwd_file_fd = open(passwd_file_name, self.open_mode) + passwd_file_fd = open(passwd_file_name, 'x') passwd_file_fd.write("realm=%s\n" % realm) passwd_file_fd.write("domain=%s\n" % domain) passwd_file_fd.write("username=%s/%s\n" % (userdom, username)) @@ -274,7 +266,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): userdom = "userdom" passwd_file_name = os.path.join(self.tempdir, "parse_file") - passwd_file_fd = open(passwd_file_name, self.open_mode) + passwd_file_fd = open(passwd_file_name, 'x') passwd_file_fd.write("username=%s\\%s%%%s\n" % (userdom, username, password)) passwd_file_fd.write("realm=ignorerealm\n") passwd_file_fd.write("domain=ignoredomain\n") @@ -297,7 +289,7 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): userdom = "userdom" passwd_file_name = os.path.join(self.tempdir, "parse_file") - passwd_file_fd = open(passwd_file_name, self.open_mode) + passwd_file_fd = open(passwd_file_name, 'x') passwd_file_fd.write("realm=ignorerealm\n") passwd_file_fd.write("username=%s\\%s%%%s\n" % (userdom, username, password)) passwd_file_fd.write("domain=ignoredomain\n")