diff --git a/examples/connect.py b/examples/connect.py index 7ecb3f50..c7b7473d 100644 --- a/examples/connect.py +++ b/examples/connect.py @@ -7,6 +7,7 @@ import txtorcon +@react @inlineCallbacks def main(reactor): ep = TCP4ClientEndpoint(reactor, "localhost", 9051) @@ -21,6 +22,3 @@ def main(reactor): print("Tor state created. Circuits:") for circuit in state.circuits.values(): print(" {circuit.id}: {circuit.path}".format(circuit=circuit)) - - -react(main) diff --git a/examples/disallow_streams_by_port.py b/examples/disallow_streams_by_port.py index 2f295fd6..1fe744fe 100755 --- a/examples/disallow_streams_by_port.py +++ b/examples/disallow_streams_by_port.py @@ -53,6 +53,7 @@ def stream_closed(x): return None +@react @inlineCallbacks def main(reactor): control_ep = clientFromString(reactor, "tcp:localhost:9051") @@ -67,6 +68,3 @@ def main(reactor): for s in state.streams.values(): print(" ", s) yield Deferred() - - -react(main) diff --git a/examples/dns_lookups.py b/examples/dns_lookups.py index 09b454ed..f49dc32d 100644 --- a/examples/dns_lookups.py +++ b/examples/dns_lookups.py @@ -6,6 +6,7 @@ import txtorcon +@react @inlineCallbacks def main(reactor): control_ep = clientFromString(reactor, "tcp:localhost:9051") @@ -17,7 +18,3 @@ def main(reactor): print("Doing PTR on {}".format(ans)) ans = yield tor.dns_resolve_ptr(ans) print("...got answer: {}".format(ans)) - - -if __name__ == '__main__': - react(main) diff --git a/examples/launch_tor.py b/examples/launch_tor.py index 42892669..3ac02204 100755 --- a/examples/launch_tor.py +++ b/examples/launch_tor.py @@ -11,6 +11,7 @@ from twisted.internet.defer import inlineCallbacks +@react @inlineCallbacks def main(reactor): # note that you can pass a few options as kwargs @@ -55,7 +56,3 @@ def main(reactor): print("Querying to see it changed:") socksport = yield tor.protocol.get_conf("SOCKSPort") print("SOCKSPort", socksport) - - -if __name__ == '__main__': - react(main) diff --git a/examples/launch_tor_endpoint.py b/examples/launch_tor_endpoint.py index ff805b0c..7346242a 100755 --- a/examples/launch_tor_endpoint.py +++ b/examples/launch_tor_endpoint.py @@ -23,6 +23,7 @@ def render_GET(self, request): return "Hello, world! I'm a hidden service!" +@react @inlineCallbacks def main(reactor): # several ways to proceed here and what they mean: @@ -88,6 +89,3 @@ def sleep(s): for i in range(10): print("Stopping in {}...".format(10 - i)) yield sleep(1) - - -react(main) diff --git a/examples/launch_tor_unix_sockets.py b/examples/launch_tor_unix_sockets.py index 56c29d2e..12e236f4 100644 --- a/examples/launch_tor_unix_sockets.py +++ b/examples/launch_tor_unix_sockets.py @@ -17,6 +17,7 @@ from twisted.internet.defer import inlineCallbacks +@react @inlineCallbacks def main(reactor): # we must have a directory owned by us with 0700 permissions to @@ -57,7 +58,3 @@ def main(reactor): body = yield readBody(resp) print("received body ({} bytes)".format(len(body))) print("{}\n[...]\n{}\n".format(body[:200], body[-200:])) - - -if __name__ == '__main__': - react(main) diff --git a/examples/web_client.py b/examples/web_client.py index 347dcbca..7f17a7c4 100644 --- a/examples/web_client.py +++ b/examples/web_client.py @@ -12,6 +12,7 @@ from txtorcon.util import default_control_port +@react @inlineCallbacks def main(reactor): # use port 9051 for system tor instances, or: @@ -39,7 +40,3 @@ def main(reactor): body = yield readBody(resp) print("received body ({} bytes)".format(len(body))) print("{}\n[...]\n{}\n".format(body[:200], body[-200:])) - - -if __name__ == '__main__': - react(main) diff --git a/examples/web_client_custom_circuit.py b/examples/web_client_custom_circuit.py index 44595579..33738b7a 100644 --- a/examples/web_client_custom_circuit.py +++ b/examples/web_client_custom_circuit.py @@ -17,6 +17,7 @@ from txtorcon.util import default_control_port +@react @inlineCallbacks def main(reactor): # use port 9051 for system tor instances, or: @@ -79,5 +80,3 @@ def connectionLost(self, reason): yield d print("All done, closing the circuit") yield circ.close() - -react(main) diff --git a/examples/web_client_treq.py b/examples/web_client_treq.py index deb28767..99d1a44b 100644 --- a/examples/web_client_treq.py +++ b/examples/web_client_treq.py @@ -18,6 +18,7 @@ raise SystemExit(1) +@react @inlineCallbacks def main(reactor): ep = TCP4ClientEndpoint(reactor, '127.0.0.1', default_control_port()) @@ -37,6 +38,3 @@ def main(reactor): data[:120], data[-120:], )) - - -react(main)