commit | author | age
|
9e5c8a
|
1 |
from pyramid.view import view_config |
CM |
2 |
from pyramid.events import subscriber |
|
3 |
|
0c29cf
|
4 |
|
9e5c8a
|
5 |
class Yup(object): |
CM |
6 |
def __init__(self, val, config): |
|
7 |
self.val = val |
|
8 |
|
|
9 |
def text(self): |
|
10 |
return 'path_startswith = %s' % (self.val,) |
|
11 |
|
|
12 |
phash = text |
|
13 |
|
|
14 |
def __call__(self, event): |
|
15 |
return getattr(event.response, 'yup', False) |
|
16 |
|
0c29cf
|
17 |
|
9e5c8a
|
18 |
class Foo(object): |
CM |
19 |
def __init__(self, response): |
|
20 |
self.response = response |
|
21 |
|
0c29cf
|
22 |
|
9e5c8a
|
23 |
class Bar(object): |
CM |
24 |
pass |
0c29cf
|
25 |
|
9e5c8a
|
26 |
|
CM |
27 |
@subscriber(Foo) |
|
28 |
def foo(event): |
|
29 |
event.response.text += 'foo ' |
|
30 |
|
0c29cf
|
31 |
|
9e5c8a
|
32 |
@subscriber(Foo, yup=True) |
CM |
33 |
def fooyup(event): |
|
34 |
event.response.text += 'fooyup ' |
0c29cf
|
35 |
|
MM |
36 |
|
9e5c8a
|
37 |
@subscriber([Foo, Bar]) |
CM |
38 |
def foobar(event): |
|
39 |
event.response.text += 'foobar ' |
0c29cf
|
40 |
|
9e5c8a
|
41 |
|
CM |
42 |
@subscriber([Foo, Bar]) |
|
43 |
def foobar2(event, context): |
|
44 |
event.response.text += 'foobar2 ' |
|
45 |
|
0c29cf
|
46 |
|
9e5c8a
|
47 |
@subscriber([Foo, Bar], yup=True) |
CM |
48 |
def foobaryup(event): |
|
49 |
event.response.text += 'foobaryup ' |
|
50 |
|
0c29cf
|
51 |
|
9e5c8a
|
52 |
@subscriber([Foo, Bar], yup=True) |
CM |
53 |
def foobaryup2(event, context): |
|
54 |
event.response.text += 'foobaryup2 ' |
0c29cf
|
55 |
|
9e5c8a
|
56 |
|
CM |
57 |
@view_config(name='sendfoo') |
|
58 |
def sendfoo(request): |
|
59 |
response = request.response |
|
60 |
response.yup = True |
|
61 |
request.registry.notify(Foo(response)) |
|
62 |
return response |
|
63 |
|
0c29cf
|
64 |
|
9e5c8a
|
65 |
@view_config(name='sendfoobar') |
CM |
66 |
def sendfoobar(request): |
|
67 |
response = request.response |
|
68 |
response.yup = True |
|
69 |
request.registry.notify(Foo(response), Bar()) |
|
70 |
return response |
|
71 |
|
0c29cf
|
72 |
|
9e5c8a
|
73 |
def includeme(config): |
CM |
74 |
config.add_subscriber_predicate('yup', Yup) |
dd3cc8
|
75 |
config.scan('tests.pkgs.eventonly') |