This file is indexed.

/usr/share/pyshared/pybridge/network/roster.py is in pybridge-common 0.3.0-7.2.

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
 99
100
# PyBridge -- online contract bridge made easy.
# Copyright (C) 2004-2007 PyBridge Project.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


from UserDict import IterableUserDict
from twisted.internet import reactor
from twisted.spread import pb
from zope.interface import implements

from pybridge.interfaces.observer import ISubject


class Roster(IterableUserDict):
    """A dictionary-like object, which combines a set of available items with
    information associated with each item.
    
    This class implements the ISubject interface to provide notifications
    when an entry in the roster is added, removed or changed.
    """

    implements(ISubject)


    def __init__(self):
        IterableUserDict.__init__(self)
        self.listeners = []


    def attach(self, listener):
        self.listeners.append(listener)


    def detach(self, listener):
        self.listeners.remove(listener)


    def notify(self, event, *args, **kwargs):
        for listener in self.listeners:
            listener.update(event, *args, **kwargs)




class LocalRoster(Roster, pb.Cacheable):
    """A server-side 'master copy' of a Roster.
    
    Changes to the LocalRoster are relayed to registered RemoteRoster objects
    as well as to all local listeners.
    """


    def __init__(self):
        Roster.__init__(self)
        self.observers = []


    def getStateToCacheAndObserveFor(self, perspective, observer):
        self.observers.append(observer)
        # Assumes that each item has an 'info' attribute.
        return dict([(id, item.info) for id, item in self.items()])


    def stoppedObserving(self, perspective, observer):
        self.observers.remove(observer)


    def notify(self, event, *args, **kwargs):
        # Override to provide event notification for remote observers.
        Roster.notify(self, event, *args, **kwargs)

        for observer in self.observers:
            # Event handlers are called on the next iteration of the reactor,
            # to allow the caller of this method to return a result.
            reactor.callLater(0, observer.callRemote, event, *args, **kwargs)




class RemoteRoster(Roster, pb.RemoteCache):
    """A client-side Roster, which mirrors a server-side LocalRoster object
    by tracking changes.
    """


    def setCopyableState(self, state):
        self.update(state)