changeset 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 1b9545d5158a
children 6a7fd9f83554
files example/example.py
diffstat 1 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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 = '<a href="/%s">%s</a>'
     body = '<br/>'.join([link % (i,i) for i in range(30)])
     body = '<html><body><a href="/map">map</a><br/>%s</body></html>' % 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()