<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import json, re, sys

from django.conf import settings
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied
from django.urls import reverse, NoReverseMatch, clear_url_caches, set_urlconf
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.utils.http import urlquote_plus as urlquote, urlunquote_plus as urlunquote
from django.utils import six

try:
    from importlib import import_module
except ImportError:
    from django.utils.importlib import import_module

from allauth.account import app_settings as account_settings
from allauth.socialaccount.models import SocialApp
from allauth.socialaccount.providers import registry
from allauth.socialaccount.providers.fake.views import FakeOAuth2Adapter
from allauth.socialaccount.tests import create_oauth2_tests
from allauth.tests import MockedResponse

from requests.exceptions import HTTPError

from .views import OAuth2Adapter, OAuth2LoginView, proxy_login_callback, MissingParameter


def get_current_site(request=None):
    """Wrapper around ``Site.objects.get_current`` to handle ``Site`` lookups
    by request in Django >= 1.8.
    :param request: optional request object
    :type request: :class:`django.http.HttpRequest`
    """
    # >= django 1.8
    if request and hasattr(Site.objects, '_get_site_by_request'):
        site = Site.objects.get_current(request=request)
    else:
        site = Site.objects.get_current()

    return site


class OAuth2Tests(TestCase):
    def param(self, param, url):
        # Look for a redirect uri
        url = urlunquote(url)
        m = re.match('.*%s=(.*?)[|&.*]' % param, url)<commit_msg>fix py2 tests<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import json, re, sys

from django.conf import settings
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied
from django.urls import reverse, NoReverseMatch, clear_url_caches, set_urlconf
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.utils.http import urlquote_plus as urlquote, urlunquote_plus as urlunquote
from django.utils import six

try:
    from importlib import import_module
except ImportError:
    from django.utils.importlib import import_module

from allauth.account import app_settings as account_settings
from allauth.socialaccount.models import SocialApp
from allauth.socialaccount.providers import registry
from allauth.socialaccount.providers.fake.views import FakeOAuth2Adapter
from allauth.socialaccount.tests import create_oauth2_tests
from allauth.tests import MockedResponse

from requests.exceptions import HTTPError

from .views import OAuth2Adapter, OAuth2LoginView, proxy_login_callback, MissingParameter

def get_current_site(request=None):
    """Wrapper around ``Site.objects.get_current`` to handle ``Site`` lookups
    by request in Django >= 1.8.
    :param request: optional request object
    :type request: :class:`django.http.HttpRequest`
    """
    # >= django 1.8
    if request and hasattr(Site.objects, '_get_site_by_request'):
        site = Site.objects.get_current(request=request)
    else:
        site = Site.objects.get_current()

    return site


def get_current_site(request=None):
    """Wrapper around ``Site.objects.get_current`` to handle ``Site`` lookups
    by request in Django >= 1.8.
    :param request: optional request object
    :type request: :class:`django.http.HttpRequest`
    """
    # >= django 1.8
    if request and hasattr(Site.objects, '_get_site_by_request'):
        site = Site.objects.get_current(request=request)
    else:
        site = Site.objects.get_current()

    return site


class OAuth2Tests(TestCase):
    def param(self, param, url):
        # Look for a redirect uri
        url = urlunquote(url)
        m = re.match('.*%s=(.*?)[|&.*]' % param, url)
{'fraction_non_alphanumeric': 0.08195592286501377, 'fraction_numerical': 0.00573921028466483, 'mean_word_length': 4.593068035943517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4324641', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1218, 'n_words': 373}