# Path: twitter-winner/oauthlib/oauth2/rfc6749/endpoints/base.py
# class BaseEndpoint(object):
#     def __init__(self):
#         self._available = True
#         self._catch_errors = False
# 
#     @property
#     def available(self):
#         return self._available
# 
#     @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()
#                 log.warning('Exception caught while processing request, %s.' % e)
#                 return {}, error.json, 500
#         else:
#             return f(endpoint, uri, *args, **kwargs)
#     return wrapper


from oauthlib.common import Request, log
from .base import BaseEndpoint, catch_errors_and_unavailability

    @property
    def default_response_type(self):
        return self._default_response_type

    @property
    def default_response_type_handler(self):
        return self.response_types.get(self.default_response_type)

    @property
    def default_token_type(self):
        return self._default_token_type

    @catch_errors_and_unavailability
    def create_authorization_response(self, uri, http_method='GET', body=None,
            headers=None, scopes=None, credentials=None):
        """Extract response_type and route to the designated handler."""
        request = Request(uri, http_method=http_method, body=body, headers=headers)
        request.scopes = scopes
        # TODO: decide whether this should be a required argument
        request.user = None     # TODO: explain this in docs
        for k, v in (credentials or {}).items():
            setattr(request, k, v)
        response_type_handler = self.response_types.get(
                request.response_type, self.default_response_type_handler)
        log.debug('Dispatching response_type %s request to %r.',
                  request.response_type, response_type_handler)
        return response_type_handler.create_authorization_response(
                        request, self.default_token_type)


# Path: twitter-winner/oauthlib/oauth2/rfc6749/endpoints/base.py
# class BaseEndpoint(object):
#     def __init__(self):
#         self._available = True
#         self._catch_errors = False
# 
#     @property
#     def available(self):
#         return self._available
# 
#     @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()
#                 log.warning('Exception caught while processing request, %s.' % e)
#                 return {}, error.json, 500
#         else:
#             return f(endpoint, uri, *args, **kwargs)
#     return wrapper


# Path: twitter-winner/oauthlib/oauth2/rfc6749/endpoints/authorization.py
from oauthlib.common import Request, log
from .base import BaseEndpoint, catch_errors_and_unavailability


    @property
    def default_response_type(self):
        return self._default_response_type

    @property
    def default_response_type_handler(self):
        return self.response_types.get(self.default_response_type)

    @property
    def default_token_type(self):
        return self._default_token_type

    @catch_errors_and_unavailability
    def create_authorization_response(self, uri, http_method='GET', body=None,
            headers=None, scopes=None, credentials=None):
        """Extract response_type and route to the designated handler."""
        request = Request(uri, http_method=http_method, body=body, headers=headers)
        request.scopes = scopes
        # TODO: decide whether this should be a required argument
        request.user = None     # TODO: explain this in docs
        for k, v in (credentials or {}).items():
            setattr(request, k, v)
        response_type_handler = self.response_types.get(
                request.response_type, self.default_response_type_handler)
        log.debug('Dispatching response_type %s request to %r.',
                  request.response_type, response_type_handler)
        return response_type_handler.create_authorization_response(
                        request, self.default_token_type)


    @catch_errors_and_unavailability