<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import os <EOL> import posixpath <EOL> from django . conf import settings <EOL> from django . http import HttpResponseNotFound , Http404 <EOL> from django . contrib . staticfiles import finders <EOL> from django . utils . six . moves . urllib . parse import unquote <EOL> from django . views import static <EOL> from django . views . generic import TemplateView as BaseTemplateView <EOL> from sentry . web . helpers import render_to_response <EOL> FOREVER_CACHE = '<STR_LIT>' <EOL> NEVER_CACHE = '<STR_LIT>' <EOL> def resolve ( path ) : <EOL> normalized_path = posixpath . normpath ( unquote ( path ) ) . lstrip ( '<STR_LIT:/>' ) <EOL> absolute_path = finders . find ( normalized_path ) <EOL> if not absolute_path : <EOL> if path . endswith ( '<STR_LIT:/>' ) or path == '<STR_LIT>' : <EOL> raise Http404 ( "<STR_LIT>" ) <EOL> raise Http404 ( "<STR_LIT>" % path ) <EOL> return os . path . split ( absolute_path ) <EOL> def static_media ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> module = kwargs . get ( '<STR_LIT>' ) <EOL> path = kwargs . get ( '<STR_LIT:path>' , '<STR_LIT>' ) <EOL> version = kwargs . get ( '<STR_LIT:version>' ) <EOL> if module : <EOL> path = '<STR_LIT>' % ( module , path ) <EOL> try : <EOL> document_root , path = resolve ( path ) <EOL> except Http404 : <EOL> return HttpResponseNotFound ( '<STR_LIT>' , content_type = '<STR_LIT>' ) <EOL> if '<STR_LIT>' in request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) and not path . endswith ( '<STR_LIT>' ) and not settings . DEBUG : <EOL> paths = ( path + '<STR_LIT>' , path ) <EOL> else : <EOL> paths = ( path , ) <EOL> for p in paths : <EOL> try : <EOL> response = static . serve ( request , p , document_root = document_root ) <EOL> break <EOL> except Http404 : <EOL> continue <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if path . endswith ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> response [ '<STR_LIT>' ] = '<STR_LIT:*>' <EOL> if version is not None and not settings . DEBUG : <EOL> response [ '<STR_LIT>' ] = FOREVER_CACHE <EOL> else : <EOL> response [ '<STR_LIT>' ] = NEVER_CACHE <EOL> return response <EOL> class TemplateView ( BaseTemplateView ) : <EOL> def render_to_response ( self , context , ** response_kwargs ) : <EOL> return render_to_response ( <EOL> request = self . request , <EOL> template = self . get_template_names ( ) , <EOL> context = context , <EOL> ** response_kwargs <EOL> ) </s>
