# 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
        Percent-decoded value.
    """
    return utf8_decode_if_bytes(unquote_plus(value))


def urlencode_s(query_params, predicate=None):
    """
    Serializes a dictionary of query parameters into a string of query
    parameters, ``name=value`` pairs separated by ``&``, sorted first by
    ``name`` then by ``value`` based on the OAuth percent-encoding
    rules and specification.

    Behaves like :func:`urllib.urlencode` with ``doseq=1``.

    :param query_params:
        Dictionary of query parameters.
    :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 string of query parameters, ``name=value`` pairs separated by ``&``,
        sorted first by ``name`` and then by ``value`` based on the OAuth
        percent-encoding rules and specification.
    """
    return SYMBOL_AMPERSAND.join(

# 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

        Percent-decoded value.
    """
    return utf8_decode_if_bytes(unquote_plus(value))


def urlencode_s(query_params, predicate=None):
    """
    Serializes a dictionary of query parameters into a string of query
    parameters, ``name=value`` pairs separated by ``&``, sorted first by
    ``name`` then by ``value`` based on the OAuth percent-encoding
    rules and specification.

    Behaves like :func:`urllib.urlencode` with ``doseq=1``.

    :param query_params:
        Dictionary of query parameters.
    :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 string of query parameters, ``name=value`` pairs separated by ``&``,
        sorted first by ``name`` and then by ``value`` based on the OAuth
        percent-encoding rules and specification.
    """
    return SYMBOL_AMPERSAND.join(

        key + SYMBOL_EQUAL + value