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
18 log = logging.getLogger(__name__)
21 class BaseEndpoint(object):
24 self._available = True
25 self._catch_errors = False
29 return self._available
32 def available(self, available):
33 self._available = available
36 def catch_errors(self):
37 return self._catch_errors
40 def catch_errors(self, catch_errors):
41 self._catch_errors = catch_errors
44 def catch_errors_and_unavailability(f):
46 def wrapper(endpoint, uri, *args, **kwargs):
47 if not endpoint.available:
48 e = TemporarilyUnavailableError()
49 log.info('Endpoint unavailable, ignoring request %s.' % uri)
50 return {}, e.json, 503
52 if endpoint.catch_errors:
54 return f(endpoint, uri, *args, **kwargs)
57 except FatalClientError:
59 except Exception as e:
62 'Exception caught while processing request, %s.' % e)
63 return {}, error.json, 500
65 return f(endpoint, uri, *args, **kwargs)