diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-10-09 07:06:13 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-10-09 07:06:13 (GMT) |
commit | 8cf4eb1463217095e9276c0caacfb2df9372504f (patch) | |
tree | 026ba0deb3d3839450766c501c6769982f25566c /Lib/logging | |
parent | 85aa0118dbe0caf704d6c5de94ddcf7f4dcba32c (diff) | |
download | cpython-8cf4eb1463217095e9276c0caacfb2df9372504f.zip cpython-8cf4eb1463217095e9276c0caacfb2df9372504f.tar.gz cpython-8cf4eb1463217095e9276c0caacfb2df9372504f.tar.bz2 |
Issue #16141: replaced old-style exception handling code in logging with the modern idiom.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 8 | ||||
-rw-r--r-- | Lib/logging/config.py | 6 | ||||
-rw-r--r-- | Lib/logging/handlers.py | 28 |
3 files changed, 12 insertions, 30 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index e79018f..0f804ae 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -67,7 +67,7 @@ else: #pragma: no cover """Return the frame object for the caller's stack frame.""" try: raise Exception - except: + except Exception: return sys.exc_info()[2].tb_frame.f_back # _srcfile is only used in conjunction with sys._getframe(). @@ -938,9 +938,7 @@ class StreamHandler(Handler): stream.write(msg) stream.write(self.terminator) self.flush() - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) class FileHandler(StreamHandler): @@ -1837,7 +1835,7 @@ def shutdown(handlerList=_handlerList): pass finally: h.release() - except: + except: # ignore everything, as we're shutting down if raiseExceptions: raise #else, swallow diff --git a/Lib/logging/config.py b/Lib/logging/config.py index e71e89c..9ba3cca 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -827,15 +827,13 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT, verify=None): d =json.loads(chunk) assert isinstance(d, dict) dictConfig(d) - except: + except Exception: #Apply new configuration. file = io.StringIO(chunk) try: fileConfig(file) - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: traceback.print_exc() if self.server.ready: self.server.ready.set() diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 1bad856..5169af0 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -72,9 +72,7 @@ class BaseRotatingHandler(logging.FileHandler): if self.shouldRollover(record): self.doRollover() logging.FileHandler.emit(self, record) - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) def rotation_filename(self, default_name): @@ -609,9 +607,7 @@ class SocketHandler(logging.Handler): try: s = self.makePickle(record) self.send(s) - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) def close(self): @@ -877,9 +873,7 @@ class SysLogHandler(logging.Handler): self.socket.sendto(msg, self.address) else: self.socket.sendall(msg) - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) class SMTPHandler(logging.Handler): @@ -957,9 +951,7 @@ class SMTPHandler(logging.Handler): smtp.login(self.username, self.password) smtp.sendmail(self.fromaddr, self.toaddrs, msg) smtp.quit() - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) class NTEventLogHandler(logging.Handler): @@ -1044,9 +1036,7 @@ class NTEventLogHandler(logging.Handler): type = self.getEventType(record) msg = self.format(record) self._welu.ReportEvent(self.appname, id, cat, type, [msg]) - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) def close(self): @@ -1131,9 +1121,7 @@ class HTTPHandler(logging.Handler): if self.method == "POST": h.send(data.encode('utf-8')) h.getresponse() #can't do anything with the result - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) class BufferingHandler(logging.Handler): @@ -1313,9 +1301,7 @@ class QueueHandler(logging.Handler): """ try: self.enqueue(self.prepare(record)) - except (KeyboardInterrupt, SystemExit): #pragma: no cover - raise - except: + except Exception: self.handleError(record) if threading: |