Skip to content

Commit 0f58dbd

Browse files
committed
Fix Python 3 compatability issues.
New raise syntax.
1 parent 8eb9065 commit 0f58dbd

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

nut2.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def __connect( self ) :
102102
self._srv_handler.write( "USERNAME %s\n" % self.__login )
103103
result = self._srv_handler.read_until( "\n", self.__timeout )
104104
if result[:2] != "OK" :
105-
raise Exception, result.replace( "\n", "" )
105+
raise Exception(result.replace( "\n", "" ))
106106

107107
if self.__password != None :
108108
self._srv_handler.write( "PASSWORD %s\n" % self.__password )
109109
result = self._srv_handler.read_until( "\n", self.__timeout )
110110
if result[:2] != "OK" :
111-
raise Exception, result.replace( "\n", "" )
111+
raise Exception(result.replace( "\n", "" ))
112112

113113
def GetUPSList( self ) :
114114
""" Returns the list of available UPS from the NUT server
@@ -121,7 +121,7 @@ def GetUPSList( self ) :
121121
self._srv_handler.write( "LIST UPS\n" )
122122
result = self._srv_handler.read_until( "\n" )
123123
if result != "BEGIN LIST UPS\n" :
124-
raise Exception, result.replace( "\n", "" )
124+
raise Exception(result.replace( "\n", "" ))
125125

126126
result = self._srv_handler.read_until( "END LIST UPS\n" )
127127
ups_list = {}
@@ -145,7 +145,7 @@ def GetUPSVars( self, ups="" ) :
145145
self._srv_handler.write( "LIST VAR %s\n" % ups )
146146
result = self._srv_handler.read_until( "\n" )
147147
if result != "BEGIN LIST VAR %s\n" % ups :
148-
raise Exception, result.replace( "\n", "" )
148+
raise Exception(result.replace( "\n", "" ))
149149

150150
ups_vars = {}
151151
result = self._srv_handler.read_until( "END LIST VAR %s\n" % ups )
@@ -171,7 +171,7 @@ def GetUPSCommands( self, ups="" ) :
171171
self._srv_handler.write( "LIST CMD %s\n" % ups )
172172
result = self._srv_handler.read_until( "\n" )
173173
if result != "BEGIN LIST CMD %s\n" % ups :
174-
raise Exception, result.replace( "\n", "" )
174+
raise Exception(result.replace( "\n", "" ))
175175

176176
ups_cmds = {}
177177
result = self._srv_handler.read_until( "END LIST CMD %s\n" % ups )
@@ -208,7 +208,7 @@ def GetRWVars( self, ups="" ) :
208208
self._srv_handler.write( "LIST RW %s\n" % ups )
209209
result = self._srv_handler.read_until( "\n" )
210210
if ( result != "BEGIN LIST RW %s\n" % ups ) :
211-
raise Exception, result.replace( "\n", "" )
211+
raise Exception( result.replace( "\n", "" ))
212212

213213
result = self._srv_handler.read_until( "END LIST RW %s\n" % ups )
214214
offset = len( "VAR %s" % ups )
@@ -238,7 +238,7 @@ def SetRWVar( self, ups="", var="", value="" ):
238238
if ( result == "OK\n" ) :
239239
return( "OK" )
240240
else :
241-
raise Exception, result
241+
raise Exception(result)
242242

243243
def RunUPSCommand( self, ups="", command="" ) :
244244
""" Send a command to the specified UPS
@@ -254,7 +254,7 @@ def RunUPSCommand( self, ups="", command="" ) :
254254
if ( result == "OK\n" ) :
255255
return( "OK" )
256256
else :
257-
raise Exception, result.replace( "\n", "" )
257+
raise Exception(result.replace( "\n", "" ))
258258

259259
def FSD( self, ups="") :
260260
""" Send FSD command
@@ -268,7 +268,7 @@ def FSD( self, ups="") :
268268
self._srv_handler.write( "MASTER %s\n" % ups )
269269
result = self._srv_handler.read_until( "\n" )
270270
if ( result != "OK MASTER-GRANTED\n" ) :
271-
raise Exception, ( "Master level function are not available", "" )
271+
raise Exception(( "Master level function are not available", "" ))
272272

273273
if self.__debug :
274274
print( "[DEBUG] FSD called..." )
@@ -277,7 +277,7 @@ def FSD( self, ups="") :
277277
if ( result == "OK FSD-SET\n" ) :
278278
return( "OK" )
279279
else :
280-
raise Exception, result.replace( "\n", "" )
280+
raise Exception(result.replace( "\n", "" ))
281281

282282
def help(self) :
283283
""" Send HELP command
@@ -308,15 +308,15 @@ def ListClients( self, ups = None ) :
308308
print( "[DEBUG] ListClients from server" )
309309

310310
if ups and (ups not in self.GetUPSList()):
311-
raise Exception, "%s is not a valid UPS" % ups
311+
raise Exception("%s is not a valid UPS" % ups)
312312

313313
if ups:
314314
self._srv_handler.write( "LIST CLIENTS %s\n" % ups)
315315
else:
316316
self._srv_handler.write( "LIST CLIENTS\n" )
317317
result = self._srv_handler.read_until( "\n" )
318318
if result != "BEGIN LIST CLIENTS\n" :
319-
raise Exception, result.replace( "\n", "" )
319+
raise Exception(result.replace( "\n", "" ))
320320

321321
result = self._srv_handler.read_until( "END LIST CLIENTS\n" )
322322
ups_list = {}

0 commit comments

Comments
 (0)