Selaa lähdekoodia

Remove exception indexing

Mike Naberezny 11 vuotta sitten
vanhempi
commit
4450eee055

+ 1 - 1
supervisor/dispatchers.py

@@ -480,7 +480,7 @@ class PInputDispatcher(PDispatcher):
             try:
                 self.flush()
             except OSError, why:
-                if why[0] == errno.EPIPE:
+                if why.args[0] == errno.EPIPE:
                     self.input_buffer = ''
                     self.close()
                 else:

+ 1 - 1
supervisor/http.py

@@ -604,7 +604,7 @@ class supervisor_af_unix_http_server(supervisor_http_server):
                     try:
                         os.chown(socketname, sockchown[0], sockchown[1])
                     except OSError, why:
-                        if why[0] == errno.EPERM:
+                        if why.args[0] == errno.EPERM:
                             msg = ('Not permitted to chown %s to uid/gid %s; '
                                    'adjust "sockchown" value in config file or '
                                    'on command line to values that the '

+ 4 - 4
supervisor/loggers.py

@@ -64,7 +64,7 @@ class Handler:
             self.stream.flush()
         except IOError, why:
             # if supervisor output is piped, EPIPE can be raised at exit
-            if why[0] != errno.EPIPE:
+            if why.args[0] != errno.EPIPE:
                 raise
 
     def close(self):
@@ -107,7 +107,7 @@ class FileHandler(Handler):
         try:
             os.remove(self.baseFilename)
         except OSError, why:
-            if why[0] != errno.ENOENT:
+            if why.args[0] != errno.ENOENT:
                 raise
 
 class StreamHandler(Handler):
@@ -206,7 +206,7 @@ class RotatingFileHandler(FileHandler):
                             os.remove(dfn)
                         except OSError, why:
                             # catch race condition (already deleted)
-                            if why[0] != errno.ENOENT:
+                            if why.args[0] != errno.ENOENT:
                                 raise
                     os.rename(sfn, dfn)
             dfn = self.baseFilename + ".1"
@@ -215,7 +215,7 @@ class RotatingFileHandler(FileHandler):
                     os.remove(dfn)
                 except OSError, why:
                     # catch race condition (already deleted)
-                    if why[0] != errno.ENOENT:
+                    if why.args[0] != errno.ENOENT:
                         raise
             os.rename(self.baseFilename, dfn)
         self.stream = open(self.baseFilename, 'w')

+ 2 - 2
supervisor/medusa/asynchat_25.py

@@ -86,7 +86,7 @@ class async_chat (asyncore.dispatcher):
 
         try:
             data = self.recv (self.ac_in_buffer_size)
-        except socket.error, why:
+        except socket.error:
             self.handle_error()
             return
 
@@ -219,7 +219,7 @@ class async_chat (asyncore.dispatcher):
                 if num_sent:
                     self.ac_out_buffer = self.ac_out_buffer[num_sent:]
 
-            except socket.error, why:
+            except socket.error:
                 self.handle_error()
                 return
 

+ 5 - 5
supervisor/medusa/asyncore_25.py

@@ -120,7 +120,7 @@ def poll(timeout=0.0, map=None):
             try:
                 r, w, e = select.select(r, w, e, timeout)
             except select.error, err:
-                if err[0] != EINTR:
+                if err.args[0] != EINTR:
                     raise
                 else:
                     return
@@ -166,7 +166,7 @@ def poll2(timeout=0.0, map=None):
         try:
             r = pollster.poll(timeout)
         except select.error, err:
-            if err[0] != EINTR:
+            if err.args[0] != EINTR:
                 raise
             r = []
         for fd, flags in r:
@@ -321,7 +321,7 @@ class dispatcher:
             conn, addr = self.socket.accept()
             return conn, addr
         except socket.error, why:
-            if why[0] == EWOULDBLOCK:
+            if why.args[0] == EWOULDBLOCK:
                 pass
             else:
                 raise
@@ -331,7 +331,7 @@ class dispatcher:
             result = self.socket.send(data)
             return result
         except socket.error, why:
-            if why[0] == EWOULDBLOCK:
+            if why.args[0] == EWOULDBLOCK:
                 return 0
             else:
                 raise
@@ -349,7 +349,7 @@ class dispatcher:
                 return data
         except socket.error, why:
             # winsock sometimes throws ENOTCONN
-            if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
+            if why.args[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
                 self.handle_close()
                 return ''
             else:

+ 1 - 1
supervisor/medusa/demo/winFTPserver.py

@@ -28,7 +28,7 @@ class Win32Authorizer:
                                                     win32con.LOGON32_LOGON_INTERACTIVE,
                                                     win32con.LOGON32_PROVIDER_DEFAULT )
         except pywintypes.error, ErrorMsg:
-            return 0, ErrorMsg[ 2 ], None
+            return 0, ErrorMsg.args[2], None
 
         userInfo = win32net.NetUserGetInfo( None, userName, 1 )
 

+ 2 - 2
supervisor/medusa/ftp_server.py

@@ -283,7 +283,7 @@ class ftp_channel (asynchat.async_chat):
                 cdc.bind (('', self.server.port - 1))
             try:
                 cdc.connect ((ip, port))
-            except socket.error, why:
+            except socket.error:
                 self.respond ("425 Can't build data connection")
         self.client_dc = cdc
 
@@ -310,7 +310,7 @@ class ftp_channel (asynchat.async_chat):
             cdc.create_socket (socket.AF_INET, socket.SOCK_STREAM)
             try:
                 cdc.connect ((ip, port))
-            except socket.error, why:
+            except socket.error:
                 self.respond ("425 Can't build data connection")
         self.client_dc = cdc
 

+ 1 - 1
supervisor/medusa/monitor.py

@@ -110,7 +110,7 @@ class monitor_channel (asynchat.async_chat):
                         else:
                             co = compile (line, repr(self), 'exec')
                     except SyntaxError, why:
-                        if why[0] == 'unexpected EOF while parsing':
+                        if why.args[0] == 'unexpected EOF while parsing':
                             self.push ('... ')
                             self.multi_line.append (line)
                             return

+ 7 - 7
supervisor/options.py

@@ -1105,22 +1105,22 @@ class ServerOptions(Options):
         try:
             self.httpservers = self.make_http_servers(supervisord)
         except socket.error, why:
-            if why[0] == errno.EADDRINUSE:
+            if why.args[0] == errno.EADDRINUSE:
                 self.usage('Another program is already listening on '
                            'a port that one of our HTTP servers is '
                            'configured to use.  Shut this program '
                            'down first before starting supervisord.')
             else:
                 help = 'Cannot open an HTTP server: socket.error reported'
-                errorname = errno.errorcode.get(why[0])
+                errorname = errno.errorcode.get(why.args[0])
                 if errorname is None:
-                    self.usage('%s %s' % (help, why[0]))
+                    self.usage('%s %s' % (help, why.args[0]))
                 else:
                     self.usage('%s errno.%s (%d)' %
-                               (help, errorname, why[0]))
+                               (help, errorname, why.args[0]))
             self.unlink_socketfiles = False
         except ValueError, why:
-            self.usage(why[0])
+            self.usage(why.args[0])
 
     def get_autochildlog_name(self, name, identifier, channel):
         prefix='%s-%s---%s-' % (name, channel, identifier)
@@ -1238,7 +1238,7 @@ class ServerOptions(Options):
         try:
             pid, sts = os.waitpid(-1, os.WNOHANG)
         except OSError, why:
-            err = why[0]
+            err = why.args[0]
             if err not in (errno.ECHILD, errno.EINTR):
                 self.logger.critical(
                     'waitpid error; a process may not be cleaned up properly')
@@ -1412,7 +1412,7 @@ class ServerOptions(Options):
         try:
             data = os.read(fd, 2 << 16) # 128K
         except OSError, why:
-            if why[0] not in (errno.EWOULDBLOCK, errno.EBADF, errno.EINTR):
+            if why.args[0] not in (errno.EWOULDBLOCK, errno.EBADF, errno.EINTR):
                 raise
             data = ''
         return data

+ 5 - 5
supervisor/process.py

@@ -218,7 +218,7 @@ class Subprocess:
         try:
             self.dispatchers, self.pipes = self.config.make_dispatchers(self)
         except OSError, why:
-            code = why[0]
+            code = why.args[0]
             if code == errno.EMFILE:
                 # too many file descriptors open
                 msg = 'too many open files to spawn %r' % self.config.name
@@ -232,7 +232,7 @@ class Subprocess:
         try:
             pid = options.fork()
         except OSError, why:
-            code = why[0]
+            code = why.args[0]
             if code == errno.EAGAIN:
                 # process table full
                 msg  = ('Too many processes in process table to spawn %r' %
@@ -319,7 +319,7 @@ class Subprocess:
                 if cwd is not None:
                     options.chdir(cwd)
             except OSError, why:
-                code = errno.errorcode.get(why[0], why[0])
+                code = errno.errorcode.get(why.args[0], why.args[0])
                 msg = "couldn't chdir to %s: %s\n" % (cwd, code)
                 options.write(2, "supervisor: " + msg)
                 return # finally clause will exit the child process
@@ -330,7 +330,7 @@ class Subprocess:
                     options.setumask(self.config.umask)
                 options.execve(filename, argv, env)
             except OSError, why:
-                code = errno.errorcode.get(why[0], why[0])
+                code = errno.errorcode.get(why.args[0], why.args[0])
                 msg = "couldn't exec %s: %s\n" % (argv[0], code)
                 options.write(2, "supervisor: " + msg)
             except:
@@ -808,7 +808,7 @@ class EventListenerPool(ProcessGroupBase):
                                                    pool_serial, payload)
                     process.write(envelope)
                 except OSError, why:
-                    if why[0] != errno.EPIPE:
+                    if why.args[0] != errno.EPIPE:
                         raise
                     continue
 

+ 1 - 1
supervisor/rpcinterface.py

@@ -743,7 +743,7 @@ class SupervisorNamespaceRPCInterface:
         try:
             process.write(chars)
         except OSError, why:
-            if why[0] == errno.EPIPE:
+            if why.args[0] == errno.EPIPE:
                 raise RPCError(Faults.NO_FILE, name)
             else:
                 raise

+ 16 - 16
supervisor/supervisorctl.py

@@ -9,7 +9,7 @@ Options:
 -h/--help -- print usage message and exit
 -i/--interactive -- start an interactive shell after executing commands
 -s/--serverurl URL -- URL on which supervisord server is listening
-     (default "http://localhost:9001").  
+     (default "http://localhost:9001").
 -u/--username -- username to use for authentication with server
 -p/--password -- password to use for authentication with server
 -r/--history-file -- keep a readline history (if readline is available)
@@ -43,7 +43,7 @@ class fgthread(threading.Thread):
     To be used for foreground output/error streaming.
     http://mail.python.org/pipermail/python-list/2004-May/260937.html
     """
-  
+
     def __init__(self, program, ctl):
         threading.Thread.__init__(self)
         import http_client
@@ -159,7 +159,7 @@ class Controller(cmd.Cmd):
                 do_func(arg)
             except SystemExit:
                 raise
-            except Exception, e:
+            except Exception:
                 (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
                 error = 'error: %s, %s: file: %s line: %s' % (t, v, file, line)
                 self.output(error)
@@ -181,7 +181,7 @@ class Controller(cmd.Cmd):
             if isinstance(stuff, unicode):
                 stuff = stuff.encode('utf-8')
             self.stdout.write(stuff + '\n')
-    
+
     def get_supervisor(self):
         return self.get_server_proxy('supervisor')
 
@@ -212,12 +212,12 @@ class Controller(cmd.Cmd):
                     '[rpcinterface:supervisor] section is enabled in the '
                     'configuration file (see sample.conf).')
                 return False
-            raise 
+            raise
         except socket.error, why:
-            if why[0] == errno.ECONNREFUSED:
+            if why.args[0] == errno.ECONNREFUSED:
                 self.output('%s refused connection' % self.options.serverurl)
                 return False
-            elif why[0] == errno.ENOENT:
+            elif why.args[0] == errno.ENOENT:
                 self.output('%s no such file' % self.options.serverurl)
                 return False
             raise
@@ -405,7 +405,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
     def do_tail(self, arg):
         if not self.ctl.upcheck():
             return
-        
+
         args = arg.strip().split()
 
         if len(args) < 1:
@@ -489,7 +489,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
     def do_maintail(self, arg):
         if not self.ctl.upcheck():
             return
-        
+
         args = arg.strip().split()
 
         if len(args) > 1:
@@ -513,7 +513,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             else:
                 self.ctl.output('Error: bad argument %s' % args[0])
                 return
-            
+
         else:
             bytes = 1600
 
@@ -556,14 +556,14 @@ class DefaultControllerPlugin(ControllerPluginBase):
             name = info['name']
         else:
             name = '%s:%s' % (info['group'], info['name'])
-                    
+
         return template % {'name':name, 'state':info['statename'],
                            'desc':info['description']}
 
     def do_status(self, arg):
         if not self.ctl.upcheck():
             return
-        
+
         supervisor = self.ctl.get_supervisor()
 
         names = arg.strip().split()
@@ -614,7 +614,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
                 self.ctl.output(str(info['pid']))
 
     def help_pid(self):
-        self.ctl.output("pid\t\t\tGet the PID of supervisord.")    
+        self.ctl.output("pid\t\t\tGet the PID of supervisord.")
         self.ctl.output("pid <name>\t\tGet the PID of a single "
             "child process by name.")
         self.ctl.output("pid all\t\t\tGet the PID of every child "
@@ -658,7 +658,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             for result in results:
                 result = self._startresult(result)
                 self.ctl.output(result)
-                
+
         else:
             for name in names:
                 group_name, process_name = split_namespec(name)
@@ -785,10 +785,10 @@ class DefaultControllerPlugin(ControllerPluginBase):
                 else:
                     raise
             except socket.error, e:
-                if e[0] == errno.ECONNREFUSED:
+                if e.args[0] == errno.ECONNREFUSED:
                     msg = 'ERROR: %s refused connection (already shut down?)'
                     self.ctl.output(msg % self.ctl.options.serverurl)
-                elif e[0] == errno.ENOENT:
+                elif e.args[0] == errno.ENOENT:
                     msg = 'ERROR: %s no such file (already shut down?)'
                     self.ctl.output(msg % self.ctl.options.serverurl)
                 else:

+ 1 - 1
supervisor/supervisord.py

@@ -218,7 +218,7 @@ class Supervisor:
                 r, w, x = self.options.select(r, w, x, timeout)
             except select.error, err:
                 r = w = x = []
-                if err[0] == errno.EINTR:
+                if err.args[0] == errno.EINTR:
                     self.options.logger.blather('EINTR encountered in select')
                 else:
                     raise

+ 1 - 1
supervisor/tests/test_process.py

@@ -613,7 +613,7 @@ class SubprocessTests(unittest.TestCase):
                     data = os.popen('ps').read()
                     break
                 except IOError, why:
-                    if why[0] != errno.EINTR:
+                    if why.args[0] != errno.EINTR:
                         raise
                         # try again ;-)
             time.sleep(0.1) # arbitrary, race condition possible