[Pkg-privacy-commits] [pyptlib] 25/136: Added examples

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:02 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 4ef07a033089dc8eb9111c58b8f7afc206592173
Author: Brandon Wiley <brandon at blanu.net>
Date:   Mon Jun 25 15:34:37 2012 -0500

    Added examples
---
 src/examples/client.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/examples/daemon.py | 41 +++++++++++++++++++++++++++++++++++++++++
 src/examples/server.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 137 insertions(+)

diff --git a/src/examples/client.py b/src/examples/client.py
new file mode 100755
index 0000000..2a418dd
--- /dev/null
+++ b/src/examples/client.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python -u
+
+import os
+import sys
+
+import argparse
+
+from struct import unpack
+from socket import inet_ntoa
+
+from pyptlib.config.config import EnvException
+from pyptlib.config.client import ClientConfig
+
+class ManagedClient(Daemon):
+  def __init__(self):
+    try:
+      Daemon.__init__(self, ClientConfig(), SocksHandler())
+    except EnvException:
+      print('error 0')
+      return
+    except UnsupportedManagedTransportVersionException:
+      print('error 1')
+      return
+    except NoSupportedTransportsException:
+      print('error 2')
+      return
+
+    try:
+      self.launchClient(self.supportedTransport, 8182)
+      self.config.writeMethod(self.supportedTransport, 5, ('127.0.0.1', 8182), None, None)
+    except TransportLaunchException as e:
+      print('error 3')
+      self.config.writeMethodError(self.supportedTransport, e.message)
+
+    self.config.writeMethodEnd()
+    
+    self.run()
+      
+  def launchClient(self, name, port):
+    if name!=self.supportedTransport:
+      raise TransportLaunchException('Tried to launch unsupported transport %s' % (name))
+
+    client=DummyClient()
+    self.handler.setTransport(client)
+    add_service(Service(self.handler, port=port))    
+
+if __name__=='__main__':
+  server=ManagedClient()
+  
diff --git a/src/examples/daemon.py b/src/examples/daemon.py
new file mode 100644
index 0000000..c365b1b
--- /dev/null
+++ b/src/examples/daemon.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+import sys
+import time
+
+from struct import unpack
+from socket import inet_ntoa
+
+class Daemon:
+  config=None
+  handler=None
+  
+  supportedTransportVersion='1'
+  supportedTransport='dummy'
+
+  def __init__(self, configManager, handler):
+    self.config=configManager
+    self.handler=handler
+    
+    if self.config.checkManagedTransportVersion(self.supportedTransportVersion):
+      self.config.writeVersion(self.supportedTransportVersion)
+    else:
+      self.config.writeVersionError()
+      raise UnsupportedManagedTransportVersionException()
+        
+    if not self.config.checkTransportEnabled(self.supportedTransport):
+      raise NoSupportedTransportsException()
+  
+  def run(self):
+    eventloop.run()
+    
+class UnsupportedManagedTransportVersionException(Exception):
+  pass
+
+class NoSupportedTransportsException(Exception):
+  pass
+
+class TransportLaunchException(Exception):
+  def __init__(self, message):
+    self.message=message
+  
diff --git a/src/examples/server.py b/src/examples/server.py
new file mode 100755
index 0000000..b8515b3
--- /dev/null
+++ b/src/examples/server.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python -u
+
+import os
+import sys
+
+from struct import unpack
+from socket import inet_ntoa
+
+from pyptlib.config.config import EnvException
+from pyptlib.config.server import ServerConfig, MethodOptions
+
+class ManagedServer(Daemon):
+  def __init__(self):
+    try:
+      Daemon.__init__(self, ServerConfig(), ProxyHandler())
+    except EnvException:
+      print('error 0')
+      return
+    except UnsupportedManagedTransportVersionException:
+      print('error 1')
+      return
+    except NoSupportedTransportsException:
+      print('error 2')
+      return
+
+    try:
+      self.launchServer(self.supportedTransport, 8182)
+      self.config.writeMethod(self.supportedTransport, ('127.0.0.1', 8182), MethodOptions())
+    except TransportLaunchException as e:
+      print('error 3')
+      self.config.writeMethodError(self.supportedTransport, e.message)
+
+    self.config.writeMethodEnd()
+    
+    self.run()
+    
+  def launchServer(self, name, port):
+    if name!=self.supportedTransport:
+      raise TransportLaunchException('Tried to launch unsupported transport %s' % (name))
+
+    client=DummyServer()
+    self.handler.setTransport(client)
+    add_service(Service(self.handler, port=port))   
+
+if __name__=='__main__':
+  server=ManagedServer()
+  

-- 
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