source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/handlers/gaehandler.py @ 42095c5

mainqndtest v1.1.1
Last change on this file since 42095c5 was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 3.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5This file is part of the web2py Web Framework
6Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
7License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
8"""
9
10##############################################################################
11# Configuration parameters for Google App Engine
12##############################################################################
13LOG_STATS = False      # web2py level log statistics
14APPSTATS = True         # GAE level usage statistics and profiling
15DEBUG = False          # debug mode
16#
17# Read more about APPSTATS here
18#   http://googleappengine.blogspot.com/2010/03/easy-performance-profiling-with.html
19# can be accessed from:
20#   http://localhost:8080/_ah/stats
21##############################################################################
22# All tricks in this file developed by Robin Bhattacharyya
23##############################################################################
24
25
26import time
27import os
28import sys
29import logging
30import cPickle
31import pickle
32import wsgiref.handlers
33import datetime
34
35path = os.path.dirname(os.path.abspath(__file__))
36
37# os.chdir(path) ?
38
39if not os.path.isdir('applications'):
40    raise RuntimeError('Running from the wrong folder')
41
42sys.path = [path] + [p for p in sys.path if not p == path]
43
44sys.modules['cPickle'] = sys.modules['pickle']
45
46
47from gluon.settings import global_settings
48from google.appengine.ext import webapp
49from google.appengine.ext.webapp.util import run_wsgi_app
50
51
52global_settings.web2py_runtime_gae = True
53global_settings.db_sessions = True
54if os.environ.get('SERVER_SOFTWARE', '').startswith('Devel'):
55    (global_settings.web2py_runtime, DEBUG) = \
56        ('gae:development', True)
57else:
58    (global_settings.web2py_runtime, DEBUG) = \
59        ('gae:production', False)
60
61
62import gluon.main
63
64
65def log_stats(fun):
66    """Function that will act as a decorator to make logging"""
67    def newfun(env, res):
68        """Log the execution time of the passed function"""
69        timer = lambda t: (t.time(), t.clock())
70        (t0, c0) = timer(time)
71        executed_function = fun(env, res)
72        (t1, c1) = timer(time)
73        log_info = """**** Request: %.2fms/%.2fms (real time/cpu time)"""
74        log_info = log_info % ((t1 - t0) * 1000, (c1 - c0) * 1000)
75        logging.info(log_info)
76        return executed_function
77    return newfun
78
79
80logging.basicConfig(level=logging.INFO)
81
82
83def wsgiapp(env, res):
84    """Return the wsgiapp"""
85    env['PATH_INFO'] = env['PATH_INFO'].decode('latin1').encode('utf8')
86
87    #when using the blobstore image uploader GAE dev SDK passes these as unicode
88    # they should be regular strings as they are parts of URLs
89    env['wsgi.url_scheme'] = str(env['wsgi.url_scheme'])
90    env['QUERY_STRING'] = str(env['QUERY_STRING'])
91    env['SERVER_NAME'] = str(env['SERVER_NAME'])
92
93    #this deals with a problem where GAE development server seems to forget
94    # the path between requests
95    if global_settings.web2py_runtime == 'gae:development':
96        gluon.admin.create_missing_folders()
97
98    web2py_path = global_settings.applications_parent  # backward compatibility
99
100    return gluon.main.wsgibase(env, res)
101
102
103if LOG_STATS or DEBUG:
104    wsgiapp = log_stats(wsgiapp)
105
106
107def main():
108    """Run the wsgi app"""
109    run_wsgi_app(wsgiapp)
110
111if __name__ == '__main__':
112    main()
Note: See TracBrowser for help on using the repository browser.