# HG changeset patch # User Jeff Hammel # Date 1355189444 28800 # Node ID 421d5119e324b7ca57aa95b3dad78a31be96b587 # Parent 7b8e40eda563c916f7d278511275a7cb8cb1c973 reluctantly make this a CLI entry point diff -r 7b8e40eda563 -r 421d5119e324 setup.py --- a/setup.py Mon Dec 10 17:16:21 2012 -0800 +++ b/setup.py Mon Dec 10 17:30:44 2012 -0800 @@ -13,6 +13,7 @@ from setuptools import setup kw['entry_points'] = """ [console_scripts] + wsgraph = wsgraph.web:main """ kw['install_requires'] = dependencies except ImportError: diff -r 7b8e40eda563 -r 421d5119e324 wsgraph/web.py --- a/wsgraph/web.py Mon Dec 10 17:16:21 2012 -0800 +++ b/wsgraph/web.py Mon Dec 10 17:30:44 2012 -0800 @@ -5,6 +5,7 @@ """ import json +import sys from webob import Request, Response, exc # rank constants @@ -106,11 +107,15 @@ # get resource requestor segments = self.path_segments(request.path_info) - if len(segments) not in (0,1,2): + rank = len(segments) + if rank not in (0,1,2): return exc.HTTPNotFound() # is resource in the graph? [TODO] + if (rank == EDGE) or (rank == NODE): + if tuple(segments) not in self.graph: + retun exc.HTTPNotFound() # formatter formatter = self.formatters[len(segments)] @@ -135,9 +140,9 @@ def OPTIONS(self, request): return Response() # TODO: Allow=', '.join(self.methods); Content-Length=0 -if __name__ == '__main__': - ### example web server +def main(args=sys.argv[1:]): + """example web server""" # imports from wsgiref import simple_server @@ -159,3 +164,5 @@ print 'http://localhost:%s/' % options.port server.serve_forever() +if __name__ == '__main__': + main()