Example #1
0
    def links(self):
        """
        Generate a link to the location that this exit points at.

        @return: an iterator which yields a single L{Link}, annotated with a
            L{Vector} that indicates a distance of 1.0 (a temporary measure,
            since L{Exit}s don't have distances yet) and a direction of this
            exit's C{name}.
        """
        l = Link(self.exitIdea, self.toLocation.idea)
        l.annotate([Vector(self.distance, self.name),
                    # We annotate this link with ourselves because the 'Named'
                    # retriever will use the last link in the path to determine
                    # if an object has any aliases.  We want this direction
                    # name to be an alias for the room itself as well as the
                    # exit, so we want to annotate the link with an INameable.
                    # This also has an effect of annotating the link with an
                    # IExit, and possibly one day an IItem as well (if such a
                    # thing ever comes to exist), so perhaps we eventually want
                    # a wrapper which elides all references here except
                    # INameable since that's what we want.  proxyForInterface
                    # perhaps?  However, for the moment, the extra annotations
                    # do no harm, so we'll leave them there.
                    self])
        yield l
Example #2
0
    def links(self):
        """
        Generate a link to the location that this exit points at.

        @return: an iterator which yields a single L{Link}, annotated with a
            L{Vector} that indicates a distance of 1.0 (a temporary measure,
            since L{Exit}s don't have distances yet) and a direction of this
            exit's C{name}.
        """
        l = Link(self.exitIdea, self.toLocation.idea)
        l.annotate([Vector(self.distance, self.name),
                    # We annotate this link with ourselves because the 'Named'
                    # retriever will use the last link in the path to determine
                    # if an object has any aliases.  We want this direction
                    # name to be an alias for the room itself as well as the
                    # exit, so we want to annotate the link with an INameable.
                    # This also has an effect of annotating the link with an
                    # IExit, and possibly one day an IItem as well (if such a
                    # thing ever comes to exist), so perhaps we eventually want
                    # a wrapper which elides all references here except
                    # INameable since that's what we want.  proxyForInterface
                    # perhaps?  However, for the moment, the extra annotations
                    # do no harm, so we'll leave them there.
                    self])
        yield l
Example #3
0
 def links(self):
     """
     If the container attached to this L{GlassBox}'s C{thing} is closed,
     yield its list of contents with each link annotated with
     L{_ObstructedByGlass}, indicating that the object cannot be reached.
     """
     container = IContainer(self.thing)
     if container.closed:
         for content in container.getContents():
             link = Link(self.thing.idea, content.idea)
             link.annotate([_ObstructedByGlass(),
                            ContainmentRelationship(container)])
             yield link
Example #4
0
 def links(self):
     """
     If the container attached to this L{GlassBox}'s C{thing} is closed,
     yield its list of contents with each link annotated with
     L{_ObstructedByGlass}, indicating that the object cannot be reached.
     """
     container = IContainer(self.thing)
     if container.closed:
         for content in container.getContents():
             link = Link(self.thing.idea, content.idea)
             link.annotate([_ObstructedByGlass(),
                            ContainmentRelationship(container,
                                                    content)])
             yield link
Example #5
0
 def links(self):
     """
     Implement L{ILinkContributor} to contribute L{Link}s to all contents of
     this container, as well as all of its exits, and its entrance from its
     location.
     """
     if not self.closed:
         for ob in self.getContents():
             content = Link(self.thing.idea, ob.idea)
             content.annotate([ContainmentRelationship(self)])
             yield content
     yield Link(self.thing.idea, self._entranceIdea)
     yield Link(self.thing.idea, self._exitIdea)
     for exit in self.getExits():
         yield Link(self.thing.idea, exit.exitIdea)
Example #6
0
 def test_repr(self):
     """
     A L{Path} instance can be rendered into a string by C{repr}.
     """
     key = Idea(AlsoKnownAs("key"))
     table = Idea(AlsoKnownAs("table"))
     hall = Idea(AlsoKnownAs("hall"))
     path = Path(links=[
         Link(source=hall, target=table),
         Link(source=table, target=key)
     ])
     self.assertEquals(
         repr(path), "Path(\n"
         "\t'hall' => 'table' []\n"
         "\t'table' => 'key' [])")
Example #7
0
 def test_unnamedDelegate(self):
     """
     The I{repr} of a L{Path} containing delegates without names includes the
     I{repr} of the delegates.
     """
     key = Idea(Reprable("key"))
     table = Idea(Reprable("table"))
     hall = Idea(Reprable("hall"))
     path = Path(links=[
         Link(source=hall, target=table),
         Link(source=table, target=key)
     ])
     self.assertEquals(
         repr(path), "Path(\n"
         "\thall => table []\n"
         "\ttable => key [])")
Example #8
0
 def test_single(self):
     """
     A L{Path} of one L{Link} has one subpath that is equal to itself.
     """
     source = Idea("source")
     target = Idea("target")
     path = Path(links=[Link(source=source, target=target)])
     self.assertEqual([path], list(path.eachSubPath()))
Example #9
0
    def setUp(self):
        garden = Idea(AlsoKnownAs("garden"))
        door = Idea(AlsoKnownAs("door"))
        hall = Idea(AlsoKnownAs("hall"))
        alice = Idea(AlsoKnownAs("alice"))
        key = Idea(AlsoKnownAs("key"))
        table = Idea(AlsoKnownAs("table"))

        alice.linkers.append(OneLink(Link(alice, hall)))
        hall.linkers.append(OneLink(Link(hall, door)))
        hall.linkers.append(OneLink(Link(hall, table)))
        table.linkers.append(OneLink(Link(table, key)))
        door.linkers.append(OneLink(Link(door, garden)))

        self.alice = alice
        self.hall = hall
        self.door = door
        self.garden = garden
        self.table = table
        self.key = key
Example #10
0
    def test_many(self):
        """
        A L{Path} of N L{Link}s has N - 1 subpaths, in order from shortest to
        longest, consisting of each L{Path} which is a prefix of it.
        """
        beginning = Idea("beginning")
        earlyMiddle = Idea("early middle")
        lateMiddle = Idea("late middle")
        end = Idea("end")

        one = Link(source=beginning, target=earlyMiddle)
        two = Link(source=earlyMiddle, target=lateMiddle)
        three = Link(source=lateMiddle, target=end)

        path = Path(links=[one, two, three])

        self.assertEqual([
            Path(links=[one]),
            Path(links=[one, two]),
            Path(links=[one, two, three])
        ], list(path.eachSubPath()))
Example #11
0
 def links(self):
     """
     Implement L{ILinkContributor.links()} by offering a link to this
     L{Thing}'s C{location} (if it has one).
     """
     # since my link contribution is to go up (out), put this last, since
     # containment (i.e. going down (in)) is a powerup.  we want to explore
     # contained items first.
     for pup in self.powerupsFor(iimaginary.ILinkContributor):
         for link in pup.links():
             # wooo composition
             yield link
     if self.location is not None:
         l = Link(self.idea, self.location.idea)
         # XXX this incorrectly identifies any container with an object in
         # it as 'here', since it doesn't distinguish the observer; however,
         # cycle detection will prevent these links from being considered in
         # any case I can think of.  However, 'here' is ambiguous in the
         # case where you are present inside a container, and that should
         # probably be dealt with.
         l.annotate([AlsoKnownAs('here')])
         yield l
Example #12
0
 def links(self):
     """
     Implement L{ILinkContributor.links()} by offering a link to this
     L{Thing}'s C{location} (if it has one).
     """
     # since my link contribution is to go up (out), put this last, since
     # containment (i.e. going down (in)) is a powerup.  we want to explore
     # contained items first.
     for pup in self.powerupsFor(iimaginary.ILinkContributor):
         for link in pup.links():
             # wooo composition
             yield link
     if self.location is not None:
         l = Link(self.idea, self.location.idea)
         # XXX this incorrectly identifies any container with an object in
         # it as 'here', since it doesn't distinguish the observer; however,
         # cycle detection will prevent these links from being considered in
         # any case I can think of.  However, 'here' is ambiguous in the
         # case where you are present inside a container, and that should
         # probably be dealt with.
         l.annotate([AlsoKnownAs('here')])
         yield l
Example #13
0
 def links(self):
     """
     Implement L{ILinkContributor} to contribute L{Link}s to all contents of
     this container, as well as all of its exits, and its entrance from its
     location.
     """
     if not self.closed:
         for ob in self.getContents():
             content = Link(self.thing.idea, ob.idea)
             content.annotate([ContainmentRelationship(self, ob)])
             yield content
     yield Link(self.thing.idea, self._entranceIdea)
     if self.thing.location is not None:
         yield Link(self.thing.idea, self._exitIdea)
     for exit in self.getExits():
         yield Link(self.thing.idea, exit.exitIdea)