<commit_before>from functools import wraps
from django.contrib.auth.models import AnonymousUser
from django.http import HttpResponse

from auth_mac.models import Nonce, Credentials
from auth_mac.tools import Validator

def require_credentials(f):
  @wraps(f)
  def wrapper(request, *args, **kwargs):
    """pull the credentials out of the request, and verify them"""
    if not request.META.has_key("HTTP_AUTHORIZATION"):
      response = HttpResponse(status=401)
      response['WWW-Authenticate'] =  'MAC'
      return response
    # Build the validation object
    authstr = request.META["HTTP_AUTHORIZATION"]
    v = Validator(authstr)
    if not v.validate():
      response = HttpResponse(status=401)
      if v.error:
        response['WWW-Authenticate'] =  'MAC error="{0}"'.format(v.error)
      else:
        response['WWW-Authenticate'] =  'MAC'
      return response

    return f(request, *args, **kwargs)
  return wrapper


# def extract(d, keys):
#   "Extract a subset of a dictionary"
#   return dict((k, d[k]) for k in keys if k in d)<commit_msg>Pass the request object to the validator<commit_after>from functools import wraps
from django.contrib.auth.models import AnonymousUser
from django.http import HttpResponse

from auth_mac.models import Nonce, Credentials
from auth_mac.tools import Validator

def require_credentials(f):
  @wraps(f)
  def wrapper(request, *args, **kwargs):
    """pull the credentials out of the request, and verify them"""
    if not request.META.has_key("HTTP_AUTHORIZATION"):
      response = HttpResponse(status=401)
      response['WWW-Authenticate'] =  'MAC'
      return response
    # Build the validation object
    authstr = request.META["HTTP_AUTHORIZATION"]
    v = Validator(authstr, request)
    if not v.validate():
      response = HttpResponse(status=401)
      if v.error:
        response['WWW-Authenticate'] =  'MAC error="{0}"'.format(v.error)
      else:
        response['WWW-Authenticate'] =  'MAC'
      return response

    return f(request, *args, **kwargs)
  return wrapper


# def extract(d, keys):
#   "Extract a subset of a dictionary"
#   return dict((k, d[k]) for k in keys if k in d)
{'fraction_non_alphanumeric': 0.11054579093432007, 'fraction_numerical': 0.0064754856614246065, 'mean_word_length': 3.7021739130434783, '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': '5682868', 'n_tokens_mistral': 678, 'n_tokens_neox': 662, 'n_words': 198}