# HG changeset patch # User Jeff Hammel # Date 1431316345 25200 # Node ID 1b077cb84be5c146a66c1fb348840d05cd44733d # Parent 1b9545d5158aa3932e28c71f1ffcf6d34899966e make the example more of a real program diff -r 1b9545d5158a -r 1b077cb84be5 example/example.py --- a/example/example.py Sun Jan 02 21:17:23 2011 -0800 +++ b/example/example.py Sun May 10 20:52:25 2015 -0700 @@ -1,15 +1,30 @@ +#!/usr/bin/env python + +""" +site map example application +""" + +# imports +import argparse import os +import sys from svgsitemap import * from webob import Request, Response +from wsgiref import simple_server def example(environ, start_response): + """example WSGI app""" + link = '%s' body = '
'.join([link % (i,i) for i in range(30)]) body = 'map
%s' % body response = Response(content_type='text/html', body=body) return response(environ, start_response) + def factory(): + """WSGI app factory""" + dirname = os.path.dirname(os.path.abspath(__file__)) inifile = os.path.join(dirname, 'example.gv.txt') svgfile = os.path.join(dirname, 'example.svg') @@ -17,7 +32,10 @@ app = SVGSiteMap(app, file=inifile, output=svgfile) return app +def main(args=sys.argv[1:]) + + server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory()) + server.serve_forever() + if __name__ == '__main__': - from wsgiref import simple_server - server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory()) - server.serve_forever() + main()