From 4d25174766cbc4cc269a2c7fa92e69354f4f257f Mon Sep 17 00:00:00 2001 From: lusitania Date: Sun, 5 Oct 2014 20:14:08 +0200 Subject: [PATCH] Py3 exception logging, issue #17 Previous commit didn't verify logging of exceptions. Critical issues: - types.TypeType is now built-in, added legacy switch - filter yields `TypeError: 'filter' object is not subscriptable`, changed to list comprehension (since it was used already the previous line) 2to3 also complained the use of map over list comprehension, changed for similar rationale. --- airbrake/handler.py | 2 +- airbrake/utils.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/airbrake/handler.py b/airbrake/handler.py index 7babe6c..4e3b008 100644 --- a/airbrake/handler.py +++ b/airbrake/handler.py @@ -93,7 +93,7 @@ def airbrake_error_from_logrecord(record): # find params from kwarg 'extra' # See "The second keyword argument is extra" # - https://docs.python.org/2/library/logging.html#logging.Logger.debug - for key, val in vars(record).items(): + for key, val in list(vars(record).items()): if not hasattr(_FAKE_LOGRECORD, key): # handle attribute/field name collisions: # logrecod attrs should not limit or take diff --git a/airbrake/utils.py b/airbrake/utils.py index f828b8d..34a7aef 100644 --- a/airbrake/utils.py +++ b/airbrake/utils.py @@ -7,7 +7,13 @@ import traceback import types +import sys +if sys.version_info < (3,): + #Py2 legacy fix + type_of_type = types.TypeType +else: + type_of_type = type class CheckableQueue(Queue): @@ -42,9 +48,9 @@ def is_exc_info_tuple(exc_info): """ try: errtype, value, tback = exc_info - if all(map(lambda x: x is None, exc_info)): + if all([x is None for x in exc_info]): return True - elif all((isinstance(errtype, types.TypeType), + elif all((isinstance(errtype, type_of_type), isinstance(value, Exception), isinstance(tback, types.TracebackType))): return True @@ -92,6 +98,6 @@ def pytb_lastline(excinfo=None): # strip whitespace, Falsy values, # and the string 'None', sometimes returned by the traceback module lines = [line.strip() for line in lines if line] - lines = filter(lambda line: str(line).lower() != 'none', lines) + lines = [line for line in lines if str(line).lower() != 'none'] if lines: return lines[-1]