<s> """<STR_LIT>""" <EOL> from guppy . etc import cmd <EOL> from guppy import hpy <EOL> from guppy . heapy import heapyc , Target <EOL> from guppy . heapy . RemoteConstants import * <EOL> from guppy . heapy . Console import Console <EOL> from guppy . sets import mutbitset <EOL> import os , socket , sys , time , thread , threading , traceback , Queue <EOL> class SocketClosed ( Exception ) : <EOL> pass <EOL> class IsolatedCaller : <EOL> def __init__ ( self , func ) : <EOL> self . func = func <EOL> def __call__ ( self , * args , ** kwds ) : <EOL> return self . func ( * args , ** kwds ) <EOL> class QueueWithReadline ( Queue . Queue ) : <EOL> def readline ( self , size = - <NUM_LIT:1> ) : <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> return self . get ( timeout = <NUM_LIT:0.5> ) <EOL> except Queue . Empty : <EOL> continue <EOL> class NotiInput : <EOL> def __init__ ( self , input , output ) : <EOL> self . input = input <EOL> self . output = output <EOL> def read ( self , size = - <NUM_LIT:1> ) : <EOL> return self . readline ( size ) <EOL> def readline ( self , size = - <NUM_LIT:1> ) : <EOL> self . output . write ( READLINE ) <EOL> return self . input . readline ( size ) <EOL> class Annex ( cmd . Cmd ) : <EOL> address_family = socket . AF_INET <EOL> socket_type = socket . SOCK_STREAM <EOL> use_rawinput = <NUM_LIT:0> <EOL> prompt = '<STR_LIT>' <EOL> def __init__ ( self , target , port = None ) : <EOL> cmd . Cmd . __init__ ( self ) <EOL> if port is None : <EOL> port = HEAPYPORT <EOL> self . server_address = ( LOCALHOST , port ) <EOL> self . target = target <EOL> target . close = IsolatedCaller ( <EOL> self . asynch_close ) <EOL> self . socket = None <EOL> self . isclosed = <NUM_LIT:0> <EOL> self . closelock = thread . allocate_lock ( ) <EOL> self . intlocals = { <EOL> } <EOL> self . do_reset ( '<STR_LIT>' ) <EOL> def asynch_close ( self ) : <EOL> self . closelock . acquire ( ) <EOL> try : <EOL> if not self . isclosed : <EOL> self . isclosed = <NUM_LIT:1> <EOL> self . disconnect ( ) <EOL> finally : <EOL> self . closelock . release ( ) <EOL> def connect ( self ) : <EOL> self . socket = socket . socket ( self . address_family , <EOL> self . socket_type ) <EOL> while not self . isclosed : <EOL> try : <EOL> self . socket . connect ( self . server_address ) <EOL> except SystemExit : <EOL> raise <EOL> except socket . error : <EOL> if self . isclosed : <EOL> raise <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> else : <EOL> break <EOL> else : <EOL> return <EOL> self . stdout = self . socket . makefile ( '<STR_LIT:w>' , bufsize = <NUM_LIT:0> ) <EOL> self . stdin = NotiInput ( self . socket . makefile ( '<STR_LIT:r>' ) , self . stdout ) <EOL> self . stderr = sys . stderr <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:4> ) : <EOL> self . interruptible = <NUM_LIT:0> <EOL> else : <EOL> self . start_ki_thread ( ) <EOL> self . interruptible = <NUM_LIT:1> <EOL> cmd . Cmd . __init__ ( self , stdin = self . stdin , stdout = self . stdout ) <EOL> def start_ki_thread ( self ) : <EOL> queue = QueueWithReadline ( ) <EOL> ostdin = self . stdin <EOL> self . stdin = NotiInput ( input = queue , <EOL> output = ostdin . output ) <EOL> socket = self . socket <EOL> def run ( ) : <EOL> try : <EOL> _hiding_tag_ = self . intlocals [ '<STR_LIT>' ] . _hiding_tag_ <EOL> while socket is self . socket : <EOL> line = ostdin . input . readline ( ) <EOL> if not line : <EOL> break <EOL> if line == KEYBOARDINTERRUPT : <EOL> if socket is self . socket : <EOL> heapyc . set_async_exc ( self . target . annex_thread , <EOL> KeyboardInterrupt ) <EOL> else : <EOL> queue . put ( line ) <EOL> finally : <EOL> if socket is self . socket : <EOL> heapyc . set_async_exc ( self . target . annex_thread , <EOL> SocketClosed ) <EOL> th = threading . Thread ( target = run , <EOL> args = ( ) ) <EOL> th . start ( ) <EOL> def disconnect ( self ) : <EOL> socket = self . socket <EOL> if socket is None : <EOL> return <EOL> self . socket = None <EOL> try : <EOL> socket . send ( DONE ) <EOL> except : <EOL> pass <EOL> try : <EOL> socket . close ( ) <EOL> except : <EOL> pass <EOL> sys . last_traceback = None <EOL> sys . exc_clear ( ) <EOL> def do_close ( self , arg ) : <EOL> self . asynch_close ( ) <EOL> return <NUM_LIT:1> <EOL> def help_close ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> do_h = cmd . Cmd . do_help <EOL> def help_h ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> help_help = help_h <EOL> def do_int ( self , arg ) : <EOL> ostdin = sys . stdin <EOL> ostdout = sys . stdout <EOL> ostderr = sys . stderr <EOL> try : <EOL> sys . stdin = self . stdin <EOL> sys . stdout = self . stdout <EOL> sys . stderr = self . stdout <EOL> con = Console ( stdin = sys . stdin , stdout = sys . stdout , <EOL> locals = self . intlocals ) <EOL> con . interact ( <EOL> "<STR_LIT>" % <EOL> con . EOF_key_sequence ) <EOL> finally : <EOL> sys . stdin = ostdin <EOL> sys . stdout = ostdout <EOL> sys . stderr = ostderr <EOL> def help_int ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> _bname = '<STR_LIT>' <EOL> def do_isolatest ( self , arg ) : <EOL> hp = self . intlocals [ '<STR_LIT>' ] <EOL> a = [ ] <EOL> self . _a = a <EOL> b = [ ] <EOL> self . intlocals [ self . _bname ] = b <EOL> eval ( '<STR_LIT:0>' , self . intlocals ) <EOL> testobjects = [ a , <EOL> b , <EOL> self . intlocals [ '<STR_LIT>' ] , <EOL> self . intlocals , <EOL> hp ] <EOL> h = hp . heap ( ) <EOL> if hp . iso ( * testobjects ) & h : <EOL> print >> self . stdout , '<STR_LIT>' <EOL> for i , v in enumerate ( testobjects ) : <EOL> if hp . iso ( v ) & h : <EOL> print >> self . stdout , '<STR_LIT>' % i <EOL> print >> self . stdout , hp . iso ( v ) . shpaths <EOL> else : <EOL> print >> self . stdout , '<STR_LIT>' <EOL> del self . _a <EOL> del self . intlocals [ self . _bname ] <EOL> def help_isolatest ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> def do_q ( self , arg ) : <EOL> print >> self . stdout , '<STR_LIT>' <EOL> print >> self . stdout , "<STR_LIT>" <EOL> def help_q ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> def do_reset ( self , arg ) : <EOL> self . intlocals . clear ( ) <EOL> self . intlocals . update ( <EOL> { '<STR_LIT>' : self . hpy , <EOL> '<STR_LIT>' : self . hpy ( ) , <EOL> '<STR_LIT:target>' : self . target <EOL> } ) <EOL> self . intlocals [ '<STR_LIT:h>' ] = self . intlocals [ '<STR_LIT>' ] <EOL> def help_reset ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> def do_stat ( self , arg ) : <EOL> print >> self . stdout , "<STR_LIT>" <EOL> print >> self . stdout , "<STR_LIT>" <EOL> print >> self . stdout , "<STR_LIT>" % self . target . sys . executable <EOL> print >> self . stdout , "<STR_LIT>" % self . target . sys . argv <EOL> print >> self . stdout , "<STR_LIT>" % self . target . wd <EOL> print >> self . stdout , "<STR_LIT>" % self . target . pid <EOL> print >> self . stdout , "<STR_LIT>" <EOL> if not self . interruptible : <EOL> print >> self . stdout , "<STR_LIT>" <EOL> def help_stat ( self ) : <EOL> print >> self . stdout , """<STR_LIT>""" <EOL> def hpy ( self , * args , ** kwds ) : <EOL> from guppy import hpy <EOL> hp = hpy ( * args , ** kwds ) <EOL> hp . View . is_hiding_calling_interpreter = <NUM_LIT:1> <EOL> hp . View . target = self . target <EOL> self . target . close . _hiding_tag_ = hp . _hiding_tag_ <EOL> hp . reprefix = '<STR_LIT>' <EOL> return hp <EOL> def run ( self ) : <EOL> try : <EOL> while not self . isclosed : <EOL> self . connect ( ) <EOL> if not self . isclosed : <EOL> self . do_stat ( '<STR_LIT>' ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> self . cmdloop ( ) <EOL> except SocketClosed : <EOL> break <EOL> except : <EOL> try : <EOL> traceback . print_exc ( file = self . stdout ) <EOL> except : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> break <EOL> continue <EOL> self . disconnect ( ) <EOL> finally : <EOL> self . asynch_close ( ) <EOL> def on ( ) : <EOL> global annex_thread , target <EOL> if annex_thread is not None : <EOL> return <EOL> if getattr ( sys , '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> return <EOL> start_annex = """<STR_LIT>""" <EOL> target = Target . Target ( ) <EOL> annex_thread = heapyc . interpreter ( start_annex , { '<STR_LIT:target>' : target } ) <EOL> target . annex_thread = annex_thread <EOL> def off ( ) : <EOL> global annex_thread , target <EOL> if annex_thread is None : <EOL> return <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> try : <EOL> close = target . close <EOL> except AttributeError : <EOL> print '<STR_LIT>' <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> else : <EOL> close ( ) <EOL> break <EOL> else : <EOL> raise <EOL> heapyc . set_async_exc ( annex_thread , SystemExit ) <EOL> annex_thread = target = None <EOL> annex_thread = None <EOL> target = None </s>
