From c38e80da17892557d991717600642f354c97be9c Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Mon, 20 Jun 2016 15:54:35 -0400 Subject: [PATCH 1/7] HandlerMixin: Make prepare async-safe. --- sprockets/mixins/correlation/mixins.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sprockets/mixins/correlation/mixins.py b/sprockets/mixins/correlation/mixins.py index 6d87db3..92ec499 100644 --- a/sprockets/mixins/correlation/mixins.py +++ b/sprockets/mixins/correlation/mixins.py @@ -1,5 +1,15 @@ import uuid +import tornado.gen + +if tornado.version_info[0] >= 4: + from tornado.concurrent import is_future +else: + import tornado.concurrent + + def is_future(maybe_future): + return isinstance(maybe_future, tornado.concurrent.Future) + class HandlerMixin(object): """ @@ -39,11 +49,15 @@ class HandlerMixin(object): self.__correlation_id = str(uuid.uuid4()) super(HandlerMixin, self).__init__(*args, **kwargs) + @tornado.gen.coroutine def prepare(self): # Here we want to copy an incoming Correlation-ID header if # one exists. We also want to set it in the outgoing response # which the property setter does for us. - super(HandlerMixin, self).prepare() + maybe_future = super(HandlerMixin, self).prepare() + if is_future(maybe_future): + yield maybe_future + correlation_id = self.get_request_header(self.__header_name, None) if correlation_id is not None: self.correlation_id = correlation_id From aef860f8335373a4be4e2cd57d1e43f302b34e0d Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Mon, 20 Jun 2016 15:57:59 -0400 Subject: [PATCH 2/7] correlation_id_logger: Add missing import. --- sprockets/mixins/correlation/mixins.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sprockets/mixins/correlation/mixins.py b/sprockets/mixins/correlation/mixins.py index 92ec499..121c4d6 100644 --- a/sprockets/mixins/correlation/mixins.py +++ b/sprockets/mixins/correlation/mixins.py @@ -1,6 +1,7 @@ import uuid import tornado.gen +import tornado.log if tornado.version_info[0] >= 4: from tornado.concurrent import is_future @@ -112,11 +113,11 @@ def correlation_id_logger(handler): is processing the client request. """ if handler.get_status() < 400: - log_method = log.access_log.info + log_method = tornado.log.access_log.info elif handler.get_status() < 500: - log_method = log.access_log.warning + log_method = tornado.log.access_log.warning else: - log_method = log.access_log.error + log_method = tornado.log.access_log.error request_time = 1000.0 * handler.request.request_time() correlation_id = getattr(handler, "correlation_id", None) if correlation_id is None: From d8f6f70142bbefca27841aec85404341082831da Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Mon, 20 Jun 2016 15:59:20 -0400 Subject: [PATCH 3/7] Add tornado 4.3 to the test suite. --- tox.ini | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 124cd9f..1f3b989 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py33,py34,pypy,pypy3,tornado31,tornado32,tornado40 +envlist = py27,py33,py34,pypy,pypy3,tornado31,tornado32,tornado40,tornado43 toxworkdir = {toxinidir}/build/tox skip_missing_intepreters = true @@ -28,3 +28,8 @@ deps = deps = -rtest-requirements.txt tornado>=4.0,<4.1 + +[testenv:tornado43] +deps = + -rtest-requirements.txt + tornado>=4.3,<4.4 From 6680f4b94071b230bb8e7171687f1c91a8e52cf4 Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Mon, 20 Jun 2016 16:01:00 -0400 Subject: [PATCH 4/7] Metadata bumps for 1.0.2. --- HISTORY.rst | 5 +++++ docs/conf.py | 2 +- sprockets/mixins/correlation/__init__.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 72e3ab7..1a621c3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,9 +1,14 @@ Version History --------------- +`1.0.2`_ (20-Jun-2016) +~~~~~~~~~~~~~~~~~~~~~~ +- Add support for async prepare in superclasses of ``HandlerMixin`` + `1.0.1`_ (31-Mar-2015) ~~~~~~~~~~~~~~~~~~~~~~ - Adds ``sprockets.mixins.correlation.HandlerMixin`` +.. _`1.0.2`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.1...1.0.2 .. _`1.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/0.0.0...1.0.1 diff --git a/docs/conf.py b/docs/conf.py index 559b41e..c50e940 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,7 @@ templates_path = [] source_suffix = '.rst' master_doc = 'index' project = 'sprockets.mixins.correlation' -copyright = '2015, AWeber Communications' +copyright = '2015-2016, AWeber Communications' version = '.'.join(__version__.split('.')[0:1]) release = __version__ if len(version_info) > 3: diff --git a/sprockets/mixins/correlation/__init__.py b/sprockets/mixins/correlation/__init__.py index c5b71e1..f081b75 100644 --- a/sprockets/mixins/correlation/__init__.py +++ b/sprockets/mixins/correlation/__init__.py @@ -1,5 +1,5 @@ from .mixins import HandlerMixin -version_info = (1, 0, 1) +version_info = (1, 0, 2) __version__ = '.'.join(str(v) for v in version_info[:3]) From cd4e20a93c0a0369dda687cd6d19cd0b07c2271c Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Mon, 20 Jun 2016 16:01:10 -0400 Subject: [PATCH 5/7] Replace readthedocs.org -> readthedocs.io. --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index dbf56e5..2e614d4 100644 --- a/README.rst +++ b/README.rst @@ -81,8 +81,8 @@ Relayed Correlation ID .. |Downloads| image:: https://img.shields.io/pypi/dm/sprockets.mixins.correlation.svg :target: https://pypi.python.org/pypi/sprockets.mixins.correlation .. |License| image:: https://pypip.in/license/sprockets.mixins.correlation/badge.svg - :target: https://sprocketsmixinscorrelation.readthedocs.org/ + :target: https://sprocketsmixinscorrelation.readthedocs.io/ .. |Documentation| image:: https://readthedocs.org/projects/sprocketsmixinscorrelation/badge - :target: https://sprocketsmixinscorrelation.readthedocs.org/ + :target: https://sprocketsmixinscorrelation.readthedocs.io/ .. _Python Package Index: https://pypi.python.org/pypi/sprockets.mixins.correlation From 4e8d3fa571e06050b90027d14bc4ebab6801908a Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Tue, 21 Jun 2016 10:25:46 -0400 Subject: [PATCH 6/7] requirements: Explicitly depend on tornado. Technically you *could* use this without Tornado but we don't. If you really want to, open an issue. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e69de29..3f55f96 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +tornado>=3.1,<4.4 From 520ad6a456cbd94e176bb54373669baf5e8cfbd9 Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Tue, 21 Jun 2016 10:30:52 -0400 Subject: [PATCH 7/7] Fix retrieving __version__ without Tornado installed. --- sprockets/mixins/correlation/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sprockets/mixins/correlation/__init__.py b/sprockets/mixins/correlation/__init__.py index f081b75..0dfe0ff 100644 --- a/sprockets/mixins/correlation/__init__.py +++ b/sprockets/mixins/correlation/__init__.py @@ -1,4 +1,11 @@ -from .mixins import HandlerMixin +try: + from .mixins import HandlerMixin + +except ImportError as error: + + class HandlerMixin(object): + def __init__(self, *args, **kwargs): + raise error version_info = (1, 0, 2)