#!/usr/bin/env python

import cherrypy
import json
import wsgiref.handlers
from datetime import datetime
#from pymongo import MongoClient
#from gridfs import GridFS

#mongo = MongoClient('mongodb://server:$Hnergle1@ds045077.mongolab.com:45077/').Shnergle

def error(status, message, traceback, version):
    cherrypy.response.headers['Content-Type'] = 'application/json'
    return json.dumps({'status': status, 'message': message})

def jsonp(self, object, **kwargs):
    def decorator():
        cherrypy.response.headers['Expires'] = datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
        cherrypy.response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
        jsonres = json.dumps(object)
        if 'callback' in kwargs:
            cherrypy.response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
            jsonres = kwargs['callback'] + '(' + jsonres + ');'
        else:
            cherrypy.response.headers['Content-Type'] = 'application/json'
        return jsonres
    return decorator
        
class Common:
    pass

class User(Common):
    @cherrypy.expose
    @jsonp
    def add(self, **kwargs):
        res = {}
        res['Function'] = 'Test'
        return self.jsonp(res, **kwargs)

class ShnergleServer(Common):
    users = User()

    @cherrypy.expose
    @jsonp
    def index(self, **kwargs):
        res = {}
        res['Function'] = 'Overview'
        return self.jsonp(res, **kwargs)

if __name__ == '__main__':
    config = {'global': {'server.socket_host': '0.0.0.0',
                         'server.socket_port': 80,
                        },
              '/':      {'error_page.default': error}
             }
    app = cherrypy.tree.mount(ShnergleServer(), "/", config)
    wsgiref.handlers.CGIHandler().run(app)

@@ -441,30 +441,12 @@
 onp(
-self, object, **kwargs
+func
 ):%0A 
@@ -686,16 +686,41 @@
 heck=0'%0A
+        funcres = func()%0A
         
@@ -744,14 +744,22 @@
 mps(
-object
+funcres%5B'res'%5D
 )%0A  
@@ -781,22 +781,33 @@
 ack' in 
+funcres%5B'
 kwargs
+'%5D
 :%0A      
@@ -911,22 +911,33 @@
 onres = 
+funcres%5B'
 kwargs
+'%5D
 %5B'callba
@@ -1272,39 +1272,46 @@
      return 
-self.jsonp(res,
+%7B'res': res, 'kwargs':
  **kwargs)%0A%0A
@@ -1307,17 +1307,17 @@
 **kwargs
-)
+%7D
 %0A%0Aclass 
@@ -1496,23 +1496,30 @@
 urn 
-self.jsonp(res,
+%7B'res': res, 'kwargs':
  **k
@@ -1523,17 +1523,17 @@
 **kwargs
-)
+%7D
 %0A%0Aif __n

Use decorators correctly