| | |
| | | |
| | | from pyramid.interfaces import ITweens |
| | | |
| | | from pyramid.compat import ( |
| | | string_types, |
| | | is_nonstr_iter, |
| | | ) |
| | | from pyramid.compat import string_types, is_nonstr_iter |
| | | |
| | | from pyramid.exceptions import ConfigurationError |
| | | |
| | | from pyramid.tweens import ( |
| | | MAIN, |
| | | INGRESS, |
| | | EXCVIEW, |
| | | ) |
| | | from pyramid.tweens import MAIN, INGRESS, EXCVIEW |
| | | |
| | | from pyramid.util import ( |
| | | is_string_or_iterable, |
| | | TopologicalSorter, |
| | | ) |
| | | from pyramid.util import is_string_or_iterable, TopologicalSorter |
| | | |
| | | from pyramid.config.util import action_method |
| | | |
| | | |
| | | class TweensConfiguratorMixin(object): |
| | | def add_tween(self, tween_factory, under=None, over=None): |
| | |
| | | - An iterable of any combination of the above. This allows the user |
| | | to specify fallbacks if the desired tween is not included, as well |
| | | as compatibility with multiple other tweens. |
| | | |
| | | |
| | | ``under`` means 'closer to the main Pyramid application than', |
| | | ``over`` means 'closer to the request ingress than'. |
| | | |
| | |
| | | For more information, see :ref:`registering_tweens`. |
| | | |
| | | """ |
| | | return self._add_tween(tween_factory, under=under, over=over, |
| | | explicit=False) |
| | | return self._add_tween( |
| | | tween_factory, under=under, over=over, explicit=False |
| | | ) |
| | | |
| | | def add_default_tweens(self): |
| | | self.add_tween(EXCVIEW) |
| | |
| | | if not isinstance(tween_factory, string_types): |
| | | raise ConfigurationError( |
| | | 'The "tween_factory" argument to add_tween must be a ' |
| | | 'dotted name to a globally importable object, not %r' % |
| | | tween_factory) |
| | | 'dotted name to a globally importable object, not %r' |
| | | % tween_factory |
| | | ) |
| | | |
| | | name = tween_factory |
| | | |
| | |
| | | if p is not None: |
| | | if not is_string_or_iterable(p): |
| | | raise ConfigurationError( |
| | | '"%s" must be a string or iterable, not %s' % (t, p)) |
| | | '"%s" must be a string or iterable, not %s' % (t, p) |
| | | ) |
| | | |
| | | if over is INGRESS or is_nonstr_iter(over) and INGRESS in over: |
| | | raise ConfigurationError('%s cannot be over INGRESS' % name) |
| | |
| | | if explicit: |
| | | tweens.add_explicit(name, tween_factory) |
| | | else: |
| | | tweens.add_implicit(name, tween_factory, under=under, over=over) |
| | | tweens.add_implicit( |
| | | name, tween_factory, under=under, over=over |
| | | ) |
| | | |
| | | discriminator = ('tween', name, explicit) |
| | | tween_type = explicit and 'explicit' or 'implicit' |
| | | |
| | | intr = self.introspectable('tweens', |
| | | discriminator, |
| | | name, |
| | | '%s tween' % tween_type) |
| | | intr = self.introspectable( |
| | | 'tweens', discriminator, name, '%s tween' % tween_type |
| | | ) |
| | | intr['name'] = name |
| | | intr['factory'] = tween_factory |
| | | intr['type'] = tween_type |
| | |
| | | introspectables.append(intr) |
| | | self.action(discriminator, register, introspectables=introspectables) |
| | | |
| | | |
| | | @implementer(ITweens) |
| | | class Tweens(object): |
| | | def __init__(self): |
| | |
| | | default_before=None, |
| | | default_after=INGRESS, |
| | | first=INGRESS, |
| | | last=MAIN) |
| | | last=MAIN, |
| | | ) |
| | | self.explicit = [] |
| | | |
| | | def add_explicit(self, name, factory): |