<s> """<STR_LIT>""" <EOL> from functools import wraps <EOL> import hashlib <EOL> import hmac <EOL> import json <EOL> from django . conf import settings <EOL> from django . http import HttpResponse , JsonResponse <EOL> from django . shortcuts import redirect <EOL> from buildservice . models import OAuthToken <EOL> def oauth_token_required ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def inner ( request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> _ = request . user . oauth_token <EOL> except ( AttributeError , OAuthToken . DoesNotExist ) : <EOL> return redirect ( '<STR_LIT>' ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return inner <EOL> def signature_required ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def inner ( request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> signature = "<STR_LIT>" % hmac . new ( <EOL> settings . GITHUB_HOOK_SECRET . encode ( '<STR_LIT:utf-8>' ) , <EOL> request . body , <EOL> hashlib . sha1 <EOL> ) . hexdigest ( ) <EOL> if signature != request . META . get ( '<STR_LIT>' ) : <EOL> return HttpResponse ( status = <NUM_LIT> , content = "<STR_LIT>" ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return inner <EOL> def anonymous_user_required ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def inner ( request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if request . user . is_authenticated ( ) : <EOL> return redirect ( '<STR_LIT>' ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return inner <EOL> def require_json ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def wrapped ( request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> request . json = json . loads ( request . body or '<STR_LIT:{}>' ) <EOL> except ( ValueError , TypeError ) : <EOL> return JsonResponse ( data = { '<STR_LIT:error>' : '<STR_LIT>' } , status = <NUM_LIT> ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return wrapped <EOL> def require_api_key ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def wrapped ( request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if request . GET . get ( '<STR_LIT>' ) != settings . BUILDSERVICE_API_KEY : <EOL> return HttpResponse ( status = <NUM_LIT> , content = '<STR_LIT>' ) <EOL> return func ( request , * args , ** kwargs ) <EOL> return wrapped </s>
