/usr/share/pyshared/grokcore/component/tests/subscriptions/ordered_subscriptions.py is in python-grokcore.component 2.5-0ubuntu1.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """
>>> grok.testing.grok(__name__)
>>> cave = Cave()
You can query the subscriptions and sort them with the information
provided by grok.order:
>>> ordered_subscriptions = grok.queryOrderedSubscriptions(cave, ICleaner)
>>> ordered_subscriptions
[<grokcore.component.tests.subscriptions.ordered_subscriptions.MondayCleaner object at ...>,
<grokcore.component.tests.subscriptions.ordered_subscriptions.WednesdayCleaner object at ...>,
<grokcore.component.tests.subscriptions.ordered_subscriptions.SaturdayCleaner object at ...>]
>>> _ = map(lambda s: s.work(), ordered_subscriptions)
Monday cleaning!
Wednesday cleaning!
Saturday cleaning!
If you use the regular query method, they won't be sorted:
>>> subscriptions = grok.querySubscriptions(cave, ICleaner)
>>> subscriptions
[<grokcore.component.tests.subscriptions.ordered_subscriptions.MondayCleaner object at ...>,
<grokcore.component.tests.subscriptions.ordered_subscriptions.SaturdayCleaner object at ...>,
<grokcore.component.tests.subscriptions.ordered_subscriptions.WednesdayCleaner object at ...>]
>>> _ = map(lambda s: s.work(), subscriptions)
Monday cleaning!
Saturday cleaning!
Wednesday cleaning!
"""
import grokcore.component as grok
from zope import interface
class Cave(grok.Context):
pass
class ICleaner(interface.Interface):
def work():
"""Clean that cave.
"""
class MondayCleaner(grok.Subscription):
grok.implements(ICleaner)
grok.order(1)
def work(self):
print 'Monday cleaning!'
class WednesdayCleaner(grok.Subscription):
grok.implements(ICleaner)
grok.order(3)
def work(self):
print 'Wednesday cleaning!'
class SaturdayCleaner(grok.Subscription):
grok.implements(ICleaner)
grok.order(6)
def work(self):
print 'Saturday cleaning!'
|