File: server.py

package info (click to toggle)
pyamf 0.6.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,692 kB
  • sloc: python: 17,944; xml: 455; makefile: 116; sql: 38; java: 11; sh: 7
file content (51 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download
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
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.

"""
Authentication example server.

@since: 0.1
"""


from pyamf.remoting.gateway.wsgi import WSGIGateway


class CalcService:
    def sum(self, a, b):
         return a + b


def auth(username, password):
    if username == 'jane' and password == 'doe':
        return True

    return False


gateway = WSGIGateway({'calc': CalcService}, authenticator=auth)


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()

    host = options.host
    port = int(options.port)

    httpd = simple_server.WSGIServer((host, port), simple_server.WSGIRequestHandler)
    httpd.set_app(gateway)

    print "Running Authentication AMF gateway on http://%s:%d" % (host, port)

    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass