<s> """<STR_LIT>""" <EOL> import warnings <EOL> from django . template import loader , RequestContext <EOL> from django . http import HttpResponse , Http404 <EOL> from django . http import HttpResponseRedirect , HttpResponsePermanentRedirect <EOL> from django . db . models . base import ModelBase <EOL> from django . db . models . manager import Manager <EOL> from django . db . models . query import QuerySet <EOL> from django . core import urlresolvers <EOL> def render_to_response ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> httpresponse_kwargs = { '<STR_LIT>' : kwargs . pop ( '<STR_LIT>' , None ) } <EOL> mimetype = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if mimetype : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" , DeprecationWarning , stacklevel = <NUM_LIT:2> ) <EOL> httpresponse_kwargs [ '<STR_LIT>' ] = mimetype <EOL> return HttpResponse ( loader . render_to_string ( * args , ** kwargs ) , ** httpresponse_kwargs ) <EOL> def render ( request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> httpresponse_kwargs = { <EOL> '<STR_LIT>' : kwargs . pop ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT:status>' : kwargs . pop ( '<STR_LIT:status>' , None ) , <EOL> } <EOL> if '<STR_LIT>' in kwargs : <EOL> context_instance = kwargs . pop ( '<STR_LIT>' ) <EOL> if kwargs . get ( '<STR_LIT>' , None ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> current_app = kwargs . pop ( '<STR_LIT>' , None ) <EOL> context_instance = RequestContext ( request , current_app = current_app ) <EOL> kwargs [ '<STR_LIT>' ] = context_instance <EOL> return HttpResponse ( loader . render_to_string ( * args , ** kwargs ) , <EOL> ** httpresponse_kwargs ) <EOL> def redirect ( to , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if kwargs . pop ( '<STR_LIT>' , False ) : <EOL> redirect_class = HttpResponsePermanentRedirect <EOL> else : <EOL> redirect_class = HttpResponseRedirect <EOL> return redirect_class ( resolve_url ( to , * args , ** kwargs ) ) <EOL> def _get_queryset ( klass ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( klass , QuerySet ) : <EOL> return klass <EOL> elif isinstance ( klass , Manager ) : <EOL> manager = klass <EOL> elif isinstance ( klass , ModelBase ) : <EOL> manager = klass . _default_manager <EOL> else : <EOL> klass__name = klass . __name__ if isinstance ( klass , type ) else klass . __class__ . __name__ <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % klass__name ) <EOL> return manager . all ( ) <EOL> def get_object_or_404 ( klass , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> queryset = _get_queryset ( klass ) <EOL> try : <EOL> return queryset . get ( * args , ** kwargs ) <EOL> except queryset . model . DoesNotExist : <EOL> raise Http404 ( '<STR_LIT>' % queryset . model . _meta . object_name ) <EOL> def get_list_or_404 ( klass , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> queryset = _get_queryset ( klass ) <EOL> obj_list = list ( queryset . filter ( * args , ** kwargs ) ) <EOL> if not obj_list : <EOL> raise Http404 ( '<STR_LIT>' % queryset . model . _meta . object_name ) <EOL> return obj_list <EOL> def resolve_url ( to , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( to , '<STR_LIT>' ) : <EOL> return to . get_absolute_url ( ) <EOL> try : <EOL> return urlresolvers . reverse ( to , args = args , kwargs = kwargs ) <EOL> except urlresolvers . NoReverseMatch : <EOL> if callable ( to ) : <EOL> raise <EOL> if '<STR_LIT:/>' not in to and '<STR_LIT:.>' not in to : <EOL> raise <EOL> return to </s>
