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
|
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.
"""
Hello world example server.
@see: U{HelloWorld<http://pyamf.org/tutorials/general/helloworld/index.html>} wiki page.
@since: 0.1.0
"""
def echo(data):
"""
Just return data back to the client.
"""
return data
services = {
'echo': echo,
'echo.echo': echo
}
if __name__ == '__main__':
import os
from pyamf.remoting.gateway.wsgi import WSGIGateway
from wsgiref import simple_server
gw = WSGIGateway(services)
httpd = simple_server.WSGIServer(
('localhost', 8000),
simple_server.WSGIRequestHandler,
)
def app(environ, start_response):
if environ['PATH_INFO'] == '/crossdomain.xml':
fn = os.path.join(os.getcwd(), os.path.dirname(__file__),
'crossdomain.xml')
fp = open(fn, 'rt')
buffer = fp.readlines()
fp.close()
start_response('200 OK', [
('Content-Type', 'application/xml'),
('Content-Length', str(len(''.join(buffer))))
])
return buffer
return gw(environ, start_response)
httpd.set_app(app)
print "Running Hello World AMF gateway on http://localhost:8000"
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
|