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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.
"""
Local Shared Object example.
@see: U{http://pyamf.org/wiki/LocalSharedObjectHowto}
"""
import os
import logging
from pyamf.remoting.gateway.wsgi import WSGIGateway
import service
# get platform specific shared object folder
path = service.default_folder()
filetype = "*.sol"
services = {
'lso': service.SharedObjectService(path, filetype)
}
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
)
application = WSGIGateway(services, logger=logging)
if __name__ == '__main__':
from optparse import OptionParser
from wsgiref import simple_server
parser = OptionParser()
parser.add_option("-p", "--port", default=8000,
dest="port", help="port number [default: %default]")
parser.add_option("--host", default="localhost",
dest="host", help="host address [default: %default]")
(options, args) = parser.parse_args()
port = int(options.port)
httpd = simple_server.WSGIServer(
(options.host, port),
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 application(environ, start_response)
httpd.set_app(app)
print "Running AMF gateway on http://%s:%d" % (options.host, port)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
|