<s> import os <EOL> import functools <EOL> import shutil <EOL> from twisted . internet import reactor , defer <EOL> from twisted . internet . endpoints import TCP4ClientEndpoint , TCP4ServerEndpoint <EOL> from twisted . web import server , resource <EOL> from twisted . internet . task import react <EOL> import txtorcon <EOL> class Simple ( resource . Resource ) : <EOL> isLeaf = True <EOL> def render_GET ( self , request ) : <EOL> return "<STR_LIT>" <EOL> @ defer . inlineCallbacks <EOL> def main ( reactor ) : <EOL> ep = TCP4ClientEndpoint ( reactor , "<STR_LIT:localhost>" , <NUM_LIT> ) <EOL> tor_protocol = yield txtorcon . build_tor_connection ( ep , build_state = False ) <EOL> print "<STR_LIT>" <EOL> hs_public_port = <NUM_LIT> <EOL> hs_port = yield txtorcon . util . available_tcp_port ( reactor ) <EOL> hs_string = '<STR_LIT>' % ( hs_public_port , hs_port ) <EOL> print "<STR_LIT>" , hs_string <EOL> print "<STR_LIT>" <EOL> hs = txtorcon . EphemeralHiddenService ( [ hs_string ] ) <EOL> yield hs . add_to_tor ( tor_protocol ) <EOL> print "<STR_LIT>" , hs . hostname <EOL> print "<STR_LIT>" <EOL> site = server . Site ( Simple ( ) ) <EOL> hs_endpoint = TCP4ServerEndpoint ( reactor , hs_port , interface = '<STR_LIT:127.0.0.1>' ) <EOL> yield hs_endpoint . listen ( site ) <EOL> d = defer . Deferred ( ) <EOL> @ defer . inlineCallbacks <EOL> def remove ( ) : <EOL> print "<STR_LIT>" <EOL> print hs . private_key <EOL> yield hs . remove_from_tor ( tor_protocol ) <EOL> d . callback ( None ) <EOL> if False : <EOL> reactor . callLater ( <NUM_LIT:5> , remove ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> yield d <EOL> react ( main ) </s>
