[tor-commits] [stem/master] Added downloadable tutotial for tutorial East of the Sun & West of the Moon

atagar at torproject.org atagar at torproject.org
Mon May 25 17:15:20 UTC 2015


commit 9886aeef2abc9de64bd00c62339b58eee0d8bc7b
Author: Sambuddha Basu <sambuddhabasu1 at gmail.com>
Date:   Mon May 25 08:12:01 2015 +0400

    Added downloadable tutotial for tutorial East of the Sun & West of the Moon
---
 docs/_static/example/utilities.py  |   28 ++++++++++++++++++++++++++++
 docs/tutorials/east_of_the_sun.rst |   33 +++------------------------------
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/docs/_static/example/utilities.py b/docs/_static/example/utilities.py
new file mode 100644
index 0000000..460f6ff
--- /dev/null
+++ b/docs/_static/example/utilities.py
@@ -0,0 +1,28 @@
+import sys
+
+from stem.util.connection import get_connections, system_resolvers
+from stem.util.system import pid_by_name
+
+resolvers = system_resolvers()
+
+if not resolvers:
+  print "Stem doesn't support any connection resolvers on our platform."
+  sys.exit(1)
+
+picked_resolver = resolvers[0]  # lets just opt for the first
+print "Our platform supports connection resolution via: %s (picked %s)" % (', '.join(resolvers), picked_resolver)
+
+tor_pids = pid_by_name('tor', multiple = True)
+
+if not tor_pids:
+  print "Unable to get tor's pid. Is it running?"
+  sys.exit(1)
+elif len(tor_pids) > 1:
+  print "You're running %i instances of tor, picking the one with pid %i" % (len(tor_pids), tor_pids[0])
+else:
+  print "Tor is running with pid %i" % tor_pids[0]
+
+print "\nConnections:\n"
+
+for conn in get_connections(picked_resolver, process_pid = tor_pids[0], process_name = 'tor'):
+  print "  %s:%s => %s:%s" % (conn.local_address, conn.local_port, conn.remote_address, conn.remote_port)
diff --git a/docs/tutorials/east_of_the_sun.rst b/docs/tutorials/east_of_the_sun.rst
index 13ede2d..f577df9 100644
--- a/docs/tutorials/east_of_the_sun.rst
+++ b/docs/tutorials/east_of_the_sun.rst
@@ -33,36 +33,9 @@ but likely also a violation of wiretap laws.
 With that out of the way, how do you look up this information? Below is a
 simple script that dumps Tor's present connections.
 
-::
-
-  import sys 
-
-  from stem.util.connection import get_connections, system_resolvers
-  from stem.util.system import pid_by_name
-
-  resolvers = system_resolvers()
-
-  if not resolvers:
-    print "Stem doesn't support any connection resolvers on our platform."
-    sys.exit(1)
-
-  picked_resolver = resolvers[0]  # lets just opt for the first
-  print "Our platform supports connection resolution via: %s (picked %s)" % (', '.join(resolvers), picked_resolver)
-
-  tor_pids = pid_by_name('tor', multiple = True)
-
-  if not tor_pids:
-    print "Unable to get tor's pid. Is it running?"
-    sys.exit(1)
-  elif len(tor_pids) > 1:
-    print "You're running %i instances of tor, picking the one with pid %i" % (len(tor_pids), tor_pids[0])
-  else:
-    print "Tor is running with pid %i" % tor_pids[0]
-
-  print "\nConnections:\n"
-
-  for conn in get_connections(picked_resolver, process_pid = tor_pids[0], process_name = 'tor'):
-    print "  %s:%s => %s:%s" % (conn.local_address, conn.local_port, conn.remote_address, conn.remote_port)
+.. literalinclude:: /_static/example/utilities.py
+   :caption: `[Download] <../_static/example/utilities.py>`__
+   :language: python
 
 ::
 





More information about the tor-commits mailing list