On Thu, Oct 10, 2013 at 12:35 PM, Arnon Marcus <a.m.mar...@gmail.com> wrote: > Thank you very much Richardo (!) > > I would really like to use your solution, and have access to the current > fully-processed request, response and session objects. > Unfortunately, though, we are using a very old version of web2py (1.89.5), > which does not have the "current" variable in "gluon.globals" (it was added > only in 1.96). > Can we somehow retro-fit our version to have that without upgrading (the > upgrade is still far away in our road-map)?
You can monkeypatching, see an example below (added green lines): #!/usr/bin/python # coding: utf-8 # To use a virtualenv: #VENV_PATH = '/home/envs/someenv' # #activate_this = VENV_PATH + '/bin/activate_this.py' #execfile(activate_this, dict(__file__=activate_this)) import gevent.monkey gevent.monkey.patch_all() import sys from gevent.pywsgi import WSGIServer # change these parameters as required LOGGING = False SOFTCRON = False import sys import os path = os.path.dirname(os.path.abspath(__file__)) os.chdir(path) if not os.path.isdir('applications'): raise RuntimeError('Running from the wrong folder') sys.path = [path] + [p for p in sys.path if not p == path] sys.stdout = sys.stderr *### XXX: Monkey patch* *import threading* *import gluon.globals* *gluon.globals.current = current = threading.local()* * * *import gluon.main* *original = gluon.main.serve_controller* * * *def serve(request, response, session):* * current.request = request* * current.response = response* * current.session = session* * print >>sys.stderr, 'call original'* * return original(request, response, session)* *gluon.main.serve_controller = serve* *### End Monkey patch* import gluon.main from logger_middleware import Logger if LOGGING: application = Logger(gluon.main.appfactory(wsgiapp=gluon.main.wsgibase, logfilename='httpserver.log', profiler_dir=None)) else: application = Logger(gluon.main.wsgibase) if SOFTCRON: from gluon.settings import global_settings global_settings.web2py_crontype = 'soft' if __name__ == '__main__': print 'Serving on 8088...' WSGIServer(('', 8088), application).serve_forever() -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.