This file is indexed.

/usr/share/pyshared/grokcore/component/tests/subscriptions/multisubscriptions.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
  >>> grok.testing.grok(__name__)

  >>> cave = Cave('Tilburg cave')
  >>> martijn = Mammoth('Martijn')

  You can query a subscriptions using multiple components. You will get
  all subscriptions registered for office and cave (since office is a
  base class of cave):

  >>> subscriptions = grok.queryMultiSubscriptions((cave, martijn), IActivity)
  >>> subscriptions
  [<grokcore.component.tests.subscriptions.multisubscriptions.Sleep object at ...>,
   <grokcore.component.tests.subscriptions.multisubscriptions.Food object at ...>,
   <grokcore.component.tests.subscriptions.multisubscriptions.WritingCode object at ...>]

  >>> _ = map(lambda s: s.do(), subscriptions)
  Martijn is sleeping at Tilburg cave.
  Martijn is feeding himself at Tilburg cave.
  Martijn is writing code at Tilburg cave!


  Now, Martijn goes to the office. You will only get subscriptions
  registered for office:

  >>> office = Office('Grok corp(r)(tm) headquarters')
  >>> office_subscriptions = grok.queryMultiSubscriptions(
  ...     (office, martijn), IActivity)
  >>> office_subscriptions
  [<grokcore.component.tests.subscriptions.multisubscriptions.Sleep object at ...>]

  >>> _ = map(lambda s: s.do(), office_subscriptions)
  Martijn is sleeping at Grok corp(r)(tm) headquarters.

"""

import grokcore.component as grok
from zope import interface


class Office(grok.Context):

    def __init__(self, name):
        self.name = name


# All caves are a kind of office.
class Cave(Office):
    pass


class Mammoth(grok.Context):

    def __init__(self, name):
        self.name = name


class IActivity(interface.Interface):

    def do():
        """Do something.
        """

class Sleep(grok.MultiSubscription):
    grok.implements(IActivity)
    grok.adapts(Office, Mammoth)

    def __init__(self, where, who):
        self.where = where
        self.who = who

    def do(self):
        print '%s is sleeping at %s.' % (self.who.name, self.where.name)


class DayTimeActivity(grok.MultiSubscription):
    grok.implements(IActivity)
    grok.adapts(Cave, Mammoth)
    grok.baseclass()

    def __init__(self, where, who):
        self.where = where
        self.who = who

    def do(self):
        print 'nothing'


class Food(DayTimeActivity):

    def do(self):
        print '%s is feeding himself at %s.' % (self.who.name, self.where.name)


class WritingCode(DayTimeActivity):

    def do(self):
        print '%s is writing code at %s!' % (self.who.name, self.where.name)