/usr/share/pyshared/pyramid/tweens.py is in python-pyramid 1.2.3+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import sys
from pyramid.interfaces import IExceptionViewClassifier
from pyramid.interfaces import IView
from zope.interface import providedBy
def excview_tween_factory(handler, registry):
""" A :term:`tween` factory which produces a tween that catches an
exception raised by downstream tweens (or the main Pyramid request
handler) and, if possible, converts it into a Response using an
:term:`exception view`."""
adapters = registry.adapters
def excview_tween(request):
attrs = request.__dict__
try:
response = handler(request)
except Exception, exc:
# WARNING: do not assign the result of sys.exc_info() to a
# local var here, doing so will cause a leak
attrs['exc_info'] = sys.exc_info()
attrs['exception'] = exc
# clear old generated request.response, if any; it may
# have been mutated by the view, and its state is not
# sane (e.g. caching headers)
if 'response' in attrs:
del attrs['response']
request_iface = attrs['request_iface']
provides = providedBy(exc)
for_ = (IExceptionViewClassifier, request_iface.combined, provides)
view_callable = adapters.lookup(for_, IView, default=None)
if view_callable is None:
raise
response = view_callable(exc, request)
finally:
# prevent leakage (wrt exc_info)
if 'exc_info' in attrs:
del attrs['exc_info']
if 'exception' in attrs:
del attrs['exception']
return response
return excview_tween
MAIN = 'MAIN'
INGRESS = 'INGRESS'
EXCVIEW = 'pyramid.tweens.excview_tween_factory'
|