2015-08-02 20:59:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
flask.signals
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Implements signals based on blinker if available, otherwise
|
2016-11-09 19:24:33 +01:00
|
|
|
falls silently back to a noop.
|
2015-08-02 20:59:11 +02:00
|
|
|
|
2016-11-09 19:24:33 +01:00
|
|
|
:copyright: (c) 2015 by Armin Ronacher.
|
2015-08-02 20:59:11 +02:00
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
signals_available = False
|
|
|
|
try:
|
|
|
|
from blinker import Namespace
|
|
|
|
signals_available = True
|
|
|
|
except ImportError:
|
|
|
|
class Namespace(object):
|
|
|
|
def signal(self, name, doc=None):
|
|
|
|
return _FakeSignal(name, doc)
|
|
|
|
|
|
|
|
class _FakeSignal(object):
|
|
|
|
"""If blinker is unavailable, create a fake class with the same
|
|
|
|
interface that allows sending of signals but will fail with an
|
|
|
|
error on anything else. Instead of doing anything on send, it
|
|
|
|
will just ignore the arguments and do nothing instead.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, name, doc=None):
|
|
|
|
self.name = name
|
|
|
|
self.__doc__ = doc
|
|
|
|
def _fail(self, *args, **kwargs):
|
|
|
|
raise RuntimeError('signalling support is unavailable '
|
|
|
|
'because the blinker library is '
|
|
|
|
'not installed.')
|
|
|
|
send = lambda *a, **kw: None
|
|
|
|
connect = disconnect = has_receivers_for = receivers_for = \
|
|
|
|
temporarily_connected_to = connected_to = _fail
|
|
|
|
del _fail
|
|
|
|
|
2016-11-09 19:24:33 +01:00
|
|
|
# The namespace for code signals. If you are not flask code, do
|
2015-08-02 20:59:11 +02:00
|
|
|
# not put signals in here. Create your own namespace instead.
|
|
|
|
_signals = Namespace()
|
|
|
|
|
|
|
|
|
2016-11-09 19:24:33 +01:00
|
|
|
# Core signals. For usage examples grep the source code or consult
|
2015-08-02 20:59:11 +02:00
|
|
|
# the API documentation in docs/api.rst as well as docs/signals.rst
|
|
|
|
template_rendered = _signals.signal('template-rendered')
|
2016-11-09 19:24:33 +01:00
|
|
|
before_render_template = _signals.signal('before-render-template')
|
2015-08-02 20:59:11 +02:00
|
|
|
request_started = _signals.signal('request-started')
|
|
|
|
request_finished = _signals.signal('request-finished')
|
|
|
|
request_tearing_down = _signals.signal('request-tearing-down')
|
|
|
|
got_request_exception = _signals.signal('got-request-exception')
|
|
|
|
appcontext_tearing_down = _signals.signal('appcontext-tearing-down')
|
|
|
|
appcontext_pushed = _signals.signal('appcontext-pushed')
|
|
|
|
appcontext_popped = _signals.signal('appcontext-popped')
|
|
|
|
message_flashed = _signals.signal('message-flashed')
|