File: __init__.py

package info (click to toggle)
python-pyramid 1.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,172 kB
  • sloc: python: 27,115; makefile: 7
file content (23 lines) | stat: -rw-r--r-- 847 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from webob import Response
from pyramid.httpexceptions import HTTPForbidden

def x_view(request): # pragma: no cover
     return Response('this is private!')

def forbidden_view(context, request):
     msg = context.message
     result = context.result
     message = msg + '\n' + str(result)
     resp = HTTPForbidden()
     resp.body = message
     return resp

def includeme(config):
     from pyramid.authentication import AuthTktAuthenticationPolicy
     from pyramid.authorization import ACLAuthorizationPolicy
     authn_policy = AuthTktAuthenticationPolicy('seekr1t')
     authz_policy = ACLAuthorizationPolicy()
     config._set_authentication_policy(authn_policy)
     config._set_authorization_policy(authz_policy)
     config.add_view(x_view, name='x', permission='private')
     config.add_view(forbidden_view, context=HTTPForbidden)