Introduction
The following tutorial describes how to set up a bare bones Pylons project with a gateway exposing a method.
Since Pylons supports generic WSGI apps as controllers, setting up a remoting gateway is trivial using the WSGI gateway.
$ paster create -t pylons testproject
$ cd testproject $ paster controller gateway
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import logging from testproject.lib import helpers as h log = logging.getLogger(__name__) def echo(data): """ This is a function that we will expose. """ # print data to the console log.debug('Echo: %s', data) # echo data back to the client return data services = { 'myservice.echo': echo, # Add other exposed functions and classes here } GatewayController = h.WSGIGateway(services, logger=log, debug=True)You can easily expose more functions by adding them to the dictionary given to WSGIGateway. You can also create a totally different controller and expose it under another gateway URL.
# CUSTOM ROUTES HERE
Just below that line, add a mapping to the controller you created earlier. This maps URLs with the prefix ‘gateway’ to the AMF gateway.
map.connect('/gateway', controller='gateway')
from pyamf.remoting.gateway.wsgi import WSGIGateway
1 2 3 4 5 6 7 8 <?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all"/> <allow-access-from domain="*" secure="false"/> <allow-http-request-headers-from domain="*" headers="*" secure="false"/> </cross-domain-policy>
$ paster serve --reload development.ini
That should print something like:
Starting subprocess with file monitor Starting server in PID 4247. serving on 0.0.0.0:5000 view at http://127.0.0.1:5000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 import logging logging.basicConfig( level=logging.DEBUG, format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s' ) from pyamf.remoting.client import RemotingService client = RemotingService('http://127.0.0.1:5000/gateway') service = client.getService('myservice') echo = service.echo('Hello World!') logging.debug(echo)