<s> import os <EOL> import sys <EOL> import cStringIO <EOL> import gluon . contrib . shell <EOL> import gluon . dal <EOL> import gluon . html <EOL> import gluon . validators <EOL> import code <EOL> import thread <EOL> from gluon . debug import communicate , web_debugger , qdb_debugger <EOL> import pydoc <EOL> if DEMO_MODE or MULTI_USER_MODE : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT:default>' , '<STR_LIT>' ) ) <EOL> FE = <NUM_LIT:10> ** <NUM_LIT:9> <EOL> def index ( ) : <EOL> app = request . args ( <NUM_LIT:0> ) or '<STR_LIT>' <EOL> reset ( ) <EOL> data = communicate ( ) <EOL> return dict ( app = app , data = data ) <EOL> def callback ( ) : <EOL> app = request . args [ <NUM_LIT:0> ] <EOL> command = request . vars . statement <EOL> session [ '<STR_LIT>' + app ] . append ( command ) <EOL> output = communicate ( command ) <EOL> k = len ( session [ '<STR_LIT>' + app ] ) - <NUM_LIT:1> <EOL> return '<STR_LIT>' % ( k + <NUM_LIT:1> , command , output ) <EOL> def reset ( ) : <EOL> app = request . args ( <NUM_LIT:0> ) or '<STR_LIT>' <EOL> session [ '<STR_LIT>' + app ] = [ ] <EOL> return '<STR_LIT>' <EOL> def interact ( ) : <EOL> app = request . args ( <NUM_LIT:0> ) or '<STR_LIT>' <EOL> reset ( ) <EOL> web_debugger . run ( ) <EOL> filename = web_debugger . filename <EOL> lineno = web_debugger . lineno <EOL> if filename : <EOL> lines = dict ( [ ( i + <NUM_LIT:1> , l ) for ( i , l ) in enumerate ( <EOL> [ l . strip ( "<STR_LIT:\n>" ) . strip ( "<STR_LIT:\r>" ) for l <EOL> in open ( filename ) . readlines ( ) ] ) ] ) <EOL> filename = os . path . basename ( filename ) <EOL> else : <EOL> lines = { } <EOL> if filename : <EOL> web_debugger . set_burst ( <NUM_LIT:2> ) <EOL> env = web_debugger . do_environment ( ) <EOL> f_locals = env [ '<STR_LIT>' ] <EOL> f_globals = { } <EOL> for name , value in env [ '<STR_LIT>' ] . items ( ) : <EOL> if name not in gluon . html . __all__ and name not in gluon . validators . __all__ and name not in gluon . dal . __all__ : <EOL> f_globals [ name ] = pydoc . text . repr ( value ) <EOL> else : <EOL> f_locals = { } <EOL> f_globals = { } <EOL> response . headers [ '<STR_LIT>' ] = "<STR_LIT:3>" <EOL> if web_debugger . exception_info : <EOL> response . flash = T ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return dict ( app = app , data = "<STR_LIT>" , <EOL> filename = web_debugger . filename , lines = lines , lineno = lineno , <EOL> f_globals = f_globals , f_locals = f_locals , <EOL> exception = web_debugger . exception_info ) <EOL> def step ( ) : <EOL> web_debugger . do_step ( ) <EOL> redirect ( URL ( "<STR_LIT>" ) ) <EOL> def next ( ) : <EOL> web_debugger . do_next ( ) <EOL> redirect ( URL ( "<STR_LIT>" ) ) <EOL> def cont ( ) : <EOL> web_debugger . do_continue ( ) <EOL> redirect ( URL ( "<STR_LIT>" ) ) <EOL> def ret ( ) : <EOL> web_debugger . do_return ( ) <EOL> redirect ( URL ( "<STR_LIT>" ) ) <EOL> def stop ( ) : <EOL> web_debugger . do_quit ( ) <EOL> redirect ( URL ( "<STR_LIT>" ) ) <EOL> def execute ( ) : <EOL> app = request . args [ <NUM_LIT:0> ] <EOL> command = request . vars . statement <EOL> session [ '<STR_LIT>' + app ] . append ( command ) <EOL> try : <EOL> output = web_debugger . do_exec ( command ) <EOL> if output is None : <EOL> output = "<STR_LIT>" <EOL> except Exception , e : <EOL> output = T ( "<STR_LIT>" ) % str ( e ) <EOL> k = len ( session [ '<STR_LIT>' + app ] ) - <NUM_LIT:1> <EOL> return '<STR_LIT>' % ( k + <NUM_LIT:1> , command , output ) <EOL> def breakpoints ( ) : <EOL> "<STR_LIT>" <EOL> files = listdir ( apath ( '<STR_LIT>' , r = request ) , '<STR_LIT>' ) <EOL> files = [ filename for filename in files <EOL> if filename and '<STR_LIT>' not in filename <EOL> and not filename . startswith ( "<STR_LIT>" ) <EOL> and not filename . startswith ( "<STR_LIT>" ) ] <EOL> form = SQLFORM . factory ( <EOL> Field ( '<STR_LIT:filename>' , requires = IS_IN_SET ( files ) , label = T ( "<STR_LIT>" ) ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , label = T ( "<STR_LIT>" ) , <EOL> comment = T ( "<STR_LIT>" ) ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT:string>' , label = T ( "<STR_LIT>" ) , <EOL> comment = T ( "<STR_LIT>" ) ) , <EOL> ) <EOL> if form . accepts ( request . vars , session ) : <EOL> filename = os . path . join ( request . env [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , form . vars . filename ) <EOL> err = qdb_debugger . do_set_breakpoint ( filename , <EOL> form . vars . lineno , <EOL> form . vars . temporary , <EOL> form . vars . condition ) <EOL> response . flash = T ( "<STR_LIT>" ) % ( <EOL> filename , form . vars . lineno , err or T ( '<STR_LIT>' ) ) <EOL> for item in request . vars : <EOL> if item [ : <NUM_LIT:7> ] == '<STR_LIT>' : <EOL> qdb_debugger . do_clear ( item [ <NUM_LIT:7> : ] ) <EOL> breakpoints = [ { '<STR_LIT>' : bp [ <NUM_LIT:0> ] , '<STR_LIT:filename>' : os . path . basename ( bp [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT:path>' : bp [ <NUM_LIT:1> ] , '<STR_LIT>' : bp [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : bp [ <NUM_LIT:3> ] , '<STR_LIT>' : bp [ <NUM_LIT:4> ] , '<STR_LIT>' : bp [ <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : bp [ <NUM_LIT:6> ] } <EOL> for bp in qdb_debugger . do_list_breakpoint ( ) ] <EOL> return dict ( breakpoints = breakpoints , form = form ) <EOL> def toggle_breakpoint ( ) : <EOL> "<STR_LIT>" <EOL> lineno = None <EOL> ok = None <EOL> try : <EOL> filename = os . path . join ( request . env [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , request . vars . filename ) <EOL> filename = os . path . normpath ( os . path . normcase ( filename ) ) <EOL> if not request . vars . data : <EOL> lineno = int ( request . vars . sel_start ) + <NUM_LIT:1> <EOL> else : <EOL> start = <NUM_LIT:0> <EOL> sel_start = int ( request . vars . sel_start ) <EOL> for lineno , line in enumerate ( request . vars . data . split ( "<STR_LIT:\n>" ) ) : <EOL> if sel_start <= start : <EOL> break <EOL> start += len ( line ) + <NUM_LIT:1> <EOL> else : <EOL> lineno = None <EOL> if lineno is not None : <EOL> for bp in qdb_debugger . do_list_breakpoint ( ) : <EOL> no , bp_filename , bp_lineno , temporary , enabled , hits , cond = bp <EOL> bp_filename = os . path . normpath ( os . path . normcase ( bp_filename ) ) <EOL> if filename == bp_filename and lineno == bp_lineno : <EOL> err = qdb_debugger . do_clear_breakpoint ( filename , lineno ) <EOL> response . flash = T ( "<STR_LIT>" , ( <EOL> filename , lineno ) ) <EOL> ok = False <EOL> break <EOL> else : <EOL> err = qdb_debugger . do_set_breakpoint ( filename , lineno ) <EOL> response . flash = T ( "<STR_LIT>" ) % ( <EOL> filename , lineno , err or T ( '<STR_LIT>' ) ) <EOL> ok = True <EOL> else : <EOL> response . flash = T ( "<STR_LIT>" ) <EOL> except Exception , e : <EOL> session . flash = str ( e ) <EOL> return response . json ( { '<STR_LIT>' : ok , '<STR_LIT>' : lineno } ) <EOL> def list_breakpoints ( ) : <EOL> "<STR_LIT>" <EOL> breakpoints = [ ] <EOL> ok = None <EOL> try : <EOL> filename = os . path . join ( request . env [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , request . vars . filename ) <EOL> filename = os . path . normpath ( os . path . normcase ( filename ) ) <EOL> for bp in qdb_debugger . do_list_breakpoint ( ) : <EOL> no , bp_filename , bp_lineno , temporary , enabled , hits , cond = bp <EOL> bp_filename = os . path . normpath ( os . path . normcase ( bp_filename ) ) <EOL> if filename == bp_filename : <EOL> breakpoints . append ( bp_lineno ) <EOL> ok = True <EOL> except Exception , e : <EOL> session . flash = str ( e ) <EOL> ok = False <EOL> return response . json ( { '<STR_LIT>' : ok , '<STR_LIT>' : breakpoints } ) </s>
