# Path: pyoauth/_compat.py
# def unquote_plus(v):
# 
# Path: pyoauth/constants.py
# OPENID_MODE_CHECK_AUTHENTICATION = "check_authentication"
# 
# HEADER_CONTENT_TYPE = "content-type"
# 
# HTTP_POST = b("POST")
# 
# OAUTH_VALUE_CALLBACK_OOB = b("oob")
# 
# OAUTH_PARAM_TOKEN = "oauth_token"
# 
# OAUTH_PARAM_VERIFIER = "oauth_verifier"
# 
# OPENID_MODE_CHECKID_SETUP = "checkid_setup"
# 
# OPENID_AX_MODE_FETCH_REQUEST = "fetch_request"
# 
# Path: pyoauth/url.py
# def url_add_query(url, query, predicate=None):
#     """
#     Adds additional query parameters to a URL while preserving existing ones.
# 
#     The URL will be normalized according to the OAuth specification with the
#     exception that the URL fragment is preserved.
# 
#     :param url:
#         The URL to add the additional query parameters to.
#     :param query:
#         The additional query parameters as a dictionary object or a query
#         string.
#     :param predicate:
#         A callback that will be called for each query parameter and should
#         return ``False`` or a falsy value if that parameter should not be
#         included. By default, all query parameters are included. The function
#         takes the following method signature::
# 
#             def predicate(name, value):
#                 return is_name_allowed(name) and is_value_allowed(value)
#     :returns:
#         A normalized URL with the fragment and existing query parameters
#         preserved and with the extra query parameters added.
#     """
#     scheme, netloc, path, params, query_s, fragment = urlparse_normalized(url)
# 
#     query_d = query_add(query_s, query)
#     query_s = urlencode_s(query_d, predicate)
#     return urlunparse((scheme, netloc, path, params, query_s, fragment))
# 
# Path: pyoauth/http.py
# class RequestAdapter(object):
#     """Adaptor HTTP Request class.
# 
#     Framework implementers can subclass this class and must use it with
#     the client methods for them to work.
#     """
#     def __init__(self, method, url, body=None, headers=None):
#         self._method = method.upper()
#         self._url = url
#         self._body = body
#         self._headers = headers
# 
#     @property
#     def method(self):
#         """
#         Determines the HTTP request method.
#         """
#         return self._method
# 
#     @property
#     def url(self):
#         """
#         Determines the URL.
#         """
#         return self._url
# 
#     @property
#     def payload(self):
#         """
#         Payload for the request.
#         """
#         return self._body
# 
#     @property
#     def body(self):
#         """Payload for the request."""
#         return self._body
# 
#     @property
#     def content(self):
#         """Payload for the request."""
#         return self._body
# 
#     @property
#     def headers(self):
#         """Dictionary of headers."""
#         return self._headers
# 
# CONTENT_TYPE_FORM_URLENCODED = b("application/x-www-form-urlencoded")


import logging
from urllib import urlencode
from mom.functional import select_dict, map_dict
from pyoauth._compat import urljoin
from pyoauth.constants import OPENID_MODE_CHECK_AUTHENTICATION, \
    HEADER_CONTENT_TYPE, HTTP_POST, OAUTH_VALUE_CALLBACK_OOB, \
    OAUTH_PARAM_TOKEN, OAUTH_PARAM_VERIFIER, OPENID_MODE_CHECKID_SETUP, \
    OPENID_AX_MODE_FETCH_REQUEST
from pyoauth.url import url_add_query
from pyoauth.http import RequestAdapter, CONTENT_TYPE_FORM_URLENCODED
            The URL to redirect to after authentication.
        :param ax_attrs:
            List of Attribute Exchange attributes to be fetched.
        :returns:
            None
        """
        ax_attrs = ax_attrs or ("name", "email",
                                "language", "username", "country")
        callback_uri = callback_uri or self.adapter_request_path
        args = self._openid_args(callback_uri, ax_attrs, oauth_scope)
        self.adapter_redirect(url_add_query(self._OPENID_ENDPOINT, args))

    def get_authenticated_user(self, callback):
        """
        Fetches the authenticated user data upon redirect.

        This method should be called by the handler that handles the callback
        URL to which the service redirects when the authenticate_redirect()
        or authorize_redirect() methods are called.

        :param callback:
            A function that is called after the authentication attempt. It is
            called passing a dictionary with the requested user attributes or
            None if the authentication failed.
        """
        request_arguments = self.adapter_request_params
        http = self.adapter_http_client

        # Verify the OpenID response via direct request to the OP
        args = map_dict(lambda k, v: (k, v[-1]), request_arguments)

# Path: pyoauth/_compat.py
# def unquote_plus(v):
# 
# Path: pyoauth/constants.py
# OPENID_MODE_CHECK_AUTHENTICATION = "check_authentication"
# 
# HEADER_CONTENT_TYPE = "content-type"
# 
# HTTP_POST = b("POST")
# 
# OAUTH_VALUE_CALLBACK_OOB = b("oob")
# 
# OAUTH_PARAM_TOKEN = "oauth_token"
# 
# OAUTH_PARAM_VERIFIER = "oauth_verifier"
# 
# OPENID_MODE_CHECKID_SETUP = "checkid_setup"
# 
# OPENID_AX_MODE_FETCH_REQUEST = "fetch_request"
# 
# Path: pyoauth/url.py
# def url_add_query(url, query, predicate=None):
#     """
#     Adds additional query parameters to a URL while preserving existing ones.
# 
#     The URL will be normalized according to the OAuth specification with the
#     exception that the URL fragment is preserved.
# 
#     :param url:
#         The URL to add the additional query parameters to.
#     :param query:
#         The additional query parameters as a dictionary object or a query
#         string.
#     :param predicate:
#         A callback that will be called for each query parameter and should
#         return ``False`` or a falsy value if that parameter should not be
#         included. By default, all query parameters are included. The function
#         takes the following method signature::
# 
#             def predicate(name, value):
#                 return is_name_allowed(name) and is_value_allowed(value)
#     :returns:
#         A normalized URL with the fragment and existing query parameters
#         preserved and with the extra query parameters added.
#     """
#     scheme, netloc, path, params, query_s, fragment = urlparse_normalized(url)
# 
#     query_d = query_add(query_s, query)
#     query_s = urlencode_s(query_d, predicate)
#     return urlunparse((scheme, netloc, path, params, query_s, fragment))
# 
# Path: pyoauth/http.py
# class RequestAdapter(object):
#     """Adaptor HTTP Request class.
# 
#     Framework implementers can subclass this class and must use it with
#     the client methods for them to work.
#     """
#     def __init__(self, method, url, body=None, headers=None):
#         self._method = method.upper()
#         self._url = url
#         self._body = body
#         self._headers = headers
# 
#     @property
#     def method(self):
#         """
#         Determines the HTTP request method.
#         """
#         return self._method
# 
#     @property
#     def url(self):
#         """
#         Determines the URL.
#         """
#         return self._url
# 
#     @property
#     def payload(self):
#         """
#         Payload for the request.
#         """
#         return self._body
# 
#     @property
#     def body(self):
#         """Payload for the request."""
#         return self._body
# 
#     @property
#     def content(self):
#         """Payload for the request."""
#         return self._body
# 
#     @property
#     def headers(self):
#         """Dictionary of headers."""
#         return self._headers
# 
# CONTENT_TYPE_FORM_URLENCODED = b("application/x-www-form-urlencoded")


# Path: pyoauth/oauth1/client/mixins.py
import logging
from urllib import urlencode
from mom.functional import select_dict, map_dict
from pyoauth._compat import urljoin
from pyoauth.constants import OPENID_MODE_CHECK_AUTHENTICATION, \
    HEADER_CONTENT_TYPE, HTTP_POST, OAUTH_VALUE_CALLBACK_OOB, \
    OAUTH_PARAM_TOKEN, OAUTH_PARAM_VERIFIER, OPENID_MODE_CHECKID_SETUP, \
    OPENID_AX_MODE_FETCH_REQUEST
from pyoauth.url import url_add_query
from pyoauth.http import RequestAdapter, CONTENT_TYPE_FORM_URLENCODED

            The URL to redirect to after authentication.
        :param ax_attrs:
            List of Attribute Exchange attributes to be fetched.
        :returns:
            None
        """
        ax_attrs = ax_attrs or ("name", "email",
                                "language", "username", "country")
        callback_uri = callback_uri or self.adapter_request_path
        args = self._openid_args(callback_uri, ax_attrs, oauth_scope)
        self.adapter_redirect(url_add_query(self._OPENID_ENDPOINT, args))

    def get_authenticated_user(self, callback):
        """
        Fetches the authenticated user data upon redirect.

        This method should be called by the handler that handles the callback
        URL to which the service redirects when the authenticate_redirect()
        or authorize_redirect() methods are called.

        :param callback:
            A function that is called after the authentication attempt. It is
            called passing a dictionary with the requested user attributes or
            None if the authentication failed.
        """
        request_arguments = self.adapter_request_params
        http = self.adapter_http_client

        # Verify the OpenID response via direct request to the OP
        args = map_dict(lambda k, v: (k, v[-1]), request_arguments)

        args["openid.mode"] = OPENID_MODE_CHECK_AUTHENTICATION