File: silabserver.py

package info (click to toggle)
python-soappy 0.9.7-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 500 kB
  • ctags: 1,020
  • sloc: python: 7,572; makefile: 43; sh: 16
file content (141 lines) | stat: -rwxr-xr-x 3,516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python

# Copyright (c) 2001 actzero, inc. All rights reserved.

# This is a server for the XMethods matrix
# (http://jake.soapware.org/currentXmethodsResults).

import getopt
import sys

sys.path.insert (1, '..')

import SOAP

if SOAP.Config.SSLserver:
    from M2Crypto import SSL

ident = '$Id: silabserver.py,v 1.1.1.1 2001/06/27 21:36:14 cullman Exp $'

def echoFloat (inputFloat):
    return inputFloat

def echoFloatArray (inputFloatArray):
    return inputFloatArray

def echoInteger (inputInteger):
    return inputInteger

def echoIntegerArray (inputIntegerArray):
    return inputIntegerArray

def echoString (inputString):
    return inputString

def echoStringArray (inputStringArray):
    return inputStringArray

def echoStruct (inputStruct):
    return inputStruct

def echoStructArray (inputStructArray):
    return inputStructArray

def echoVoid ():
    return SOAP.voidType()

def echoDate (inputDate):
    return SOAP.dateTimeType (inputDate)

def echoBase64 (inputBase64):
    return SOAP.binaryType (inputBase64)

namespace = 'http://soapinterop.org/'

DEFAULT_HOST            = 'localhost'
DEFAULT_HTTP_PORT       = 8080
DEFAULT_HTTPS_PORT      = 8443

def usage (error = None):
    sys.stdout = sys.stderr

    if error != None:
        print error

    print """usage: %s [options]
  If a long option shows an argument is mandatory, it's mandatory for the
  equivalent short option also. The default (if any) is shown in brackets.

  -?, --help            display this usage
  -h, --host=HOST       use HOST in the address to listen on [%s]
  -p, --port=PORT       listen on PORT [%d]
""" % (sys.argv[0], DEFAULT_HOST, DEFAULT_HTTP_PORT),

    if SOAP.Config.SSLserver:
        print "  -s, --ssl             serve using SSL"

    sys.exit (0)

def main ():
    host = DEFAULT_HOST
    port = None
    ssl = 0

    try:
        opts = '?h:p:'
        args = ['help', 'host', 'port']

        if SOAP.Config.SSLserver:
            opts += 's'
            args += ['ssl']

        opts, args = getopt.getopt (sys.argv[1:], opts, args)

        for opt, arg in opts:
            if opt in ('-?', '--help'):
                usage ()
            elif opt in ('-h', '--host'):
                host = arg
            elif opt in ('-p', '--port'):
                port = int (arg)
            elif opt in ('-s', '--ssl'):
                ssl = 1
            else:
                raise AttributeError, \
                     "Recognized but unimplemented option `%s'" % opt
    except SystemExit:
        raise
    except:
        usage (sys.exc_info ()[1])

    if port == None:
        port = [DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT][ssl]

    if ssl:
        ssl_context = SSL.Context()
        ssl_context.load_cert('server.pem')
    else:
        ssl_context = None

    server = SOAP.SOAPServer ((host, port), namespace = namespace,
        ssl_context = ssl_context)

    server.registerFunction (echoFloat)
    server.registerFunction (echoFloatArray)
    server.registerFunction (echoInteger)
    server.registerFunction (echoIntegerArray)
    server.registerFunction (echoString)
    server.registerFunction (echoStringArray)
    server.registerFunction (echoStruct)
    server.registerFunction (echoStructArray)
    server.registerFunction (echoVoid)
    server.registerFunction (echoDate)
    server.registerFunction (echoBase64)

    server.serve_forever()

if __name__ == '__main__':
    try:
        sys.exit (main ())
    except KeyboardInterrupt:
        sys.exit (0)