From: Thierry Parmentelat Date: Thu, 31 Mar 2016 07:51:27 +0000 (+0200) Subject: 2to3 -f except X-Git-Tag: sfa-3.1-21~29 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=a0ef6e7c91c3c8fa376943d28fec8c5c204a78cd 2to3 -f except --- diff --git a/clientbin/getNodes.py b/clientbin/getNodes.py index d77bbbcf..f2d39a2c 100644 --- a/clientbin/getNodes.py +++ b/clientbin/getNodes.py @@ -82,6 +82,6 @@ def main(): if __name__ == '__main__': try: main() - except Exception, e: + except Exception as e: raise print e diff --git a/clientbin/getRecord.py b/clientbin/getRecord.py index e2be593b..c88f193e 100755 --- a/clientbin/getRecord.py +++ b/clientbin/getRecord.py @@ -78,8 +78,8 @@ def main(): if __name__ == '__main__': try: main() - except ExpatError, e: + except ExpatError as e: print "RecordError. Is your record valid XML?" print e - except Exception, e: + except Exception as e: print e diff --git a/clientbin/setRecord.py b/clientbin/setRecord.py index bd776069..aafd95c2 100755 --- a/clientbin/setRecord.py +++ b/clientbin/setRecord.py @@ -103,5 +103,5 @@ def main(): if __name__ == '__main__': try: main() - except Exception, e: + except Exception as e: print e diff --git a/flashpolicy/sfa_flashpolicy.py b/flashpolicy/sfa_flashpolicy.py index de98be1e..1fe3f844 100644 --- a/flashpolicy/sfa_flashpolicy.py +++ b/flashpolicy/sfa_flashpolicy.py @@ -63,7 +63,7 @@ class policy_server(object): try: while True: thread.start_new_thread(self.handle, self.sock.accept()) - except socket.error, e: + except socket.error as e: self.log('Error accepting connection: %s' % (e[1],)) def handle(self, conn, addr): addrstr = '%s:%s' % (addr[0],addr[1]) @@ -79,9 +79,9 @@ class policy_server(object): self.log('Valid request received from %s' % (addrstr,)) conn.sendall(self.policy) self.log('Sent policy file to %s' % (addrstr,)) - except socket.error, e: + except socket.error as e: self.log('Error handling connection from %s: %s' % (addrstr, e[1])) - except Exception, e: + except Exception as e: self.log('Error handling connection from %s: %s' % (addrstr, e[1])) def log(self, str): print >>sys.stderr, str @@ -105,7 +105,7 @@ def main(): if opts.daemon: daemon() policy_server(opts.port, opts.path).run() - except Exception, e: + except Exception as e: print >> sys.stderr, e sys.exit(1) except KeyboardInterrupt: diff --git a/sfa/client/manifolduploader.py b/sfa/client/manifolduploader.py index c291a428..66874bae 100755 --- a/sfa/client/manifolduploader.py +++ b/sfa/client/manifolduploader.py @@ -113,7 +113,7 @@ class ManifoldUploader: try: self.logger.debug("Using new v2 method forward+annotation@%s %s"%(platform,message)) retcod2=manifold.forward (query, annotation) - except Exception,e: + except Exception as e: # xxx we need a constant constant for UNKNOWN, how about using 1 MANIFOLD_UNKNOWN=1 retcod2={'code':MANIFOLD_UNKNOWN,'description':"%s"%e} @@ -129,7 +129,7 @@ class ManifoldUploader: self.logger.debug("****** full retcod2") for (k,v) in retcod2.items(): self.logger.debug("**** %s: %s"%(k,v)) return False - except Exception, e: + except Exception as e: if message: self.logger.error("Could not upload %s %s"%(message,e)) else: self.logger.error("Could not upload credential %s"%e) if self.logger.debugEnabled(): diff --git a/sfa/client/multiclient.py b/sfa/client/multiclient.py index 28b5b15a..6bdf2b27 100644 --- a/sfa/client/multiclient.py +++ b/sfa/client/multiclient.py @@ -17,7 +17,7 @@ def ThreadedMethod(callable, results, errors): def run(self): try: results.put(callable(*args, **kwds)) - except Exception, e: + except Exception as e: logger.log_exc('MultiClient: Error in thread: ') errors.put(traceback.format_exc()) diff --git a/sfa/client/sfaserverproxy.py b/sfa/client/sfaserverproxy.py index d326b3aa..ca62ddf0 100644 --- a/sfa/client/sfaserverproxy.py +++ b/sfa/client/sfaserverproxy.py @@ -27,7 +27,7 @@ class ExceptionUnmarshaller(xmlrpclib.Unmarshaller): def close(self): try: return xmlrpclib.Unmarshaller.close(self) - except xmlrpclib.Fault, e: + except xmlrpclib.Fault as e: raise ServerException(e.faultString) ## diff --git a/sfa/managers/aggregate_manager_eucalyptus.py b/sfa/managers/aggregate_manager_eucalyptus.py index b8c83d8c..2356f333 100644 --- a/sfa/managers/aggregate_manager_eucalyptus.py +++ b/sfa/managers/aggregate_manager_eucalyptus.py @@ -79,7 +79,7 @@ class EucaInstance(SQLObject): self.instance_id = instance.id # If there is an error, destroy itself. - except EC2ResponseError, ec2RespErr: + except EC2ResponseError as ec2RespErr: errTree = ET.fromstring(ec2RespErr.body) msg = errTree.find('.//Message') logger.error(msg.text) @@ -524,7 +524,7 @@ class AggregateManagerEucalyptus: instList.append(instInfoDict) AggregateManagerEucalyptus.cloud['instances'] = instancesDict - except EC2ResponseError, ec2RespErr: + except EC2ResponseError as ec2RespErr: errTree = ET.fromstring(ec2RespErr.body) errMsgE = errTree.find('.//Message') logger.error(errMsgE.text) @@ -661,7 +661,7 @@ class AggregateManagerEucalyptus: try: os.makedirs(outdir) - except OSError, e: + except OSError as e: if e.errno != errno.EEXIST: raise diff --git a/sfa/managers/slice_manager.py b/sfa/managers/slice_manager.py index 2a99b6f4..b8aafcc2 100644 --- a/sfa/managers/slice_manager.py +++ b/sfa/managers/slice_manager.py @@ -73,7 +73,7 @@ class SliceManager: stats_elements = rspec.xml.xpath('//statistics') for node in stats_elements: node.getparent().remove(node) - except Exception, e: + except Exception as e: logger.warn("drop_slicemgr_stats failed: %s " % (str(e))) def add_slicemgr_stat(self, rspec, callname, aggname, elapsed, status, exc_info=None): @@ -99,7 +99,7 @@ class SliceManager: exc_frame = exc_tag.add_element("tb_frame", filename=str(item[0]), line=str(item[1]), func=str(item[2]), code=str(item[3])) - except Exception, e: + except Exception as e: logger.warn("add_slicemgr_stat failed on %s: %s" %(aggname, str(e))) def ListResources(self, api, creds, options): @@ -117,7 +117,7 @@ class SliceManager: forward_options['geni_rspec_version'] = options.get('geni_rspec_version') result = server.ListResources(credential, forward_options) return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"} - except Exception, e: + except Exception as e: api.logger.log_exc("ListResources failed at %s" %(server.url)) return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()} diff --git a/sfa/openstack/osaggregate.py b/sfa/openstack/osaggregate.py index 2b653997..29681a05 100644 --- a/sfa/openstack/osaggregate.py +++ b/sfa/openstack/osaggregate.py @@ -395,7 +395,7 @@ class OSAggregate: meta=metadata, name=instance_name) slivers.append(server) - except Exception, err: + except Exception as err: logger.log_exc(err) return slivers diff --git a/sfa/openstack/security_group.py b/sfa/openstack/security_group.py index 70e191e5..6aced8c6 100644 --- a/sfa/openstack/security_group.py +++ b/sfa/openstack/security_group.py @@ -9,7 +9,7 @@ class SecurityGroup: def create_security_group(self, name): try: self.client.security_groups.create(name=name, description=name) - except Exception, ex: + except Exception as ex: logger.log_exc("Failed to add security group") raise @@ -17,7 +17,7 @@ class SecurityGroup: try: security_group = self.client.security_groups.find(name=name) self.client.security_groups.delete(security_group.id) - except Exception, ex: + except Exception as ex: logger.log_exc("Failed to delete security group") @@ -58,7 +58,7 @@ class SecurityGroup: group = self.client.security_groups.find(name=group_name) self.client.security_group_rules.create(group.id, \ protocol, from_port, to_port,cidr_ip) - except Exception, ex: + except Exception as ex: logger.log_exc("Failed to add rule to group %s" % group_name) @@ -81,6 +81,6 @@ class SecurityGroup: rule = self.client.security_group_rules.find(**filter) if rule: self.client.security_group_rules.delete(rule) - except Exception, ex: + except Exception as ex: logger.log_exc("Failed to remove rule from group %s" % group_name) diff --git a/sfa/planetlab/topology.py b/sfa/planetlab/topology.py index cd6036af..c05b198b 100644 --- a/sfa/planetlab/topology.py +++ b/sfa/planetlab/topology.py @@ -25,6 +25,6 @@ class Topology(set): tup = line.split() if len(tup) > 1: self.add((tup[0], tup[1])) - except Exception, e: + except Exception as e: logger.log_exc("Could not find or load the configuration file: %s" % config_file) raise diff --git a/sfa/server/modpython/SfaAggregateModPython.py b/sfa/server/modpython/SfaAggregateModPython.py index 50f9f5f3..5d38a553 100755 --- a/sfa/server/modpython/SfaAggregateModPython.py +++ b/sfa/server/modpython/SfaAggregateModPython.py @@ -50,7 +50,7 @@ def handler(req): return apache.OK - except Exception, err: + except Exception as err: # Log error in /var/log/httpd/(ssl_)?error_log logger.log_exc('%r'%err) return apache.HTTP_INTERNAL_SERVER_ERROR diff --git a/sfa/server/modpython/SfaRegistryModPython.py b/sfa/server/modpython/SfaRegistryModPython.py index 31d0812d..6d17cd2c 100755 --- a/sfa/server/modpython/SfaRegistryModPython.py +++ b/sfa/server/modpython/SfaRegistryModPython.py @@ -50,7 +50,7 @@ def handler(req): return apache.OK - except Exception, err: + except Exception as err: # Log error in /var/log/httpd/(ssl_)?error_log logger.log_exc('%r'%err) return apache.HTTP_INTERNAL_SERVER_ERROR diff --git a/sfa/server/modpython/SfaSliceMgrModPython.py b/sfa/server/modpython/SfaSliceMgrModPython.py index 61cb1614..dcb85626 100755 --- a/sfa/server/modpython/SfaSliceMgrModPython.py +++ b/sfa/server/modpython/SfaSliceMgrModPython.py @@ -50,7 +50,7 @@ def handler(req): return apache.OK - except Exception, err: + except Exception as err: # Log error in /var/log/httpd/(ssl_)?error_log logger.log_exc('%r'%err) return apache.HTTP_INTERNAL_SERVER_ERROR diff --git a/sfa/server/threadedserver.py b/sfa/server/threadedserver.py index 7dfac7d7..daf40e45 100644 --- a/sfa/server/threadedserver.py +++ b/sfa/server/threadedserver.py @@ -119,7 +119,7 @@ class SecureXMLRpcRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler): remote_addr = (remote_ip, remote_port) = self.connection.getpeername() self.api.remote_addr = remote_addr response = self.api.handle(remote_addr, request, self.server.method_map) - except Exception, fault: + except Exception as fault: # This should only happen if the module is buggy # internal error, report as HTTP server error logger.log_exc("server.do_POST") diff --git a/sfa/server/xmlrpcapi.py b/sfa/server/xmlrpcapi.py index 8b8bd781..167ac880 100644 --- a/sfa/server/xmlrpcapi.py +++ b/sfa/server/xmlrpcapi.py @@ -138,7 +138,7 @@ class XmlrpcApi: method = method_map[method] methodresponse = True - except Exception, e: + except Exception as e: if SOAPpy is not None: self.protocol = 'soap' interface = SOAPpy @@ -151,10 +151,10 @@ class XmlrpcApi: try: result = self.call(source, method, *args) - except SfaFault, fault: + except SfaFault as fault: result = fault self.logger.log_exc("XmlrpcApi.handle has caught Exception") - except Exception, fault: + except Exception as fault: self.logger.log_exc("XmlrpcApi.handle has caught Exception") result = SfaAPIError(fault) diff --git a/sfa/trust/credential.py b/sfa/trust/credential.py index ae2cc8d2..37af67bd 100644 --- a/sfa/trust/credential.py +++ b/sfa/trust/credential.py @@ -191,7 +191,7 @@ class Signature(object): try: doc = parseString(self.xml) - except ExpatError,e: + except ExpatError as e: logger.log_exc ("Failed to parse credential, %s"%self.xml) raise sig = doc.getElementsByTagName("Signature")[0] @@ -730,7 +730,7 @@ class Credential(object): doc = None try: doc = parseString(self.xml) - except ExpatError,e: + except ExpatError as e: raise CredentialNotVerifiable("Malformed credential") doc = parseString(self.xml) sigs = [] @@ -860,7 +860,7 @@ class Credential(object): # or non PEM files trusted_cert_objects.append(GID(filename=f)) ok_trusted_certs.append(f) - except Exception, exc: + except Exception as exc: logger.error("Failed to load trusted cert from %s: %r"%( f, exc)) trusted_certs = ok_trusted_certs diff --git a/sfa/trust/credential_factory.py b/sfa/trust/credential_factory.py index ef738af3..a51673ef 100644 --- a/sfa/trust/credential_factory.py +++ b/sfa/trust/credential_factory.py @@ -62,7 +62,7 @@ class CredentialFactory: if credFile: try: credString = open(credFile).read() - except Exception, e: + except Exception as e: logger.info("Error opening credential file %s: %s" % credFile, e) return None @@ -72,7 +72,7 @@ class CredentialFactory: if credO.has_key('geni_value') and credO.has_key('geni_type'): cred_type = credO['geni_type'] credString = credO['geni_value'] - except Exception, e: + except Exception as e: # It wasn't a struct. So the credString is XML. Pull the type directly from the string logger.debug("Credential string not JSON: %s" % e) cred_type = CredentialFactory.getType(credString) @@ -81,7 +81,7 @@ class CredentialFactory: try: cred = Credential(string=credString) return cred - except Exception, e: + except Exception as e: if credFile: msg = "credString started: %s" % credString[:50] raise Exception("%s not a parsable SFA credential: %s. " % (credFile, e) + msg) @@ -92,7 +92,7 @@ class CredentialFactory: try: cred = ABACCredential(string=credString) return cred - except Exception, e: + except Exception as e: if credFile: raise Exception("%s not a parsable ABAC credential: %s" % (credFile, e)) else: diff --git a/sfa/trust/hierarchy.py b/sfa/trust/hierarchy.py index 43b318ee..5e76dbf3 100644 --- a/sfa/trust/hierarchy.py +++ b/sfa/trust/hierarchy.py @@ -160,7 +160,8 @@ class Hierarchy: try: os.makedirs(directory) # if the path already exists then pass - except OSError, (errno, strerr): + except OSError as xxx_todo_changeme: + (errno, strerr) = xxx_todo_changeme.args if errno == 17: pass diff --git a/sfa/trust/speaksfor_util.py b/sfa/trust/speaksfor_util.py index 9bad61db..20819c90 100644 --- a/sfa/trust/speaksfor_util.py +++ b/sfa/trust/speaksfor_util.py @@ -211,14 +211,14 @@ def verify_speaks_for(cred, tool_gid, speaking_for_urn, # User certificate must validate against trusted roots try: user_gid.verify_chain(trusted_roots) - except Exception, e: + except Exception as e: return False, None, \ "Cred signer (user) cert not trusted: %s" % e # Tool certificate must validate against trusted roots try: tool_gid.verify_chain(trusted_roots) - except Exception, e: + except Exception as e: return False, None, \ "Tool cert not trusted: %s" % e diff --git a/sfa/util/method.py b/sfa/util/method.py index 4e211703..1d3de575 100644 --- a/sfa/util/method.py +++ b/sfa/util/method.py @@ -203,7 +203,7 @@ class Method: try: self.type_check(name, value, item, args) return - except SfaInvalidArgument, fault: + except SfaInvalidArgument as fault: pass raise fault diff --git a/sfatables/commands/moo.py b/sfatables/commands/moo.py index bd19a9d5..a8828540 100644 --- a/sfatables/commands/moo.py +++ b/sfatables/commands/moo.py @@ -122,7 +122,7 @@ class Command: try: self.type_check(name, value, item, args) return - except SfaInvalidArgument, fault: + except SfaInvalidArgument as fault: pass raise fault