@@ -0,0 +1,1689 @@
+# Standard library imports%0Aimport operator%0A%0A# Local imports%0Afrom uplink.clients.io import RequestTemplate, transitions%0A%0A%0Aclass DefaultRequestTemplate(RequestTemplate):%0A    %22%22%22The fallback behaviors for all templates.%22%22%22%0A%0A    def before_request(self, request):%0A        return transitions.send(request)%0A%0A    def after_response(self, request, response):%0A        return transitions.finish(response)%0A%0A    def after_exception(self, request, exc_type, exc_val, exc_tb):%0A        return transitions.fail(exc_type, exc_val, exc_tb)%0A%0A%0Aclass CompositeRequestTemplate(RequestTemplate):%0A    %22%22%22Chains together many templates with a fallback behavior.%22%22%22%0A%0A    def _get_transition(self, method, *args, **kwargs):%0A        caller = operator.methodcaller(method, *args, **kwargs)%0A        for template in self._templates:%0A            transition = caller(template)%0A            if transition is not None:%0A                return transition%0A        else:%0A            return caller(self._fallback)%0A%0A    def __init__(self, templates, fallback=DefaultRequestTemplate()):%0A        self._templates = list(templates)%0A        self._fallback = fallback%0A%0A    def before_request(self, request):%0A        return self._get_transition(%0A            RequestTemplate.before_request.__name__, request%0A        )%0A%0A    def after_response(self, request, response):%0A        return self._get_transition(%0A            RequestTemplate.after_response.__name__, request, response%0A        )%0A%0A    def after_exception(self, request, exc_type, exc_val, exc_tb):%0A        return self._get_transition(%0A            RequestTemplate.after_exception.__name__,%0A            request,%0A            exc_type,%0A            exc_val,%0A            exc_tb,%0A        )%0A

Add default and composite templates