# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# def raise_from_error(error, params=None):
#     import inspect
#     import sys
#     kwargs = {
#         'description': params.get('error_description'),
#         'uri': params.get('error_uri'),
#         'state': params.get('state')
#     }
#     for _, cls in  inspect.getmembers(sys.modules[__name__], inspect.isclass):
#         if cls.error == error:
#             raise cls(**kwargs)
# 
# class MissingTokenError(OAuth2Error):
#     error = 'missing_token'
# 
# class MissingTokenTypeError(OAuth2Error):
#     error = 'missing_token_type'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class MismatchingStateError(OAuth2Error):
#     error = 'mismatching_state'
#     description = 'CSRF Warning! State not equal in request and response.'
# 
# class MissingCodeError(OAuth2Error):
#     error = 'missing_code'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class InsecureTransportError(OAuth2Error):
#     error = 'insecure_transport'
#     description = 'OAuth 2 MUST utilize https.'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/utils.py
# def list_to_scope(scope):
#     """Convert a list of scopes to a space separated string."""
#     if isinstance(scope, unicode_type) or scope is None:
#         return scope
#     elif isinstance(scope, list):
#         return " ".join([unicode_type(s) for s in scope])
#     else:
#         raise ValueError("Invalid scope, must be string or list.")
# 
# def scope_to_list(scope):
#     """Convert a space separated string to a list of scopes."""
#     if isinstance(scope, list):
#         return [unicode_type(s) for s in scope]
#     elif scope is None:
#         return None
#     else:
#         return scope.split(" ")
# 
# def is_secure_transport(uri):
#     """Check if the uri is over ssl."""
#     if os.environ.get('OAUTHLIB_INSECURE_TRANSPORT'):
#         return True
#     return uri.lower().startswith('https://')


import json
import time
    import urlparse
    import urllib.parse as urlparse
from oauthlib.common import add_params_to_uri, add_params_to_qs, unicode_type
from .errors import raise_from_error, MissingTokenError, MissingTokenTypeError
from .errors import MismatchingStateError, MissingCodeError
from .errors import InsecureTransportError
from .utils import list_to_scope, scope_to_list, is_secure_transport
    **code**
            REQUIRED.  The authorization code generated by the
            authorization server.  The authorization code MUST expire
            shortly after it is issued to mitigate the risk of leaks.  A
            maximum authorization code lifetime of 10 minutes is
            RECOMMENDED.  The client MUST NOT use the authorization code
            more than once.  If an authorization code is used more than
            once, the authorization server MUST deny the request and SHOULD
            revoke (when possible) all tokens previously issued based on
            that authorization code.  The authorization code is bound to
            the client identifier and redirection URI.

    **state**
            REQUIRED if the "state" parameter was present in the client
            authorization request.  The exact value received from the
            client.

    :param uri: The full redirect URL back to the client.
    :param state: The state parameter from the authorization request.

    For example, the authorization server redirects the user-agent by
    sending the following HTTP response:

    .. code-block:: http

        HTTP/1.1 302 Found
        Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA
                &state=xyz

    """

# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# def raise_from_error(error, params=None):
#     import inspect
#     import sys
#     kwargs = {
#         'description': params.get('error_description'),
#         'uri': params.get('error_uri'),
#         'state': params.get('state')
#     }
#     for _, cls in  inspect.getmembers(sys.modules[__name__], inspect.isclass):
#         if cls.error == error:
#             raise cls(**kwargs)
# 
# class MissingTokenError(OAuth2Error):
#     error = 'missing_token'
# 
# class MissingTokenTypeError(OAuth2Error):
#     error = 'missing_token_type'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class MismatchingStateError(OAuth2Error):
#     error = 'mismatching_state'
#     description = 'CSRF Warning! State not equal in request and response.'
# 
# class MissingCodeError(OAuth2Error):
#     error = 'missing_code'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/errors.py
# class InsecureTransportError(OAuth2Error):
#     error = 'insecure_transport'
#     description = 'OAuth 2 MUST utilize https.'
# 
# Path: twitter-winner/oauthlib/oauth2/rfc6749/utils.py
# def list_to_scope(scope):
#     """Convert a list of scopes to a space separated string."""
#     if isinstance(scope, unicode_type) or scope is None:
#         return scope
#     elif isinstance(scope, list):
#         return " ".join([unicode_type(s) for s in scope])
#     else:
#         raise ValueError("Invalid scope, must be string or list.")
# 
# def scope_to_list(scope):
#     """Convert a space separated string to a list of scopes."""
#     if isinstance(scope, list):
#         return [unicode_type(s) for s in scope]
#     elif scope is None:
#         return None
#     else:
#         return scope.split(" ")
# 
# def is_secure_transport(uri):
#     """Check if the uri is over ssl."""
#     if os.environ.get('OAUTHLIB_INSECURE_TRANSPORT'):
#         return True
#     return uri.lower().startswith('https://')


# Path: twitter-winner/oauthlib/oauth2/rfc6749/parameters.py
import json
import time
    import urlparse
    import urllib.parse as urlparse
from oauthlib.common import add_params_to_uri, add_params_to_qs, unicode_type
from .errors import raise_from_error, MissingTokenError, MissingTokenTypeError
from .errors import MismatchingStateError, MissingCodeError
from .errors import InsecureTransportError
from .utils import list_to_scope, scope_to_list, is_secure_transport

    **code**
            REQUIRED.  The authorization code generated by the
            authorization server.  The authorization code MUST expire
            shortly after it is issued to mitigate the risk of leaks.  A
            maximum authorization code lifetime of 10 minutes is
            RECOMMENDED.  The client MUST NOT use the authorization code
            more than once.  If an authorization code is used more than
            once, the authorization server MUST deny the request and SHOULD
            revoke (when possible) all tokens previously issued based on
            that authorization code.  The authorization code is bound to
            the client identifier and redirection URI.

    **state**
            REQUIRED if the "state" parameter was present in the client
            authorization request.  The exact value received from the
            client.

    :param uri: The full redirect URL back to the client.
    :param state: The state parameter from the authorization request.

    For example, the authorization server redirects the user-agent by
    sending the following HTTP response:

    .. code-block:: http

        HTTP/1.1 302 Found
        Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA
                &state=xyz

    """

    if not is_secure_transport(uri):