From f43cb7c38d1945cdeca259b53a433c68803482d0 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 14 Feb 2018 10:33:06 +1300 Subject: [PATCH] source4/scripting python: convert 'except X, e' to 'except X as e' Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- source4/scripting/bin/autoidl | 2 +- source4/scripting/bin/minschema | 8 ++++---- source4/scripting/bin/rpcclient | 2 +- source4/scripting/bin/samba-tool | 4 ++-- source4/scripting/bin/samba_dnsupdate | 6 +++--- source4/scripting/bin/samba_kcc | 2 +- source4/scripting/bin/samba_spnupdate | 4 ++-- source4/scripting/bin/samba_upgradedns | 2 +- source4/scripting/bin/samba_upgradeprovision | 8 ++++---- source4/scripting/bin/w32err_code.py | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/source4/scripting/bin/autoidl b/source4/scripting/bin/autoidl index 313ab4babda..6a13caa2510 100755 --- a/source4/scripting/bin/autoidl +++ b/source4/scripting/bin/autoidl @@ -157,5 +157,5 @@ for i in range(num_funcs): data = Function(conn, i) try: data.find_idl() - except Exception, e: + except Exception as e: print "Error: %r" % e diff --git a/source4/scripting/bin/minschema b/source4/scripting/bin/minschema index f60538753e9..8ec559a4584 100755 --- a/source4/scripting/bin/minschema +++ b/source4/scripting/bin/minschema @@ -257,7 +257,7 @@ def find_objectclass_auto(ldb, o): ldif += "\nobjectClass: " + o.name try: ldb.add(ldif) - except LdbError, e: + except LdbError as e: print "error adding %s: %s" % (o.name, e) print "%s" % ldif return @@ -316,13 +316,13 @@ def walk_dn(ldb, dn): attrs = ["allowedAttributes"] try: res = ldb.search("objectClass=*", dn, SCOPE_BASE, attrs) - except LdbError, e: + except LdbError as e: print >>sys.stderr, "Unable to fetch allowedAttributes for '%s' - %r" % (dn, e) return allattrs = res[0]["allowedAttributes"] try: res = ldb.search("objectClass=*", dn, SCOPE_BASE, allattrs) - except LdbError, e: + except LdbError as e: print >>sys.stderr, "Unable to fetch all attributes for '%s' - %s" % (dn, e) return msg = res[0] @@ -335,7 +335,7 @@ def walk_naming_context(ldb, namingContext): try: res = ldb.search("objectClass=*", namingContext, SCOPE_DEFAULT, ["objectClass"]) - except LdbError, e: + except LdbError as e: print >>sys.stderr, "Unable to fetch objectClasses for '%s' - %s" % (namingContext, e) return for msg in res: diff --git a/source4/scripting/bin/rpcclient b/source4/scripting/bin/rpcclient index 871dc74bcf1..cbab0d53820 100755 --- a/source4/scripting/bin/rpcclient +++ b/source4/scripting/bin/rpcclient @@ -49,7 +49,7 @@ class rpcclient(Cmd): try: Cmd.onecmd(self, line) - except dcerpc.NTSTATUS, arg: + except dcerpc.NTSTATUS as arg: print 'The command returned an error: %s' % arg[1] # Command handlers diff --git a/source4/scripting/bin/samba-tool b/source4/scripting/bin/samba-tool index bb9662666c1..7f4b7a756a0 100755 --- a/source4/scripting/bin/samba-tool +++ b/source4/scripting/bin/samba-tool @@ -42,9 +42,9 @@ if len(sys.argv) > 1: try: retval = cmd._run("samba-tool", subcommand, *args) -except SystemExit, e: +except SystemExit as e: retval = e.code -except Exception, e: +except Exception as e: cmd.show_command_error(e) retval = 1 sys.exit(retval) diff --git a/source4/scripting/bin/samba_dnsupdate b/source4/scripting/bin/samba_dnsupdate index d9948a6f9b8..ac6cf616b8f 100755 --- a/source4/scripting/bin/samba_dnsupdate +++ b/source4/scripting/bin/samba_dnsupdate @@ -539,7 +539,7 @@ def call_nsupdate(d, op="add"): error_count = error_count + 1 if opts.verbose: print("Failed nsupdate: %d" % ret) - except Exception, estr: + except Exception as estr: if opts.fail_immediately: sys.exit(1) error_count = error_count + 1 @@ -627,7 +627,7 @@ def call_samba_tool(d, op="add", zone=None): error_count = error_count + 1 if opts.verbose: print("Failed 'samba-tool dns' based update of %s" % (str(d))) - except Exception, estr: + except Exception as estr: if opts.fail_immediately: sys.exit(1) error_count = error_count + 1 @@ -678,7 +678,7 @@ def rodc_dns_update(d, t, op): if ret_names.names[0].status != 0: print("Failed to set DNS entry: %s (status %u)" % (d, ret_names.names[0].status)) error_count = error_count + 1 - except RuntimeError, reason: + except RuntimeError as reason: print("Error setting DNS entry of type %u: %s: %s" % (t, d, reason)) error_count = error_count + 1 diff --git a/source4/scripting/bin/samba_kcc b/source4/scripting/bin/samba_kcc index 05ca55a180b..dd9630fe9c2 100755 --- a/source4/scripting/bin/samba_kcc +++ b/source4/scripting/bin/samba_kcc @@ -337,6 +337,6 @@ try: attempt_live_connections=opts.attempt_live_connections) sys.exit(rc) -except GraphError, e: +except GraphError as e: print e sys.exit(1) diff --git a/source4/scripting/bin/samba_spnupdate b/source4/scripting/bin/samba_spnupdate index c83e5753eea..9bc85567186 100755 --- a/source4/scripting/bin/samba_spnupdate +++ b/source4/scripting/bin/samba_spnupdate @@ -213,7 +213,7 @@ def call_rodc_update(d): net = Net(creds=creds, lp=lp) try: cldap_ret = net.finddc(domain=domain, flags=nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) - except Exception, reason: + except Exception as reason: print("Unable to find writeable DC for domain '%s' to send DRS writeSPN to : %s" % (domain, reason)) sys.exit(1) server = cldap_ret.pdc_dns_name @@ -223,7 +223,7 @@ def call_rodc_update(d): binding_options += ",print" drs = drsuapi.drsuapi('ncacn_ip_tcp:%s[%s]' % (server, binding_options), lp, creds) (drs_handle, supported_extensions) = drs_utils.drs_DsBind(drs) - except Exception, reason: + except Exception as reason: print("Unable to connect to DC '%s' for domain '%s' : %s" % (server, domain, reason)) sys.exit(1) req1 = drsuapi.DsWriteAccountSpnRequest1() diff --git a/source4/scripting/bin/samba_upgradedns b/source4/scripting/bin/samba_upgradedns index 261d8a1922d..db15b65e1dc 100755 --- a/source4/scripting/bin/samba_upgradedns +++ b/source4/scripting/bin/samba_upgradedns @@ -330,7 +330,7 @@ if __name__ == '__main__': zone = dns.zone.from_file(paths.dns, relativize=False) rrset = zone.get_rdataset("%s." % dnsdomain, dns.rdatatype.SOA) serial = int(rrset[0].serial) - except Exception, e: + except Exception as e: logger.warn("Error parsing DNS data from '%s' (%s)" % (paths.dns, str(e))) logger.warn("DNS records will be automatically created") autofill = True diff --git a/source4/scripting/bin/samba_upgradeprovision b/source4/scripting/bin/samba_upgradeprovision index 1dbe1acd7b8..f3e690ba552 100755 --- a/source4/scripting/bin/samba_upgradeprovision +++ b/source4/scripting/bin/samba_upgradeprovision @@ -1155,7 +1155,7 @@ def update_partition(ref_samdb, samdb, basedn, names, schema, provisionUSNs, pre message(SIMPLE, "There are %d changed objects" % (changed)) return 1 - except StandardError, err: + except StandardError as err: message(ERROR, "Exception during upgrade of samdb:") (typ, val, tb) = sys.exc_info() traceback.print_exception(typ, val, tb) @@ -1258,7 +1258,7 @@ def rebuild_sd(samdb, names): delta["nTSecurityDescriptor"] = MessageElement(descr, FLAG_MOD_REPLACE, "nTSecurityDescriptor") samdb.modify(delta, ["sd_flags:1:%d" % sd_flags,"relax:0","local_oid:%s:0" % dsdb.DSDB_CONTROL_DBCHECK]) - except LdbError, e: + except LdbError as e: samdb.transaction_cancel() res = samdb.search(expression="objectClass=*", base=str(delta.dn), scope=SCOPE_BASE, @@ -1804,7 +1804,7 @@ if __name__ == '__main__': if opts.full: try: update_gpo(paths, ldbs.sam, names, lp, message) - except ProvisioningError, e: + except ProvisioningError as e: message(ERROR, "The policy for domain controller is missing. " "You should restart upgradeprovision with --full") @@ -1823,7 +1823,7 @@ if __name__ == '__main__': message(SIMPLE, "Reindexing finished") shutil.rmtree(provisiondir) - except StandardError, err: + except StandardError as err: message(ERROR, "A problem occurred while trying to upgrade your " "provision. A full backup is located at %s" % backupdir) if opts.debugall or opts.debugchange: diff --git a/source4/scripting/bin/w32err_code.py b/source4/scripting/bin/w32err_code.py index cd17f995ce1..6687c8222a0 100755 --- a/source4/scripting/bin/w32err_code.py +++ b/source4/scripting/bin/w32err_code.py @@ -113,7 +113,7 @@ class WerrorHtmlParser(object): for line in fp: html_str += line.strip() fp.close() - except IOError, e: + except IOError as e: print "error loading url: " + e.strerror pass -- 2.47.3