moved handlers
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
This folder contains example files.
|
||||
They much be copied to the web2py root folder in order to work properly.
|
||||
They should not be linked in the handlers folder.
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
This is a CGI handler for Apache
|
||||
Requires apache+[mod_cgi or mod_cgid].
|
||||
|
||||
In httpd.conf put something like:
|
||||
|
||||
LoadModule cgi_module modules/mod_cgi.so
|
||||
ScriptAlias / /path/to/cgihandler.py/
|
||||
|
||||
Example of httpd.conf ------------
|
||||
<VirtualHost *:80>
|
||||
ServerName web2py.example.com
|
||||
ScriptAlias / /users/www-data/web2py/cgihandler.py/
|
||||
|
||||
<Directory /users/www-data/web2py>
|
||||
AllowOverride None
|
||||
Order Allow,Deny
|
||||
Deny from all
|
||||
<Files cgihandler.py>
|
||||
Allow from all
|
||||
</Files>
|
||||
</Directory>
|
||||
|
||||
AliasMatch ^/([^/]+)/static/(.*) \
|
||||
/users/www-data/web2py/applications/$1/static/$2
|
||||
<Directory /users/www-data/web2py/applications/*/static/>
|
||||
Order Allow,Deny
|
||||
Allow from all
|
||||
</Directory>
|
||||
|
||||
<Location /admin>
|
||||
Deny from all
|
||||
</Location>
|
||||
|
||||
<LocationMatch ^/([^/]+)/appadmin>
|
||||
Deny from all
|
||||
</LocationMatch>
|
||||
|
||||
CustomLog /private/var/log/apache2/access.log common
|
||||
ErrorLog /private/var/log/apache2/error.log
|
||||
</VirtualHost>
|
||||
----------------------------------
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import wsgiref.handlers
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(path)
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
import gluon.main
|
||||
|
||||
wsgiref.handlers.CGIHandler().run(gluon.main.wsgibase)
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
This is a handler for lighttpd+fastcgi
|
||||
This file has to be in the PYTHONPATH
|
||||
Put something like this in the lighttpd.conf file:
|
||||
|
||||
server.port = 8000
|
||||
server.bind = '127.0.0.1'
|
||||
server.event-handler = 'freebsd-kqueue'
|
||||
server.modules = ('mod_rewrite', 'mod_fastcgi')
|
||||
server.error-handler-404 = '/test.fcgi'
|
||||
server.document-root = '/somewhere/web2py'
|
||||
server.errorlog = '/tmp/error.log'
|
||||
fastcgi.server = ('.fcgi' =>
|
||||
('localhost' =>
|
||||
('min-procs' => 1,
|
||||
'socket' => '/tmp/fcgi.sock'
|
||||
)
|
||||
)
|
||||
)
|
||||
"""
|
||||
|
||||
LOGGING = False
|
||||
SOFTCRON = False
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(path)
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
import gluon.main
|
||||
import gluon.contrib.gateways.fcgi as fcgi
|
||||
|
||||
if LOGGING:
|
||||
application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
|
||||
logfilename='httpserver.log',
|
||||
profiler_dir=None)
|
||||
else:
|
||||
application = gluon.main.wsgibase
|
||||
|
||||
if SOFTCRON:
|
||||
from gluon.settings import global_settings
|
||||
global_settings.web2py_crontype = 'soft'
|
||||
|
||||
fcgi.WSGIServer(application, bindAddress='/tmp/fcgi.sock').run()
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
"""
|
||||
|
||||
##############################################################################
|
||||
# Configuration parameters for Google App Engine
|
||||
##############################################################################
|
||||
LOG_STATS = False # web2py level log statistics
|
||||
APPSTATS = True # GAE level usage statistics and profiling
|
||||
DEBUG = False # debug mode
|
||||
#
|
||||
# Read more about APPSTATS here
|
||||
# http://googleappengine.blogspot.com/2010/03/easy-performance-profiling-with.html
|
||||
# can be accessed from:
|
||||
# http://localhost:8080/_ah/stats
|
||||
##############################################################################
|
||||
# All tricks in this file developed by Robin Bhattacharyya
|
||||
##############################################################################
|
||||
|
||||
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import cPickle
|
||||
import pickle
|
||||
import wsgiref.handlers
|
||||
import datetime
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
sys.modules['cPickle'] = sys.modules['pickle']
|
||||
|
||||
|
||||
from gluon.settings import global_settings
|
||||
from google.appengine.ext import webapp
|
||||
from google.appengine.ext.webapp.util import run_wsgi_app
|
||||
|
||||
|
||||
global_settings.web2py_runtime_gae = True
|
||||
global_settings.db_sessions = True
|
||||
if os.environ.get('SERVER_SOFTWARE', '').startswith('Devel'):
|
||||
(global_settings.web2py_runtime, DEBUG) = \
|
||||
('gae:development', True)
|
||||
else:
|
||||
(global_settings.web2py_runtime, DEBUG) = \
|
||||
('gae:production', False)
|
||||
|
||||
|
||||
import gluon.main
|
||||
|
||||
|
||||
def log_stats(fun):
|
||||
"""Function that will act as a decorator to make logging"""
|
||||
def newfun(env, res):
|
||||
"""Log the execution time of the passed function"""
|
||||
timer = lambda t: (t.time(), t.clock())
|
||||
(t0, c0) = timer(time)
|
||||
executed_function = fun(env, res)
|
||||
(t1, c1) = timer(time)
|
||||
log_info = """**** Request: %.2fms/%.2fms (real time/cpu time)"""
|
||||
log_info = log_info % ((t1 - t0) * 1000, (c1 - c0) * 1000)
|
||||
logging.info(log_info)
|
||||
return executed_function
|
||||
return newfun
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def wsgiapp(env, res):
|
||||
"""Return the wsgiapp"""
|
||||
env['PATH_INFO'] = env['PATH_INFO'].decode('latin1').encode('utf8')
|
||||
|
||||
#when using the blobstore image uploader GAE dev SDK passes these as unicode
|
||||
# they should be regular strings as they are parts of URLs
|
||||
env['wsgi.url_scheme'] = str(env['wsgi.url_scheme'])
|
||||
env['QUERY_STRING'] = str(env['QUERY_STRING'])
|
||||
env['SERVER_NAME'] = str(env['SERVER_NAME'])
|
||||
|
||||
#this deals with a problem where GAE development server seems to forget
|
||||
# the path between requests
|
||||
if global_settings.web2py_runtime == 'gae:development':
|
||||
gluon.admin.create_missing_folders()
|
||||
|
||||
web2py_path = global_settings.applications_parent # backward compatibility
|
||||
|
||||
return gluon.main.wsgibase(env, res)
|
||||
|
||||
|
||||
if LOG_STATS or DEBUG:
|
||||
wsgiapp = log_stats(wsgiapp)
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the wsgi app"""
|
||||
run_wsgi_app(wsgiapp)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
web2py handler for isapi-wsgi for IIS. Requires:
|
||||
http://code.google.com/p/isapi-wsgi/
|
||||
"""
|
||||
# The entry point for the ISAPI extension.
|
||||
|
||||
|
||||
def __ExtensionFactory__():
|
||||
import os
|
||||
import sys
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(path)
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
import gluon.main
|
||||
import isapi_wsgi
|
||||
application = gluon.main.wsgibase
|
||||
return isapi_wsgi.ISAPIThreadPoolHandler(application)
|
||||
|
||||
# ISAPI installation:
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
if len(sys.argv) < 2:
|
||||
print "USAGE: python isapiwsgihandler.py install --server=Sitename"
|
||||
sys.exit(0)
|
||||
from isapi.install import ISAPIParameters
|
||||
from isapi.install import ScriptMapParams
|
||||
from isapi.install import VirtualDirParameters
|
||||
from isapi.install import HandleCommandLine
|
||||
|
||||
params = ISAPIParameters()
|
||||
sm = [ScriptMapParams(Extension="*", Flags=0)]
|
||||
vd = VirtualDirParameters(Name="appname",
|
||||
Description="Web2py in Python",
|
||||
ScriptMaps=sm,
|
||||
ScriptMapUpdate="replace")
|
||||
params.VirtualDirs = [vd]
|
||||
HandleCommandLine(params)
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
WSGI wrapper for mod_python. Requires Python 2.2 or greater.
|
||||
Part of CherryPy mut modified by Massimo Di Pierro (2008) for web2py
|
||||
|
||||
<Location /myapp>
|
||||
SetHandler python-program
|
||||
PythonHandler modpythonhandler
|
||||
PythonPath \"['/path/to/web2py/'] + sys.path\"
|
||||
PythonOption SCRIPT_NAME /myapp
|
||||
</Location>
|
||||
|
||||
Some WSGI implementations assume that the SCRIPT_NAME environ variable will
|
||||
always be equal to 'the root URL of the app'; Apache probably won't act as
|
||||
you expect in that case. You can add another PythonOption directive to tell
|
||||
modpython_gateway to force that behavior:
|
||||
|
||||
PythonOption SCRIPT_NAME /mcontrol
|
||||
|
||||
The module.function will be called with no arguments on server shutdown,
|
||||
once for each child process or thread.
|
||||
"""
|
||||
|
||||
import traceback
|
||||
import sys
|
||||
import os
|
||||
from mod_python import apache
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(path)
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
import gluon.main
|
||||
|
||||
|
||||
class InputWrapper(object):
|
||||
""" Input wrapper for the wsgi handler """
|
||||
|
||||
def __init__(self, req):
|
||||
""" InputWrapper constructor """
|
||||
|
||||
self.req = req
|
||||
|
||||
def close(self):
|
||||
""" """
|
||||
|
||||
pass
|
||||
|
||||
def read(self, size=-1):
|
||||
""" Wrapper for req.read """
|
||||
|
||||
return self.req.read(size)
|
||||
|
||||
def readline(self, size=-1):
|
||||
""" Wrapper for req.readline """
|
||||
|
||||
return self.req.readline(size)
|
||||
|
||||
def readlines(self, hint=-1):
|
||||
""" Wrapper for req.readlines """
|
||||
|
||||
return self.req.readlines(hint)
|
||||
|
||||
def __iter__(self):
|
||||
""" Defines a generator with the req data """
|
||||
|
||||
line = self.readline()
|
||||
while line:
|
||||
yield line
|
||||
|
||||
# Notice this won't prefetch the next line; it only
|
||||
# gets called if the generator is resumed.
|
||||
line = self.readline()
|
||||
|
||||
|
||||
class ErrorWrapper(object):
|
||||
""" Error wrapper for the wsgi handler """
|
||||
|
||||
def __init__(self, req):
|
||||
""" ErrorWrapper constructor """
|
||||
|
||||
self.req = req
|
||||
|
||||
def flush(self):
|
||||
""" """
|
||||
|
||||
pass
|
||||
|
||||
def write(self, msg):
|
||||
""" Logs the given msg in the log file """
|
||||
|
||||
self.req.log_error(msg)
|
||||
|
||||
def writelines(self, seq):
|
||||
""" Writes various lines in the log file """
|
||||
|
||||
self.write(''.join(seq))
|
||||
|
||||
|
||||
bad_value = "You must provide a PythonOption '%s', either 'on' or 'off', when running a version of mod_python < 3.1"
|
||||
|
||||
|
||||
class Handler:
|
||||
""" Defines the handler """
|
||||
|
||||
def __init__(self, req):
|
||||
""" Handler constructor """
|
||||
|
||||
self.started = False
|
||||
options = req.get_options()
|
||||
|
||||
# Threading and forking
|
||||
try:
|
||||
q = apache.mpm_query
|
||||
threaded = q(apache.AP_MPMQ_IS_THREADED)
|
||||
forked = q(apache.AP_MPMQ_IS_FORKED)
|
||||
except AttributeError:
|
||||
threaded = options.get('multithread', '').lower()
|
||||
|
||||
if threaded == 'on':
|
||||
threaded = True
|
||||
elif threaded == 'off':
|
||||
threaded = False
|
||||
else:
|
||||
raise ValueError(bad_value % 'multithread')
|
||||
|
||||
forked = options.get('multiprocess', '').lower()
|
||||
|
||||
if forked == 'on':
|
||||
forked = True
|
||||
elif forked == 'off':
|
||||
forked = False
|
||||
else:
|
||||
raise ValueError(bad_value % 'multiprocess')
|
||||
|
||||
env = self.environ = dict(apache.build_cgi_env(req))
|
||||
|
||||
if 'SCRIPT_NAME' in options:
|
||||
# Override SCRIPT_NAME and PATH_INFO if requested.
|
||||
env['SCRIPT_NAME'] = options['SCRIPT_NAME']
|
||||
env['PATH_INFO'] = req.uri[len(options['SCRIPT_NAME']):]
|
||||
|
||||
env['wsgi.input'] = InputWrapper(req)
|
||||
env['wsgi.errors'] = ErrorWrapper(req)
|
||||
env['wsgi.version'] = (1, 0)
|
||||
env['wsgi.run_once'] = False
|
||||
|
||||
if env.get('HTTPS') in ('yes', 'on', '1'):
|
||||
env['wsgi.url_scheme'] = 'https'
|
||||
else:
|
||||
env['wsgi.url_scheme'] = 'http'
|
||||
|
||||
env['wsgi.multithread'] = threaded
|
||||
env['wsgi.multiprocess'] = forked
|
||||
|
||||
self.request = req
|
||||
|
||||
def run(self, application):
|
||||
""" Run the application """
|
||||
|
||||
try:
|
||||
result = application(self.environ, self.start_response)
|
||||
|
||||
for data in result:
|
||||
self.write(data)
|
||||
|
||||
if not self.started:
|
||||
self.request.set_content_length(0)
|
||||
|
||||
if hasattr(result, 'close'):
|
||||
result.close()
|
||||
except:
|
||||
traceback.print_exc(None, self.environ['wsgi.errors'])
|
||||
|
||||
if not self.started:
|
||||
self.request.status = 500
|
||||
self.request.content_type = 'text/plain'
|
||||
data = 'A server error occurred. Please contact the ' + \
|
||||
'administrator.'
|
||||
self.request.set_content_length(len(data))
|
||||
self.request.write(data)
|
||||
|
||||
def start_response(self, status, headers, exc_info=None):
|
||||
""" Defines the request data """
|
||||
|
||||
if exc_info:
|
||||
try:
|
||||
if self.started:
|
||||
raise exc_info[0], exc_info[1], exc_info[2]
|
||||
finally:
|
||||
exc_info = None
|
||||
|
||||
self.request.status = int(status[:3])
|
||||
|
||||
for (key, val) in headers:
|
||||
if key.lower() == 'content-length':
|
||||
self.request.set_content_length(int(val))
|
||||
elif key.lower() == 'content-type':
|
||||
self.request.content_type = val
|
||||
else:
|
||||
self.request.headers_out.add(key, val)
|
||||
|
||||
return self.write
|
||||
|
||||
def write(self, data):
|
||||
""" Write the request data """
|
||||
|
||||
if not self.started:
|
||||
self.started = True
|
||||
|
||||
self.request.write(data)
|
||||
|
||||
|
||||
def handler(req):
|
||||
""" Execute the gluon app """
|
||||
|
||||
Handler(req).run(gluon.main.wsgibase)
|
||||
return apache.OK
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
scgihandler.py - handler for SCGI protocol
|
||||
|
||||
Modified by Michele Comitini <michele.comitini@glisco.it>
|
||||
from fcgihandler.py to support SCGI
|
||||
|
||||
fcgihandler has the following copyright:
|
||||
" This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
"
|
||||
|
||||
This is a handler for lighttpd+scgi
|
||||
This file has to be in the PYTHONPATH
|
||||
Put something like this in the lighttpd.conf file:
|
||||
|
||||
server.document-root="/var/www/web2py/"
|
||||
# for >= linux-2.6
|
||||
server.event-handler = "linux-sysepoll"
|
||||
|
||||
url.rewrite-once = (
|
||||
"^(/.+?/static/.+)$" => "/applications$1",
|
||||
"(^|/.*)$" => "/handler_web2py.scgi$1",
|
||||
)
|
||||
scgi.server = ( "/handler_web2py.scgi" =>
|
||||
("handler_web2py" =>
|
||||
( "host" => "127.0.0.1",
|
||||
"port" => "4000",
|
||||
"check-local" => "disable", # don't forget to set "disable"!
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
LOGGING = False
|
||||
SOFTCRON = False
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(path)
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
import gluon.main
|
||||
|
||||
# uncomment one of the two imports below depending on the SCGIWSGI server installed
|
||||
#import paste.util.scgiserver as scgi
|
||||
from wsgitools.scgi.forkpool import SCGIServer
|
||||
from wsgitools.filters import WSGIFilterMiddleware, GzipWSGIFilter
|
||||
|
||||
wsgiapp = WSGIFilterMiddleware(gluon.main.wsgibase, GzipWSGIFilter)
|
||||
|
||||
if LOGGING:
|
||||
application = gluon.main.appfactory(wsgiapp=wsgiapp,
|
||||
logfilename='httpserver.log',
|
||||
profiler_dir=None)
|
||||
else:
|
||||
application = wsgiapp
|
||||
|
||||
if SOFTCRON:
|
||||
from gluon.settings import global_settings
|
||||
global_settings.web2py_crontype = 'soft'
|
||||
|
||||
# uncomment one of the two rows below depending on the SCGIWSGI server installed
|
||||
#scgi.serve_application(application, '', 4000).run()
|
||||
SCGIServer(application, port=4000).enable_sighandler().run()
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
This file is part of the web2py Web Framework
|
||||
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
|
||||
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
|
||||
This is a WSGI handler for Apache
|
||||
Requires apache+mod_wsgi.
|
||||
|
||||
In httpd.conf put something like:
|
||||
|
||||
LoadModule wsgi_module modules/mod_wsgi.so
|
||||
WSGIScriptAlias / /path/to/wsgihandler.py
|
||||
|
||||
"""
|
||||
|
||||
# change these parameters as required
|
||||
LOGGING = False
|
||||
SOFTCRON = False
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(path)
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
sys.stdout = sys.stderr
|
||||
|
||||
import gluon.main
|
||||
|
||||
if LOGGING:
|
||||
application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
|
||||
logfilename='httpserver.log',
|
||||
profiler_dir=None)
|
||||
else:
|
||||
application = gluon.main.wsgibase
|
||||
|
||||
if SOFTCRON:
|
||||
from gluon.settings import global_settings
|
||||
global_settings.web2py_crontype = 'soft'
|
||||
Reference in New Issue
Block a user