[Pkg-privacy-commits] [pyptlib] 52/136: Update examples.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:07 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository pyptlib.

commit 000ae550fef9a0f1321d751c07f2af2f22adc90b
Author: George Kadianakis <desnacked at riseup.net>
Date:   Fri Oct 5 10:11:43 2012 -0400

    Update examples.
---
 examples/client.py | 47 ++++++++++++++++++++++-------------------------
 examples/server.py | 48 ++++++++++++++++++++++++------------------------
 2 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/examples/client.py b/examples/client.py
index c413b72..6ea4ab1 100755
--- a/examples/client.py
+++ b/examples/client.py
@@ -1,35 +1,32 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-""" This is an example client which shows how to call the pyptlib.easy high-level API. """
+"""This is a client-side example of the pyptlib API."""
 
-from pyptlib.client import init, reportSuccess, reportFailure, \
-    reportEnd
-
-
-class TransportLaunchException(Exception):
-
-    pass
-
-
-def launchClient(self, name, port):
-    if name != 'dummy':
-        raise TransportLaunchException('Tried to launch unsupported transport %s'
-                 % name)
+import sys
 
+import pyptlib
+import pyptlib.client
 
 if __name__ == '__main__':
-    supportedTransports = ['dummy', 'rot13']
-
-    managed_info = init(supportedTransports)
-    if managed_info is None:
-        print "Failed!"
-        return
+    try:
+        managed_info = pyptlib.client.init(["blackfish", "bluefish"])
+    except pyptlib.config.EnvError, err:
+        print "pyptlib could not bootstrap ('%s')." % str(err)
+        sys.exit(1)
 
     for transport in managed_info['transports']:
+        # Spawn all the transports in the list, and for each spawned
+        # transport report back the port where it is listening, and
+        # the SOCKS version it supports.
+
         try:
-            launchClient(transport, 8182)
-            reportSuccess(transport, 5, ('127.0.0.1', 8182), None, None)
-        except TransportLaunchException:
-            reportFailure(transport, 'Failed to launch')
-    reportEnd()
+            socks_version, bind_addrport = your_function_that_launches_transports(transport)
+        except YourFailException, err:
+            reportFailure(transport, "Failed to launch ('%s')." % str(err))
+            continue
+
+        pyptlib.client.reportSuccess(transport, socks_version, bind_addrport, None, None)
+
+    # After spawning our transports, report that we are done.
+    pyptlib.client.reportEnd()
diff --git a/examples/server.py b/examples/server.py
index 408a5e4..3e3d0c0 100755
--- a/examples/server.py
+++ b/examples/server.py
@@ -1,35 +1,35 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-""" This is an example server which shows how to call the pyptlib.easy high-level API. """
+"""This is a server-side example of the pyptlib API."""
 
-from pyptlib.server import init, reportSuccess, reportFailure, \
-    reportEnd
+import sys
 
+import pyptlib
+import pyptlib.server
 
-class TransportLaunchException(Exception):
-
-    pass
-
+if __name__ == '__main__':
+    try:
+        managed_info = pyptlib.server.init(["blackfish", "bluefish"])
+    except pyptlib.config.EnvError, err:
+        print "pyptlib could not bootstrap ('%s')." % str(err)
+        sys.exit(1)
 
-def launchServer(self, name, port):
-    if name != 'dummy':
-        raise TransportLaunchException('Tried to launch unsupported transport %s'
-                 % name)
+    for transport, transport_bindaddr in managed_info['transports'].items():
+        # Try to spawn transports and make them listen in the ports
+        # that Tor wants. Report failure or success appropriately.
 
+        # 'transport' is a string with the name of the transport.
+        # 'transport_bindaddr' is the (<ip>,<port>) where that
+        # transport should listen for connections.
 
-if __name__ == '__main__':
-    supportedTransports = ['dummy', 'rot13']
+        try:
+            bind_addrport = your_function_that_launches_transports(transport, transport_bindaddr)
+        except YourFailException, err:
+            reportFailure(transport, "Failed to launch ('%s')." % str(err))
+            continue
 
-    managed_info = init(supportedTransports)
-    if managed_info is None:
-        print "Failed!"
-        return
+        pyptlib.server.reportSuccess(transport, bind_addrport, None)
 
-    for transport, transport_bindaddr in managed_info['transports'].items():
-        try:
-            launchServer(transport, transport_bindaddr[1])
-            reportSuccess(transport, transport_bindaddr, None)
-        except TransportLaunchException:
-            reportFailure(transport, 'Failed to launch')
-    reportEnd()
+    # Report back after we finish spawning transports.
+    pyptlib.server.reportEnd()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git



More information about the Pkg-privacy-commits mailing list