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/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 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/requirements.txt b/requirements.txt index e69de29..3f55f96 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +tornado>=3.1,<4.4 diff --git a/sprockets/mixins/correlation/__init__.py b/sprockets/mixins/correlation/__init__.py index c5b71e1..0dfe0ff 100644 --- a/sprockets/mixins/correlation/__init__.py +++ b/sprockets/mixins/correlation/__init__.py @@ -1,5 +1,12 @@ -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, 1) +version_info = (1, 0, 2) __version__ = '.'.join(str(v) for v in version_info[:3]) diff --git a/sprockets/mixins/correlation/mixins.py b/sprockets/mixins/correlation/mixins.py index 6d87db3..121c4d6 100644 --- a/sprockets/mixins/correlation/mixins.py +++ b/sprockets/mixins/correlation/mixins.py @@ -1,5 +1,16 @@ import uuid +import tornado.gen +import tornado.log + +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 +50,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 @@ -98,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: 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