<s> """<STR_LIT>""" <EOL> import time <EOL> import gtk <EOL> import gobject <EOL> import gtk . glade <EOL> from twisted . python . util import sibpath <EOL> from twisted . python import reflect <EOL> from twisted . manhole . ui import gtk2manhole <EOL> from twisted . python . components import Adapter , registerAdapter <EOL> from twisted . python import log <EOL> from twisted . protocols import policies <EOL> from zope . interface import implements , Interface <EOL> import gnome <EOL> version = "<STR_LIT>" [ <NUM_LIT:11> : - <NUM_LIT:2> ] <EOL> gnome . init ( "<STR_LIT>" , version ) <EOL> class ConsoleOutput ( gtk2manhole . ConsoleOutput ) : <EOL> def _captureLocalLog ( self ) : <EOL> self . fobs = log . FileLogObserver ( gtk2manhole . _Notafile ( self , "<STR_LIT>" ) ) <EOL> self . fobs . start ( ) <EOL> def stop ( self ) : <EOL> self . fobs . stop ( ) <EOL> del self . fobs <EOL> class ConsoleInput ( gtk2manhole . ConsoleInput ) : <EOL> def sendMessage ( self ) : <EOL> buffer = self . textView . get_buffer ( ) <EOL> iter1 , iter2 = buffer . get_bounds ( ) <EOL> text = buffer . get_text ( iter1 , iter2 , False ) <EOL> self . do ( text ) <EOL> def do ( self , text ) : <EOL> self . toplevel . do ( text ) <EOL> class INode ( Interface ) : <EOL> """<STR_LIT>""" <EOL> def __adapt__ ( adaptable , default ) : <EOL> if hasattr ( adaptable , "<STR_LIT>" ) : <EOL> return InstanceNode ( adaptable ) <EOL> return AttributesNode ( adaptable ) <EOL> class InspectorNode ( Adapter ) : <EOL> implements ( INode ) <EOL> def postInit ( self , offset , parent , slot ) : <EOL> self . offset = offset <EOL> self . parent = parent <EOL> self . slot = slot <EOL> def getPath ( self ) : <EOL> L = [ ] <EOL> x = self <EOL> while x . parent is not None : <EOL> L . append ( x . offset ) <EOL> x = x . parent <EOL> L . reverse ( ) <EOL> return L <EOL> def __getitem__ ( self , index ) : <EOL> slot , o = self . get ( index ) <EOL> n = INode ( o , persist = False ) <EOL> n . postInit ( index , self , slot ) <EOL> return n <EOL> def origstr ( self ) : <EOL> return str ( self . original ) <EOL> def format ( self ) : <EOL> return ( self . slot , self . origstr ( ) ) <EOL> class ConstantNode ( InspectorNode ) : <EOL> def __len__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> class DictionaryNode ( InspectorNode ) : <EOL> def get ( self , index ) : <EOL> L = self . original . items ( ) <EOL> L . sort ( ) <EOL> return L [ index ] <EOL> def __len__ ( self ) : <EOL> return len ( self . original ) <EOL> def origstr ( self ) : <EOL> return "<STR_LIT>" <EOL> class ListNode ( InspectorNode ) : <EOL> def get ( self , index ) : <EOL> return index , self . original [ index ] <EOL> def origstr ( self ) : <EOL> return "<STR_LIT>" <EOL> def __len__ ( self ) : <EOL> return len ( self . original ) <EOL> class AttributesNode ( InspectorNode ) : <EOL> def __len__ ( self ) : <EOL> return len ( dir ( self . original ) ) <EOL> def get ( self , index ) : <EOL> L = dir ( self . original ) <EOL> L . sort ( ) <EOL> return L [ index ] , getattr ( self . original , L [ index ] ) <EOL> class InstanceNode ( InspectorNode ) : <EOL> def __len__ ( self ) : <EOL> return len ( self . original . __dict__ ) + <NUM_LIT:1> <EOL> def get ( self , index ) : <EOL> if index == <NUM_LIT:0> : <EOL> if hasattr ( self . original , "<STR_LIT>" ) : <EOL> v = self . original . __class__ <EOL> else : <EOL> v = type ( self . original ) <EOL> return "<STR_LIT>" , v <EOL> else : <EOL> index -= <NUM_LIT:1> <EOL> L = self . original . __dict__ . items ( ) <EOL> L . sort ( ) <EOL> return L [ index ] <EOL> import types <EOL> for x in dict , types . DictProxyType : <EOL> registerAdapter ( DictionaryNode , x , INode ) <EOL> for x in list , tuple : <EOL> registerAdapter ( ListNode , x , INode ) <EOL> for x in int , str : <EOL> registerAdapter ( ConstantNode , x , INode ) <EOL> class InspectorTreeModel ( gtk . GenericTreeModel ) : <EOL> def __init__ ( self , root ) : <EOL> gtk . GenericTreeModel . __init__ ( self ) <EOL> self . root = INode ( root , persist = False ) <EOL> self . root . postInit ( <NUM_LIT:0> , None , '<STR_LIT:root>' ) <EOL> def on_get_flags ( self ) : <EOL> return <NUM_LIT:0> <EOL> def on_get_n_columns ( self ) : <EOL> return <NUM_LIT:1> <EOL> def on_get_column_type ( self , index ) : <EOL> return gobject . TYPE_STRING <EOL> def on_get_path ( self , node ) : <EOL> return node . getPath ( ) <EOL> def on_get_iter ( self , path ) : <EOL> x = self . root <EOL> for elem in path : <EOL> x = x [ elem ] <EOL> return x <EOL> def on_get_value ( self , node , column ) : <EOL> return node . format ( ) [ column ] <EOL> def on_iter_next ( self , node ) : <EOL> try : <EOL> return node . parent [ node . offset + <NUM_LIT:1> ] <EOL> except IndexError : <EOL> return None <EOL> def on_iter_children ( self , node ) : <EOL> return node [ <NUM_LIT:0> ] <EOL> def on_iter_has_child ( self , node ) : <EOL> return len ( node ) <EOL> def on_iter_n_children ( self , node ) : <EOL> return len ( node ) <EOL> def on_iter_nth_child ( self , node , n ) : <EOL> if node is None : <EOL> return None <EOL> return node [ n ] <EOL> def on_iter_parent ( self , node ) : <EOL> return node . parent <EOL> class Inspectro : <EOL> selected = None <EOL> def __init__ ( self , o = None ) : <EOL> self . xml = x = gtk . glade . XML ( sibpath ( __file__ , "<STR_LIT>" ) ) <EOL> self . tree_view = x . get_widget ( "<STR_LIT>" ) <EOL> colnames = [ "<STR_LIT:Name>" , "<STR_LIT>" ] <EOL> for i in range ( len ( colnames ) ) : <EOL> self . tree_view . append_column ( <EOL> gtk . TreeViewColumn ( <EOL> colnames [ i ] , gtk . CellRendererText ( ) , text = i ) ) <EOL> d = { } <EOL> for m in reflect . prefixedMethods ( self , "<STR_LIT>" ) : <EOL> d [ m . im_func . __name__ ] = m <EOL> self . xml . signal_autoconnect ( d ) <EOL> if o is not None : <EOL> self . inspect ( o ) <EOL> self . ns = { '<STR_LIT>' : self . inspect } <EOL> iwidget = x . get_widget ( '<STR_LIT:input>' ) <EOL> self . input = ConsoleInput ( iwidget ) <EOL> self . input . toplevel = self <EOL> iwidget . connect ( "<STR_LIT>" , self . input . _on_key_press_event ) <EOL> self . output = ConsoleOutput ( x . get_widget ( '<STR_LIT>' ) ) <EOL> def select ( self , o ) : <EOL> self . selected = o <EOL> self . ns [ '<STR_LIT>' ] = o <EOL> self . xml . get_widget ( "<STR_LIT>" ) . set_text ( repr ( o ) ) <EOL> self . xml . get_widget ( "<STR_LIT>" ) . set_text ( "<STR_LIT>" ) <EOL> def inspect ( self , o ) : <EOL> self . model = InspectorTreeModel ( o ) <EOL> self . tree_view . set_model ( self . model ) <EOL> self . inspected = o <EOL> def do ( self , command ) : <EOL> filename = '<STR_LIT>' <EOL> try : <EOL> print repr ( command ) <EOL> try : <EOL> code = compile ( command , filename , '<STR_LIT>' ) <EOL> except : <EOL> code = compile ( command , filename , '<STR_LIT>' ) <EOL> val = eval ( code , self . ns , self . ns ) <EOL> if val is not None : <EOL> print repr ( val ) <EOL> self . ns [ '<STR_LIT:_>' ] = val <EOL> except : <EOL> log . err ( ) <EOL> def on_inspect ( self , * a ) : <EOL> self . inspect ( self . selected ) <EOL> def on_inspect_new ( self , * a ) : <EOL> Inspectro ( self . selected ) <EOL> def on_row_activated ( self , tv , path , column ) : <EOL> self . select ( self . model . on_get_iter ( path ) . original ) <EOL> class LoggingProtocol ( policies . ProtocolWrapper ) : <EOL> """<STR_LIT>""" <EOL> logging = True <EOL> logViewer = None <EOL> def __init__ ( self , * args ) : <EOL> policies . ProtocolWrapper . __init__ ( self , * args ) <EOL> self . inLog = [ ] <EOL> self . outLog = [ ] <EOL> def write ( self , data ) : <EOL> if self . logging : <EOL> self . outLog . append ( ( time . time ( ) , data ) ) <EOL> if self . logViewer : <EOL> self . logViewer . updateOut ( self . outLog [ - <NUM_LIT:1> ] ) <EOL> policies . ProtocolWrapper . write ( self , data ) <EOL> def dataReceived ( self , data ) : <EOL> if self . logging : <EOL> self . inLog . append ( ( time . time ( ) , data ) ) <EOL> if self . logViewer : <EOL> self . logViewer . updateIn ( self . inLog [ - <NUM_LIT:1> ] ) <EOL> policies . ProtocolWrapper . dataReceived ( self , data ) <EOL> def __repr__ ( self ) : <EOL> r = "<STR_LIT>" + repr ( self . wrappedProtocol ) <EOL> if self . logging : <EOL> r += "<STR_LIT>" <EOL> return r <EOL> class LoggingFactory ( policies . WrappingFactory ) : <EOL> """<STR_LIT>""" <EOL> protocol = LoggingProtocol <EOL> logging = True <EOL> def buildProtocol ( self , addr ) : <EOL> p = self . protocol ( self , self . wrappedFactory . buildProtocol ( addr ) ) <EOL> p . logging = self . logging <EOL> return p <EOL> def __repr__ ( self ) : <EOL> r = "<STR_LIT>" + repr ( self . wrappedFactory ) <EOL> if self . logging : <EOL> r += "<STR_LIT>" <EOL> return r <EOL> class LogViewer : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , p ) : <EOL> self . p = p <EOL> vals = [ time . time ( ) ] <EOL> if p . inLog : <EOL> vals . append ( p . inLog [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> if p . outLog : <EOL> vals . append ( p . outLog [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> self . startTime = min ( vals ) <EOL> p . logViewer = self <EOL> self . xml = x = gtk . glade . XML ( sibpath ( __file__ , "<STR_LIT>" ) ) <EOL> self . xml . signal_autoconnect ( self ) <EOL> self . loglist = self . xml . get_widget ( "<STR_LIT>" ) <EOL> self . model = gtk . ListStore ( str , str , str ) <EOL> self . loglist . set_model ( self . model ) <EOL> self . loglist . set_reorderable ( <NUM_LIT:1> ) <EOL> self . loglist . set_headers_clickable ( <NUM_LIT:1> ) <EOL> for col in [ <EOL> gtk . TreeViewColumn ( '<STR_LIT>' , <EOL> gtk . CellRendererText ( ) , <EOL> text = <NUM_LIT:0> ) , <EOL> gtk . TreeViewColumn ( '<STR_LIT:D>' , <EOL> gtk . CellRendererText ( ) , <EOL> text = <NUM_LIT:1> ) , <EOL> gtk . TreeViewColumn ( '<STR_LIT>' , <EOL> gtk . CellRendererText ( ) , <EOL> text = <NUM_LIT:2> ) ] : <EOL> self . loglist . append_column ( col ) <EOL> col . set_resizable ( <NUM_LIT:1> ) <EOL> r = [ ] <EOL> for t , data in p . inLog : <EOL> r . append ( ( ( str ( t - self . startTime ) , "<STR_LIT:R>" , repr ( data ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) ) ) <EOL> for t , data in p . outLog : <EOL> r . append ( ( ( str ( t - self . startTime ) , "<STR_LIT:S>" , repr ( data ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) ) ) <EOL> r . sort ( ) <EOL> for i in r : <EOL> self . model . append ( i ) <EOL> def updateIn ( self , ( time , data ) ) : <EOL> self . model . append ( ( str ( time - self . startTime ) , "<STR_LIT:R>" , repr ( data ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) ) <EOL> def updateOut ( self , ( time , data ) ) : <EOL> self . model . append ( ( str ( time - self . startTime ) , "<STR_LIT:S>" , repr ( data ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) ) <EOL> def on_logview_destroy ( self , w ) : <EOL> self . p . logViewer = None <EOL> del self . p <EOL> def main ( ) : <EOL> x = Inspectro ( ) <EOL> x . inspect ( x ) <EOL> gtk . main ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> log . startLogging ( sys . stdout ) <EOL> main ( ) </s>
