Imported Upstream version 12.1.0
[contrib/python-twisted.git] / doc / web / examples / soap.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 This is an example of a simple SOAP server.
6
7 Usage:
8     $ python soap.py
9
10 An example session (assuming the server is running):
11
12    >>> import SOAPpy
13    >>> p = SOAPpy.SOAPProxy('http://localhost:8080/')
14    >>> p.add(a=1)
15    1
16    >>> p.add(a=1, b=3)
17    4
18    >>> p.echo("Hello World")
19    'Hello World'
20
21 """
22
23 from twisted.web import soap, server
24 from twisted.internet import reactor, defer
25
26
27 class Example(soap.SOAPPublisher):
28     """
29     It publishs two methods, 'add' and 'echo'.
30     """
31
32     def soap_echo(self, x):
33         return x
34
35     def soap_add(self, a=0, b=0):
36         return a + b
37     soap_add.useKeywords = 1
38
39     def soap_deferred(self):
40         return defer.succeed(2)
41
42
43 reactor.listenTCP(8080, server.Site(Example()))
44 reactor.run()