samba-tool: convert 'except X, e' to 'except X as e' for all X
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 13 Feb 2018 21:07:23 +0000 (10:07 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 14 Feb 2018 23:18:30 +0000 (00:18 +0100)
This is needed for Python 3 and is compatible with python 2.6

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
15 files changed:
python/samba/netcmd/__init__.py
python/samba/netcmd/delegation.py
python/samba/netcmd/dns.py
python/samba/netcmd/domain.py
python/samba/netcmd/drs.py
python/samba/netcmd/fsmo.py
python/samba/netcmd/gpo.py
python/samba/netcmd/group.py
python/samba/netcmd/ldapcmp.py
python/samba/netcmd/ntacl.py
python/samba/netcmd/ou.py
python/samba/netcmd/rodc.py
python/samba/netcmd/sites.py
python/samba/netcmd/testparm.py
python/samba/netcmd/user.py

index fcad7f6399d1e2e4d017db14e75e0183fdfdd3d5..9037d033190fcc364b67803ec33ba22b7050c96b 100644 (file)
@@ -174,7 +174,7 @@ class Command(object):
 
         try:
             return self.run(*args, **kwargs)
-        except Exception, e:
+        except Exception as e:
             self.show_command_error(e)
             return -1
 
index 39397bbcc754e3cb7fc5f9857de975aa43674a6c..49e5957c2b70a33d0a811d345462fe7d01910ed2 100644 (file)
@@ -138,7 +138,7 @@ class cmd_delegation_for_any_service(Command):
             sam.toggle_userAccountFlags(search_filter, flag,
                                         flags_str="Trusted-for-Delegation",
                                         on=on, strict=True)
-        except Exception, err:
+        except Exception as err:
             raise CommandError(err)
 
 
@@ -192,7 +192,7 @@ class cmd_delegation_for_any_protocol(Command):
             sam.toggle_userAccountFlags(search_filter, flag,
                         flags_str="Trusted-to-Authenticate-for-Delegation",
                         on=on, strict=True)
-        except Exception, err:
+        except Exception as err:
             raise CommandError(err)
 
 
@@ -246,7 +246,7 @@ class cmd_delegation_add_service(Command):
                                           "msDS-AllowedToDelegateTo")
         try:
             sam.modify(msg)
-        except Exception, err:
+        except Exception as err:
             raise CommandError(err)
 
 
@@ -300,7 +300,7 @@ class cmd_delegation_del_service(Command):
                                           "msDS-AllowedToDelegateTo")
         try:
             sam.modify(msg)
-        except Exception, err:
+        except Exception as err:
             raise CommandError(err)
 
 
index 33f81ee7fcad4631df29d039d1a47f66c54b7cef..8bd6a9bf8a0a58495b3beb88cd5c1a6c4b2576da 100644 (file)
@@ -47,7 +47,7 @@ def dns_connect(server, lp, creds):
     binding_str = "ncacn_ip_tcp:%s[sign]" % server
     try:
         dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
-    except RuntimeError, e:
+    except RuntimeError as e:
         raise CommandError('Connecting to DNS RPC server %s failed with %s' % (server, e))
 
     return dns_conn
index 2cb14f150ecbe848ba284022d9934cb3ccba43af..52c70acfacc50bc67d8b6265ae5e75ffde476a08 100644 (file)
@@ -499,7 +499,7 @@ class cmd_domain_provision(Command):
                   base_schema=base_schema,
                   plaintext_secrets=plaintext_secrets)
 
-        except ProvisioningError, e:
+        except ProvisioningError as e:
             raise CommandError("Provision failed", e)
 
         result.report_logger(self.logger)
@@ -865,7 +865,7 @@ class cmd_domain_demote(Command):
             dc_dn = res[0].dn
             uac = int(str(res[0]["userAccountControl"]))
 
-        except Exception, e:
+        except Exception as e:
             if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
                 self.errf.write(
                     "Error while demoting, re-enabling inbound replication\n")
@@ -897,7 +897,7 @@ class cmd_domain_demote(Command):
                                                         "userAccountControl")
         try:
             remote_samdb.modify(msg)
-        except Exception, e:
+        except Exception as e:
             if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
                 self.errf.write(
                     "Error while demoting, re-enabling inbound replication")
@@ -952,7 +952,7 @@ class cmd_domain_demote(Command):
         try:
             newdn = ldb.Dn(remote_samdb, "%s,%s" % (newrdn, str(computer_dn)))
             remote_samdb.rename(dc_dn, newdn)
-        except Exception, e:
+        except Exception as e:
             if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
                 self.errf.write(
                     "Error while demoting, re-enabling inbound replication\n")
@@ -1012,7 +1012,7 @@ class cmd_domain_demote(Command):
             try:
                 remote_samdb.delete(ldb.Dn(remote_samdb,
                                     "%s,%s" % (s, str(newdn))))
-            except ldb.LdbError, l:
+            except ldb.LdbError as l:
                 pass
 
         self.errf.write("Demote successful\n")
@@ -1328,7 +1328,7 @@ class cmd_domain_passwordsettings(Command):
             else:
                 cur_account_lockout_duration = abs(int(res[0]["lockoutDuration"][0])) / (1e7 * 60)
             cur_reset_account_lockout_after = abs(int(res[0]["lockOutObservationWindow"][0])) / (1e7 * 60)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Could not retrieve password properties!", e)
 
         if subcommand == "show":
@@ -3853,7 +3853,7 @@ This command expunges tombstones from the database."""
                                                                current_time=current_time,
                                                                tombstone_lifetime=tombstone_lifetime)
 
-        except Exception, err:
+        except Exception as err:
             if started_transaction:
                 samdb.transaction_cancel()
             raise CommandError("Failed to expunge / garbage collect tombstones", err)
index a45b906282771fddc001ffc006f0062ef4dc1c63..5498f098714345b54b8c0426771ee91f3756ca62 100644 (file)
@@ -42,7 +42,7 @@ def drsuapi_connect(ctx):
     '''make a DRSUAPI connection to the server'''
     try:
         (ctx.drsuapi, ctx.drsuapi_handle, ctx.bind_supported_extensions) = drs_utils.drsuapi_connect(ctx.server, ctx.lp, ctx.creds)
-    except Exception, e:
+    except Exception as e:
         raise CommandError("DRS connection to %s failed" % ctx.server, e)
 
 def samdb_connect(ctx):
@@ -51,7 +51,7 @@ def samdb_connect(ctx):
         ctx.samdb = SamDB(url="ldap://%s" % ctx.server,
                           session_info=system_session(),
                           credentials=ctx.creds, lp=ctx.lp)
-    except Exception, e:
+    except Exception as e:
         raise CommandError("LDAP connection to %s failed" % ctx.server, e)
 
 def drs_errmsg(werr):
@@ -143,7 +143,7 @@ class cmd_drs_showrepl(Command):
         try:
             (info_type, info) = self.drsuapi.DsReplicaGetInfo(
                 self.drsuapi_handle, 1, req1)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("DsReplicaGetInfo of type %u failed" % info_type, e)
         return (info_type, info)
 
@@ -166,7 +166,7 @@ class cmd_drs_showrepl(Command):
         (site, server) = drs_parse_ntds_dn(ntds_dn)
         try:
             ntds = self.samdb.search(base=ntds_dn, scope=ldb.SCOPE_BASE, attrs=['options', 'objectGUID', 'invocationId'])
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Failed to search NTDS DN %s" % ntds_dn)
 
         dsa_details = {
@@ -300,7 +300,7 @@ class cmd_drs_kcc(Command):
         req1 = drsuapi.DsExecuteKCC1()
         try:
             self.drsuapi.DsExecuteKCC(self.drsuapi_handle, 1, req1)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("DsExecuteKCC failed", e)
         self.message("Consistency check on %s successful." % DC)
 
@@ -351,7 +351,7 @@ def drs_local_replicate(self, SOURCE_DC, NC, full_sync=False, single_object=Fals
                                                   source_dsa_invocation_id, destination_dsa_guid,
                                                   rodc=rodc, full_sync=full_sync,
                                                   exop=exop, sync_forced=sync_forced)
-    except Exception, e:
+    except Exception as e:
         raise CommandError("Error replicating DN %s" % NC, e)
     self.samdb.transaction_commit()
 
@@ -452,7 +452,7 @@ class cmd_drs_replicate(Command):
 
         try:
             drs_utils.sendDsReplicaSync(server_bind, server_bind_handle, source_dsa_guid, NC, req_options)
-        except drs_utils.drsException, estr:
+        except drs_utils.drsException as estr:
             raise CommandError("DsReplicaSync failed", estr)
         if async_op:
             self.message("Replicate from %s to %s was started." % (SOURCE_DC, DEST_DC))
index 62b3e438e18d380ea068424c22576d6cde3ee251..c00e8dda45ba20720d6aa600aaf49076cd1a6e4f 100644 (file)
@@ -126,7 +126,7 @@ def transfer_dns_role(outf, sambaopts, credopts, role, samdb):
         try:
             connection = samba.drs_utils.drsuapi_connect(samdb.host_dns_name(),
                                                          lp, creds)
-        except samba.drs_utils.drsException, e:
+        except samba.drs_utils.drsException as e:
             raise CommandError("Drsuapi Connect failed", e)
 
         try:
@@ -138,7 +138,7 @@ def transfer_dns_role(outf, sambaopts, credopts, role, samdb):
                                               drsuapi_handle,
                                               master_guid,
                                               NC, req_options)
-        except samba.drs_utils.drsException, estr:
+        except samba.drs_utils.drsException as estr:
             raise CommandError("Replication failed", estr)
 
         outf.write("FSMO transfer of '%s' role successful\n" % role)
@@ -463,7 +463,7 @@ class cmd_fsmo_show(Command):
                     self.message("%s owner: %s" % (long_name, str(master)))
                 else:
                     self.message("%s has no current owner" % (long_name))
-            except CommandError, e:
+            except CommandError as e:
                 self.message("%s: * %s" % (long_name, e.message))
 
 class cmd_fsmo_transfer(Command):
index 23b562eb6358fba17dd5151203ff4ca67c2ea1d7..5f4ad0ebca0d008d3cd73d0bde24172a3dd17510 100644 (file)
@@ -52,7 +52,7 @@ def samdb_connect(ctx):
         ctx.samdb = SamDB(url=ctx.url,
                           session_info=system_session(),
                           credentials=ctx.creds, lp=ctx.lp)
-    except Exception, e:
+    except Exception as e:
         raise CommandError("LDAP connection to %s failed " % ctx.url, e)
 
 
@@ -113,7 +113,7 @@ def dc_url(lp, creds, url=None, dc=None):
         if dc is None:
             try:
                 dc = netcmd_finddc(lp, creds)
-            except Exception, e:
+            except Exception as e:
                 raise RuntimeError("Could not find a DC for domain", e)
         url = 'ldap://' + dc
     return url
@@ -159,7 +159,7 @@ def get_gpo_info(samdb, gpo=None, displayname=None, dn=None,
                                     'displayName',
                                     'gPCFileSysPath'],
                             controls=['sd_flags:1:%d' % sd_flags])
-    except Exception, e:
+    except Exception as e:
         if gpo is not None:
             mesg = "Cannot get information for GPO %s" % gpo
         else:
@@ -175,7 +175,7 @@ def get_gpo_containers(samdb, gpo):
     search_expr = "(&(objectClass=*)(gPLink=*%s*))" % gpo
     try:
         msg = samdb.search(expression=search_expr, attrs=['gPLink'])
-    except Exception, e:
+    except Exception as e:
         raise CommandError("Could not find container(s) with GPO %s" % gpo, e)
 
     return msg
@@ -188,7 +188,7 @@ def del_gpo_link(samdb, container_dn, gpo):
         msg = samdb.search(base=container_dn, scope=ldb.SCOPE_BASE,
                             expression="(objectClass=*)",
                             attrs=['gPLink'])[0]
-    except Exception, e:
+    except Exception as e:
         raise CommandError("Container '%s' does not exist" % container_dn, e)
 
     found = False
@@ -215,7 +215,7 @@ def del_gpo_link(samdb, container_dn, gpo):
         m['d0'] = ldb.MessageElement(msg['gPLink'][0], ldb.FLAG_MOD_DELETE, 'gPLink')
     try:
         samdb.modify(m)
-    except Exception, e:
+    except Exception as e:
         raise CommandError("Error removing GPO from container", e)
 
 
@@ -617,7 +617,7 @@ class cmd_setlink(Command):
 
         try:
             self.samdb.modify(m)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Error adding GPO Link", e)
 
         self.outf.write("Added/Updated GPO link\n")
@@ -793,7 +793,7 @@ class cmd_setinheritance(Command):
 
         try:
             self.samdb.modify(m)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Error setting inheritance state %s" % inherit_state, e)
 
 
@@ -864,7 +864,7 @@ class cmd_fetch(Command):
         try:
             os.mkdir(gpodir)
             copy_directory_remote_to_local(conn, sharepath, gpodir)
-        except Exception, e:
+        except Exception as e:
             # FIXME: Catch more specific exception
             raise CommandError("Error copying GPO from DC", e)
         self.outf.write('GPO copied to %s\n' % gpodir)
@@ -944,14 +944,14 @@ class cmd_create(Command):
             os.mkdir(os.path.join(gpodir, "User"))
             gpt_contents = "[General]\r\nVersion=0\r\n"
             file(os.path.join(gpodir, "GPT.INI"), "w").write(gpt_contents)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Error Creating GPO files", e)
 
         # Connect to DC over SMB
         [dom_name, service, sharepath] = parse_unc(unc_path)
         try:
             conn = smb.SMB(dc_hostname, service, lp=self.lp, creds=self.creds)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Error connecting to '%s' using SMB" % dc_hostname, e)
 
         self.samdb.transaction_start()
@@ -1064,7 +1064,7 @@ class cmd_del(Command):
         [dom_name, service, sharepath] = parse_unc(unc_path)
         try:
             conn = smb.SMB(dc_hostname, service, lp=self.lp, creds=self.creds)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Error connecting to '%s' using SMB" % dc_hostname, e)
 
         self.samdb.transaction_start()
index 782a1ef1014f5cd0d6b26842541496affec04494..a4969cc6ba9ec2f4c5ade747c9799f5724aca6f0 100644 (file)
@@ -124,7 +124,7 @@ Example3 adds a new RFC2307 enabled group for NIS domain samdom and GID 12345 (b
             samdb.newgroup(groupname, groupou=groupou, grouptype = gtype,
                           description=description, mailaddress=mail_address, notes=notes,
                           gidnumber=gid_number, nisdomain=nis_domain)
-        except Exception, e:
+        except Exception as e:
             # FIXME: catch more specific exception
             raise CommandError('Failed to create group "%s"' % groupname, e)
         self.outf.write("Added group %s\n" % groupname)
@@ -186,7 +186,7 @@ Example2 deletes group Group2 from the local server.  The command is run under r
 
         try:
             samdb.delete(group_dn)
-        except Exception, e:
+        except Exception as e:
             # FIXME: catch more specific exception
             raise CommandError('Failed to remove group "%s"' % groupname, e)
         self.outf.write("Deleted group %s\n" % groupname)
@@ -239,7 +239,7 @@ Example2 shows how to add a single user account, User2, to the supergroup AD gro
             groupmembers = listofmembers.split(',')
             samdb.add_remove_group_members(groupname, groupmembers,
                     add_members_operation=True)
-        except Exception, e:
+        except Exception as e:
             # FIXME: catch more specific exception
             raise CommandError('Failed to add members "%s" to group "%s"' % (
                 listofmembers, groupname), e)
@@ -290,7 +290,7 @@ Example2 shows how to remove a single user account, User2, from the supergroup A
                           credentials=creds, lp=lp)
             samdb.add_remove_group_members(groupname, listofmembers.split(","),
                     add_members_operation=False)
-        except Exception, e:
+        except Exception as e:
             # FIXME: Catch more specific exception
             raise CommandError('Failed to remove members "%s" from group "%s"' % (listofmembers, groupname), e)
         self.outf.write("Removed members from group %s\n" % groupname)
@@ -418,7 +418,7 @@ samba-tool group listmembers \"Domain Users\" -H ldap://samba.samdom.example.com
                     member_name = msg.get("cn", idx=0)
                 self.outf.write("%s\n" % member_name)
 
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to list members of "%s" group ' % groupname, e)
 
 class cmd_group_move(Command):
@@ -485,7 +485,7 @@ class cmd_group_move(Command):
 
         try:
             full_new_parent_dn = samdb.normalize_dn_in_domain(new_parent_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid new_parent_dn "%s": %s' %
                                (new_parent_dn, e.message))
 
@@ -495,7 +495,7 @@ class cmd_group_move(Command):
 
         try:
             samdb.rename(group_dn, full_new_group_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to move group "%s"' % groupname, e)
         self.outf.write('Moved group "%s" into "%s"\n' %
                         (groupname, full_new_parent_dn))
index 7b8d93e07fa23d31a1e748ff16cc030ca44a5bf4..0c0a76cadbaa4a2391183d8acdeee02511b05d0e 100644 (file)
@@ -131,7 +131,7 @@ class LDAPBase(object):
     def delete_force(self, object_dn):
         try:
             self.ldb.delete(object_dn)
-        except Ldb.LdbError, e:
+        except Ldb.LdbError as e:
             assert "No such object" in str(e)
 
     def get_attribute_name(self, key):
index eaea0e7af1711729b2bbb3b85a3a3b9e4f378c3a..5aeb667d8fb2439f4176079316ba2bbbed2405a2 100644 (file)
@@ -71,7 +71,7 @@ class cmd_ntacl_set(Command):
         try:
             samdb = SamDB(session_info=system_session(),
                           lp=lp)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Unable to open samdb:", e)
 
         if not use_ntvfs and not use_s3fs:
@@ -146,7 +146,7 @@ class cmd_ntacl_get(Command):
         try:
             samdb = SamDB(session_info=system_session(),
                           lp=lp)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Unable to open samdb:", e)
 
         if not use_ntvfs and not use_s3fs:
@@ -199,7 +199,7 @@ class cmd_ntacl_sysvolreset(Command):
         try:
             samdb = SamDB(session_info=system_session(),
                           lp=lp)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Unable to open samdb:", e)
 
         if not use_ntvfs and not use_s3fs:
@@ -259,7 +259,7 @@ class cmd_ntacl_sysvolcheck(Command):
         sysvol = lp.get("path", "sysvol")
         try:
             samdb = SamDB(session_info=system_session(), lp=lp)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Unable to open samdb:", e)
 
         domain_sid = security.dom_sid(samdb.domain_sid)
index 16b7f653f71015f345371f9e0a95f36b5d633be7..61717678cd4c6197abd4940e0ab846544797b0f4 100644 (file)
@@ -70,12 +70,12 @@ class cmd_rename(Command):
 
         try:
             full_old_ou_dn = samdb.normalize_dn_in_domain(old_ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid old_ou_dn "%s": %s' %
                                (old_ou_dn, e.message))
         try:
             full_new_ou_dn = samdb.normalize_dn_in_domain(new_ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid new_ou_dn "%s": %s' %
                                (new_ou_dn, e.message))
 
@@ -88,7 +88,7 @@ class cmd_rename(Command):
                 return
 
             samdb.rename(full_old_ou_dn, full_new_ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to rename ou "%s"' % full_old_ou_dn, e)
         self.outf.write('Renamed ou "%s" to "%s"\n' % (full_old_ou_dn,
                                                        full_new_ou_dn))
@@ -134,12 +134,12 @@ class cmd_move(Command):
         domain_dn = ldb.Dn(samdb, samdb.domain_dn())
         try:
             full_old_ou_dn = samdb.normalize_dn_in_domain(old_ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid old_ou_dn "%s": %s' %
                                (old_ou_dn, e.message))
         try:
             full_new_parent_dn = samdb.normalize_dn_in_domain(new_parent_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid new_parent_dn "%s": %s' %
                                (new_parent_dn, e.message))
 
@@ -155,7 +155,7 @@ class cmd_move(Command):
                 self.outf.write('Unable to find ou "%s"\n' % full_old_ou_dn)
                 return
             samdb.rename(full_old_ou_dn, full_new_ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to move ou "%s"' % full_old_ou_dn, e)
         self.outf.write('Moved ou "%s" into "%s"\n' %
                         (full_old_ou_dn, full_new_parent_dn))
@@ -199,12 +199,12 @@ class cmd_create(Command):
 
         try:
             full_ou_dn = samdb.normalize_dn_in_domain(ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid ou_dn "%s": %s' % (ou_dn, e.message))
 
         try:
             samdb.create_ou(full_ou_dn, description=description)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to create ou "%s"' % full_ou_dn, e)
 
         self.outf.write('Created ou "%s"\n' % full_ou_dn)
@@ -250,7 +250,7 @@ class cmd_listobjects(Command):
 
         try:
             full_ou_dn = samdb.normalize_dn_in_domain(ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid ou_dn "%s": %s' % (ou_dn, e.message))
 
         minchilds = 0
@@ -274,7 +274,7 @@ class cmd_listobjects(Command):
                     child.dn.remove_base_components(len(domain_dn))
                 self.outf.write("%s\n" % child.dn)
 
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to list contents of ou "%s"' %
                                full_ou_dn, e)
 
@@ -362,7 +362,7 @@ class cmd_delete(Command):
 
         try:
             full_ou_dn = samdb.normalize_dn_in_domain(ou_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid ou_dn "%s": %s' % (ou_dn, e.message))
 
         controls = []
@@ -377,7 +377,7 @@ class cmd_delete(Command):
                 self.outf.write('Unable to find ou "%s"\n' % ou_dn)
                 return
             samdb.delete(full_ou_dn, controls)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to delete ou "%s"' % full_ou_dn, e)
 
         self.outf.write('Deleted ou "%s"\n' % full_ou_dn)
index 533f9446a091b8bae72eb6ab3459dce07b80b87c..000858d59454bca3f410f260039a86d4a36f18d4 100644 (file)
@@ -127,7 +127,7 @@ class cmd_rodc_preload(Command):
 
             try:
                 dn = self.get_dn(samdb, account)
-            except RODCException, e:
+            except RODCException as e:
                 if not ignore_errors:
                     raise CommandError(str(e))
                 errors.append(e)
@@ -139,7 +139,7 @@ class cmd_rodc_preload(Command):
             try:
                 repl.replicate(dn, source_dsa_invocation_id, destination_dsa_guid,
                                exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
-            except Exception, e:
+            except Exception as e:
                 local_samdb.transaction_cancel()
                 if not ignore_errors:
                     raise CommandError("Error replicating DN %s" % dn)
index d0b7b9f4e6a8c5bf7b6ce87632b33f1deebaccf4..38b251ca8fe1759d0118f71d64fea2342fb6d531 100644 (file)
@@ -57,7 +57,7 @@ class cmd_sites_create(Command):
         try:
             sites.create_site(samdb, samdb.get_config_basedn(), sitename)
             samdb.transaction_commit()
-        except sites.SiteAlreadyExistsException, e:
+        except sites.SiteAlreadyExistsException as e:
             samdb.transaction_cancel()
             raise CommandError("Error while creating site %s, error: %s" %
                                (sitename, str(e)))
@@ -94,7 +94,7 @@ class cmd_sites_delete(Command):
         try:
             sites.delete_site(samdb, samdb.get_config_basedn(), sitename)
             samdb.transaction_commit()
-        except sites.SiteException, e:
+        except sites.SiteException as e:
             samdb.transaction_cancel()
             raise CommandError(
                 "Error while removing site %s, error: %s" % (sitename, str(e)))
@@ -130,7 +130,7 @@ class cmd_sites_subnet_create(Command):
             subnets.create_subnet(samdb, samdb.get_config_basedn(), subnetname,
                                   site_of_subnet)
             samdb.transaction_commit()
-        except subnets.SubnetException, e:
+        except subnets.SubnetException as e:
             samdb.transaction_cancel()
             raise CommandError("Error while creating subnet %s: %s" %
                                (subnetname, e))
@@ -167,7 +167,7 @@ class cmd_sites_subnet_delete(Command):
         try:
             subnets.delete_subnet(samdb, samdb.get_config_basedn(), subnetname)
             samdb.transaction_commit()
-        except subnets.SubnetException, e:
+        except subnets.SubnetException as e:
             samdb.transaction_cancel()
             raise CommandError("Error while removing subnet %s, error: %s" %
                                (subnetname, e))
@@ -203,7 +203,7 @@ class cmd_sites_subnet_set_site(Command):
             subnets.set_subnet_site(samdb, samdb.get_config_basedn(),
                                     subnetname, site_of_subnet)
             samdb.transaction_commit()
-        except subnets.SubnetException, e:
+        except subnets.SubnetException as e:
             samdb.transaction_cancel()
             raise CommandError("Error assigning subnet %s to site %s: %s" %
                                (subnetname, site_of_subnet, e))
index f9099b34e6df41b75954158dae91d5ae70d472df..2cd0897dfea48d5ef23eb06802c7e4ab6c321a69 100644 (file)
@@ -84,7 +84,7 @@ class cmd_testparm(Command):
 
         try:
             lp = sambaopts.get_loadparm()
-        except RuntimeError, err:
+        except RuntimeError as err:
             raise CommandError(err)
 
         # We need this to force the output
index 478e263a9bde6556ed3e9dc00f17bbc9e5e93539..94959bbe2ba5f0dfa8d9b1346a63edb969e1f0ab 100644 (file)
@@ -378,7 +378,7 @@ Example5 shows how to create an RFC2307/NIS domain enabled user account. If
                           uidnumber=uid_number, gidnumber=gid_number,
                           gecos=gecos, loginshell=login_shell,
                           smartcard_required=smartcard_required)
-        except Exception, e:
+        except Exception as e:
             raise CommandError("Failed to add user '%s': " % username, e)
 
         self.outf.write("User '%s' created successfully\n" % username)
@@ -453,7 +453,7 @@ Example2 shows how to delete a user in the domain against the local server.   su
 
         try:
             samdb.delete(user_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to remove user "%s"' % username, e)
         self.outf.write("Deleted user %s\n" % username)
 
@@ -557,7 +557,7 @@ Example3 shows how to enable a user in the domain against a local LDAP server.
             credentials=creds, lp=lp)
         try:
             samdb.enable_account(filter)
-        except Exception, msg:
+        except Exception as msg:
             raise CommandError("Failed to enable user '%s': %s" % (username or filter, msg))
         self.outf.write("Enabled user '%s'\n" % (username or filter))
 
@@ -596,7 +596,7 @@ class cmd_user_disable(Command):
             credentials=creds, lp=lp)
         try:
             samdb.disable_account(filter)
-        except Exception, msg:
+        except Exception as msg:
             raise CommandError("Failed to disable user '%s': %s" % (username or filter, msg))
 
 
@@ -663,7 +663,7 @@ Example4 shows how to set the account expiration so that it will never expire.
 
         try:
             samdb.setexpiry(filter, days*24*3600, no_expiry_req=noexpiry)
-        except Exception, msg:
+        except Exception as msg:
             # FIXME: Catch more specific exception
             raise CommandError("Failed to set expiry for user '%s': %s" % (
                 username or filter, msg))
@@ -714,7 +714,7 @@ class cmd_user_password(Command):
 
         try:
             net.change_password(password.encode('utf-8'))
-        except Exception, msg:
+        except Exception as msg:
             # FIXME: catch more specific exception
             raise CommandError("Failed to change password : %s" % msg)
         self.outf.write("Changed password OK\n")
@@ -832,7 +832,7 @@ Example3 shows how an administrator would reset TestUser3 user's password to pas
                 samdb.toggle_userAccountFlags(filter, flags, on=True)
                 command = "Failed to enable account for user '%s'" % (username or filter)
                 samdb.enable_account(filter)
-            except Exception, msg:
+            except Exception as msg:
                 # FIXME: catch more specific exception
                 raise CommandError("%s: %s" % (command, msg))
             self.outf.write("Added UF_SMARTCARD_REQUIRED OK\n")
@@ -847,7 +847,7 @@ Example3 shows how an administrator would reset TestUser3 user's password to pas
                 samdb.setpassword(filter, password,
                                   force_change_at_next_login=must_change_at_next_login,
                                   username=username)
-            except Exception, msg:
+            except Exception as msg:
                 # FIXME: catch more specific exception
                 raise CommandError("%s: %s" % (command, msg))
             self.outf.write("Changed password OK\n")
@@ -2561,7 +2561,7 @@ class cmd_user_move(Command):
 
         try:
             full_new_parent_dn = samdb.normalize_dn_in_domain(new_parent_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Invalid new_parent_dn "%s": %s' %
                                (new_parent_dn, e.message))
 
@@ -2571,7 +2571,7 @@ class cmd_user_move(Command):
 
         try:
             samdb.rename(user_dn, full_new_user_dn)
-        except Exception, e:
+        except Exception as e:
             raise CommandError('Failed to move user "%s"' % username, e)
         self.outf.write('Moved user "%s" into "%s"\n' %
                         (username, full_new_parent_dn))