Exemplo n.º 1
0
class Room(InstanceTracker):
    """A room without a title or description."""

    def __init__(self, title, desc):
        self.title = title
        self.desc = desc
        self.contents = OrderedSet()
        InstanceTracker.__init__(self)

    def add(self, obj):
        """Add an object to the room. Does not modify the object to reflect
        this.
        """
        self.contents.add(obj)

    def remove(self, obj):
        """Remove an object from the room. Does not modify the object to 
        reflect this.
        """
        self.contents.remove(obj)

    def matchContent(self, attrs, count, test = (lambda x: True)):
        """Looks for an object matching the given criteria in the room.

        attrs is a set of attributes the object must have. count is the number
        of the object in the room. test is an optional function to check the
        object up against.

        This function may or may not be deprecated.
        """
        for obj in self.matchContentAll(attrs):
            if test(obj):
                if count == 0:
                    return obj
                else:
                    count -= 1
        raise UnfoundError()

    def matchContentAll(self, attrs):
        """Return an iterator that yields all the objects that match a certain
        set of attributes.
        """
        for obj in self:
            if hasattr(obj, 'match') and obj.match(attrs):
                yield obj

    def __contains__(self, obj):
        return obj in self.contents

    def __iter__(self):
        return iter(self.contents)
Exemplo n.º 2
0
class Room(InstanceTracker):
    """A room without a title or description."""
    def __init__(self, title, desc):
        self.title = title
        self.desc = desc
        self.contents = OrderedSet()
        InstanceTracker.__init__(self)

    def add(self, obj):
        """Add an object to the room. Does not modify the object to reflect
        this.
        """
        self.contents.add(obj)

    def remove(self, obj):
        """Remove an object from the room. Does not modify the object to 
        reflect this.
        """
        self.contents.remove(obj)

    def matchContent(self, attrs, count, test=(lambda x: True)):
        """Looks for an object matching the given criteria in the room.

        attrs is a set of attributes the object must have. count is the number
        of the object in the room. test is an optional function to check the
        object up against.

        This function may or may not be deprecated.
        """
        for obj in self.matchContentAll(attrs):
            if test(obj):
                if count == 0:
                    return obj
                else:
                    count -= 1
        raise UnfoundError()

    def matchContentAll(self, attrs):
        """Return an iterator that yields all the objects that match a certain
        set of attributes.
        """
        for obj in self:
            if hasattr(obj, 'match') and obj.match(attrs):
                yield obj

    def __contains__(self, obj):
        return obj in self.contents

    def __iter__(self):
        return iter(self.contents)
Exemplo n.º 3
0
 def __init__(self):
     self.signatures = OrderedSet()
     self.s2fs = {}
     self.next_method_stack = []
Exemplo n.º 4
0
 def __init__(self, title, desc):
     self.title = title
     self.desc = desc
     self.contents = OrderedSet()
     InstanceTracker.__init__(self)
Exemplo n.º 5
0
 def __init__(self, title, desc):
     self.title = title
     self.desc = desc
     self.contents = OrderedSet()
     InstanceTracker.__init__(self)