# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class TemporarilyUnavailableError(OAuth2Error):
#     """The authorization server is currently unable to handle the request
#     due to a temporary overloading or maintenance of the server.
#     (This error code is needed because a 503 Service Unavailable HTTP
#     status code cannot be returned to the client via a HTTP redirect.)
#     """
#     error = 'temporarily_unavailable'
# 
# class ServerError(OAuth2Error):
#     """The authorization server encountered an unexpected condition that
#     prevented it from fulfilling the request.  (This error code is needed
#     because a 500 Internal Server Error HTTP status code cannot be returned
#     to the client via a HTTP redirect.)
#     """
#     error = 'server_error'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class FatalClientError(OAuth2Error):
#     """Errors during authorization where user should not be redirected back.
# 
#     If the request fails due to a missing, invalid, or mismatching
#     redirection URI, or if the client identifier is missing or invalid,
#     the authorization server SHOULD inform the resource owner of the
#     error and MUST NOT automatically redirect the user-agent to the
#     invalid redirection URI.
# 
#     Instead the user should be informed of the error by the provider itself.
#     """
#     pass
# 
# class OAuth2Error(Exception):
#     error = None
#     status_code = 400
# 
#     def __init__(self, description=None, uri=None, state=None, status_code=None,
#                  request=None):
#         """
#         description:    A human-readable ASCII [USASCII] text providing
#                         additional information, used to assist the client
#                         developer in understanding the error that occurred.
#                         Values for the "error_description" parameter MUST NOT
#                         include characters outside the set
#                         x20-21 / x23-5B / x5D-7E.
# 
#         uri:    A URI identifying a human-readable web page with information
#                 about the error, used to provide the client developer with
#                 additional information about the error.  Values for the
#                 "error_uri" parameter MUST conform to the URI- Reference
#                 syntax, and thus MUST NOT include characters outside the set
#                 x21 / x23-5B / x5D-7E.
# 
#         state:  A CSRF protection value received from the client.
# 
#         request:  Oauthlib Request object
#         """
#         self.description = description
#         self.uri = uri
#         self.state = state
# 
#         if status_code:
#             self.status_code = status_code
# 
#         if request:
#             self.redirect_uri = request.redirect_uri
#             self.client_id = request.client_id
#             self.scopes = request.scopes
#             self.response_type = request.response_type
#             self.grant_type = request.grant_type
# 
#     def in_uri(self, uri):
#         return add_params_to_uri(uri, self.twotuples)
# 
#     @property
#     def twotuples(self):
#         error = [('error', self.error)]
#         if self.description:
#             error.append(('error_description', self.description))
#         if self.uri:
#             error.append(('error_uri', self.uri))
#         if self.state:
#             error.append(('state', self.state))
#         return error
# 
#     @property
#     def urlencoded(self):
#         return urlencode(self.twotuples)
# 
#     @property
#     def json(self):
#         return json.dumps(dict(self.twotuples))


import functools
from oauthlib.common import log
from ..errors import TemporarilyUnavailableError, ServerError
from ..errors import FatalClientError, OAuth2Error

    @available.setter
    def available(self, available):
        self._available = available

    @property
    def catch_errors(self):
        return self._catch_errors

    @catch_errors.setter
    def catch_errors(self, catch_errors):
        self._catch_errors = catch_errors


def catch_errors_and_unavailability(f):
    @functools.wraps(f)
    def wrapper(endpoint, uri, *args, **kwargs):
        if not endpoint.available:
            e = TemporarilyUnavailableError()
            log.info('Endpoint unavailable, ignoring request %s.' % uri)
            return {}, e.json, 503

        if endpoint.catch_errors:
            try:
                return f(endpoint, uri, *args, **kwargs)
            except OAuth2Error:
                raise
            except FatalClientError:
                raise
            except Exception as e:

# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class TemporarilyUnavailableError(OAuth2Error):
#     """The authorization server is currently unable to handle the request
#     due to a temporary overloading or maintenance of the server.
#     (This error code is needed because a 503 Service Unavailable HTTP
#     status code cannot be returned to the client via a HTTP redirect.)
#     """
#     error = 'temporarily_unavailable'
# 
# class ServerError(OAuth2Error):
#     """The authorization server encountered an unexpected condition that
#     prevented it from fulfilling the request.  (This error code is needed
#     because a 500 Internal Server Error HTTP status code cannot be returned
#     to the client via a HTTP redirect.)
#     """
#     error = 'server_error'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class FatalClientError(OAuth2Error):
#     """Errors during authorization where user should not be redirected back.
# 
#     If the request fails due to a missing, invalid, or mismatching
#     redirection URI, or if the client identifier is missing or invalid,
#     the authorization server SHOULD inform the resource owner of the
#     error and MUST NOT automatically redirect the user-agent to the
#     invalid redirection URI.
# 
#     Instead the user should be informed of the error by the provider itself.
#     """
#     pass
# 
# class OAuth2Error(Exception):
#     error = None
#     status_code = 400
# 
#     def __init__(self, description=None, uri=None, state=None, status_code=None,
#                  request=None):
#         """
#         description:    A human-readable ASCII [USASCII] text providing
#                         additional information, used to assist the client
#                         developer in understanding the error that occurred.
#                         Values for the "error_description" parameter MUST NOT
#                         include characters outside the set
#                         x20-21 / x23-5B / x5D-7E.
# 
#         uri:    A URI identifying a human-readable web page with information
#                 about the error, used to provide the client developer with
#                 additional information about the error.  Values for the
#                 "error_uri" parameter MUST conform to the URI- Reference
#                 syntax, and thus MUST NOT include characters outside the set
#                 x21 / x23-5B / x5D-7E.
# 
#         state:  A CSRF protection value received from the client.
# 
#         request:  Oauthlib Request object
#         """
#         self.description = description
#         self.uri = uri
#         self.state = state
# 
#         if status_code:
#             self.status_code = status_code
# 
#         if request:
#             self.redirect_uri = request.redirect_uri
#             self.client_id = request.client_id
#             self.scopes = request.scopes
#             self.response_type = request.response_type
#             self.grant_type = request.grant_type
# 
#     def in_uri(self, uri):
#         return add_params_to_uri(uri, self.twotuples)
# 
#     @property
#     def twotuples(self):
#         error = [('error', self.error)]
#         if self.description:
#             error.append(('error_description', self.description))
#         if self.uri:
#             error.append(('error_uri', self.uri))
#         if self.state:
#             error.append(('state', self.state))
#         return error
# 
#     @property
#     def urlencoded(self):
#         return urlencode(self.twotuples)
# 
#     @property
#     def json(self):
#         return json.dumps(dict(self.twotuples))


# Path: twitter-winner/oauthlib/oauth2/rfc6749/endpoints/base.py
import functools
from oauthlib.common import log
from ..errors import TemporarilyUnavailableError, ServerError
from ..errors import FatalClientError, OAuth2Error


    @available.setter
    def available(self, available):
        self._available = available

    @property
    def catch_errors(self):
        return self._catch_errors

    @catch_errors.setter
    def catch_errors(self, catch_errors):
        self._catch_errors = catch_errors


def catch_errors_and_unavailability(f):
    @functools.wraps(f)
    def wrapper(endpoint, uri, *args, **kwargs):
        if not endpoint.available:
            e = TemporarilyUnavailableError()
            log.info('Endpoint unavailable, ignoring request %s.' % uri)
            return {}, e.json, 503

        if endpoint.catch_errors:
            try:
                return f(endpoint, uri, *args, **kwargs)
            except OAuth2Error:
                raise
            except FatalClientError:
                raise
            except Exception as e:

                error = ServerError()