Skip to content

Commit 8d24302

Browse files
qinz0822andyhhp
authored andcommitted
Update 'except' syntax
Signed-off-by: Qin Zhang (张琴) <[email protected]> Acked-by: Andrew Cooper <[email protected]>
1 parent f4f99ed commit 8d24302

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+132
-132
lines changed

XSConsole.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main():
3535
app.Build( ['plugins-base', 'plugins-oem', 'plugins-extras'] )
3636
try:
3737
app.Enter()
38-
except Exception, e:
38+
except Exception as e:
3939
# it may be that the screen size has changed
4040
app.AssertScreenSize()
4141
# if we get here then it was some other problem
@@ -44,7 +44,7 @@ def main():
4444
if __name__ == "__main__":
4545
try:
4646
main()
47-
except Exception, e:
47+
except Exception as e:
4848
# Add backtrace to log
4949
try:
5050
trace = traceback.format_tb(sys.exc_info()[2])

XSConsoleAuth.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def PAMConv(inAuth, inQueryList, *theRest):
128128
auth.authenticate()
129129
auth.acct_mgmt()
130130
# No exception implies a successful login
131-
except Exception, e:
131+
except Exception as e:
132132
# Display a generic message for all failures
133133
raise Exception(Lang("The system could not log you in. Please check your access credentials and try again."))
134134

@@ -188,7 +188,7 @@ def OpenSession(self):
188188
session = None
189189
self.masterConnectionBroken = True
190190
self.error = 'The master connection has timed out.'
191-
except Exception, e:
191+
except Exception as e:
192192
session = None
193193
self.error = e
194194

@@ -198,15 +198,15 @@ def OpenSession(self):
198198
try:
199199
session.login_with_password('root', self.defaultPassword,'','XSConsole')
200200

201-
except XenAPI.Failure, e:
201+
except XenAPI.Failure as e:
202202
if e.details[0] != 'HOST_IS_SLAVE': # Ignore slave errors when testing
203203
session = None
204204
self.error = e
205205
except socket.timeout:
206206
session = None
207207
self.masterConnectionBroken = True
208208
self.error = 'The master connection has timed out.'
209-
except Exception, e:
209+
except Exception as e:
210210
session = None
211211
self.error = e
212212
return session
@@ -218,7 +218,7 @@ def CloseSession(self, inSession):
218218
if inSession._session is not None:
219219
try:
220220
inSession.logout()
221-
except XenAPI.Failure, e:
221+
except XenAPI.Failure as e:
222222
XSLog('XAPI Failed to logout exception was ', e)
223223
return None
224224

@@ -241,7 +241,7 @@ def ChangePassword(self, inOldPassword, inNewPassword):
241241
if self.IsPasswordSet():
242242
try:
243243
self.PAMAuthenticate('root', inOldPassword)
244-
except Exception, e:
244+
except Exception as e:
245245
raise Exception(Lang('Old password not accepted. Please check your access credentials and try again.'))
246246
self.AssertAuthenticated()
247247

@@ -252,7 +252,7 @@ def ChangePassword(self, inOldPassword, inNewPassword):
252252
session.xenapi.session.change_password(inOldPassword, inNewPassword)
253253
finally:
254254
self.CloseSession(session)
255-
except Exception, e:
255+
except Exception as e:
256256
ShellPipe("/usr/bin/passwd", "--stdin", "root").Call(inNewPassword)
257257
raise Exception(Lang("The underlying Xen API xapi could not be used. Password changed successfully on this host only."))
258258

XSConsoleCurses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def ClippedAddStr(self, inString, inX, inY, inColour): # Internal use
180180
self.win.addstr(inY, xPos, len(clippedStr)*' ', CursesPalette.ColourAttr(FirstValue(inColour, self.defaultColour)))
181181
self.win.refresh()
182182
self.win.addstr(inY, xPos, encodedStr, CursesPalette.ColourAttr(FirstValue(inColour, self.defaultColour)))
183-
except Exception, e:
183+
except Exception as e:
184184
if xPos + len(inString) == self.xSize and inY + 1 == self.ySize:
185185
# Curses incorrectly raises an exception when writing the bottom right
186186
# character in a window, but still completes the write, so ignore it

XSConsoleData.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def Update(self):
164164
try:
165165
try:
166166
thisHost = self.session.xenapi.session.get_this_host(self.session._session)
167-
except XenAPI.Failure, e:
167+
except XenAPI.Failure as e:
168168
XSLog('Data update connection failed - retrying. Exception was:', e)
169169
self.session = Auth.Inst().CloseSession(self.session)
170170
self.RequireSession()
@@ -203,7 +203,7 @@ def convertPIF(inPIF):
203203

204204
try:
205205
retVal['network'] = self.session.xenapi.network.get_record(retVal['network'])
206-
except XenAPI.Failure, e:
206+
except XenAPI.Failure as e:
207207
XSLogError('Missing network record: ', e)
208208

209209
retVal['opaqueref'] = inPIF
@@ -306,7 +306,7 @@ def update_SR_reference(inPool, retPool, key):
306306

307307
except socket.timeout:
308308
self.session = None
309-
except Exception, e:
309+
except Exception as e:
310310
XSLogError('Data update failed: ', e)
311311

312312
try:
@@ -326,7 +326,7 @@ def update_SR_reference(inPool, retPool, key):
326326

327327
self.data['sr'].append(values)
328328

329-
except Exception, e:
329+
except Exception as e:
330330
XSLogError('SR data update failed: ', e)
331331

332332
self.UpdateFromResolveConf()
@@ -1046,7 +1046,7 @@ def PurgeVBDs(self):
10461046
if vbd['currently_attached']:
10471047
self.UnplugVBD(vbd)
10481048
self.DestroyVBD(vbd)
1049-
except Exception, e:
1049+
except Exception as e:
10501050
XSLogError('VBD purge failed', e)
10511051

10521052
def IsXAPIRunning(self):

XSConsoleDataUtils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def SizeString(cls, inSizeOrFilename, inDefault = None):
130130
else:
131131
retVal = str(int(fileSize))
132132

133-
except Exception, e:
133+
except Exception as e:
134134
retVal = FirstValue(inDefault, '')
135135

136136
return retVal
@@ -164,7 +164,7 @@ def USBFormat(self, inVDI):
164164
try:
165165
popenObj.wait() # Must wait for completion before mkfs
166166
break
167-
except IOError, e:
167+
except IOError as e:
168168
if e.errno != errno.EINTR: # Loop if EINTR
169169
raise
170170

@@ -241,17 +241,17 @@ def __init__(self, inVDI, inMode = None):
241241
if status != 0:
242242
try:
243243
self.Unmount()
244-
except Exception, e:
244+
except Exception as e:
245245
XSLogFailure('Device failed to unmount', e)
246246
output += '\n'+self.mountDev
247247
self.HandleMountFailure(output.split("\n"))
248248

249249
self.mountedVBD = True
250250

251-
except Exception, e:
251+
except Exception as e:
252252
try:
253253
self.Unmount()
254-
except Exception, e:
254+
except Exception as e:
255255
# Report the original exception, not this one
256256
XSLogFailure('Device failed to unmount', e)
257257
raise e
@@ -324,7 +324,7 @@ def Unmount(self):
324324
time.sleep(5)
325325
try:
326326
self.vbd = Data.Inst().UnplugVBD(self.vbd)
327-
except Exception, e:
327+
except Exception as e:
328328
XSLogFailure('Device failed to unmount', e)
329329

330330
self.pluggedVBD = False
@@ -364,17 +364,17 @@ def __init__(self, inVDI, inMode = None):
364364
if status != 0:
365365
try:
366366
self.Unmount()
367-
except Exception, e:
367+
except Exception as e:
368368
XSLogFailure('Device failed to unmount', e)
369369
output += '\n'+self.mountDev
370370
self.HandleMountFailure(status, output.split("\n"))
371371

372372
self.mountedVDI = True
373373
XSLog('Mounted '+self.mountDev + ' on ' + self.mountPoint + ' mode ' + self.mode)
374-
except Exception, e:
374+
except Exception as e:
375375
try:
376376
self.Unmount()
377-
except Exception, e:
377+
except Exception as e:
378378
XSLogFailure('Device failed to unmount', e)
379379
raise e
380380

XSConsoleDialogueBases.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def HandleKey(self, inKey):
204204
else:
205205
Layout.Inst().PushDialogue(InfoDialogue( Lang('Login Successful')))
206206

207-
except Exception, e:
207+
except Exception as e:
208208
Layout.Inst().PushDialogue(InfoDialogue( Lang('Login Failed: ')+Lang(e)))
209209

210210
Data.Inst().Update()
@@ -401,7 +401,7 @@ def HandleKeyUSBNOTFORMATTED(self, inKey):
401401
try:
402402
FileUtils.USBFormat(self.vdi)
403403
self.HandleDevice()
404-
except Exception, e:
404+
except Exception as e:
405405
Layout.Inst().PushDialogue(InfoDialogue( Lang("Formatting Failed"), Lang(e)))
406406

407407
handled = True
@@ -425,7 +425,7 @@ def HandleKeyCUSTOM(self, inKey):
425425
FileUtils.AssertSafeLeafname(inputValues['filename'])
426426
self.filename = inputValues['filename']
427427
self.ChangeState('CONFIRM')
428-
except Exception, e:
428+
except Exception as e:
429429
Layout.Inst().PopDialogue()
430430
Layout.Inst().PushDialogue(InfoDialogue(Lang(e)))
431431
elif pane.CurrentInput().HandleKey(inKey):
@@ -477,7 +477,7 @@ def HandleDevice(self):
477477
except USBNotMountable:
478478
Layout.Inst().PopDialogue()
479479
self.ChangeState('USBNOTMOUNTABLE')
480-
except Exception, e:
480+
except Exception as e:
481481
try:
482482
self.PreExitActions()
483483
except Exception:
@@ -542,7 +542,7 @@ def HandleKey(self, inKey):
542542
Layout.Inst().DoUpdate()
543543
title, info = self.HandleCommit(self.Pane().GetFieldValues())
544544
Layout.Inst().PushDialogue(InfoDialogue( title, info))
545-
except Exception, e:
545+
except Exception as e:
546546
Layout.Inst().PushDialogue(InfoDialogue( Lang('Failed: ')+Lang(e)))
547547
elif inKey == 'KEY_TAB':
548548
pane.ActivateNextInput()
@@ -651,7 +651,7 @@ def UpdateFieldsINITIAL(self):
651651
durationSecs = self.task.DurationSecs()
652652
elapsedStr = TimeUtils.DurationString(durationSecs)
653653

654-
except Exception, e:
654+
except Exception as e:
655655
progressStr = Lang('<Unavailable>')
656656
elapsedStr = Lang('<Unavailable>')
657657

@@ -677,7 +677,7 @@ def UpdateFieldsCANCEL(self):
677677
durationSecs = self.task.DurationSecs()
678678
elapsedStr = TimeUtils.DurationString(durationSecs)
679679

680-
except Exception, e:
680+
except Exception as e:
681681
progressStr = Lang('<Unavailable>')
682682
elapsedStr = Lang('<Unavailable>')
683683

@@ -702,7 +702,7 @@ def UpdateFieldsCOMPLETE(self):
702702
durationSecs = self.task.DurationSecs()
703703
elapsedStr = TimeUtils.DurationString(durationSecs)
704704

705-
except Exception, e:
705+
except Exception as e:
706706
elapsedStr = Lang(e)
707707

708708
pane.AddWrappedTextField(Lang('Time', 16) + elapsedStr)

XSConsoleHotData.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def GetData(self, inNames, inDefault, inRefs):
196196
raise Exception("List index "+str(currentRef)+" out of range in '"+'.'.join(inNames)+"'")
197197
itemRef = itemRef[currentRef]
198198
return itemRef
199-
except Exception, e:
199+
except Exception as e:
200200
# Data not present/fetchable, so return the default value
201201
return FirstValue(inDefault, None)
202202

XSConsoleImporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def ImportAbsDir(cls, inDir):
4747
# Import using variable as module name
4848
(fileObj, pathName, description) = imp.find_module(importName, [root])
4949
imp.load_module(importName, fileObj, pathName, description)
50-
except Exception, e:
50+
except Exception as e:
5151
try: XSLogError(*traceback.format_tb(sys.exc_info()[2]))
5252
except: pass
5353
try: XSLogError("*** PlugIn '"+importName+"' failed to load: "+str(e))

XSConsoleMetrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def LocalHostMetrics(self):
5151

5252
try:
5353
retVal['memory_total'] = float(self.data[hostPrefix +':memory_total_kib']) * 1024.0
54-
except Exception, e:
54+
except Exception as e:
5555
retVal['memory_total'] = None
5656

5757
try:
5858
retVal['memory_free'] = float(self.data[hostPrefix +':memory_free_kib']) * 1024.0
59-
except Exception, e:
59+
except Exception as e:
6060
retVal['memory_free'] = None
6161

6262
return retVal
@@ -76,12 +76,12 @@ def VMMetrics(self, inUUID):
7676

7777
try:
7878
retVal['memory_total'] = float(self.data[vmPrefix +':memory']) # Not scaled
79-
except Exception, e:
79+
except Exception as e:
8080
retVal['memory_total'] = None
8181

8282
try:
8383
retVal['memory_free'] = float(self.data[vmPrefix +':memory_internal_free']) * 1024.0 # Value is in kiB
84-
except Exception, e:
84+
except Exception as e:
8585
retVal['memory_free'] = None
8686

8787
return retVal

XSConsoleRemoteTest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def ErrorString(self, inException = None):
108108
for i, pane in enumerate(snapshot):
109109
for line in pane:
110110
retVal += 'Pane '+str(i) + ':' + line + '\n'
111-
except Exception, e:
111+
except Exception as e:
112112
retVal += 'Failed: '+Lang(e)
113113
if len(self.errors) > 0:
114114
retVal += "\n\nExceptions process by Lang()\n\n" + "\n".join(self.errors)
@@ -121,14 +121,14 @@ def ErrorString(self, inException = None):
121121
def WrapProcedure(self, inProc): # Any return value of inProc is discarded
122122
try:
123123
inProc()
124-
except Exception, e:
124+
except Exception as e:
125125
raise xmlrpclib.Fault(1, self.ErrorString(e))
126126
return None
127127

128128
def WrapFunction(self, inFunc): # inFunc returns a value
129129
try:
130130
retVal = inFunc()
131-
except Exception, e:
131+
except Exception as e:
132132
raise xmlrpclib.Fault(1, self.ErrorString(e))
133133
return retVal
134134

XSConsoleRootDialogue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def UpdateFields(self):
6767
else:
6868
raise Exception(Lang("Missing status handler"))
6969

70-
except Exception, e:
70+
except Exception as e:
7171
statusPane.ResetFields()
7272
statusPane.ResetPosition()
7373
statusPane.AddTitleField(Lang("Information not available"))

XSConsoleState.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def Inst(cls):
5959
# Version mismatch - don't use the state information
6060
cls.instance = None
6161
XSLog('State file version mismatch - discarding')
62-
except Exception, e:
62+
except Exception as e:
6363
cls.instance = None
6464

6565
if cls.instance is None:
@@ -144,7 +144,7 @@ def SaveIfRequired(self):
144144
pickler.dump(self)
145145
saveFile.close()
146146
XSLog('Saved state file')
147-
except Exception, e:
147+
except Exception as e:
148148
XSLogFailure('Failed to save state file', e)
149149

150150

0 commit comments

Comments
 (0)