Source

pyrest / pyrest / integration / cherry.py

import cherrypy
from pyrest.pyrest import get_handlers, requesthandler

API = None #This should be set to a PyRest backend API if used as WSGI application

class PyRest(object):
    def __init__(self, api):
        self._handlers = get_handlers(api)
        
    def index(self):
        return "Awesome API..."

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



if __name__ == '__main__':
    from pyrest.examples import hg
    CONF = {
    'global': {
        'server.socket_host': '0.0.0.0',
        'server.socket_port': 8888,
    }}

    ROOT = PyRest(hg)

    cherrypy.quickstart(ROOT, '/', CONF)
    
#Not actually working right now
def application(environ, start_response):
  cherrypy.tree.mount(PyRest(), '/', None)
  return cherrypy.tree(environ, start_response)