<s> import sys <EOL> import pprint <EOL> import json <EOL> import datetime <EOL> import uuid <EOL> import urllib <EOL> import types <EOL> import traceback <EOL> from django . core . urlresolvers import reverse , resolve <EOL> from django . http import HttpResponseRedirect , Http404 , HttpResponseServerError , HttpResponseNotFound <EOL> from django . conf import settings <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . views . decorators . cache import never_cache <EOL> from django . views . debug import ExceptionReporter , get_safe_settings <EOL> from django . template import TemplateDoesNotExist , Context <EOL> from django . template . loader import render_to_string <EOL> from django . utils . encoding import force_bytes <EOL> from django . shortcuts import render <EOL> from splunkdj . decorators . render import render_to <EOL> from splunkdj . utility import make_splunkweb_url <EOL> from urlparse import urlparse <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> error_logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def format ( value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> return value <EOL> if isinstance ( value , ( int , long , str , float , list , dict , tuple , bool , unicode ) ) : <EOL> return value <EOL> return str ( pprint . pformat ( value ) ) <EOL> def get_exception_info ( request ) : <EOL> exc_info = sys . exc_info ( ) <EOL> reporter = ExceptionReporter ( request , * exc_info ) <EOL> ctx = reporter . get_traceback_data ( ) <EOL> exception_type = ctx [ '<STR_LIT>' ] if '<STR_LIT>' in ctx else "<STR_LIT>" <EOL> exception_value = ctx [ '<STR_LIT>' ] if '<STR_LIT>' in ctx else "<STR_LIT>" <EOL> django_version = ctx [ "<STR_LIT>" ] <EOL> python_executable = ctx [ '<STR_LIT>' ] <EOL> python_version = ctx [ '<STR_LIT>' ] <EOL> python_path = ctx [ '<STR_LIT>' ] <EOL> server_time = str ( ctx [ '<STR_LIT>' ] ) <EOL> unicode_hint = None <EOL> if '<STR_LIT>' in ctx : <EOL> unicdoe_hint = ctx [ '<STR_LIT>' ] <EOL> last_frame = None <EOL> if '<STR_LIT>' in ctx : <EOL> frame_info = ctx [ '<STR_LIT>' ] <EOL> last_frame = "<STR_LIT>" % ( frame_info [ '<STR_LIT:filename>' ] , frame_info [ '<STR_LIT>' ] , frame_info [ '<STR_LIT>' ] ) <EOL> loaders = [ ] <EOL> if '<STR_LIT>' in ctx and '<STR_LIT>' in ctx and ctx [ '<STR_LIT>' ] : <EOL> for loader in ctx [ '<STR_LIT>' ] : <EOL> loader_info = { "<STR_LIT:name>" : loader [ '<STR_LIT>' ] , "<STR_LIT>" : [ ] } <EOL> for tmpl in loader [ '<STR_LIT>' ] : <EOL> loader_info [ '<STR_LIT>' ] . append ( { "<STR_LIT:file>" : tmpl [ '<STR_LIT:name>' ] , "<STR_LIT>" : tmpl [ '<STR_LIT>' ] } ) <EOL> loaders . append ( loader_info ) <EOL> template_errors = None <EOL> if '<STR_LIT>' in ctx and ctx [ '<STR_LIT>' ] : <EOL> template_info = ctx [ '<STR_LIT>' ] <EOL> template_errors = { <EOL> "<STR_LIT:name>" : template_info [ '<STR_LIT:name>' ] , <EOL> "<STR_LIT>" : template_info [ '<STR_LIT>' ] , <EOL> "<STR_LIT:message>" : template_info [ '<STR_LIT:message>' ] <EOL> } <EOL> exception_info = [ ] <EOL> if '<STR_LIT>' in ctx : <EOL> frames = ctx [ '<STR_LIT>' ] <EOL> for frame in frames : <EOL> frame_info = { <EOL> "<STR_LIT:filename>" : frame [ '<STR_LIT:filename>' ] , <EOL> "<STR_LIT>" : frame [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : frame [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : frame [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : [ ] <EOL> } <EOL> if '<STR_LIT>' in frame : <EOL> for var in frame [ '<STR_LIT>' ] : <EOL> frame_info [ '<STR_LIT>' ] . append ( { <EOL> "<STR_LIT>" : str ( var [ <NUM_LIT:0> ] ) , <EOL> "<STR_LIT:value>" : format ( var [ <NUM_LIT:1> ] ) <EOL> } ) <EOL> exception_info . append ( frame_info ) <EOL> request_info = { <EOL> "<STR_LIT>" : request . path_info , <EOL> "<STR_LIT>" : request . META [ '<STR_LIT>' ] , <EOL> "<STR_LIT:url>" : request . build_absolute_uri ( ) , <EOL> "<STR_LIT:GET>" : { } , <EOL> "<STR_LIT:POST>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> if hasattr ( request , "<STR_LIT:GET>" ) : <EOL> for key , value in request . GET . iteritems ( ) : <EOL> request_info [ '<STR_LIT:GET>' ] [ key ] = format ( value ) <EOL> if "<STR_LIT>" in ctx : <EOL> for key , value in ctx [ '<STR_LIT>' ] . iteritems ( ) : <EOL> request_info [ '<STR_LIT:POST>' ] [ key ] = format ( value ) <EOL> if hasattr ( request , "<STR_LIT>" ) : <EOL> for key , value in request . FILES . iteritems ( ) : <EOL> request_info [ '<STR_LIT>' ] [ key ] = format ( value ) <EOL> if hasattr ( request , "<STR_LIT>" ) : <EOL> for key , value in request . COOKIES . iteritems ( ) : <EOL> request_info [ '<STR_LIT>' ] [ key ] = format ( value ) <EOL> if hasattr ( request , "<STR_LIT>" ) : <EOL> for key , value in request . META . iteritems ( ) : <EOL> request_info [ '<STR_LIT>' ] [ key ] = format ( value ) <EOL> settings_info = { } <EOL> for key , value in ctx [ '<STR_LIT>' ] . iteritems ( ) : <EOL> settings_info [ key ] = format ( value ) <EOL> ctx [ '<STR_LIT>' ] = errorid = uuid . uuid4 ( ) . hex <EOL> full_info = dict ( <EOL> __time = datetime . datetime . now ( ) . isoformat ( ) , <EOL> __uuid = errorid , <EOL> settings = settings_info , <EOL> request = request_info , <EOL> traceback = exception_info , <EOL> stack = traceback . format_exc ( exc_info [ <NUM_LIT:2> ] ) , <EOL> last_frame = last_frame , <EOL> template_loaders = loaders , <EOL> template_errors = template_errors , <EOL> unicode_hint = unicdoe_hint , <EOL> exception_type = exception_type , <EOL> exception_value = exception_value , <EOL> django_version = django_version , <EOL> python_version = python_version , <EOL> python_executable = python_executable , <EOL> python_path = python_path , <EOL> server_time = server_time <EOL> ) <EOL> return ( errorid , ctx , full_info ) <EOL> def redirector ( request , app , view ) : <EOL> params = { } <EOL> for ( key , val ) in request . GET . iteritems ( ) : <EOL> params [ key ] = val <EOL> full_name = "<STR_LIT>" % ( app , view ) <EOL> if not view or not app : <EOL> logger . error ( "<STR_LIT>" % ( app , view ) ) <EOL> raise Error ( "<STR_LIT>" % ( app , view ) ) <EOL> return HttpResponseRedirect ( reverse ( full_name , kwargs = params ) ) <EOL> def default_search ( request ) : <EOL> app = request . app_name <EOL> lang_code = request . LANGUAGE_CODE <EOL> return HttpResponseRedirect ( make_splunkweb_url ( "<STR_LIT>" % ( lang_code , app ) ) ) <EOL> def default_flashtimeline ( request ) : <EOL> app = request . app_name <EOL> lang_code = request . LANGUAGE_CODE <EOL> return HttpResponseRedirect ( make_splunkweb_url ( "<STR_LIT>" % ( lang_code , app ) ) ) <EOL> @ render_to ( ) <EOL> @ login_required <EOL> def default_template_render ( request , template_name ) : <EOL> app = request . app_name <EOL> template_path = "<STR_LIT>" % ( app , template_name ) <EOL> return { <EOL> "<STR_LIT>" : template_path <EOL> } <EOL> @ never_cache <EOL> def handle404 ( request ) : <EOL> exc_info = sys . exc_info ( ) <EOL> exception = exc_info [ <NUM_LIT:1> ] <EOL> try : <EOL> tried = exception . args [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> except ( IndexError , TypeError , KeyError ) : <EOL> tried = [ ] <EOL> urlconf = getattr ( request , '<STR_LIT>' , settings . ROOT_URLCONF ) <EOL> if isinstance ( urlconf , types . ModuleType ) : <EOL> urlconf = urlconf . __name__ <EOL> c = Context ( { <EOL> '<STR_LIT>' : urlconf , <EOL> '<STR_LIT>' : settings . ROOT_URLCONF , <EOL> '<STR_LIT>' : request . path_info [ <NUM_LIT:1> : ] , <EOL> '<STR_LIT>' : tried , <EOL> '<STR_LIT>' : force_bytes ( exception , errors = '<STR_LIT:replace>' ) , <EOL> '<STR_LIT>' : request , <EOL> '<STR_LIT>' : get_safe_settings ( ) , <EOL> } ) <EOL> return HttpResponseNotFound ( render_to_string ( '<STR_LIT>' , context_instance = c ) ) <EOL> @ never_cache <EOL> def handle500 ( request ) : <EOL> errorid , ctx , exception = get_exception_info ( request ) <EOL> error_logger . error ( json . dumps ( exception , sort_keys = True ) ) <EOL> lang_code = request . LANGUAGE_CODE <EOL> query_args = { <EOL> "<STR_LIT:q>" : '<STR_LIT>' % errorid , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> query_string = urllib . urlencode ( query_args ) <EOL> ctx [ '<STR_LIT>' ] = make_splunkweb_url ( "<STR_LIT>" % ( lang_code , query_string ) ) <EOL> return HttpResponseServerError ( render_to_string ( '<STR_LIT>' , context_instance = Context ( ctx ) ) ) <EOL> @ never_cache <EOL> @ render_to ( '<STR_LIT>' , mimetype = "<STR_LIT>" ) <EOL> @ login_required <EOL> def get_page_config ( request ) : <EOL> referer = request . META . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> app = "<STR_LIT>" <EOL> app_label = "<STR_LIT>" <EOL> if referer : <EOL> try : <EOL> parsed = urlparse ( referer ) <EOL> parsed_path = parsed . path . replace ( "<STR_LIT>" % settings . MOUNT , "<STR_LIT:/>" ) <EOL> resolved = resolve ( parsed_path ) <EOL> app = resolved . app_name <EOL> if app : <EOL> app_label = request . service . apps [ app ] [ "<STR_LIT:label>" ] <EOL> except Exception , e : <EOL> app = app or "<STR_LIT>" <EOL> app_label = app_label or app <EOL> zone_info = request . service . get ( '<STR_LIT>' ) . body . read ( ) <EOL> return { <EOL> "<STR_LIT>" : "<STR_LIT:1>" == request . GET . get ( "<STR_LIT>" , "<STR_LIT:0>" ) , <EOL> "<STR_LIT>" : json . dumps ( { <EOL> "<STR_LIT>" : request . user . is_free , <EOL> "<STR_LIT>" : "<STR_LIT>" % str ( settings . SPLUNK_WEB_MOUNT ) . strip ( "<STR_LIT:/>" ) , <EOL> "<STR_LIT>" : "<STR_LIT>" % str ( settings . RAW_MOUNT ) , <EOL> "<STR_LIT>" : str ( settings . SPLUNK_WEB_PORT ) , <EOL> "<STR_LIT>" : str ( settings . DJANGO_PORT ) , <EOL> "<STR_LIT>" : str ( request . LANGUAGE_CODE ) , <EOL> "<STR_LIT>" : "<STR_LIT:None>" , <EOL> "<STR_LIT>" : str ( request . user . username ) , <EOL> "<STR_LIT>" : str ( request . user . realname ) , <EOL> "<STR_LIT>" : str ( app ) , <EOL> "<STR_LIT>" : str ( app_label ) , <EOL> "<STR_LIT>" : str ( zone_info ) , <EOL> } ) <EOL> } </s>
