diff --git a/pyVim/connect.py b/pyVim/connect.py index 936742678..7a125f794 100644 --- a/pyVim/connect.py +++ b/pyVim/connect.py @@ -220,7 +220,7 @@ def Connect(host='localhost', port=443, user='root', pwd='', host = info.group(1)[1:-1] if info.group(2) is not None: port = int(info.group(2)[1:]) - except ValueError, ve: + except ValueError as ve: pass if namespace: @@ -249,7 +249,7 @@ def Disconnect(si): def GetLocalTicket(si, user): try: sessionManager = si.content.sessionManager - except Exception, e: + except Exception as e: if type(e).__name__ == 'ExpatError': msg = 'Malformed response while querying for local ticket: "%s"' % e raise vim.fault.HostConnectFault(msg=msg) @@ -305,7 +305,7 @@ def __Login(host, port, user, pwd, service, adapter, version, path, content = si.RetrieveContent() except vmodl.MethodFault: raise - except Exception, e: + except Exception as e: raise vim.fault.HostConnectFault(msg=str(e)) # Get a ticket if we're connecting to localhost and password is not specified @@ -321,7 +321,7 @@ def __Login(host, port, user, pwd, service, adapter, version, path, x = content.sessionManager.Login(user, pwd, None) except vim.fault.InvalidLogin: raise - except Exception, e: + except Exception as e: raise return si, stub @@ -337,7 +337,7 @@ def __Logout(si): if si: content = si.RetrieveContent() content.sessionManager.Logout() - except Exception, e: + except Exception as e: pass @@ -457,7 +457,7 @@ def __VersionIsSupported(desiredVersion, serviceVersionDescription): root = serviceVersionDescription if root.tag == 'namespaces': # serviceVersionDescription appears to be a vimServiceVersions.xml document - if root.get('version') <> '1.0': + if root.get('version') != '1.0': raise RuntimeError('vimServiceVersions.xml has version %s,' \ ' which is not understood' % (root.get('version'))) desiredVersionId = versionIdMap[desiredVersion] diff --git a/pyVmomi/DynamicTypeManagerHelper.py b/pyVmomi/DynamicTypeManagerHelper.py index 10ef64e5a..630cc865d 100644 --- a/pyVmomi/DynamicTypeManagerHelper.py +++ b/pyVmomi/DynamicTypeManagerHelper.py @@ -45,7 +45,7 @@ def GetTypeManager(self): if self.hostSystem: try: dynTypeMgr = self.hostSystem.RetrieveDynamicTypeManager() - except vmodl.fault.MethodNotFound, err: + except vmodl.fault.MethodNotFound as err: pass if not dynTypeMgr: @@ -139,7 +139,7 @@ def _CreateAllTypes(self, enumTypes, dataTypes, managedTypes): for typeInfo in infos: try: fn(*typeInfo) - except Exception, err: + except Exception as err: #Ignore errors due to duplicate importing pass diff --git a/pyVmomi/Iso8601.py b/pyVmomi/Iso8601.py index 8f0e2f7fe..951d1754b 100644 --- a/pyVmomi/Iso8601.py +++ b/pyVmomi/Iso8601.py @@ -176,7 +176,7 @@ def ParseISO8601(datetimeStr): datetimeVal = datetime(**dt) if delta: datetimeVal += delta - except Exception, e: + except Exception as e: pass return datetimeVal @@ -253,7 +253,7 @@ def ISO8601Format(dt): ]: dt = ParseISO8601(testStr) if dt == None: - print 'Failed to parse (%s)' % testStr + print('Failed to parse (%s)' % testStr) assert(False) # Make sure we can translate back @@ -262,16 +262,16 @@ def ISO8601Format(dt): if dt.tzinfo is None: dt = dt.replace(tzinfo=dt1.tzinfo) if dt1 != dt: - print 'ParseISO8601 -> ISO8601Format -> ParseISO8601 failed (%s)' % testStr + print('ParseISO8601 -> ISO8601Format -> ParseISO8601 failed (%s)' % testStr) assert(False) # Make sure we can parse python isoformat() dt2 = ParseISO8601(dt.isoformat()) if dt2 == None: - print 'ParseISO8601("%s".isoformat()) failed' % testStr + print('ParseISO8601("%s".isoformat()) failed' % testStr) assert(False) - print testStr, '->', dt, isoformat + print(testStr, '->', dt, isoformat) # Basic form for testStr in [ @@ -293,7 +293,7 @@ def ISO8601Format(dt): # Reject for now dt = ParseISO8601(testStr) if dt != None: - print 'ParseISO8601 (%s) should fail, but it did not' % testStr + print('ParseISO8601 (%s) should fail, but it did not' % testStr) assert(False) #print testStr, '->', dt #assert(dt != None) @@ -352,5 +352,5 @@ def ISO8601Format(dt): ]: dt = ParseISO8601(testStr) if dt != None: - print 'ParseISO8601 (%s) should fail, but it did not' % testStr + print('ParseISO8601 (%s) should fail, but it did not' % testStr) assert(False)