Created
September 26, 2011 17:11
-
-
Save plq/1242760 to your computer and use it in GitHub Desktop.
django wrapper for rpclib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is not yet included in main rpclib distribution because | |
# it does a lot of unnecessary copying. However, it's reportedly | |
# working fine, so if you're not caring that much about performance | |
# you can use this. | |
from rpclib.server.wsgi import WsgiApplication | |
from cStringIO import StringIO | |
from django.http import HttpResponse | |
class DjangoApplication(WsgiApplication): | |
def __call__(self, request): | |
django_response = HttpResponse() | |
def start_response(status, headers): | |
status, reason = status.split(' ', 1) | |
django_response.status_code = int(status) | |
for header, value in headers: | |
django_response[header] = value | |
environ = request.META.copy() | |
body = ''.join(['%s=%s' % v for v in request.POST.items()]) | |
environ['CONTENT_LENGTH'] = len(body) | |
environ['wsgi.input'] = StringIO(body) | |
environ['wsgi.multithread'] = False | |
response = WsgiApplication.__call__(self, environ, start_response) | |
django_response.content = "\n".join(response) | |
return django_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rpclib.server.django import DjangoApplication # not real import path. | |
from rpclib.model.primitive import String, Integer | |
from rpclib.model.complex import Iterable | |
from rpclib.service import ServiceBase | |
from rpclib.interface.wsdl import Wsdl11 | |
from rpclib.protocol.soap import Soap11 | |
from rpclib.application import Application | |
from rpclib.decorator import rpc | |
class HelloWorldService(ServiceBase): | |
@rpc(String, Integer, _returns=Iterable(String)) | |
def say_hello(ctx, name, times): | |
for i in xrange(times): | |
yield 'Hello, %s' % name | |
hello_world_service = DjangoApplication(Application([HelloWorldService], | |
'some.tns', | |
interface=Wsdl11(), | |
in_protocol=Soap11(), | |
out_protocol=Soap11() | |
)) |
also, this is part of the rpclib already. there's an example project here:
https://github.com/arskom/rpclib/tree/a3b14df62da696960eb3157b65f5032f295cddf3/examples/django
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
again, if you want to deploy to mod_wsgi, just avoid django and do
if this doesn't answer your question, ask it at soap@python.org, where other ml members can help you.