From 7d435711692a7c6485bb13e626727400d01d21e3 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 9 May 2018 20:17:30 +0100 Subject: [PATCH] python/samba/emulate: Fix some more missed exception tuple assignments In python3 we need to change except LdbError as e: - (status, _) = e to except LdbError as e: + (status, _) = e.args Signed-off-by: Noel Power Reviewed-by: Andreas Schneider Reviewed-by: Douglas Bagnall --- python/samba/emulate/traffic.py | 14 +++++++------- python/samba/netcmd/domain.py | 14 +++++++------- python/samba/tests/net_join.py | 2 +- python/samba/tests/netlogonsvc.py | 2 +- python/samba/tests/ntlmdisabled.py | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py index dba2c3f32f9..c96530b0164 100644 --- a/python/samba/emulate/traffic.py +++ b/python/samba/emulate/traffic.py @@ -1568,7 +1568,7 @@ def create_ou(ldb, instance_id): ldb.add({"dn": ou.split(',', 1)[1], "objectclass": "organizationalunit"}) except LdbError as e: - (status, _) = e + (status, _) = e.args # ignore already exists if status != 68: raise @@ -1576,7 +1576,7 @@ def create_ou(ldb, instance_id): ldb.add({"dn": ou, "objectclass": "organizationalunit"}) except LdbError as e: - (status, _) = e + (status, _) = e.args # ignore already exists if status != 68: raise @@ -1626,7 +1626,7 @@ def generate_traffic_accounts(ldb, instance_id, number, password): create_machine_account(ldb, instance_id, netbios_name, password) added += 1 except LdbError as e: - (status, _) = e + (status, _) = e.args if status == 68: break else: @@ -1642,7 +1642,7 @@ def generate_traffic_accounts(ldb, instance_id, number, password): create_user_account(ldb, instance_id, username, password) added += 1 except LdbError as e: - (status, _) = e + (status, _) = e.args if status == 68: break else: @@ -1728,7 +1728,7 @@ def generate_users(ldb, instance_id, number, password): create_user_account(ldb, instance_id, username, password) users += 1 except LdbError as e: - (status, _) = e + (status, _) = e.args # Stop if entry exists if status == 68: break @@ -1752,7 +1752,7 @@ def generate_groups(ldb, instance_id, number): create_group(ldb, instance_id, name) groups += 1 except LdbError as e: - (status, _) = e + (status, _) = e.args # Stop if entry exists if status == 68: break @@ -1767,7 +1767,7 @@ def clean_up_accounts(ldb, instance_id): try: ldb.delete(ou, ["tree_delete:1"]) except LdbError as e: - (status, _) = e + (status, _) = e.args # ignore does not exist if status != 32: raise diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index 86249073652..d50cf3f526c 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -1715,7 +1715,7 @@ def check_runtime_error(self, runtime, val): if runtime is None: return False - err32 = self._uint32(runtime[0]) + err32 = self._uint32(runtime.args[0]) if err32 == val: return True @@ -1723,24 +1723,24 @@ def check_runtime_error(self, runtime, val): class LocalRuntimeError(CommandError): def __init__(exception_self, self, runtime, message): - err32 = self._uint32(runtime[0]) - errstr = runtime[1] + err32 = self._uint32(runtime.args[0]) + errstr = runtime.args[1] msg = "LOCAL_DC[%s]: %s - ERROR(0x%08X) - %s" % ( self.local_server, message, err32, errstr) CommandError.__init__(exception_self, msg) class RemoteRuntimeError(CommandError): def __init__(exception_self, self, runtime, message): - err32 = self._uint32(runtime[0]) - errstr = runtime[1] + err32 = self._uint32(runtime.args[0]) + errstr = runtime.args[1] msg = "REMOTE_DC[%s]: %s - ERROR(0x%08X) - %s" % ( self.remote_server, message, err32, errstr) CommandError.__init__(exception_self, msg) class LocalLdbError(CommandError): def __init__(exception_self, self, ldb_error, message): - errval = ldb_error[0] - errstr = ldb_error[1] + errval = ldb_error.args[0] + errstr = ldb_error.args[1] msg = "LOCAL_DC[%s]: %s - ERROR(%d) - %s" % ( self.local_server, message, errval, errstr) CommandError.__init__(exception_self, msg) diff --git a/python/samba/tests/net_join.py b/python/samba/tests/net_join.py index daba2d2e3bc..41220280e62 100644 --- a/python/samba/tests/net_join.py +++ b/python/samba/tests/net_join.py @@ -57,7 +57,7 @@ def test_net_join(self): self.domain, netbios_name, LIBNET_JOIN_AUTOMATIC, machinepass=machinepass) except NTSTATUSError as e: - code = ctypes.c_uint32(e[0]).value + code = ctypes.c_uint32(e.args[0]).value if code == ntstatus.NT_STATUS_CONNECTION_DISCONNECTED: self.fail("Connection failure") raise diff --git a/python/samba/tests/netlogonsvc.py b/python/samba/tests/netlogonsvc.py index 87afa3e233e..3dac66c71cc 100644 --- a/python/samba/tests/netlogonsvc.py +++ b/python/samba/tests/netlogonsvc.py @@ -57,7 +57,7 @@ def test_have_netlogon_connection(self): except NTSTATUSError as e: # On non-DC test environments, netlogon should not be running on # the server, so we expect the test to fail here - enum = ctypes.c_uint32(e[0]).value + enum = ctypes.c_uint32(e.args[0]).value if enum == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND: self.fail("netlogon service is not running") else: diff --git a/python/samba/tests/ntlmdisabled.py b/python/samba/tests/ntlmdisabled.py index 90341a5cee3..dadebb327f5 100644 --- a/python/samba/tests/ntlmdisabled.py +++ b/python/samba/tests/ntlmdisabled.py @@ -56,7 +56,7 @@ def test_ntlm_connection(self): self.assertIsNotNone(conn) except NTSTATUSError as e: # NTLM might be blocked on this server - enum = ctypes.c_uint32(e[0]).value + enum = ctypes.c_uint32(e.args[0]).value if enum == ntstatus.NT_STATUS_NTLM_BLOCKED: self.fail("NTLM is disabled on this server") else: @@ -77,7 +77,7 @@ def test_samr_change_password(self): conn.ChangePasswordUser2(server, username, None, None, True, None, None) except NTSTATUSError as e: # changing passwords should be rejected when NTLM is disabled - enum = ctypes.c_uint32(e[0]).value + enum = ctypes.c_uint32(e.args[0]).value if enum == ntstatus.NT_STATUS_NTLM_BLOCKED: self.fail("NTLM is disabled on this server") elif enum == ntstatus.NT_STATUS_WRONG_PASSWORD: