Skip to content
Snippets Groups Projects
Commit 51866990 authored by Brandon Wiley's avatar Brandon Wiley
Browse files

Examples for high-level API

parent d0df9964
No related branches found
No related tags found
No related merge requests found
#!/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()
#!/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
......@@ -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)
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment