<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function , with_statement , unicode_literals <EOL> from . middleware import * <EOL> from . uimodules import * <EOL> from . options import * <EOL> from . tests import * <EOL> import traceback <EOL> import base64 <EOL> import pprint <EOL> import linecache <EOL> class DebugBreakException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def debug ( ) : <EOL> """<STR_LIT>""" <EOL> raise DebugBreakException ( ) <EOL> class ErrorFrame ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tback , filename , function , lineno , vars , id , pre_context , context_line , post_context , pre_context_lineno ) : <EOL> self . tback = tback <EOL> self . filename = filename <EOL> self . function = function <EOL> self . lineno = lineno <EOL> self . vars = vars <EOL> self . id = id <EOL> self . pre_context = pre_context <EOL> self . context_line = context_line <EOL> self . post_context = post_context <EOL> self . pre_context_lineno = pre_context_lineno <EOL> def get_lines_from_file ( filename , lineno , context_lines ) : <EOL> """<STR_LIT>""" <EOL> get_lines = lambda s , e : [ linecache . getline ( filename , l ) . rstrip ( ) for l in range ( s , e ) ] <EOL> lower_bound = max ( <NUM_LIT:1> , lineno - context_lines ) <EOL> upper_bound = lineno + context_lines <EOL> linecache . checkcache ( filename ) <EOL> pre_context = get_lines ( lower_bound , lineno ) <EOL> context_line = linecache . getline ( filename , lineno ) . rstrip ( ) <EOL> post_context = get_lines ( lineno + <NUM_LIT:1> , upper_bound ) <EOL> return lower_bound , pre_context , context_line , post_context <EOL> def get_frames ( tback , is_breakpoint ) : <EOL> """<STR_LIT>""" <EOL> frames = [ ] <EOL> while tback is not None : <EOL> if tback . tb_next == None and is_breakpoint : <EOL> break <EOL> filename = tback . tb_frame . f_code . co_filename <EOL> function = tback . tb_frame . f_code . co_name <EOL> context = tback . tb_frame . f_locals <EOL> lineno = tback . tb_lineno - <NUM_LIT:1> <EOL> tback_id = id ( tback ) <EOL> pre_context_lineno , pre_context , context_line , post_context = get_lines_from_file ( filename , lineno + <NUM_LIT:1> , <NUM_LIT:7> ) <EOL> frames . append ( ErrorFrame ( tback , filename , function , lineno , context , tback_id , pre_context , context_line , post_context , pre_context_lineno ) ) <EOL> tback = tback . tb_next <EOL> return frames <EOL> def prettify_object ( obj ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return pprint . pformat ( str ( obj ) ) <EOL> except UnicodeDecodeError as e : <EOL> raise <EOL> except Exception as e : <EOL> return "<STR_LIT>" % ( e . __class__ . __name__ , str ( e ) ) </s>
