File: README

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 (228 lines) | stat: -rw-r--r-- 7,189 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Copyright (c) 2001

SOAP.py 0.9.7 - Cayce Ullman   (c_ullman@yahoo.com)
                Brian Matthews (blm@blmatthews.com)

MANIFEST:
README
SOAP.py       the library
SOAPtest.py   tests the builder and parser
echoClient.py an example client
echoServer.py an example server
speedTest.py  benchmarks the various parsers, compares speed to DOM
TCtest.py     experimental type coercion system tests
tests/*       examples
validate/*    interop client and servers
bid/*	      N+I interop client and server

IMPORTANT NOTE:

It appears that there are some memory leaks in the Python 2.0 pyexpat, so
if you run a server under Python 2.0, eventually it will run out of memory.
We *strongly* recommend upgrading to Python 2.1, which doesn't exhibit the
memory leak (and has a number of other bug fixes and additional features).

SSL NOTE:

If you want to use either an SSL client or server, you'll need to have
OpenSSL (http://www.openssl.org/) available, and build your Python with
OpenSSL support (see the README in the top of the Python source directory
for how to customize Modules/Setup, and make sure the socket module with
SSL support lines are uncommented). If you want to use an SSL server, in
addition to building your Python for OpenSSL, you'll need to build and
install M2Crypto (http://www.pobox.org.sg/home/ngps/m2/).

HOWTO:

The easiest way to get up to speed is to run and read the scripts in the
tests directory. Better documentation is coming.

Here are some examples of how to use SOAP.py:

CLIENT EXAMPLES:

## CODE
import SOAP
server = SOAP.SOAPProxy("http://localhost:8080/")
print server.echo("Hello world")
## /CODE

This opens a connection to the server listening on localhost:8080, calls the
method echo with the ordered parameter of "Hello World", and prints the
results.

## CODE
import SOAP
server = SOAP.SOAPProxy("https://localhost:8443/")
print server.echo("Hello world")
## /CODE

This opens a secure connection to the SSL server listening on
localhost:8443, calls the method echo with the ordered parameter of
"Hello World" and prints the results. Python must be built with OpenSSL.

## CODE
import SOAP
server = SOAP.SOAPProxy("http://services.xmethods.com/soap",
        	        namespace = "urn:xmethods-delayed-quotes")
print server.getQuote(symbol = "IBM")
## /CODE

This calls method getQuote that is in the namespace URI of
urn:xmethods-delayed-quotes on server services.xmethods.com. getQuote is
passed a named parameter, symbol.

## CODE
import SOAP
server = SOAP.SOAPProxy("http://services.xmethods.com/soap")

print server._ns("urn:xmethods-delayed-quotes").getQuote(symbol = "IBM")
## /CODE

This does the same thing as the previous example, however namespace is
specified inline on a per call basis rather than at the server level.

## CODE
import SOAP
server = SOAP.SOAPProxy("http://services.xmethods.com/soap",
			soapaction = "http://somesite.com/myaction")

print server._ns("urn:xmethods-delayed-quotes").getQuote(symbol = "IBM")
## /CODE

This is the same quote call with a soapaction specified.

## CODE
import SOAP
server = SOAP.SOAPProxy("http://services.xmethods.com:80/soap")

ns = "urn:xmethods-delayed-quotes")
sa = "http://somesite.com/myaction"
my_call = server._ns(ns)._sa(sa)
my_call.getQuote(symbol = "IBM")
my_call.getQuote(symbol = "IBM")
my_call.getQuote(symbol = "IBM")
## /CODE

The same example, this time with both the soapaction and the namespace
specified inline and saved in a local variable for getQuote to be called
against.

** What SOAP.py does with the results of a call could seem surprising. If
there is only one element in the structType that has the return value and
unwrap_results is turned on (the default) it will bubble up the single
attribute, otherwise it will return you a structType object with all of the
attributes.

SERVER EXAMPLES:

## CODE
import SOAP
def echo(s):
    return s + s # repeats a string twice

server = SOAP.SOAPServer(("localhost", 8080))
server.registerFunction(echo)
server.serve_forever()
## /CODE

This exposes the function echo (that takes an unnamed arguement) on a server
running on localhost:8080.

## CODE
import SOAP
def echo(s):
    return s + s # repeats a string twice

server = SOAP.SOAPServer()
server.registerFunction(echo, "echo-space")
server.serve_forever()
## /CODE

The same as above, but this time the method is available in the namespace
"echo-space".

## CODE
import SOAP

class echoBuilder:
    def echo(self, val):
        return val + val

server = SOAP.SOAPServer()
e = echoBuilder()
server.registerObject(e)
server.serve_forever()
## /CODE

This registers the whole instance of the object echoBuilder, e.  Every
method of the instance is exposed on the server.

## CODE
import SOAP

def echo(**kw):
    return kw['first'] + kw['second'] + kw['third']

server = SOAP.SOAPServer()
server.registerKWFunction(echo)
server.serve_forever()
## /CODE

This time the method echo is exposed and it expects named arguments. The
main thing to notice here is the use of the method registerKWFunction over
registerFunction.

## CODE
import SOAP

from M2Crypto import SSL

def echo(s):
    return s+s # repeats a string twice

ssl_context = SSL.Context()
ssl_context.load_cert('server.pem')

server = SOAP.SOAPServer(("localhost",8443), ssl_context = ssl_context)
server.registerFunction(echo)
server.serve_forever()
## /CODE

This exposes the function echo (taking an unnamed arguement) on a server
accepting SSL connections at localhost:8443. Ng Pheng Siong's M2Crypto
package (available at <http://www.pobox.org.sg/home/ngps/m2/>) must be
installed. Also see tests/silabserver.py.


Copyright (c) 2001, Cayce Ullman.
Copyright (c) 2001, Brian Matthews.

All rights reserved.

LICENSE:
----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

Neither the name of actzero, inc. nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.