本文整理汇总了Python中web.unloadhook函数的典型用法代码示例。如果您正苦于以下问题:Python unloadhook函数的具体用法?Python unloadhook怎么用?Python unloadhook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unloadhook函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_app
def init_app():
app = web.application(urls, globals())
#app.notfound = api_notfound
#app.internalerror = api_internalerror
app.add_processor(web.loadhook(api_loadhook))
app.add_processor(web.unloadhook(api_unloadhook))
return app
示例2: __init__
def __init__(self, mapping, fvars):
# Parent constructor
web.application.__init__(self, mapping, fvars) #@UndefinedVariable
# The views are bound once for all to the configuration
config.views = web.template.render("app/views/", globals={
"all_seasons": lambda: Season.all(),
"all_polls": lambda: Poll.all(),
"webparts": webparts,
"formatting": formatting,
"dates": dates,
"zip": zip,
"getattr": getattr,
"hasattr": hasattr,
"class_name": lambda x: x.__class__.__name__,
"namedtuple": collections.namedtuple,
"config": config,
"result_statuses": Result.STATUSES,
"Events": Events
})
# The ORM is bound once since it dynamically loads the engine from the configuration
config.orm = meta.init_orm(lambda : config.engine)
# Binds the hooking mechanism & the SQL Alchemy processor
self.add_processor(web.loadhook(http.init_hooks))
self.add_processor(web.unloadhook(http.execute_hooks))
self.add_processor(http.sqlalchemy_processor)
# Binds the webparts initialization mechanism
self.add_processor(web.loadhook(webparts.init_webparts))
示例3: testUnload
def testUnload(self):
x = web.storage(a=0)
urls = ("/foo", "foo", "/bar", "bar")
class foo:
def GET(self):
return "foo"
class bar:
def GET(self):
raise web.notfound()
app = web.application(urls, locals())
def unload():
x.a += 1
app.add_processor(web.unloadhook(unload))
app.request("/foo")
self.assertEquals(x.a, 1)
app.request("/bar")
self.assertEquals(x.a, 2)
示例4: setup
def setup():
import home, inlibrary, borrow_home, libraries, stats, support, events, status, merge_editions, authors
home.setup()
inlibrary.setup()
borrow_home.setup()
libraries.setup()
stats.setup()
support.setup()
events.setup()
status.setup()
merge_editions.setup()
authors.setup()
import api
api.setup()
from stats import stats_hook
delegate.app.add_processor(web.unloadhook(stats_hook))
if infogami.config.get("dev_instance") is True:
import dev_instance
dev_instance.setup()
setup_template_globals()
setup_logging()
logger = logging.getLogger("openlibrary")
logger.info("Application init")
示例5: setup
def setup():
import home, inlibrary, borrow_home, libraries, stats, support, \
events, status, merge_editions, authors
home.setup()
inlibrary.setup()
borrow_home.setup()
libraries.setup()
stats.setup()
support.setup()
events.setup()
status.setup()
merge_editions.setup()
authors.setup()
import api
from stats import stats_hook
delegate.app.add_processor(web.unloadhook(stats_hook))
if infogami.config.get("dev_instance") is True:
import dev_instance
dev_instance.setup()
setup_context_defaults()
setup_template_globals()
示例6: setup
def setup():
from openlibrary.plugins.openlibrary import (home, inlibrary, borrow_home, libraries,
stats, support, events, design, status,
merge_editions, authors)
home.setup()
design.setup()
inlibrary.setup()
borrow_home.setup()
libraries.setup()
stats.setup()
support.setup()
events.setup()
status.setup()
merge_editions.setup()
authors.setup()
from openlibrary.plugins.openlibrary import api
delegate.app.add_processor(web.unloadhook(stats.stats_hook))
if infogami.config.get("dev_instance") is True:
from openlibrary.plugins.openlibrary import dev_instance
dev_instance.setup()
setup_context_defaults()
setup_template_globals()
示例7: __new__
def __new__(cls, *args, **kwargs):
app = web.application(*args, **kwargs)
app.add_processor(web.loadhook(cls._connect))
app.add_processor(web.unloadhook(cls._disconnect))
return app
示例8: test_hook
def test_hook(self):
app.add_processor(web.loadhook(before))
app.add_processor(web.unloadhook(after))
self.assertEqual(app.request('/hello').data, 'yx')
global str
self.assertEqual(str, 'yxz')
示例9: set_webpy_hooks
def set_webpy_hooks(self, app, shutdown, rollback):
try:
import web
except ImportError:
return
if not hasattr(web, 'application'):
return
if not isinstance(app, web.application):
return
app.processors.append(0, web.unloadhook(shutdown))
示例10: setup
def setup():
import home, inlibrary, borrow_home, libraries
home.setup()
inlibrary.setup()
borrow_home.setup()
libraries.setup()
from stats import stats_hook
delegate.app.add_processor(web.unloadhook(stats_hook))
setup_template_globals()
示例11: set_webpy_hooks
def set_webpy_hooks(self, app, shutdown, rollback):
"""Setup the webpy-specific ``web.unloadhook`` to call
``db.session.remove()`` after each response.
"""
try:
import web
except ImportError:
return
if not hasattr(web, 'application'):
return
if not isinstance(app, web.application):
return
app.processors.append(0, web.unloadhook(shutdown))
示例12: createprocessor
def createprocessor():
createsession()
def pre_hook():
mylog.loginfo()
app.add_processor(web.loadhook(pre_hook))
def post_hook():
if web.ctx.fullpath[0:6] == "/rest/":
if web.ctx.fullpath[6:14] != "resource" \
and web.ctx.fullpath[6:11] != "photo":
web.header("content-type", "application/json")
else:
return
else:
web.header("content-type", "text/html; charset=utf-8")
app.add_processor(web.unloadhook(post_hook))
示例13: globals
"/([^/]*)/reindex", "reindex",
"/([^/]*)/new_key", "new_key",
"/([^/]*)/things", "things",
"/([^/]*)/versions", "versions",
"/([^/]*)/write", "write",
"/([^/]*)/account/(.*)", "account",
"/([^/]*)/permission", "permission",
"/([^/]*)/log/(\d\d\d\d-\d\d-\d\d:\d+)", 'readlog',
"/_invalidate", "invalidate"
)
app = web.application(urls, globals(), autoreload=False)
app.add_processor(web.loadhook(setup_remoteip))
app.add_processor(web.loadhook(cache.loadhook))
app.add_processor(web.unloadhook(cache.unloadhook))
def process_exception(e):
if isinstance(e, common.InfobaseException):
status = e.status
else:
status = "500 Internal Server Error"
msg = str(e)
raise web.HTTPError(status, {}, msg)
class JSON:
"""JSON marker. instances of this class not escaped by jsonify.
"""
def __init__(self, json):
self.json = json
示例14: rot
"""
#global session
#session = s
if __name__ == "__main__":
curdir = os.path.dirname(__file__)
curdir=""
web.config.debug = config.web_debug
#web.config.debug = False
app = rot(webctx.urls, globals())
init_session(app)
app.add_processor(web.loadhook(loadhook))
app.add_processor(web.unloadhook(unloadhook))
# web.myapp = app
# web.init_session = init_session
app.run(config.port, "0.0.0.0", Log)
else:
web.config.debug = config.web_debug
app = web.application(webctx.urls, globals())
init_session(app)
app.add_processor(web.loadhook(loadhook))
app.add_processor(web.unloadhook(unloadhook))
# web.myapp = app
示例15: service
"""
try:
webctx.session
except NameError:
web.debug("Resetting session ...")
webctx.session = None
"""
app = None
if __name__ == "__main__":
web.config.debug = False
app = service(urls, globals())
# session setup, make sure to call it only once if in debug mode
init_session(app)
app.add_processor(web.loadhook(hooks.load))
app.add_processor(web.unloadhook(hooks.unload))
#webctx.session["pid"] += 1
#print "starting ..."
#app.add_processor(web.loadhook(loadhook))
#app.add_processor(web.unloadhook(unloadhook))
#app.run(config.port, "0.0.0.0")
#webctx.session = get_session(app)
app.run(config.port, "0.0.0.0", Log)