Source

pyrest / pyrest.py

Full commit
import cherrypy, hgapi
from collections import namedtuple

Response = namedtuple('response', 'status content')

def requesthandler(method, *pathargs, **kwargs):
    """Main dispatch for calls to PyRest; no framework specific 
    code to be present after this point"""

    if not method == 'get':
        return Response('500 Server Error', 'Not implemented')

    repo = hgapi.Repo('.')
    return Response('200 Ok', repo.hg_id())
    

class PyRest(object):

    def index(self, *args, **kwargs):
        method = cherrypy.request.method.lower()
        response = requesthandler(method, *args, **kwargs)
        cherrypy.response.status = response.status
        return response.content
    index.exposed = True
    

CONF = {
    'global': {
        'server.socket_host': '0.0.0.0',
        'server.socket_port': 8888,
    }
}


if __name__ == '__main__':
    ROOT = PyRest()
    cherrypy.quickstart(ROOT, '/', CONF)
    
def application(environ, start_response):
  cherrypy.tree.mount(PyRest(), '/', None)
  return cherrypy.tree(environ, start_response)