MCPcopy Index your code
hub / github.com/webpy/webpy / unloadhook

Function unloadhook

web/application.py:683–723  ·  view source on GitHub ↗

Converts an unload hook into an application processor. >>> app = auto_application() >>> def f(): "something done after handling request" ... >>> app.add_processor(unloadhook(f))

(h)

Source from the content-addressed store, hash-verified

681
682
683def unloadhook(h):
684 """
685 Converts an unload hook into an application processor.
686
687 >>> app = auto_application()
688 >>> def f(): "something done after handling request"
689 ...
690 >>> app.add_processor(unloadhook(f))
691 """
692
693 def processor(handler):
694 try:
695 result = handler()
696 except:
697 # run the hook even when handler raises some exception
698 h()
699 raise
700
701 if result and hasattr(result, "__next__"):
702 return wrap(result)
703 else:
704 h()
705 return result
706
707 def wrap(result):
708 def next_hook():
709 try:
710 return next(result)
711 except:
712 # call the hook at the and of iterator
713 h()
714 raise
715
716 result = iter(result)
717 while True:
718 try:
719 yield next_hook()
720 except StopIteration:
721 return
722
723 return processor
724
725
726def autodelegate(prefix=""):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected