]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Replace all bare "except:" blocks with "except Exception:" so we don't
authorBen Darnell <ben@bendarnell.com>
Mon, 27 Jun 2011 01:51:12 +0000 (18:51 -0700)
committerBen Darnell <ben@bendarnell.com>
Mon, 27 Jun 2011 01:51:12 +0000 (18:51 -0700)
accidentally catch KeyboardInterrupt.

13 files changed:
tornado/auth.py
tornado/autoreload.py
tornado/curl_httpclient.py
tornado/database.py
tornado/escape.py
tornado/httpserver.py
tornado/ioloop.py
tornado/iostream.py
tornado/options.py
tornado/stack_context.py
tornado/template.py
tornado/testing.py
tornado/web.py

index 91a29519be8bb362380efcc064aac2b5686bc456..9bcbef91fa79c250e8e97a1827c17a22499a7f4e 100644 (file)
@@ -903,7 +903,7 @@ class FacebookMixin(object):
             return
         try:
             json = escape.json_decode(response.body)
-        except:
+        except Exception:
             logging.warning("Invalid JSON from Facebook: %r", response.body)
             callback(None)
             return
index c4ced92d657f677e3c8538c791d3210867a4d39d..5d16d77c661e095bcf21d3587b3f4e6ae3230810 100644 (file)
@@ -97,7 +97,7 @@ def _reload_on_update(io_loop, modify_times):
 def _check_file(io_loop, modify_times, path):
         try:
             modified = os.stat(path).st_mtime
-        except:
+        except Exception:
             return
         if path not in modify_times:
             modify_times[path] = modified
@@ -108,7 +108,7 @@ def _check_file(io_loop, modify_times, path):
             for fd in io_loop._handlers.keys():
                 try:
                     os.close(fd)
-                except:
+                except Exception:
                     pass
             if hasattr(signal, "setitimer"):
                 # Clear the alarm signal set by
index db47c26ba185767029dd1e842453c272402efd2f..d7e1918112a5b96a939e2ff81eb95c4d03fbc238 100644 (file)
@@ -247,9 +247,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
                 buffer=buffer, effective_url=effective_url, error=error,
                 request_time=time.time() - info["curl_start_time"],
                 time_info=time_info))
-        except (KeyboardInterrupt, SystemExit):
-            raise
-        except:
+        except Exception:
             self.handle_callback_exception(info["callback"])
 
 
index 74daab6dc83a1ce0989093598a27f8e75bcf3df6..e0f16e706b57a505891aec9425dd99d0bcb4810a 100644 (file)
@@ -72,7 +72,7 @@ class Connection(object):
         self._last_use_time = time.time()
         try:
             self.reconnect()
-        except:
+        except Exception:
             logging.error("Cannot connect to MySQL on %s", self.host,
                           exc_info=True)
 
index 44fe9368d2934659448b77f2898625ff4b2bb4cd..089f6d48587a3d794468bdb48d70c4278db34104 100644 (file)
@@ -28,7 +28,7 @@ import urllib
 
 # Python3 compatibility:  On python2.5, introduce the bytes alias from 2.6
 try: bytes
-except: bytes = str
+except Exception: bytes = str
 
 try:
     from urlparse import parse_qs  # Python 2.6+
@@ -42,7 +42,7 @@ try:
     assert hasattr(json, "loads") and hasattr(json, "dumps")
     _json_decode = json.loads
     _json_encode = json.dumps
-except:
+except Exception:
     try:
         import simplejson
         _json_decode = lambda s: simplejson.loads(_unicode(s))
index 7468b8bf987eae704a4875cfc30db71b51894075..1fd74c35ca14b3399725f92783e8b5b4328ce695 100644 (file)
@@ -315,7 +315,7 @@ class HTTPServer(object):
                     stream = iostream.IOStream(connection, io_loop=self.io_loop)
                 HTTPConnection(stream, address, self.request_callback,
                                self.no_keep_alive, self.xheaders)
-            except:
+            except Exception:
                 logging.error("Error in connection callback", exc_info=True)
 
 class _BadRequestException(Exception):
index 1609c2cb5f47ab9fbf3a561581a8edddc43d1b0f..0e6b8a7661ca4fa51797e445d21ab2969b459335 100644 (file)
@@ -307,8 +307,6 @@ class IOLoop(object):
                 fd, events = self._events.popitem()
                 try:
                     self._handlers[fd](fd, events)
-                except (KeyboardInterrupt, SystemExit):
-                    raise
                 except (OSError, IOError), e:
                     if e.args[0] == errno.EPIPE:
                         # Happens when the client closes the connection
@@ -316,7 +314,7 @@ class IOLoop(object):
                     else:
                         logging.error("Exception in I/O handler for fd %d",
                                       fd, exc_info=True)
-                except:
+                except Exception:
                     logging.error("Exception in I/O handler for fd %d",
                                   fd, exc_info=True)
         # reset the stopped flag so another start/stop pair can be issued
@@ -390,9 +388,7 @@ class IOLoop(object):
     def _run_callback(self, callback):
         try:
             callback()
-        except (KeyboardInterrupt, SystemExit):
-            raise
-        except:
+        except Exception:
             self.handle_callback_exception(callback)
 
     def handle_callback_exception(self, callback):
@@ -474,9 +470,7 @@ class PeriodicCallback(object):
         if not self._running: return
         try:
             self.callback()
-        except (KeyboardInterrupt, SystemExit):
-            raise
-        except:
+        except Exception:
             logging.error("Error in periodic callback", exc_info=True)
         if self._running:
             self.start()
@@ -628,7 +622,7 @@ else:
         # Linux systems with our C module installed
         import epoll
         _poll = _EPoll
-    except:
+    except Exception:
         # All other systems
         import sys
         if "linux" in sys.platform:
index fdb1e28d3d279c0a8982916d718244239835a817..3ae241c2c50af74b4e670df91a653e850846c975 100644 (file)
@@ -240,7 +240,7 @@ class IOStream(object):
             if state != self._state:
                 self._state = state
                 self.io_loop.update_handler(self.socket.fileno(), self._state)
-        except:
+        except Exception:
             logging.error("Uncaught exception, closing connection.",
                           exc_info=True)
             self.close()
@@ -250,7 +250,7 @@ class IOStream(object):
         def wrapper():
             try:
                 callback(*args)
-            except:
+            except Exception:
                 logging.error("Uncaught exception, closing connection.",
                               exc_info=True)
                 # Close the socket on an uncaught exception from a user callback
index b539e8e1b530740d56d54963651bddfdb396c9ca..2010159c712346fb329c524b3f3cd3c4f9132fdc 100644 (file)
@@ -60,7 +60,7 @@ from tornado.escape import _unicode
 # For pretty log messages, if available
 try:
     import curses
-except:
+except ImportError:
     curses = None
 
 
@@ -295,7 +295,7 @@ class _Option(object):
                 sum += datetime.timedelta(**{units: num})
                 start = m.end()
             return sum
-        except:
+        except Exception:
             raise
 
     def _parse_bool(self, value):
@@ -333,7 +333,7 @@ def enable_pretty_logging():
                 curses.setupterm()
                 if curses.tigetnum("colors") > 0:
                     color = True
-            except:
+            except Exception:
                 pass
         channel = logging.StreamHandler()
         channel.setFormatter(_LogFormatter(color=color))
index 53edbd2739303d78db8ec6f900e8cd42d3e470e6..7504cd783c30733b57a7344a1b8acc787680a10b 100644 (file)
@@ -35,7 +35,7 @@ Example usage::
     def die_on_error():
         try:
             yield
-        except:
+        except Exception:
             logging.error("exception in asynchronous operation",exc_info=True)
             sys.exit(1)
 
index 4f9d51b4dd3a357ef7bf001dee350f7b0138ad0f..f8b33bc69a85e2bc1845f36519990948e237405b 100644 (file)
@@ -122,7 +122,7 @@ class Template(object):
         try:
             self.compiled = compile(self.code, "<template %s>" % self.name,
                                     "exec")
-        except:
+        except Exception:
             formatted_code = _format_code(self.code).rstrip()
             logging.error("%s code:\n%s", self.name, formatted_code)
             raise
@@ -145,7 +145,7 @@ class Template(object):
         execute = namespace["_execute"]
         try:
             return execute()
-        except:
+        except Exception:
             formatted_code = _format_code(self.code).rstrip()
             logging.error("%s code:\n%s", self.name, formatted_code)
             raise
index f068b167dea61523bacec7556d60b83a42065c60..c2156173b9ab140c9187c330703b38f2bb5cbfe1 100644 (file)
@@ -115,7 +115,7 @@ class AsyncTestCase(unittest.TestCase):
     def _stack_context(self):
         try:
             yield
-        except:
+        except Exception:
             self.__failure = sys.exc_info()
             self.stop()
 
@@ -152,7 +152,7 @@ class AsyncTestCase(unittest.TestCase):
                         raise self.failureException(
                           'Async operation timed out after %d seconds' %
                           timeout)
-                    except:
+                    except Exception:
                         self.__failure = sys.exc_info()
                     self.stop()
                 self.io_loop.add_timeout(time.time() + timeout, timeout_func)
index 485f29205724700f5480109aee0478d347b713a6..2e5a4c2f79963f7eb978c89001f9b4707cba7d04 100644 (file)
@@ -286,7 +286,7 @@ class RequestHandler(object):
                 try:
                     self._cookies.load(
                         escape.native_str(self.request.headers["Cookie"]))
-                except:
+                except Exception:
                     self.clear_all_cookies()
         return self._cookies
 
@@ -396,7 +396,7 @@ class RequestHandler(object):
             logging.warning("Tampered cookie %r", value)
         try:
             return base64.b64decode(parts[0])
-        except:
+        except Exception:
             return None
 
     def _cookie_signature(self, *parts):
@@ -837,7 +837,7 @@ class RequestHandler(object):
                 f = open(abs_path, "rb")
                 hashes[abs_path] = hashlib.md5(f.read()).hexdigest()
                 f.close()
-            except:
+            except Exception:
                 logging.error("Could not open static file %r", path)
                 hashes[abs_path] = None
         base = self.request.protocol + "://" + self.request.host \
@@ -896,7 +896,7 @@ class RequestHandler(object):
             # so re-raise the exception to ensure that it's in
             # sys.exc_info()
             raise type, value, traceback
-        except:
+        except Exception:
             self._handle_request_exception(value)
         return True