<s> from functools import wraps <EOL> from django . http import Http404 <EOL> from django . contrib . auth . models import User <EOL> from repository . models import Repository <EOL> from git . repo import Repo <EOL> def require_existing_repo ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def _decorator ( request , * args , ** kwargs ) : <EOL> try : <EOL> user = User . objects . get ( username = kwargs [ '<STR_LIT:username>' ] ) <EOL> repo = Repository . objects . get ( owner = user , name = kwargs [ '<STR_LIT>' ] ) <EOL> return func ( request , * args , ** kwargs ) <EOL> except : <EOL> raise Http404 ( ) <EOL> return _decorator <EOL> def require_existing_rev ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def _decorator ( request , * args , ** kwargs ) : <EOL> try : <EOL> repo = Repo ( Repo . get_repository_location ( kwargs [ '<STR_LIT:username>' ] , kwargs [ '<STR_LIT>' ] ) ) <EOL> branches = repo . get_branches ( ) <EOL> if '<STR_LIT>' not in kwargs or kwargs [ '<STR_LIT>' ] in branches + [ '<STR_LIT>' ] : <EOL> return func ( request , * args , ** kwargs ) <EOL> else : <EOL> raise Http404 ( ) <EOL> except : <EOL> raise Http404 ( ) <EOL> return _decorator <EOL> def require_access ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def _decorator ( request , * args , ** kwargs ) : <EOL> try : <EOL> user = User . objects . get ( username = kwargs [ '<STR_LIT:username>' ] ) <EOL> repo = Repository . objects . get ( owner = user , name = kwargs [ '<STR_LIT>' ] ) <EOL> if repo . private and request . user . id != user . id : <EOL> raise Http404 ( ) <EOL> else : <EOL> return func ( request , * args , ** kwargs ) <EOL> except : <EOL> raise Http404 ( ) <EOL> return _decorator <EOL> def require_owner_access ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def _decorator ( request , * args , ** kwargs ) : <EOL> if request . user . username != kwargs [ '<STR_LIT:username>' ] : <EOL> raise Http404 ( ) <EOL> else : <EOL> return func ( request , * args , ** kwargs ) <EOL> return _decorator <EOL> def require_valid_readme ( func ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( func ) <EOL> def _decorator ( request , * args , ** kwargs ) : <EOL> if request . path_info . endswith ( '<STR_LIT>' ) or request . path_info . endswith ( '<STR_LIT>' ) : <EOL> return func ( request , * args , ** kwargs ) <EOL> else : <EOL> raise Http404 ( ) <EOL> return _decorator </s>
