# 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
            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):
        raise InsecureTransportError()

    query = urlparse.urlparse(uri).query
    params = dict(urlparse.parse_qsl(query))

    if not 'code' in params:
        raise MissingCodeError("Missing code parameter in response.")

    if state and params.get('state', None) != state:

# 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

            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):
        raise InsecureTransportError()

    query = urlparse.urlparse(uri).query
    params = dict(urlparse.parse_qsl(query))

    if not 'code' in params:
        raise MissingCodeError("Missing code parameter in response.")

    if state and params.get('state', None) != state:

        raise MismatchingStateError()