No description
Find a file
Dave Shawley f80f3dd16c ClientMixin: Fix strange infinite recursion bug.
When running the LoggingTests on pypy3 (PyPy 2.4.0), both the server and
client error tests result in infinite recursion in
tornado.httpclient.HTTPResponse.__repr__ when logging the error with a
%r.  The initializer for the response creates a HTTPError object with a
referential loop:

    def __init__(self, ... error=None):
    	# ....
        if error is None:
	    self.error = HTTPError(self.code, message=self.reason,
	                           response=self)

When printing a HTTPError with %r it prints to response object's repr
which in turn prints the error's repr.
2016-01-08 07:27:40 -05:00
docs Initial implementation of ClientMixin. 2016-01-07 19:59:55 -05:00
examples Initial implementation of ClientMixin. 2016-01-07 19:59:55 -05:00
requires Initial implementation of ClientMixin. 2016-01-07 19:59:55 -05:00
sprockets ClientMixin: Fix strange infinite recursion bug. 2016-01-08 07:27:40 -05:00
tests ClientMixin: Don't overwrite existing self.logger. 2016-01-08 07:27:32 -05:00
.gitignore SYN 2016-01-07 19:58:39 -05:00
LICENSE SYN 2016-01-07 19:58:39 -05:00
MANIFEST.in SYN 2016-01-07 19:58:39 -05:00
README.rst SYN 2016-01-07 19:58:39 -05:00
setup.cfg SYN 2016-01-07 19:58:39 -05:00
setup.py Initial implementation of ClientMixin. 2016-01-07 19:59:55 -05:00
tox.ini SYN 2016-01-07 19:58:39 -05:00

sprockets.clients.http
======================

Simplifies calling HTTP APIs from Tornado-based applications.

This library implements a mix-in class that adds a single method which
makes a HTTP request and calls a callback when an error occurs.  The
request is made using Tornado's asynchronous HTTP client so it does
not block the active IO loop.

.. code-block:: python

   from sprockets.clients import http
   from tornado import gen, web

   class MyHandler(http.ClientMixin, web.RequestHandler):

       @gen.coroutine
       def get(self):
           response = yield self.make_http_request(
               some_server_url, on_error=self.handle_api_error)
           if self._finished:
               yield gen.Return()

           # handle response as you wish
           # ...
           self.finish()

       def handle_api_error(self, request, error):
           self.send_error(error.code)

That's it.  What you do not see is asynchronous client usage and logging
that happens inside of the library.  There is some setup code in
``ClientMixin.initialize`` so make sure to call the super implementation
if you implement ``initialize`` in your request handler.