Skip to content

Commit

Permalink
added wsgi_soap_application() function in the new rpclib.util.simple …
Browse files Browse the repository at this point in the history
…module.

also updated documentation and helloworld_soap example.
  • Loading branch information
plq committed Dec 6, 2011
1 parent 549d06a commit c0d9cca
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 26 deletions.
19 changes: 15 additions & 4 deletions doc/source/manual/helloworld.rst
Expand Up @@ -14,7 +14,7 @@ Defining an Rpclib Service
Here we introduce the fundamental mechanisms the rpclib offers to expose your
services.

This example is available here: http://github.com/arskom/rpclib/blob/master/examples/helloworld_soap.py
The simpler version of this example is available here: http://github.com/arskom/rpclib/blob/master/examples/helloworld_soap.py
::

import logging
Expand Down Expand Up @@ -162,16 +162,27 @@ under the targetNamespace 'rpclib.examples.hello.soap': ::
application = Application([HelloWorldService], 'rpclib.examples.hello.soap',
interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11())

We then wrap the rpclib application with its wsgi wrapper and register it as the
handler to the wsgi server, and run the http server: ::
We then wrap the rpclib application with its wsgi wrapper: ::

server = make_server('127.0.0.1', 7789, WsgiApplication(application))
wsgi_app = WsgiApplication(application)

The above two lines can be replaced with an easier-to-use function that covers
this common use case: ::

from rpclib.util.simple import wsgi_soap_application
wsgi_app = wsgi_soap_application([HelloWorldService], 'rpclib.examples.hello.soap')

We now register the WSGI application as the handler to the wsgi server, and run
the http server: ::

server = make_server('127.0.0.1', 7789, wsgi_app)

print "listening to http://127.0.0.1:7789"
print "wsdl is at: http://localhost:7789/?wsdl"

server.serve_forever()


.. NOTE::
* **Django users:** See this gist for a django wrapper example: https://gist.github.com/1242760
* **Twisted users:** See the this example that illustrates deploying an
Expand Down
12 changes: 6 additions & 6 deletions doc/source/reference/util.rst
Expand Up @@ -7,33 +7,33 @@ Class Dictionary

.. automodule:: rpclib.util.cdict
:members:
:inherited-members:

Element Tree Conversion
-----------------------

.. automodule:: rpclib.util.etreeconv
:members:
:inherited-members:

Simple Wrappers
---------------

.. automodule:: rpclib.util.simple
:members:

Xml Utilities
-------------

.. automodule:: rpclib.util.xml
:members:
:inherited-members:

Ordered Dictionary
------------------

.. automodule:: rpclib.util.odict
:members:
:inherited-members:

Ordered Set
-----------

.. automodule:: rpclib.util.oset
:members:
:inherited-members:

28 changes: 12 additions & 16 deletions examples/helloworld_soap.py
Expand Up @@ -31,15 +31,19 @@

import logging

from rpclib.application import Application
from rpclib.decorator import srpc
from rpclib.interface.wsdl import Wsdl11
from rpclib.protocol.soap import Soap11
from rpclib.service import ServiceBase
from rpclib.model.complex import Iterable
from rpclib.model.primitive import Integer
from rpclib.model.primitive import String
from rpclib.server.wsgi import WsgiApplication

from rpclib.util.simple import wsgi_soap_application

try:
from wsgiref.simple_server import make_server
except ImportError:
print "Error: example server code requires Python >= 2.5"
raise

'''
This is a simple HelloWorld example to show the basics of writing
Expand Down Expand Up @@ -78,20 +82,12 @@ def say_hello(name, times):
yield 'Hello, %s' % name

if __name__=='__main__':
try:
from wsgiref.simple_server import make_server
except ImportError:
print "Error: example server code requires Python >= 2.5"

logging.basicConfig(level=logging.DEBUG)
logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)

application = Application([HelloWorldService], 'rpclib.examples.hello.soap',
interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11())

server = make_server('127.0.0.1', 7789, WsgiApplication(application))

print "listening to http://127.0.0.1:7789"
print "wsdl is at: http://localhost:7789/?wsdl"
logging.info("listening to http://127.0.0.1:7789")
logging.info("wsdl is at: http://localhost:7789/?wsdl")

wsgi_app = wsgi_soap_application([HelloWorldService], 'rpclib.examples.hello.soap')
server = make_server('127.0.0.1', 7789, wsgi_app)
server.serve_forever()
1 change: 1 addition & 0 deletions examples/xml_utils.py
Expand Up @@ -47,6 +47,7 @@
from rpclib.util.xml import get_object_as_xml
from rpclib.util.xml import get_validation_schema


class Punk(ComplexModel):
__namespace__ = 'some_namespace'

Expand Down
36 changes: 36 additions & 0 deletions src/rpclib/util/simple.py
@@ -0,0 +1,36 @@

#
# rpclib - Copyright (C) Rpclib contributors.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#

"""Contains functions that implement the most common protocol and transport
combinations"""

from rpclib.application import Application
from rpclib.interface.wsdl import Wsdl11
from rpclib.protocol.soap import Soap11
from rpclib.server.wsgi import WsgiApplication

def wsgi_soap11_application(services, tns='rpclib.simple.soap', validator=None):
"""Wraps `services` argument inside a WsgiApplication that uses Wsdl 1.1 as
interface document and Soap 1.1 and both input and output protocols.
"""

application = Application(services, tns, interface=Wsdl11(),
in_protocol=Soap11(validator=validator), out_protocol=Soap11())

return WsgiApplication(application)

0 comments on commit c0d9cca

Please sign in to comment.