Skip to content

Commit

Permalink
Merge pull request #14 from nvllsvm/rav
Browse files Browse the repository at this point in the history
Tornado 5 support
  • Loading branch information
gmr committed Nov 30, 2018
2 parents bd69878 + b72ff2f commit 339fa10
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 69 deletions.
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
---
sudo: false
language: python
dist: xenial
python:
- 2.7
- 3.5
- 3.6
- 3.7-dev
- pypy
- pypy3
- 3.7
install:
- pip install -r test-requirements.txt
- pip install -r requirements.txt
script: nosetests
- pip install -r requires/development.txt
script:
- nosetests
- python setup.py build_sphinx
after_success:
- codecov
deploy:
distributions: sdist bdist_wheel
provider: pypi
on:
python: 3.6
python: 3.7
tags: true
all_branches: true
user: sprockets
Expand Down
3 changes: 0 additions & 3 deletions dev-requirements.txt

This file was deleted.

12 changes: 1 addition & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
#!/usr/bin/env python
import sphinx_rtd_theme
from sprockets.mixins.sentry import __version__

from sprockets.mixins.sentry import version_info, __version__

needs_sphinx = '1.0'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinxcontrib.httpdomain',
]
templates_path = []
source_suffix = '.rst'
master_doc = 'index'
project = 'sprockets.mixins.sentry'
copyright = '2016, AWeber Communications'
version = '.'.join(__version__.split('.')[0:1])
release = __version__
if len(version_info) > 3:
release += '-{0}'.format(str(v) for v in version_info[3:])
exclude_patterns = []
pygments_style = 'sphinx'
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
intersphinx_mapping = {
'python': ('https://docs.python.org/', None),
'tornado': ('http://tornadoweb.org/en/stable/', None),
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

3 changes: 3 additions & 0 deletions requires/development.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e .
-r docs.txt
-r testing.txt
2 changes: 2 additions & 0 deletions requires/docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx-rtd-theme==0.4.2
sphinx==1.8.1
2 changes: 2 additions & 0 deletions requires/installation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
raven>=6,<7
tornado>=4,<6
4 changes: 4 additions & 0 deletions requires/testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
codecov==2.0.15
coverage==4.5.2
flake8==3.6.0
nose==1.3.7
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[bdist_wheel]
universal = 1
universal = 1

[build_sphinx]
fresh-env = 1
warning-is-error = 1
13 changes: 2 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import codecs
import sys

import setuptools

Expand All @@ -20,12 +19,8 @@ def read_requirements_file(req_name):
return requirements


install_requires = read_requirements_file('requirements.txt')
setup_requires = read_requirements_file('setup-requirements.txt')
tests_require = read_requirements_file('test-requirements.txt')

if sys.version_info < (3, 0):
tests_require.append('mock')
install_requires = read_requirements_file('requires/installation.txt')
tests_require = read_requirements_file('requires/testing.txt')

setuptools.setup(
name='sprockets.mixins.sentry',
Expand All @@ -42,14 +37,11 @@ def read_requirements_file(req_name):
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
],
Expand All @@ -61,7 +53,6 @@ def read_requirements_file(req_name):
namespace_packages=['sprockets',
'sprockets.mixins'],
install_requires=install_requires,
setup_requires=setup_requires,
tests_require=tests_require,
test_suite='nose.collector',
zip_safe=False)
1 change: 0 additions & 1 deletion sprockets/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion sprockets/mixins/__init__.py

This file was deleted.

22 changes: 7 additions & 15 deletions sprockets/mixins/sentry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import math
import os
import re
import sys
import time

import raven
Expand All @@ -22,13 +21,6 @@
__version__ = '.'.join(str(v) for v in version_info)


if sys.version_info[0] == 3:
string_types = str
text_type = str
else:
string_types = basestring
text_type = unicode

# This matches the userinfo production from RFC3986 with some extra
# leniancy to account for poorly formed URLs. For example, it lets
# you include braces and other things in the password section.
Expand Down Expand Up @@ -64,7 +56,7 @@ def sanitize(self, key, value):
if value is None:
return

if isinstance(value, string_types):
if isinstance(value, str):
return self.VALUES_RE.sub(self.MASK, value)

if not key: # key can be a NoneType
Expand All @@ -75,7 +67,7 @@ def sanitize(self, key, value):
if isinstance(key, bytes):
key = key.decode('utf-8', 'replace')
else:
key = text_type(key)
key = str(key)

key = key.lower()
for field in self.FIELDS:
Expand All @@ -85,7 +77,7 @@ def sanitize(self, key, value):
return value


class SentryMixin(object):
class SentryMixin:
"""
Report unexpected exceptions to Sentry.
Expand Down Expand Up @@ -123,14 +115,14 @@ def __init__(self, *args, **kwargs):
self.sentry_client = None
self.sentry_extra = {}
self.sentry_tags = {}
super(SentryMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def initialize(self):
self.sentry_client = get_client(self.application)
if self.sentry_client is None:
install(self.application)
self.sentry_client = get_client(self.application)
super(SentryMixin, self).initialize()
super().initialize()

def _strip_uri_passwords(self, values):
for key in values.keys():
Expand All @@ -143,7 +135,7 @@ def _handle_request_exception(self, e):
if (isinstance(e, web.HTTPError)
or isinstance(e, web.Finish)
or self.sentry_client is None):
return super(SentryMixin, self)._handle_request_exception(e)
return super()._handle_request_exception(e)

duration = math.ceil((time.time() - self.request._start_time) * 1000)
kwargs = {'extra': self.sentry_extra, 'time_spent': duration}
Expand All @@ -168,7 +160,7 @@ def _handle_request_exception(self, e):
kwargs.update({'tags': self.sentry_tags})
self.sentry_client.captureException(**kwargs)

super(SentryMixin, self)._handle_request_exception(e)
super()._handle_request_exception(e)


def install(application, **kwargs):
Expand Down
5 changes: 0 additions & 5 deletions test-requirements.txt

This file was deleted.

16 changes: 5 additions & 11 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
Tests for the sprockets.mixins.sentry package
"""
from unittest import mock
import os
import sys
import unittest
import uuid
try:
import unittest2 as unittest
except ImportError:
import unittest

try:
from unittest import mock
except ImportError:
import mock

from tornado import testing, web
import raven
Expand Down Expand Up @@ -48,7 +41,7 @@ class TestRequestHandler(sentry.SentryMixin, web.RequestHandler):
send_to_sentry = mock.Mock()

def initialize(self):
super(TestRequestHandler, self).initialize()
super().initialize()
self.sentry_client.send = self.send_to_sentry
self.send_to_sentry.reset_mock()

Expand Down Expand Up @@ -156,7 +149,8 @@ def test_that_tornado_is_not_in_app(self):
class InstallationTests(unittest.TestCase):

# cannot use mock since it answers True to getattr calls
class Application(object): pass
class Application:
pass

def test_that_client_is_installed(self):
application = self.Application()
Expand Down

0 comments on commit 339fa10

Please sign in to comment.