From ecc85e0b923922cf7117d29b380f5284edb88f21 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 31 Mar 2016 08:57:04 +0200 Subject: [PATCH] 2to3 -f raise --- clientbin/setRecord.py | 4 ++-- sfa/client/sfaclientlib.py | 6 +++--- sfa/dummy/dummyshell.py | 2 +- sfa/federica/fdshell.py | 2 +- sfa/managers/managerwrapper.py | 2 +- sfa/managers/registry_manager.py | 2 +- sfa/nitos/nitosdriver.py | 2 +- sfa/nitos/nitosshell.py | 2 +- sfa/planetlab/plshell.py | 2 +- sfa/rspecs/elements/versions/ofeliav1Port.py | 4 ++-- sfa/rspecs/versions/ofeliav1.py | 4 ++-- sfa/server/xmlrpcapi.py | 6 +++--- sfa/storage/alchemy.py | 2 +- sfa/storage/parameter.py | 2 +- sfa/storage/record.py | 2 +- sfa/trust/certificate.py | 8 ++++---- sfa/util/method.py | 12 ++++++------ sfa/util/storage.py | 8 ++++---- sfa/util/xrn.py | 6 +++--- sfatables/commands/moo.py | 12 ++++++------ wsdl/sfa2wsdl.py | 2 +- 21 files changed, 46 insertions(+), 46 deletions(-) diff --git a/clientbin/setRecord.py b/clientbin/setRecord.py index 405c90d9..bd776069 100755 --- a/clientbin/setRecord.py +++ b/clientbin/setRecord.py @@ -47,9 +47,9 @@ def editDict(args, recordDict, options): if vect in recordDict: del recordDict[vect] else: - raise TypeError, "Argument error: Records are updated with \n" \ + raise TypeError("Argument error: Records are updated with \n" \ "key=val1,val2,valN or\n" \ - "key+=val1,val2,valN \n%s Unknown key/val" % vect + "key+=val1,val2,valN \n%s Unknown key/val" % vect) def replaceDict(newval, recordDict, options): diff --git a/sfa/client/sfaclientlib.py b/sfa/client/sfaclientlib.py index ccdf36ac..7736e52a 100644 --- a/sfa/client/sfaclientlib.py +++ b/sfa/client/sfaclientlib.py @@ -200,7 +200,7 @@ class SfaClientBootstrap: records = registry_proxy.Resolve (hrn, credential_string) records=[record for record in records if record['type']==type] if not records: - raise RecordNotFound, "hrn %s (%s) unknown to registry %s"%(hrn,type,self.registry_url) + raise RecordNotFound("hrn %s (%s) unknown to registry %s"%(hrn,type,self.registry_url)) record=records[0] self.plain_write (output, record['gid']) self.logger.debug("SfaClientBootstrap: Wrote GID for %s (%s) in %s"% (hrn,type,output)) @@ -316,7 +316,7 @@ class SfaClientBootstrap: def assert_filename (self, filename, kind): if not os.path.isfile (filename): - raise IOError,"Missing %s file %s"%(kind,filename) + raise IOError("Missing %s file %s"%(kind,filename)) return True def assert_private_key (self): @@ -354,7 +354,7 @@ class SfaClientBootstrap: message="Could not produce/retrieve %s (%s -- %s)"%\ (filename,error[0],error[1]) self.logger.log_exc(message) - raise Exception, message + raise Exception(message) return wrapped return wrap diff --git a/sfa/dummy/dummyshell.py b/sfa/dummy/dummyshell.py index c6cc833a..50e78ac5 100644 --- a/sfa/dummy/dummyshell.py +++ b/sfa/dummy/dummyshell.py @@ -26,7 +26,7 @@ class DummyShell: def __getattr__(self, name): def func(*args, **kwds): if not name in DummyShell.direct_calls: - raise Exception, "Illegal method call %s for DUMMY driver"%(name) + raise Exception("Illegal method call %s for DUMMY driver"%(name)) result=getattr(self.proxy, name)(*args, **kwds) logger.debug('DummyShell %s returned ... '%(name)) return result diff --git a/sfa/federica/fdshell.py b/sfa/federica/fdshell.py index 42ec030f..aefbdd1e 100644 --- a/sfa/federica/fdshell.py +++ b/sfa/federica/fdshell.py @@ -30,7 +30,7 @@ class FdShell: def __getattr__(self, name): def func(*args, **kwds): if name not in FdShell.direct_calls: - raise Exception, "Illegal method call %s for FEDERICA driver"%(name) + raise Exception("Illegal method call %s for FEDERICA driver"%(name)) logger.info("Issuing %s args=%s kwds=%s to federica"%\ (name,args,kwds)) # result=getattr(self.proxy, "AggregateManager.%s"%name)(credential, *args, **kwds) diff --git a/sfa/managers/managerwrapper.py b/sfa/managers/managerwrapper.py index 946f7d2b..da8c98f6 100644 --- a/sfa/managers/managerwrapper.py +++ b/sfa/managers/managerwrapper.py @@ -27,7 +27,7 @@ class ManagerWrapper: # that's what happens when there's something wrong with the db # or any bad stuff of that kind at startup time logger.log_exc("Failed to create a manager, startup sequence is broken") - raise SfaAPIError,"Argument to ManagerWrapper must be a module or class" + raise SfaAPIError("Argument to ManagerWrapper must be a module or class") self.interface = interface def __getattr__(self, method): diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index a88c9de0..5567197d 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -625,7 +625,7 @@ class RegistryManager: for command in all_commands: (status, output) = commands.getstatusoutput(command) if status: - raise Exception, output + raise Exception(output) for filename in [key_filename, gid_filename]: os.unlink(filename) diff --git a/sfa/nitos/nitosdriver.py b/sfa/nitos/nitosdriver.py index 40db2a70..8e3da348 100644 --- a/sfa/nitos/nitosdriver.py +++ b/sfa/nitos/nitosdriver.py @@ -668,7 +668,7 @@ class NitosDriver (Driver): # xxx this code is quite old and has not run for ages # it is obviously totally broken and needs a rewrite def get_ticket (self, slice_urn, slice_hrn, creds, rspec_string, options): - raise SfaNotImplemented,"NitosDriver.get_ticket needs a rewrite" + raise SfaNotImplemented("NitosDriver.get_ticket needs a rewrite") # please keep this code for future reference # slices = PlSlices(self) # peer = slices.get_peer(slice_hrn) diff --git a/sfa/nitos/nitosshell.py b/sfa/nitos/nitosshell.py index 269e3676..2636e6de 100644 --- a/sfa/nitos/nitosshell.py +++ b/sfa/nitos/nitosshell.py @@ -33,7 +33,7 @@ class NitosShell: actual_name=None if name in NitosShell.direct_calls: actual_name=name if not actual_name: - raise Exception, "Illegal method call %s for NITOS driver"%(name) + raise Exception("Illegal method call %s for NITOS driver"%(name)) actual_name = "scheduler.server." + actual_name result=getattr(self.proxy, actual_name)(*args, **kwds) logger.debug('NitosShell %s (%s) returned ... '%(name,actual_name)) diff --git a/sfa/planetlab/plshell.py b/sfa/planetlab/plshell.py index 16af128d..15c58b69 100644 --- a/sfa/planetlab/plshell.py +++ b/sfa/planetlab/plshell.py @@ -89,7 +89,7 @@ class PlShell: if name in PlShell.direct_calls: actual_name=name if name in PlShell.alias_calls: actual_name=PlShell.alias_calls[name] if not actual_name: - raise Exception, "Illegal method call %s for PL driver"%(name) + raise Exception("Illegal method call %s for PL driver"%(name)) result=getattr(self.proxy, actual_name)(self.plauth, *args, **kwds) logger.debug('PlShell %s (%s) returned ... '%(name,actual_name)) return result diff --git a/sfa/rspecs/elements/versions/ofeliav1Port.py b/sfa/rspecs/elements/versions/ofeliav1Port.py index f4cf74dc..009d551c 100644 --- a/sfa/rspecs/elements/versions/ofeliav1Port.py +++ b/sfa/rspecs/elements/versions/ofeliav1Port.py @@ -8,7 +8,7 @@ class Ofeliav1Port: @staticmethod def add_portrs(xml, ports): - raise Exception, "not implemented yet" + raise Exception("not implemented yet") if not ports: return if not isinstance(ports, list): @@ -22,7 +22,7 @@ class Ofeliav1Port: @staticmethod def add_port_attribute(xml, name, value): - raise Exception, "not implemented yet" + raise Exception("not implemented yet") elem = xml.add_element(name) elem.set_text(value) diff --git a/sfa/rspecs/versions/ofeliav1.py b/sfa/rspecs/versions/ofeliav1.py index ff4ae42e..0608e7a0 100755 --- a/sfa/rspecs/versions/ofeliav1.py +++ b/sfa/rspecs/versions/ofeliav1.py @@ -30,7 +30,7 @@ class Ofelia(RSpecVersion): # Network def get_networks(self): - raise Exception, "Not implemented" + raise Exception("Not implemented") network_elems = self.xml.xpath('//network') networks = [network_elem.get_instance(fields=['name', 'slice']) for \ network_elem in network_elems] @@ -38,7 +38,7 @@ class Ofelia(RSpecVersion): def add_network(self, network): - raise Exception, "Not implemented" + raise Exception("Not implemented") network_tags = self.xml.xpath('//network[@name="%s"]' % network) if not network_tags: network_tag = self.xml.add_element('network', name=network) diff --git a/sfa/server/xmlrpcapi.py b/sfa/server/xmlrpcapi.py index b6f8e951..8b8bd781 100644 --- a/sfa/server/xmlrpcapi.py +++ b/sfa/server/xmlrpcapi.py @@ -71,7 +71,7 @@ def xmlrpclib_dump(self, value, write): if isinstance(value, Type): f(*args) return - raise TypeError, "cannot marshal %s objects" % type(value) + raise TypeError("cannot marshal %s objects" % type(value)) else: f(*args) @@ -102,7 +102,7 @@ class XmlrpcApi: """ # Look up method if method not in self.methods: - raise SfaInvalidAPIMethod, method + raise SfaInvalidAPIMethod(method) # Get new instance of method try: @@ -112,7 +112,7 @@ class XmlrpcApi: return getattr(module, classname)(self) except (ImportError, AttributeError): self.logger.log_exc("Error importing method: %s" % method) - raise SfaInvalidAPIMethod, method + raise SfaInvalidAPIMethod(method) def call(self, source, method, *args): """ diff --git a/sfa/storage/alchemy.py b/sfa/storage/alchemy.py index f052fba5..fb8dfac1 100644 --- a/sfa/storage/alchemy.py +++ b/sfa/storage/alchemy.py @@ -39,7 +39,7 @@ class Alchemy: except: pass self.engine=None - raise Exception,"Could not connect to database %s as %s with psycopg2"%(dbname,config.SFA_DB_USER) + raise Exception("Could not connect to database %s as %s with psycopg2"%(dbname,config.SFA_DB_USER)) # expects boolean True: debug is ON or False: debug is OFF diff --git a/sfa/storage/parameter.py b/sfa/storage/parameter.py index e520bfc2..6737d0bd 100644 --- a/sfa/storage/parameter.py +++ b/sfa/storage/parameter.py @@ -100,4 +100,4 @@ def xmlrpc_type(arg): # documentation purposes. return "mixed" else: - raise SfaAPIError, "XML-RPC cannot marshal %s objects" % arg_type + raise SfaAPIError("XML-RPC cannot marshal %s objects" % arg_type) diff --git a/sfa/storage/record.py b/sfa/storage/record.py index 3a9c3159..96222682 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -88,7 +88,7 @@ class Record: elif format == 'simple': print(self.dump_simple()) else: - raise Exception, "Invalid format %s" % format + raise Exception("Invalid format %s" % format) def dump_text(self, dump_parents=False, sort=False): print(40*'=') diff --git a/sfa/trust/certificate.py b/sfa/trust/certificate.py index 6b1e2603..6f3ecc62 100644 --- a/sfa/trust/certificate.py +++ b/sfa/trust/certificate.py @@ -90,11 +90,11 @@ def test_passphrase(string, passphrase): def convert_public_key(key): keyconvert_path = "/usr/bin/keyconvert.py" if not os.path.isfile(keyconvert_path): - raise IOError, "Could not find keyconvert in %s" % keyconvert_path + raise IOError("Could not find keyconvert in %s" % keyconvert_path) # we can only convert rsa keys if "ssh-dss" in key: - raise Exception, "keyconvert: dss keys are not supported" + raise Exception("keyconvert: dss keys are not supported") (ssh_f, ssh_fn) = tempfile.mkstemp() ssl_fn = tempfile.mktemp() @@ -108,7 +108,7 @@ def convert_public_key(key): # that it can be expected to see why it failed. # TODO: for production, cleanup the temporary files if not os.path.exists(ssl_fn): - raise Exception, "keyconvert: generated certificate not found. keyconvert may have failed." + raise Exception("keyconvert: generated certificate not found. keyconvert may have failed.") k = Keypair() try: @@ -570,7 +570,7 @@ class Certificate: if self.isCA != None: # Can't double set properties - raise Exception, "Cannot set basicConstraints CA:?? more than once. Was %s, trying to set as %s" % (self.isCA, val) + raise Exception("Cannot set basicConstraints CA:?? more than once. Was %s, trying to set as %s" % (self.isCA, val)) self.isCA = val if val: diff --git a/sfa/util/method.py b/sfa/util/method.py index e7bdee7b..4e211703 100644 --- a/sfa/util/method.py +++ b/sfa/util/method.py @@ -250,20 +250,20 @@ class Method: if expected_type in StringTypes: if min is not None and \ len(value.encode(self.api.encoding)) < min: - raise SfaInvalidArgument, "%s must be at least %d bytes long" % (name, min) + raise SfaInvalidArgument("%s must be at least %d bytes long" % (name, min)) if max is not None and \ len(value.encode(self.api.encoding)) > max: - raise SfaInvalidArgument, "%s must be at most %d bytes long" % (name, max) + raise SfaInvalidArgument("%s must be at most %d bytes long" % (name, max)) elif expected_type in (list, tuple, set): if min is not None and len(value) < min: - raise SfaInvalidArgument, "%s must contain at least %d items" % (name, min) + raise SfaInvalidArgument("%s must contain at least %d items" % (name, min)) if max is not None and len(value) > max: - raise SfaInvalidArgument, "%s must contain at most %d items" % (name, max) + raise SfaInvalidArgument("%s must contain at most %d items" % (name, max)) else: if min is not None and value < min: - raise SfaInvalidArgument, "%s must be > %s" % (name, str(min)) + raise SfaInvalidArgument("%s must be > %s" % (name, str(min))) if max is not None and value > max: - raise SfaInvalidArgument, "%s must be < %s" % (name, str(max)) + raise SfaInvalidArgument("%s must be < %s" % (name, str(max))) # If a list with particular types of items is expected if isinstance(expected, (list, tuple, set)): diff --git a/sfa/util/storage.py b/sfa/util/storage.py index 89a25099..9033434f 100644 --- a/sfa/util/storage.py +++ b/sfa/util/storage.py @@ -19,8 +19,8 @@ class SimpleStorage(dict): db_file = open(self.db_filename, 'r') dict.__init__(self, eval(db_file.read())) elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename): - raise IOError, '%s exists but is not a file. please remove it and try again' \ - % self.db_filename + raise IOError('%s exists but is not a file. please remove it and try again' \ + % self.db_filename) else: self.write() self.load() @@ -49,8 +49,8 @@ class XmlStorage(SimpleStorage): xml = XML(self.db_filename) dict.__init__(self, xml.todict()) elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename): - raise IOError, '%s exists but is not a file. please remove it and try again' \ - % self.db_filename + raise IOError('%s exists but is not a file. please remove it and try again' \ + % self.db_filename) else: self.write() self.load() diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index b16ea511..6198f83c 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -162,7 +162,7 @@ class Xrn: def get_hrn_type(self): return (self.hrn, self.type) def _normalize(self): - if self.hrn is None: raise SfaAPIError, "Xrn._normalize" + if self.hrn is None: raise SfaAPIError("Xrn._normalize") if not hasattr(self,'leaf'): self.leaf=Xrn.hrn_split(self.hrn)[-1] # self.authority keeps a list @@ -211,7 +211,7 @@ class Xrn: # if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX): if not Xrn.is_urn(self.urn): - raise SfaAPIError, "Xrn.urn_to_hrn" + raise SfaAPIError("Xrn.urn_to_hrn") parts = Xrn.urn_split(self.urn) type=parts.pop(2) @@ -249,7 +249,7 @@ class Xrn: # if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX): if Xrn.is_urn(self.hrn): - raise SfaAPIError, "Xrn.hrn_to_urn, hrn=%s"%self.hrn + raise SfaAPIError("Xrn.hrn_to_urn, hrn=%s"%self.hrn) if self.type and self.type.startswith('authority'): self.authority = Xrn.hrn_auth_list(self.hrn) diff --git a/sfatables/commands/moo.py b/sfatables/commands/moo.py index bd8c88ef..bd19a9d5 100644 --- a/sfatables/commands/moo.py +++ b/sfatables/commands/moo.py @@ -170,20 +170,20 @@ class Command: if expected_type in StringTypes: if min is not None and \ len(value.encode(self.api.encoding)) < min: - raise SfaInvalidArgument, "%s must be at least %d bytes long" % (name, min) + raise SfaInvalidArgument("%s must be at least %d bytes long" % (name, min)) if max is not None and \ len(value.encode(self.api.encoding)) > max: - raise SfaInvalidArgument, "%s must be at most %d bytes long" % (name, max) + raise SfaInvalidArgument("%s must be at most %d bytes long" % (name, max)) elif expected_type in (list, tuple, set): if min is not None and len(value) < min: - raise SfaInvalidArgument, "%s must contain at least %d items" % (name, min) + raise SfaInvalidArgument("%s must contain at least %d items" % (name, min)) if max is not None and len(value) > max: - raise SfaInvalidArgument, "%s must contain at most %d items" % (name, max) + raise SfaInvalidArgument("%s must contain at most %d items" % (name, max)) else: if min is not None and value < min: - raise SfaInvalidArgument, "%s must be > %s" % (name, str(min)) + raise SfaInvalidArgument("%s must be > %s" % (name, str(min))) if max is not None and value > max: - raise SfaInvalidArgument, "%s must be < %s" % (name, str(max)) + raise SfaInvalidArgument("%s must be < %s" % (name, str(max))) # If a list with particular types of items is expected if isinstance(expected, (list, tuple, set)): diff --git a/wsdl/sfa2wsdl.py b/wsdl/sfa2wsdl.py index a9e3c32a..2ec13072 100755 --- a/wsdl/sfa2wsdl.py +++ b/wsdl/sfa2wsdl.py @@ -166,7 +166,7 @@ class WSDLGen: return "xsd:string" else: pdb.set_trace() - raise SoapError, "Cannot handle %s objects" % arg_type + raise SoapError("Cannot handle %s objects" % arg_type) def param_type(self, arg): return (self.name_complex_type(arg)) -- 2.43.0