<commit_before>import oauth2

class RequestValidatorMixin(object):
    '''
    A 'mixin' for OAuth request validation.
    '''
    def __init__(self):
        super(RequestValidatorMixin, self).__init__()

        self.oauth_server = oauth2.Server()
        signature_method = oauth2.SignatureMethod_HMAC_SHA1()
        self.oauth_server.add_signature_method(signature_method)
        self.oauth_consumer = oauth2.Consumer(self.consumer_key,
                self.consumer_secret)

    def is_valid_request(self, request, handle_error = True):
        '''
        Validates an OAuth request using the python-oauth2 library:
            https://github.com/simplegeo/python-oauth2

        '''
        try:
            params = {}
            if len(request.form) > 1:
                for key in request.form:
                    params[key] = request.form[key]

            oauth_request = oauth2.Request.from_request(
                    request.method, 
                    request.url,
                    headers = request.headers,
                    parameters = params)
            self.oauth_server.verify_request(oauth_request, 
                    self.oauth_consumer, {})
        except oauth2.MissingSignature, e:
            if handle_error:
                return False
            else:
                raise e
        # Signature was valid
        return True

    def valid_request(self, request):
        '''
        Check whether the OAuth-signed request is valid and throw error if not.<commit_msg>Simpler way to get parameters<commit_after>import oauth2

class RequestValidatorMixin(object):
    '''
    A 'mixin' for OAuth request validation.
    '''
    def __init__(self):
        super(RequestValidatorMixin, self).__init__()

        self.oauth_server = oauth2.Server()
        signature_method = oauth2.SignatureMethod_HMAC_SHA1()
        self.oauth_server.add_signature_method(signature_method)
        self.oauth_consumer = oauth2.Consumer(self.consumer_key,
                self.consumer_secret)

    def is_valid_request(self, request, handle_error = True):
        '''
        Validates an OAuth request using the python-oauth2 library:
            https://github.com/simplegeo/python-oauth2

        '''
        try:
            params = request.form.copy()

            oauth_request = oauth2.Request.from_request(
                    request.method,
                    request.url,
                    headers = request.headers,
                    parameters = params)
            self.oauth_server.verify_request(oauth_request,
                    self.oauth_consumer, {})
        except oauth2.MissingSignature, e:
            if handle_error:
                return False
            else:
                raise e
        # Signature was valid
        return True

    def valid_request(self, request):
        '''
        Check whether the OAuth-signed request is valid and throw error if not.
{'fraction_non_alphanumeric': 0.07810368349249659, 'fraction_numerical': 0.006480218281036835, 'mean_word_length': 1.8229066410009624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3374049', 'n_tokens_mistral': 799, 'n_tokens_neox': 759, 'n_words': 169}