1 # -*- coding: utf-8 -*-
3 oauthlib.oauth2.rfc6749
4 ~~~~~~~~~~~~~~~~~~~~~~~
6 This module is an implementation of various logic needed
7 for consuming and providing OAuth 2.0 RFC6749.
9 from __future__ import absolute_import, unicode_literals
14 from ..errors import TemporarilyUnavailableError, ServerError
15 from ..errors import FatalClientError, OAuth2Error
17 log = logging.getLogger(__name__)
20 class BaseEndpoint(object):
23 self._available = True
24 self._catch_errors = False
28 return self._available
31 def available(self, available):
32 self._available = available
35 def catch_errors(self):
36 return self._catch_errors
39 def catch_errors(self, catch_errors):
40 self._catch_errors = catch_errors
43 def catch_errors_and_unavailability(f):
45 def wrapper(endpoint, uri, *args, **kwargs):
46 if not endpoint.available:
47 e = TemporarilyUnavailableError()
48 log.info('Endpoint unavailable, ignoring request %s.' % uri)
49 return {}, e.json, 503
51 if endpoint.catch_errors:
53 return f(endpoint, uri, *args, **kwargs)
56 except FatalClientError:
58 except Exception as e:
61 'Exception caught while processing request, %s.' % e)
62 return {}, error.json, 500
64 return f(endpoint, uri, *args, **kwargs)