Skip to content

Commit

Permalink
Merge pull request #19 from lusitania/py3py2
Browse files Browse the repository at this point in the history
Py3 compatibility as proposed in issue #17
  • Loading branch information
stavxyz committed Oct 29, 2014
2 parents c7f53e1 + 4d25174 commit 4c9f8bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion airbrake/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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
Expand Down
29 changes: 20 additions & 9 deletions airbrake/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
"""Util functions/classes for airbrake-python."""
import Queue
try:
from queue import Queue, Full, Empty
except ImportError:
#Py2 legacy fix
from Queue import Queue, Full, Empty

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.Queue):
class CheckableQueue(Queue):

"""Checkable FIFO Queue which makes room for new items."""

def __init__(self, maxsize=1000):
Queue.Queue.__init__(self, maxsize=maxsize)
Queue.__init__(self, maxsize=maxsize)

def __contains__(self, item):
try:
Expand All @@ -20,11 +31,11 @@ def __contains__(self, item):

def put(self, item, block=False, timeout=1):
try:
Queue.Queue.put(self, item, block=block, timeout=timeout)
except Queue.Full:
Queue.put(self, item, block=block, timeout=timeout)
except Full:
try:
self.get_nowait()
except Queue.Empty:
except Empty:
pass
self.put(item)

Expand All @@ -37,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
Expand Down Expand Up @@ -87,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]
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
test_suite='tests',
install_requires=dependencies,
packages=find_packages(exclude=['tests']),
classifiers=["Programming Language :: Python"],
classifiers=["Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4"
],
license='Apache License (2.0)'
)

0 comments on commit 4c9f8bf

Please sign in to comment.