| 1 | # Copyright (c) 2007-2009 The PyAMF Project. |
|---|
| 2 | # See LICENSE for details. |
|---|
| 3 | |
|---|
| 4 | """ |
|---|
| 5 | ByteArray test server. |
|---|
| 6 | """ |
|---|
| 7 | |
|---|
| 8 | from pyamf.amf3 import ByteArray |
|---|
| 9 | from pyamf import register_class |
|---|
| 10 | import os, os.path |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | class Example(object): |
|---|
| 14 | def __init__(self): |
|---|
| 15 | self.id = 1 |
|---|
| 16 | self.data = ByteArray() |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | def getExample(): |
|---|
| 20 | return Example() |
|---|
| 21 | |
|---|
| 22 | def echoExample(example): |
|---|
| 23 | return example |
|---|
| 24 | |
|---|
| 25 | register_class(Example, 'Example') |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | def app(environ, start_response): |
|---|
| 29 | if environ['PATH_INFO'] == '/crossdomain.xml': |
|---|
| 30 | fn = os.path.join(os.getcwd(), os.path.dirname(__file__), |
|---|
| 31 | 'crossdomain.xml') |
|---|
| 32 | |
|---|
| 33 | fp = open(fn, 'rt') |
|---|
| 34 | buffer = fp.readlines() |
|---|
| 35 | fp.close() |
|---|
| 36 | |
|---|
| 37 | start_response('200 OK', [ |
|---|
| 38 | ('Content-Type', 'application/xml'), |
|---|
| 39 | ('Content-Length', str(len(''.join(buffer)))) |
|---|
| 40 | ]) |
|---|
| 41 | |
|---|
| 42 | return buffer |
|---|
| 43 | |
|---|
| 44 | return gw(environ, start_response) |
|---|
| 45 | |
|---|
| 46 | services = { |
|---|
| 47 | 'get': getExample, |
|---|
| 48 | 'echo': echoExample |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if __name__ == '__main__': |
|---|
| 52 | from pyamf.remoting.gateway.wsgi import WSGIGateway |
|---|
| 53 | from wsgiref import simple_server |
|---|
| 54 | |
|---|
| 55 | gw = WSGIGateway(services) |
|---|
| 56 | |
|---|
| 57 | def app(environ, start_response): |
|---|
| 58 | if environ['PATH_INFO'] == '/crossdomain.xml': |
|---|
| 59 | fn = os.path.join(os.getcwd(), os.path.dirname(__file__), |
|---|
| 60 | 'crossdomain.xml') |
|---|
| 61 | |
|---|
| 62 | fp = open(fn, 'rt') |
|---|
| 63 | buffer = fp.readlines() |
|---|
| 64 | fp.close() |
|---|
| 65 | |
|---|
| 66 | start_response('200 OK', [ |
|---|
| 67 | ('Content-Type', 'application/xml'), |
|---|
| 68 | ('Content-Length', str(len(''.join(buffer)))) |
|---|
| 69 | ]) |
|---|
| 70 | |
|---|
| 71 | return buffer |
|---|
| 72 | |
|---|
| 73 | return gw(environ, start_response) |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | httpd = simple_server.WSGIServer( |
|---|
| 78 | ('localhost', 8000), |
|---|
| 79 | simple_server.WSGIRequestHandler, |
|---|
| 80 | ) |
|---|
| 81 | |
|---|
| 82 | httpd.set_app(app) |
|---|
| 83 | |
|---|
| 84 | print "Running ByteArray Test AMF gateway on http://localhost:8000" |
|---|
| 85 | |
|---|
| 86 | try: |
|---|
| 87 | httpd.serve_forever() |
|---|
| 88 | except KeyboardInterrupt: |
|---|
| 89 | pass |
|---|