summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
dfa7ab2)
This is a style convention that makes it easier to see where one
definition ends and the next begins. It's particularly necessary
in this file, because it can separate the CherryPy glue associated
with one function from the unrelated function below it.
svn path=/package_branches/invirt-web/cherrypy-rebased/; revision=2723
from invirt.config import structs as config
from webcommon import State
from invirt.config import structs as config
from webcommon import State
class MakoHandler(cherrypy.dispatch.LateParamPageHandler):
"""Callable which processes a dictionary, returning the rendered body."""
class MakoHandler(cherrypy.dispatch.LateParamPageHandler):
"""Callable which processes a dictionary, returning the rendered body."""
cherrypy.tools.mako = cherrypy.Tool('on_start_resource', MakoLoader())
cherrypy.tools.mako = cherrypy.Tool('on_start_resource', MakoLoader())
def revertStandardError():
"""Move stderr to stdout, and return the contents of the old stderr."""
errio = sys.stderr
def revertStandardError():
"""Move stderr to stdout, and return the contents of the old stderr."""
errio = sys.stderr
errio.seek(0)
return errio.read()
errio.seek(0)
return errio.read()
def catchStderr():
old_handler = cherrypy.request.handler
def wrapper(*args, **kwargs):
def catchStderr():
old_handler = cherrypy.request.handler
def wrapper(*args, **kwargs):
cherrypy.tools.catch_stderr = cherrypy.Tool('before_handler', catchStderr)
cherrypy.tools.catch_stderr = cherrypy.Tool('before_handler', catchStderr)
class JSONEncoder(simplejson.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
class JSONEncoder(simplejson.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
else:
return simplejson.JSONEncoder.default(self, obj)
else:
return simplejson.JSONEncoder.default(self, obj)
def jsonify_tool_callback(*args, **kwargs):
if not cherrypy.request.cached:
response = cherrypy.response
def jsonify_tool_callback(*args, **kwargs):
if not cherrypy.request.cached:
response = cherrypy.response
cherrypy.tools.jsonify = cherrypy.Tool('before_finalize', jsonify_tool_callback, priority=30)
cherrypy.tools.jsonify = cherrypy.Tool('before_finalize', jsonify_tool_callback, priority=30)
def require_login():
"""If the user isn't logged in, raise 403 with an error."""
if cherrypy.request.login is False:
def require_login():
"""If the user isn't logged in, raise 403 with an error."""
if cherrypy.request.login is False:
cherrypy.tools.require_login = cherrypy.Tool('on_start_resource', require_login, priority=150)
cherrypy.tools.require_login = cherrypy.Tool('on_start_resource', require_login, priority=150)
def require_POST():
"""If the request isn't a POST request, raise 405 Method Not Allowed"""
if cherrypy.request.method != "POST":
def require_POST():
"""If the request isn't a POST request, raise 405 Method Not Allowed"""
if cherrypy.request.method != "POST":
cherrypy.tools.require_POST = cherrypy.Tool('on_start_resource', require_POST, priority=150)
cherrypy.tools.require_POST = cherrypy.Tool('on_start_resource', require_POST, priority=150)
def remote_user_login():
"""Get remote user from SSL or GSSAPI, and store in request object.
def remote_user_login():
"""Get remote user from SSL or GSSAPI, and store in request object.
cherrypy.tools.remote_user_login = cherrypy.Tool('on_start_resource', remote_user_login, priority=50)
cherrypy.tools.remote_user_login = cherrypy.Tool('on_start_resource', remote_user_login, priority=50)
def invirtwebstate_init():
"""Initialize the cherrypy.request.state object from Invirt"""
if not hasattr(cherrypy.request, "state"):
def invirtwebstate_init():
"""Initialize the cherrypy.request.state object from Invirt"""
if not hasattr(cherrypy.request, "state"):
cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)
cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)
class View(object):
_cp_config = {'tools.mako.directories': [os.path.join(os.path.dirname(__file__),'templates')]}
class View(object):
_cp_config = {'tools.mako.directories': [os.path.join(os.path.dirname(__file__),'templates')]}