comparison example/example.py @ 22:1b077cb84be5

make the example more of a real program
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 May 2015 20:52:25 -0700
parents aa4eab6dc994
children 6a7fd9f83554
comparison
equal deleted inserted replaced
21:1b9545d5158a 22:1b077cb84be5
1 #!/usr/bin/env python
2
3 """
4 site map example application
5 """
6
7 # imports
8 import argparse
1 import os 9 import os
10 import sys
2 from svgsitemap import * 11 from svgsitemap import *
3 from webob import Request, Response 12 from webob import Request, Response
13 from wsgiref import simple_server
4 14
5 def example(environ, start_response): 15 def example(environ, start_response):
16 """example WSGI app"""
17
6 link = '<a href="/%s">%s</a>' 18 link = '<a href="/%s">%s</a>'
7 body = '<br/>'.join([link % (i,i) for i in range(30)]) 19 body = '<br/>'.join([link % (i,i) for i in range(30)])
8 body = '<html><body><a href="/map">map</a><br/>%s</body></html>' % body 20 body = '<html><body><a href="/map">map</a><br/>%s</body></html>' % body
9 response = Response(content_type='text/html', body=body) 21 response = Response(content_type='text/html', body=body)
10 return response(environ, start_response) 22 return response(environ, start_response)
11 23
24
12 def factory(): 25 def factory():
26 """WSGI app factory"""
27
13 dirname = os.path.dirname(os.path.abspath(__file__)) 28 dirname = os.path.dirname(os.path.abspath(__file__))
14 inifile = os.path.join(dirname, 'example.gv.txt') 29 inifile = os.path.join(dirname, 'example.gv.txt')
15 svgfile = os.path.join(dirname, 'example.svg') 30 svgfile = os.path.join(dirname, 'example.svg')
16 app = MapserverMiddleware(example, svgfile) 31 app = MapserverMiddleware(example, svgfile)
17 app = SVGSiteMap(app, file=inifile, output=svgfile) 32 app = SVGSiteMap(app, file=inifile, output=svgfile)
18 return app 33 return app
19 34
35 def main(args=sys.argv[1:])
36
37 server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory())
38 server.serve_forever()
39
20 if __name__ == '__main__': 40 if __name__ == '__main__':
21 from wsgiref import simple_server 41 main()
22 server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory())
23 server.serve_forever()