<commit_before># -*- coding: utf-8 -*-

"""
Middleware for authentication.

:Copyright: (c) 2009 Accense Technology, Inc. All rights reserved.
:copyright: (c) 2009 by <NAME> <<EMAIL>>. See AUTHORS
for more details.
:license: BSD, see LICENSE for more details.
"""

from kay import auth
from kay.exceptions import ImproperlyConfigured
from kay.conf import settings
from kay.utils.importlib import import_module
from kay.utils import local

class LazyUser(object):
  def __get__(self, request, obj_type=None):
    if not hasattr(request, '_cached_user'):
      request._cached_user = local.app.auth_backend.get_user(request)
    return request._cached_user


class AuthenticationMiddleware(object):
  def process_request(self, request):
    if not hasattr(request, 'session'):
      raise ImproperlyConfigured(
        "The Django authentication middleware requires session middleware to "
        "be installed. Edit your MIDDLEWARE_CLASSES setting to insert "
        "'kay.sessions.middleware.SessionMiddleware'.")
    request.__class__.user = LazyUser()
    return None


class LazyGoogleUser(object):
  """
  A lazily evaluated object that contains information
  about the current user.
  WARNING: Should not be used for anything but the CURRENT user.
  """  
  def __get__(self, request, obj_type=None):<commit_msg>Changed the way to check if SessionMiddleware is enabled.<commit_after># -*- coding: utf-8 -*-

"""
Middleware for authentication.

:Copyright: (c) 2009 Accense Technology, Inc. All rights reserved.
:copyright: (c) 2009 by <NAME> <<EMAIL>>. See AUTHORS
for more details.
:license: BSD, see LICENSE for more details.
"""

from kay import auth
from kay.exceptions import ImproperlyConfigured
from kay.conf import settings
from kay.utils.importlib import import_module
from kay.utils import local

class LazyUser(object):
  def __get__(self, request, obj_type=None):
    if not hasattr(request, '_cached_user'):
      request._cached_user = local.app.auth_backend.get_user(request)
    return request._cached_user


class AuthenticationMiddleware(object):
  def process_request(self, request):
    if not 'kay.sessions.middleware.SessionMiddleware' in \
          settings.MIDDLEWARE_CLASSES:
      raise ImproperlyConfigured(
        "The Kay authentication middleware requires session middleware to "
        "be installed. Edit your MIDDLEWARE_CLASSES setting to insert "
        "'kay.sessions.middleware.SessionMiddleware'.")
    request.__class__.user = LazyUser()
    return None


class LazyGoogleUser(object):
  """
  A lazily evaluated object that contains information
  about the current user.
  WARNING: Should not be used for anything but the CURRENT user.
  """  
  def __get__(self, request, obj_type=None):
{'fraction_non_alphanumeric': 0.08948137326515705, 'fraction_numerical': 0.006574141709276844, 'mean_word_length': 4.237093690248566, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4295575', 'n_tokens_mistral': 809, 'n_tokens_neox': 770, 'n_words': 262}