<s> from __future__ import print_function <EOL> from twisted . internet . task import react <EOL> from twisted . internet . defer import inlineCallbacks , Deferred <EOL> from twisted . internet . endpoints import TCP4ClientEndpoint <EOL> from zope . interface import implementer <EOL> import txtorcon <EOL> @ implementer ( txtorcon . ICircuitListener ) <EOL> class MyCircuitListener ( object ) : <EOL> def circuit_new ( self , circuit ) : <EOL> print ( "<STR_LIT>" , circuit ) <EOL> def circuit_launched ( self , circuit ) : <EOL> print ( "<STR_LIT>" , circuit ) <EOL> def circuit_extend ( self , circuit , router ) : <EOL> print ( "<STR_LIT>" , circuit ) <EOL> def circuit_built ( self , circuit ) : <EOL> print ( "<STR_LIT>" , circuit ) <EOL> def circuit_closed ( self , circuit , ** kw ) : <EOL> print ( "<STR_LIT>" , circuit , kw ) <EOL> def circuit_failed ( self , circuit , ** kw ) : <EOL> print ( "<STR_LIT>" , circuit , kw ) <EOL> @ inlineCallbacks <EOL> def main ( reactor ) : <EOL> tor_ep = TCP4ClientEndpoint ( reactor , "<STR_LIT:localhost>" , <NUM_LIT> ) <EOL> connection = yield txtorcon . build_tor_connection ( tor_ep , build_state = False ) <EOL> version = yield connection . get_info ( '<STR_LIT:version>' , '<STR_LIT>' ) <EOL> print ( "<STR_LIT>" . format ( ** version ) ) <EOL> print ( "<STR_LIT>" , version [ '<STR_LIT>' ] ) <EOL> print ( "<STR_LIT>" ) <EOL> state = yield txtorcon . TorState . from_protocol ( connection ) <EOL> print ( "<STR_LIT>" ) <EOL> state . add_circuit_listener ( MyCircuitListener ( ) ) <EOL> print ( "<STR_LIT>" ) <EOL> yield connection . signal ( '<STR_LIT>' ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> for c in state . circuits . values ( ) : <EOL> print ( '<STR_LIT:U+0020>' , c ) <EOL> print ( "<STR_LIT>" ) <EOL> def print_info ( i ) : <EOL> print ( "<STR_LIT>" , i ) <EOL> connection . add_event_listener ( '<STR_LIT>' , print_info ) <EOL> done = Deferred ( ) <EOL> yield done <EOL> react ( main ) </s>
