[Pkg-privacy-commits] [pyptlib] 30/136: Examples for high-level API
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:03 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 5186699086f02b42b72d02e1aeee3fd6aca6aec4
Author: Brandon Wiley <brandon at blanu.net>
Date: Fri Jun 29 14:10:10 2012 -0500
Examples for high-level API
---
src/examples/client.py | 64 ++++++++++------------------------------------
src/examples/server.py | 53 ++++++++++----------------------------
src/pyptlib/easy/client.py | 6 ++++-
src/pyptlib/easy/server.py | 6 ++++-
4 files changed, 37 insertions(+), 92 deletions(-)
diff --git a/src/examples/client.py b/src/examples/client.py
index bf2782b..048cdb5 100755
--- a/src/examples/client.py
+++ b/src/examples/client.py
@@ -1,62 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import os
-import sys
-
-import argparse
-
-from struct import unpack
-from socket import inet_ntoa
-
-from pyptlib.config import EnvException
-from pyptlib.client import ClientConfig
-
-
-class UnsupportedManagedTransportVersionException(Exception):
-
- pass
-
-
-class NoSupportedTransportsException(Exception):
-
- pass
-
+from pyptlib.easy.client import init, reportSucess, reportFailure, reportEnd
class TransportLaunchException(Exception):
-
- def __init__(self, message):
- message = message
-
+ pass
def launchClient(self, name, port):
- if name != supportedTransport:
+ if name != 'dummy':
raise TransportLaunchException('Tried to launch unsupported transport %s'
% name)
-
if __name__ == '__main__':
- supportedTransportVersion = '1'
- supportedTransport = 'dummy'
- config = ClientConfig()
-
- if config.checkManagedTransportVersion(supportedTransportVersion):
- config.writeVersion(supportedTransportVersion)
- else:
- config.writeVersionError()
- raise UnsupportedManagedTransportVersionException()
-
- if not config.checkTransportEnabled(supportedTransport):
- raise NoSupportedTransportsException()
-
- try:
- launchClient(supportedTransport, 8182)
- config.writeMethod(supportedTransport, 5, ('127.0.0.1', 8182),
- None, None)
- except TransportLaunchException, e:
- print 'error 3'
- config.writeMethodError(supportedTransport, e.message)
-
- config.writeMethodEnd()
-
- run()
+ supportedTransports = ['dummy', 'rot13']
+
+ matchedTransports=init(supportedTransports)
+ for transport in matchedTransports:
+ try:
+ launchClient(transport, 8182)
+ reportSuccess(transport, 5, ('127.0.0.1', 8182), None, None)
+ except TransportLaunchException:
+ reportFailure(transport, 'Failed to launch')
+ reportEnd()
diff --git a/src/examples/server.py b/src/examples/server.py
index 4340f89..4f1b968 100755
--- a/src/examples/server.py
+++ b/src/examples/server.py
@@ -1,49 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import os
-import sys
-
-from struct import unpack
-from socket import inet_ntoa
-
-from pyptlib.config import EnvException
-from pyptlib.server import ServerConfig, MethodOptions
-
-supportedTransport = 'dummy'
+from pyptlib.easy.server import init, reportSucess, reportFailure, reportEnd
+class TransportLaunchException(Exception):
+ pass
def launchServer(self, name, port):
- if name != supportedTransport:
+ if name != 'dummy':
raise TransportLaunchException('Tried to launch unsupported transport %s'
% name)
-
if __name__ == '__main__':
- supportedTransportVersion = '1'
- config = ClientConfig()
- try:
- if config.checkManagedTransportVersion(supportedTransportVersion):
- config.writeVersion(supportedTransportVersion)
- else:
- config.writeVersionError()
- raise UnsupportedManagedTransportVersionException()
- except EnvException:
- print 'error 0'
- return
- except UnsupportedManagedTransportVersionException:
- print 'error 1'
- return
- except NoSupportedTransportsException:
- print 'error 2'
- return
-
- try:
- launchServer(supportedTransport, 8182)
- config.writeMethod(supportedTransport, ('127.0.0.1', 8182),
- MethodOptions())
- except TransportLaunchException, e:
- print 'error 3'
- config.writeMethodError(supportedTransport, e.message)
-
- config.writeMethodEnd()
+ supportedTransports = ['dummy', 'rot13']
+
+ matchedTransports=init(supportedTransports)
+ for transport in matchedTransports:
+ try:
+ launchServer(transport, 8182)
+ reportSuccess(transport, ('127.0.0.1', 8182), None)
+ except TransportLaunchException:
+ reportFailure(transport, 'Failed to launch')
+ reportEnd()
\ No newline at end of file
diff --git a/src/pyptlib/easy/client.py b/src/pyptlib/easy/client.py
index 7f4129d..5461f8b 100644
--- a/src/pyptlib/easy/client.py
+++ b/src/pyptlib/easy/client.py
@@ -14,7 +14,11 @@ from pyptlib.client import ClientConfig
def init(transports):
supportedTransportVersion = '1'
- config = ClientConfig()
+
+ try:
+ config = ClientConfig()
+ except EnvException:
+ return []
if config.checkManagedTransportVersion(supportedTransportVersion):
config.writeVersion(supportedTransportVersion)
diff --git a/src/pyptlib/easy/server.py b/src/pyptlib/easy/server.py
index e916007..0be7441 100644
--- a/src/pyptlib/easy/server.py
+++ b/src/pyptlib/easy/server.py
@@ -14,7 +14,11 @@ from pyptlib.client import ServerConfig
def init(transports):
supportedTransportVersion = '1'
- config = ServerConfig()
+
+ try:
+ config = ServerConfig()
+ except EnvException:
+ return []
if config.checkManagedTransportVersion(supportedTransportVersion):
config.writeVersion(supportedTransportVersion)
--
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