# Path: restkit/util.py
# def to_bytestring(s):
#     if not isinstance(s, basestring):
#         raise TypeError("value should be a str or unicode")
# 
#     if isinstance(s, unicode):
#         return s.encode('utf-8')
#     return s
# 
# Path: restkit/version.py



import base64
import urllib
import time
import random
import urlparse
import hmac
import binascii
    import sha
    from urlparse import parse_qs, parse_qsl
    from cgi import parse_qs, parse_qsl
from restkit.util import to_bytestring
    from hashlib import sha1
from restkit.version import __version__
    def check(self, request, consumer, token, signature):
        """Returns whether the given signature is the correct signature for
        the given consumer and token signing the given request."""
        built = self.sign(request, consumer, token)
        return built == signature


class SignatureMethod_HMAC_SHA1(SignatureMethod):
    name = 'HMAC-SHA1'

    def signing_base(self, request, consumer, token):
        if not hasattr(request, 'normalized_url') or request.normalized_url is None:
            raise ValueError("Base URL for request is not set.")

        sig = (
            escape(request.method),
            escape(request.normalized_url),
            escape(request.get_normalized_parameters()),
        )

        key = '%s&' % escape(consumer.secret)
        if token:
            key += escape(token.secret)
        raw = '&'.join(sig)
        return to_bytestring(key), raw

    def sign(self, request, consumer, token):
        """Builds the base signature string."""
        key, raw = self.signing_base(request, consumer, token)


# Path: restkit/util.py
# def to_bytestring(s):
#     if not isinstance(s, basestring):
#         raise TypeError("value should be a str or unicode")
# 
#     if isinstance(s, unicode):
#         return s.encode('utf-8')
#     return s
# 
# Path: restkit/version.py



# Path: restkit/oauth2.py
import base64
import urllib
import time
import random
import urlparse
import hmac
import binascii
    import sha
    from urlparse import parse_qs, parse_qsl
    from cgi import parse_qs, parse_qsl
from restkit.util import to_bytestring
    from hashlib import sha1
from restkit.version import __version__

    def check(self, request, consumer, token, signature):
        """Returns whether the given signature is the correct signature for
        the given consumer and token signing the given request."""
        built = self.sign(request, consumer, token)
        return built == signature


class SignatureMethod_HMAC_SHA1(SignatureMethod):
    name = 'HMAC-SHA1'

    def signing_base(self, request, consumer, token):
        if not hasattr(request, 'normalized_url') or request.normalized_url is None:
            raise ValueError("Base URL for request is not set.")

        sig = (
            escape(request.method),
            escape(request.normalized_url),
            escape(request.get_normalized_parameters()),
        )

        key = '%s&' % escape(consumer.secret)
        if token:
            key += escape(token.secret)
        raw = '&'.join(sig)
        return to_bytestring(key), raw

    def sign(self, request, consumer, token):
        """Builds the base signature string."""
        key, raw = self.signing_base(request, consumer, token)


        hashed = hmac.new(to_bytestring(key), raw, sha)