<commit_before>import time
import json
import urllib
from oauth import oauth
from base64 import b64decode, b64encode
from django.conf import settings
from blti.crypto import aes128cbc


class BLTIException(Exception):
    pass


class BLTI(object):
    """
    Basic LTI Validator
    """
    def validate(self, request):
        try:
            self._oauth_server = oauth.OAuthServer(data_store=BLTIDataStore())
            self._oauth_server.add_signature_method(
                oauth.OAuthSignatureMethod_HMAC_SHA1())

            params = None
            body = request.read()
            if body and len(body):
                params = dict((k, v) for k, v in [tuple(
                    map(urllib.unquote_plus, kv.split('='))
                ) for kv in body.split('&')])
            else:
                raise BLTIException('Missing or malformed parameter or value')

            oauth_request = oauth.OAuthRequest.from_request(
                request.method,
                request.build_absolute_uri(),
                headers=request.META,
                parameters=params
            )
            consumer = self._oauth_server._get_consumer(oauth_request)
            self._oauth_server._check_signature(oauth_request, consumer, None)
            return oauth_request.get_nonoauth_parameters()

        except oauth.OAuthError as err:
            raise BLTIException('%s' % err)<commit_msg>breaks out oauth validation method<commit_after>import time
import json
import urllib
from oauth import oauth
from base64 import b64decode, b64encode
from django.conf import settings
from blti.crypto import aes128cbc


class BLTIException(Exception):
    pass


class BLTI(object):
    """
    Basic LTI Validator
    """
    def validate(self, request):
        params = {}
        body = request.read()
        if body and len(body):
            params = dict((k, v) for k, v in [tuple(
                map(urllib.unquote_plus, kv.split('='))
            ) for kv in body.split('&')])
        else:
            raise BLTIException('Missing or malformed parameter or value')

        return self.oauth_validate(request, params=params)

    def oauth_validate(self, request, params={}):
        try:
            self._oauth_server = oauth.OAuthServer(data_store=BLTIDataStore())
            self._oauth_server.add_signature_method(
                oauth.OAuthSignatureMethod_HMAC_SHA1())

            oauth_request = oauth.OAuthRequest.from_request(
                request.method,
                request.build_absolute_uri(),
                headers=request.META,
                parameters=params
            )

            if oauth_request:
                consumer = self._oauth_server._get_consumer(oauth_request)
                self._oauth_server._check_signature(oauth_request, consumer, None)
                return oauth_request.get_nonoauth_parameters()

            raise BLTIException('Invalid OAuth Request')

        except oauth.OAuthError as err:
            raise BLTIException('%s' % err)
{'fraction_non_alphanumeric': 0.0828363154406892, 'fraction_numerical': 0.0066269052352551355, 'mean_word_length': 2.1778947368421053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4691260', 'n_tokens_mistral': 870, 'n_tokens_neox': 825, 'n_words': 193}