# Path: pyoauth/_compat.py
# def unquote_plus(v):
# 
# Path: pyoauth/constants.py
# SYMBOL_QUESTION_MARK = b("?")
# 
# SYMBOL_AMPERSAND = b("&")
# 
# SYMBOL_EQUAL = b("=")
# 
# OAUTH_PARAM_PREFIX = "oauth_"
# 
# OAUTH_VALUE_CALLBACK_OOB = b("oob")
# 
# OAUTH_PARAM_CONSUMER_SECRET = "oauth_consumer_secret"
# 
# OAUTH_PARAM_TOKEN_SECRET = "oauth_token_secret"
# 
# SYMBOL_EMPTY_BYTES = b("")
# 
# Path: pyoauth/error.py
# class InvalidQueryParametersError(OAuthError):
#     """
#     Raised when a query parameter is invalid.
#     """
#     pass
# 
# class InsecureOAuthParametersError(OAuthError):
#     """
#     Raised when an OAuth confidential parameter is passed into protocol
#     parameters.
#     """
#     pass
# 
# class InvalidOAuthParametersError(OAuthError):
#     """
#     Raised when invalid protocol parameters are detected.
#     """
#     pass
# 
# class InsecureOAuthUrlError(OAuthError):
#     """
#     Raised when an insecure (non-HTTPS) URL is detected for requesting OAuth
#     credentials.
#     """
#     pass
# 
# class InvalidUrlError(OAuthError):
#     """
#     Raised when a specified URL is invalid for consumption by a routine.
#     """
#     pass


import logging
from mom.builtins import is_sequence, bytes, is_bytes_or_unicode, is_bytes
from mom.codec.text import utf8_encode_if_unicode, \
    utf8_encode, utf8_decode_if_bytes
from mom.functional import select_dict, map_dict
from mom.builtins import b
from pyoauth._compat import urlparse, urlunparse, parse_qs as _parse_qs, \
    quote, \
    unquote_plus
from pyoauth.constants import SYMBOL_QUESTION_MARK, \
    SYMBOL_AMPERSAND, SYMBOL_EQUAL, OAUTH_PARAM_PREFIX, \
    OAUTH_VALUE_CALLBACK_OOB, OAUTH_PARAM_CONSUMER_SECRET, \
    OAUTH_PARAM_TOKEN_SECRET, SYMBOL_EMPTY_BYTES
from pyoauth.error import InvalidQueryParametersError, \
    InsecureOAuthParametersError, \
    InvalidOAuthParametersError, \
    InsecureOAuthUrlError, \
    InvalidUrlError
        """
        Allows only valid oauth parameters.

        Raises an error if multiple values are specified.

        :param name:
            Protocol parameter name.
        :param value:
            Protocol parameter value.
        :returns:
            ``True`` if the parameter should be included; ``False`` otherwise.
        """
        name = utf8_decode_if_bytes(name)
        if name.startswith(OAUTH_PARAM_PREFIX):
            # This gets rid of "realm" or any non-OAuth param.
            if len(value) > 1:
                # Multiple values for a protocol parameter are not allowed.
                # We don't silently discard values because failing fast
                # is better than simply logging and waiting for the user
                # to figure it out all by herself.
                #
                # See Making Requests
                # (http://tools.ietf.org/html/rfc5849#section-3.1)
                # Point 2. Each parameter MUST NOT appear more than once per
                # request, so we disallow multiple values for a protocol
                # parameter.
                raise InvalidOAuthParametersError(
                    "Multiple protocol parameter values found %r=%r" \
                    % (name, value))
            elif name in (OAUTH_PARAM_CONSUMER_SECRET,

# Path: pyoauth/_compat.py
# def unquote_plus(v):
# 
# Path: pyoauth/constants.py
# SYMBOL_QUESTION_MARK = b("?")
# 
# SYMBOL_AMPERSAND = b("&")
# 
# SYMBOL_EQUAL = b("=")
# 
# OAUTH_PARAM_PREFIX = "oauth_"
# 
# OAUTH_VALUE_CALLBACK_OOB = b("oob")
# 
# OAUTH_PARAM_CONSUMER_SECRET = "oauth_consumer_secret"
# 
# OAUTH_PARAM_TOKEN_SECRET = "oauth_token_secret"
# 
# SYMBOL_EMPTY_BYTES = b("")
# 
# Path: pyoauth/error.py
# class InvalidQueryParametersError(OAuthError):
#     """
#     Raised when a query parameter is invalid.
#     """
#     pass
# 
# class InsecureOAuthParametersError(OAuthError):
#     """
#     Raised when an OAuth confidential parameter is passed into protocol
#     parameters.
#     """
#     pass
# 
# class InvalidOAuthParametersError(OAuthError):
#     """
#     Raised when invalid protocol parameters are detected.
#     """
#     pass
# 
# class InsecureOAuthUrlError(OAuthError):
#     """
#     Raised when an insecure (non-HTTPS) URL is detected for requesting OAuth
#     credentials.
#     """
#     pass
# 
# class InvalidUrlError(OAuthError):
#     """
#     Raised when a specified URL is invalid for consumption by a routine.
#     """
#     pass


# Path: pyoauth/url.py
import logging
from mom.builtins import is_sequence, bytes, is_bytes_or_unicode, is_bytes
from mom.codec.text import utf8_encode_if_unicode, \
    utf8_encode, utf8_decode_if_bytes
from mom.functional import select_dict, map_dict
from mom.builtins import b
from pyoauth._compat import urlparse, urlunparse, parse_qs as _parse_qs, \
    quote, \
    unquote_plus
from pyoauth.constants import SYMBOL_QUESTION_MARK, \
    SYMBOL_AMPERSAND, SYMBOL_EQUAL, OAUTH_PARAM_PREFIX, \
    OAUTH_VALUE_CALLBACK_OOB, OAUTH_PARAM_CONSUMER_SECRET, \
    OAUTH_PARAM_TOKEN_SECRET, SYMBOL_EMPTY_BYTES
from pyoauth.error import InvalidQueryParametersError, \
    InsecureOAuthParametersError, \
    InvalidOAuthParametersError, \
    InsecureOAuthUrlError, \
    InvalidUrlError

        """
        Allows only valid oauth parameters.

        Raises an error if multiple values are specified.

        :param name:
            Protocol parameter name.
        :param value:
            Protocol parameter value.
        :returns:
            ``True`` if the parameter should be included; ``False`` otherwise.
        """
        name = utf8_decode_if_bytes(name)
        if name.startswith(OAUTH_PARAM_PREFIX):
            # This gets rid of "realm" or any non-OAuth param.
            if len(value) > 1:
                # Multiple values for a protocol parameter are not allowed.
                # We don't silently discard values because failing fast
                # is better than simply logging and waiting for the user
                # to figure it out all by herself.
                #
                # See Making Requests
                # (http://tools.ietf.org/html/rfc5849#section-3.1)
                # Point 2. Each parameter MUST NOT appear more than once per
                # request, so we disallow multiple values for a protocol
                # parameter.
                raise InvalidOAuthParametersError(
                    "Multiple protocol parameter values found %r=%r" \
                    % (name, value))
            elif name in (OAUTH_PARAM_CONSUMER_SECRET,

                          OAUTH_PARAM_TOKEN_SECRET, ):