<s> """<STR_LIT>""" <EOL> import inspect <EOL> import pdb <EOL> import os <EOL> import re <EOL> import socket <EOL> import string <EOL> import sys <EOL> import tempfile <EOL> import traceback <EOL> try : <EOL> import epdb_server <EOL> import epdb_client <EOL> import epdb_stackutil <EOL> hasTelnet = True <EOL> except ImportError : <EOL> hasTelnet = False <EOL> from pdb import _saferepr <EOL> class Epdb ( pdb . Pdb ) : <EOL> _historyPath = os . path . expanduser ( '<STR_LIT>' ) <EOL> multiline_prompt = '<STR_LIT>' <EOL> fail_silently_on_ioerror = False <EOL> __old_stdin = None <EOL> __old_stdout = None <EOL> __old_pgid = None <EOL> _displayList = { } <EOL> trace_counts = { '<STR_LIT:default>' : [ True , <NUM_LIT:0> ] } <EOL> _server = None <EOL> def __init__ ( self ) : <EOL> self . _exc_type = None <EOL> self . _exc_msg = None <EOL> self . _tb = None <EOL> self . _config = { } <EOL> pdb . Pdb . __init__ ( self ) <EOL> try : <EOL> import erlcompleter <EOL> import readline <EOL> except ImportError : <EOL> self . _readline = None <EOL> self . _completer = None <EOL> else : <EOL> self . _readline = readline <EOL> self . _completer = erlcompleter . ECompleter ( ) <EOL> self . _oldHistory = [ ] <EOL> self . prompt = '<STR_LIT>' <EOL> def store_old_history ( self ) : <EOL> historyLen = self . _readline . get_current_history_length ( ) <EOL> oldHistory = [ self . _readline . get_history_item ( x ) <EOL> for x in xrange ( historyLen ) ] <EOL> self . _oldHistory = oldHistory <EOL> self . _readline . clear_history ( ) <EOL> def restore_old_history ( self ) : <EOL> self . _readline . clear_history ( ) <EOL> for line in self . _oldHistory : <EOL> if line is None : <EOL> continue <EOL> self . _readline . add_history ( line ) <EOL> self . _oldHistory = [ ] <EOL> def read_history ( self , storeOldHistory = False ) : <EOL> if self . _readline and self . _historyPath : <EOL> if storeOldHistory : <EOL> self . store_old_history ( ) <EOL> else : <EOL> self . _readline . clear_history ( ) <EOL> try : <EOL> self . _readline . read_history_file ( self . _historyPath ) <EOL> except IOError : <EOL> pass <EOL> def save_history ( self , restoreOldHistory = False ) : <EOL> if self . _readline and self . _historyPath : <EOL> self . _readline . set_history_length ( <NUM_LIT:1000> ) <EOL> try : <EOL> self . _readline . write_history_file ( self . _historyPath ) <EOL> except IOError : <EOL> pass <EOL> if restoreOldHistory : <EOL> self . restore_old_history ( ) <EOL> else : <EOL> self . _readline . clear_history ( ) <EOL> if hasTelnet : <EOL> def serve ( self , port = <NUM_LIT> ) : <EOL> if not Epdb . _server : <EOL> print '<STR_LIT>' % port <EOL> Epdb . _server = epdb_server . InvertedTelnetServer ( ( '<STR_LIT>' , port ) ) <EOL> Epdb . _server . handle_request ( ) <EOL> Epdb . _port = port <EOL> self . set_trace ( skip = <NUM_LIT:2> ) <EOL> def serve_post_mortem ( self , t , exc_type = None , exc_msg = None , port = <NUM_LIT> ) : <EOL> if not Epdb . _server : <EOL> print '<STR_LIT>' % port <EOL> Epdb . _server = epdb_server . InvertedTelnetServer ( ( '<STR_LIT>' , port ) ) <EOL> Epdb . _server . handle_request ( ) <EOL> self . post_mortem ( t , exc_type , exc_msg ) <EOL> def do_detach ( self , arg ) : <EOL> if Epdb . _server : <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> Epdb . _server . close_request ( ) <EOL> Epdb . _server = epdb_server . InvertedTelnetServer ( ( '<STR_LIT>' , Epdb . _port ) ) <EOL> Epdb . _server . handle_request ( ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> def do_close ( self , arg ) : <EOL> if Epdb . _server : <EOL> print '<STR_LIT>' <EOL> Epdb . _server . close_request ( ) <EOL> Epdb . _server = None <EOL> return self . do_continue ( '<STR_LIT>' ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> def do_savestack ( self , path ) : <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> frame = self . stack [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> frame = sys . _getframe ( <NUM_LIT:1> ) <EOL> while frame . f_globals [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> frame = frame . f_back <EOL> if path == "<STR_LIT>" : <EOL> ( tbfd , path ) = tempfile . mkstemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> output = os . fdopen ( tbfd , '<STR_LIT:w>' ) <EOL> else : <EOL> output = open ( path , '<STR_LIT:w>' ) <EOL> epdb_stackutil . printStack ( frame , output ) <EOL> print "<STR_LIT>" % path <EOL> def do_mailstack ( self , arg ) : <EOL> tolist = arg . split ( ) <EOL> subject = '<STR_LIT>' <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> frame = self . stack [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> frame = sys . _getframe ( <NUM_LIT:1> ) <EOL> while frame . f_globals [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> frame = frame . f_back <EOL> sender = os . environ [ '<STR_LIT>' ] <EOL> host = socket . getfqdn ( ) <EOL> extracontent = None <EOL> if self . _tb : <EOL> lines = traceback . format_exception ( self . _exc_type , self . _exc_msg , <EOL> self . _tb ) <EOL> extracontent = string . joinfields ( lines , "<STR_LIT>" ) <EOL> epdb_stackutil . mailStack ( frame , tolist , sender + '<STR_LIT:@>' + host , subject , <EOL> extracontent ) <EOL> print "<STR_LIT>" % tolist <EOL> def do_printstack ( self , arg ) : <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> frame = self . stack [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> frame = sys . _getframe ( <NUM_LIT:1> ) <EOL> while frame . f_globals [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> frame = frame . f_back <EOL> epdb_stackutil . printStack ( frame , sys . stderr ) <EOL> def do_printframe ( self , arg ) : <EOL> if not arg : <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> depth = self . curindex <EOL> else : <EOL> depth = <NUM_LIT:0> <EOL> else : <EOL> depth = int ( arg ) <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> depth = <NUM_LIT:0> - ( depth + <NUM_LIT:1> ) <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> print "<STR_LIT>" % depth <EOL> frame = self . stack [ depth ] [ <NUM_LIT:0> ] <EOL> else : <EOL> frame = sys . _getframe ( <NUM_LIT:1> ) <EOL> while frame . f_globals [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> frame = frame . f_back <EOL> for i in xrange ( <NUM_LIT:0> , depth ) : <EOL> frame = frame . f_back <EOL> epdb_stackutil . printFrame ( frame , sys . stderr ) <EOL> def do_file ( self , arg ) : <EOL> frame , lineno = self . stack [ self . curindex ] <EOL> filename = self . canonic ( frame . f_code . co_filename ) <EOL> print "<STR_LIT>" % ( filename , lineno ) <EOL> do_f = do_file <EOL> def do_until ( self , arg ) : <EOL> numBreaks = len ( self . breaks ) <EOL> self . do_tbreak ( arg ) <EOL> if len ( self . breaks ) > numBreaks : <EOL> self . set_continue ( ) <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def do_set ( self , arg ) : <EOL> if not arg : <EOL> keys = self . _config . keys ( ) <EOL> keys . sort ( ) <EOL> for key in keys : <EOL> print "<STR_LIT>" % ( key , self . _config [ key ] ) <EOL> else : <EOL> args = arg . split ( None , <NUM_LIT:1> ) <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> key = args [ <NUM_LIT:0> ] <EOL> if key in self . _config : <EOL> print "<STR_LIT>" % ( key , self . _config [ key ] ) <EOL> del self . _config [ key ] <EOL> else : <EOL> print "<STR_LIT>" % ( key ) <EOL> else : <EOL> key , value = args <EOL> if ( hasattr ( self , '<STR_LIT>' + key ) ) : <EOL> fn = getattr ( self , '<STR_LIT>' + key ) <EOL> fn ( value ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> def do_trace_cond ( self , args ) : <EOL> args = args . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) <EOL> if len ( args ) not in ( <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> print "<STR_LIT>" <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> cond = args [ <NUM_LIT:0> ] <EOL> marker = '<STR_LIT:default>' <EOL> else : <EOL> marker , cond = args <EOL> if cond == '<STR_LIT:None>' : <EOL> cond = None <EOL> self . set_trace_cond ( marker , cond ) <EOL> return <EOL> try : <EOL> cond = int ( cond ) <EOL> self . set_trace_cond ( marker , cond ) <EOL> return <EOL> except ValueError : <EOL> locals = self . curframe . f_locals <EOL> globals = self . curframe . f_globals <EOL> try : <EOL> cond = eval ( cond + '<STR_LIT:\n>' , globals , locals ) <EOL> rv = ( type ( cond ) == bool ) or bool ( cond ( <NUM_LIT:1> ) ) <EOL> self . set_trace_cond ( marker , cond ) <EOL> except : <EOL> print self . _reprExc ( ) <EOL> do_tc = do_trace_cond <EOL> def _set_path ( self , paths ) : <EOL> paths = paths . split ( '<STR_LIT:U+0020>' ) <EOL> for path in paths : <EOL> if path [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> print "<STR_LIT>" <EOL> if not os . path . exists ( path ) : <EOL> print "<STR_LIT>" % path <EOL> if path [ - <NUM_LIT:1> ] == '<STR_LIT:/>' : <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> path = os . path . realpath ( path ) <EOL> if '<STR_LIT:path>' not in self . _config : <EOL> self . _config [ '<STR_LIT:path>' ] = [ ] <EOL> self . _config [ '<STR_LIT:path>' ] . append ( path ) <EOL> print "<STR_LIT>" % self . _config [ '<STR_LIT:path>' ] <EOL> def do_list ( self , arg ) : <EOL> rel = re . compile ( r'<STR_LIT>' ) <EOL> if arg and arg == '<STR_LIT:.>' : <EOL> self . lineno = None <EOL> pdb . Pdb . do_list ( self , '<STR_LIT>' ) <EOL> return <EOL> if rel . match ( arg ) : <EOL> if arg == '<STR_LIT:->' : <EOL> reldist = - <NUM_LIT:7> <EOL> else : <EOL> reldist = int ( arg ) <EOL> if self . lineno is None : <EOL> lineno = self . curframe . f_lineno <EOL> else : <EOL> lineno = self . lineno <EOL> lineno += reldist - <NUM_LIT:5> <EOL> pdb . Pdb . do_list ( self , str ( lineno ) ) <EOL> self . lastcmd = '<STR_LIT>' + arg <EOL> else : <EOL> pdb . Pdb . do_list ( self , arg ) <EOL> do_l = do_list <EOL> def lookupmodule ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isabs ( filename ) and os . path . exists ( filename ) : <EOL> return filename <EOL> f = os . path . join ( sys . path [ <NUM_LIT:0> ] , filename ) <EOL> if os . path . exists ( f ) and self . canonic ( f ) == self . mainpyfile : <EOL> return f <EOL> root , ext = os . path . splitext ( filename ) <EOL> origFileName = filename <EOL> if ext == '<STR_LIT>' : <EOL> filename = filename + '<STR_LIT>' <EOL> if os . path . isabs ( filename ) : <EOL> return filename <EOL> for dirname in sys . path : <EOL> while os . path . islink ( dirname ) : <EOL> dirname = os . path . realpath ( os . path . join ( os . path . dirname ( dirname ) , os . readlink ( dirname ) ) ) <EOL> fullname = os . path . join ( dirname , filename ) <EOL> if os . path . exists ( fullname ) : <EOL> return fullname <EOL> if origFileName in sys . modules : <EOL> return sys . modules [ origFileName ] . __file__ <EOL> return None <EOL> def default ( self , line ) : <EOL> if line [ <NUM_LIT:0> ] == '<STR_LIT:!>' : line = line [ <NUM_LIT:1> : ] <EOL> if self . handle_directive ( line ) : <EOL> return <EOL> if line == '<STR_LIT>' : <EOL> return self . multiline ( ) <EOL> if line . strip ( ) . endswith ( '<STR_LIT::>' ) : <EOL> return self . multiline ( line ) <EOL> if line . endswith ( '<STR_LIT:\\>' ) : <EOL> return self . multiline ( line ) <EOL> origLine = line <EOL> line = _removeQuotes ( line ) <EOL> if line is None : <EOL> return self . multiline ( origLine ) <EOL> if line . count ( '<STR_LIT:(>' ) > line . count ( '<STR_LIT:)>' ) : <EOL> return self . multiline ( origLine ) <EOL> try : <EOL> self . save_history ( ) <EOL> return pdb . Pdb . default ( self , origLine ) <EOL> finally : <EOL> self . read_history ( ) <EOL> def multiline ( self , firstline = '<STR_LIT>' ) : <EOL> full_input = [ ] <EOL> old_hist = [ ] <EOL> if firstline : <EOL> print '<STR_LIT:U+0020>' + firstline <EOL> full_input . append ( firstline ) <EOL> while True : <EOL> if self . _readline : <EOL> old_hist . append ( self . _readline . get_current_history_length ( ) ) <EOL> if self . use_rawinput : <EOL> try : <EOL> line = raw_input ( self . multiline_prompt ) <EOL> except EOFError : <EOL> line = '<STR_LIT>' <EOL> else : <EOL> self . stdout . write ( self . multiline_prompt ) <EOL> self . stdout . flush ( ) <EOL> line = self . stdin . readline ( ) <EOL> if not len ( line ) : <EOL> line = '<STR_LIT>' <EOL> else : <EOL> line = line [ : - <NUM_LIT:1> ] <EOL> if line == '<STR_LIT>' : <EOL> break <EOL> full_input . append ( line ) <EOL> if self . _readline : <EOL> old_hist . append ( self . _readline . get_current_history_length ( ) ) <EOL> cmd = '<STR_LIT:\n>' . join ( full_input ) + '<STR_LIT:\n>' <EOL> if self . _readline : <EOL> old_hist = sorted ( set ( old_hist ) ) <EOL> for pos in reversed ( old_hist ) : <EOL> self . _readline . remove_history_item ( pos - <NUM_LIT:1> ) <EOL> self . _readline . add_history ( cmd ) <EOL> locals = self . curframe . f_locals <EOL> globals = self . curframe . f_globals <EOL> print <EOL> self . save_history ( ) <EOL> try : <EOL> try : <EOL> code = compile ( cmd , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exec code in globals , locals <EOL> except : <EOL> print self . _reprExc ( ) <EOL> finally : <EOL> self . read_history ( ) <EOL> def handle_directive ( self , line ) : <EOL> cmd = line . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> if len ( cmd ) == <NUM_LIT:1> : <EOL> return False <EOL> cmd , directive = cmd <EOL> if directive and directive not in '<STR_LIT>' : <EOL> return False <EOL> self . do_define ( cmd ) <EOL> if directive == '<STR_LIT:?>' : <EOL> self . do_doc ( cmd ) <EOL> if directive == '<STR_LIT:c>' : <EOL> self . do_showclasses ( cmd ) <EOL> elif directive == '<STR_LIT:d>' : <EOL> self . do_showdata ( cmd ) <EOL> elif directive == '<STR_LIT:m>' : <EOL> self . do_showmethods ( cmd ) <EOL> elif directive == '<STR_LIT:p>' : <EOL> pdb . Pdb . default ( self , '<STR_LIT>' + cmd ) <EOL> elif directive == '<STR_LIT:x>' : <EOL> pdb . Pdb . default ( self , '<STR_LIT>' % cmd ) <EOL> return True <EOL> def do_p ( self , arg ) : <EOL> cmd = arg . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> if len ( cmd ) == <NUM_LIT:1> : <EOL> self . save_history ( ) <EOL> pdb . Pdb . do_p ( self , arg ) <EOL> self . read_history ( ) <EOL> else : <EOL> self . default ( arg ) <EOL> def _showmethods ( self , obj ) : <EOL> methods = self . _getMembersOfType ( obj , '<STR_LIT:m>' ) <EOL> methods . sort ( ) <EOL> for ( methodName , method ) in methods : <EOL> try : <EOL> self . _define ( method ) <EOL> except : <EOL> if hasattr ( obj , '<STR_LIT>' ) : <EOL> prefix = obj . __name__ <EOL> else : <EOL> prefix = obj . __class__ . __name__ <EOL> print prefix + '<STR_LIT:.>' + methodName <EOL> def _showdata ( self , obj ) : <EOL> data = self . _getMembersOfType ( obj , '<STR_LIT:d>' ) <EOL> data . sort ( ) <EOL> print [ x [ <NUM_LIT:0> ] for x in data ] <EOL> def _showclasses ( self , obj ) : <EOL> classes = self . _getMembersOfType ( obj , '<STR_LIT:c>' ) <EOL> classes . sort ( ) <EOL> for ( className , class_ ) in classes : <EOL> self . _define ( class_ ) <EOL> print <EOL> def _objtype ( self , obj ) : <EOL> if inspect . isroutine ( obj ) or type ( obj ) . __name__ == '<STR_LIT>' : <EOL> return '<STR_LIT:m>' <EOL> elif inspect . isclass ( obj ) : <EOL> return '<STR_LIT:c>' <EOL> else : <EOL> return '<STR_LIT:d>' <EOL> def _eval ( self , arg , fn = None , printExc = True ) : <EOL> locals = self . curframe . f_locals <EOL> globals = self . curframe . f_globals <EOL> try : <EOL> result = eval ( arg + '<STR_LIT:\n>' , globals , locals ) <EOL> if fn is None : <EOL> return True , result <EOL> return True , fn ( result ) <EOL> except : <EOL> if printExc : <EOL> exc = self . _reprExc ( ) <EOL> print exc <EOL> return False , exc <EOL> else : <EOL> return False , self . _reprExc ( ) <EOL> def _reprExc ( self ) : <EOL> t , v = sys . exc_info ( ) [ : <NUM_LIT:2> ] <EOL> if type ( t ) == type ( '<STR_LIT>' ) : <EOL> exc_type_name = t <EOL> else : exc_type_name = t . __name__ <EOL> return '<STR_LIT:U+0020>' . join ( ( '<STR_LIT>' , exc_type_name + '<STR_LIT::>' , _saferepr ( str ( v ) ) ) ) <EOL> def _getMembersOfType ( self , obj , objType ) : <EOL> names = dir ( obj ) <EOL> members = [ ] <EOL> for n in names : <EOL> member = getattr ( obj , n ) <EOL> if self . _objtype ( member ) == objType : <EOL> members . append ( ( n , member ) ) <EOL> return members <EOL> def do_showmethods ( self , arg ) : <EOL> self . _eval ( arg , self . _showmethods ) <EOL> def do_showclasses ( self , arg ) : <EOL> self . _eval ( arg , self . _showclasses ) <EOL> def do_display ( self , arg ) : <EOL> if not arg : <EOL> self . _displayItems ( ) <EOL> else : <EOL> params = arg . split ( ) <EOL> if params [ <NUM_LIT:0> ] == '<STR_LIT:list>' and not params [ <NUM_LIT:1> : ] : <EOL> self . _listDisplayItems ( ) <EOL> elif params [ <NUM_LIT:0> ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> nums = [ int ( x ) for x in params [ <NUM_LIT:1> : ] ] <EOL> except ValueError , msg : <EOL> print '<STR_LIT>' , ValueError , msg <EOL> return <EOL> missing = [ ] <EOL> _nums = [ ] <EOL> for num in nums : <EOL> if num in self . _displayList : <EOL> _nums . append ( num ) <EOL> else : <EOL> missing . append ( str ( num ) ) <EOL> if params [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> for num in _nums : <EOL> self . _displayList [ num ] [ <NUM_LIT:0> ] = True <EOL> if params [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> for num in _nums : <EOL> self . _displayList [ num ] [ <NUM_LIT:0> ] = False <EOL> if params [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> for num in nums : <EOL> del self . _displayList [ num ] <EOL> self . _listDisplayItems ( ) <EOL> if missing : <EOL> print "<STR_LIT>" % '<STR_LIT:U+002C>' . join ( missing ) <EOL> else : <EOL> if self . _displayList : <EOL> displayNum = max ( self . _displayList ) + <NUM_LIT:1> <EOL> else : <EOL> displayNum = <NUM_LIT:0> <EOL> self . _displayList [ displayNum ] = [ True , arg ] <EOL> self . _listDisplayItems ( ) <EOL> def _listDisplayItems ( self ) : <EOL> displayedItem = False <EOL> for num in sorted ( self . _displayList . iterkeys ( ) ) : <EOL> if not displayedItem : <EOL> displayedItem = True <EOL> print <EOL> print "<STR_LIT>" <EOL> enabled , item = self . _displayList [ num ] <EOL> if not enabled : <EOL> print "<STR_LIT>" % ( num , item ) <EOL> else : <EOL> print "<STR_LIT>" % ( num , item ) <EOL> if displayedItem : <EOL> print <EOL> else : <EOL> print "<STR_LIT>" <EOL> def _displayItems ( self ) : <EOL> displayedItem = False <EOL> for num in sorted ( self . _displayList . iterkeys ( ) ) : <EOL> enabled , item = self . _displayList [ num ] <EOL> if not enabled : <EOL> continue <EOL> if not displayedItem : <EOL> displayedItem = True <EOL> print <EOL> passed , result = self . _eval ( item , printExc = False ) <EOL> print "<STR_LIT>" % ( num , item , _saferepr ( result ) ) <EOL> if displayedItem : <EOL> print <EOL> def do_define ( self , arg ) : <EOL> self . _eval ( arg , self . _define ) <EOL> def do_showdata ( self , arg ) : <EOL> result = self . _eval ( arg , self . _showdata ) <EOL> def _define ( self , obj ) : <EOL> if inspect . isclass ( obj ) : <EOL> bases = inspect . getmro ( obj ) <EOL> bases = [ x . __name__ for x in bases [ <NUM_LIT:1> : ] ] <EOL> if bases : <EOL> bases = '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( bases ) + '<STR_LIT:)>' <EOL> else : <EOL> bases = '<STR_LIT>' <EOL> if hasattr ( obj , '<STR_LIT>' ) and inspect . isroutine ( obj . __init__ ) : <EOL> try : <EOL> initfn = obj . __init__ . im_func <EOL> argspec = inspect . getargspec ( initfn ) <EOL> fnargs = argspec [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> newArgSpec = ( fnargs , argspec [ <NUM_LIT:1> ] , argspec [ <NUM_LIT:2> ] , argspec [ <NUM_LIT:3> ] ) <EOL> argspec = inspect . formatargspec ( * newArgSpec ) <EOL> except TypeError : <EOL> argspec = '<STR_LIT>' <EOL> else : <EOL> argspec = '<STR_LIT>' <EOL> print "<STR_LIT>" + obj . __name__ + argspec + bases <EOL> elif inspect . ismethod ( obj ) or type ( obj ) . __name__ == '<STR_LIT>' : <EOL> m_class = obj . im_class <EOL> m_self = obj . im_self <EOL> m_func = obj . im_func <EOL> name = m_class . __name__ + '<STR_LIT:.>' + m_func . __name__ <EOL> argspec = inspect . formatargspec ( * inspect . getargspec ( m_func ) ) <EOL> print "<STR_LIT>" % ( name , argspec ) <EOL> elif type ( obj ) . __name__ == '<STR_LIT>' : <EOL> print obj <EOL> elif inspect . isfunction ( obj ) : <EOL> name = obj . __name__ <EOL> argspec = inspect . formatargspec ( * inspect . getargspec ( obj ) ) <EOL> print "<STR_LIT>" % ( name , argspec ) <EOL> else : <EOL> print type ( obj ) <EOL> def do_doc ( self , arg ) : <EOL> self . _eval ( arg , self . _doc ) <EOL> def _doc ( self , result ) : <EOL> docloc = None <EOL> if hasattr ( result , '<STR_LIT>' ) : <EOL> if result . __doc__ is not None : <EOL> docstr = result . __doc__ <EOL> elif inspect . ismethod ( result ) : <EOL> bases = inspect . getmro ( result . im_class ) <EOL> found = False <EOL> for base in bases : <EOL> if hasattr ( base , result . __name__ ) : <EOL> baseres = getattr ( base , result . __name__ ) <EOL> if ( hasattr ( baseres , '<STR_LIT>' ) <EOL> and baseres . __doc__ is not None ) : <EOL> docloc = baseres <EOL> docstr = baseres . __doc__ <EOL> found = True <EOL> break <EOL> if not found : <EOL> docstr = None <EOL> else : <EOL> docstr = None <EOL> print "<STR_LIT>" % docstr <EOL> if docloc : <EOL> print "<STR_LIT>" % docloc <EOL> if inspect . isclass ( result ) : <EOL> if hasattr ( result , '<STR_LIT>' ) : <EOL> self . _define ( result ) <EOL> if hasattr ( result . __init__ , '<STR_LIT>' ) : <EOL> print "<STR_LIT>" % result . __init__ . __doc__ <EOL> else : <EOL> print "<STR_LIT>" <EOL> def interaction ( self , frame , traceback ) : <EOL> try : <EOL> self . switch_input_output ( ) <EOL> except IOError : <EOL> if True or self . fail_silently_on_ioerror : <EOL> self . set_continue ( ) <EOL> return <EOL> else : <EOL> raise <EOL> self . read_history ( storeOldHistory = True ) <EOL> self . setup ( frame , traceback ) <EOL> self . _displayItems ( ) <EOL> self . print_stack_entry ( self . stack [ self . curindex ] ) <EOL> self . cmdloop ( ) <EOL> self . forget ( ) <EOL> self . save_history ( restoreOldHistory = True ) <EOL> self . restore_input_output ( ) <EOL> def post_mortem ( self , t , exc_type , exc_msg ) : <EOL> self . _exc_type = exc_type <EOL> self . _exc_msg = exc_msg <EOL> self . _tb = t <EOL> self . reset ( ) <EOL> while t . tb_next is not None : <EOL> t = t . tb_next <EOL> self . interaction ( t . tb_frame , t ) <EOL> def switch_input_output ( self ) : <EOL> self . switch_stdout ( ) <EOL> self . switch_stdin ( ) <EOL> self . switch_pgid ( ) <EOL> def restore_input_output ( self ) : <EOL> if self . __old_stdout is not None : <EOL> sys . stdout . flush ( ) <EOL> sys . stdout = self . __old_stdout <EOL> if self . __old_stdin is not None : <EOL> sys . stdin = self . __old_stdin <EOL> if self . __old_pgid is not None : <EOL> os . setpgid ( <NUM_LIT:0> , self . __old_pgid ) <EOL> def switch_pgid ( self ) : <EOL> try : <EOL> if os . getpgrp ( ) != os . tcgetpgrp ( <NUM_LIT:0> ) : <EOL> self . __old_pgid = os . getpgrp ( ) <EOL> os . setpgid ( <NUM_LIT:0> , os . tcgetpgrp ( <NUM_LIT:0> ) ) <EOL> else : <EOL> self . __old_pgid = None <EOL> except OSError : <EOL> self . __old_pgid = None <EOL> def switch_stdout ( self ) : <EOL> isatty = False <EOL> try : <EOL> fileno = sys . stdout . fileno ( ) <EOL> isatty = isinstance ( sys . stdout , file ) and os . isatty ( fileno ) <EOL> except AttributeError : <EOL> pass <EOL> if not isatty : <EOL> sys . stdout . flush ( ) <EOL> self . __old_stdout = sys . stdout <EOL> stdout = open ( '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> sys . stdout = stdout <EOL> else : <EOL> self . __old_stdout = None <EOL> def switch_stdin ( self ) : <EOL> isatty = False <EOL> try : <EOL> fileno = sys . stdin . fileno ( ) <EOL> isatty = isinstance ( sys . stdout , file ) and os . isatty ( fileno ) <EOL> except AttributeError : <EOL> pass <EOL> if not isatty : <EOL> sys . stdin . flush ( ) <EOL> self . __old_stdin = sys . stdin <EOL> stdin = open ( '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> sys . stdin = stdin <EOL> else : <EOL> self . __old_stdin = None <EOL> def canonic ( self , filename ) : <EOL> canonic = self . fncache . get ( filename ) <EOL> if not canonic or not os . path . exists ( canonic ) : <EOL> canonic = os . path . abspath ( filename ) <EOL> canonic = os . path . normcase ( canonic ) <EOL> if not os . path . exists ( canonic ) : <EOL> if '<STR_LIT:path>' in self . _config : <EOL> for path in self . _config [ '<STR_LIT:path>' ] : <EOL> pos = matchFileOnDirPath ( path , canonic ) <EOL> if pos : <EOL> canonic = pos <EOL> break <EOL> self . fncache [ filename ] = canonic <EOL> return canonic <EOL> def reset_trace_count ( klass , marker = '<STR_LIT:default>' ) : <EOL> tc = klass . trace_counts <EOL> try : <EOL> tc [ marker ] [ <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> except KeyError : <EOL> pass <EOL> reset_trace_count = classmethod ( reset_trace_count ) <EOL> def set_trace_cond ( klass , marker = '<STR_LIT:default>' , cond = None ) : <EOL> """<STR_LIT>""" <EOL> tc = klass . trace_counts <EOL> try : <EOL> curVals = tc [ marker ] <EOL> except KeyError : <EOL> curVals = [ None , <NUM_LIT:0> ] <EOL> tc [ marker ] = ( cond , <NUM_LIT:0> ) <EOL> set_trace_cond = classmethod ( set_trace_cond ) <EOL> def set_trace ( self , marker = '<STR_LIT:default>' , skip = <NUM_LIT:0> ) : <EOL> tc = Epdb . trace_counts <EOL> try : <EOL> ( cond , curCount ) = tc [ marker ] <EOL> curCount += <NUM_LIT:1> <EOL> except KeyError : <EOL> ( cond , curCount ) = None , <NUM_LIT:1> <EOL> if cond is True : <EOL> rv = True <EOL> elif cond is None or cond is False : <EOL> rv = False <EOL> else : <EOL> try : <EOL> rv = cond ( curCount ) <EOL> except TypeError : <EOL> rv = curCount >= cond <EOL> if rv : <EOL> if marker != '<STR_LIT:default>' : <EOL> self . prompt = '<STR_LIT>' % marker <EOL> self . _set_trace ( skip = skip + <NUM_LIT:1> ) <EOL> tc [ marker ] = [ cond , curCount ] <EOL> def do_debug ( self , arg ) : <EOL> sys . settrace ( None ) <EOL> globals = self . curframe . f_globals <EOL> locals = self . curframe . f_locals <EOL> p = Epdb ( ) <EOL> p . prompt = "<STR_LIT>" % self . prompt . strip ( ) <EOL> print "<STR_LIT>" <EOL> sys . call_tracing ( p . run , ( arg , globals , locals ) ) <EOL> print "<STR_LIT>" <EOL> sys . settrace ( self . trace_dispatch ) <EOL> self . lastcmd = p . lastcmd <EOL> def _set_trace ( self , skip = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> frame = sys . _getframe ( ) . f_back <EOL> for i in range ( <NUM_LIT:0> , skip ) : <EOL> frame = frame . f_back <EOL> self . reset ( ) <EOL> while frame : <EOL> frame . f_trace = self . trace_dispatch <EOL> self . botframe = frame <EOL> frame = frame . f_back <EOL> self . set_step ( ) <EOL> sys . settrace ( self . trace_dispatch ) <EOL> def user_call ( self , frame , argument_list ) : <EOL> """<STR_LIT>""" <EOL> if self . stop_here ( frame ) : <EOL> pdb . Pdb . user_call ( self , frame , argument_list ) <EOL> def user_line ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> pdb . Pdb . user_line ( self , frame ) <EOL> def user_return ( self , frame , return_value ) : <EOL> """<STR_LIT>""" <EOL> pdb . Pdb . user_return ( self , frame , return_value ) <EOL> def user_exception ( self , frame , exc_info ) : <EOL> """<STR_LIT>""" <EOL> pdb . Pdb . user_exception ( self , frame , exc_info ) <EOL> def complete ( self , text , state ) : <EOL> if self . _readline : <EOL> allvars = { } <EOL> globals = self . curframe . f_globals . copy ( ) <EOL> locals = self . curframe . f_locals . copy ( ) <EOL> allvars . update ( globals ) <EOL> allvars . update ( locals ) <EOL> self . _completer . namespace = allvars <EOL> self . _completer . use_main_ns = <NUM_LIT:0> <EOL> matches = self . _completer . complete ( text , state ) <EOL> return matches <EOL> else : <EOL> return pdb . Pdb . complete ( self , text , state ) <EOL> def beingTraced ( ) : <EOL> frame = sys . _getframe ( <NUM_LIT:0> ) <EOL> while frame : <EOL> if not frame . f_trace is None : <EOL> return True <EOL> frame = frame . f_back <EOL> return False <EOL> def set_trace_cond ( * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> for key , val in kw . iteritems ( ) : <EOL> Epdb . set_trace_cond ( key , val ) <EOL> for arg in args : <EOL> Epdb . set_trace_cond ( arg , True ) <EOL> stc = set_trace_cond <EOL> def reset_trace_count ( marker = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> Epdb . reset_trace_count ( marker ) <EOL> def set_trace ( marker = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> Epdb ( ) . set_trace ( marker = marker , skip = <NUM_LIT:1> ) <EOL> st = set_trace <EOL> if hasTelnet : <EOL> def serve ( port = <NUM_LIT> ) : <EOL> Epdb ( ) . serve ( port ) <EOL> def serve_post_mortem ( t , exc_type = None , exc_msg = None , port = <NUM_LIT> ) : <EOL> Epdb ( ) . serve_post_mortem ( t , exc_type , exc_msg , port ) <EOL> def connect ( host = '<STR_LIT:localhost>' , port = <NUM_LIT> ) : <EOL> t = epdb_client . TelnetClient ( host , port ) <EOL> t . interact ( ) <EOL> def post_mortem ( t , exc_type = None , exc_msg = None ) : <EOL> Epdb ( ) . post_mortem ( t , exc_type = None , exc_msg = None ) <EOL> def matchFileOnDirPath ( curpath , pathdir ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( curpath ) : <EOL> return curpath <EOL> filedirs = curpath . split ( '<STR_LIT:/>' ) [ <NUM_LIT:1> : ] <EOL> filename = filedirs [ - <NUM_LIT:1> ] <EOL> filedirs = filedirs [ : - <NUM_LIT:1> ] <EOL> if pathdir [ - <NUM_LIT:1> ] == '<STR_LIT:/>' : <EOL> pathdir = pathdir [ : - <NUM_LIT:1> ] <EOL> pathdirs = pathdir . split ( '<STR_LIT:/>' ) [ <NUM_LIT:1> : ] <EOL> lp = len ( pathdirs ) <EOL> for x in range ( <NUM_LIT:1> , min ( len ( filedirs ) , len ( pathdirs ) ) ) : <EOL> if filedirs [ - <NUM_LIT:1> ] == pathdirs [ - x ] : <EOL> filedirs = filedirs [ : - <NUM_LIT:1> ] <EOL> else : <EOL> break <EOL> while filedirs : <EOL> tmppath = '<STR_LIT:/>' + '<STR_LIT:/>' . join ( pathdirs + filedirs + [ filename ] ) <EOL> if os . path . exists ( tmppath ) : <EOL> return tmppath <EOL> filedirs = filedirs [ <NUM_LIT:1> : ] <EOL> tmppath = '<STR_LIT:/>' + '<STR_LIT:/>' . join ( pathdirs + [ filename ] ) <EOL> if os . path . exists ( tmppath ) : <EOL> return tmppath <EOL> return None <EOL> def _removeQuotes ( line ) : <EOL> origLine = line <EOL> line = line . replace ( r'<STR_LIT:\\>' , '<STR_LIT:X>' ) <EOL> line = re . sub ( r'<STR_LIT>' , '<STR_LIT:X>' , line ) <EOL> line = _removeQuoteSet ( line , '<STR_LIT>' , "<STR_LIT>" ) <EOL> if line is None : return None <EOL> if line != _removeQuoteSet ( line , '<STR_LIT>' , "<STR_LIT>" ) : <EOL> return origLine <EOL> line = _removeQuoteSet ( line , '<STR_LIT:">' , "<STR_LIT:'>" ) <EOL> if line is None : <EOL> return origLine <EOL> return line <EOL> def _removeQuoteSet ( line , quote1 , quote2 ) : <EOL> ln = len ( quote1 ) <EOL> while True : <EOL> a = line . find ( quote1 ) , quote1 <EOL> b = line . find ( quote2 ) , quote2 <EOL> if a [ <NUM_LIT:0> ] == - <NUM_LIT:1> and b [ <NUM_LIT:0> ] == - <NUM_LIT:1> : <EOL> return line <EOL> if b [ <NUM_LIT:0> ] == - <NUM_LIT:1> or ( b [ <NUM_LIT:0> ] < a [ <NUM_LIT:0> ] ) : <EOL> firstPoint = a [ <NUM_LIT:0> ] <EOL> firstQuote = a [ <NUM_LIT:1> ] <EOL> else : <EOL> firstPoint = b [ <NUM_LIT:0> ] <EOL> firstQuote = b [ <NUM_LIT:1> ] <EOL> secondPoint = line [ ( firstPoint + ln ) : ] . find ( firstQuote ) <EOL> if secondPoint == - <NUM_LIT:1> : <EOL> return None <EOL> secondPoint += firstPoint <EOL> line = line [ : firstPoint ] + line [ ( secondPoint + <NUM_LIT:2> * ln ) : ] <EOL> def main ( argv ) : <EOL> if len ( argv ) == <NUM_LIT:1> : <EOL> set_trace ( ) <EOL> return <EOL> command = argv [ <NUM_LIT:1> ] <EOL> if command == '<STR_LIT>' : <EOL> if len ( argv ) > <NUM_LIT:2> : <EOL> host = argv [ <NUM_LIT:2> ] <EOL> else : <EOL> host = '<STR_LIT:localhost>' <EOL> if len ( argv ) > <NUM_LIT:3> : <EOL> port = int ( argv [ <NUM_LIT:3> ] ) <EOL> else : <EOL> port = <NUM_LIT> <EOL> connect ( host = host , port = port ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( sys . argv ) ) </s>
