#!/usr/bin/python

#################
# Configuration #
#################

port = 8081
ip = '127.0.0.1'

#########################
# Proposed AMF services #
#########################

def echo(data):
    return data

def fortytwo(data):
    sentence = """
	What do you get if you multiply six by nine?
	Six by nine. Forty two.
	That's it. That's all there is.
	I always thought something was fundamentally wrong with the universe."""
    return sentence

services = { 'echo': echo, '42': fortytwo }

#############
# Main code #
#############

if __name__ == '__main__':

    from pyamf.remoting.gateway.wsgi import WSGIGateway
    from wsgiref import simple_server
    from pyamf import _version

    gw = WSGIGateway(services)
    httpd = simple_server.WSGIServer((ip, port), simple_server.WSGIRequestHandler)

    def app(environ, start_response):
        return gw(environ, start_response)

    httpd.set_app(app)

    print '[+] AMF gateway starting on %s:%d' % (ip, port)
    print '[+] PyAMF version: v%s' % str(_version.version)

    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print
	print '[+] Bye!'
        pass

