From: Ben Darnell Date: Mon, 27 Jun 2011 01:51:12 +0000 (-0700) Subject: Replace all bare "except:" blocks with "except Exception:" so we don't X-Git-Tag: v2.1.0~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17eed4fef3fc7b63087c247bdb1732a621cb841a;p=thirdparty%2Ftornado.git Replace all bare "except:" blocks with "except Exception:" so we don't accidentally catch KeyboardInterrupt. --- diff --git a/tornado/auth.py b/tornado/auth.py index 91a29519b..9bcbef91f 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -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 diff --git a/tornado/autoreload.py b/tornado/autoreload.py index c4ced92d6..5d16d77c6 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -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 diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index db47c26ba..d7e191811 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -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"]) diff --git a/tornado/database.py b/tornado/database.py index 74daab6dc..e0f16e706 100644 --- a/tornado/database.py +++ b/tornado/database.py @@ -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) diff --git a/tornado/escape.py b/tornado/escape.py index 44fe9368d..089f6d485 100644 --- a/tornado/escape.py +++ b/tornado/escape.py @@ -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)) diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 7468b8bf9..1fd74c35c 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -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): diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 1609c2cb5..0e6b8a766 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -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: diff --git a/tornado/iostream.py b/tornado/iostream.py index fdb1e28d3..3ae241c2c 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -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 diff --git a/tornado/options.py b/tornado/options.py index b539e8e1b..2010159c7 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -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)) diff --git a/tornado/stack_context.py b/tornado/stack_context.py index 53edbd273..7504cd783 100644 --- a/tornado/stack_context.py +++ b/tornado/stack_context.py @@ -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) diff --git a/tornado/template.py b/tornado/template.py index 4f9d51b4d..f8b33bc69 100644 --- a/tornado/template.py +++ b/tornado/template.py @@ -122,7 +122,7 @@ class Template(object): try: self.compiled = compile(self.code, "