2to3 -f raise
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 31 Mar 2016 06:57:04 +0000 (08:57 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 31 Mar 2016 06:57:04 +0000 (08:57 +0200)
21 files changed:
clientbin/setRecord.py
sfa/client/sfaclientlib.py
sfa/dummy/dummyshell.py
sfa/federica/fdshell.py
sfa/managers/managerwrapper.py
sfa/managers/registry_manager.py
sfa/nitos/nitosdriver.py
sfa/nitos/nitosshell.py
sfa/planetlab/plshell.py
sfa/rspecs/elements/versions/ofeliav1Port.py
sfa/rspecs/versions/ofeliav1.py
sfa/server/xmlrpcapi.py
sfa/storage/alchemy.py
sfa/storage/parameter.py
sfa/storage/record.py
sfa/trust/certificate.py
sfa/util/method.py
sfa/util/storage.py
sfa/util/xrn.py
sfatables/commands/moo.py
wsdl/sfa2wsdl.py

index 405c90d..bd77606 100755 (executable)
@@ -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):
index ccdf36a..7736e52 100644 (file)
@@ -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
 
index c6cc833..50e78ac 100644 (file)
@@ -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
index 42ec030..aefbdd1 100644 (file)
@@ -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)
index 946f7d2..da8c98f 100644 (file)
@@ -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):
index a88c9de..5567197 100644 (file)
@@ -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)
index 40db2a7..8e3da34 100644 (file)
@@ -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)
index 269e367..2636e6d 100644 (file)
@@ -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))
index 16af128..15c58b6 100644 (file)
@@ -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
index f4cf74d..009d551 100644 (file)
@@ -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)
     
index ff4ae42..0608e7a 100755 (executable)
@@ -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)
index b6f8e95..8b8bd78 100644 (file)
@@ -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):
         """
index f052fba..fb8dfac 100644 (file)
@@ -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
index e520bfc..6737d0b 100644 (file)
@@ -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)
index 3a9c315..9622268 100644 (file)
@@ -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*'=')
index 6b1e260..6f3ecc6 100644 (file)
@@ -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:
index e7bdee7..4e21170 100644 (file)
@@ -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)):
index 89a2509..9033434 100644 (file)
@@ -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()
index b16ea51..6198f83 100644 (file)
@@ -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)
index bd8c88e..bd19a9d 100644 (file)
@@ -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)):
index a9e3c32..2ec1307 100755 (executable)
@@ -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))