浏览代码

Remove old exception syntax

Mike Naberezny 11 年之前
父节点
当前提交
c155571c63

+ 4 - 4
supervisor/datatypes.py

@@ -92,7 +92,7 @@ def dict_of_key_value_pairs(arg):
     while i < tokens_len:
         k_eq_v = tokens[i:i+3]
         if len(k_eq_v) != 3 or k_eq_v[1] != '=':
-            raise ValueError, "Unexpected end of key/value pairs"
+            raise ValueError("Unexpected end of key/value pairs")
         D[k_eq_v[0]] = k_eq_v[2].strip('\'"')
         i += 4
     return D
@@ -285,7 +285,7 @@ def colon_separated_user_group(arg):
             gid = name_to_gid(parts[1])
         return (uid, gid)
     except:
-        raise ValueError, 'Invalid user:group definition %s' % arg
+        raise ValueError('Invalid user:group definition %s' % arg)
 
 def name_to_uid(name):
     """ Find a user ID from a string containing a user name or ID.
@@ -351,8 +351,8 @@ def existing_dirpath(v):
         return nv
     if os.path.isdir(dir):
         return nv
-    raise ValueError, ('The directory named as part of the path %s '
-                       'does not exist.' % v)
+    raise ValueError('The directory named as part of the path %s '
+                     'does not exist.' % v)
 
 def logging_level(value):
     s = str(value).lower()

+ 2 - 2
supervisor/medusa/asynchat_25.py

@@ -65,10 +65,10 @@ class async_chat (asyncore.dispatcher):
         asyncore.dispatcher.__init__ (self, conn)
 
     def collect_incoming_data(self, data):
-        raise NotImplementedError, "must be implemented in subclass"
+        raise NotImplementedError("must be implemented in subclass")
 
     def found_terminator(self):
-        raise NotImplementedError, "must be implemented in subclass"
+        raise NotImplementedError("must be implemented in subclass")
 
     def set_terminator (self, term):
         "Set the input delimiter.  Can be a fixed string of any length, an integer, or None"

+ 1 - 1
supervisor/medusa/asyncore_25.py

@@ -313,7 +313,7 @@ class dispatcher:
             self.connected = True
             self.handle_connect()
         else:
-            raise socket.error, (err, errorcode[err])
+            raise socket.error(err, errorcode[err])
 
     def accept(self):
         # XXX can return either an address pair or None

+ 19 - 19
supervisor/medusa/docs/programming.html

@@ -21,7 +21,7 @@
       CPU bound, then pre-emptive scheduled threads are probably what
       you really need.  Network servers are rarely CPU-bound, however.
     </p>
-      
+
     <p>
       If your operating system supports the <code>select()</code>
       system call in its I/O library (and nearly all do), then you can
@@ -34,7 +34,7 @@
       of building sophisticated high-performance network servers and
       clients a snap.
     </p>
-    
+
     <h3>Select-based multiplexing in the real world</h3>
 
     <p>
@@ -52,7 +52,7 @@
       An interesting web server comparison chart is available at the
       <a href="http://www.acme.com/software/thttpd/benchmarks.html">thttpd web site</a>
     <p>
-      
+
     <h3>Variations on a Theme: poll() and WaitForMultipleObjects</h3>
     <p>
       Of similar (but better) design is the <code>poll()</code> system
@@ -109,7 +109,7 @@
       also keeps the low-level interface as simple as possible -
       always a good thing in my book.
     </p>
-    
+
     <h3>The polling loop</h3>
     <p>
       Now that you know what <code>select()</code> does, you're ready
@@ -135,7 +135,7 @@ while (any_descriptors_left):
       the functions poll() and loop()).  Now, on to the magic that must
       take place to handle the events...
     </p>
-    
+
     <h2>The Code</h2>
     <h3>Blocking vs. Non-Blocking</h3>
     <p>
@@ -233,7 +233,7 @@ while (any_descriptors_left):
       demonstrates how easy it is to build a powerful tool in only a few
       lines of code.
     </p>
-    
+
 <pre>
 <font color="800000"># -*- Mode: Python; tab-width: 4 -*-</font>
 
@@ -265,7 +265,7 @@ while (any_descriptors_left):
     <font color="808000">for</font> url <font color="808000">in</font> sys.argv[1:]:
         parts = urlparse.urlparse (url)
         <font color="808000">if</font> parts[0] != <font color="008000">'http'</font>:
-            <font color="808000">raise</font> ValueError, <font color="008000">"HTTP URL's only, please"</font>
+            <font color="808000">raise</font> <font color="008000">ValueError("HTTP URL's only, please")</font>
         <font color="808000">else</font>:
             host = parts[1]
             path = parts[2]
@@ -300,7 +300,7 @@ while (any_descriptors_left):
     <p><font color="006000"><code>$ python asynhttp.py http://www.nightmare.com/</code></font>
     <p>You should see something like this:
     <p>
-      
+
 <pre>
 [rushing@gnome demo]$ python asynhttp.py http://www.nightmare.com/
 log: adding channel &lt;http_client  at 80ef3e8&gt;
@@ -347,7 +347,7 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
         print 'read', r
         print 'write', w
         [...]
-</pre>      
+</pre>
 
     <p>
       Each time through the loop you will see which channels have fired
@@ -390,14 +390,14 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
     <font color="808000">def</font><font color="000080"> handle_write</font> (self):
         sent = self.send (self.buffer)
         self.buffer = self.buffer[sent:]
-</pre>   
+</pre>
 
     <p>
       The <code>handle_connect</code> method no longer assumes it can
       send its request string successfully.  We move its work over to
       <code>handle_write</code>; which trims <code>self.buffer</code>
       as pieces of it are sent succesfully.
-      
+
     <p>
       We also introduce the <code>writable</code> method.  Each time
       through the loop, the set of sockets is scanned, the
@@ -413,7 +413,7 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
       If you try the client now (with the print statements in
       <code>asyncore.poll()</code>), you'll see that
       <code>select</code> is firing more efficiently.
-      
+
     <h3>asynchat.py</h3>
     <p>
       The dispatcher class is useful, but somewhat limited in
@@ -443,11 +443,11 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
 	<br>Called whenever data is available from
 	a socket.  Usually, your implementation will accumulate this
 	data into a buffer of some kind.
-      
+
       <li><code>found_terminator (self)</code>
 	<br>Called whenever an end-of-line marker has been seen.  Typically
 	your code will process and clear the input buffer.
-	
+
       <li><code>push (data)</code>
 	<br>This is a buffered version of <code>send</code>.  It will place
 	the data in an outgoing buffer.
@@ -460,7 +460,7 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
       <code>handle_read</code> collects data into an input buffer, which
       is continually scanned for the terminator string.  Data in between
       terminators is feed to your <code>collect_incoming_data</code> method.
-      
+
     <p>
       The implementation of <code>handle_write</code> and <code>writable</code>
       examine an outgoing-data queue, and automatically send data whenever
@@ -482,7 +482,7 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
 <font color="808000">import</font> string
 
 <font color="808000">class</font><font color="000080"> proxy_server</font> (asyncore.dispatcher):
-    
+
     <font color="808000">def</font><font color="000080"> __init__</font> (self, host, port):
         asyncore.dispatcher.__init__ (self)
         self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
@@ -538,7 +538,7 @@ log: closing channel 4:&lt;http_client connected at 80ef3e8&gt;
 
     <font color="808000">def</font><font color="000080"> collect_incoming_data</font> (self, data):
         self.buffer = self.buffer + data
-        
+
     <font color="808000">def</font><font color="000080"> found_terminator</font> (self):
         data = self.buffer
         self.buffer = <font color="008000">''</font>
@@ -595,7 +595,7 @@ python proxy.py localhost 25
       time for each command is long. You'd like to be able to send a
       bunch of <code>RCPT</code> commands in one batch, and then count
       off the responses to them as they come.
-      
+
     <p>
       I have a favorite visual when explaining the advantages of
       pipelining.  Imagine each request to the server is a boxcar on a
@@ -620,7 +620,7 @@ python proxy.py localhost 25
       interested in the gory details.
 
     <h3>Producers</h3>
-      
+
     <p>
       <code>async_chat</code> supports a sophisticated output
       buffering model, using a queue of data-producing objects.  For

+ 21 - 21
supervisor/medusa/http_server.py

@@ -64,11 +64,11 @@ class http_request:
                 'Server'        : 'Medusa/%s' % VERSION_STRING,
                 'Date'          : http_date.build_http_date (time.time())
                 }
-        
-        # New reply header list (to support multiple 
+
+        # New reply header list (to support multiple
         # headers with same name)
         self.__reply_header_list = []
-        
+
         self.request_number = http_request.request_counter.increment()
         self._split_uri = None
         self._header_cache = {}
@@ -104,11 +104,11 @@ class http_request:
     # but the big exception is the Set-Cookie header.
     # dictionary centric.
     #---------------------------------------------------
-    
+
     def add_header(self, name, value):
         """ Adds a header to the reply headers """
         self.__reply_header_list.append((name, value))
-    
+
     def clear_headers(self):
         """ Clears the reply header list """
 
@@ -116,19 +116,19 @@ class http_request:
         self.reply_headers.clear()
 
         self.__reply_header_list[:] = []
-    
+
     def remove_header(self, name, value=None):
         """ Removes the specified header.
-        If a value is provided, the name and 
-        value must match to remove the header.  
+        If a value is provided, the name and
+        value must match to remove the header.
         If the value is None, removes all headers
         with that name."""
 
         found_it = 0
-        
+
         # Remove things from the old dict as well
         if (self.reply_headers.has_key(name) and
-            (value is None or 
+            (value is None or
              self.reply_headers[name] == value)):
             del self.reply_headers[name]
             found_it = 1
@@ -152,7 +152,7 @@ class http_request:
                 search_value = "%s: %s" % (name, value)
 
             raise LookupError("Header '%s' not found" % search_value)
-        
+
         for h in removed_headers:
             self.__reply_header_list.remove(h)
 
@@ -161,9 +161,9 @@ class http_request:
         """ Get the tuple of headers that will be used
         for generating reply headers"""
         header_tuples = self.__reply_header_list[:]
-       
-        # The idea here is to insert the headers from 
-        # the old header dict into the new header list, 
+
+        # The idea here is to insert the headers from
+        # the old header dict into the new header list,
         # UNLESS there's already an entry in the list
         # that would have overwritten the dict entry
         # if the dict was the only storage...
@@ -176,24 +176,24 @@ class http_request:
         # headers in the dict that weren't in the list,
         # they should have been copied in.  If the name
         # was already in the list, we didn't copy it,
-        # because the value from the dict has been 
+        # because the value from the dict has been
         # 'overwritten' by the one in the list.
 
-        return header_tuples        
+        return header_tuples
 
     def get_reply_header_text(self):
-        """ Gets the reply header (including status and 
+        """ Gets the reply header (including status and
         additional crlf)"""
 
         header_tuples = self.get_reply_headers()
 
         headers = [self.response(self.reply_code)]
         headers += ["%s: %s" % h for h in header_tuples]
-        
+
         return string.join(headers, '\r\n') + '\r\n\r\n'
 
     #---------------------------------------------------
-    # This is the end of the new reply header 
+    # This is the end of the new reply header
     # management section.
     ####################################################
 
@@ -212,7 +212,7 @@ class http_request:
         if self._split_uri is None:
             m = self.path_regex.match (self.uri)
             if m.end() != len(self.uri):
-                raise ValueError, "Broken URI"
+                raise ValueError("Broken URI")
             else:
                 self._split_uri = m.groups()
         return self._split_uri
@@ -533,7 +533,7 @@ class http_channel (asynchat.async_chat):
     def handle_error (self):
         t, v = sys.exc_info()[:2]
         if t is SystemExit:
-            raise t, v
+            raise t(v)
         else:
             asynchat.async_chat.handle_error (self)
 

+ 1 - 1
supervisor/medusa/monitor.py

@@ -117,7 +117,7 @@ class monitor_channel (asynchat.async_chat):
                         else:
                             t,v,tb = sys.exc_info()
                             del tb
-                            raise t,v
+                            raise t(v)
                     exec co in self.local_env
                     method = 'exec'
             except:

+ 2 - 2
supervisor/medusa/rpc_client.py

@@ -143,7 +143,7 @@ class rpc_proxy:
                 print 'RPC: <== proxy(%08x)' % (value)
             return rpc_proxy (self.conn, value)
         elif kind == 1:
-            raise RPC_Error, value
+            raise RPC_Error(value)
         else:
             if self.DEBUG:
                 print 'RPC: <== %s' % (repr(value))
@@ -209,7 +209,7 @@ class fastrpc_proxy:
         if error is None:
             return result
         else:
-            raise RPC_Error, error
+            raise RPC_Error(error)
 
     def __repr__ (self):
         return '<remote-method-%s at %x>' % (string.join (self.path, '.'), id (self))

+ 2 - 2
supervisor/medusa/thread/select_trigger.py

@@ -79,7 +79,7 @@ if os.name == 'posix':
                 for fd in self._fds:
                     os.close(fd)
                 self._fds = []
- 
+
         def __repr__ (self):
             return '<select-trigger (pipe) at %x>' % id(self)
 
@@ -156,7 +156,7 @@ else:
                 else:
                     break
             else:
-                raise RuntimeError, 'Cannot bind trigger!'
+                raise RuntimeError('Cannot bind trigger!')
 
             a.listen(1)
             w.setblocking(0)

+ 1 - 1
supervisor/medusa/virtual_handler.py

@@ -19,7 +19,7 @@ class virtual_handler:
         try:
             self.ip = socket.gethostbyname (hostname)
         except socket.error:
-            raise ValueError, "Virtual Hostname %s does not appear to be registered in the DNS" % hostname
+            raise ValueError("Virtual Hostname %s does not appear to be registered in the DNS" % hostname)
 
     def match (self, request):
         if (request.channel.addr[0] == self.ip):

+ 14 - 14
supervisor/options.py

@@ -169,41 +169,41 @@ class Options:
         """
         if flag is not None:
             if handler is not None:
-                raise ValueError, "use at most one of flag= and handler="
+                raise ValueError("use at most one of flag= and handler=")
             if not long and not short:
-                raise ValueError, "flag= requires a command line flag"
+                raise ValueError("flag= requires a command line flag")
             if short and short.endswith(":"):
-                raise ValueError, "flag= requires a command line flag"
+                raise ValueError("flag= requires a command line flag")
             if long and long.endswith("="):
-                raise ValueError, "flag= requires a command line flag"
+                raise ValueError("flag= requires a command line flag")
             handler = lambda arg, flag=flag: flag
 
         if short and long:
             if short.endswith(":") != long.endswith("="):
-                raise ValueError, "inconsistent short/long options: %r %r" % (
-                    short, long)
+                raise ValueError("inconsistent short/long options: %r %r" % (
+                    short, long))
 
         if short:
             if short[0] == "-":
-                raise ValueError, "short option should not start with '-'"
+                raise ValueError("short option should not start with '-'")
             key, rest = short[:1], short[1:]
             if rest not in ("", ":"):
-                raise ValueError, "short option should be 'x' or 'x:'"
+                raise ValueError("short option should be 'x' or 'x:'")
             key = "-" + key
             if self.options_map.has_key(key):
-                raise ValueError, "duplicate short option key '%s'" % key
+                raise ValueError("duplicate short option key '%s'" % key)
             self.options_map[key] = (name, handler)
             self.short_options.append(short)
 
         if long:
             if long[0] == "-":
-                raise ValueError, "long option should not start with '-'"
+                raise ValueError("long option should not start with '-'")
             key = long
             if key[-1] == "=":
                 key = key[:-1]
             key = "--" + key
             if self.options_map.has_key(key):
-                raise ValueError, "duplicate long option key '%s'" % key
+                raise ValueError("duplicate long option key '%s'" % key)
             self.options_map[key] = (name, handler)
             self.long_options.append(long)
 
@@ -553,7 +553,7 @@ class ServerOptions(Options):
 
         sections = parser.sections()
         if not 'supervisord' in sections:
-            raise ValueError, '.ini file does not include supervisord section'
+            raise ValueError('.ini file does not include supervisord section')
         get = parser.getdefault
         section.minfds = integer(get('minfds', 1024))
         section.minprocs = integer(get('minprocs', 200))
@@ -811,7 +811,7 @@ class ServerOptions(Options):
 
         command = get(section, 'command', None)
         if command is None:
-            raise ValueError, (
+            raise ValueError(
                 'program section %s does not specify a command' % section)
 
         process_name = process_or_group_name(
@@ -1523,7 +1523,7 @@ class ClientOptions(Options):
         config.readfp(fp)
         sections = config.sections()
         if not 'supervisorctl' in sections:
-            raise ValueError,'.ini file does not include supervisorctl section'
+            raise ValueError('.ini file does not include supervisorctl section')
         serverurl = config.getdefault('serverurl', 'http://localhost:9001')
         if serverurl.startswith('unix://'):
             sf = serverurl[7:]

+ 6 - 6
supervisor/tests/test_rpcinterfaces.py

@@ -1670,8 +1670,8 @@ class SystemNamespaceXMLRPCInterfaceTests(TestBase):
             try:
                 interface.methodSignature(k)
             except xmlrpc.RPCError:
-                raise AssertionError, ('methodSignature for %s raises '
-                                       'RPCError (missing @return doc?)' % k)
+                raise AssertionError('methodSignature for %s raises '
+                                     'RPCError (missing @return doc?)' % k)
 
             # we want to test that the number of arguments implemented in
             # the function is the same as the number of arguments implied by
@@ -1712,9 +1712,9 @@ class SystemNamespaceXMLRPCInterfaceTests(TestBase):
             # param tokens
 
             if len(argnames) != len(pnames):
-                raise AssertionError, ('Incorrect documentation '
-                                       '(%s args, %s doc params) in %s'
-                                       % (len(argnames), len(pnames), k))
+                raise AssertionError('Incorrect documentation '
+                                     '(%s args, %s doc params) in %s'
+                                     % (len(argnames), len(pnames), k))
             for docline in plines:
                 self.assertTrue(type(docline) == int, (docline,
                                                        type(docline),
@@ -1728,7 +1728,7 @@ class SystemNamespaceXMLRPCInterfaceTests(TestBase):
                                                                  argnames[x],
                                                                  k,
                                                                  parsed)
-                    raise AssertionError, msg
+                    raise AssertionError(msg)
             for doctext in ptexts:
                 self.assertTrue(type(doctext) == type(''), doctext)