<s> """<STR_LIT>""" <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> import sys , urlparse , pprint , traceback <EOL> from net import websafe <EOL> from template import Template <EOL> from utils import sendmail , safestr <EOL> import webapi as web <EOL> import os , os . path <EOL> whereami = os . path . join ( os . getcwd ( ) , __file__ ) <EOL> whereami = os . path . sep . join ( whereami . split ( os . path . sep ) [ : - <NUM_LIT:1> ] ) <EOL> djangoerror_t = """<STR_LIT>""" <EOL> djangoerror_r = None <EOL> def djangoerror ( ) : <EOL> def _get_lines_from_file ( filename , lineno , context_lines ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> source = open ( filename ) . readlines ( ) <EOL> lower_bound = max ( <NUM_LIT:0> , lineno - context_lines ) <EOL> upper_bound = lineno + context_lines <EOL> pre_context = [ line . strip ( '<STR_LIT:\n>' ) for line in source [ lower_bound : lineno ] ] <EOL> context_line = source [ lineno ] . strip ( '<STR_LIT:\n>' ) <EOL> post_context = [ line . strip ( '<STR_LIT:\n>' ) for line in source [ lineno + <NUM_LIT:1> : upper_bound ] ] <EOL> return lower_bound , pre_context , context_line , post_context <EOL> except ( OSError , IOError , IndexError ) : <EOL> return None , [ ] , None , [ ] <EOL> exception_type , exception_value , tback = sys . exc_info ( ) <EOL> frames = [ ] <EOL> while tback is not None : <EOL> filename = tback . tb_frame . f_code . co_filename <EOL> function = tback . tb_frame . f_code . co_name <EOL> lineno = tback . tb_lineno - <NUM_LIT:1> <EOL> lineno += tback . tb_frame . f_locals . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> pre_context_lineno , pre_context , context_line , post_context = _get_lines_from_file ( filename , lineno , <NUM_LIT:7> ) <EOL> if '<STR_LIT>' not in tback . tb_frame . f_locals : <EOL> frames . append ( web . storage ( { <EOL> '<STR_LIT>' : tback , <EOL> '<STR_LIT:filename>' : filename , <EOL> '<STR_LIT>' : function , <EOL> '<STR_LIT>' : lineno , <EOL> '<STR_LIT>' : tback . tb_frame . f_locals , <EOL> '<STR_LIT:id>' : id ( tback ) , <EOL> '<STR_LIT>' : pre_context , <EOL> '<STR_LIT>' : context_line , <EOL> '<STR_LIT>' : post_context , <EOL> '<STR_LIT>' : pre_context_lineno , <EOL> } ) ) <EOL> tback = tback . tb_next <EOL> frames . reverse ( ) <EOL> urljoin = urlparse . urljoin <EOL> def prettify ( x ) : <EOL> try : <EOL> out = pprint . pformat ( x ) <EOL> except Exception , e : <EOL> out = '<STR_LIT>' + e . __class__ . __name__ + '<STR_LIT>' + str ( e ) + '<STR_LIT>' <EOL> return out <EOL> global djangoerror_r <EOL> if djangoerror_r is None : <EOL> djangoerror_r = Template ( djangoerror_t , filename = __file__ , filter = websafe ) <EOL> t = djangoerror_r <EOL> globals = { '<STR_LIT>' : web . ctx , '<STR_LIT>' : web , '<STR_LIT>' : dict , '<STR_LIT:str>' : str , '<STR_LIT>' : prettify } <EOL> t . t . func_globals . update ( globals ) <EOL> return t ( exception_type , exception_value , frames ) <EOL> def debugerror ( ) : <EOL> """<STR_LIT>""" <EOL> return web . _InternalError ( djangoerror ( ) ) <EOL> def emailerrors ( to_address , olderror , from_address = None ) : <EOL> """<STR_LIT>""" <EOL> from_address = from_address or to_address <EOL> def emailerrors_internal ( ) : <EOL> error = olderror ( ) <EOL> tb = sys . exc_info ( ) <EOL> error_name = tb [ <NUM_LIT:0> ] <EOL> error_value = tb [ <NUM_LIT:1> ] <EOL> tb_txt = '<STR_LIT>' . join ( traceback . format_exception ( * tb ) ) <EOL> path = web . ctx . path <EOL> request = web . ctx . method + '<STR_LIT:U+0020>' + web . ctx . home + web . ctx . fullpath <EOL> message = "<STR_LIT>" % ( request , tb_txt ) <EOL> sendmail ( <EOL> "<STR_LIT>" % from_address , <EOL> "<STR_LIT>" % to_address , <EOL> "<STR_LIT>" % locals ( ) , <EOL> message , <EOL> attachments = [ <EOL> dict ( filename = "<STR_LIT>" , content = safestr ( djangoerror ( ) ) ) <EOL> ] , <EOL> ) <EOL> return error <EOL> return emailerrors_internal <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> urls = ( <EOL> '<STR_LIT:/>' , '<STR_LIT:index>' <EOL> ) <EOL> from application import application <EOL> app = application ( urls , globals ( ) ) <EOL> app . internalerror = debugerror <EOL> class index : <EOL> def GET ( self ) : <EOL> thisdoesnotexist <EOL> app . run ( ) </s>
